Deprecation:
Inheritance: extends Frontend\Core\Language\Language
Ejemplo n.º 1
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $fields = $this->frm->getFields();
         if ($fields['email']->isEmail(FL::err('EmailIsInvalid'))) {
         }
         if (FrontendMailengineModel::isSubscribed($fields['email']->getValue())) {
             $fields['email']->addError(FL::err('AlreadySubscribed'));
         }
         if ($this->frm->isCorrect()) {
             //--Subscribe
             $id = FrontendMailengineModel::subscribe($fields['email']->getValue());
             //--Get the default group
             $defaultGroup = FrontendModel::getModuleSetting($this->module, 'default_group');
             if ($defaultGroup > 0) {
                 $data = array();
                 $data['user_id'] = $id;
                 $data['group_id'] = $defaultGroup;
                 //--Add user to group
                 FrontendMailengineModel::insertUserToGroup($data);
             }
             // redirect
             $this->redirect(FrontendNavigation::getURLForBlock('Mailengine', 'MailengineSubscribe') . '?sent=true#subscribe');
         }
     }
     $this->frm->parse($this->tpl);
 }
Ejemplo n.º 2
0
 /**
  * Parse the data into the template
  */
 private function parse()
 {
     // get vars
     $title = \SpoonFilter::ucfirst(FL::msg('BlogAllComments'));
     $link = SITE_URL . FrontendNavigation::getURLForBlock('Blog');
     $detailLink = SITE_URL . FrontendNavigation::getURLForBlock('Blog', 'Detail');
     $description = null;
     // create new rss instance
     $rss = new FrontendRSS($title, $link, $description);
     // loop articles
     foreach ($this->items as $item) {
         // init vars
         $title = $item['author'] . ' ' . FL::lbl('On') . ' ' . $item['post_title'];
         $link = $detailLink . '/' . $item['post_url'] . '/#comment-' . $item['id'];
         $description = $item['text'];
         // create new instance
         $rssItem = new FrontendRSSItem($title, $link, $description);
         // set item properties
         $rssItem->setPublicationDate($item['created_on']);
         $rssItem->setAuthor($item['author']);
         // add item
         $rss->addItem($rssItem);
     }
     $rss->parse();
 }
Ejemplo n.º 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));
     }
     // 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) {
         // get the ids of the items linked to the tag
         $otherIds = (array) $this->get('database')->getColumn('SELECT other_id
              FROM modules_tags
              WHERE module = ? AND tag_id = ?', array($module, $this->record['id']));
         // set module class
         $class = 'Frontend\\Modules\\' . $module . '\\Engine\\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);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Parse the data into the template
  */
 private function parse()
 {
     // get vars
     $title = isset($this->settings['rss_title_' . FRONTEND_LANGUAGE]) ? $this->settings['rss_title_' . FRONTEND_LANGUAGE] : $this->get('fork.settings')->get('Blog', 'rss_title_' . FRONTEND_LANGUAGE, SITE_DEFAULT_TITLE);
     $link = SITE_URL . FrontendNavigation::getURLForBlock('Blog');
     $description = isset($this->settings['rss_description_' . FRONTEND_LANGUAGE]) ? $this->settings['rss_description_' . FRONTEND_LANGUAGE] : null;
     // create new rss instance
     $rss = new FrontendRSS($title, $link, $description);
     // loop articles
     foreach ($this->items as $item) {
         // init vars
         $title = $item['title'];
         $link = $item['full_url'];
         $description = $item['introduction'] != '' ? $item['introduction'] : $item['text'];
         // meta is wanted
         if ($this->get('fork.settings')->get('Blog', 'rss_meta_' . FRONTEND_LANGUAGE, true)) {
             // append meta
             $description .= '<div class="meta">' . "\n";
             $description .= '	<p><a href="' . $link . '" title="' . $title . '">' . $title . '</a> ' . sprintf(FL::msg('WrittenBy'), FrontendUser::getBackendUser($item['user_id'])->getSetting('nickname'));
             $description .= ' ' . FL::lbl('In') . ' <a href="' . $item['category_full_url'] . '" title="' . $item['category_title'] . '">' . $item['category_title'] . '</a>.</p>' . "\n";
             // any tags
             if (isset($item['tags'])) {
                 // append tags-paragraph
                 $description .= '	<p>' . \SpoonFilter::ucfirst(FL::lbl('Tags')) . ': ';
                 $first = true;
                 // loop tags
                 foreach ($item['tags'] as $tag) {
                     // prepend separator
                     if (!$first) {
                         $description .= ', ';
                     }
                     // add
                     $description .= '<a href="' . $tag['full_url'] . '" rel="tag" title="' . $tag['name'] . '">' . $tag['name'] . '</a>';
                     // reset
                     $first = false;
                 }
                 // end
                 $description .= '.</p>' . "\n";
             }
             // end HTML
             $description .= '</div>' . "\n";
         }
         // create new instance
         $rssItem = new FrontendRSSItem($title, $link, $description);
         // set item properties
         $rssItem->setPublicationDate($item['publish_on']);
         $rssItem->addCategory($item['category_title']);
         $rssItem->setAuthor(FrontendUser::getBackendUser($item['user_id'])->getSetting('nickname'));
         // add item
         $rss->addItem($rssItem);
     }
     // output
     $rss->parse();
 }
Ejemplo n.º 5
0
 /**
  * Contstructor
  *
  */
 public function execute()
 {
     parent::execute();
     //--Set post var to check submit
     $_POST["form"] = "add_image";
     //--Set module
     $module = (string) \SpoonFilter::getPostValue('mediaModule', null, '', 'string');
     //--Set action
     $action = (string) \SpoonFilter::getPostValue('mediaAction', null, '', 'string');
     //--Set the id
     $id = (int) \SpoonFilter::getPostValue('mediaId', null, '', 'int');
     //--Set the type
     $type = (string) \SpoonFilter::getPostValue('mediaType', null, '', 'string');
     //--Create media helper
     $this->media = new BackendMediaHelper(new BackendForm('add_image', null, 'post', false), $module, $id, $action, $type);
     //--Validate media -> upload file
     $this->media->validate();
     //--File is image
     if ($this->media->item['filetype'] == 1) {
         //Create html
         $tpl = new Template();
         $this->media->item['txtText'] = $this->media->frm->addTextarea("text-" . $this->media->item["id"], $this->media->item['text'])->setAttribute('style', 'resize: none;')->parse();
         //--Get file info (ext, filename, path)
         $path_parts = pathinfo(FRONTEND_FILES_PATH . '/Media/Images/Source/' . $this->media->item['filename']);
         $this->media->item['name'] = $path_parts['filename'];
         $folders = BackendModel::getThumbnailFolders(FRONTEND_FILES_PATH . '/Media/Images', true);
         foreach ($folders as $folder) {
             $this->media->item['image_' . $folder['dirname']] = $folder['url'] . '/' . $folder['dirname'] . '/' . $this->media->item['filename'];
         }
         $tpl->assign('mediaItems', array('images' => array($this->media->item)));
         $html = $tpl->getContent(BACKEND_MODULES_PATH . '/Media/Layout/Templates/Ajax/Image.tpl');
         //--File is file
     } else {
         //Create html
         $tpl = new Template();
         $this->media->item['txtText'] = $this->media->frm->addTextarea("text-" . $this->media->item["id"], $this->media->item['text'])->setAttribute('style', 'resize: none;')->parse();
         //--Get file info (ext, filename, path)
         $path_parts = pathinfo(FRONTEND_FILES_PATH . '/Media/Files/' . $this->media->item['filename']);
         $this->media->item['url'] = FRONTEND_FILES_URL . '/Media/Files/' . $this->media->item['filename'];
         $this->media->item['name'] = $path_parts['filename'];
         $tpl->assign('mediaItems', array('files' => array($this->media->item)));
         $html = $tpl->getContent(BACKEND_MODULES_PATH . '/Media/Layout/Templates/Ajax/File.tpl');
     }
     // output (filetype, html)
     $this->output(self::OK, array($this->media->item['filetype'], $html), FrontendLanguage::msg('Success'));
 }
Ejemplo n.º 6
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $fields = $this->frm->getFields();
         if ($fields['email']->isEmail(FL::err('EmailIsInvalid'))) {
         }
         if (!FrontendMailengineModel::isSubscribed($fields['email']->getValue())) {
             $fields['email']->addError(FL::err('NotSubscribed'));
         }
         if ($this->frm->isCorrect()) {
             //--Subscribe
             FrontendMailengineModel::unsubscribe($fields['email']->getValue());
             // redirect
             $this->redirect(FrontendNavigation::getURLForBlock('Mailengine', 'MailengineUnsubscribe') . '?sent=true#unsubscribe');
         }
     }
     $this->frm->parse($this->tpl);
 }
Ejemplo n.º 7
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // validate required fields
         $email = $this->frm->getField('email');
         // validate required fields
         if ($email->isEmail(FL::err('EmailIsInvalid'))) {
             if (FrontendMailmotorModel::isSubscribed($email->getValue())) {
                 $email->addError(FL::err('AlreadySubscribed'));
             }
         }
         // no errors
         if ($this->frm->isCorrect()) {
             try {
                 // subscribe the user to our default group
                 if (!FrontendMailmotorCMHelper::subscribe($email->getValue())) {
                     throw new FrontendException('Could not subscribe');
                 }
                 // trigger event
                 FrontendModel::triggerEvent('Mailmotor', 'after_subscribe', array('email' => $email->getValue()));
                 // redirect
                 $this->redirect(FrontendNavigation::getURLForBlock('Mailmotor', 'Subscribe') . '?sent=true#subscribeForm');
             } catch (\Exception $e) {
                 // make sure RedirectExceptions get thrown
                 if ($e instanceof RedirectException) {
                     throw $e;
                 }
                 // when debugging we need to see the exceptions
                 if ($this->getContainer()->getParameter('kernel.debug')) {
                     throw $e;
                 }
                 // show error
                 $this->tpl->assign('subscribeHasError', true);
             }
         } else {
             $this->tpl->assign('subscribeHasFormError', true);
         }
     }
 }
 /**
  * @param FormBuilderSubmittedEvent $event
  */
 public function onFormSubmitted(FormBuilderSubmittedEvent $event)
 {
     $form = $event->getForm();
     // need to send mail
     if ($form['method'] == 'database_email') {
         // build our message
         $from = FrontendModel::get('fork.settings')->get('Core', 'mailer_from');
         $fieldData = $this->getEmailFields($event->getData());
         $message = \Common\Mailer\Message::newInstance(sprintf(FL::getMessage('FormBuilderSubject'), $form['name']))->parseHtml(FRONTEND_MODULES_PATH . '/FormBuilder/Layout/Templates/Mails/Form.tpl', array('sentOn' => time(), 'name' => $form['name'], 'fields' => $fieldData), true)->setTo($form['email'])->setFrom(array($from['email'] => $from['name']));
         // check if we have a replyTo email set
         foreach ($form['fields'] as $field) {
             if (array_key_exists('reply_to', $field['settings']) && $field['settings']['reply_to'] === true) {
                 $email = $fieldData[$field['id']]['value'];
                 $message->setReplyTo(array($email => $email));
             }
         }
         if ($message->getReplyTo() === null) {
             $replyTo = FrontendModel::get('fork.settings')->get('Core', 'mailer_reply_to');
             $message->setReplyTo(array($replyTo['email'] => $replyTo['name']));
         }
         $this->mailer->send($message);
     }
 }
 /**
  * Returns the mailchimp object.
  *
  * @return mailchimp
  */
 public static function getMC()
 {
     // mailchimp reference exists
     if (!\Spoon::exists('mailchimp')) {
         // check if the mailchimp class exists
         if (!\SpoonFile::exists(PATH_LIBRARY . '/external/mcapi.php')) {
             // the class doesn't exist, so throw an exception
             throw new \SpoonFileException(sprintf(FL::err('ClassDoesNotExist'), 'mailchimp'));
         }
         // require mailchimp class
         require_once PATH_LIBRARY . '/external/mcapi.php';
         // set login data
         $key = FrontendModel::getModuleSetting('MailMotor', 'api_key');
         if (empty($key)) {
             throw new \Exception('Mailmotor api_key is required.');
         }
         // init mailchimp object
         $mc = new \MCAPI($key);
         // set mailchimp object reference
         \Spoon::set('mailchimp', $mc);
     }
     // return the CampaignMonitor object
     return \Spoon::get('mailchimp');
 }
Ejemplo n.º 10
0
 /**
  * Parse the default error messages
  */
 private function parseErrorMessages()
 {
     // set frontend locale
     FL::setLocale(BL::getWorkingLanguage(), true);
     // assign error messages
     $this->tpl->assign('errors', BackendFormBuilderModel::getErrors());
 }
Ejemplo n.º 11
0
 /**
  * Parse the languages
  */
 protected function parseLanguages()
 {
     // just execute if the site is multi-language
     if ($this->getContainer()->getParameter('site.multilanguage')) {
         // get languages
         $activeLanguages = Language::getActiveLanguages();
         // init var
         $languages = array();
         // loop active languages
         foreach ($activeLanguages as $language) {
             // build temp array
             $temp = array();
             $temp['url'] = '/' . $language;
             $temp['label'] = $language;
             $temp['name'] = Language::msg(strtoupper($language));
             $temp['current'] = (bool) ($language == FRONTEND_LANGUAGE);
             // add
             $languages[] = $temp;
         }
         // assign
         if (count($languages) > 1) {
             $this->tpl->assign('languages', $languages);
         }
     }
 }
Ejemplo n.º 12
0
 /**
  *
  * Get all the users for a group
  *
  * @param $id
  *
  * @return array()
  */
 public static function getAddressesForGroup($id, $search = "", $orderby = false)
 {
     $strOr = "";
     $strWhere = "";
     $strOrderBy = "";
     if ($orderby != false) {
         $strOrderBy = " ORDER BY " . $orderby;
     }
     //--Check if search is filled in
     if ($search != "") {
         $returnTemp = array();
         //--Search fields
         $fields = array("company", "address", "zipcode", "city", "fax", "website", "email");
         $arrSearch = explode(" ", $search);
         foreach ($arrSearch as $rowSearch) {
             //--Reset or
             $strOr = '';
             $strWhere = " AND (";
             //--Loop all the field to search in
             foreach ($fields as $field) {
                 $strWhere .= $strOr . " {$field} LIKE '%" . $rowSearch . "%'";
                 $strOr = " OR ";
             }
             $strWhere .= ")";
             $returnSearch = FrontendModel::getContainer()->get('database')->getRecords("SELECT i.address_id, a.name, a.firstname, a.company, a.address, a.zipcode, a.city, a.country, a.phone, a.fax, a.email, a.website, a.lat, a.lng, a.contact, a.assort, a.vat, a.size, a.open, a.closed, a.visit, m.url, m.data as meta_data\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM addresses_in_group AS i\n\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN addresses AS a ON a.id = i.address_id\n\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN meta AS m ON m.id = a.meta_id\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE i.group_id = ? AND a.hidden=? {$strWhere} {$strOrderBy}", array($id, 'N'));
             if (!empty($returnSearch)) {
                 $returnTemp = array_merge($returnTemp, $returnSearch);
             }
         }
         if (!empty($returnTemp)) {
             foreach ($returnTemp as $key => $row) {
                 $return[$row['address_id']] = $row;
             }
         }
     } else {
         $return = FrontendModel::getContainer()->get('database')->getRecords("SELECT i.address_id, a.name, a.firstname, a.company, a.address, a.zipcode, a.city, a.country, a.phone, a.fax, a.email, a.website, a.lat, a.lng, a.contact, a.assort, a.vat, a.size, a.open, a.closed, a.visit, m.url, m.data as meta_data\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM addresses_in_group AS i\n\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN addresses AS a ON a.id = i.address_id\n\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN meta AS m ON m.id = a.meta_id\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE i.group_id = ? AND a.hidden=? {$strWhere} {$strOrderBy}", array($id, 'N'));
     }
     //--Get link for the categories
     $detailLink = FrontendNavigation::getURLForBlock('Addresses', 'Detail');
     //--Get folders
     $folders = FrontendModel::getThumbnailFolders(FRONTEND_FILES_PATH . '/addresses/images', true);
     if (!empty($return)) {
         // loop items and unserialize
         foreach ($return as &$row) {
             $row['company'] = self::replaceCharacters($row['company']);
             $row['full_url'] = "/" . strtolower(FRONTEND_LANGUAGE) . "/" . FL::getAction('Adressen') . '/' . FL::getAction('detail') . '/' . $row['url'];
             if (isset($row['meta_data'])) {
                 $row['meta_data'] = @unserialize($row['meta_data']);
             }
             // image?
             if (isset($row['image'])) {
                 foreach ($folders as $folder) {
                     $row['image_' . $folder['dirname']] = $folder['url'] . '/' . $folder['dirname'] . '/' . $row['image'];
                 }
             }
         }
     }
     return $return;
 }
Ejemplo n.º 13
0
 public function execute()
 {
     parent::execute();
     //--Get the video info
     //$video_type = \SpoonFilter::getPostValue('video_type', null, '', 'int');
     $video_url = \SpoonFilter::getPostValue('video', null, '', 'string');
     if (preg_match('%youtube|youtu\\.be%i', $video_url)) {
         $video_type = 0;
         $video_id = self::getYoutubeId($video_url);
     } elseif (preg_match('%vimeo%i', $video_url)) {
         $video_type = 1;
         $video_id = self::getVimeoId($video_url);
     } elseif (preg_match('%vine%i', $video_url)) {
         $video_type = 2;
         $video_id = preg_replace('/^.*\\//', '', $video_url);
     }
     if (isset($video_id)) {
         //--Set module
         $module = (string) \SpoonFilter::getPostValue('mediaModule', null, '', 'string');
         //--Set action
         $action = (string) \SpoonFilter::getPostValue('mediaAction', null, '', 'string');
         //--Set the id
         $id = (int) \SpoonFilter::getPostValue('mediaId', null, '', 'int');
         //--Set the type
         $type = (string) \SpoonFilter::getPostValue('mediaType', null, '', 'string');
         //--Create media object
         $media = new BackendMediaHelper(new BackendForm('add_image', null, 'post', false), $module, $id, $action, $type);
         //--Validate media -> add video
         $media->addVideo($video_type, $video_id);
         $tpl = new Template();
         $media->item['txtText'] = $media->frm->addTextarea("text-" . $media->item["id"], $media->item['text'])->setAttribute('style', 'resize: none;')->parse();
         switch ($media->item['extension']) {
             //youtube
             case 0:
                 $media->item['video_html'] = '<iframe id="ytplayer" type="text/html" width="100%" src="http://www.youtube.com/embed/' . $media->item['filename'] . '?autoplay=0" frameborder="0"></iframe>';
                 break;
                 //vimeo
             //vimeo
             case 1:
                 $media->item['video_html'] = '<iframe src="//player.vimeo.com/video/' . $media->item['filename'] . '" width="100%" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
                 break;
                 //vine
             //vine
             case 2:
                 $media->item['video_html'] = '<iframe src="https://vine.co/v/' . $media->item['filename'] . '/embed/postcard" width="100%" frameborder="0"></iframe><script src="https://platform.vine.co/static/scripts/embed.js"></script>';
                 break;
             default:
                 $media->item['video_html'] = "";
                 break;
         }
         $tpl->assign('mediaItems', array('videos' => array($media->item)));
         $html = $tpl->getContent(BACKEND_MODULES_PATH . '/Media/Layout/Templates/Ajax/Video.tpl');
         $this->output(self::OK, array($media->item['filetype'], $html), FrontendLanguage::msg('Success'));
     } else {
         $this->output(self::OK, null, 'video not added');
     }
     // success output
 }
Ejemplo n.º 14
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // get settings
     $subscriptionsAllowed = isset($this->settings['allow_subscriptions']) && $this->settings['allow_subscriptions'];
     // subscriptions aren't allowed so we don't have to validate
     if (!$subscriptionsAllowed) {
         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('agenda_subscription_' . $this->record['id'])) {
             // calculate difference
             $diff = time() - (int) \SpoonSession::get('agenda_subscription_' . $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('name')->isFilled(FL::err('NameIsRequired'));
         $this->frm->getField('email')->isEmail(FL::err('EmailIsRequired'));
         // no errors?
         if ($this->frm->isCorrect()) {
             // get module setting
             $moderationEnabled = isset($this->settings['moderation']) && $this->settings['moderation'];
             // reformat data
             $name = $this->frm->getField('name')->getValue();
             $email = $this->frm->getField('email')->getValue();
             // build array
             $subscription['agenda_id'] = $this->record['id'];
             $subscription['language'] = FRONTEND_LANGUAGE;
             $subscription['created_on'] = FrontendModel::getUTCDate();
             $subscription['name'] = $name;
             $subscription['email'] = $email;
             $subscription['status'] = 'subscribed';
             // 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 subscription status so it will appear in the moderation queue
                 if (!FrontendAgendaModel::isModerated($name, $email)) {
                     $subscription['status'] = 'moderation';
                 }
             }
             // insert comment
             $subscription['id'] = FrontendAgendaModel::insertSubscription($subscription);
             // trigger event
             FrontendModel::triggerEvent('agenda', 'after_add_subscription', array('subscription' => $subscription));
             // append a parameter to the URL so we can show moderation
             if (strpos($redirectLink, '?') === false) {
                 if ($subscription['status'] == 'moderation') {
                     $redirectLink .= '?subscription=moderation#' . FL::act('Subscribe');
                 }
                 if ($subscription['status'] == 'subscribed') {
                     $redirectLink .= '?subscription=true#subscription-' . $subscription['id'];
                 }
             } else {
                 if ($subscription['status'] == 'moderation') {
                     $redirectLink .= '&subscription=moderation#' . FL::act('Subscribe');
                 }
                 if ($subscription['status'] == 'subscribed') {
                     $redirectLink .= '&subscription=true#comment-' . $subscription['id'];
                 }
             }
             // set title
             $subscription['agenda_title'] = $this->record['title'];
             $subscription['agenda_url'] = $this->record['url'];
             // notify the admin
             FrontendAgendaModel::notifyAdmin($subscription);
             // store timestamp in session so we can block excessive usage
             \SpoonSession::set('agenda_subscription_' . $this->record['id'], time());
             // store author-data in cookies
             try {
                 Cookie::set('subscription_author', $name);
                 Cookie::set('subscription_email', $email);
             } catch (Exception $e) {
                 // settings cookies isn't allowed, but because this isn't a real problem we ignore the exception
             }
             // redirect
             $this->redirect($redirectLink);
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * Set the language
  *
  * @param string $value The (interface-)language, will be used to parse labels.
  */
 public function setLanguage($value)
 {
     // get the possible languages
     $possibleLanguages = Language::getActiveLanguages();
     // validate
     if (!in_array($value, $possibleLanguages)) {
         // only 1 active language?
         if (!Model::getContainer()->getParameter('site.multilanguage') && count($possibleLanguages) == 1) {
             $this->language = array_shift($possibleLanguages);
         } else {
             // multiple languages available but none selected
             throw new Exception('Language invalid.');
         }
     } else {
         // language is valid: set property
         $this->language = (string) $value;
     }
     // define constant
     defined('FRONTEND_LANGUAGE') || define('FRONTEND_LANGUAGE', $this->language);
     // set the locale (we need this for the labels)
     Language::setLocale($this->language);
 }
Ejemplo n.º 16
0
 /**
  * Get the URL for a give module & action combination
  *
  * @param string $module   The module to get the URL for.
  * @param string $action   The action to get the URL for.
  * @param string $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 : Language::getWorkingLanguage();
     $pageIdForURL = null;
     $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']) || $properties['hidden']) {
                     continue;
                 }
                 // loop extras
                 foreach ($properties['extra_blocks'] as $extra) {
                     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) {
                         $pageIdForURL = (int) $pageId;
                     }
                 }
             }
         }
     }
     // still no page id?
     if ($pageIdForURL === null) {
         return self::getURL(404);
     }
     $URL = self::getURL($pageIdForURL, $language);
     // set locale with force
     FrontendLanguage::setLocale($language, true);
     // append action
     $URL .= '/' . urldecode(FrontendLanguage::act(\SpoonFilter::toCamelCase($action)));
     // return the unique URL!
     return $URL;
 }
Ejemplo n.º 17
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtDisplayName = $this->frm->getField('display_name');
         $txtEmail = $this->frm->getField('email');
         $txtPassword = $this->frm->getField('password');
         // check email
         if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
             // valid email?
             if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                 // email already exists?
                 if (FrontendProfilesModel::existsByEmail($txtEmail->getValue())) {
                     // set error
                     $txtEmail->setError(FL::getError('EmailExists'));
                 }
             }
         }
         // check password
         $txtPassword->isFilled(FL::getError('PasswordIsRequired'));
         // no errors
         if ($this->frm->isCorrect()) {
             // init values
             $settings = array();
             $values = array();
             // generate salt
             $settings['salt'] = FrontendProfilesModel::getRandomString();
             $settings['language'] = FRONTEND_LANGUAGE;
             // values
             $values['email'] = $txtEmail->getValue();
             $values['password'] = FrontendProfilesModel::getEncryptedString($txtPassword->getValue(), $settings['salt']);
             $values['status'] = 'inactive';
             $values['display_name'] = $txtDisplayName->getValue();
             $values['registered_on'] = FrontendModel::getUTCDate();
             $values['last_login'] = FrontendModel::getUTCDate(null, 0);
             /*
              * Add a profile.
              * We use a try-catch statement to catch errors when more users sign up simultaneously.
              */
             try {
                 // insert profile
                 $profileId = FrontendProfilesModel::insert($values);
                 // use the profile id as url until we have an actual url
                 FrontendProfilesModel::update($profileId, array('url' => FrontendProfilesModel::getUrl($values['display_name'])));
                 // trigger event
                 FrontendModel::triggerEvent('Profiles', 'after_register', array('id' => $profileId));
                 // generate activation key
                 $settings['activation_key'] = FrontendProfilesModel::getEncryptedString($profileId . microtime(), $settings['salt']);
                 // set settings
                 FrontendProfilesModel::setSettings($profileId, $settings);
                 // login
                 FrontendProfilesAuthentication::login($profileId);
                 // activation URL
                 $mailValues['activationUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'Activate') . '/' . $settings['activation_key'];
                 // send email
                 $from = $this->get('fork.settings')->get('Core', 'mailer_from');
                 $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to');
                 $message = \Common\Mailer\Message::newInstance(FL::getMessage('RegisterSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($txtEmail->getValue() => ''))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_MODULES_PATH . '/Profiles/Layout/Templates/Mails/Register.tpl', $mailValues, true);
                 $this->get('mailer')->send($message);
                 // redirect
                 $this->redirect(SITE_URL . '/' . $this->URL->getQueryString() . '?sent=true');
             } catch (\Exception $e) {
                 // when debugging we need to see the exceptions
                 if ($this->getContainer()->getParameter('kernel.debug')) {
                     throw $e;
                 }
                 // show error
                 $this->tpl->assign('registerHasFormError', true);
             }
         } else {
             $this->tpl->assign('registerHasFormError', true);
         }
     }
 }
Ejemplo n.º 18
0
 public function parse()
 {
     // more matches to be found than?
     if ($this->pagination['num_items'] > count($this->items)) {
         // remove last result (to add this reference)
         array_pop($this->items);
         // add reference to full search results page
         $this->items[] = array('title' => FL::lbl('More'), 'text' => FL::msg('MoreResults'), 'full_url' => FrontendNavigation::getURLForBlock('Search') . '?form=search&q=' . $this->term);
     }
     $charset = $this->getContainer()->getParameter('kernel.charset');
     // format data
     foreach ($this->items as &$item) {
         // format description
         $item['text'] = !empty($item['text']) ? mb_strlen($item['text']) > $this->length ? mb_substr(strip_tags($item['text']), 0, $this->length, $charset) . '…' : $item['text'] : '';
     }
     // output
     $this->output(self::OK, $this->items);
 }
Ejemplo n.º 19
0
 /**
  * Get an unique URL for a page
  *
  * @param string $URL      The URL to base on.
  * @param int    $id       The id to ignore.
  * @param int    $parentId The parent for the page to create an url for.
  * @param bool   $isAction Is this page an action.
  * @return string
  */
 public static function getURL($URL, $id = null, $parentId = 0, $isAction = false)
 {
     $URL = (string) $URL;
     $parentIds = array((int) $parentId);
     // 0, 1, 2, 3, 4 are all top levels, so we should place them on the same level
     if ($parentId == 0 || $parentId == 1 || $parentId == 2 || $parentId == 3 || $parentId == 4) {
         $parentIds = array(0, 1, 2, 3, 4);
     }
     // get db
     $db = BackendModel::getContainer()->get('database');
     // no specific id
     if ($id === null) {
         // no items?
         if ((bool) $db->getVar('SELECT 1
              FROM pages AS i
              INNER JOIN meta AS m ON i.meta_id = m.id
              WHERE i.parent_id IN(' . implode(',', $parentIds) . ') AND i.status = ? AND m.url = ?
                 AND i.language = ?
              LIMIT 1', array('active', $URL, BL::getWorkingLanguage()))) {
             // add a number
             $URL = BackendModel::addNumber($URL);
             // recall this method, but with a new URL
             return self::getURL($URL, null, $parentId, $isAction);
         }
     } else {
         // one item should be ignored
         // there are items so, call this method again.
         if ((bool) $db->getVar('SELECT 1
              FROM pages AS i
              INNER JOIN meta AS m ON i.meta_id = m.id
              WHERE i.parent_id IN(' . implode(',', $parentIds) . ') AND i.status = ?
                 AND m.url = ? AND i.id != ? AND i.language = ?
              LIMIT 1', array('active', $URL, $id, BL::getWorkingLanguage()))) {
             // add a number
             $URL = BackendModel::addNumber($URL);
             // recall this method, but with a new URL
             return self::getURL($URL, $id, $parentId, $isAction);
         }
     }
     // get full URL
     $fullURL = self::getFullUrl($parentId) . '/' . $URL;
     // get info about parent page
     $parentPageInfo = self::get($parentId, null, BL::getWorkingLanguage());
     // does the parent have extras?
     if ($parentPageInfo['has_extra'] == 'Y' && !$isAction) {
         // set locale
         FrontendLanguage::setLocale(BL::getWorkingLanguage(), true);
         // get all on-site action
         $actions = FrontendLanguage::getActions();
         // if the new URL conflicts with an action we should rebuild the URL
         if (in_array($URL, $actions)) {
             // add a number
             $URL = BackendModel::addNumber($URL);
             // recall this method, but with a new URL
             return self::getURL($URL, $id, $parentId, $isAction);
         }
     }
     // check if folder exists
     if (is_dir(PATH_WWW . '/' . $fullURL) || is_file(PATH_WWW . '/' . $fullURL)) {
         // add a number
         $URL = BackendModel::addNumber($URL);
         // recall this method, but with a new URL
         return self::getURL($URL, $id, $parentId, $isAction);
     }
     // check if it is an application
     if (in_array(trim($fullURL, '/'), array_keys(\ApplicationRouting::getRoutes()))) {
         // add a number
         $URL = BackendModel::addNumber($URL);
         // recall this method, but with a new URL
         return self::getURL($URL, $id, $parentId, $isAction);
     }
     // return the unique URL!
     return $URL;
 }
Ejemplo n.º 20
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(urlencode(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;
 }
Ejemplo n.º 21
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.
  * @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 : 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 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) {
                         // exact page was found, so return
                         return self::getURL($properties['page_id'], $language);
                     } elseif ($extra['module'] == $module && $extra['action'] == null) {
                         // correct module but no action
                         // store pageId
                         $pageIdForURL = (int) $pageId;
                     }
                 }
             }
         }
     }
     // pageId still null?
     if ($pageIdForURL === null) {
         return self::getURL(404, $language);
     }
     // build URL
     $URL = self::getURL($pageIdForURL, $language);
     // append action
     $URL .= '/' . Language::act(\SpoonFilter::toCamelCase($action));
     // return the URL
     return $URL;
 }
Ejemplo n.º 22
0
 /**
  * This method exists because the service container needs to be set before
  * the page's functionality gets loaded.
  */
 public function initialize()
 {
     // because some cronjobs will be run on the command line we should pass parameters
     if (isset($_SERVER['argv'])) {
         // init var
         $first = true;
         // loop all passes arguments
         foreach ($_SERVER['argv'] as $parameter) {
             // ignore first, because this is the scripts name.
             if ($first) {
                 // reset
                 $first = false;
                 // skip
                 continue;
             }
             // split into chunks
             $chunks = explode('=', $parameter, 2);
             // valid parameters?
             if (count($chunks) == 2) {
                 // build key and value
                 $key = trim($chunks[0], '--');
                 $value = $chunks[1];
                 // set in GET
                 if ($key != '' && $value != '') {
                     $_GET[$key] = $value;
                 }
             }
         }
     }
     // define the Named Application
     if (!defined('NAMED_APPLICATION')) {
         define('NAMED_APPLICATION', 'Backend');
     }
     // set the module
     $this->setModule(\SpoonFilter::toCamelCase(\SpoonFilter::getGetValue('module', null, '')));
     // set the requested file
     $this->setAction(\SpoonFilter::toCamelCase(\SpoonFilter::getGetValue('action', null, '')));
     // set the language
     $this->setLanguage(\SpoonFilter::getGetValue('language', FrontendLanguage::getActiveLanguages(), SITE_DEFAULT_LANGUAGE));
     // mark cronjob as run
     $cronjobs = (array) $this->get('fork.settings')->get('Core', 'cronjobs');
     $cronjobs[] = $this->getModule() . '.' . $this->getAction();
     $this->get('fork.settings')->set('Core', 'cronjobs', array_unique($cronjobs));
     $this->execute();
 }
Ejemplo n.º 23
0
 /**
  * Process the query string
  */
 private function processQueryString()
 {
     // store the query string local, so we don't alter it.
     $queryString = trim($this->request->getPathInfo(), '/');
     // split into chunks
     $chunks = (array) explode('/', $queryString);
     $hasMultiLanguages = $this->getContainer()->getParameter('site.multilanguage');
     // single language
     if (!$hasMultiLanguages) {
         // set language id
         $language = $this->get('fork.settings')->get('Core', 'default_language', SITE_DEFAULT_LANGUAGE);
     } else {
         // multiple languages
         // default value
         $mustRedirect = false;
         // get possible languages
         $possibleLanguages = (array) Language::getActiveLanguages();
         $redirectLanguages = (array) Language::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
                 CommonCookie::set('frontend_language', $language);
             } 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 (CommonCookie::exists('frontend_language') && in_array(CommonCookie::get('frontend_language'), $redirectLanguages)) {
             // set languageId
             $language = (string) CommonCookie::get('frontend_language');
             // redirect is needed
             $mustRedirect = true;
         } else {
             // default browser language
             // set languageId & abbreviation
             $language = Language::getBrowserLanguage();
             // try to set a cookie with the language
             try {
                 // set cookie
                 CommonCookie::set('frontend_language', $language);
             } 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(), '/');
             // when we are just adding the language to the domain, it's a temporary redirect because
             // Safari keeps the 301 in cache, so the cookie to switch language doesn't work any more
             $redirectCode = $URL == '/' . $language ? 302 : 301;
             // set header & redirect
             \SpoonHTTP::redirect($URL, $redirectCode);
         }
     }
     // define the language
     defined('FRONTEND_LANGUAGE') || define('FRONTEND_LANGUAGE', $language);
     // sets the locale file
     Language::setLocale($language);
     // list of pageIds & their full URL
     $keys = Navigation::getKeys();
     // rebuild our URL, but without the language parameter. (it's tripped earlier)
     $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 query string
     if ($hasMultiLanguages) {
         $queryString = trim(substr($queryString, strlen($language)), '/');
     }
     // if it's the homepage AND parameters were given (not allowed!)
     if ($URL == '' && $queryString != '') {
         // get 404 URL
         $URL = Navigation::getURL(404);
         // remove language
         if ($hasMultiLanguages) {
             $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 = Navigation::getPageId(implode('/', $this->getPages()));
     $pageInfo = Navigation::getPageInfo($pageId);
     // invalid page, or parameters but no extra
     if ($pageInfo === false || !empty($parameters) && !$pageInfo['has_extra']) {
         // get 404 URL
         $URL = Navigation::getURL(404);
         // remove language
         if ($hasMultiLanguages) {
             $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 = Navigation::getURL((int) $pageInfo['redirect_page_id']);
         $errorURL = Navigation::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']);
     }
 }
Ejemplo n.º 24
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // shorten the fields
         $txtName = $this->frm->getField('name');
         $txtEmail = $this->frm->getField('email');
         $ddmMethod = $this->frm->getField('method');
         $txtSuccessMessage = $this->frm->getField('success_message');
         $txtIdentifier = $this->frm->getField('identifier');
         $emailAddresses = (array) explode(',', $txtEmail->getValue());
         // validate fields
         $txtName->isFilled(BL::getError('NameIsRequired'));
         $txtSuccessMessage->isFilled(BL::getError('SuccessMessageIsRequired'));
         if ($ddmMethod->isFilled(BL::getError('NameIsRequired')) && $ddmMethod->getValue() == 'database_email') {
             $error = false;
             // check the addresses
             foreach ($emailAddresses as $address) {
                 $address = trim($address);
                 if (!\SpoonFilter::isEmail($address)) {
                     $error = true;
                     break;
                 }
             }
             // add error
             if ($error) {
                 $txtEmail->addError(BL::getError('EmailIsInvalid'));
             }
         }
         // identifier
         if ($txtIdentifier->isFilled()) {
             // invalid characters
             if (!\SpoonFilter::isValidAgainstRegexp('/^[a-zA-Z0-9\\.\\_\\-]+$/', $txtIdentifier->getValue())) {
                 $txtIdentifier->setError(BL::getError('InvalidIdentifier'));
             } elseif (BackendFormBuilderModel::existsIdentifier($txtIdentifier->getValue())) {
                 // unique identifier
                 $txtIdentifier->setError(BL::getError('UniqueIdentifier'));
             }
         }
         if ($this->frm->isCorrect()) {
             // build array
             $values['language'] = BL::getWorkingLanguage();
             $values['user_id'] = BackendAuthentication::getUser()->getUserId();
             $values['name'] = $txtName->getValue();
             $values['method'] = $ddmMethod->getValue();
             $values['email'] = $ddmMethod->getValue() == 'database_email' ? serialize($emailAddresses) : null;
             $values['success_message'] = $txtSuccessMessage->getValue(true);
             $values['identifier'] = $txtIdentifier->isFilled() ? $txtIdentifier->getValue() : BackendFormBuilderModel::createIdentifier();
             $values['created_on'] = BackendModel::getUTCDate();
             $values['edited_on'] = BackendModel::getUTCDate();
             // insert the item
             $id = BackendFormBuilderModel::insert($values);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $values));
             // set frontend locale
             FL::setLocale(BL::getWorkingLanguage(), true);
             // create submit button
             $field['form_id'] = $id;
             $field['type'] = 'submit';
             $field['settings'] = serialize(array('values' => \SpoonFilter::ucfirst(FL::getLabel('Send'))));
             BackendFormBuilderModel::insertField($field);
             // everything is saved, so redirect to the editform
             $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $id . '&report=added&var=' . urlencode($values['name']) . '#tabFields');
         }
     }
 }
Ejemplo n.º 25
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)
 {
     $used = array();
     $finder = new Finder();
     $finder->notPath('cache')->name('*.php')->name('*.tpl')->name('*.js');
     // loop files
     foreach ($finder->files()->in(FRONTEND_PATH) as $file) {
         /** @var $file \SplFileInfo */
         // grab content
         $content = $file->getContents();
         // process the file based on extension
         switch ($file->getExtension()) {
             // 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->getRealPath(), $used[$type][$match]['files'])) {
                             $used[$type][$match]['files'][] = $file->getRealPath();
                         }
                     }
                 }
                 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->getRealPath(), $used[$type][$match]['files'])) {
                             $used[$type][$match]['files'][] = $file->getRealPath();
                         }
                     }
                 }
                 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->getRealPath(), $used[$type][$match]['files'])) {
                             $used[$type][$match]['files'][] = $file->getRealPath();
                         }
                     }
                 }
                 break;
         }
     }
     // init var
     $nonExisting = array();
     // set language
     FL::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, false) == '{$' . $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, false) == '{$' . $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, false) == '{$' . $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, false) == '{$' . $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;
 }
Ejemplo n.º 26
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 = $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 (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);
         }
     }
 }
Ejemplo n.º 27
0
 /**
  * This function will return the errors. It is extended so we can do image checks automatically.
  *
  * @return string
  */
 public function getErrors()
 {
     // do an image validation
     if ($this->isFilled()) {
         $this->isAllowedExtension(array('jpg', 'jpeg', 'gif', 'png'), FL::err('JPGGIFAndPNGOnly'));
         $this->isAllowedMimeType(array('image/jpeg', 'image/gif', 'image/png'), FL::err('JPGGIFAndPNGOnly'));
     }
     return $this->errors;
 }
Ejemplo n.º 28
0
 /**
  * Validate the form.
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtDisplayName = $this->frm->getField('display_name');
         $txtFirstName = $this->frm->getField('first_name');
         $txtLastName = $this->frm->getField('last_name');
         $txtCity = $this->frm->getField('city');
         $ddmCountry = $this->frm->getField('country');
         $ddmGender = $this->frm->getField('gender');
         $ddmDay = $this->frm->getField('day');
         $ddmMonth = $this->frm->getField('month');
         $ddmYear = $this->frm->getField('year');
         // get number of display name changes
         $nameChanges = (int) FrontendProfilesModel::getSetting($this->profile->getId(), 'display_name_changes');
         // has there been a valid display name change request?
         if ($this->profile->getDisplayName() !== $txtDisplayName->getValue() && $nameChanges <= FrontendProfilesModel::MAX_DISPLAY_NAME_CHANGES) {
             // display name filled in?
             if ($txtDisplayName->isFilled(FL::getError('FieldIsRequired'))) {
                 // display name exists?
                 if (FrontendProfilesModel::existsDisplayName($txtDisplayName->getValue(), $this->profile->getId())) {
                     // set error
                     $txtDisplayName->addError(FL::getError('DisplayNameExists'));
                 }
             }
         }
         // birthdate is not required but if one is filled we need all
         if ($ddmMonth->isFilled() || $ddmDay->isFilled() || $ddmYear->isFilled()) {
             // valid birth date?
             if (!checkdate($ddmMonth->getValue(), $ddmDay->getValue(), $ddmYear->getValue())) {
                 // set error
                 $ddmYear->addError(FL::getError('DateIsInvalid'));
             }
         }
         // validate avatar when given
         $this->frm->getField('avatar')->isFilled();
         // no errors
         if ($this->frm->isCorrect()) {
             // init
             $values = array();
             $settings = array();
             // has there been a valid display name change request?
             if ($this->profile->getDisplayName() !== $txtDisplayName->getValue() && $nameChanges <= FrontendProfilesModel::MAX_DISPLAY_NAME_CHANGES) {
                 // get display name value
                 $values['display_name'] = $txtDisplayName->getValue();
                 // update url based on the new display name
                 $values['url'] = FrontendProfilesModel::getUrl($txtDisplayName->getValue(), $this->profile->getId());
                 // update display name count
                 $settings['display_name_changes'] = $nameChanges + 1;
             }
             // update values
             if (!empty($values)) {
                 FrontendProfilesModel::update($this->profile->getId(), $values);
             }
             // build settings
             $settings['first_name'] = $txtFirstName->getValue();
             $settings['last_name'] = $txtLastName->getValue();
             $settings['city'] = $txtCity->getValue();
             $settings['country'] = $ddmCountry->getValue();
             $settings['gender'] = $ddmGender->getValue();
             // birthday is filled in
             if ($ddmYear->isFilled()) {
                 // mysql format
                 $settings['birth_date'] = $ddmYear->getValue() . '-';
                 $settings['birth_date'] .= str_pad($ddmMonth->getValue(), 2, '0', STR_PAD_LEFT) . '-';
                 $settings['birth_date'] .= str_pad($ddmDay->getValue(), 2, '0', STR_PAD_LEFT);
             } else {
                 // not filled in
                 $settings['birth_date'] = null;
             }
             // avatar
             $settings['avatar'] = $this->profile->getSetting('avatar');
             // create new filename
             if ($this->frm->getField('avatar')->isFilled()) {
                 // field value
                 $settings['avatar'] = \SpoonFilter::urlise($this->profile->getDisplayName()) . '.' . $this->frm->getField('avatar')->getExtension();
                 // move the file
                 $this->frm->getField('avatar')->generateThumbnails(FRONTEND_FILES_PATH . '/Profiles/Avatars/', $settings['avatar']);
             }
             // save settings
             $this->profile->setSettings($settings);
             // trigger event
             FrontendModel::triggerEvent('Profiles', 'after_saved_settings', array('id' => $this->profile->getId()));
             // redirect
             $this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'Settings') . '?sent=true');
         } else {
             $this->tpl->assign('updateSettingsHasFormError', true);
         }
     }
 }
Ejemplo n.º 29
0
 /**
  * Validate the form.
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtPassword = $this->frm->getField('password');
         $txtEmail = $this->frm->getField('email');
         // password filled in?
         if ($txtPassword->isFilled(FL::getError('PasswordIsRequired'))) {
             // password correct?
             if (FrontendProfilesAuthentication::getLoginStatus($this->profile->getEmail(), $txtPassword->getValue()) !== FrontendProfilesAuthentication::LOGIN_ACTIVE) {
                 // set error
                 $txtPassword->addError(FL::getError('InvalidPassword'));
             }
             // email filled in?
             if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
                 // valid email?
                 if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                     // email already exists?
                     if (FrontendProfilesModel::existsByEmail($txtEmail->getValue(), $this->profile->getId())) {
                         // set error
                         $txtEmail->setError(FL::getError('EmailExists'));
                     }
                 }
             }
         }
         // no errors
         if ($this->frm->isCorrect()) {
             // update email
             FrontendProfilesModel::update($this->profile->getId(), array('email' => $txtEmail->getValue()));
             // trigger event
             FrontendModel::triggerEvent('Profiles', 'after_change_email', array('id' => $this->profile->getId()));
             // redirect
             $this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'ChangeEmail') . '?sent=true');
         } else {
             $this->tpl->assign('updateEmailHasFormError', true);
         }
     }
 }
Ejemplo n.º 30
0
 /**
  * Notify the admin
  *
  * @param array $comment The comment that was submitted.
  */
 public static function notifyAdmin(array $comment)
 {
     // don't notify admin in case of spam
     if ($comment['status'] == 'spam') {
         return;
     }
     // build data for push notification
     if ($comment['status'] == 'moderation') {
         $key = 'BLOG_COMMENT_MOD';
     } else {
         $key = 'BLOG_COMMENT';
     }
     $author = $comment['author'];
     if (mb_strlen($author) > 20) {
         $author = mb_substr($author, 0, 19) . '…';
     }
     $text = $comment['text'];
     if (mb_strlen($text) > 50) {
         $text = mb_substr($text, 0, 49) . '…';
     }
     $alert = array('loc-key' => $key, 'loc-args' => array($author, $text));
     // build data
     $data = array('api' => SITE_URL . '/api/1.0', 'id' => $comment['id']);
     // push it
     FrontendModel::pushToAppleApp($alert, null, 'default', $data);
     // get settings
     $notifyByMailOnComment = FrontendModel::get('fork.settings')->get('Blog', 'notify_by_email_on_new_comment', false);
     $notifyByMailOnCommentToModerate = FrontendModel::get('fork.settings')->get('Blog', 'notify_by_email_on_new_comment_to_moderate', false);
     // create URLs
     $URL = SITE_URL . FrontendNavigation::getURLForBlock('Blog', 'Detail') . '/' . $comment['post_url'] . '#comment-' . $comment['id'];
     $backendURL = SITE_URL . FrontendNavigation::getBackendURLForBlock('comments', 'Blog') . '#tabModeration';
     // notify on all comments
     if ($notifyByMailOnComment) {
         // init var
         $variables = null;
         // comment to moderate
         if ($comment['status'] == 'moderation') {
             $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewCommentToModerate'), array($comment['author'], $URL, $comment['post_title'], $backendURL));
         } elseif ($comment['status'] == 'published') {
             // comment was published
             $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewComment'), array($comment['author'], $URL, $comment['post_title']));
         }
         $to = FrontendModel::get('fork.settings')->get('Core', 'mailer_to');
         $from = FrontendModel::get('fork.settings')->get('Core', 'mailer_from');
         $replyTo = FrontendModel::get('fork.settings')->get('Core', 'mailer_reply_to');
         $message = \Common\Mailer\Message::newInstance(FL::msg('NotificationSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_CORE_PATH . '/Layout/Templates/Mails/Notification.tpl', $variables, true);
         FrontendModel::get('mailer')->send($message);
     } elseif ($notifyByMailOnCommentToModerate && $comment['status'] == 'moderation') {
         // only notify on new comments to moderate and if the comment is one to moderate
         // set variables
         $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewCommentToModerate'), array($comment['author'], $URL, $comment['post_title'], $backendURL));
         $to = FrontendModel::get('fork.settings')->get('Core', 'mailer_to');
         $from = FrontendModel::get('fork.settings')->get('Core', 'mailer_from');
         $replyTo = FrontendModel::get('fork.settings')->get('Core', 'mailer_reply_to');
         $message = \Common\Mailer\Message::newInstance(FL::msg('NotificationSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_CORE_PATH . '/Layout/Templates/Mails/Notification.tpl', $variables, true);
         FrontendModel::get('mailer')->send($message);
     }
 }