|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2008-2011 Stephan Petzl <spetzl@gmx.at> and Christian Kartnig <office@hahnepeter.de> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 00028 /** 00029 * Loads TSref information from a XML file an responds to an AJAX call. 00030 * 00031 * @TODO Refactor and correct phpDoc comments 00032 * @package TYPO3 00033 * @author Stephan Petzl <spetzl@gmx.at> 00034 * @author Christian Kartnig <office@hahnepeter.de> 00035 */ 00036 00037 $GLOBALS['LANG']->includeLLFile('EXT:t3editor/locallang.xml'); 00038 00039 class tx_t3editor_TSrefLoader { 00040 /** @var DOMDocument */ 00041 protected $xmlDoc; 00042 00043 /** @var TYPO3AJAX */ 00044 protected $ajaxObj; 00045 00046 /** 00047 * General processor for AJAX requests. 00048 * (called by typo3/ajax.php) 00049 * 00050 * @param array $params: additional parameters (not used here) 00051 * @param TYPO3AJAX &$ajaxObj: the TYPO3AJAX object of this request 00052 * @return void 00053 * @author Oliver Hader <oliver@typo3.org> 00054 */ 00055 public function processAjaxRequest($params, TYPO3AJAX &$ajaxObj) { 00056 $this->ajaxObj = $ajaxObj; 00057 00058 // Load the TSref XML information: 00059 $this->loadFile(t3lib_extMgm::extPath('t3editor') . 'res/tsref/tsref.xml'); 00060 00061 $ajaxIdParts = explode('::', $ajaxObj->getAjaxID(), 2); 00062 $ajaxMethod = $ajaxIdParts[1]; 00063 $response = array(); 00064 00065 // Process the AJAX requests: 00066 if ($ajaxMethod == 'getTypes') { 00067 $ajaxObj->setContent($this->getTypes()); 00068 $ajaxObj->setContentFormat('jsonbody'); 00069 } elseif ($ajaxMethod == 'getDescription') { 00070 $ajaxObj->addContent( 00071 '', 00072 $this->getDescription( 00073 t3lib_div::_GP('typeId'), 00074 t3lib_div::_GP('parameterName') 00075 ) 00076 ); 00077 $ajaxObj->setContentFormat('plain'); 00078 } 00079 } 00080 00081 /** 00082 * Enter description here... 00083 * 00084 * @param string $filepath 00085 * @return void 00086 */ 00087 protected function loadFile($filepath) { 00088 $this->xmlDoc = new DOMDocument('1.0', 'utf-8'); 00089 $this->xmlDoc->load($filepath); 00090 00091 // @TODO: oliver@typo3.org: I guess this is not required here 00092 $this->xmlDoc->saveXML(); 00093 } 00094 00095 /** 00096 * Enter description here... 00097 * 00098 * @return array 00099 */ 00100 protected function getTypes() { 00101 $types = $this->xmlDoc->getElementsByTagName('type'); 00102 $typeArr = array(); 00103 foreach($types as $type){ 00104 $typeId = $type->getAttribute('id'); 00105 $typeName = $type->getAttribute('name'); 00106 if(!$typeName) { 00107 $typeName = $typeId; 00108 } 00109 $properties = $type->getElementsByTagName('property'); 00110 $propArr = array(); 00111 foreach($properties as $property) { 00112 $p = array(); 00113 $p['name'] = $property->getAttribute('name'); 00114 $p['type'] = $property->getAttribute('type'); 00115 $propArr[$property->getAttribute('name')] = $p; 00116 } 00117 $typeArr[$typeId] = array(); 00118 $typeArr[$typeId]['properties'] = $propArr; 00119 $typeArr[$typeId]['name'] = $typeName; 00120 if($type->hasAttribute('extends')) { 00121 $typeArr[$typeId]['extends'] = $type->getAttribute('extends'); 00122 } 00123 } 00124 return $typeArr; 00125 } 00126 00127 /** 00128 * Enter description here... 00129 * 00130 * @param string $typeId 00131 * @param string $parameterName 00132 * @return string 00133 */ 00134 protected function getDescription($typeId, $parameterName = '') { 00135 if (!$typeId) { 00136 $this->ajaxObj->setError($GLOBALS['LANG']->getLL('typeIDMissing')); 00137 return ''; 00138 } 00139 00140 // getElementById does only work with schema 00141 $type = $this->getType($typeId); 00142 if ($parameterName) { //retrieve propertyDescription 00143 $properties = $type->getElementsByTagName('property'); 00144 foreach ($properties as $propery) { 00145 $propName = $propery->getAttribute('name'); 00146 if ($propName == $parameterName) { 00147 $descriptions = $propery->getElementsByTagName('description'); 00148 if ($descriptions->length) { 00149 $description = $descriptions->item(0)->textContent; 00150 $description = htmlspecialchars($description); 00151 $description = nl2br($description); 00152 return $description; 00153 } 00154 } 00155 } 00156 } else { // retrieve typedescription 00157 /* 00158 $descriptions = $type->getElementsByTagName('description'); 00159 if($descriptions->length){ 00160 $description = $descriptions->item(0)->textContent; 00161 00162 return htmlspecialchars($description); 00163 }*/ 00164 } 00165 00166 return ''; 00167 } 00168 00169 /** 00170 * Enter description here... 00171 * 00172 * @param string $typeId 00173 * @return DOMNode 00174 */ 00175 protected function getType($typeId) { 00176 $types = $this->xmlDoc->getElementsByTagName('type'); 00177 foreach ($types as $type) { 00178 if ($type->getAttribute('id') == $typeId) { 00179 return $type; 00180 } 00181 } 00182 } 00183 } 00184 00185 ?>
1.8.0