예제 #1
0
 /**
  * Get the current action
  * REMARK: You should not use this method from your code, but it has to be public so we can access it later on in the core-code
  *
  * @return	string
  */
 public function getAction()
 {
     // no action specified?
     if ($this->action === null) {
         // get first parameter
         $actionParameter = $this->URL->getParameter(0);
         // unknown action and not provided in URL
         if ($actionParameter === null) {
             $this->setAction($this->config->getDefaultAction());
         } else {
             // loop possible actions
             foreach ($this->config->getPossibleActions() as $actionName) {
                 // get action that should be passed as parameter
                 $actionURL = FL::act(SpoonFilter::toCamelCase($actionName));
                 // the action is the requested one
                 if ($actionURL == $actionParameter) {
                     // set action
                     $this->setAction($actionName);
                     // stop the loop
                     break;
                 }
             }
         }
     }
     // return
     return $this->action;
 }
예제 #2
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // get settings
     $commentsAllowed = isset($this->settings['allow_comments']) && $this->settings['allow_comments'];
     // comments aren't allowed so we don't have to validate
     if (!$commentsAllowed) {
         return false;
     }
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // does the key exists?
         if (SpoonSession::exists('blog_comment_' . $this->record['id'])) {
             // calculate difference
             $diff = time() - (int) SpoonSession::get('blog_comment_' . $this->record['id']);
             // calculate difference, it it isn't 10 seconds the we tell the user to slow down
             if ($diff < 10 && $diff != 0) {
                 $this->frm->getField('message')->addError(FL::err('CommentTimeout'));
             }
         }
         // validate required fields
         $this->frm->getField('author')->isFilled(FL::err('AuthorIsRequired'));
         $this->frm->getField('email')->isEmail(FL::err('EmailIsRequired'));
         $this->frm->getField('message')->isFilled(FL::err('MessageIsRequired'));
         // validate optional fields
         if ($this->frm->getField('website')->isFilled() && $this->frm->getField('website')->getValue() != 'http://') {
             $this->frm->getField('website')->isURL(FL::err('InvalidURL'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // get module setting
             $spamFilterEnabled = isset($this->settings['spamfilter']) && $this->settings['spamfilter'];
             $moderationEnabled = isset($this->settings['moderation']) && $this->settings['moderation'];
             // reformat data
             $author = $this->frm->getField('author')->getValue();
             $email = $this->frm->getField('email')->getValue();
             $website = $this->frm->getField('website')->getValue();
             if (trim($website) == '' || $website == 'http://') {
                 $website = null;
             }
             $text = $this->frm->getField('message')->getValue();
             // build array
             $comment['post_id'] = $this->record['id'];
             $comment['language'] = FRONTEND_LANGUAGE;
             $comment['created_on'] = FrontendModel::getUTCDate();
             $comment['author'] = $author;
             $comment['email'] = $email;
             $comment['website'] = $website;
             $comment['text'] = $text;
             $comment['status'] = 'published';
             $comment['data'] = serialize(array('server' => $_SERVER));
             // get URL for article
             $permaLink = FrontendNavigation::getURLForBlock('blog', 'detail') . '/' . $this->record['url'];
             $redirectLink = $permaLink;
             // is moderation enabled
             if ($moderationEnabled) {
                 // if the commenter isn't moderated before alter the comment status so it will appear in the moderation queue
                 if (!FrontendBlogModel::isModerated($author, $email)) {
                     $comment['status'] = 'moderation';
                 }
             }
             // should we check if the item is spam
             if ($spamFilterEnabled) {
                 // check for spam
                 $result = FrontendModel::isSpam($text, SITE_URL . $permaLink, $author, $email, $website);
                 // if the comment is spam alter the comment status so it will appear in the spam queue
                 if ($result) {
                     $comment['status'] = 'spam';
                 } elseif ($result == 'unknown') {
                     $comment['status'] = 'moderation';
                 }
             }
             // insert comment
             $comment['id'] = FrontendBlogModel::insertComment($comment);
             // trigger event
             FrontendModel::triggerEvent('blog', 'after_add_comment', array('comment' => $comment));
             // append a parameter to the URL so we can show moderation
             if (strpos($redirectLink, '?') === false) {
                 if ($comment['status'] == 'moderation') {
                     $redirectLink .= '?comment=moderation#' . FL::act('Comment');
                 }
                 if ($comment['status'] == 'spam') {
                     $redirectLink .= '?comment=spam#' . FL::act('Comment');
                 }
                 if ($comment['status'] == 'published') {
                     $redirectLink .= '?comment=true#comment-' . $comment['id'];
                 }
             } else {
                 if ($comment['status'] == 'moderation') {
                     $redirectLink .= '&comment=moderation#' . FL::act('Comment');
                 }
                 if ($comment['status'] == 'spam') {
                     $redirectLink .= '&comment=spam#' . FL::act('Comment');
                 }
                 if ($comment['status'] == 'published') {
                     $redirectLink .= '&comment=true#comment-' . $comment['id'];
                 }
             }
             // set title
             $comment['post_title'] = $this->record['title'];
             $comment['post_url'] = $this->record['url'];
             // notify the admin
             FrontendBlogModel::notifyAdmin($comment);
             // store timestamp in session so we can block excesive usage
             SpoonSession::set('blog_comment_' . $this->record['id'], time());
             // store author-data in cookies
             try {
                 SpoonCookie::set('comment_author', $author, 30 * 24 * 60 * 60, '/', '.' . $this->URL->getDomain());
                 SpoonCookie::set('comment_email', $email, 30 * 24 * 60 * 60, '/', '.' . $this->URL->getDomain());
                 SpoonCookie::set('comment_website', $website, 30 * 24 * 60 * 60, '/', '.' . $this->URL->getDomain());
             } catch (Exception $e) {
                 // settings cookies isn't allowed, but because this isn't a real problem we ignore the exception
             }
             // redirect
             $this->redirect($redirectLink);
         }
     }
 }
예제 #3
0
 /**
  * Get the locale that is used in the frontend but doesn't exists.
  *
  * @param string $language The language to check.
  * @return array
  */
 public static function getNonExistingFrontendLocale($language)
 {
     // get files to process
     $tree = self::getTree(FRONTEND_PATH);
     $used = array();
     // loop files
     foreach ($tree as $file) {
         // grab content
         $content = SpoonFile::getContent($file);
         // process the file based on extension
         switch (SpoonFile::getExtension($file)) {
             // javascript file
             case 'js':
                 $matches = array();
                 // get matches
                 preg_match_all('/\\{\\$(act|err|lbl|msg)(.*)(\\|.*)?\\}/iU', $content, $matches);
                 // any matches?
                 if (isset($matches[2])) {
                     // loop matches
                     foreach ($matches[2] as $key => $match) {
                         // set type
                         $type = $matches[1][$key];
                         // init if needed
                         if (!isset($used[$match])) {
                             $used[$type][$match] = array('files' => array());
                         }
                         // add file
                         if (!in_array($file, $used[$type][$match]['files'])) {
                             $used[$type][$match]['files'][] = $file;
                         }
                     }
                 }
                 break;
                 // PHP file
             // PHP file
             case 'php':
                 $matches = array();
                 // get matches
                 preg_match_all('/(FrontendLanguage|FL)::(get(Action|Label|Error|Message)|act|lbl|err|msg)\\(\'(.*)\'\\)/iU', $content, $matches);
                 // any matches?
                 if (!empty($matches[4])) {
                     // loop matches
                     foreach ($matches[4] as $key => $match) {
                         $type = 'lbl';
                         if ($matches[3][$key] == 'Action') {
                             $type = 'act';
                         }
                         if ($matches[2][$key] == 'act') {
                             $type = 'act';
                         }
                         if ($matches[3][$key] == 'Error') {
                             $type = 'err';
                         }
                         if ($matches[2][$key] == 'err') {
                             $type = 'err';
                         }
                         if ($matches[3][$key] == 'Message') {
                             $type = 'msg';
                         }
                         if ($matches[2][$key] == 'msg') {
                             $type = 'msg';
                         }
                         // init if needed
                         if (!isset($used[$type][$match])) {
                             $used[$type][$match] = array('files' => array());
                         }
                         // add file
                         if (!in_array($file, $used[$type][$match]['files'])) {
                             $used[$type][$match]['files'][] = $file;
                         }
                     }
                 }
                 break;
                 // template file
             // template file
             case 'tpl':
                 $matches = array();
                 // get matches
                 preg_match_all('/\\{\\$(act|err|lbl|msg)([a-z-_]*)(\\|.*)?\\}/iU', $content, $matches);
                 // any matches?
                 if (isset($matches[2])) {
                     // loop matches
                     foreach ($matches[2] as $key => $match) {
                         // set type
                         $type = $matches[1][$key];
                         // init if needed
                         if (!isset($used[$type][$match])) {
                             $used[$type][$match] = array('files' => array());
                         }
                         // add file
                         if (!in_array($file, $used[$type][$match]['files'])) {
                             $used[$type][$match]['files'][] = $file;
                         }
                     }
                 }
                 break;
         }
     }
     // init var
     $nonExisting = array();
     // set language
     FrontendLanguage::setLocale($language);
     // check if the locale is present in the current language
     foreach ($used as $type => $items) {
         // loop items
         foreach ($items as $key => $data) {
             // process based on type
             switch ($type) {
                 case 'act':
                     // if the action isn't available add it to the list
                     if (FL::act($key) == '{$' . $type . $key . '}') {
                         $nonExisting['frontend' . $key . $type] = array('language' => $language, 'application' => 'frontend', 'module' => 'core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files']));
                     }
                     break;
                 case 'err':
                     // if the error isn't available add it to the list
                     if (FL::err($key) == '{$' . $type . $key . '}') {
                         $nonExisting['frontend' . $key . $type] = array('language' => $language, 'application' => 'frontend', 'module' => 'core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files']));
                     }
                     break;
                 case 'lbl':
                     // if the label isn't available add it to the list
                     if (FL::lbl($key) == '{$' . $type . $key . '}') {
                         $nonExisting['frontend' . $key . $type] = array('language' => $language, 'application' => 'frontend', 'module' => 'core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files']));
                     }
                     break;
                 case 'msg':
                     // if the message isn't available add it to the list
                     if (FL::msg($key) == '{$' . $type . $key . '}') {
                         $nonExisting['frontend' . $key . $type] = array('language' => $language, 'application' => 'frontend', 'module' => 'core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files']));
                     }
                     break;
             }
         }
     }
     ksort($nonExisting);
     return $nonExisting;
 }
예제 #4
0
 /**
  * Get the URL for a give module & action combination
  *
  * @return	string
  * @param	string $module					The module wherefor the URL should be build.
  * @param	string[optional] $action		The specific action wherefor the URL shoul be build.
  * @param	string[optional] $language		The language wherein the URL should be retrieved, if not provided we will load the language that was provided in the URL.
  */
 public static function getURLForBlock($module, $action = null, $language = null)
 {
     // redefine
     $module = (string) $module;
     $action = $action !== null ? (string) $action : null;
     $language = $language !== null ? (string) $language : FRONTEND_LANGUAGE;
     // init var
     $pageIdForURL = null;
     // get the menuItems
     $navigation = self::getNavigation($language);
     // loop types
     foreach ($navigation as $level) {
         // loop level
         foreach ($level as $pages) {
             // loop pages
             foreach ($pages as $pageId => $properties) {
                 // only process pages with extra_blocks
                 if (isset($properties['extra_blocks'])) {
                     // loop extras
                     foreach ($properties['extra_blocks'] as $extra) {
                         // direct link?
                         if ($extra['module'] == $module && $extra['action'] == $action) {
                             // exact page was found, so return
                             return self::getURL($properties['page_id'], $language);
                         } elseif ($extra['module'] == $module && $extra['action'] == null) {
                             // store pageId
                             $pageIdForURL = (int) $pageId;
                         }
                     }
                 }
             }
         }
     }
     // pageId stored?
     if ($pageIdForURL !== null) {
         // build URL
         $URL = self::getURL($pageIdForURL, $language);
         // append action
         $URL .= '/' . FL::act(SpoonFilter::toCamelCase($action));
         // return the URL
         return $URL;
     }
     // fallback
     return self::getURL(404, $language);
 }
예제 #5
0
 /**
  * Get the URL for a give module & action combination
  *
  * @param string $module The module to get the URL for.
  * @param string[optional] $action The action to get the URL for.
  * @param string[optional] $language The language to use, if not provided we will use the working language.
  * @return string
  */
 public static function getURLForBlock($module, $action = null, $language = null)
 {
     $module = (string) $module;
     $action = $action !== null ? (string) $action : null;
     $language = $language !== null ? (string) $language : BackendLanguage::getWorkingLanguage();
     // init var
     $pageIdForURL = null;
     // get the menuItems
     $navigation = self::getNavigation($language);
     // loop types
     foreach ($navigation as $level) {
         foreach ($level as $pages) {
             foreach ($pages as $pageId => $properties) {
                 // only process pages with extra_blocks
                 if (isset($properties['extra_blocks'])) {
                     // loop extras
                     foreach ($properties['extra_blocks'] as $extra) {
                         // direct link?
                         if ($extra['module'] == $module && $extra['action'] == $action) {
                             // exacte page was found, so return
                             return self::getURL($properties['page_id'], $language);
                         } elseif ($extra['module'] == $module && $extra['action'] == null) {
                             // store pageId
                             $pageIdForURL = (int) $pageId;
                         }
                     }
                 }
             }
         }
     }
     // still no page id?
     if ($pageIdForURL === null) {
         return self::getURL(404);
     }
     // build URL
     $URL = self::getURL($pageIdForURL, $language);
     // set locale
     FrontendLanguage::setLocale($language);
     // append action
     $URL .= '/' . urldecode(FL::act(SpoonFilter::toCamelCase($action)));
     // return the unique URL!
     return $URL;
 }