public function wolf_pages()
 {
     $root = Page::findByUri('/');
     $pages = array();
     $pages[] = array('title' => $root->title(), 'url' => $root->url());
     $this->_wolf_pages_list($root, $pages);
     header("Content-type: application/x-javascript; charset=utf8");
     // Display our page list using view in 'views/ckeditor_plugins/wolf_pages/list.php'
     $this->display('wolf_pages/list', array('pages' => $pages));
 }
Example #2
0
/**
 * Presents browser with a custom 404 page.
 */
function behavior_page_not_found()
{
    $sql = 'SELECT * FROM ' . TABLE_PREFIX . "page WHERE behavior_id='page_not_found'";
    $stmt = Record::getConnection()->prepare($sql);
    $stmt->execute();
    $page = $stmt->fetchObject();
    if ($page) {
        $page = Page::findByUri($page->slug);
        if (is_object($page)) {
            header("HTTP/1.0 404 Not Found");
            header("Status: 404 Not Found");
            $page->_executeLayout();
            exit;
            // need to exit otherwise true error page will be sent
        }
    }
}
Example #3
0
 /**
  * This function should no longer be used.
  *
  * @deprecated
  * @see findByUri()
  *
  * @param type $uri
  * @return type
  */
 public static function find_page_by_uri($uri)
 {
     return Page::findByUri($uri);
 }
Example #4
0
function main()
{
    // get the uri string from the query
    $uri = $_SERVER['QUERY_STRING'];
    // Make sure special characters are decoded (support non-western glyphs like japanese)
    $uri = urldecode($uri);
    // START processing $_GET variables
    // If we're NOT using mod_rewrite, we check for GET variables we need to integrate
    if (!USE_MOD_REWRITE && strpos($uri, '?') !== false) {
        $_GET = array();
        // empty $_GET array since we're going to rebuild it
        list($uri, $get_var) = explode('?', $uri);
        $exploded_get = explode('&', $get_var);
        if (count($exploded_get)) {
            foreach ($exploded_get as $get) {
                list($key, $value) = explode('=', $get);
                $_GET[$key] = $value;
            }
        }
    } else {
        if (!USE_MOD_REWRITE && (strpos($uri, '&') !== false || strpos($uri, '=') !== false)) {
            $uri = '/';
        }
    }
    // If we're using mod_rewrite, we should have a WOLFPAGE entry.
    if (USE_MOD_REWRITE && array_key_exists('WOLFPAGE', $_GET)) {
        $uri = $_GET['WOLFPAGE'];
        unset($_GET['WOLFPAGE']);
    } else {
        if (USE_MOD_REWRITE) {
            // We're using mod_rewrite but don't have a WOLFPAGE entry, assume site root.
            $uri = '/';
        }
    }
    // Needed to allow for ajax calls to backend
    if (array_key_exists('WOLFAJAX', $_GET)) {
        $uri = '/' . ADMIN_DIR . $_GET['WOLFAJAX'];
        unset($_GET['WOLFAJAX']);
    }
    // END processing $_GET variables
    // remove suffix page if founded
    if (URL_SUFFIX !== '' and URL_SUFFIX !== '/') {
        $uri = preg_replace('#^(.*)(' . URL_SUFFIX . ')$#i', "\$1", $uri);
    }
    define('CURRENT_URI', trim($uri, '/'));
    if ($uri != null && $uri[0] != '/') {
        $uri = '/' . $uri;
    }
    // Check if there's a custom route defined for this URI,
    // otherwise continue and assume page was requested.
    if (Dispatcher::hasRoute($uri)) {
        Observer::notify('dispatch_route_found', $uri);
        Dispatcher::dispatch($uri);
        exit;
    }
    foreach (Observer::getObserverList('page_requested') as $callback) {
        $uri = call_user_func_array($callback, array(&$uri));
    }
    // this is where 80% of the things is done
    $page = Page::findByUri($uri, true);
    // if we found it, display it!
    if (is_object($page)) {
        // If a page is in preview status, only display to logged in users
        if (Page::STATUS_PREVIEW == $page->status_id) {
            AuthUser::load();
            if (!AuthUser::isLoggedIn() || !AuthUser::hasPermission('page_view')) {
                page_not_found();
            }
        }
        // If page needs login, redirect to login
        if ($page->getLoginNeeded() == Page::LOGIN_REQUIRED) {
            AuthUser::load();
            if (!AuthUser::isLoggedIn()) {
                Flash::set('redirect', $page->url());
                redirect(URL_PUBLIC . (USE_MOD_REWRITE ? '' : '?/') . ADMIN_DIR . '/login');
            }
        }
        Observer::notify('page_found', $page);
        $page->_executeLayout();
    } else {
        page_not_found();
    }
}
Example #5
0
/**
 * Replaces the content of the 'body' part if a language specific part exists.
 *
 * @param Page $page Page object.
 */
function replaceContent($page)
{
    $source = Plugin::getSetting('langsource', 'multi_lang');
    $style = Plugin::getSetting('style', 'multi_lang');
    if (!$source || !$style) {
        return;
    }
    if ($source == 'header' && $style == 'tab') {
        use_helper('I18n');
        $found = false;
        foreach (I18n::getPreferredLanguages() as $lang) {
            if (Setting::get('language') == $lang) {
                break;
            }
            if (isset($page->part->{$lang}) && !empty($page->part->{$lang}->content_html) && $page->part->{$lang}->content_html != '') {
                $page->part->body->content_html = $page->part->{$lang}->content_html;
                $found = true;
            }
            if ($found) {
                break;
            }
        }
    } else {
        if ($source == 'preferences' && $style == 'tab') {
            AuthUser::load();
            if (AuthUser::isLoggedIn()) {
                $lang = AuthUser::getRecord()->language;
                if (isset($page->part->{$lang}) && !empty($page->part->{$lang}->content_html) && $page->part->{$lang}->content_html != '') {
                    $page->part->body->content_html = $page->part->{$lang}->content_html;
                }
            }
        } else {
            if ($source == 'header' && $style == 'page') {
                use_helper('I18n');
                foreach (I18n::getPreferredLanguages() as $lang) {
                    if (Setting::get('language') == $lang) {
                        break;
                    }
                    $uri = $lang . '/' . CURRENT_URI;
                    $page = Page::findByUri($uri);
                    if (false !== $page) {
                        redirect(BASE_URL . $uri);
                    }
                }
            } else {
                if ($source == 'preferences' && $style == 'page') {
                    AuthUser::load();
                    if (AuthUser::isLoggedIn()) {
                        $lang = AuthUser::getRecord()->language;
                        $uri = $lang . '/' . CURRENT_URI;
                        $page = Page::findByUri($uri);
                        if (false !== $page) {
                            redirect(BASE_URL . $uri);
                        }
                    }
                }
            }
        }
    }
}
Example #6
0
 static function find($params = null, $class = __CLASS__)
 {
     /* Assume we should call Record finder. */
     if (is_array($params)) {
         return parent::find($params, $class);
     } else {
         /* Maintain BC. Assume string mean find by URI. */
         return Page::findByUri($params);
     }
 }
Example #7
0
function main()
{
    /* Get the uri string from the query. */
    $uri = $_SERVER['QUERY_STRING'];
    /* Real integration of GET. */
    if (strpos($uri, '?') !== false) {
        list($uri, $get_var) = explode('?', $uri);
        $exploded_get = explode('&', $get_var);
        if (count($exploded_get)) {
            foreach ($exploded_get as $get) {
                list($key, $value) = explode('=', $get);
                $_GET[$key] = $value;
            }
        }
    }
    /* Remove suffix page if found. */
    if (URL_SUFFIX !== '' and URL_SUFFIX !== '/') {
        $uri = preg_replace('#^(.*)(' . URL_SUFFIX . ')$#i', "\$1", $uri);
    }
    define('CURRENT_URI', trim($uri, '/'));
    /* This is where 80% of the things are done. */
    $page = Page::findByUri($uri);
    /* If we found it, display it! */
    if (is_object($page)) {
        Observer::notify('page_found', $page);
        $page->show();
    } else {
        page_not_found();
    }
}
Example #8
0
 public static function find($args = null)
 {
     if (is_int($args)) {
         // Assumes find was called with an id
         return Page::findById($args);
     }
     if (is_string($args)) {
         // Assumes find was called with a uri
         return Page::findByUri($args);
     } elseif (!is_array($args)) {
         $args = (array) $args;
     }
     // Collect attributes...
     $where = isset($args['where']) ? trim($args['where']) : '';
     $order_by = isset($args['order']) ? trim($args['order']) : '';
     $offset = isset($args['offset']) ? (int) $args['offset'] : 0;
     $limit = isset($args['limit']) ? (int) $args['limit'] : 0;
     $values = isset($args['values']) ? (array) $args['values'] : null;
     // Prepare query parts
     $where_string = empty($where) ? '' : "WHERE {$where}";
     $order_by_string = empty($order_by) ? '' : "ORDER BY {$order_by}";
     $limit_string = $limit > 0 ? "LIMIT {$offset}, {$limit}" : '';
     $tablename = self::tableNameFromClassName('Page');
     $tablename_user = self::tableNameFromClassName('User');
     // Prepare SQL
     $sql = "SELECT page.*, creator.name AS created_by_name, updater.name AS updated_by_name FROM {$tablename} AS page" . " LEFT JOIN {$tablename_user} AS creator ON page.created_by_id = creator.id" . " LEFT JOIN {$tablename_user} AS updater ON page.updated_by_id = updater.id" . " {$where_string} {$order_by_string} {$limit_string}";
     $stmt = self::$__CONN__->prepare($sql);
     if ($values) {
         $stmt->execute($values);
     } else {
         $stmt->execute();
     }
     // Run!
     if ($limit == 1) {
         return $stmt->fetchObject('Page');
         // $page = $stmt->fetchObject('Page');
         // if ( ! empty($page->behavior_id)) {
         //     $page_class = Behavior::loadPageHack($page->behavior_id);
         //     $ret = new $page_class($page);
         // } else {
         //     $ret = $page;
         // }
     } else {
         $objects = array();
         while ($object = $stmt->fetchObject('Page')) {
             $objects[] = $object;
         }
         return $objects;
         // $ret = array();
         // while ($page = $stmt->fetchObject('Page')){
         //     if ( ! empty($page->behavior_id)) {
         //         $page_class = Behavior::loadPageHack($page->behavior_id);
         //         $page = new $page_class($page);
         //     }
         //     $ret[] = $page;
         // }
     }
     // return $ret;
 }
Example #9
0
 /**
  * Finds a Page record based on supplied arguments.
  * 
  * Usage:
  *      $page = Page::find('/the/uri/to/your/page');
  *      $page = Page::find(array('where' => 'created_by_id=12'));
  * 
  * Argument array can contain:
  *      - where
  *      - order
  *      - offset
  *      - limit
  * 
  * Return values can be:
  *      - A single Page object
  *      - An array of Page objects which can be empty
  *      - False
  *
  * @param mixed $args   Uri string or array of arguments.
  * @return mixed        Page or array of Pages, otherwise false.
  */
 public static function find($args = null)
 {
     if (!is_array($args)) {
         // Assumes find was called with a uri
         return Page::findByUri($args);
     }
     $page_class = 'Page';
     // Collect attributes...
     $where = isset($args['where']) ? trim($args['where']) : '';
     $order_by = isset($args['order']) ? trim($args['order']) : '';
     $offset = isset($args['offset']) ? (int) $args['offset'] : 0;
     $limit = isset($args['limit']) ? (int) $args['limit'] : 0;
     // Prepare query parts
     $where_string = empty($where) ? '' : "WHERE {$where}";
     $order_by_string = empty($order_by) ? '' : "ORDER BY {$order_by}";
     $limit_string = $limit > 0 ? "LIMIT {$limit}" : '';
     $offset_string = $offset > 0 ? "OFFSET {$offset}" : '';
     $tablename = self::tableNameFromClassName('Page');
     $tablename_user = self::tableNameFromClassName('User');
     // Prepare SQL
     $sql = "SELECT page.*, creator.name AS created_by_name, updater.name AS updated_by_name FROM {$tablename} AS page" . " LEFT JOIN {$tablename_user} AS creator ON page.created_by_id = creator.id" . " LEFT JOIN {$tablename_user} AS updater ON page.updated_by_id = updater.id" . " {$where_string} {$order_by_string} {$limit_string} {$offset_string}";
     $stmt = self::$__CONN__->prepare($sql);
     if (!$stmt->execute()) {
         return false;
     }
     // Run!
     $objects = array();
     while ($page = $stmt->fetchObject('Page')) {
         $parent = $page->parent();
         if (!empty($parent->behavior_id)) {
             // will return Page by default (if not found!)
             $page_class = Behavior::loadPageHack($parent->behavior_id);
         }
         // create the object page
         $page = new $page_class($page, $parent);
         $page->part = self::get_parts($page->id);
         $objects[] = $page;
     }
     // if we're loading just one result return it
     if ($limit == 1) {
         if (isset($objects['0']) && is_object($objects['0'])) {
             return $objects['0'];
         }
     } else {
         // or return them all
         return $objects;
     }
     return false;
 }