Пример #1
0
    /**
     * The function that does the actual rendering of the smarty template
     *
     * @param string $template
     */
    function parseTemplate($template)
    {
        global $PIVOTX, $build, $version, $codename, $timetaken;
        $this->maintemplate = $template;
        // Extra security measures for when we're rendering 'frontside' pages:
        $PIVOTX['template']->security = true;
        if ($PIVOTX['config']->get('allow_php_in_templates') == 1) {
            $PIVOTX['template']->security_settings['PHP_TAGS'] = true;
        }
        $allowedfunctions = explode(',', "array,addslashes,trim,ltrim,rtrim,strlen,date," . "substr,strpos,md5,nl2br,strstr,strtoupper,strtolower,ucfirst,ucwords," . "count,empty,is_array,is_object,in_array,is_int,is_float,is_integer,is_numeric," . "is_string,serialize,unserialize,isset,sizeof,true,false,stripslashes," . "encode_text,safe_string,htmlentities,htmlspecialchars,html_entity_decode," . "trimtext,round,function_exists,tag_exists,intval,basename,dirname");
        $PIVOTX['template']->security_settings['IF_FUNCS'] = $allowedfunctions;
        $PIVOTX['template']->security_settings['MODIFIER_FUNCS'] = $allowedfunctions;
        // Check if we use caching..
        if ($PIVOTX['config']->get('smarty_cache')) {
            $PIVOTX['template']->caching = true;
            $PIVOTX['template']->compile_check = true;
            $PIVOTX['template']->force_compile = false;
            $code = getDefault($this->code, "");
            $cachekey = "tpl_" . $code . substr(md5($template . ',' . implode(',', $this->modifier)), 0, 10);
            // Now, let's see if the page we want is already in the cache..
            if ($PIVOTX['template']->is_cached($template, $cachekey)) {
                // It is! We can get that, and return to the calling function..
                // But first, we check for cache_before_read hooks..
                $PIVOTX['extensions']->executeHook('cache_before_read', $template);
                $this->html = $PIVOTX['template']->fetch($template, $cachekey);
                // Before we return, we check for cache_after_read hooks..
                $PIVOTX['extensions']->executeHook('cache_after_read', $this->html);
                return;
            } else {
                // Before we continue, we check for cache_missed_read hooks..
                $PIVOTX['extensions']->executeHook('cache_missed_read', $template);
            }
        } else {
            $cachekey = "";
        }
        // If we've set the hidden config option for 'always jquery', add the hook here:
        if ($PIVOTX['config']->get('always_jquery') == 1) {
            $PIVOTX['extensions']->addHook('after_parse', 'callback', 'jqueryIncludeCallback');
        }
        // Add a favicon to the page, PiovtX or user configured, unless it's set
        // to display nothing (by using '0' as user configured favicon)
        $favicon_html = "\t<link rel=\"shortcut icon\" href=\"%s\" />\n";
        $favicon = $PIVOTX['config']->get('favicon');
        if ($favicon == '0') {
            $favicon_html = '';
        } else {
            if ($favicon == '') {
                $favicon = $PIVOTX['paths']['pivotx_url'] . "pics/favicon.ico";
            }
            $favicon_html = sprintf($favicon_html, $favicon);
        }
        // Add a hook to insert the generator meta tag and possibly a favicon link
        $PIVOTX['extensions']->addHook('after_parse', 'insert_before_close_head', "\t<meta name=\"generator\" content=\"PivotX\" /><!-- version: " . strip_tags($build) . " -->\n" . $favicon_html);
        // Output the canonical link. See:
        // http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html
        if ($PIVOTX['config']->get('dont_add_canonical') == 0) {
            // If we're at the site's root, regardless of _what_ page or blog it is,
            // we always return the site url..
            if ($this->modifier['action'] == "page" && $PIVOTX['config']->get('root') == "p:" . $this->modifier['uri'] || $this->modifier['action'] == "weblog" && $PIVOTX['config']->get('root') == "w:" . $this->modifier['uri'] || $this->modifier['uri'] == "" && $PIVOTX['config']->get('root') == "" && !isset($this->modifier['offset'])) {
                $link = "";
                // Also set $modifier.home, so we can check if we're at the homepage from the templates.
                $this->modifier['home'] = true;
            } else {
                $link = smarty_link(array('hrefonly' => true), $PIVOTX['template']);
            }
            if (isset($this->modifier['canonical_link'])) {
                $link = $this->modifier['canonical_link'];
            }
            // Set the canonical link..
            $canonical = sprintf("\t<link rel=\"canonical\" href=\"%s%s\" />\n", $PIVOTX['paths']['canonical_host'], empty($link) ? $PIVOTX['paths']['site_url'] : $link);
            $PIVOTX['extensions']->addHook('after_parse', 'insert_before_close_head', $canonical);
        }
        // Add a hook to insert the scheduler. Unless the hidden configuration option
        // 'dont_run_scheduler' is set.
        if ($PIVOTX['config']->get('dont_run_scheduler') == 0) {
            $PIVOTX['extensions']->addHook('after_parse', 'insert_before_close_body', "\t<div class='scheduler-wrapper'><img src='" . $PIVOTX['paths']['pivotx_url'] . "scheduler.php' alt='' width='0' height='0' /></div>\n");
        }
        // If we've enabled the XML Feeds for this weblog, insert the auto-discovery tags..
        if ($PIVOTX['weblogs']->get('', 'rss') == 1) {
            $feedtitle = $PIVOTX['config']->get('sitename') . ' &raquo; ' . $PIVOTX['weblogs']->get('', 'name');
            $feedtitle = encodeText($feedtitle);
            $autodiscovery = sprintf("\t<link rel=\"alternate\" type=\"application/rss+xml\" title=\"%s (%s)\" href=\"%s\" />\n", $feedtitle, __("RSS feed"), makeFeedLink("rss"));
            $autodiscovery .= sprintf("\t<link rel=\"alternate\" type=\"application/atom+xml\" title=\"%s (%s)\" href=\"%s\" />\n", $feedtitle, __("Atom feed"), makeFeedLink("atom"));
            if ($PIVOTX['config']->get('feed_posts_only') != 1) {
                $feedlink_params = array('content' => 'comments');
                $autodiscovery .= sprintf("\t<link rel=\"alternate\" type=\"application/rss+xml\" title=\"%s (%s)\" href=\"%s\" />\n", $feedtitle, __("RSS feed for comments"), makeFeedLink("rss", $feedlink_params));
                $autodiscovery .= sprintf("\t<link rel=\"alternate\" type=\"application/atom+xml\" title=\"%s (%s)\" href=\"%s\" />\n", $feedtitle, __("Atom feed for comments"), makeFeedLink("atom", $feedlink_params));
            }
            if ($this->modifier['category'] != "") {
                $feedcategory = $PIVOTX['categories']->getCategory($this->modifier['category']);
                if (count($feedcategory) > 0) {
                    $feedtitle = $PIVOTX['config']->get('sitename') . ' &raquo; ' . __('category') . ' ' . $feedcategory['display'];
                    $feedtitle = encodeText($feedtitle);
                    $feedlink_params = array('category' => $feedcategory['name']);
                    $autodiscovery = sprintf("\t<link rel=\"alternate\" type=\"application/rss+xml\" title=\"%s (%s)\" href=\"%s\" />\n", $feedtitle, __("RSS feed"), makeFeedLink("rss", $feedlink_params)) . $autodiscovery;
                    $autodiscovery = sprintf("\t<link rel=\"alternate\" type=\"application/atom+xml\" title=\"%s (%s)\" href=\"%s\" />\n", $feedtitle, __("Atom feed"), makeFeedLink("atom", $feedlink_params)) . $autodiscovery;
                }
            }
            // Add a hook to insert RSS and ATOM autodiscovery-tag
            $PIVOTX['extensions']->addHook('after_parse', 'insert_before_close_head', $autodiscovery);
        }
        // If we've enabled XML-RPC / the MetaWeblog API, insert the auto-discovery tags...
        if ($PIVOTX['config']->get('xmlrpc') == 1) {
            $autodiscovery = sprintf("\t<link rel=\"EditURI\" type=\"application/rsd+xml\" title=\"RSD\" href=\"%s\" />\n", makeRSDLink());
            // Add a hook to insert XML-RPC / the MetaWeblog API autodiscovery-tag
            $PIVOTX['extensions']->addHook('after_parse', 'insert_before_close_head', $autodiscovery);
        }
        // If we've enabled (non-hardened) trackback, insert the auto-discovery tags...
        if ($PIVOTX['config']->get('trackbacks') == 1 && $PIVOTX['config']->get('hardened_trackback') != 1) {
            $autodiscovery = <<<EOM
<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description
rdf:about="%url%"
dc:identifier="%url%"
dc:title="%title%"
trackback:ping="%tb-url%" />
</rdf:RDF> -->
EOM;
            $url = $PIVOTX['paths']['host'] . makeFilelink($PIVOTX['db']->entry['code'], '', '');
            if ($PIVOTX['config']->get('mod_rewrite') == 0) {
                $tb_url = $url . '&amp;trackback';
            } else {
                $tb_url = $url . '/trackback/';
            }
            $autodiscovery = str_replace("%url%", $url, $autodiscovery);
            $autodiscovery = str_replace("%title%", $PIVOTX['db']->entry['title'], $autodiscovery);
            $autodiscovery = str_replace("%tb-url%", $tb_url, $autodiscovery);
            // Add a hook to insert XML-RPC / the MetaWeblog API autodiscovery-tag
            $PIVOTX['extensions']->addHook('after_parse', 'insert_before_close_head', $autodiscovery);
        }
        // Assign some stuff to $smarty, so it's accessible from the templates.
        $PIVOTX['template']->assign('build', $build);
        $PIVOTX['template']->assign('version', $version);
        $PIVOTX['template']->assign('codename', $codename);
        $PIVOTX['template']->assign('config', $PIVOTX['config']->getConfigArray());
        $PIVOTX['template']->assign('weblogs', $PIVOTX['weblogs']->getWeblogs());
        $PIVOTX['template']->assign('paths', $PIVOTX['paths']);
        $PIVOTX['template']->assign('modifier', $this->modifier);
        $PIVOTX['template']->assign('timetaken', timeTaken());
        $PIVOTX['template']->assign('memtaken', getMem());
        $PIVOTX['template']->assign('query_count', $timetaken['query_count']);
        // If we've set the hidden config option for 'set_request_variables', set them..
        if ($PIVOTX['config']->get('set_request_variables') == 1) {
            $PIVOTX['template']->assign('get', $_GET);
            $PIVOTX['template']->assign('post', $_POST);
            $PIVOTX['template']->assign('request', $_REQUEST);
            $PIVOTX['template']->assign('server', $_SERVER);
            $PIVOTX['template']->assign('session', $_SESSION);
        }
        // Add the 'base part' of the path to the smarty variables as well
        $PIVOTX['template']->assign('templatedir', dirname($template));
        if (file_exists($PIVOTX['paths']['templates_path'] . $template)) {
            // Execute a hook, if present.
            $PIVOTX['extensions']->executeHook('during_parse', $template);
        } else {
            // hmm, template doesn't exist, so we set it to our '404' template..
            $template = "";
            // Execute a hook, if present.
            $PIVOTX['extensions']->executeHook('during_parse', $template);
            if ($template == "") {
                $template = "404.html";
                // TODO: what will be our 404 template?
            }
        }
        if ($PIVOTX['config']->get('smarty_cache')) {
            // Before we continue, we check for cache_before_write hooks..
            $PIVOTX['extensions']->executeHook('cache_before_write', $template);
        }
        $this->html = $PIVOTX['template']->fetch($template, $cachekey);
        // We're going to something really, really stupid here. If we've enabled
        // caching, and we've just written to the cache, we immediately get
        // the page from the cache again, because the copy that's in memory does
        // not have the HTML that's updated with our hooks. Thankfully this step
        // is really, really fast, because we use caching. :-)
        if ($PIVOTX['config']->get('smarty_cache')) {
            $this->html = $PIVOTX['template']->fetch($template, $cachekey);
            // Before we continue, we check for cache_after_write hooks..
            $PIVOTX['extensions']->executeHook('cache_after_write', $this->html);
        }
    }
Пример #2
0
            // Skip "PRAGMA .." queries by SQLITE.
            if (strpos($query['sql'], "PRAGMA ") === 0) {
                continue;
            }
            $queries[] = array('query' => $query['sql'], 'params' => $query['params'], 'types' => $query['types'], 'duration' => sprintf("%0.2f", $query['executionMS']));
            $querycount++;
            $querytime += $query['executionMS'];
        }
        $twig = $app['twig.loader'];
        $templates = hackislyParseRegexTemplates($twig);
        $route = $request->get('_route');
        $route_params = $request->get('_route_params');
        $log = $app['log']->getMemorylog();
        // echo "<pre>\n" . util::var_dump($log, true) . "</pre>\n";
        $servervars = array('cookies <small>($_COOKIES)</small>' => $request->cookies->all(), 'headers' => makeValuepairs($request->headers->all(), '', '0'), 'query <small>($_GET)</small>' => $request->query->all(), 'request <small>($_POST)</small>' => $request->request->all(), 'session <small>($_SESSION)</small>' => $request->getSession()->all(), 'server <small>($_SERVER)</small>' => $request->server->all(), 'response' => makeValuepairs($response->headers->all(), '', '0'), 'statuscode' => $response->getStatusCode());
        echo $app['twig']->render('debugbar.twig', array('timetaken' => timeTaken(), 'memtaken' => getMem(), 'memtaken' => getMaxMem(), 'querycount' => $querycount, 'querytime' => sprintf("%0.2f", $querytime), 'queries' => $queries, 'servervars' => $servervars, 'templates' => $templates, 'log' => $log, 'route' => "/" . $route, 'route_params' => $route_params, 'editlink' => $app['editlink'], 'paths' => getPaths($app['config'])));
    });
}
$app->after(function (Request $request, Response $response) use($app) {
    $end = !empty($app['end']) ? $app['end'] : false;
    if ($end == "frontend") {
        $html = $response->getContent();
        // Insert our 'generator' after the last <meta ..> tag.
        $app['extensions']->insertSnippet('aftermeta', '<meta name="generator" content="Bolt">');
        $html = $app['extensions']->processSnippetQueue($html);
        $response->setContent($html);
    }
});
/**
 * Error page.
 */
Пример #3
0
$zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-38.jpg"), "images/rossi-perfectisboring-38.jpg");
$f .= "\r\n38: " . getMem();
$zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-39.jpg"), "images/rossi-perfectisboring-39.jpg");
$f .= "\r\n39: " . getMem();
$zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-40.jpg"), "images/rossi-perfectisboring-40.jpg");
$f .= "\r\n40: " . getMem();
$zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-41.jpg"), "images/rossi-perfectisboring-41.jpg");
$f .= "\r\n41: " . getMem();
$zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-42.jpg"), "images/rossi-perfectisboring-42.jpg");
$f .= "\r\n42: " . getMem();
$zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-43.jpg"), "images/rossi-perfectisboring-43.jpg");
$f .= "\r\n43: " . getMem();
$zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-44.jpg"), "images/rossi-perfectisboring-44.jpg");
$f .= "\r\n44: " . getMem();

$f .= "\r\n\r\nFinal:" . getMem();

$zip->addFile($f, "mem.txt");
$rv = $zip->finalize();

// If non-fatal errors occurred during execution, this will append them
//  to the end of the generated file.
// It'll create an invalid Zip file, however chances are that it is invalid
//  already due to the error happening in the first place.
// The idea is that errors will be very easy to spot.
if (!empty($errors)) {
	echo "\n<pre>\n**************\n*** ERRORS ***\n**************\n\n$errors\n</pre>\n";
}

function getMem() {
    global $tLast;