Beispiel #1
0
 /**
 * Module tag parsing
 *
 * Used to include other object-modules in current workspace
 *
 * @access private
 * @param string $res template strings
 * @param array $hash data params
 * @param string $dir current template directory (for correct [#inc ...#] tags parsing)
 */
 function parseModules(&$res, &$hash, $dir)
 {
     global $md;
     global $inst;
     $instance = $inst;
     if (preg_match_all('/\\[#module (.*?)#\\]/', $res, $matches, PREG_PATTERN_ORDER)) {
         $count_matches_0 = count($matches[0]);
         for ($i = 0; $i < $count_matches_0; $i++) {
             $data = $matches[1][$i];
             $tmp = "";
             // reading module data from module including directive
             $module_data = array();
             if (preg_match_all('/(\\w+?)="(.*?)"/i', $data, $matches1, PREG_PATTERN_ORDER)) {
                 $count_matches1_0 = count($matches1[0]);
                 for ($k = 0; $k < $count_matches1_0; $k++) {
                     $key = $matches1[1][$k];
                     $value = $matches1[2][$k];
                     if ($key == "template") {
                         $value = $dir . $value;
                     }
                     $module_data[$key] = $value;
                 }
             }
             if (file_exists(DIR_MODULES . $module_data["name"] . '/' . $module_data["name"] . ".class.php") || class_exists($module_data["name"])) {
                 // including module class
                 if (!class_exists($module_data["name"])) {
                     include_once DIR_MODULES . $module_data["name"] . '/' . $module_data["name"] . ".class.php";
                 }
                 // creating code for module creation and running
                 $obj = "\$object{$i}";
                 $code = "";
                 $code .= "{$obj}=new " . $module_data["name"] . ";\n";
                 $code .= $obj . "->owner=&\$this->owner;\n";
                 // setting module parameters from module including directive
                 foreach ($module_data as $k => $v) {
                     if ($k == "name") {
                         continue;
                     }
                     $code .= $obj . "->" . $k . "='" . addslashes($v) . "';\n";
                 }
                 // setting other module parameters
                 // if current request is to this module, then run get params otherwise get params from encoded query
                 if ($md != $module_data["name"] || $module_data["instance"] != '' && $module_data["instance"] != $instance && $instance != '') {
                     // restoring module params from coded string (module should not overwrite this method)
                     $code .= $obj . "->restoreParams();\n";
                 } elseif ($module_data["name"] == $md && ($module_data["instance"] == '' || $module_data["instance"] == $instance || $instance == '')) {
                     // getting module params from query string (every module should handle this method)
                     $code .= $obj . "->getParams();\n";
                 }
                 // repeating module set parameters for security reasons
                 foreach ($module_data as $k => $v) {
                     if ($k == "name") {
                         continue;
                     }
                     $code .= $obj . "->" . $k . "='" . addslashes($v) . "';\n";
                 }
                 StartMeasure("module_" . $module_data["name"]);
                 if (SETTINGS_SITE_LANGUAGE && file_exists(ROOT . 'languages/' . $module_data["name"] . '_' . SETTINGS_SITE_LANGUAGE . '.php')) {
                     include_once ROOT . 'languages/' . $module_data["name"] . '_' . SETTINGS_SITE_LANGUAGE . '.php';
                 }
                 if (file_exists(ROOT . 'languages/' . $module_data["name"] . '_default.php')) {
                     include_once ROOT . 'languages/' . $module_data["name"] . '_default.php';
                 }
                 // run module and insert module result in template
                 $code .= $obj . "->run();\n";
                 $code .= "\$tmp=" . $obj . "->result;\n";
                 eval($code);
                 EndMeasure("module_" . $module_data["name"]);
             } else {
                 // module class file was not found
                 global $current_installing_module;
                 $rep_ext = '';
                 if (preg_match('/\\.dev/is', $_SERVER['HTTP_HOST'])) {
                     $rep_ext = '.dev';
                     $install_dir = "/var/projects/repository/engine_2.x/modules/";
                 }
                 if (preg_match('/\\.jbk/is', $_SERVER['HTTP_HOST'])) {
                     $rep_ext = '.jbk';
                     $install_dir = "d:/jey/projects/repository/engine_2.x/modules/";
                 }
                 if (!$current_installing_module[$module_data["name"]] && $rep_ext != '' && @Is_Dir($install_dir . $module_data["name"])) {
                     //$tmp="<div><iframe src=\"http://installer.dev/installer.php?host=".$_SERVER['HTTP_HOST']."&doc_root=".$_SERVER['DOCUMENT_ROOT']."&mode=install&modules[]=".$module_data["name"]."\" width=100% height=100></iframe></div>";
                     $wnd_name = "win" . rand(1, 10000000);
                     $tmp = "<script language='javascript' type='text/JavaScript'>wnd=window.open(\"http://installer" . $rep_ext . "/installer.php?host=" . $_SERVER['HTTP_HOST'] . "&doc_root=" . $_SERVER['DOCUMENT_ROOT'] . "&mode=install&modules[]=" . $module_data["name"] . "\", \"" . $wnd_name . "\", \"height=400,width=400\");</script>";
                     $current_installing_module[$module_data["name"]] = 1;
                     echo $tmp;
                 } else {
                     $tmp = "<p align=center><font color='red'><b>Module \"" . $module_data["name"] . "\" not found</b> (" . str_replace('#', '', $matches[0][$i]) . ")</font></p>";
                 }
             }
             //echo $matches[0][$i];
             //echo htmlspecialchars($tmp)."\n\n";
             $res = str_replace($matches[0][$i], $tmp, $res);
         }
     }
 }
Beispiel #2
0
/**
* Report builder
*
* Printing report for all blocks
*
* @param boolean $hidden n/a
*/
function PerformanceReport($hidden = 1)
{
    global $perf_data;
    echo "<!-- BEGIN PERFORMANCE REPORT\n";
    foreach ($perf_data as $k => $v) {
        if (!$v['NUM']) {
            EndMeasure($k);
        }
    }
    foreach ($perf_data as $k => $v) {
        if ($perf_data['TOTAL']['TIME']) {
            $v['PROC'] = (int) ($v['TIME'] / $perf_data['TOTAL']['TIME'] * 100 * 100) / 100;
        }
        $rs = "{$k} (" . $v['NUM'] . "): " . round($v['TIME'], 4) . " " . round($v['PROC'], 2) . "%";
        if ($v['MEMORY_START']) {
            $rs .= ' M (s): ' . $v['MEMORY_START'] . 'b';
        }
        if ($v['MEMORY_END']) {
            $rs .= ' M (e): ' . $v['MEMORY_END'] . 'b';
        }
        if (!$v['NUM']) {
            $tmp[] = "Not finished {$k}";
        }
        $tmp[] = $rs;
    }
    echo implode("\n", $tmp);
    echo "\n END PERFORMANCE REPORT -->";
}