TYPO3 CMS  TYPO3_6-2
TypoScriptReferenceLoader.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\T3editor;
3 
24 
28  protected $xmlDoc;
29 
33  protected $ajaxObj;
34 
38  public function __construct() {
39  $GLOBALS['LANG']->includeLLFile('EXT:t3editor/locallang.xlf');
40  }
41 
51  public function processAjaxRequest($params, \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj) {
52  $this->ajaxObj = $ajaxObj;
53  // Load the TSref XML information:
54  $this->loadFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('t3editor') . 'res/tsref/tsref.xml');
55  $ajaxIdParts = explode('::', $ajaxObj->getAjaxID(), 2);
56  $ajaxMethod = $ajaxIdParts[1];
57  $response = array();
58  // Process the AJAX requests:
59  if ($ajaxMethod == 'getTypes') {
60  $ajaxObj->setContent($this->getTypes());
61  $ajaxObj->setContentFormat('jsonbody');
62  } elseif ($ajaxMethod == 'getDescription') {
63  $ajaxObj->addContent('', $this->getDescription(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('typeId'), \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('parameterName')));
64  $ajaxObj->setContentFormat('plain');
65  }
66  }
67 
74  protected function loadFile($filepath) {
75  // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
76  $previousValueOfEntityLoader = libxml_disable_entity_loader(TRUE);
77  $this->xmlDoc = new \DOMDocument('1.0', 'utf-8');
78  $this->xmlDoc->loadXML(file_get_contents($filepath));
79  libxml_disable_entity_loader($previousValueOfEntityLoader);
80  // @TODO: oliver@typo3.org: I guess this is not required here
81  $this->xmlDoc->saveXML();
82  }
83 
89  protected function getTypes() {
90  $types = $this->xmlDoc->getElementsByTagName('type');
91  $typeArr = array();
92  foreach ($types as $type) {
93  $typeId = $type->getAttribute('id');
94  $typeName = $type->getAttribute('name');
95  if (!$typeName) {
96  $typeName = $typeId;
97  }
98  $properties = $type->getElementsByTagName('property');
99  $propArr = array();
100  foreach ($properties as $property) {
101  $p = array();
102  $p['name'] = $property->getAttribute('name');
103  $p['type'] = $property->getAttribute('type');
104  $propArr[$property->getAttribute('name')] = $p;
105  }
106  $typeArr[$typeId] = array();
107  $typeArr[$typeId]['properties'] = $propArr;
108  $typeArr[$typeId]['name'] = $typeName;
109  if ($type->hasAttribute('extends')) {
110  $typeArr[$typeId]['extends'] = $type->getAttribute('extends');
111  }
112  }
113  return $typeArr;
114  }
115 
123  protected function getDescription($typeId, $parameterName = '') {
124  if (!$typeId) {
125  $this->ajaxObj->setError($GLOBALS['LANG']->getLL('typeIDMissing'));
126  return '';
127  }
128  // getElementById does only work with schema
129  $type = $this->getType($typeId);
130  // Retrieve propertyDescription
131  if ($parameterName) {
132  $properties = $type->getElementsByTagName('property');
133  foreach ($properties as $propery) {
134  $propName = $propery->getAttribute('name');
135  if ($propName == $parameterName) {
136  $descriptions = $propery->getElementsByTagName('description');
137  if ($descriptions->length) {
138  $description = $descriptions->item(0)->textContent;
139  $description = htmlspecialchars($description);
140  $description = nl2br($description);
141  return $description;
142  }
143  }
144  }
145  }
146  return '';
147  }
148 
155  protected function getType($typeId) {
156  $types = $this->xmlDoc->getElementsByTagName('type');
157  foreach ($types as $type) {
158  if ($type->getAttribute('id') == $typeId) {
159  return $type;
160  }
161  }
162  }
163 
164 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
processAjaxRequest($params, \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj)