コード例 #1
0
ファイル: structure.php プロジェクト: kidaa30/Swevers
 public static function check_structure($xml = "", $force_update = false)
 {
     $filemtime = 0;
     set_time_limit(0);
     if (!$xml) {
         $xml = '<structure>';
         $handle = opendir(CONTENTPATH);
         $opts = array('http' => array('method' => "GET", 'header' => "Content-Type: text/html; charset=utf-8"));
         $context = stream_context_create($opts);
         while (false !== ($file = readdir($handle))) {
             if (is_dir(CONTENTPATH . $file) && file_exists(CONTENTPATH . $file . '/structure.xml')) {
                 $current_filemtime = filemtime(CONTENTPATH . $file . '/structure.xml');
                 try {
                     $structure = new SimpleXMLElement('<structure>' . file_get_contents(CONTENTPATH . $file . '/structure.xml', false, $context) . '</structure>');
                 } catch (Exception $exception) {
                     die('Fout bij lezen van xml voor ' . $file);
                 }
                 foreach ($structure->xpath('//object|//page') as $child) {
                     $child->addAttribute('contentname', $file);
                 }
                 foreach ($structure->children() as $child) {
                     $xml .= str_replace('&', '&amp;', $child->asXML());
                 }
                 if ($current_filemtime > $filemtime) {
                     $filemtime = $current_filemtime;
                 }
             }
         }
         closedir($handle);
         $xml .= '</structure>';
         $xml = self::expand_protocols(new SimpleXMLElement($xml))->asXML();
         self::$structure_xml = new SimpleXMLElement($xml);
         if (!$force_update) {
             $site = current_site();
             $last_update = $site->table_check_date;
         } else {
             $last_update = 0;
         }
         if ($filemtime > $last_update || $force_update) {
             $structure = new SimpleXMLElement($xml);
             if (!count($structure->xpath("//site"))) {
                 $structure->addChild('site');
             }
             $expanded_xml = self::expand_node($structure);
             foreach ($expanded_xml as $type => $data) {
                 if ($type == 'page' || $type == 'object' || $type == 'site') {
                     self::process_searchable_fields($data);
                 }
             }
             if (count(self::$searchable_fields)) {
                 $searchable = $expanded_xml->addChild('object');
                 $searchable->addAttribute('name', '_search_index');
                 $searchableObject = $searchable->addChild('string');
                 $searchableObject->addAttribute('name', 'object_name');
                 $searchableObject->addAttribute('index', 'index');
                 $searchableLanguage = $searchable->addChild('string');
                 $searchableLanguage->addAttribute('name', '_language');
                 $searchableLanguage->addAttribute('index', 'index');
                 $searchableLanguage->addAttribute('length', '2');
                 $searchableId = $searchable->addChild('number');
                 $searchableId->addAttribute('name', 'object_id');
                 $searchableId->addAttribute('index', 'index');
                 $searchableVersion = $searchable->addChild('number');
                 $searchableVersion->addAttribute('name', '_version_id');
                 $searchableVersion->addAttribute('index', 'index');
                 foreach (self::$searchable_fields as $searchable_field => $searchable_type) {
                     $searchfield = $searchable->addChild($searchable_type);
                     $searchfield->addAttribute('name', $searchable_field);
                     if ($searchable_type == 'bool') {
                         $searchfield->addAttribute('allownull', 'allownull');
                     }
                     if (in_array($searchable_type, array('text', 'string'))) {
                         $searchfield->addAttribute('index', 'fulltext');
                     }
                 }
             }
             $db = FW4_Db::get_instance();
             foreach ($expanded_xml as $type => $data) {
                 if ($type == 'page' || $type == 'object' || $type == 'site') {
                     self::process_object($data);
                 }
             }
             update('site', array('table_check_date' => intval($filemtime), 'structure_xml' => $xml, 'structure_xml_expanded' => $expanded_xml->asXML()));
             FW4_Site::reload_site();
             //self::rebuild_search_index();
             return $xml;
         }
     } else {
         $structure = new SimpleXMLElement($xml);
         foreach ($structure as $type => $data) {
             if ($type == 'page' || $type == 'object' || $type == 'site') {
                 self::process_object($data);
             }
         }
     }
 }
コード例 #2
0
ファイル: site.php プロジェクト: kidaa30/Swevers
 public static function reload_site()
 {
     $db = FW4_Db::get_instance();
     $site = false;
     if (!$site) {
         try {
             if (count(languages()) > 1) {
                 $query = from('site')->where('url LIKE %s', $_SERVER['HTTP_HOST'] . '%');
                 $language_codes = array_keys(languages());
                 if ($countries = Config::countries()) {
                     $language_codes = array_keys($countries);
                 }
                 foreach ($language_codes as $code) {
                     $query->or_where('`url_' . $code . '` LIKE %s', $_SERVER['HTTP_HOST'] . '%');
                 }
                 $site = $query->get_row();
             } else {
                 $site = from('site')->where('url LIKE %s', $_SERVER['HTTP_HOST'] . '%')->get_row();
             }
         } catch (PDOException $exception) {
             FW4_Structure::check_structure('', true);
         }
         if (!$site) {
             if (!($site = get_row('site'))) {
                 $name = str_ireplace('www.', '', $_SERVER['HTTP_HOST']);
                 $name = ucfirst(substr($name, 0, strpos($name, '.')));
                 $url = $_SERVER['HTTP_HOST'];
                 if (stristr(getcwd(), 'httpdocs')) {
                     $url .= substr(getcwd(), stripos(getcwd(), 'httpdocs') + strlen('httpdocs'));
                 }
                 insert('site', array("url" => $url, "name" => $name));
                 FW4_Structure::check_structure();
                 $site = where('url LIKE %s', $_SERVER['HTTP_HOST'])->get_row('site');
             } else {
                 $domain_handled = false;
                 // Process minisites
                 $types = FW4_Type_Manager::get_instance()->get_types();
                 foreach ($types as $typename => $type) {
                     if (method_exists($type, 'handle_domain')) {
                         if (!$site->structure_xml_expanded) {
                             FW4_Structure::check_structure("", true);
                             return self::reload_site();
                         }
                         $structure = new SimpleXMLElement($site->structure_xml_expanded);
                         $fields = $structure->xpath('//*[@type_name="' . $typename . '"]');
                         if (count($fields)) {
                             $prev = self::$current;
                             self::$current = $site;
                             if (call_user_func_array(array($type, 'handle_domain'), array($_SERVER['HTTP_HOST'], $fields))) {
                                 $domain_handled = true;
                                 break;
                             }
                             self::$current = $prev;
                         }
                     }
                 }
                 // Process subdomains
                 foreach (Config::subdomains() as $subdomain => $handler) {
                     //if () Router::set_content_prefix($handler);
                 }
                 if (!$domain_handled && $site->live) {
                     redirect((Config::https() ? 'https' : 'http') . '://' . $site->url . $_SERVER['REQUEST_URI']);
                 }
             }
         }
     }
     if (!$site->live && false === stristr($_SERVER['HTTP_HOST'], '.fw4.') && false === stristr($_SERVER['HTTP_HOST'], 'local')) {
         $db->query("UPDATE site SET live = 1 WHERE id = " . $site->id);
         if (stristr($site->url, '.fw4.be')) {
             where('id = %d', $site->id)->update('site', array('url' => $_SERVER['HTTP_HOST']));
         }
     }
     self::$current = $site;
     return $site;
 }