コード例 #1
0
 /**
  * Reads given template file contents.
  * It prepares it for filling.
  * It fills it with template variables values provided.
  * It does special HTML formatting if needed, e.g. draw red debug template frames.
  *
  *
  * @param string $folder_name Template file path: full folder path.
  * @param string $tmpl_short_filename Template file path: file name.
  * @param arrat $vars Template variables values.
  * @return string template html contents with tags replaced with their values.
  */
 function fill($folder_name, $tmpl_short_filename, $vars, $customer_zone = false)
 {
     //Open file, read contents, replace tags.
     $this->PreviousTemplateFilename = $this->CurrentTemplateFilename;
     if ($customer_zone) {
         $this->CurrentTemplateFilename = getTemplateFileAbsolutePath($this->TemplateDirPrefix . $folder_name . $tmpl_short_filename);
     } else {
         $this->CurrentTemplateFilename = $this->TemplateDirPrefix . $folder_name . "views/admin/templates/" . $tmpl_short_filename;
         if (!is_file($this->CurrentTemplateFilename)) {
             $this->CurrentTemplateFilename = $this->TemplateDirPrefix . $folder_name . $tmpl_short_filename;
         }
         if (!is_file($this->CurrentTemplateFilename)) {
             $this->CurrentTemplateFilename = modApiFunc('application', 'getAppIni', 'PATH_ADMIN_TPLS_VIEWS') . $folder_name . $tmpl_short_filename;
         }
     }
     $code_to_include = $this->getCachedCode($this->CurrentTemplateFilename);
     if ($code_to_include === null) {
         $tpl_file = new CFile($this->CurrentTemplateFilename);
         $code_to_include = $tpl_file->getContent();
         //                        ,                                                (        > 128)
         $code_to_include = convertTemplate($code_to_include);
         if ($code_to_include === FALSE) {
             CTrace::backtrace();
             _fatal("TMPL_FILLER_ERROR_CANNOT_READ_FILE", $this->CurrentTemplateFilename);
         }
         $code_to_include = '?>' . $this->removeTemplateWrapper($code_to_include);
         $this->saveInCache($this->CurrentTemplateFilename, $code_to_include);
     }
     $text = $this->includeTmplCode($code_to_include);
     $_vars = array();
     foreach ($vars as $key => $value) {
         $_vars['{' . $key . '}'] = $value;
     }
     $text = strtr($text, $_vars);
     $text = $this->addCrossSiteProtectinField($text);
     return $text;
 }
コード例 #2
0
/**
 * The global function to generate the fatal error.
 *
 * <code>
 * _fatal(string $code [, mixed $var1 [, mixed $var2 [, ...]]])
 * </code>
 * Error code $code and a certain number of variables are passed in
 * the function. They are inserted to the text of the error message,
 * which matches the error code. Error codes and their texts are stored
 * in the resource files templates/resources/<module_name>.ini
 *
 * @see Resource
 * @see _warning()
 * @ function is not completed
 * @access public
 * @return
 */
function _fatal($msg)
{
    global $application, $zone;
    $numargs = func_num_args();
    $listargs = func_get_args();
    $args = array();
    if ($numargs > 1) {
        for ($i = 1; $i < $numargs; $i++) {
            $args['{' . ($i - 1) . '}'] = $listargs[$i];
        }
    }
    if (isset($application)) {
        $lang = _ml_strtolower($application->getAppIni('LANGUAGE'));
        if (!isset($lang) || $lang == '') {
            $lang = 'eng';
        }
        $path = $application->getAppIni('PATH_ADMIN_RESOURCES');
        $filename = 'system-messages-' . $lang . '.ini';
        $messages_resources = @_parse_ini_file($path . $filename);
    }
    if (isset($listargs[0]["CODE"])) {
        // Code
        $err_code = $listargs[0]["CODE"];
    }
    if (isset($listargs[0]["MODULE"])) {
        // Module
        $err_module = $listargs[0]["MODULE"];
    }
    if (isset($listargs[0]["DIRECTIVE"])) {
        // Directive
        $err_directive = $listargs[0]["DIRECTIVE"];
    }
    if (isset($listargs[0]["SECTION"])) {
        // Section
        $err_section = $listargs[0]["SECTION"];
    }
    if (isset($listargs[0]["FILE"])) {
        // File
        $err_file = $listargs[0]["FILE"];
    } elseif (isset($listargs[0]["file"])) {
        $err_file = $listargs[0]["file"];
    }
    if (isset($listargs[0]["LINE"])) {
        // Line
        $err_line = $listargs[0]["LINE"];
    } elseif (isset($listargs[0]["line"])) {
        $err_line = $listargs[0]["line"];
    }
    if (isset($listargs[0]["MESSAGE"])) {
        // Message
        $err_message = $listargs[0]["MESSAGE"];
    } elseif (isset($messages_resources[$listargs[0]["CODE"]])) {
        $err_message = strtr($messages_resources[$listargs[0]["CODE"]], $args);
    } elseif (isset($listargs[0]["message"])) {
        $err_message = $listargs[0]["message"];
    }
    CTrace::err('Fatal Error: ' . (isset($zone) ? $zone : 'Unspecified Zone') . "\n" . (isset($err_code) ? "Code = {$err_code}\n" : '') . (isset($err_module) ? "Module = {$err_module}\n" : '') . "Referer = " . $_SERVER['PHP_SELF'] . "\n" . (isset($err_file) ? "File = {$err_file}\n" : '') . (isset($err_line) ? "Line = {$err_line}\n" : '') . (isset($err_message) ? "Message = {$err_message}" : ''));
    CTrace::backtrace();
    if (isset($zone) && $zone == 'CustomerZone' && isset($application)) {
        header("location:" . $application->appIni['SITE_URL'] . "internal-server-error.html", TRUE, 307);
        die;
    } elseif (isset($zone) && $zone == 'CustomerZone') {
        header("location:internal-server-error.html", TRUE, 307);
        die;
    }
    if (is_array($listargs[0])) {
        if (isset($listargs[0])) {
            $header = "<!DOCTYPE HTML>\n";
            $header .= "<HTML><HEAD><TITLE>Tags Errors and Warnings</TITLE>";
            $header .= "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">\n";
            $header .= "<LINK HREF=\"../../includes/bootstrap/css/bootstrap.min.css\" TYPE=\"text/css\" REL=\"stylesheet\">\n";
            $header .= "</HEAD><BODY><DIV class='container'><br /><br /><br /><br />\n";
            $subtitle = "<div class='alert alert-danger'><h1>%s</h1>\n";
            $subtitle .= "<strong>Error Code:</strong> %s</div>\n";
            $tablecontent = "%s<br /><br />\n";
            $tablecontent .= "%s\n";
            $source_line = "<strong>%s</strong>\n";
            $source_line .= "%s<br />\n";
            $output = $header;
            $source = "";
            if (isset($err_file)) {
                $source .= sprintf($source_line, "File:", $err_file);
            }
            if (isset($err_line)) {
                $source .= sprintf($source_line, "Line:", $err_line);
            }
            if (isset($err_section)) {
                $source .= sprintf($source_line, "Section:", "[" . $err_section . "]");
            }
            if (isset($err_directive)) {
                $source .= sprintf($source_line, "Directive:", $err_directive);
            }
            if (isset($err_module)) {
                $source .= sprintf($source_line, "Module:", $err_module);
            }
            if (isset($err_message)) {
                $source .= sprintf($source_line, "Message:", $err_message);
            }
            $content = sprintf($tablecontent, $listargs[0]["CODE"], $source);
            $output .= sprintf($subtitle, "FATAL Core Error", $content);
            $footer = "</DIV></BODY></HTML>";
            $output .= $footer;
            die($output);
        } else {
            die(print_r($listargs[0], true));
        }
    } else {
        $msg = '';
        foreach ($listargs as $a) {
            $msg .= $a . "<br>\n";
        }
        die('<B><FONT COLOR="red">FATAL ERROR</FONT></B><br> ' . $msg);
    }
}
コード例 #3
0
 function prepareTemplateToFill($tmpl_file)
 {
     $cache_result = $this->prepared_template_cache->read($tmpl_file);
     if ($cache_result !== null) {
         return $cache_result;
     } else {
         //Open file, read contents, replace tags.
         $this->CurrentTemplateFilename = $tmpl_file;
         $tpl_file = new CFile($this->CurrentTemplateFilename);
         $text = $tpl_file->getContent();
         if ($text === FALSE) {
             CTrace::backtrace();
             _fatal("TMPL_FILLER_ERROR_CANNOT_READ_FILE", $this->CurrentTemplateFilename);
         }
         $text = $this->removeTemplateWrapper($text);
         // find and modify all the image references.
         // for customer zone only
         $zone = modApiFunc('Users', 'getZone');
         if ($zone == 'CustomerZone') {
             $text = $this->replaceImages($text);
         }
         $this->prepared_template_cache->write($tmpl_file, $text);
         return $text;
     }
 }