1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of MediaInternetBaseHandler.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* A base class for managing the addition of Internet media.
|
10
|
*
|
11
|
* Classes extending this class manage the addition of Internet media. To
|
12
|
* achieve this, the class should parse user-submitted embed code, claim it
|
13
|
* when appropriate and save it as a managed file.
|
14
|
*/
|
15
|
abstract class MediaInternetBaseHandler {
|
16
|
|
17
|
/**
|
18
|
* The constructor for the MediaInternetBaseHandler class. This method is also called
|
19
|
* from the classes that extend this class and override this method.
|
20
|
*/
|
21
|
public function __construct($embedCode) {
|
22
|
$this->embedCode = $embedCode;
|
23
|
}
|
24
|
|
25
|
/**
|
26
|
* Determines if this handler should claim the item.
|
27
|
*
|
28
|
* @param string $embed_code
|
29
|
* A string of user-submitted embed code.
|
30
|
*
|
31
|
* @return boolean
|
32
|
* Pass TRUE to claim the item.
|
33
|
*/
|
34
|
abstract public function claim($embed_code);
|
35
|
|
36
|
/**
|
37
|
* Returns a file object which can be used for validation.
|
38
|
*
|
39
|
* @return StdClass
|
40
|
*/
|
41
|
abstract public function getFileObject();
|
42
|
|
43
|
/**
|
44
|
* If required, implementors can validate the embedCode.
|
45
|
*/
|
46
|
public function validate() {
|
47
|
}
|
48
|
|
49
|
/**
|
50
|
* Before the file has been saved, implementors may do additional operations.
|
51
|
*
|
52
|
* @param object $file_obj
|
53
|
*/
|
54
|
public function preSave(&$file_obj) {
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* Saves a file to the file_managed table (with file_save).
|
59
|
*
|
60
|
* @return StdClass
|
61
|
*/
|
62
|
public function save() {
|
63
|
$file_obj = $this->getFileObject();
|
64
|
$this->preSave($file_obj);
|
65
|
file_save($file_obj);
|
66
|
$this->postSave($file_obj);
|
67
|
return $file_obj;
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* After the file has been saved, implementors may do additional operations.
|
72
|
*
|
73
|
* @param object $file_obj
|
74
|
*/
|
75
|
public function postSave(&$file_obj) {
|
76
|
}
|
77
|
}
|