/** * Returns an array with all attribute names not used in template * * We accept Tx_Rnbase_Domain_Model_DataInterface, but the model must also * implement IteratorAggregate! * * @param Tx_Rnbase_Domain_Model_Data $item * @param string $template * @param string $marker * @return array */ public static function findUnusedAttributes(Tx_Rnbase_Domain_Model_DataInterface $item, $template, $marker) { $ignore = array(); $minfo = self::containsMarker($template, $marker . '___MINFO'); $minfoArr = array(); foreach ($item as $key => $value) { if ($minfo) { $minfoArr[$key] = $marker . '_' . strtoupper($key); } if (!self::containsMarker($template, $marker . '_' . strtoupper($key))) { $ignore[] = $key; } } if ($minfo) { tx_rnbase::load('tx_rnbase_util_Debug'); $item->setProperty('__MINFO', tx_rnbase_util_Debug::viewArray($minfoArr)); } return $ignore; }
/** * Returns the localized label of the LOCAL_LANG key. * This is a reimplementation from tslib_pibase::pi_getLL(). */ public function getLL($key, $alt = '', $hsc = FALSE) { return $this->localLangUtil->getLL($key, $alt, $hsc, tx_rnbase_util_Debug::isLabelDebugEnabled($this)); }
/** * @param tx_rnbase_parameters $parameters * @param tx_rnbase_configurations $configurations * * @return string */ function execute(&$parameters, &$configurations) { $this->setConfigurations($configurations); $debugKey = $configurations->get($this->getConfId() . '_debugview'); $debug = $debugKey && ($debugKey === '1' || $_GET['debug'] && array_key_exists($debugKey, array_flip(tx_rnbase_util_Strings::trimExplode(',', $_GET['debug']))) || $_POST['debug'] && array_key_exists($debugKey, array_flip(tx_rnbase_util_Strings::trimExplode(',', $_POST['debug'])))); if ($debug) { $time = microtime(TRUE); $memStart = memory_get_usage(); } if ($configurations->getBool($this->getConfId() . 'toUserInt')) { if ($debug) { tx_rnbase_util_Debug::debug('Converting to USER_INT!', 'View statistics for: ' . $this->getConfId() . ' Key: ' . $debugKey); } $configurations->convertToUserInt(); } // Add JS or CSS files $this->addResources($configurations, $this->getConfId()); $cacheHandler = $this->getCacheHandler($configurations, $this->getConfId() . '_caching.'); $out = $cacheHandler ? $cacheHandler->getOutput() : ''; $cached = !empty($out); if (!$cached) { $viewData =& $configurations->getViewData(); tx_rnbase_util_Misc::pushTT(get_class($this), 'handleRequest'); $out = $this->handleRequest($parameters, $configurations, $viewData); tx_rnbase_util_Misc::pullTT(); if (!$out) { // View // It is possible to set another view via typoscript $viewClassName = $configurations->get($this->getConfId() . 'viewClassName'); $viewClassName = strlen($viewClassName) > 0 ? $viewClassName : $this->getViewClassName(); // TODO: error handling... $view = tx_rnbase::makeInstance($viewClassName); $view->setTemplatePath($configurations->getTemplatePath()); if (method_exists($view, 'setController')) { $view->setController($this); } // Das Template wird komplett angegeben $tmplName = $this->getTemplateName(); if (!$tmplName || !strlen($tmplName)) { tx_rnbase_util_Misc::mayday('No template name defined!'); } $view->setTemplateFile($configurations->get($tmplName . 'Template', TRUE)); tx_rnbase_util_Misc::pushTT(get_class($this), 'render'); $out = $view->render($tmplName, $configurations); tx_rnbase_util_Misc::pullTT(); } if ($cacheHandler) { $cacheHandler->setOutput($out); } } if ($debug) { $memEnd = memory_get_usage(); tx_rnbase_util_Debug::debug(array('Action' => get_class($this), 'Conf Id' => $this->getConfId(), 'Execution Time' => microtime(TRUE) - $time, 'Memory Start' => $memStart, 'Memory End' => $memEnd, 'Memory Consumed' => $memEnd - $memStart, 'Cached?' => $cached ? 'yes' : 'no', 'CacheHandler' => is_object($cacheHandler) ? get_class($cacheHandler) : '', 'SubstCacheEnabled?' => tx_rnbase_util_Templates::isSubstCacheEnabled() ? 'yes' : 'no'), 'View statistics for: ' . $this->getConfId() . ' Key: ' . $debugKey); } // reset the substCache after each view! tx_rnbase_util_Templates::resetSubstCache(); return $out; }
/** * Stops PHP execution : die() if some critical error appeared * This method is taken from the great ameos_formidable extension. * * @param string $msg: the error message * @return void */ public static function mayday($msg, $extKey = '') { tx_rnbase::load('tx_rnbase_util_Logger'); tx_rnbase::load('tx_rnbase_util_Debug'); tx_rnbase_util_Logger::fatal($msg, $extKey ? $extKey : 'rn_base'); $aTrace = debug_backtrace(); $aLocation = array_shift($aTrace); $aTrace1 = array_shift($aTrace); $aTrace2 = array_shift($aTrace); $aTrace3 = array_shift($aTrace); $aTrace4 = array_shift($aTrace); $aDebug = array(); $aDebug[] = '<h2 id="backtracetitle">Call stack</h2>'; $aDebug[] = '<div class="backtrace">'; $aDebug[] = '<span class="notice"><b>Call 0: </b>' . str_replace(PATH_site, '/', $aLocation['file']) . ':' . $aLocation['line'] . ' | <b>' . $aTrace1['class'] . $aTrace1['type'] . $aTrace1['function'] . '</b></span><br/>With parameters: ' . (!empty($aTrace1['args']) ? self::viewMixed($aTrace1['args']) : ' no parameters'); $aDebug[] = '<hr/>'; $aDebug[] = '<span class="notice"><b>Call -1: </b>' . str_replace(PATH_site, '/', $aTrace1['file']) . ':' . $aTrace1['line'] . ' | <b>' . $aTrace2['class'] . $aTrace2['type'] . $aTrace2['function'] . '</b></span><br />With parameters: ' . (!empty($aTrace2['args']) ? self::viewMixed($aTrace2['args']) : ' no parameters'); $aDebug[] = '<hr/>'; $aDebug[] = '<span class="notice"><b>Call -2: </b>' . str_replace(PATH_site, '/', $aTrace2['file']) . ':' . $aTrace2['line'] . ' | <b>' . $aTrace3['class'] . $aTrace3['type'] . $aTrace3['function'] . '</b></span><br />With parameters: ' . (!empty($aTrace3['args']) ? self::viewMixed($aTrace3['args']) : ' no parameters'); $aDebug[] = '<hr/>'; $aDebug[] = '<span class="notice"><b>Call -3: </b>' . str_replace(PATH_site, '/', $aTrace3['file']) . ':' . $aTrace3['line'] . ' | <b>' . $aTrace4['class'] . $aTrace4['type'] . $aTrace4['function'] . '</b></span><br />With parameters: ' . (!empty($aTrace4['args']) ? self::viewMixed($aTrace4['args']) : ' no parameters'); $aDebug[] = '<hr/>'; if ($debugTrail = tx_rnbase_util_Debug::getDebugTrail()) { $aDebug[] = '<span class="notice">' . $debugTrail . '</span>'; $aDebug[] = '<hr/>'; } $aDebug[] = '</div>'; if (intval(tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'forceException4Mayday'))) { throw tx_rnbase::makeInstance('tx_rnbase_util_Exception', $msg, 0, array('Info' => $aDebug)); } $aDebug[] = '<br/>'; $sContent = '<h1 id="title">Mayday</h1>'; $sContent .= '<div id="errormessage">' . $msg . '</div>'; $sContent .= '<hr />'; $verbose = intval(tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'verboseMayday')); if ($verbose) { $sContent .= implode('', $aDebug); } $sPage = <<<MAYDAYPAGE <!DOCTYPE html \tPUBLIC '-//W3C//DTD XHTML 1.1//EN' \t'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'> \t<head> \t\t<title>{$extKey}::Mayday</title> \t\t<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> \t\t<meta name="robots" content="noindex, nofollow" /> \t\t<style type="text/css"> \t\t\t#title { \t\t\t\tcolor: red; \t\t\t\tfont-family: Verdana; \t\t\t} \t\t\t#errormessage { \t\t\t\tborder: 2px solid red; \t\t\t\tpadding: 10px; \t\t\t\tcolor: white; \t\t\t\tbackground-color: red; \t\t\t\tfont-family: Verdana; \t\t\t\tfont-size: 12px; \t\t\t} \t\t\t.notice { \t\t\t\tfont-family: Verdana; \t\t\t\tfont-size: 9px; \t\t\t\tfont-style: italic; \t\t\t} \t\t\t#backtracetitle { \t\t\t} \t\t\t.backtrace { \t\t\t\tbackground-color: #FFFFCC; \t\t\t} \t\t\tHR { \t\t\t\tborder: 1px solid silver; \t\t\t} \t\t</style> \t</head> \t<body> \t\t{$sContent} \t</body> </html> MAYDAYPAGE; $dieOnMayday = intval(tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'dieOnMayday')); if ($dieOnMayday) { die($sPage); } else { echo $sPage; } }
/** * Returns an array with all column names not used in template * * @param array $record * @param string $template * @param string $marker * @return array * @deprecated use Tx_Rnbase_Frontend_Marker_Utility::findUnusedAttributes */ public static function findUnusedCols(&$record, $template, $marker) { $ignore = array(); $minfo = self::containsMarker($template, $marker . '___MINFO'); $minfoArr = array(); foreach ($record as $key => $value) { if ($minfo) { $minfoArr[$key] = $marker . '_' . strtoupper($key); } if (!self::containsMarker($template, $marker . '_' . strtoupper($key))) { $ignore[] = $key; } } if ($minfo) { tx_rnbase::load('tx_rnbase_util_Debug'); $record['__MINFO'] = tx_rnbase_util_Debug::viewArray($minfoArr); } return $ignore; }
/** * Returns the Backtrase excluding the log calls. * * @return array */ private function getBacktrace() { \tx_rnbase::load('tx_rnbase_util_Debug'); $trace = array_reverse(\tx_rnbase_util_Debug::getTracePaths()); $lastIgnoreKey = 0; $ignoreClasses = array('DMK\\Mklog\\Logger\\', 'TYPO3\\CMS\\Core\\Log\\', 'TYPO3\\CMS\\Core\\Utility\\GeneralUtility::devLog', 'Tx_Rnbase_Utility_Logger', 'tx_rnbase_util_Logger'); foreach ($trace as $key => $path) { $ignore = false; foreach ($ignoreClasses as $ignoreClass) { $ignore = \Tx_Rnbase_Utility_Strings::isFirstPartOfStr($path, $ignoreClass); if ($ignore) { break; } } // break if ther is no more ignore if ($ignore) { $lastIgnoreKey = $key; } } return array_splice($trace, $lastIgnoreKey + 1); }
/** * (non-PHPdoc) * @see tx_mklib_srv_Base::handleCreation() */ public function handleCreation(array $data) { tx_rnbase::load('tx_rnbase_util_Debug'); tx_rnbase_util_Debug::debug(array('creating a static country via the service can\'t be done.'), __METHOD__ . ' Line: ' . __LINE__); // @TODO: remove me }
/** * Make a query to database. You will receive an array with result rows. All * database resources are closed after each call. * A Hidden and Delete-Clause for FE-Requests is added for requested table. * * @param $what requested columns * @param $from either the name of on table or an array with index 0 the from clause * and index 1 the requested tablename * @param $where * @param $groupby * @param $orderby * @param $wrapperClass Name einer WrapperKlasse für jeden Datensatz * @param $limit = '' Limits number of results * @param $debug = 0 Set to 1 to debug sql-String * @deprecated use tx_rnbase_util_DB::doSelect() */ function queryDB($what, $from, $where, $groupBy = '', $orderBy = '', $wrapperClass = 0, $limit = '', $debug = 0) { $tableName = $from; $fromClause = $from; if (is_array($from)) { $tableName = $from[1]; $fromClause = $from[0]; } $limit = intval($limit) > 0 ? intval($limit) : ''; // Zur Where-Clause noch die gültigen Felder hinzufügen $contentObjectRendererClass = tx_rnbase_util_Typo3Classes::getContentObjectRendererClass(); $where .= $contentObjectRendererClass::enableFields($tableName); if ($debug) { $sql = $GLOBALS['TYPO3_DB']->SELECTquery($what, $fromClause, $where, $groupBy, $orderBy); tx_rnbase_util_Debug::debug($sql, 'SQL'); tx_rnbase_util_Debug::debug(array($what, $from, $where)); } $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($what, $fromClause, $where, $groupBy, $orderBy, $limit); $wrapper = is_string($wrapperClass) ? tx_rnbase::makeInstanceClassName($wrapperClass) : 0; $rows = array(); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $rows[] = $wrapper ? new $wrapper($row) : $row; } $GLOBALS['TYPO3_DB']->sql_free_result($res); if ($debug) { tx_rnbase_util_Debug::debug(count($rows), 'Rows retrieved'); } return $rows; }
/** * Returns the localized label of the LOCAL_LANG key. * This is a reimplementation from tslib_pibase::pi_getLL(). * * @param string $key * @param string $alt * @param string $hsc * @param string $labelDebug * * @return string */ public function getLL($key, $alt = '', $hsc = FALSE, $labelDebug = FALSE) { $label = tx_rnbase_util_TYPO3::isTYPO46OrHigher() ? $this->getLL46($key, $alt, $hsc) : $this->getLL40($key, $alt, $hsc); if ($labelDebug) { $options = array(); if ($labelDebug !== 'html') { $options['plain'] = TRUE; } $label = tx_rnbase_util_Debug::wrapDebugInfo($label, strtolower($key), $options); } return $label; }
/** * Render an array of data entries with an html template. The html template should look like this: * ###DATAS### * ###DATA### * ###DATA_UID### * ###DATA### * ###DATAEMPTYLIST### * Shown if list is empty * ###DATAEMPTYLIST### * ###DATAS### * We have some conventions here: * The given parameter $marker should be named 'DATA' for this example. The the list subpart * is experted to be named '###'.$marker.'S###'. Please notice the trailing S! * If you want to render a pagebrowser add it to the $viewData with key 'pagebrowser'. * A filter will be detected and rendered too. It should be available in $viewData with key 'filter'. * * @param array|Traversable $dataArr entries * @param string $template * @param string $markerClassname item-marker class * @param string $confId ts-Config for data entries like team. * @param string $marker name of marker like TEAM * @param tx_rnbase_util_FormatUtil $formatter * @param array $markerParams array of settings for itemmarker * @return string */ function render(&$dataArr, $viewData, $template, $markerClassname, $confId, $marker, $formatter, $markerParams = NULL) { $viewData = is_object($viewData) ? $viewData : new ArrayObject(); $debugKey = $formatter->getConfigurations()->get($confId . '_debuglb'); $debug = $debugKey && ($debugKey === '1' || $_GET['debug'] && array_key_exists($debugKey, array_flip(tx_rnbase_util_Strings::trimExplode(',', $_GET['debug']))) || $_POST['debug'] && array_key_exists($debugKey, array_flip(tx_rnbase_util_Strings::trimExplode(',', $_POST['debug'])))); if ($debug) { $time = microtime(TRUE); $mem = memory_get_usage(); $wrapTime = tx_rnbase_util_FormatUtil::$time; $wrapMem = tx_rnbase_util_FormatUtil::$mem; } $outerMarker = $this->getOuterMarker($marker, $template); $htmlParser = tx_rnbase_util_Typo3Classes::getHtmlParserClass(); while ($templateList = $htmlParser::getSubpart($template, '###' . $outerMarker . 'S###')) { if ((is_array($dataArr) || $dataArr instanceof Traversable) && count($dataArr)) { /* @var $listMarker tx_rnbase_util_ListMarker */ $listMarker = tx_rnbase::makeInstance('tx_rnbase_util_ListMarker', $this->info->getListMarkerInfo()); $templateEntry = $htmlParser::getSubpart($templateList, '###' . $marker . '###'); $offset = 0; $pageBrowser = $viewData->offsetGet('pagebrowser'); if ($pageBrowser) { $state = $pageBrowser->getState(); $offset = $state['offset']; } $markerArray = $subpartArray = array(); $listMarker->addVisitors($this->visitors); $out = $listMarker->render($dataArr, $templateEntry, $markerClassname, $confId, $marker, $formatter, $markerParams, $offset); $subpartArray['###' . $marker . '###'] = $out; $subpartArray['###' . $marker . 'EMPTYLIST###'] = ''; // Das Menu für den PageBrowser einsetzen if ($pageBrowser) { $subpartArray['###PAGEBROWSER###'] = tx_rnbase_util_BaseMarker::fillPageBrowser($htmlParser::getSubpart($template, '###PAGEBROWSER###'), $pageBrowser, $formatter, $confId . 'pagebrowser.'); $listSize = $pageBrowser->getListSize(); } else { $listSize = count($dataArr); } $markerArray['###' . $marker . 'COUNT###'] = $formatter->wrap($listSize, $confId . 'count.'); // charbrowser $pagerData = $viewData->offsetGet('pagerData'); $charPointer = $viewData->offsetGet('charpointer'); $subpartArray['###CHARBROWSER###'] = tx_rnbase_util_BaseMarker::fillCharBrowser(tx_rnbase_util_Templates::getSubpart($template, '###CHARBROWSER###'), $markerArray, $pagerData, $charPointer, $formatter->getConfigurations(), $confId . 'charbrowser.'); $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($templateList, $markerArray, $subpartArray); } else { // Support für EMPTYLIST-Block if (tx_rnbase_util_BaseMarker::containsMarker($template, $marker . 'EMPTYLIST')) { $out = $htmlParser::getSubpart($template, '###' . $marker . 'EMPTYLIST###'); } else { $out = $this->info->getEmptyListMessage($confId, $viewData, $formatter->getConfigurations()); } } $template = tx_rnbase_util_Templates::substituteSubpart($template, '###' . $outerMarker . 'S###', $out, 0); } $markerArray = array(); $subpartArray = array(); // Muss ein Formular mit angezeigt werden // Zuerst auf einen Filter prüfen $filter = $viewData->offsetGet('filter'); if ($filter) { $template = $filter->getMarker()->parseTemplate($template, $formatter, $confId . 'filter.', $marker); } // Jetzt noch die alte Variante $markerArray['###SEARCHFORM###'] = ''; $seachform = $viewData->offsetGet('searchform'); if ($seachform) { $markerArray['###SEARCHFORM###'] = $seachform; } $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($template, $markerArray, $subpartArray); if ($debug) { tx_rnbase::load('class.tx_rnbase_util_Misc.php'); $wrapTime = tx_rnbase_util_FormatUtil::$time - $wrapTime; $wrapMem = tx_rnbase_util_FormatUtil::$mem - $wrapMem; tx_rnbase_util_Debug::debug(array('Rows' => count($dataArr), 'Execustion time' => microtime(TRUE) - $time, 'WrapTime' => $wrapTime, 'WrapMem' => $wrapMem, 'Memory start' => $mem, 'Memory consumed' => memory_get_usage() - $mem), 'ListBuilder Statistics for: ' . $confId . ' Key: ' . $debugKey); } return $out; }
/** * @return array */ public static function getDebugBacktrace() { tx_rnbase::load('tx_rnbase_util_Debug'); return tx_rnbase_util_Debug::getDebugTrail(); }
/** * Puts all columns in $record to a Marker-Array. Each column is wrapped according to it's name. * So if your confId is 'profile.' and your column is 'date' you can define a TS setup like * <pre>profile.date.strftime = %Y</pre> * @return Array */ function getItemMarkerArrayWrapped($record, $confId, $noMap = 0, $markerPrefix = '', $initMarkers = 0) { if (!is_array($record)) { return array(); } $start = microtime(TRUE); $mem = memory_get_usage(); $tmpArr = $this->cObj->data; // Ensure the initMarkers are part of the record if (is_array($initMarkers)) { for ($i = 0, $cnt = count($initMarkers); $i < $cnt; $i++) { if (!array_key_exists($initMarkers[$i], $record)) { $record[$initMarkers[$i]] = ''; } } } // extend the record by dc columns $conf = $this->getConfigurations()->get($confId); if (is_array($conf)) { // Add dynamic columns $keys = $this->getConfigurations()->getUniqueKeysNames($conf); foreach ($keys as $key) { if ($key[0] === 'd' && $key[1] === 'c' && !isset($record[$key])) { $record[$key] = $conf[$key]; } } } if (array_key_exists('__MINFO', $record)) { // Die TS-Config in die Ausgabe integrieren $record['__MINFO'] .= tx_rnbase_util_Debug::viewArray(array('TS-Path' => $confId)); $record['__MINFO'] .= tx_rnbase_util_Debug::viewArray(array($conf)); } $this->cObj->data = $record; // Alle Metadaten auslesen und wrappen $data = array(); foreach ($record as $colname => $value) { if (is_array($noMap) && in_array($colname, $noMap)) { continue; } // Für DATETIME gibt es eine Sonderbehandlung, um leere Werte zu behandeln if ($conf[$colname] == 'DATETIME' && $conf[$colname . '.']['ifEmpty'] && !$value) { $data[$colname] = $conf[$colname . '.']['ifEmpty']; } elseif ($conf[$colname]) { // Get value using cObjGetSingle $this->cObj->setCurrentVal($value); $data[$colname] = $this->cObj->cObjGetSingle($conf[$colname], $conf[$colname . '.']); $this->cObj->setCurrentVal(FALSE); } elseif ($conf[$colname] == 'CASE') { $data[$colname] = $this->cObj->CASEFUNC($conf[$colname . '.']); } else { // Es wird ein normaler Wrap gestartet // Zuerst Numberformat durchführen $value = $this->numberFormat($value, $conf[$colname . '.']); $data[$colname] = $this->stdWrap($value, $conf[$colname . '.']); } } reset($record); $markerArray = tx_rnbase_util_FormatUtil::getItemMarkerArray($data, $noMap, $markerPrefix, $initMarkers); unset($data); // 400 kB $this->cObj->data = $tmpArr; self::$time += microtime(TRUE) - $start; self::$mem += memory_get_usage() - $mem; return $markerArray; }
/** * Gibt die gesammelten Debug meldungen aus * Funktioiniert nur, wenn die debugs nicht in eine datie geschrieben wird. */ public static function t3Debug() { tx_rnbase_util_Debug::debug(self::$aDebug, 'tx_mklib_util_Debug', 'mklib Debug'); // @TODO: remove me }