TYPO3 API  SVNRelease
class.tx_tstemplateanalyzer.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
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  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00029  */
00030 
00031 $GLOBALS['LANG']->includeLLFile('EXT:tstemplate_analyzer/locallang.xml');
00032 
00033 class tx_tstemplateanalyzer extends t3lib_extobjbase {
00034     function init(&$pObj,$conf) {
00035         parent::init($pObj,$conf);
00036 
00037         $this->pObj->modMenu_setDefaultList.= ',ts_analyzer_checkLinenum,ts_analyzer_checkSyntax';
00038     }
00039 
00040     function modMenu()  {
00041         global $LANG;
00042 
00043         return array (
00044             'ts_analyzer_checkSetup' => '1',
00045             'ts_analyzer_checkConst' => '1',
00046             'ts_analyzer_checkLinenum' => '1',
00047             'ts_analyzer_checkComments' => '1',
00048             'ts_analyzer_checkCrop' => '1',
00049             'ts_analyzer_checkSyntax' => '1',
00050         );
00051     }
00052 
00053     function initialize_editor($pageId,$template_uid=0) {
00054             // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
00055         global $tmpl,$tplRow,$theConstants,$rootLine;
00056 
00057         $tmpl = t3lib_div::makeInstance("t3lib_tsparser_ext");  // Defined global here!
00058         $tmpl->tt_track = 0;    // Do not log time-performance information
00059         $tmpl->init();
00060 
00061             // Gets the rootLine
00062         $sys_page = t3lib_div::makeInstance("t3lib_pageSelect");
00063         $rootLine = $sys_page->getRootLine($pageId);
00064         $tmpl->runThroughTemplates($rootLine,$template_uid);    // This generates the constants/config + hierarchy info for the template.
00065 
00066         $tplRow = $tmpl->ext_getFirstTemplate($pageId,$template_uid);   // Get the row of the first VISIBLE template of the page. whereclause like the frontend.
00067         if (is_array($tplRow))  {   // IF there was a template...
00068             return 1;
00069         }
00070     }
00071     function main() {
00072             // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
00073         global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
00074         global $tmpl,$tplRow,$theConstants,$rootLine;
00075 
00076         // **************************
00077         // Checking for more than one template an if, set a menu...
00078         // **************************
00079         $manyTemplatesMenu = $this->pObj->templateMenu();
00080         $template_uid = 0;
00081         if ($manyTemplatesMenu) {
00082             $template_uid = $this->pObj->MOD_SETTINGS["templatesOnPage"];
00083         }
00084 
00085         // **************************
00086         // Main
00087         // **************************
00088 
00089         // BUGBUG: Should we check if the uset may at all read and write template-records???
00090         $existTemplate = $this->initialize_editor($this->pObj->id,$template_uid);       // initialize
00091         if ($existTemplate) {
00092             $theOutput.=$this->pObj->doc->divider(5);
00093             $theOutput.=$this->pObj->doc->section($GLOBALS['LANG']->getLL('currentTemplate', true) ,
00094                 t3lib_iconWorks::getSpriteIconForRecord('sys_template', $tplRow) . '<strong>' .
00095                 $this->pObj->linkWrapTemplateTitle($tplRow["title"]) . '</strong>' .
00096                 htmlspecialchars(trim($tplRow["sitetitle"]) ? ' - (' . $tplRow["sitetitle"] . ')' : ''));
00097         }
00098         if ($manyTemplatesMenu) {
00099             $theOutput.=$this->pObj->doc->section("",$manyTemplatesMenu);
00100         }
00101 
00102         //  debug($tmpl->hierarchyInfo);
00103 
00104         $tmpl->clearList_const_temp = array_flip($tmpl->clearList_const);
00105         $tmpl->clearList_setup_temp = array_flip($tmpl->clearList_setup);
00106 
00107         $pointer = count($tmpl->hierarchyInfo);
00108         $tmpl->hierarchyInfoArr = $tmpl->ext_process_hierarchyInfo(array(), $pointer);
00109         $tmpl->processIncludes();
00110 
00111         $hierarArr = array();
00112         $head = '<tr class="t3-row-header">';
00113         $head.= '<td>' . $GLOBALS['LANG']->getLL('title', true) . '</td>';
00114         $head.= '<td>' . $GLOBALS['LANG']->getLL('rootlevel', true) . '</td>';
00115         $head.= '<td>' . $GLOBALS['LANG']->getLL('clearSetup', true) . '</td>';
00116         $head.= '<td>' . $GLOBALS['LANG']->getLL('clearConstants', true) . '</td>';
00117         $head.= '<td>' . $GLOBALS['LANG']->getLL('pid', true) . '</td>';
00118         $head.= '<td>' . $GLOBALS['LANG']->getLL('rootline', true) . '</td>';
00119         $head.= '<td>' . $GLOBALS['LANG']->getLL('nextLevel', true) . '</td>';
00120         $head.= '</tr>';
00121         $hierar = implode(array_reverse($tmpl->ext_getTemplateHierarchyArr($tmpl->hierarchyInfoArr, "", array(), 1)), "");
00122         $hierar= '<table id="ts-analyzer" border="0" cellpadding="0" cellspacing="1">' . $head . $hierar . '</table>';
00123 
00124         $theOutput.=$this->pObj->doc->spacer(5);
00125         $theOutput.=$this->pObj->doc->section($GLOBALS['LANG']->getLL('templateHierarchy', true), $hierar, 0, 1);
00126 
00127         $completeLink = '<p><a href="index.php?id=' . $GLOBALS['SOBE']->id . '&amp;template=all">' . $GLOBALS['LANG']->getLL('viewCompleteTS', TRUE) . '</a></p>';
00128         $theOutput .= $this->pObj->doc->spacer(5);
00129         $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('completeTS', TRUE), $completeLink, 0, 1);
00130 
00131 
00132             // Output options
00133         $theOutput.=$this->pObj->doc->spacer(25);
00134         $theOutput.=$this->pObj->doc->divider(0);
00135         $theOutput.=$this->pObj->doc->section($GLOBALS['LANG']->getLL('displayOptions', true), '', 1, 1);
00136         $addParams = t3lib_div::_GET('template') ? '&template=' . t3lib_div::_GET('template') : '';
00137         $theOutput .= '<div class="tst-analyzer-options">' .
00138             t3lib_BEfunc::getFuncCheck($this->pObj->id, "SET[ts_analyzer_checkLinenum]", $this->pObj->MOD_SETTINGS["ts_analyzer_checkLinenum"], '', $addParams, 'id="checkTs_analyzer_checkLinenum"') .
00139             '<label for="checkTs_analyzer_checkLinenum">' . $GLOBALS['LANG']->getLL('lineNumbers', true) . '</label> ' .
00140             t3lib_BEfunc::getFuncCheck($this->pObj->id, "SET[ts_analyzer_checkSyntax]", $this->pObj->MOD_SETTINGS["ts_analyzer_checkSyntax"], '', $addParams, 'id="checkTs_analyzer_checkSyntax"') .
00141             '<label for="checkTs_analyzer_checkSyntax">' . $GLOBALS['LANG']->getLL('syntaxHighlight', true) . '</label> ' .
00142             (!$this->pObj->MOD_SETTINGS["ts_analyzer_checkSyntax"] ?
00143                 t3lib_BEfunc::getFuncCheck($this->pObj->id, "SET[ts_analyzer_checkComments]", $this->pObj->MOD_SETTINGS["ts_analyzer_checkComments"], '', $addParams, 'id="checkTs_analyzer_checkComments"') .
00144                 '<label for="checkTs_analyzer_checkComments">' . $GLOBALS['LANG']->getLL('comments', true) . '</label> ' .
00145                 t3lib_BEfunc::getFuncCheck($this->pObj->id, "SET[ts_analyzer_checkCrop]", $this->pObj->MOD_SETTINGS["ts_analyzer_checkCrop"], '', $addParams, 'id="checkTs_analyzer_checkCrop"') .
00146                 '<label for="checkTs_analyzer_checkCrop">' . $GLOBALS['LANG']->getLL('cropLines', true) . '</label> '
00147                 :
00148                 ''
00149             ) . '</div>';
00150 
00151 
00152 
00153                 // Output Constants
00154             if (t3lib_div::_GET('template')) {
00155                 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('constants', true), "", 0, 1);
00156                 $theOutput .= $this->pObj->doc->sectionEnd();
00157                 $theOutput .= '
00158                     <table border="0" cellpadding="1" cellspacing="0">
00159                 ';
00160                 $tmpl->ext_lineNumberOffset = -2;   // Don't know why -2 and not 0... :-) But works.
00161                 $tmpl->ext_lineNumberOffset_mode = "const";
00162                 $tmpl->ext_lineNumberOffset += count(explode(LF, t3lib_TSparser::checkIncludeLines("" . $GLOBALS["TYPO3_CONF_VARS"]["FE"]["defaultTypoScript_constants"]))) + 1;
00163 
00164                 reset($tmpl->clearList_const);
00165                 foreach ($tmpl->constants as $key => $val) {
00166                     $cVal = current($tmpl->clearList_const);
00167                     if ($cVal == t3lib_div::_GET('template') || t3lib_div::_GET('template') == 'all') {
00168                         $theOutput .= '
00169                             <tr>
00170                                 <td><img src="clear.gif" width="3" height="1" alt="" /></td><td class="bgColor2"><strong>' . htmlspecialchars($tmpl->templateTitles[$cVal]) . '</strong></td></tr>
00171                             <tr>
00172                                 <td><img src="clear.gif" width="3" height="1" alt="" /></td>
00173                                 <td class="bgColor2"><table border="0" cellpadding="0" cellspacing="0" class="bgColor0" width="100%"><tr><td nowrap="nowrap">' .
00174                                 $tmpl->ext_outputTS(array($val), $this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'], $this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], 0) .
00175                                 '</td></tr></table>
00176                                 </td>
00177                             </tr>
00178                         ';
00179                         if (t3lib_div::_GET('template') != "all") {
00180                             break;
00181                         }
00182                     }
00183                     $tmpl->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
00184                     next($tmpl->clearList_const);
00185                 }
00186                 $theOutput .= '
00187                     </table>
00188                 ';
00189             }
00190 
00191             // Output setup
00192             if (t3lib_div::_GET('template')) {
00193                 $theOutput .= $this->pObj->doc->spacer(15);
00194                 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('setup', true), "", 0, 1);
00195                 $theOutput .= $this->pObj->doc->sectionEnd();
00196                 $theOutput .= '
00197                     <table border="0" cellpadding="1" cellspacing="0">
00198                 ';
00199                 $tmpl->ext_lineNumberOffset = 0;
00200                 $tmpl->ext_lineNumberOffset_mode = "setup";
00201                 $tmpl->ext_lineNumberOffset += count(explode(LF, t3lib_TSparser::checkIncludeLines("" . $GLOBALS["TYPO3_CONF_VARS"]["FE"]["defaultTypoScript_setup"]))) + 1;
00202 
00203                 reset($tmpl->clearList_setup);
00204                 foreach ($tmpl->config as $key => $val) {
00205                     if (current($tmpl->clearList_setup) == t3lib_div::_GET('template') || t3lib_div::_GET('template') == 'all') {
00206                         $theOutput .= '
00207                             <tr>
00208                                 <td><img src="clear.gif" width="3" height="1" alt="" /></td><td class="bgColor2"><strong>' . htmlspecialchars($tmpl->templateTitles[current($tmpl->clearList_setup)]) . '</strong></td></tr>
00209                             <tr>
00210                                 <td><img src="clear.gif" width="3" height="1" alt="" /></td>
00211                                 <td class="bgColor2"><table border="0" cellpadding="0" cellspacing="0" class="bgColor0" width="100%"><tr><td nowrap="nowrap">'.$tmpl->ext_outputTS(array($val),$this->pObj->MOD_SETTINGS['ts_analyzer_checkLinenum'],$this->pObj->MOD_SETTINGS['ts_analyzer_checkComments'],$this->pObj->MOD_SETTINGS['ts_analyzer_checkCrop'],$this->pObj->MOD_SETTINGS['ts_analyzer_checkSyntax'], 0).'</td></tr></table>
00212                                 </td>
00213                             </tr>
00214                         ';
00215                         if (t3lib_div::_GET('template') != "all") {
00216                             break;
00217                         }
00218                     }
00219                     $tmpl->ext_lineNumberOffset += count(explode(LF, $val)) + 1;
00220                     next($tmpl->clearList_setup);
00221                 }
00222                 $theOutput .= '
00223                     </table>
00224                 ';
00225             }
00226 
00227         return $theOutput;
00228     }
00229 }
00230 
00231 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_analyzer/class.tx_tstemplateanalyzer.php"]) {
00232     include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate_analyzer/class.tx_tstemplateanalyzer.php"]);
00233 }
00234 
00235 ?>