function processTags($matches) { global $pretext, $production_status, $txptrace, $txptracelevel, $txp_current_tag; $tag = $matches[1]; $trouble_makers = array('link'); if (in_array($tag, $trouble_makers)) { $tag = 'tpt_' . $tag; } $atts = isset($matches[2]) ? splat($matches[2]) : ''; $thing = isset($matches[4]) ? $matches[4] : null; $old_tag = @$txp_current_tag; $txp_current_tag = '<txp:' . $tag . ($atts ? $matches[2] : '') . ($thing ? '>' : '/>'); trace_add($txp_current_tag); @++$txptracelevel; if ($production_status == 'debug') { maxMemUsage(trim($matches[0])); } $out = ''; if (function_exists($tag)) { $out = $tag($atts, $thing, $matches[0]); } elseif (isset($pretext[$tag])) { $out = $pretext[$tag]; } else { trigger_error(gTxt('unknown_tag', array('{tag}' => $tag)), E_USER_WARNING); } @--$txptracelevel; if (isset($matches[4])) { trace_add('</txp:' . $tag . '>'); } $txp_current_tag = $old_tag; return $out; }
/** * Parse a tag for attributes and hand over to the tag handler function. * * @param string $tag The tag name without '<txp:' * @param string $atts The attribute string * @param string|null $thing The tag's content in case of container tags (optional) * @return string Parsed tag result */ function processTags($tag, $atts, $thing = NULL) { global $production_status, $txptrace, $txptracelevel, $txp_current_tag; if ($production_status !== 'live') { $old_tag = $txp_current_tag; $txp_current_tag = '<txp:' . $tag . $atts . (isset($thing) ? '>' : '/>'); trace_add($txp_current_tag); ++$txptracelevel; if ($production_status === 'debug') { maxMemUsage($txp_current_tag); } } if ($tag === 'link') { $tag = 'tpt_' . $tag; } if (maybe_tag($tag)) { $out = $tag(splat($atts), $thing); } elseif (isset($GLOBALS['pretext'][$tag])) { $out = txpspecialchars($pretext[$tag]); trigger_error(gTxt('deprecated_tag'), E_USER_NOTICE); } else { $out = ''; trigger_error(gTxt('unknown_tag'), E_USER_WARNING); } if ($production_status !== 'live') { --$txptracelevel; if (isset($thing)) { trace_add('</txp:' . $tag . '>'); } $txp_current_tag = $old_tag; } return $out; }
function textpattern() { global $pretext, $microstart, $prefs, $qcount, $qtime, $production_status, $txptrace, $siteurl, $has_article_tag; $has_article_tag = false; callback_event('textpattern'); if ($pretext['status'] == '404') { txp_die(gTxt('404_not_found'), '404'); } if ($pretext['status'] == '410') { txp_die(gTxt('410_gone'), '410'); } $html = safe_field('user_html', 'txp_page', "name='" . doSlash($pretext['page']) . "'"); if (!$html) { txp_die(gTxt('unknown_section'), '404'); } // useful for clean urls with error-handlers txp_status_header('200 OK'); trace_add('[' . gTxt('page') . ': ' . $pretext['page'] . ']'); set_error_handler("tagErrorHandler"); $pretext['secondpass'] = false; $html = parse($html); $pretext['secondpass'] = true; trace_add('[ ~~~ ' . gTxt('secondpass') . ' ~~~ ]'); $html = parse($html); // the function so nice, he ran it twice // make sure the page has an article tag if necessary if (!$has_article_tag and $production_status != 'live' and $pretext['context'] == 'article' and (!empty($pretext['id']) or !empty($pretext['c']) or !empty($pretext['q']) or !empty($pretext['pg']))) { trigger_error(gTxt('missing_article_tag', array('{page}' => $pretext['page']))); } restore_error_handler(); header("Content-type: text/html; charset=utf-8"); echo $html; if (in_array($production_status, array('debug', 'testing'))) { $microdiff = getmicrotime() - $microstart; echo n, comment('Runtime: ' . substr($microdiff, 0, 6)); echo n, comment('Query time: ' . sprintf('%02.6f', $qtime)); echo n, comment('Queries: ' . $qcount); echo maxMemUsage('end of textpattern()', 1); if (!empty($txptrace) and is_array($txptrace)) { echo n, comment('txp tag trace: ' . n . str_replace('--', '­­', join(n, $txptrace)) . n); } // '­­' is *no* tribute to Kajagoogoo, but an attempt to avoid prematurely terminating HTML comments } callback_event('textpattern_end'); }
function processTags($matches) { global $pretext, $production_status, $txptrace, $txp_current_tag; $tag = $matches[1]; $atts = isset($matches[2]) ? splat($matches[2]) : ''; $thing = isset($matches[4]) ? $matches[4] : ''; $old_tag = @$txp_current_tag; $txp_current_tag = '<txp:' . $tag . ($atts ? ' ' . $matches[2] : '') . ($thing ? '>' : ' />'); if ($production_status == 'debug') { @($txptrace[] = trim($matches[0])); maxMemUsage(trim($matches[0])); } $out = ''; if ($thing) { if (function_exists($tag)) { $out = $tag($atts, $thing, $matches[0]); } elseif (isset($pretext[$tag])) { $out = $pretext[$tag]; } else { trigger_error(gTxt('unknown_tag'), E_USER_WARNING); } } else { if (function_exists($tag)) { $out = $tag($atts, null, $matches[0]); } elseif (isset($pretext[$tag])) { $out = $pretext[$tag]; } else { trigger_error(gTxt('unknown_tag'), E_USER_WARNING); } } $txp_current_tag = $old_tag; return $out; }
function processTags($matches) { global $pretext, $production_status, $txptrace; $tag = $matches[1]; $atts = isset($matches[2]) ? splat($matches[2]) : ''; $thing = isset($matches[4]) ? $matches[4] : ''; if ($production_status == 'debug') { @($txptrace[] = trim($matches[0])); maxMemUsage(trim($matches[0])); } if ($thing) { if (function_exists($tag)) { return $tag($atts, $thing, $matches[0]); } if (isset($pretext[$tag])) { return $pretext[$tag]; } } else { if (function_exists($tag)) { return $tag($atts); } if (isset($pretext[$tag])) { return $pretext[$tag]; } } if ($production_status == 'debug') { // return unknown Tag with removed attributes return htmlspecialchars(preg_replace('#\\"[^"]*\\"#i', '"***"', $matches[0])); } }
/** * Parse a tag for attributes and hand over to the tag handler function. * * @param string $tag The tag name * @param string $atts The attribute string * @param string|null $thing The tag's content in case of container tags * @return string Parsed tag result * @package TagParser */ function processTags($tag, $atts, $thing = null) { global $production_status, $txp_current_tag, $txp_current_form; static $registry = null; if ($production_status !== 'live') { $old_tag = $txp_current_tag; $txp_current_tag = '<txp:' . $tag . $atts . (isset($thing) ? '>' : '/>'); trace_add($txp_current_tag, 1); if ($production_status === 'debug') { maxMemUsage("Form='{$txp_current_form}', Tag='{$txp_current_tag}'"); } } if ($registry === null) { $registry = Txp::get('Textpattern_Tag_Registry'); } if ($registry->isRegistered($tag)) { $out = $registry->process($tag, splat($atts), $thing); } elseif (maybe_tag($tag)) { $out = $tag(splat($atts), $thing); trigger_error(gTxt('unregistered_tag'), E_USER_NOTICE); } elseif (isset($GLOBALS['pretext'][$tag])) { $out = txpspecialchars($pretext[$tag]); trigger_error(gTxt('deprecated_tag'), E_USER_NOTICE); } else { $out = ''; trigger_error(gTxt('unknown_tag'), E_USER_WARNING); } if ($production_status !== 'live') { trace_add('', -1); if (isset($thing)) { trace_add('</txp:' . $tag . '>'); } $txp_current_tag = $old_tag; } return $out; }
/** * Trace log: Start / Display / Result values. * * @param int $flags One of TEXTPATTERN_TRACE_START | TEXTPATTERN_TRACE_DISPLAY | TEXTPATTERN_TRACE_RESULT * @return mixed * @package Debug */ function trace_log($flags = TEXTPATTERN_TRACE_RESULT) { global $production_status, $txptrace, $qtime, $qcount; static $microstart = 0; if ($flags & TEXTPATTERN_TRACE_START) { $microstart = getmicrotime(); $production_status = 'debug'; $txptrace = array(); return; } $microdiff = getmicrotime() - $microstart; $memory_peak = is_callable('memory_get_peak_usage') ? ceil(memory_get_peak_usage(true) / 1024) : '-'; if ($production_status !== 'live' && $flags & TEXTPATTERN_TRACE_DISPLAY) { echo n, comment('Runtime: ' . substr($microdiff, 0, 6)); echo n, comment('Query time: ' . sprintf('%02.6f', $qtime)); echo n, comment('Queries: ' . $qcount); echo n . comment(sprintf('Memory Peak: %sKb', $memory_peak)); echo maxMemUsage('', 1); if ($production_status === 'debug') { echo n, comment('Trace log: ' . n . 'Mem(Kb)_|_+(Kb)_|_Trace___' . n . join(n, preg_replace('/[\\r\\n]+/s', ' ', $txptrace)) . n); } } if ($flags & TEXTPATTERN_TRACE_RESULT) { return array('microdiff' => $microdiff, 'memory_peak' => $memory_peak); } }
function textpattern() { global $pretext, $microstart, $prefs, $qcount, $qtime, $production_status, $txptrace, $siteurl, $has_article_tag; $has_article_tag = false; callback_event('textpattern'); if ($pretext['status'] == '404') { txp_die(gTxt('404_not_found'), '404'); } if ($pretext['status'] == '410') { txp_die(gTxt('410_gone'), '410'); } $html = fetch_page_template($pretext['page']); if (!$html) { txp_die(gTxt('unknown_section'), '404'); } // useful for clean urls with error-handlers txp_status_header('200 OK'); trace_add('[' . gTxt('page') . ': ' . $pretext['page'] . ']'); set_error_handler("tagErrorHandler"); $pretext['secondpass'] = false; $html = parse($html); $pretext['secondpass'] = true; trace_add('[ ~~~ ' . gTxt('secondpass') . ' ~~~ ]'); $html = parse($html); // the function so nice, he ran it twice $html = $prefs['allow_page_php_scripting'] ? evalString($html) : $html; // make sure the page has an article tag if necessary if (!$has_article_tag and $production_status != 'live' and (!empty($pretext['id']) or !empty($pretext['c']) or !empty($pretext['q']) or !empty($pretext['pg']))) { trigger_error(gTxt('missing_article_tag', array('{page}' => $pretext['page']))); } restore_error_handler(); header("Content-type: text/html; charset=utf-8"); echo $html; if (in_array($production_status, array('debug', 'testing'))) { $microdiff = getmicrotime() - $microstart; echo n, comment('Runtime: ' . substr($microdiff, 0, 6)); echo n, comment('Query time: ' . $qtime); echo n, comment('Queries: ' . $qcount); echo maxMemUsage('end of textpattern()', 1); if (!empty($txptrace) and is_array($txptrace)) { echo n, comment('txp tag trace: ' . n . join(n, $txptrace) . n); } } callback_event('textpattern_end'); }
function textpattern() { global $pretext, $microstart, $prefs, $qcount, $qtime, $production_status, $txptrace, $siteurl, $has_article_tag; $has_article_tag = false; callback_event('textpattern'); if ($pretext['status'] == '404') { txp_die(gTxt('404_not_found'), '404'); } if ($pretext['status'] == '410') { txp_die(gTxt('410_gone'), '410'); } // Useful for clean URLs with error-handlers. txp_status_header('200 OK'); set_error_handler('tagErrorHandler'); $html = parse_page($pretext['page']); if ($html === false) { txp_die(gTxt('unknown_section'), '404'); } // Make sure the page has an article tag if necessary. if (!$has_article_tag and $production_status != 'live' and $pretext['context'] == 'article' and (!empty($pretext['id']) or !empty($pretext['c']) or !empty($pretext['q']) or !empty($pretext['pg']))) { trigger_error(gTxt('missing_article_tag', array('{page}' => $pretext['page']))); } restore_error_handler(); header("Content-type: text/html; charset=utf-8"); echo $html; if (in_array($production_status, array('debug', 'testing'))) { $microdiff = getmicrotime() - $microstart; echo n, comment('Runtime: ' . substr($microdiff, 0, 6)); echo n, comment('Query time: ' . sprintf('%02.6f', $qtime)); echo n, comment('Queries: ' . $qcount); echo maxMemUsage('end of textpattern()', 1); if (!empty($txptrace) and is_array($txptrace)) { echo n, comment('txp tag trace: ' . n . join(n, $txptrace) . n); } } callback_event('textpattern_end'); }