Example #1
0
 public function load($viewname, $_vars = array())
 {
     foreach ($_vars as $_key => $_value) {
         ${$_key} = htmlentities_all($_value, true);
         if ($_key == 'title') {
             Router::$document_title = ${$_key};
         }
     }
     $parameters = $_vars;
     unset($_vars);
     ob_start();
     if (strstr($viewname, '/')) {
         $viewpath = explode('/', $viewname);
         if (file_exists(CONTENTPATH . Router::get_content_prefix() . strtolower($viewpath[0]) . '/views/' . strtolower($viewpath[1]) . ".php")) {
             include CONTENTPATH . Router::get_content_prefix() . strtolower($viewpath[0]) . '/views/' . strtolower($viewpath[1]) . ".php";
         } else {
             if (file_exists($this->pathname . '/views/' . strtolower($viewname) . ".php")) {
                 include $this->pathname . '/views/' . strtolower($viewname) . ".php";
             } else {
                 if (strlen(Router::get_content_prefix()) > 1 && file_exists(CONTENTPATH . Router::get_content_prefix() . 'views/' . strtolower($viewname) . ".php")) {
                     include CONTENTPATH . Router::get_content_prefix() . 'views/' . strtolower($viewname) . ".php";
                 } else {
                     if (file_exists(VIEWSPATH . strtolower($viewname) . ".php")) {
                         include VIEWSPATH . strtolower($viewname) . ".php";
                     }
                 }
             }
         }
     } else {
         if (file_exists($this->pathname . '/views/' . strtolower($viewname) . ".php")) {
             include $this->pathname . '/views/' . strtolower($viewname) . ".php";
         } else {
             if (strlen(Router::get_content_prefix()) > 1 && file_exists(CONTENTPATH . Router::get_content_prefix() . 'views/' . strtolower($viewname) . ".php")) {
                 include CONTENTPATH . Router::get_content_prefix() . 'views/' . strtolower($viewname) . ".php";
             } else {
                 if (file_exists(VIEWSPATH . strtolower($viewname) . ".php")) {
                     include VIEWSPATH . strtolower($viewname) . ".php";
                 }
             }
         }
     }
     $result = ob_get_contents();
     ob_end_clean();
     return $result;
 }
Example #2
0
function error($code = 404, $message = '', $debug_info = '')
{
    View_Loader::get_instance()->set_path(CONTENTPATH . Router::get_content_prefix() . 'home');
    if (!language()) {
        Router::determine_language();
    }
    switch ($code) {
        case 404:
            header("X-Robots-Tag: noindex");
            header("HTTP/1.0 404 Not Found");
            echo view('errors/404');
            break;
        case 400:
            header("HTTP/1.0 400 Bad Request");
            echo view('errors/400');
            break;
        case 500:
            while (ob_get_level() > 1) {
                ob_end_clean();
            }
            header("HTTP/1.0 500 Internal Server Error");
            if (!stristr($_SERVER['HTTP_HOST'], 'fw4.be')) {
                $mailcontent = '';
                if ($message) {
                    $mailcontent .= "{$message}\n\n";
                }
                if ($debug_info) {
                    $mailcontent .= "{$debug_info}\n\n";
                }
                if (count($_POST)) {
                    $mailcontent .= "POST: " . print_r($_POST, true) . "\n\n";
                }
                $mailcontent .= print_r(debug_backtrace(), true);
                // Automatic error reporting disabled for now
                //mail('*****@*****.**', '['.$_SERVER['HTTP_HOST'].'] Error 500', $mailcontent);
            }
            echo view('errors/500', array('message' => $message, 'debug_info' => $debug_info));
            break;
    }
    exit;
}
Example #3
0
 public function get($objectname = false)
 {
     if ($objectname && !$this->structure && !($this->structure = FW4_Structure::get_object_structure($this->objectname_prefix . $objectname))) {
         return false;
     }
     if (!count($this->order_by)) {
         if (isset($this->structure['order'])) {
             $this->order_by(strval($this->structure['order']));
         } else {
             if (isset($this->structure['sortable']) && $this->structure['sortable']) {
                 $this->order_by('_sort_order, id DESC');
             }
         }
     }
     $translate = array();
     if ($this->structure) {
         // A page always needs a record
         if ($this->structure->getName() == 'page' && !count($this->where)) {
             $force_entry = true;
         } else {
             $force_entry = false;
         }
         $types = FW4_Type_Manager::get_instance();
         foreach ($this->structure->children() as $child) {
             if ($child->getName() == 'object' && !isset($this->children[strval($child['name'])])) {
                 $this->children[strval($child['name'])] = true;
             } else {
                 if ($this->translate && isset($child['translatable']) && $child['translatable'] && $child['translatable'] != 'false') {
                     if ($child->getName() == 'slug' && !isset($child['name'])) {
                         $child['name'] = 'slug';
                     }
                     $translate[strval($child['name'])] = strval($child['name']) . '_' . language();
                 } else {
                     if ($child->getName() == 'dbrelation' && !isset($this->relations[strval($child['name'])])) {
                         $this->relations[strval($child['name'])] = current($child->attributes());
                     } else {
                         if (count($this->select) == 0 && isset($child['type_name']) && ($type_obj = $types->get_type(strval($child['type_name'])))) {
                             if (method_exists($type_obj, 'on_fetch')) {
                                 $this->fetchable_fields[] = array('type' => $type_obj, 'field' => new SimpleXMLElement($child->asXML()));
                             }
                         } else {
                             if ($child->getName() == 'recursive') {
                                 if (count($this->where) == 0) {
                                     $this->where('parent_id IS NULL');
                                 }
                                 $this->relations[strval($child['name'])] = array('local_key' => 'id', 'foreign_key' => 'parent_id', 'source' => strval($this->structure['stack']));
                             }
                         }
                     }
                 }
             }
         }
         if (isset($this->structure['recursive'])) {
             $this->relations[strval($this->structure['name'])] = array('local_key' => 'id', 'foreign_key' => 'parent_id', 'source' => strval($this->structure['stack']));
             if (isset($this->structure['order'])) {
                 $this->relations[strval($this->structure['name'])]['order'] = strval($this->structure['order']);
             }
         }
     }
     if (isset($this->structure['model']) && !count($this->select) && (class_exists(ucfirst($this->structure['model'])) || file_exists(CONTENTPATH . Router::get_content_prefix() . strtolower($this->structure['contentname']) . '/models/' . strtolower($this->structure['model']) . ".php"))) {
         if (!class_exists(ucfirst($this->structure['model']))) {
             include_once CONTENTPATH . Router::get_content_prefix() . strtolower($this->structure['contentname']) . '/models/' . strtolower($this->structure['model']) . ".php";
         }
         if (class_exists(ucfirst($this->structure['model']))) {
             $this->model_name = ucfirst($this->structure['model']);
         }
     } else {
         if ($this->model_name != 'Model') {
             if (!class_exists($this->model_name)) {
                 include_once CONTENTPATH . Router::get_content_prefix() . strtolower($this->structure['contentname']) . '/models/' . strtolower($this->model_name) . ".php";
             }
         }
     }
     $sql = $this->get_sql();
     if ($this->debug) {
         var_dump($sql);
     }
     $start = microtime(true);
     $result = new Resultset($this->db->query($sql, PDO::FETCH_CLASS, $this->model_name, array('translate' => $translate)), $this->structure ? strval($this->structure['stack']) : $this->from, $this->structure ? strval($this->structure['name']) : $objectname, !isset($this->structure['child']));
     $time = microtime(true) - $start;
     FW4_Db::$query_log[$sql] = round($time * 1000, 3);
     $result->_children($this->children);
     $result->_relations($this->relations);
     $result->_fetchable_fields($this->fetchable_fields);
     if ($this->structure && $force_entry && $result->rowCount() == 0) {
         if ($this->structure['parent_type'] == 'site') {
             $site = current_site();
             $id = insert($objectname, array('site_id' => $site['id']));
         } else {
             $id = insert($objectname, array());
         }
         return $this->get($objectname);
     }
     return $result;
 }