Beispiel #1
0
function qa_load_override_files()
{
    global $qa_override_files, $qa_overrides;
    $functionindex = array();
    foreach ($qa_override_files as $index => $override) {
        $filename = $override['directory'] . $override['include'];
        $functionsphp = file_get_contents($filename);
        preg_match_all('/\\Wfunction\\s+(qa_[a-z_]+)\\s*\\(/im', $functionsphp, $rawmatches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
        $reversematches = array_reverse($rawmatches[1], true);
        // reverse so offsets remain correct as we step through
        $postreplace = array();
        $suffix = '_in_' . preg_replace('/[^A-Za-z0-9_]+/', '_', basename($override['include']));
        // include file name in defined function names to make debugging easier if there is an error
        foreach ($reversematches as $rawmatch) {
            $function = strtolower($rawmatch[0]);
            $position = $rawmatch[1];
            if (isset($qa_overrides[$function])) {
                $postreplace[$function . '_base'] = $qa_overrides[$function];
            }
            $newname = $function . '_override_' . @++$functionindex[$function] . $suffix;
            $functionsphp = substr_replace($functionsphp, $newname, $position, strlen($function));
            $qa_overrides[$function] = $newname;
        }
        foreach ($postreplace as $oldname => $newname) {
            if (preg_match_all('/\\W(' . preg_quote($oldname) . ')\\s*\\(/im', $functionsphp, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE)) {
                $searchmatches = array_reverse($matches[1]);
                foreach ($searchmatches as $searchmatch) {
                    $functionsphp = substr_replace($functionsphp, $newname, $searchmatch[1], strlen($searchmatch[0]));
                }
            }
        }
        //	echo '<pre style="text-align:left;">'.htmlspecialchars($functionsphp).'</pre>'; // to debug munged code
        qa_eval_from_file($functionsphp, $filename);
    }
}
Beispiel #2
0
function qa_load_theme_class($theme, $template, $content, $request)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    global $qa_layers;
    //	First load the default class
    require_once QA_INCLUDE_DIR . 'qa-theme-base.php';
    $classname = 'qa_html_theme_base';
    //	Then load the selected theme if valid, otherwise load the Classic theme
    if (!file_exists(QA_THEME_DIR . $theme . '/qa-styles.css')) {
        $theme = 'Classic';
    }
    $themeroothtml = qa_html(qa_path_to_root() . 'qa-theme/' . $theme . '/');
    if (file_exists(QA_THEME_DIR . $theme . '/qa-theme.php')) {
        require_once QA_THEME_DIR . $theme . '/qa-theme.php';
        if (class_exists('qa_html_theme')) {
            $classname = 'qa_html_theme';
        }
    }
    //	Create the list of layers to load
    $loadlayers = $qa_layers;
    if (!qa_user_maximum_permit_error('permit_view_voters_flaggers')) {
        $loadlayers[] = array('directory' => QA_INCLUDE_DIR . 'plugins/', 'include' => 'qa-layer-voters-flaggers.php', 'urltoroot' => null);
    }
    //	Then load any theme layers using some class-munging magic (substitute class names)
    $layerindex = 0;
    foreach ($loadlayers as $layer) {
        $filename = $layer['directory'] . $layer['include'];
        $layerphp = file_get_contents($filename);
        if (strlen($layerphp)) {
            $newclassname = 'qa_layer_' . ++$layerindex . '_from_' . preg_replace('/[^A-Za-z0-9_]+/', '_', basename($layer['include']));
            // include file name in layer class name to make debugging easier if there is an error
            if (preg_match('/\\s+class\\s+qa_html_theme_layer\\s+extends\\s+qa_html_theme_base\\s+/im', $layerphp) != 1) {
                qa_fatal_error('Class for layer must be declared as "class qa_html_theme_layer extends qa_html_theme_base" in ' . $layer['directory'] . $layer['include']);
            }
            $searchwordreplace = array('qa_html_theme_base::qa_html_theme_base' => $classname . '::__construct', 'parent::qa_html_theme_base' => 'parent::__construct', 'qa_html_theme_layer' => $newclassname, 'qa_html_theme_base' => $classname, 'QA_HTML_THEME_LAYER_DIRECTORY' => "'" . $layer['directory'] . "'", 'QA_HTML_THEME_LAYER_URLTOROOT' => "'" . qa_path_to_root() . $layer['urltoroot'] . "'");
            foreach ($searchwordreplace as $searchword => $replace) {
                if (preg_match_all('/\\W(' . preg_quote($searchword, '/') . ')\\W/im', $layerphp, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE)) {
                    $searchmatches = array_reverse($matches[1]);
                    // don't use preg_replace due to complication of escaping replacement phrase
                    foreach ($searchmatches as $searchmatch) {
                        $layerphp = substr_replace($layerphp, $replace, $searchmatch[1], strlen($searchmatch[0]));
                    }
                }
            }
            //	echo '<pre style="text-align:left;">'.htmlspecialchars($layerphp).'</pre>'; // to debug munged code
            qa_eval_from_file($layerphp, $filename);
            $classname = $newclassname;
        }
    }
    //	Finally, instantiate the object
    $themeclass = new $classname($template, $content, $themeroothtml, $request);
    return $themeclass;
}