Пример #1
0
 public static function IncludeFile($path)
 {
     // if running ALERT: CANNOT BE CALLED AT RUN TIME
     if (!file_exists($path)) {
         $path = utopia::GetAbsolutePath($path);
     }
     if (!file_exists($path)) {
         return;
     }
     self::$includeFiles[] = $path;
 }
Пример #2
0
 public static function OutputTemplate()
 {
     uEvents::TriggerEvent('BeforeOutputTemplate');
     if (!self::UsingTemplate()) {
         ob_end_clean();
         echo utopia::GetVar('content');
         return;
     }
     if (isset($_GET['inline']) && !is_numeric($_GET['inline'])) {
         $_GET['inline'] = 0;
     }
     if (self::UsingTemplate(TEMPLATE_BLANK) || isset($_GET['inline']) && $_GET['inline'] == 0) {
         $template = utopia::GetVar('content');
     } else {
         $tCount = -1;
         // do all by default
         if (isset($_GET['inline'])) {
             $tCount = $_GET['inline'] - 1;
         }
         $template = '';
         $css = self::GetTemplateCSS();
         foreach ($css as $cssfile) {
             uCSS::LinkFile($cssfile);
         }
         // first get list of parents
         $templates = array();
         $templateDir = utopia::GetTemplateDir(true);
         if (!file_exists($templateDir)) {
             $templateDir = utopia::GetAbsolutePath($templateDir);
         }
         if (file_exists($templateDir)) {
             $templates[] = $templateDir;
         }
         while ($tCount-- && file_exists($templateDir . '/template.ini')) {
             $inifile = parse_ini_file($templateDir . '/template.ini');
             if (!isset($inifile['parent'])) {
                 break;
             }
             if (file_exists(PATH_ABS_ROOT . $inifile['parent'])) {
                 $templateDir = PATH_ABS_ROOT . $inifile['parent'];
             } else {
                 $templateDir = dirname($templateDir) . '/' . $inifile['parent'];
             }
             $templates[] = $templateDir;
         }
         foreach ($templates as $templateDir) {
             // set templatedir
             self::SetVar('templatedir', self::GetRelativePath($templateDir));
             $templatePath = $templateDir . '/template.php';
             $template = get_include_contents($templatePath);
             // mergevars
             while (self::MergeVars($template)) {
             }
             // setvar
             self::SetVar('content', $template);
         }
         if (!$template) {
             $template = '{utopia.content}';
         }
     }
     ob_end_clean();
     while (self::MergeVars($template)) {
     }
     $template = str_replace('<head>', '<head>' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>', $template);
     // Make all resources secure
     if (self::IsRequestSecure()) {
         $template = str_replace('http://' . self::GetDomainName(), 'https://' . self::GetDomainName(), $template);
     }
     do {
         if (self::UsingTemplate() && class_exists('DOMDocument')) {
             libxml_use_internal_errors(true);
             $doc = new DOMDocument();
             $doc->formatOutput = false;
             $doc->preserveWhiteSpace = true;
             $doc->validateOnParse = true;
             if (!$doc->loadHTML('<?xml encoding="UTF-8">' . utf8_decode($template))) {
                 break;
             }
             $isSnip = stripos($template, '<html') === false;
             $doc->encoding = 'UTF-8';
             // no html tag?  break out.
             if (!$doc->getElementsByTagName('html')->length) {
                 break;
             }
             // remove multiple xmlns attributes
             $doc->documentElement->removeAttributeNS(NULL, 'xmlns');
             // assert BODY tag
             if (!$doc->getElementsByTagName('body')->length) {
                 $node = $doc->createElement("body");
                 $doc->getElementsByTagName('html')->item(0)->appendChild($node);
             }
             // assert HEAD tag
             if (!$doc->getElementsByTagName('head')->length) {
                 // create head node
                 $node = $doc->createElement("head");
                 $body = $doc->getElementsByTagName('body')->item(0);
                 $newnode = $body->parentNode->insertBefore($node, $body);
             }
             // add HEAD children
             $head = $doc->getElementsByTagName('head')->item(0);
             // set title
             if (!$head->getElementsByTagName('title')->length) {
                 $node = $doc->createElement('title');
                 $node->appendChild($doc->createTextNode(utopia::GetTitle(true)));
                 $head->appendChild($node);
             }
             if (utopia::GetDescription(true)) {
                 $node = $doc->createElement('meta');
                 $node->setAttribute('name', 'description');
                 $node->setAttribute('content', utopia::GetDescription(true));
                 $head->appendChild($node);
             }
             if (utopia::GetKeywords(true)) {
                 $node = $doc->createElement('meta');
                 $node->setAttribute('name', 'keywords');
                 $node->setAttribute('content', utopia::GetKeywords(true));
                 $head->appendChild($node);
             }
             $node = $doc->createElement('meta');
             $node->setAttribute('name', 'generator');
             $node->setAttribute('content', 'uCore PHP Framework');
             $head->appendChild($node);
             // template is all done, now lets run a post process event
             try {
                 uEvents::TriggerEvent('ProcessDomDocument', null, array(&$doc));
             } catch (Exception $e) {
                 uErrorHandler::EchoException($e);
             }
             $ctNode = null;
             foreach ($head->getElementsByTagName('meta') as $meta) {
                 if ($meta->hasAttribute('http-equiv') && strtolower($meta->getAttribute('http-equiv')) == 'content-type') {
                     $ctNode = $meta;
                     break;
                 }
             }
             if (!$ctNode) {
                 $ctNode = $doc->createElement('meta');
                 $head->appendChild($ctNode);
             }
             $ctNode->setAttribute('http-equiv', 'content-type');
             $ctNode->setAttribute('content', 'text/html;charset=' . CHARSET_ENCODING);
             if ($ctNode !== $head->firstChild) {
                 $head->insertBefore($ctNode, $head->firstChild);
             }
             $doc->normalizeDocument();
             if (strpos(strtolower($doc->doctype->publicId), ' xhtml ')) {
                 $template = $doc->saveXML();
             } else {
                 $template = $doc->saveHTML();
             }
             $template = preg_replace('/<\\?xml encoding="UTF-8"\\??>\\n?/i', '', $template);
             if ($isSnip && !self::$noSnip) {
                 $template = preg_replace('/.*<body[^>]*>\\s*/ims', '', $template);
                 // remove everything up to and including the body open tag
                 $template = preg_replace('/\\s*<\\/body>.*/ims', '', $template);
                 // remove everything after and including the body close tag
             }
         }
     } while (false);
     while (self::MergeVars($template)) {
     }
     if (isset($_GET['callback'])) {
         $output = json_encode(array('title' => self::GetTitle(true), 'content' => $template));
         header('Content-Type: application/javascript');
         echo $_GET['callback'] . '(' . $output . ')';
         return;
     }
     echo $template;
 }
Пример #3
0
 public static function IncludeFile($path, $order = NULL)
 {
     // if running ALERT: CANNOT BE CALLED AT RUN TIME
     if (!file_exists($path)) {
         $path = utopia::GetAbsolutePath($path);
     }
     if (!file_exists($path)) {
         return;
     }
     if ($order === null) {
         $order = count(self::$includeFiles);
     }
     self::$includeFiles[] = array('path' => $path, 'order' => $order);
 }