1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package toolkit |
4
|
|
|
*/ |
5
|
|
|
/** |
6
|
|
|
* XMLPage extends the Page class to provide an object representation |
7
|
|
|
* of a Symphony backend XML/AJAX page. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
abstract class XMLPage extends TextPage |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* The root node for the response of the XMLPage |
14
|
|
|
* @var XMLElement |
15
|
|
|
*/ |
16
|
|
|
protected $_Result; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The constructor for `XMLPage`. This sets the page status to `Page::HTTP_STATUS_OK`, |
20
|
|
|
* the default content type to `text/xml` and initialises `$this->_Result` |
21
|
|
|
* with an `XMLElement`. The constructor also starts the Profiler for this |
22
|
|
|
* page template. |
23
|
|
|
* |
24
|
|
|
* @see toolkit.Profiler |
25
|
|
|
*/ |
26
|
|
|
public function __construct() |
27
|
|
|
{ |
28
|
|
|
$this->_Result = new XMLElement('result'); |
29
|
|
|
$this->_Result->setIncludeHeader(true); |
30
|
|
|
|
31
|
|
|
$this->setHttpStatus(self::HTTP_STATUS_OK); |
32
|
|
|
$this->addHeaderToPage('Content-Type', 'text/xml'); |
33
|
|
|
|
34
|
|
|
Symphony::Profiler()->sample('Page template created', PROFILE_LAP); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* This function is called by Administration class when a user is not authenticated |
39
|
|
|
* to the Symphony backend. It sets the status of this page to |
40
|
|
|
* `Page::HTTP_STATUS_UNAUTHORIZED` and appends a message for generation |
41
|
|
|
*/ |
42
|
|
|
public function handleFailedAuthorisation() |
43
|
|
|
{ |
44
|
|
|
$this->setHttpStatus(self::HTTP_STATUS_UNAUTHORIZED); |
45
|
|
|
$this->_Result->setValue(__('You are not authorised to access this page.')); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* The generate functions outputs the correct headers for |
50
|
|
|
* this `XMLPage`, adds `$this->getHttpStatusCode()` code to the root attribute |
51
|
|
|
* before calling the parent generate function and generating |
52
|
|
|
* the `$this->_Result` XMLElement |
53
|
|
|
* |
54
|
|
|
* @param null $page |
|
|
|
|
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function generate($page = null) |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
// Set the actual status code in the xml response |
60
|
|
|
$this->_Result->setAttribute('status', $this->getHttpStatusCode()); |
61
|
|
|
|
62
|
|
|
parent::generate($page); |
63
|
|
|
|
64
|
|
|
return $this->_Result->generate(true); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|