|
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 require_once(PATH_t3lib.'class.t3lib_page.php'); 00029 $GLOBALS['LANG']->includeLLFile('EXT:t3editor/locallang.xml'); 00030 00031 class tx_t3editor_codecompletion { 00032 /** @var TYPO3AJAX */ 00033 protected $ajaxObj; 00034 00035 /** 00036 * General processor for AJAX requests. 00037 * (called by typo3/ajax.php) 00038 * 00039 * @param array $params: additional parameters (not used here) 00040 * @param TYPO3AJAX &$ajaxObj: the TYPO3AJAX object of this request 00041 * @return void 00042 * @author Oliver Hader <oliver@typo3.org> 00043 */ 00044 public function processAjaxRequest($params, TYPO3AJAX &$ajaxObj) { 00045 $this->ajaxObj = $ajaxObj; 00046 00047 $ajaxIdParts = explode('::', $ajaxObj->getAjaxID(), 2); 00048 $ajaxMethod = $ajaxIdParts[1]; 00049 $response = array(); 00050 00051 // Process the AJAX requests: 00052 if ($ajaxMethod == 'loadTemplates') { 00053 $ajaxObj->setContent($this->loadTemplates( 00054 intval(t3lib_div::_GP('pageId'))) 00055 ); 00056 $ajaxObj->setContentFormat('jsonbody'); 00057 } 00058 } 00059 00060 /** 00061 * Loads all templates up to a given page id (walking the rootline) and 00062 * cleans parts that are not required for the t3editor codecompletion. 00063 * 00064 * @param integer $pageId: id of the page 00065 * @param integer $templateId: currently unused (default: 0) 00066 * @return array Cleaned array of TypoScript information 00067 * @author Oliver Hader <oliver@typo3.org> 00068 */ 00069 protected function loadTemplates($pageId, $templateId = 0) { 00070 $templates = array(); 00071 00072 // Check whether access is granted (only admin have access to sys_template records): 00073 if ($GLOBALS['BE_USER']->isAdmin()) { 00074 // Check whether there is a pageId given: 00075 if ($pageId) { 00076 $templates = $this->getMergedTemplates($pageId); 00077 // Otherwise, set an error: 00078 } else { 00079 $this->ajaxObj->setError($GLOBALS['LANG']->getLL('pageIDInteger')); 00080 } 00081 // Set an error if user has no access to sys_template records: 00082 } else { 00083 $this->ajaxObj->setError($GLOBALS['LANG']->getLL('noPermission')); 00084 } 00085 00086 return $templates; 00087 } 00088 00089 /** 00090 * Gets merged templates by walking the rootline to a given page id. 00091 * 00092 * @todo oliver@typo3.org: Refactor this method and comment what's going on there 00093 * @param integer $pageId 00094 * @param integer $templateId 00095 * @return array Setup part of merged template records 00096 */ 00097 protected function getMergedTemplates($pageId, $templateId = 0) { 00098 $result = array(); 00099 00100 /** @var $tsParser t3lib_tsparser_ext */ 00101 $tsParser = t3lib_div::makeInstance('t3lib_tsparser_ext'); 00102 $tsParser->tt_track = 0; 00103 $tsParser->init(); 00104 // Gets the rootLine 00105 $page = t3lib_div::makeInstance('t3lib_pageSelect'); 00106 $rootLine = $page->getRootLine($pageId); 00107 00108 // This generates the constants/config + hierarchy info for the template. 00109 $tsParser->runThroughTemplates($rootLine); 00110 00111 // ts-setup & ts-constants of the currently edited template should not be included 00112 // therefor we have to delete the last template from the stack 00113 array_pop($tsParser->config); 00114 array_pop($tsParser->constants); 00115 00116 // some of the lines are not clear to me... do we need them? 00117 //$tsParser->matchAlternative[] = 'dummydummydummydummydummydummydummydummydummydummydummy'; // This is just here to make sure that at least one element is in the array so that the tsparser actually uses this array to match. 00118 //$tsParser->regexMode = $this->pObj->MOD_SETTINGS["ts_browser_regexsearch"]; 00119 // ?? 00120 //$tsParser->fixedLgd=$this->pObj->MOD_SETTINGS["ts_browser_fixedLgd"]; 00121 //$tsParser->matchAlternative = $this->pObj->MOD_SETTINGS['tsbrowser_conditions']; 00122 $tsParser->linkObjects = TRUE; 00123 $tsParser->ext_regLinenumbers = FALSE; 00124 $tsParser->bType=$bType; 00125 $tsParser->resourceCheck=1; 00126 $tsParser->uplPath = PATH_site . $tsParser->uplPath; 00127 $tsParser->removeFromGetFilePath = PATH_site; 00128 $tsParser->generateConfig(); 00129 00130 $result = $this->treeWalkCleanup($tsParser->setup); 00131 00132 return $result; 00133 } 00134 00135 /** 00136 * Walks through a tree of TypoScript configuration an cleans it up. 00137 * 00138 * @TODO oliver@typo3.org: Define and comment why this is necessary and exactly happens below 00139 * @param array $treeBranch: TypoScript configuration or sub branch of it 00140 * @return array Cleaned TypoScript branch 00141 */ 00142 private function treeWalkCleanup(array $treeBranch){ 00143 $cleanedTreeBranch = array(); 00144 00145 foreach ($treeBranch as $key => $value) { 00146 $dotCount = substr_count($key, '.'); 00147 if ($dotCount == 0){ //type definition or value-assignment 00148 if ($value != '') { 00149 if (strlen($value) > 20) { 00150 $value = substr($value, 0, 20); 00151 } 00152 if (!isset($cleanedTreeBranch[$key])) { 00153 $cleanedTreeBranch[$key] = array(); 00154 } 00155 $cleanedTreeBranch[$key]['v'] = $value; 00156 } 00157 } else if ($dotCount == 1) { // subtree (definition of properties) 00158 $subBranch = $this->treeWalkCleanup($value); 00159 if ($subBranch) { 00160 $key = str_replace('.', '', $key); 00161 if (!isset($cleanedTreeBranch[$key])) { 00162 $cleanedTreeBranch[$key] = array(); 00163 } 00164 $cleanedTreeBranch[$key]['c'] = $subBranch; 00165 } 00166 } //in other cases do nothing (this information (lineNo,..) is not needed in the editor) 00167 } 00168 00169 return $cleanedTreeBranch; 00170 } 00171 } 00172 00173 ?>
1.8.0