class.tx_tstemplateanalyzer.php

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

Generated on Sat Jul 24 04:17:41 2010 for TYPO3 API by  doxygen 1.4.7