Exemplo n.º 1
0
 private static function parse($path)
 {
     $path = trim($path);
     $libmodules = array();
     if (file_exists($path)) {
         convertXmlObjToArr($xml = simplexml_load_file($path), $structure);
     } else {
         throw new Exception('[' . $path . '] cant be loaded');
     }
     $i = 0;
     foreach ($structure[0]['@children'] as $children) {
         if (in_array($children['@name'], array('stylesheet', 'javascript'))) {
             self::$data[$children['@name']][] = $children['@attributes'];
         } else {
             if (in_array($children['@name'], array('layout'))) {
                 self::$data[$children['@name']]['file'] = $children['@attributes']['file'];
             } else {
                 if (in_array($children['@name'], array('role'))) {
                     self::$data[$children['@name']]['need'] = $children['@attributes']['need'];
                 } else {
                     self::$data[$children['@name']] = $children['@text'];
                 }
             }
         }
     }
     if (isset(self::$data['role']['need'])) {
         Error::CheckThrowAuth(self::$data['role']['need']);
     }
     // вынимаем модули
     $i = 0;
     $j = 0;
     foreach ($structure[1]['@children'] as $data) {
         $container = $data['@name'];
         foreach ($data['@children'] as $module) {
             $i++;
             $libmodules[$i] = $module['@attributes'];
             $libmodules[$i]['container'] = $container;
             if (isset($module['@children'])) {
                 foreach ($module['@children'] as $param) {
                     if ($param['@name'] == 'param') {
                         $libmodules[$i]['params'][$j++] = $param['@attributes'];
                     }
                 }
             }
         }
     }
     //navigations
     if (isset($structure[2])) {
         /* @var $xml SimpleXMLElement */
         $dom = new DOMDocument();
         self::$navigations_string = $xml->navigations->asXML();
         $dom->loadXML(self::$navigations_string);
         self::$navigations = $dom->getElementsByTagName('navigations')->item(0);
     }
     foreach ($libmodules as $module) {
         self::$modules[] = $module;
     }
 }
Exemplo n.º 2
0
 public function process()
 {
     global $current_user;
     /* @var $current_user CurrentUser */
     if ($pid = Request::get('pid')) {
         Statistics::setPartnerCookie($pid);
     }
     XMLClass::$pageNode = XMLClass::createNodeFromObject(array(), false, 'page', false);
     XMLClass::appendNode(XMLClass::$pageNode, '');
     XMLClass::$accessNode = XMLClass::createNodeFromObject(AccessRules::getRules(), false, 'access', true);
     XMLClass::appendNode(XMLClass::$accessNode, '');
     XMLClass::$pageNode->setAttribute('current_url', Request::$url);
     if ($mn = $this->getMessageNode()) {
         XMLClass::$pageNode->appendChild($mn);
     }
     XMLClass::$pageNode->setAttribute('prefix', Config::need('www_path') . '/');
     XMLClass::$varNode = XMLClass::$xml->createElement('variables');
     foreach (Request::$get_normal as $f => $v) {
         if (is_numeric($f)) {
             // cachebreaker?
             XMLClass::$varNode->setAttribute('n' . $f, $f);
         } else {
             XMLClass::$varNode->setAttribute($f, $v);
         }
     }
     XMLClass::$pageNode->appendChild(XMLClass::$varNode);
     XMLClass::$rootNode->appendChild(XMLClass::$xml->importNode(StructureParser::toXML(), 1));
     if ($current_user->authorized) {
         XMLClass::$CurrentUserNode = XMLClass::createNodeFromObject($current_user->getXMLInfo(), false, 'current_user', true);
     } else {
         XMLClass::$CurrentUserNode = XMLClass::createNodeFromObject(array(), false, 'current_user', false);
     }
     XMLClass::$pageNode->appendChild(XMLClass::$CurrentUserNode);
     // втыкаем модули страницы
     $role = $current_user->getRole();
     foreach ($this->modules as $module) {
         $this->processModule($module['name'], $module);
     }
     if ($pageTitle = StructureParser::getTitle()) {
         $this->buildPageTitle($pageTitle);
     }
     switch (Request::$responseType) {
         case 'xml':
         case 'xmlc':
             return XMLClass::dumpToBrowser();
             break;
         case 'xsl':
         case 'xslc':
             $xslTemplateClass = new XSLClass($this->xsltFileName);
             return $xslTemplateClass->dumpToBrowser();
             break;
         case 'html':
             $xslTemplateClass = new XSLClass($this->xsltFileName);
             $html = $xslTemplateClass->getHTML(XMLClass::$xml);
             return $html;
             break;
         default:
             return XMLClass::dumpToBrowser();
             break;
     }
 }
Exemplo n.º 3
0
 public static function clear()
 {
     self::$modules = array();
     self::$data = array();
 }
Exemplo n.º 4
0
    Request::initialize();
    // авторизуем пользователя
    $current_user = new CurrentUser();
    // выполняем модули записи, если был соответствующий POST запрос
    if (Request::post('writemodule')) {
        PostWrite::process(Request::post('writemodule'));
    }
    // запускаем обработку страницы
    $page = new PageConstructor(Request::$structureFile);
    @ob_end_clean();
    echo $page->process();
} catch (Exception $e) {
    if ($dev_mode) {
        $errorString = $e->getMessage();
        $errorDescription = '[' . $e->getFile() . ':' . $e->getLine() . '][' . $e->getCode() . ']';
        $errorDescription .= '<br/><pre>' . $e->getTraceAsString() . '</pre>';
    } else {
        $errorDescription = '';
        $errorString = $e->getMessage();
    }
    $errorCode = $e->getCode();
    XMLClass::reinitialize();
    StructureParser::clear();
    $page = new PageConstructor('errors/p502.xml');
    @ob_end_clean();
    echo $page->process();
}
Log::timing('total');
if ($dev_mode) {
    echo Log::getHtmlLog();
}