예제 #1
0
 /**
  * Execute the extra.
  *
  * @return	void
  */
 public function execute()
 {
     // get reset key
     $key = $this->URL->getParameter(0);
     // do we have an reset key?
     if (isset($key)) {
         // load parent
         parent::execute();
         // load template
         $this->loadTemplate();
         // get profile id
         $profileId = FrontendProfilesModel::getIdBySetting('forgot_password_key', $key);
         // have id?
         if ($profileId !== 0) {
             // load
             $this->loadForm();
             // validate
             $this->validateForm();
         } elseif ($this->URL->getParameter('saved') != 'true') {
             $this->redirect(FrontendNavigation::getURL(404));
         }
         // parse
         $this->parse();
     } else {
         $this->redirect(FrontendNavigation::getURL(404));
     }
 }
예제 #2
0
 /**
  * Execute the extra.
  */
 public function execute()
 {
     // get activation key
     $key = $this->URL->getParameter(0);
     // load template
     $this->loadTemplate();
     // do we have an activation key?
     if (isset($key)) {
         // get profile id
         $profileId = FrontendProfilesModel::getIdBySetting('activation_key', $key);
         // have id?
         if ($profileId != null) {
             // update status
             FrontendProfilesModel::update($profileId, array('status' => 'active'));
             // delete activation key
             FrontendProfilesModel::deleteSetting($profileId, 'activation_key');
             // login profile
             FrontendProfilesAuthentication::login($profileId);
             // trigger event
             FrontendModel::triggerEvent('profiles', 'after_activate', array('id' => $profileId));
             // show success message
             $this->tpl->assign('activationSuccess', true);
         } else {
             $this->redirect(FrontendNavigation::getURL(404));
         }
     } else {
         $this->redirect(FrontendNavigation::getURL(404));
     }
 }
예제 #3
0
 /**
  * Load the data, don't forget to validate the incoming data
  */
 private function getData()
 {
     // validate incoming parameters
     if ($this->URL->getParameter(1) === null) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // get by URL
     $this->record = FrontendFaqModel::get($this->URL->getParameter(1));
     // anything found?
     if (empty($this->record)) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // overwrite URLs
     $this->record['category_full_url'] = FrontendNavigation::getURLForBlock('faq', 'category') . '/' . $this->record['category_url'];
     $this->record['full_url'] = FrontendNavigation::getURLForBlock('faq', 'detail') . '/' . $this->record['url'];
     // get tags
     $this->record['tags'] = FrontendTagsModel::getForItem('faq', $this->record['id']);
     // get settings
     $this->settings = FrontendModel::getModuleSettings('faq');
     // reset allow comments
     if (!$this->settings['allow_feedback']) {
         $this->record['allow_feedback'] = false;
     }
     // ge status
     $this->status = $this->URL->getParameter(2);
     if ($this->status == FL::getAction('Success')) {
         $this->status = 'success';
     }
     if ($this->status == FL::getAction('Spam')) {
         $this->status = 'spam';
     }
 }
예제 #4
0
 /**
  * Load the data, don't forget to validate the incoming data
  *
  * @return	void
  */
 private function getData()
 {
     // get categories
     $categories = FrontendBlogModel::getAllCategories();
     $possibleCategories = array();
     foreach ($categories as $category) {
         $possibleCategories[$category['url']] = $category['id'];
     }
     // requested category
     $requestedCategory = SpoonFilter::getValue($this->URL->getParameter(1, 'string'), array_keys($possibleCategories), 'false');
     // requested page
     $requestedPage = $this->URL->getParameter('page', 'int', 1);
     // validate category
     if ($requestedCategory == 'false') {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // set category
     $this->category = $categories[$possibleCategories[$requestedCategory]];
     // set URL and limit
     $this->pagination['url'] = FrontendNavigation::getURLForBlock('blog', 'category') . '/' . $requestedCategory;
     $this->pagination['limit'] = FrontendModel::getModuleSetting('blog', 'overview_num_items', 10);
     // populate count fields in pagination
     $this->pagination['num_items'] = FrontendBlogModel::getAllForCategoryCount($requestedCategory);
     $this->pagination['num_pages'] = (int) ceil($this->pagination['num_items'] / $this->pagination['limit']);
     // redirect if the request page doesn't exists
     if ($requestedPage > $this->pagination['num_pages'] || $requestedPage < 1) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // populate calculated fields in pagination
     $this->pagination['requested_page'] = $requestedPage;
     $this->pagination['offset'] = $this->pagination['requested_page'] * $this->pagination['limit'] - $this->pagination['limit'];
     // get articles
     $this->items = FrontendBlogModel::getAllForCategory($requestedCategory, $this->pagination['limit'], $this->pagination['offset']);
 }
예제 #5
0
    /**
     * Load the data, don't forget to validate the incoming data
     */
    private function getData()
    {
        // validate incoming parameters
        if ($this->URL->getParameter(1) === null) {
            $this->redirect(FrontendNavigation::getURL(404));
        }
        // fetch record
        $this->record = FrontendTagsModel::get($this->URL->getParameter(1));
        // validate record
        if (empty($this->record)) {
            $this->redirect(FrontendNavigation::getURL(404));
        }
        // fetch modules
        $this->modules = FrontendTagsModel::getModulesForTag($this->record['id']);
        // loop modules
        foreach ($this->modules as $module) {
            // set module class
            $class = 'Frontend' . SpoonFilter::toCamelCase($module) . 'Model';
            // get the ids of the items linked to the tag
            $otherIds = (array) FrontendModel::getDB()->getColumn('SELECT other_id
				 FROM modules_tags
				 WHERE module = ? AND tag_id = ?', array($module, $this->record['id']));
            // set module class
            $class = 'Frontend' . SpoonFilter::toCamelCase($module) . 'Model';
            // get the items that are linked to the tags
            $items = (array) FrontendTagsModel::callFromInterface($module, $class, 'getForTags', $otherIds);
            // add into results array
            if (!empty($items)) {
                $this->results[] = array('name' => $module, 'label' => FL::lbl(SpoonFilter::ucfirst($module)), 'items' => $items);
            }
        }
    }
예제 #6
0
 /**
  * Load the data, don't forget to validate the incoming data
  */
 private function getData()
 {
     // validate incoming parameters
     if ($this->URL->getParameter(1) === null) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // load revision
     if ($this->URL->getParameter('revision', 'int') != 0) {
         // get data
         $this->record = FrontendBlogModel::getRevision($this->URL->getParameter(1), $this->URL->getParameter('revision', 'int'));
         // add no-index, so the draft won't get accidentally indexed
         $this->header->addMetaData(array('name' => 'robots', 'content' => 'noindex, nofollow'), true);
     } else {
         $this->record = FrontendBlogModel::get($this->URL->getParameter(1));
     }
     // anything found?
     if (empty($this->record)) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // get comments
     $this->comments = FrontendBlogModel::getComments($this->record['id']);
     // get tags
     $this->record['tags'] = FrontendTagsModel::getForItem('blog', $this->record['id']);
     // get settings
     $this->settings = FrontendModel::getModuleSettings('blog');
     // overwrite URLs
     $this->record['category_full_url'] = FrontendNavigation::getURLForBlock('blog', 'category') . '/' . $this->record['category_url'];
     $this->record['full_url'] = FrontendNavigation::getURLForBlock('blog', 'detail') . '/' . $this->record['url'];
     $this->record['allow_comments'] = $this->record['allow_comments'] == 'Y';
     $this->record['comments_count'] = count($this->comments);
     // reset allow comments
     if (!$this->settings['allow_comments']) {
         $this->record['allow_comments'] = false;
     }
 }
예제 #7
0
파일: Detail.php 프로젝트: Comsa/modules
 /**
  * Load the data
  */
 protected function loadData()
 {
     //--Check the params
     if ($this->URL->getParameter(1) === null) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     //--Get record
     $this->record = FrontendGalleryModel::getAlbum($this->URL->getParameter(1));
     //--Redirect if empty
     if (empty($this->record)) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
 }
예제 #8
0
 /**
  * Execute the extra
  */
 public function execute()
 {
     // profile not logged in
     if (!FrontendProfilesAuthentication::isLoggedIn()) {
         parent::execute();
         $this->loadTemplate();
         $this->loadForm();
         $this->validateForm();
         $this->parse();
     } else {
         $this->redirect(FrontendNavigation::getURL(404));
     }
 }
예제 #9
0
 /**
  * Load the data, don't forget to validate the incoming data
  *
  * @return	void
  */
 private function getData()
 {
     // store the ID
     $this->id = $this->URL->getParameter(1);
     // store the type
     $this->type = SpoonFilter::getGetValue('type', array('html', 'plain'), 'html');
     // is this CM asking the info?
     $this->forCM = SpoonFilter::getGetValue('cm', array(0, 1), 0, 'bool');
     // fetch the mailing data
     $this->record = FrontendMailmotorModel::get($this->id);
     // anything found?
     if (empty($this->record)) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
 }
예제 #10
0
 /**
  * Execute the extra.
  *
  * @return	void
  */
 public function execute()
 {
     // no url parameter
     if (FrontendProfilesAuthentication::isLoggedIn()) {
         // call the parent
         parent::execute();
         /*
          * You could use this as some kind of dashboard where you could show an activity stream, some statistics, ...
          */
         // load template
         $this->loadTemplate();
     } else {
         $this->redirect(FrontendNavigation::getURL(404));
     }
 }
 /**
  * Load the data, don't forget to validate the incoming data
  */
 private function getData()
 {
     // validate incoming parameters
     if ($this->URL->getParameter(1) === null) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // get record
     $this->record = FrontendBlogModel::get($this->URL->getParameter(1));
     // anything found?
     if (empty($this->record)) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // get articles
     $this->items = FrontendBlogModel::getComments($this->record['id']);
 }
예제 #12
0
 /**
  * Load the data, don't forget to validate the incoming data
  */
 private function getData()
 {
     // validate incoming parameters
     if ($this->URL->getParameter(1) === null) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // get by URL
     $this->record = FrontendFaqModel::getCategory($this->URL->getParameter(1));
     // anything found?
     if (empty($this->record)) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     $this->record['full_url'] = FrontendNavigation::getURLForBlock('faq', 'category') . '/' . $this->record['url'];
     $this->questions = FrontendFaqModel::getAllForCategory($this->record['id']);
 }
예제 #13
0
 /**
  * Execute the extra.
  */
 public function execute()
 {
     // only logged in profiles can seer their dashboard
     if (FrontendProfilesAuthentication::isLoggedIn()) {
         // call the parent
         parent::execute();
         /*
          * You could use this as some kind of dashboard where you can show an activity
          * stream, some statistics, ...
          */
         $this->loadTemplate();
     } else {
         $this->redirect(FrontendNavigation::getURL(404));
     }
 }
예제 #14
0
 /**
  * Default constructor
  *
  * @return	void
  */
 public function __construct()
 {
     // call parent
     parent::__construct();
     // add into the reference
     Spoon::set('breadcrumb', $this);
     // get more information for the homepage
     $homeInfo = FrontendNavigation::getPageInfo(1);
     // add homepage as first item (with correct element)
     $this->addElement($homeInfo['navigation_title'], FrontendNavigation::getURL(1));
     // get other pages
     $pages = $this->URL->getPages();
     // init vars
     $items = array();
     $errorURL = FrontendNavigation::getUrl(404);
     // loop pages
     while (!empty($pages)) {
         // init vars
         $URL = implode('/', $pages);
         $menuId = FrontendNavigation::getPageId($URL);
         $pageInfo = FrontendNavigation::getPageInfo($menuId);
         // do we know something about the page
         if ($pageInfo !== false && isset($pageInfo['navigation_title'])) {
             // only add pages that aren't direct actions
             if ($pageInfo['tree_type'] != 'direct_action') {
                 // get URL
                 $pageURL = FrontendNavigation::getUrl($menuId);
                 // if this is the error-page, so we won't show an URL.
                 if ($pageURL == $errorURL) {
                     $pageURL = null;
                 }
                 // add to the items
                 $items[] = array('title' => $pageInfo['navigation_title'], 'url' => $pageURL);
             }
         }
         // remove element
         array_pop($pages);
     }
     // reverse so everything is in place
     krsort($items);
     // loop and add elements
     foreach ($items as $row) {
         $this->addElement($row['title'], $row['url']);
     }
 }
예제 #15
0
 /**
  * Execute the extra.
  *
  * @return	void
  */
 public function execute()
 {
     // profile logged in
     if (FrontendProfilesAuthentication::isLoggedIn()) {
         // load parent
         parent::execute();
         // get data
         $this->getData();
         // load template
         $this->loadTemplate();
         // load
         $this->loadForm();
         // validate
         $this->validateForm();
         // parse
         $this->parse();
     } else {
         $this->redirect(FrontendNavigation::getURL(404));
     }
 }
예제 #16
0
    /**
     * Parse the search results for this module
     *
     * Note: a module's search function should always:
     * 		- accept an array of entry id's
     * 		- return only the entries that are allowed to be displayed, with their array's index being the entry's id
     *
     * @return	array
     * @param	array $ids		The ids of the found results.
     */
    public static function search(array $ids)
    {
        // get db
        $db = FrontendModel::getDB();
        // define ids's to ignore
        $ignore = array(404);
        // get items
        $items = (array) $db->getRecords('SELECT p.id, p.title, m.url, p.revision_id AS text
											FROM pages AS p
											INNER JOIN meta AS m ON p.meta_id = m.id
											INNER JOIN pages_templates AS t ON p.template_id = t.id
											WHERE p.id IN (' . implode(', ', $ids) . ') AND p.id NOT IN (' . implode(', ', $ignore) . ') AND p.status = ? AND p.hidden = ? AND p.language = ?', array('active', 'N', FRONTEND_LANGUAGE), 'id');
        // prepare items for search
        foreach ($items as &$item) {
            $item['text'] = implode(' ', (array) $db->getColumn('SELECT pb.html
																	FROM pages_blocks AS pb
																	WHERE pb.revision_id = ? AND pb.status = ?', array($item['text'], 'active')));
            $item['full_url'] = FrontendNavigation::getURL($item['id']);
        }
        // return
        return $items;
    }
예제 #17
0
 /**
  * Load the data, don't forget to validate the incoming data
  *
  * @return	void
  */
 private function getData()
 {
     // requested page
     $requestedPage = $this->URL->getParameter('page', 'int', 1);
     // set URL and limit
     $this->pagination['url'] = FrontendNavigation::getURLForBlock('blog');
     $this->pagination['limit'] = FrontendModel::getModuleSetting('blog', 'overview_num_items', 10);
     // populate count fields in pagination
     $this->pagination['num_items'] = FrontendBlogModel::getAllCount();
     $this->pagination['num_pages'] = (int) ceil($this->pagination['num_items'] / $this->pagination['limit']);
     // num pages is always equal to at least 1
     if ($this->pagination['num_pages'] == 0) {
         $this->pagination['num_pages'] = 1;
     }
     // redirect if the request page doesn't exist
     if ($requestedPage > $this->pagination['num_pages'] || $requestedPage < 1) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // populate calculated fields in pagination
     $this->pagination['requested_page'] = $requestedPage;
     $this->pagination['offset'] = $this->pagination['requested_page'] * $this->pagination['limit'] - $this->pagination['limit'];
     // get articles
     $this->items = FrontendBlogModel::getAll($this->pagination['limit'], $this->pagination['offset']);
 }
예제 #18
0
 /**
  * Load the data, don't forget to validate the incoming data
  */
 private function getData()
 {
     // get parameters
     $this->year = $this->URL->getParameter(1);
     $this->month = $this->URL->getParameter(2);
     // redirect /2010/6 to /2010/06 to avoid duplicate content
     if ($this->month !== null && mb_strlen($this->month) != 2) {
         $queryString = isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '';
         $this->redirect(FrontendNavigation::getURLForBlock('blog', 'archive') . '/' . $this->year . '/' . str_pad($this->month, 2, '0', STR_PAD_LEFT) . $queryString, 301);
     }
     if (mb_strlen($this->year) != 4) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // redefine
     $this->year = (int) $this->year;
     if ($this->month !== null) {
         $this->month = (int) $this->month;
     }
     // validate parameters
     if ($this->year == 0 || $this->month === 0) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // requested page
     $requestedPage = $this->URL->getParameter('page', 'int', 1);
     // rebuild url
     $url = $this->year;
     // build timestamp
     if ($this->month !== null) {
         $this->startDate = gmmktime(00, 00, 00, $this->month, 01, $this->year);
         $this->endDate = gmmktime(23, 59, 59, $this->month, gmdate('t', $this->startDate), $this->year);
         $url .= '/' . str_pad($this->month, 2, '0', STR_PAD_LEFT);
     } else {
         $this->startDate = gmmktime(00, 00, 00, 01, 01, $this->year);
         $this->endDate = gmmktime(23, 59, 59, 12, 31, $this->year);
     }
     // set URL and limit
     $this->pagination['url'] = FrontendNavigation::getURLForBlock('blog', 'archive') . '/' . $url;
     $this->pagination['limit'] = FrontendModel::getModuleSetting('blog', 'overview_num_items', 10);
     // populate count fields in pagination
     $this->pagination['num_items'] = FrontendBlogModel::getAllForDateRangeCount($this->startDate, $this->endDate);
     $this->pagination['num_pages'] = (int) ceil($this->pagination['num_items'] / $this->pagination['limit']);
     // redirect if the request page doesn't exists
     if ($requestedPage > $this->pagination['num_pages'] || $requestedPage < 1) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // populate calculated fields in pagination
     $this->pagination['requested_page'] = $requestedPage;
     $this->pagination['offset'] = $this->pagination['requested_page'] * $this->pagination['limit'] - $this->pagination['limit'];
     // get articles
     $this->items = FrontendBlogModel::getAllForDateRange($this->startDate, $this->endDate, $this->pagination['limit'], $this->pagination['offset']);
 }
예제 #19
0
 /**
  * Load the data
  */
 private function getRealData()
 {
     // no search term = no search
     if (!$this->term) {
         return;
     }
     // set url
     $this->pagination['url'] = FrontendNavigation::getURLForBlock('search') . '?form=search&q=' . $this->term;
     $this->pagination['limit'] = FrontendModel::getModuleSetting('search', 'overview_num_items', 20);
     // populate calculated fields in pagination
     $this->pagination['requested_page'] = $this->requestedPage;
     $this->pagination['offset'] = $this->pagination['requested_page'] * $this->pagination['limit'] - $this->pagination['limit'];
     // get items
     $this->items = FrontendSearchModel::search($this->term, $this->pagination['limit'], $this->pagination['offset']);
     // populate count fields in pagination
     // this is done after actual search because some items might be activated/deactivated (getTotal only does rough checking)
     $this->pagination['num_items'] = FrontendSearchModel::getTotal($this->term);
     $this->pagination['num_pages'] = (int) ceil($this->pagination['num_items'] / $this->pagination['limit']);
     // num pages is always equal to at least 1
     if ($this->pagination['num_pages'] == 0) {
         $this->pagination['num_pages'] = 1;
     }
     // redirect if the request page doesn't exist
     if ($this->requestedPage > $this->pagination['num_pages'] || $this->requestedPage < 1) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // debug mode = no cache
     if (!SPOON_DEBUG) {
         // set cache content
         SpoonFile::setContent($this->cacheFile, "<?php\n" . '$pagination = ' . var_export($this->pagination, true) . ";\n" . '$items = ' . var_export($this->items, true) . ";\n?>");
     }
 }
예제 #20
0
 /**
  * Process the querystring
  *
  * @return	void
  */
 private function processQueryString()
 {
     // store the querystring local, so we don't alter it.
     $queryString = $this->getQueryString();
     // fix GET-parameters
     $getChunks = explode('?', $queryString);
     // are there GET-parameters
     if (isset($getChunks[1])) {
         // get key-value pairs
         $get = explode('&', $getChunks[1]);
         // remove from querystring
         $queryString = str_replace('?' . $getChunks[1], '', $this->getQueryString());
         // loop pairs
         foreach ($get as $getItem) {
             // get key and value
             $getChunks = explode('=', $getItem, 2);
             // key available?
             if (isset($getChunks[0])) {
                 // reset in $_GET
                 $_GET[$getChunks[0]] = isset($getChunks[1]) ? (string) $getChunks[1] : '';
                 // add into parameters
                 if (isset($getChunks[1])) {
                     $this->parameters[(string) $getChunks[0]] = (string) $getChunks[1];
                 }
             }
         }
     }
     // split into chunks
     $chunks = (array) explode('/', $queryString);
     // single language
     if (!SITE_MULTILANGUAGE) {
         // set language id
         $language = FrontendModel::getModuleSetting('core', 'default_language', SITE_DEFAULT_LANGUAGE);
     } else {
         // default value
         $mustRedirect = false;
         // get possible languages
         $possibleLanguages = (array) FrontendLanguage::getActiveLanguages();
         $redirectLanguages = (array) FrontendLanguage::getRedirectLanguages();
         // the language is present in the URL
         if (isset($chunks[0]) && in_array($chunks[0], $possibleLanguages)) {
             // define language
             $language = (string) $chunks[0];
             // try to set a cookie with the language
             try {
                 // set cookie
                 SpoonCookie::set('frontend_language', $language, 7 * 24 * 60 * 60, '/', '.' . $this->getDomain());
             } catch (SpoonCookieException $e) {
                 // settings cookies isn't allowed, because this isn't a real problem we ignore the exception
             }
             // set sessions
             SpoonSession::set('frontend_language', $language);
             // remove the language part
             array_shift($chunks);
         } elseif (SpoonCookie::exists('frontend_language') && in_array(SpoonCookie::get('frontend_language'), $redirectLanguages)) {
             // set languageId
             $language = (string) SpoonCookie::get('frontend_language');
             // redirect is needed
             $mustRedirect = true;
         } else {
             // set languageId & abbreviation
             $language = FrontendLanguage::getBrowserLanguage();
             // try to set a cookie with the language
             try {
                 // set cookie
                 SpoonCookie::set('frontend_language', $language, 7 * 24 * 60 * 60, '/', '.' . $this->getDomain());
             } catch (SpoonCookieException $e) {
                 // settings cookies isn't allowed, because this isn't a real problem we ignore the exception
             }
             // redirect is needed
             $mustRedirect = true;
         }
         // redirect is required
         if ($mustRedirect) {
             // build URL
             $URL = rtrim('/' . $language . '/' . $this->getQueryString(), '/');
             // set header & redirect
             SpoonHTTP::redirect($URL, 301);
         }
     }
     // define the language
     define('FRONTEND_LANGUAGE', $language);
     // sets the localefile
     FrontendLanguage::setLocale($language);
     // list of pageIds & their full URL
     $keys = FrontendNavigation::getKeys();
     // full URL
     $URL = implode('/', $chunks);
     $startURL = $URL;
     // loop until we find the URL in the list of pages
     while (!in_array($URL, $keys)) {
         // remove the last chunk
         array_pop($chunks);
         // redefine the URL
         $URL = implode('/', $chunks);
     }
     // remove language from querystring
     if (SITE_MULTILANGUAGE) {
         $queryString = trim(substr($queryString, strlen($language)), '/');
     }
     // if it's the homepage AND parameters were given (not allowed!)
     if ($URL == '' && $queryString != '') {
         // get 404 URL
         $URL = FrontendNavigation::getURL(404);
         // remove language
         if (SITE_MULTILANGUAGE) {
             $URL = str_replace('/' . $language, '', $URL);
         }
     }
     // set pages
     $URL = trim($URL, '/');
     // currently not in the homepage
     if ($URL != '') {
         // explode in pages
         $pages = explode('/', $URL);
         // reset pages
         $this->setPages($pages);
         // reset parameters
         $this->setParameters(array());
     }
     // set parameters
     $parameters = trim(substr($startURL, strlen($URL)), '/');
     // has at least one parameter
     if ($parameters != '') {
         // parameters will be separated by /
         $parameters = explode('/', $parameters);
         // set parameters
         $this->setParameters($parameters);
     }
     // pageId, parentId & depth
     $pageId = FrontendNavigation::getPageId(implode('/', $this->getPages()));
     $pageInfo = FrontendNavigation::getPageInfo($pageId);
     // invalid page, or parameters but no extra
     if ($pageInfo === false || !empty($parameters) && !$pageInfo['has_extra']) {
         // get 404 URL
         $URL = FrontendNavigation::getURL(404);
         // remove language
         if (SITE_MULTILANGUAGE) {
             $URL = trim(str_replace('/' . $language, '', $URL), '/');
         }
         // currently not in the homepage
         if ($URL != '') {
             // explode in pages
             $pages = explode('/', $URL);
             // reset pages
             $this->setPages($pages);
             // reset parameters
             $this->setParameters(array());
         }
     }
     // is this an internal redirect?
     if (isset($pageInfo['redirect_page_id']) && $pageInfo['redirect_page_id'] != '') {
         // get url for item
         $newPageURL = FrontendNavigation::getURL((int) $pageInfo['redirect_page_id']);
         $errorURL = FrontendNavigation::getURL(404);
         // not an error?
         if ($newPageURL != $errorURL) {
             // redirect
             SpoonHTTP::redirect($newPageURL, $pageInfo['redirect_code']);
         }
     }
     // is this an external redirect?
     if (isset($pageInfo['redirect_url']) && $pageInfo['redirect_url'] != '') {
         // redirect
         SpoonHTTP::redirect($pageInfo['redirect_url'], $pageInfo['redirect_code']);
     }
 }
예제 #21
0
 /**
  * Get the URL for a given pageId & language
  * 	syntax: {$var|geturl:pageId[:language]}
  *
  * @param string $var The string passed from the template.
  * @param int $pageId The id of the page to build the URL for.
  * @param string[optional] $language The language to use, if not provided we will use the loaded language.
  * @return string
  */
 public static function getURL($var, $pageId, $language = null)
 {
     // redefine
     $var = (string) $var;
     $pageId = (int) $pageId;
     $language = $language !== null ? (string) $language : null;
     // return url
     return FrontendNavigation::getURL($pageId, $language);
 }
예제 #22
0
 /**
  * Get navigation HTML
  *
  * @return	string
  * @param	string[optional] $type			The type of navigation the HTML should be build for.
  * @param	int[optional] $parentId			The parentID to start of.
  * @param	int[optional] $depth			The maximum depth to parse.
  * @param	array[optional] $excludeIds		PageIDs to be excluded.
  * @param	bool[optional] $includeChildren	Children can be included regardless of whether we're at the current page.
  * @param	int[optional] $depthCounter		A counter that will hold the current depth.
  */
 public static function getNavigationHTML($type = 'page', $parentId = 0, $depth = null, $excludeIds = array(), $includeChildren = false, $depthCounter = 1)
 {
     // get navigation
     $navigation = self::getNavigation();
     // meta-navigation is requested but meta isn't enabled
     if ($type == 'meta' && !FrontendModel::getModuleSetting('pages', 'meta_navigation', true)) {
         return '';
     }
     // validate
     if (!isset($navigation[$type])) {
         throw new FrontendException('This type (' . $type . ') isn\'t a valid navigation type. Possible values are: page, footer, meta.');
     }
     if (!isset($navigation[$type][$parentId])) {
         throw new FrontendException('The parent (' . $parentId . ') doesn\'t exists.');
     }
     // special construction to merge home with it's immediate children
     $mergedHome = false;
     while (true) {
         // loop elements
         foreach ($navigation[$type][$parentId] as $id => $page) {
             // home is a special item, it should live on the same depth
             if ($page['page_id'] == 1 && !$mergedHome) {
                 // extra checks otherwise exceptions will wbe triggered.
                 if (!isset($navigation[$type][$parentId]) || !is_array($navigation[$type][$parentId])) {
                     $navigation[$type][$parentId] = array();
                 }
                 if (!isset($navigation[$type][$page['page_id']]) || !is_array($navigation[$type][$page['page_id']])) {
                     $navigation[$type][$page['page_id']] = array();
                 }
                 // add children
                 $navigation[$type][$parentId] = array_merge($navigation[$type][$parentId], $navigation[$type][$page['page_id']]);
                 // mark as merged
                 $mergedHome = true;
                 // restart loop
                 continue 2;
             }
             // not hidden
             if ($page['hidden']) {
                 unset($navigation[$type][$parentId][$id]);
                 continue;
             }
             // some ids should be excluded
             if (in_array($page['page_id'], (array) $excludeIds)) {
                 unset($navigation[$type][$parentId][$id]);
                 continue;
             }
             // if the item is in the selected page it should get an selected class
             if (in_array($page['page_id'], self::$selectedPageIds)) {
                 $navigation[$type][$parentId][$id]['selected'] = true;
             } else {
                 $navigation[$type][$parentId][$id]['selected'] = false;
             }
             // add nofollow attribute if needed
             if ($page['no_follow']) {
                 $navigation[$type][$parentId][$id]['nofollow'] = true;
             } else {
                 $navigation[$type][$parentId][$id]['nofollow'] = false;
             }
             // has children and is selected and is desired?
             if (isset($navigation[$type][$page['page_id']]) && $page['page_id'] != 1 && ($navigation[$type][$parentId][$id]['selected'] == true || $includeChildren) && ($depth == null || $depthCounter + 1 <= $depth)) {
                 $navigation[$type][$parentId][$id]['children'] = self::getNavigationHTML($type, $page['page_id'], $depth, $excludeIds, $includeChildren, $depthCounter + 1);
             } else {
                 $navigation[$type][$parentId][$id]['children'] = false;
             }
             // add parent id
             $navigation[$type][$parentId][$id]['parent_id'] = $parentId;
             // add depth
             $navigation[$type][$parentId][$id]['depth'] = $depth;
             // set link
             $navigation[$type][$parentId][$id]['link'] = FrontendNavigation::getURL($page['page_id']);
             // is this an internal redirect?
             if (isset($page['redirect_page_id']) && $page['redirect_page_id'] != '') {
                 $navigation[$type][$parentId][$id]['link'] = FrontendNavigation::getURL((int) $page['redirect_page_id']);
             }
             // is this an external redirect?
             if (isset($page['redirect_url']) && $page['redirect_url'] != '') {
                 $navigation[$type][$parentId][$id]['link'] = $page['redirect_url'];
             }
         }
         // break the loop (it is only used for the special construction with home)
         break;
     }
     // create template
     $tpl = new FrontendTemplate(false);
     // assign navigation to template
     $tpl->assign('navigation', $navigation[$type][$parentId]);
     // return parsed content
     return $tpl->getContent(self::$templatePath, true, true);
 }
예제 #23
0
 /**
  * Load the data, don't forget to validate the incoming data
  */
 protected function loadData()
 {
     $this->id = $this->URL->getParameter(1);
     $this->mailing = FrontendMailmotorModel::get($this->id);
     $this->type = SpoonFilter::getGetValue('type', array('html', 'plain'), 'html');
     $this->forCM = SpoonFilter::getGetValue('cm', array(0, 1), 0, 'bool');
     // no point continueing if the mailing record is not set
     if (empty($this->mailing)) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
 }
예제 #24
0
 /**
  * Get page content
  */
 protected function getPageContent()
 {
     // load revision
     if ($this->URL->getParameter('page_revision', 'int') != 0) {
         // get data
         $this->record = FrontendModel::getPageRevision($this->URL->getParameter('page_revision', 'int'));
         // add no-index to meta-custom, so the draft won't get accidentally indexed
         $this->header->addMetaData(array('name' => 'robots', 'content' => 'noindex, nofollow'), true);
     } else {
         $this->record = (array) FrontendModel::getPage($this->pageId);
     }
     // empty record (pageId doesn't exists, hope this line is never used)
     if (empty($this->record) && $this->pageId != 404) {
         SpoonHTTP::redirect(FrontendNavigation::getURL(404), 404);
     }
     // init var
     $redirect = true;
     // loop blocks, if all are empty we should redirect to the first child
     foreach ($this->record['positions'] as $position => $blocks) {
         // loop blocks in position
         foreach ($blocks as $block) {
             // HTML provided?
             if ($block['html'] != '') {
                 $redirect = false;
             }
             // an decent extra provided?
             if ($block['extra_type'] == 'block') {
                 $redirect = false;
             }
             // a widget provided
             if ($block['extra_type'] == 'widget') {
                 $redirect = false;
             }
         }
     }
     // should we redirect?
     if ($redirect) {
         // get first child
         $firstChildId = FrontendNavigation::getFirstChildId($this->record['id']);
         // validate the child
         if ($firstChildId !== false) {
             // build URL
             $URL = FrontendNavigation::getURL($firstChildId);
             // redirect
             SpoonHTTP::redirect($URL, 301);
         }
     }
 }