예제 #1
0
 public function Query()
 {
     $this->db = FW4_Db::get_instance();
 }
예제 #2
0
 public static function describe_table($table)
 {
     $result = array();
     try {
         $db = FW4_Db::get_instance();
         $query = $db->query("SHOW COLUMNS FROM `" . $table . "`");
     } catch (PDOException $exception) {
         $error = $db->errorInfo();
         if ($error[1] == 1146 || $error[1] == 1017) {
             return false;
         }
     }
     foreach ($query as $row) {
         $field = array('type' => strstr($row['Type'], '(') ? substr($row['Type'], 0, strpos($row['Type'], "(")) : $row['Type'], 'length' => strstr($row['Type'], '(') ? substr($row['Type'], strpos($row['Type'], "(") + 1, -1) : NULL, 'null' => $row['Null'] == 'YES', 'index' => false, 'key_name' => false, 'default' => is_null($row['Default']) ? false : $row['Default']);
         $result[$row['Field']] = $field;
     }
     try {
         $query = $db->query("SHOW INDEX FROM `" . $table . "`;");
     } catch (PDOException $exception) {
         $error = $db->errorInfo();
         if ($error[1] == 1146 || $error[1] == 1017) {
             return false;
         }
     }
     foreach ($query as $row) {
         if ($row['Key_name'] == 'PRIMARY') {
             $result[$row['Column_name']]['index'] = 'primary';
         } else {
             if ($row['Index_type'] == 'FULLTEXT') {
                 $result[$row['Column_name']]['index'] = 'fulltext';
                 if ($row['Key_name'] != $row['Column_name']) {
                     $result[$row['Column_name']]['key_name'] = $row['Key_name'];
                 }
             } else {
                 if ($row['Column_name'] == $row['Key_name'] && $row['Seq_in_index'] == 1 && isset($row['Column_name'])) {
                     $result[$row['Column_name']]['index'] = 'index';
                 } else {
                     if (!isset($result[$row['Key_name']])) {
                         $result[$row['Key_name']] = array('fields' => array(), 'index' => 'index');
                     }
                     $result[$row['Key_name']]['fields'][] = $row['Column_name'];
                 }
             }
         }
     }
     return $result;
 }
예제 #3
0
파일: admin.php 프로젝트: kidaa30/Swevers
 private static function update_sorting_field($objectname)
 {
     if (!($structure = FW4_Structure::get_object_structure($objectname))) {
         return false;
     }
     $db = FW4_Db::get_instance();
     $db->query('SELECT @row:=0;');
     $db->query('UPDATE `' . $structure['path'] . '` SET _sort_order = (@row:=@row+1) ORDER BY _sort_order, id DESC;');
     if (isset($structure['archived']) && strval($structure['name']) != '_versions') {
         $db->query('UPDATE `' . $structure['path'] . '>_versions` versions JOIN `' . $structure['path'] . '` origtable ON origtable.id = versions.id SET versions._sort_order = origtable._sort_order WHERE versions.version_id IN (SELECT * FROM (SELECT MAX(version_id) FROM `' . $structure['path'] . '>_versions` GROUP BY id) as version_ids)');
     }
 }
예제 #4
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;
 }