act() public static method

Get an action from the language-file
public static act ( string $key, boolean $fallback = true ) : string
$key string The key to get.
$fallback boolean Should we provide a fallback in English?
return string
Esempio n. 1
0
 /**
  * Get an action from the language-file
  *
  * @param string $key      The key to get.
  * @param bool   $fallback Should we provide a fallback in English?
  *
  * @return string
  */
 public static function act($key, $fallback = true)
 {
     trigger_error('Frontend\\Core\\Engine\\Language is deprecated.
          It has been moved to Frontend\\Core\\Language\\Language', E_USER_DEPRECATED);
     return parent::act($key, $fallback);
 }
Esempio n. 2
0
 /**
  * Get the URL for a give module & action combination
  *
  * @param string $module   The module wherefore the URL should be build.
  * @param string $action   The specific action wherefore the URL should be build.
  * @param string $language The language wherein the URL should be retrieved,
  *                         if not provided we will load the language that was provided in the URL.
  * @param array $data      An array with keys and values that partially or fully match the data of the block.
  *                         If it matches multiple versions of that block it will just return the first match.
  *
  * @return string
  */
 public static function getURLForBlock($module, $action = null, $language = null, array $data = null)
 {
     $module = (string) $module;
     $action = $action !== null ? (string) $action : null;
     $language = $language !== null ? (string) $language : BackendLanguage::getWorkingLanguage();
     $pageIdForURL = null;
     $navigation = self::getNavigation($language);
     $dataMatch = false;
     // 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 that are visible
                 if (!isset($properties['extra_blocks']) || $properties['hidden']) {
                     continue;
                 }
                 // loop extras
                 foreach ($properties['extra_blocks'] as $extra) {
                     // direct link?
                     if ($extra['module'] == $module && $extra['action'] == $action && $extra['action'] !== null) {
                         // if there is data check if all the requested data matches the extra data
                         if (isset($extra['data']) && $data !== null && array_intersect_assoc($data, (array) $extra['data']) !== $data) {
                             // It is the correct action but has the wrong data
                             continue;
                         }
                         // exact page was found, so return
                         return self::getURL($properties['page_id'], $language);
                     }
                     if ($extra['module'] == $module && $extra['action'] == null) {
                         // if there is data check if all the requested data matches the extra data
                         if (isset($extra['data']) && $data !== null) {
                             if (array_intersect_assoc($data, (array) $extra['data']) !== $data) {
                                 // It is the correct module but has the wrong data
                                 continue;
                             }
                             $pageIdForURL = (int) $pageId;
                             $dataMatch = true;
                         }
                         if ($extra['data'] === null && $data === null) {
                             $pageIdForURL = (int) $pageId;
                             $dataMatch = true;
                         }
                         if (!$dataMatch) {
                             $pageIdForURL = (int) $pageId;
                         }
                     }
                 }
             }
         }
     }
     // still no page id?
     if ($pageIdForURL === null) {
         return self::getURL(404, $language);
     }
     $url = self::getURL($pageIdForURL, $language);
     // set locale with force
     FrontendLanguage::setLocale($language, true);
     // append action
     if ($action !== null) {
         $url .= '/' . urldecode(FrontendLanguage::act(\SpoonFilter::toCamelCase($action)));
     }
     // return the unique URL!
     return $url;
 }
Esempio n. 3
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 {
             // action provided in the URL
             // loop possible actions
             $actionParameter = \SpoonFilter::toCamelCase($actionParameter);
             foreach ($this->config->getPossibleActions() as $actionName) {
                 // get action that should be passed as parameter
                 $actionURL = \SpoonFilter::toCamelCase(rawurlencode(FL::act(\SpoonFilter::toCamelCase($actionName))));
                 // the action is the requested one
                 if ($actionURL == $actionParameter) {
                     // set action
                     $this->setAction($actionName);
                     // stop the loop
                     break;
                 }
             }
         }
     }
     return $this->action;
 }
Esempio n. 4
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'] = 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 = $this->record['full_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') {
                     // if the status is unknown then we should moderate it manually
                     $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 (mb_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 excessive usage
             \SpoonSession::set('blog_comment_' . $this->record['id'], time());
             // store author-data in cookies
             try {
                 CommonCookie::set('comment_author', $author);
                 CommonCookie::set('comment_email', $email);
                 CommonCookie::set('comment_website', $website);
             } catch (\Exception $e) {
                 // settings cookies isn't allowed, but because this isn't a real problem we ignore the exception
             }
             // redirect
             $this->redirect($redirectLink);
         }
     }
 }