Beispiel #1
0
 /**
  * Validate the form
  *
  * @return	void
  */
 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
                 FrontendMailmotorCMHelper::subscribe($email->getValue());
                 // trigger event
                 FrontendModel::triggerEvent('mailmotor', 'after_subscribe', array('email' => $email->getValue()));
                 // redirect
                 $this->redirect(FrontendNavigation::getURLForBlock('mailmotor', 'subscribe') . '?sent=true#subscribeForm');
             } catch (Exception $e) {
                 // when debugging we need to see the exceptions
                 if (SPOON_DEBUG) {
                     throw $e;
                 }
                 // show error
                 $this->tpl->assign('subscribeHasError', true);
             }
         } else {
             $this->tpl->assign('subscribeHasFormError', true);
         }
     }
 }
Beispiel #2
0
 /**
  * Load the datagrid
  */
 private function loadDataGrid()
 {
     // create a new source-object
     $source = new SpoonDataGridSourceDB(FrontendModel::getDB(), array(FrontendMailmotorModel::QRY_DATAGRID_BROWSE_SENT, array('sent', FRONTEND_LANGUAGE)));
     // create datagrid
     $this->dataGrid = new SpoonDataGrid($source);
     $this->dataGrid->setCompileDirectory(FRONTEND_CACHE_PATH . '/compiled_templates');
     // set hidden columns
     $this->dataGrid->setColumnsHidden(array('id', 'status'));
     // set headers values
     $headers['name'] = SpoonFilter::ucfirst(FL::lbl('Name'));
     $headers['send_on'] = SpoonFilter::ucfirst(FL::lbl('Sent'));
     // set headers
     $this->dataGrid->setHeaderLabels($headers);
     // sorting columns
     $this->dataGrid->setSortingColumns(array('name', 'send_on'), 'name');
     $this->dataGrid->setSortParameter('desc');
     // set colum URLs
     $this->dataGrid->setColumnURL('name', FrontendNavigation::getURLForBlock('mailmotor', 'detail') . '/[id]');
     // set column functions
     $this->dataGrid->setColumnFunction(array('SpoonDate', 'getTimeAgo'), array('[send_on]'), 'send_on', true);
     // add styles
     $this->dataGrid->setColumnAttributes('name', array('class' => 'title'));
     // set paging limit
     $this->dataGrid->setPagingLimit(self::MAILINGS_PAGING_LIMIT);
 }
Beispiel #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) {
            // set module class
            $class = 'Frontend' . SpoonFilter::toCamelCase($module) . 'Model';
            // get the ids of the items linked to the tag
            $otherIds = (array) FrontendModel::getDB()->getColumn('SELECT other_id
				 FROM modules_tags
				 WHERE module = ? AND tag_id = ?', array($module, $this->record['id']));
            // set module class
            $class = 'Frontend' . SpoonFilter::toCamelCase($module) . 'Model';
            // get the items that are linked to the tags
            $items = (array) FrontendTagsModel::callFromInterface($module, $class, 'getForTags', $otherIds);
            // add into results array
            if (!empty($items)) {
                $this->results[] = array('name' => $module, 'label' => FL::lbl(SpoonFilter::ucfirst($module)), 'items' => $items);
            }
        }
    }
 /**
  * Parse the data into the template
  */
 private function parse()
 {
     // get vars
     $title = vsprintf(FL::msg('CommentsOn'), array($this->record['title']));
     $link = SITE_URL . FrontendNavigation::getURLForBlock('blog', 'article_comments_rss') . '/' . $this->record['url'];
     $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') . ' ' . $this->record['title'];
         $link = $detailLink . '/' . $this->record['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();
 }
Beispiel #5
0
 public function setOptions()
 {
     $this->_fl_instance = FL::getInstance();
     $this->_output = array();
     $this->_preType = 0;
     $this->_preText = '';
     $this->_punct = split(' ', '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::');
 }
Beispiel #6
0
 /**
  * Parse the data into the template
  *
  * @return	void
  */
 private function parse()
 {
     // get vars
     $title = isset($this->settings['rss_title_' . FRONTEND_LANGUAGE]) ? $this->settings['rss_title_' . FRONTEND_LANGUAGE] : FrontendModel::getModuleSetting('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 (FrontendModel::getModuleSetting('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>' . 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();
 }
Beispiel #7
0
 /**
  * Validate the form.
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtEmail = $this->frm->getField('email');
         $txtPassword = $this->frm->getField('password');
         $chkRemember = $this->frm->getField('remember');
         // required fields
         $txtEmail->isFilled(FL::getError('EmailIsRequired'));
         $txtPassword->isFilled(FL::getError('PasswordIsRequired'));
         // both fields filled in
         if ($txtEmail->isFilled() && $txtPassword->isFilled()) {
             // valid email?
             if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                 // get the status for the given login
                 $loginStatus = FrontendProfilesAuthentication::getLoginStatus($txtEmail->getValue(), $txtPassword->getValue());
                 // valid login?
                 if ($loginStatus !== FrontendProfilesAuthentication::LOGIN_ACTIVE) {
                     // get the error string to use
                     $errorString = sprintf(FL::getError('Profiles' . SpoonFilter::toCamelCase($loginStatus) . 'Login'), FrontendNavigation::getURLForBlock('profiles', 'resend_activation'));
                     // add the error to stack
                     $this->frm->addError($errorString);
                     // add the error to the template variables
                     $this->tpl->assign('loginError', $errorString);
                 }
             }
         }
         // valid login
         if ($this->frm->isCorrect()) {
             // get profile id
             $profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue());
             // login
             FrontendProfilesAuthentication::login($profileId, $chkRemember->getChecked());
             // update salt and password for Dieter's security features
             FrontendProfilesAuthentication::updatePassword($profileId, $txtPassword->getValue());
             // trigger event
             FrontendModel::triggerEvent('profiles', 'after_logged_in', array('id' => $profileId));
             // querystring
             $queryString = urldecode(SpoonFilter::getGetValue('queryString', null, SITE_URL));
             // redirect
             $this->redirect($queryString);
         }
     }
 }
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     $generalSettings = BackendModel::getModuleSettings();
     $generalSettings = $generalSettings['location'];
     // get parameters
     $itemId = SpoonFilter::getPostValue('id', null, null, 'int');
     $zoomLevel = trim(SpoonFilter::getPostValue('zoom', null, 'auto'));
     $mapType = strtoupper(trim(SpoonFilter::getPostValue('type', array('roadmap', 'satelitte', 'hybrid', 'terrain'), 'roadmap')));
     $centerLat = SpoonFilter::getPostValue('centerLat', null, 1, 'float');
     $centerlng = SpoonFilter::getPostValue('centerLng', null, 1, 'float');
     $height = SpoonFilter::getPostValue('height', null, $generalSettings['height'], 'int');
     $width = SpoonFilter::getPostValue('width', null, $generalSettings['width'], 'int');
     $showLink = SpoonFilter::getPostValue('link', array('true', 'false'), 'false', 'string');
     $showDirections = SpoonFilter::getPostValue('directions', array('true', 'false'), 'false', 'string');
     $showOverview = SpoonFilter::getPostValue('showOverview', array('true', 'false'), 'true', 'string');
     // reformat
     $center = array('lat' => $centerLat, 'lng' => $centerlng);
     $showLink = $showLink == 'true';
     $showDirections = $showDirections == 'true';
     $showOverview = $showOverview == 'true';
     // standard dimensions
     if ($width > 800) {
         $width = 800;
     }
     if ($width < 300) {
         $width = $generalSettings['width'];
     }
     if ($height < 150) {
         $height = $generalSettings['height'];
     }
     // no id given, this means we should update the main map
     BackendLocationModel::setMapSetting($itemId, 'zoom_level', (string) $zoomLevel);
     BackendLocationModel::setMapSetting($itemId, 'map_type', (string) $mapType);
     BackendLocationModel::setMapSetting($itemId, 'center', (array) $center);
     BackendLocationModel::setMapSetting($itemId, 'height', (int) $height);
     BackendLocationModel::setMapSetting($itemId, 'width', (int) $width);
     BackendLocationModel::setMapSetting($itemId, 'directions', $showDirections);
     BackendLocationModel::setMapSetting($itemId, 'full_url', $showLink);
     $item = array('id' => $itemId, 'language' => BL::getWorkingLanguage(), 'show_overview' => $showOverview ? 'Y' : 'N');
     BackendLocationModel::update($item);
     // output
     $this->output(self::OK, null, FL::msg('Success'));
 }
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get field
         $txtEmail = $this->frm->getField('email');
         // field is filled in?
         if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
             // valid email?
             if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                 // email exists?
                 if (!FrontendProfilesModel::existsByEmail($txtEmail->getValue())) {
                     $txtEmail->addError(FL::getError('EmailIsUnknown'));
                 }
             }
         }
         // valid login
         if ($this->frm->isCorrect()) {
             // get profile id
             $profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue());
             // generate forgot password key
             $key = FrontendProfilesModel::getEncryptedString($profileId . microtime(), FrontendProfilesModel::getRandomString());
             // insert forgot password key
             FrontendProfilesModel::setSetting($profileId, 'forgot_password_key', $key);
             // reset url
             $mailValues['resetUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'reset_password') . '/' . $key;
             $mailValues['firstName'] = FrontendProfilesModel::getSetting($profileId, 'first_name');
             $mailValues['lastName'] = FrontendProfilesModel::getSetting($profileId, 'last_name');
             // trigger event
             FrontendModel::triggerEvent('profiles', 'after_forgot_password', array('id' => $profileId));
             // send email
             FrontendMailer::addEmail(FL::getMessage('ForgotPasswordSubject'), FRONTEND_MODULES_PATH . '/profiles/layout/templates/mails/forgot_password.tpl', $mailValues, $txtEmail->getValue(), '');
             // redirect
             $this->redirect(SELF . '?sent=true');
         } else {
             $this->tpl->assign('forgotPasswordHasError', true);
         }
     }
 }
Beispiel #10
0
 /**
  * Parse the data into the template
  *
  * @return	void
  */
 private function parse()
 {
     // get RSS-link
     $rssLink = FrontendModel::getModuleSetting('blog', 'feedburner_url_' . FRONTEND_LANGUAGE);
     if ($rssLink == '') {
         $rssLink = FrontendNavigation::getURLForBlock('blog', 'rss');
     }
     // add RSS-feed
     $this->header->addLink(array('rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => FrontendModel::getModuleSetting('blog', 'rss_title_' . FRONTEND_LANGUAGE), 'href' => $rssLink), true);
     // add into breadcrumb
     $this->breadcrumb->addElement(ucfirst(FL::lbl('Category')));
     $this->breadcrumb->addElement($this->category['label']);
     // set pageTitle
     $this->header->setPageTitle(ucfirst(FL::lbl('Category')));
     $this->header->setPageTitle($this->category['label']);
     // advanced SEO-attributes
     if (isset($this->category['meta_data']['seo_index'])) {
         $this->header->addMetaData(array('name' => 'robots', 'content' => $this->category['meta_data']['seo_index']));
     }
     if (isset($this->category['meta_data']['seo_follow'])) {
         $this->header->addMetaData(array('name' => 'robots', 'content' => $this->category['meta_data']['seo_follow']));
     }
     // assign category
     $this->tpl->assign('category', $this->category);
     // assign articles
     $this->tpl->assign('items', $this->items);
     // parse the pagination
     $this->parsePagination();
 }
Beispiel #11
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $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()) {
             // generate salt
             $salt = FrontendProfilesModel::getRandomString();
             // init values
             $values = array();
             // values
             $values['email'] = $txtEmail->getValue();
             $values['password'] = FrontendProfilesModel::getEncryptedString($txtPassword->getValue(), $salt);
             $values['status'] = 'inactive';
             $values['display_name'] = $txtEmail->getValue();
             $values['registered_on'] = FrontendModel::getUTCDate();
             /*
              * 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
                 $activationKey = FrontendProfilesModel::getEncryptedString($profileId . microtime(), $salt);
                 // set settings
                 FrontendProfilesModel::setSetting($profileId, 'salt', $salt);
                 FrontendProfilesModel::setSetting($profileId, 'activation_key', $activationKey);
                 // login
                 FrontendProfilesAuthentication::login($profileId);
                 // activation URL
                 $mailValues['activationUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'activate') . '/' . $activationKey;
                 // send email
                 FrontendMailer::addEmail(FL::getMessage('RegisterSubject'), FRONTEND_MODULES_PATH . '/profiles/layout/templates/mails/register.tpl', $mailValues, $values['email'], '');
                 // redirect
                 $this->redirect(SELF . '?sent=true');
             } catch (Exception $e) {
                 // when debugging we need to see the exceptions
                 if (SPOON_DEBUG) {
                     throw $e;
                 }
                 // show error
                 $this->tpl->assign('registerHasFormError', true);
             }
         } else {
             $this->tpl->assign('registerHasFormError', true);
         }
     }
 }
Beispiel #12
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', 'change_email') . '?sent=true');
         } else {
             $this->tpl->assign('updateEmailHasFormError', true);
         }
     }
 }
Beispiel #13
0
 /**
  * Get errors (optional by type).
  *
  * @return	mixed
  * @param	string[optional] $type		Type of error.
  */
 public static function getErrors($type = null)
 {
     // init
     $errors['required'] = FL::getError('FieldIsRequired');
     $errors['email'] = FL::getError('EmailIsInvalid');
     $errors['numeric'] = FL::getError('NumericCharactersOnly');
     // specific type
     if ($type !== null) {
         // redefine
         $type = (string) $type;
         // get specific error
         return $errors[$type];
     } else {
         // init
         $return = array();
         // loop errors
         foreach ($errors as $key => $error) {
             $return[] = array('type' => $key, 'message' => $error);
         }
         // cough up
         return $return;
     }
 }
Beispiel #14
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate required fields
         $this->frm->getField('q')->isFilled(FL::err('TermIsRequired'));
         // no errors?
         if ($this->frm->isCorrect()) {
             // get search term
             $this->term = $this->frm->getField('q')->getValue();
         }
     }
 }
Beispiel #15
0
 /**
  * Parse the default error messages
  */
 private function parseErrorMessages()
 {
     // set frontend locale
     FL::setLocale(BL::getWorkingLanguage());
     // assign error messages
     $this->tpl->assign('errors', BackendFormBuilderModel::getErrors());
 }
Beispiel #16
0
 /**
  * Parse the languages
  */
 protected function parseLanguages()
 {
     // just execute if the site is multi-language
     if (SITE_MULTILANGUAGE) {
         // get languages
         $activeLanguages = FrontendLanguage::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'] = FL::msg(strtoupper($language));
             $temp['current'] = (bool) ($language == FRONTEND_LANGUAGE);
             // add
             $languages[] = $temp;
         }
         // assign
         if (count($languages) > 1) {
             $this->tpl->assign('languages', $languages);
         }
     }
 }
Beispiel #17
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;
 }
 /**
  * Validate the form
  *
  * @return	void
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtOldPassword = $this->frm->getField('old_password');
         $txtNewPassword = $this->frm->getField('new_password');
         // old password filled in?
         if ($txtOldPassword->isFilled(FL::getError('PasswordIsRequired'))) {
             // old password correct?
             if (FrontendProfilesAuthentication::getLoginStatus($this->profile->getEmail(), $txtOldPassword->getValue()) !== FrontendProfilesAuthentication::LOGIN_ACTIVE) {
                 // set error
                 $txtOldPassword->addError(FL::getError('InvalidPassword'));
             }
             // new password filled in?
             $txtNewPassword->isFilled(FL::getError('PasswordIsRequired'));
         }
         // no errors
         if ($this->frm->isCorrect()) {
             // update password
             FrontendProfilesAuthentication::updatePassword($this->profile->getId(), $txtNewPassword->getValue());
             // trigger event
             FrontendModel::triggerEvent('profiles', 'after_profile_password', array('id' => $this->profile->getId()));
             // redirect
             $this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'profile_password') . '?saved=true');
         } else {
             $this->tpl->assign('updatePasswordHasFormError', true);
         }
     }
 }
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get field
         $txtEmail = $this->frm->getField('email');
         // field is filled in?
         if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
             // valid email?
             if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                 // email exists?
                 if (FrontendProfilesModel::existsByEmail($txtEmail->getValue())) {
                     // get profile id using the filled in email
                     $profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue());
                     // get profile
                     $profile = FrontendProfilesModel::get($profileId);
                     // must be inactive
                     if ($profile->getStatus() != FrontendProfilesAuthentication::LOGIN_INACTIVE) {
                         $txtEmail->addError(FL::getError('ProfileIsActive'));
                     }
                 } else {
                     $txtEmail->addError(FL::getError('EmailIsInvalid'));
                 }
             }
         }
         // valid login
         if ($this->frm->isCorrect()) {
             // activation URL
             $mailValues['activationUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('profiles', 'activate') . '/' . $profile->getSetting('activation_key');
             // trigger event
             FrontendModel::triggerEvent('profiles', 'after_resend_activation', array('id' => $profileId));
             // send email
             FrontendMailer::addEmail(FL::getMessage('RegisterSubject'), FRONTEND_MODULES_PATH . '/profiles/layout/templates/mails/register.tpl', $mailValues, $profile->getEmail(), '');
             // redirect
             $this->redirect(SELF . '?sent=true');
         } else {
             $this->tpl->assign('resendActivationHasError', true);
         }
     }
 }
Beispiel #20
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;
 }
Beispiel #21
0
    /**
     * Notify the admin
     *
     * @return	void
     * @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 pushnotification
        if ($comment['status'] == 'moderation') {
            $alert = array('loc-key' => 'NEW_COMMENT_TO_MODERATE');
        } else {
            $alert = array('loc-key' => 'NEW_COMMENT');
        }
        // get count of unmoderated items
        $badge = (int) FrontendModel::getDB()->getVar('SELECT COUNT(i.id)
														FROM blog_comments AS i
														WHERE i.status = ? AND i.language = ?
														GROUP BY i.status', array('moderation', FRONTEND_LANGUAGE));
        // reset if needed
        if ($badge == 0) {
            $badge = null;
        }
        // build data
        $data = array('data' => array('endpoint' => SITE_URL . '/api/1.0', 'comment_id' => $comment['id']));
        // push it
        FrontendModel::pushToAppleApp($alert, $badge, null, $data);
        // get settings
        $notifyByMailOnComment = FrontendModel::getModuleSetting('blog', 'notify_by_email_on_new_comment', false);
        $notifyByMailOnCommentToModerate = FrontendModel::getModuleSetting('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) {
            // comment to moderate
            if ($comment['status'] == 'moderation') {
                // set variables
                $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewCommentToModerate'), array($comment['author'], $URL, $comment['post_title'], $backendURL));
            } elseif ($comment['status'] == 'published') {
                // set variables
                $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewComment'), array($comment['author'], $URL, $comment['post_title']));
            }
            // send the mail
            FrontendMailer::addEmail(FL::msg('NotificationSubject'), FRONTEND_CORE_PATH . '/layout/templates/mails/notification.tpl', $variables);
        } elseif ($notifyByMailOnCommentToModerate && $comment['status'] == 'moderation') {
            // set variables
            $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewCommentToModerate'), array($comment['author'], $URL, $comment['post_title'], $backendURL));
            // send the mail
            FrontendMailer::addEmail(FL::msg('NotificationSubject'), FRONTEND_CORE_PATH . '/layout/templates/mails/notification.tpl', $variables);
        }
    }
Beispiel #22
0
 /**
  * Parse the data into the template
  */
 private function parse()
 {
     // get RSS-link
     $rssLink = FrontendModel::getModuleSetting('blog', 'feedburner_url_' . FRONTEND_LANGUAGE);
     if ($rssLink == '') {
         $rssLink = FrontendNavigation::getURLForBlock('blog', 'rss');
     }
     // add RSS-feed
     $this->header->addLink(array('rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => FrontendModel::getModuleSetting('blog', 'rss_title_' . FRONTEND_LANGUAGE), 'href' => $rssLink), true);
     // add into breadcrumb
     $this->breadcrumb->addElement(SpoonFilter::ucfirst(FL::lbl('Archive')));
     $this->breadcrumb->addElement($this->year);
     if ($this->month !== null) {
         $this->breadcrumb->addElement(SpoonDate::getDate('F', $this->startDate, FRONTEND_LANGUAGE, true));
     }
     // set pageTitle
     $this->header->setPageTitle(SpoonFilter::ucfirst(FL::lbl('Archive')));
     $this->header->setPageTitle($this->year);
     if ($this->month !== null) {
         $this->header->setPageTitle(SpoonDate::getDate('F', $this->startDate, FRONTEND_LANGUAGE, true));
     }
     // assign category
     $this->tpl->assign('archive', array('start_date' => $this->startDate, 'end_date' => $this->endDate, 'year' => $this->year, 'month' => $this->month));
     // assign items
     $this->tpl->assign('items', $this->items);
     // parse the pagination
     $this->parsePagination();
 }
Beispiel #23
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);
         }
     }
 }
Beispiel #24
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);
 }
Beispiel #25
0
 /**
  * Validate the form.
  */
 private function validateForm()
 {
     // submitted
     if ($this->frm->isSubmitted()) {
         // does the key exists?
         if (SpoonSession::exists('formbuilder_' . $this->item['id'])) {
             // calculate difference
             $diff = time() - (int) SpoonSession::get('formbuilder_' . $this->item['id']);
             // calculate difference, it it isn't 10 seconds the we tell the user to slow down
             if ($diff < 10 && $diff != 0) {
                 $this->frm->addError(FL::err('FormTimeout'));
             }
         }
         // validate fields
         foreach ($this->item['fields'] as $field) {
             // fieldname
             $fieldName = 'field' . $field['id'];
             // skip
             if ($field['type'] == 'submit' || $field['type'] == 'paragraph' || $field['type'] == 'heading') {
                 continue;
             }
             // loop other validations
             foreach ($field['validations'] as $rule => $settings) {
                 // already has an error so skip
                 if ($this->frm->getField($fieldName)->getErrors() !== null) {
                     continue;
                 }
                 // required
                 if ($rule == 'required') {
                     $this->frm->getField($fieldName)->isFilled($settings['error_message']);
                 } elseif ($rule == 'email') {
                     // only check this if the field is filled, if the field is required it will be validated before
                     if ($this->frm->getField($fieldName)->isFilled()) {
                         $this->frm->getField($fieldName)->isEmail($settings['error_message']);
                     }
                 } elseif ($rule == 'numeric') {
                     // only check this if the field is filled, if the field is required it will be validated before
                     if ($this->frm->getField($fieldName)->isFilled()) {
                         $this->frm->getField($fieldName)->isNumeric($settings['error_message']);
                     }
                 }
             }
         }
         // valid form
         if ($this->frm->isCorrect()) {
             // item
             $data['form_id'] = $this->item['id'];
             $data['session_id'] = SpoonSession::getSessionId();
             $data['sent_on'] = FrontendModel::getUTCDate();
             $data['data'] = serialize(array('server' => $_SERVER));
             // insert data
             $dataId = FrontendFormBuilderModel::insertData($data);
             // init fields array
             $fields = array();
             // loop all fields
             foreach ($this->item['fields'] as $field) {
                 // skip
                 if ($field['type'] == 'submit' || $field['type'] == 'paragraph' || $field['type'] == 'heading') {
                     continue;
                 }
                 // field data
                 $fieldData['data_id'] = $dataId;
                 $fieldData['label'] = $field['settings']['label'];
                 $fieldData['value'] = $this->frm->getField('field' . $field['id'])->getValue();
                 // prepare fields for email
                 if ($this->item['method'] == 'database_email') {
                     // add field for email
                     $emailFields[] = array('label' => $field['settings']['label'], 'value' => is_array($fieldData['value']) ? implode(',', $fieldData['value']) : nl2br($fieldData['value']));
                 }
                 // clean up
                 if (is_array($fieldData['value']) && empty($fieldData['value'])) {
                     $fieldData['value'] = null;
                 }
                 // serialize
                 if ($fieldData['value'] !== null) {
                     $fieldData['value'] = serialize($fieldData['value']);
                 }
                 // save fields data
                 $fields[] = $fieldData;
                 // insert
                 FrontendFormBuilderModel::insertDataField($fieldData);
             }
             // need to send mail
             if ($this->item['method'] == 'database_email') {
                 // build variables
                 $variables['sentOn'] = time();
                 $variables['name'] = $this->item['name'];
                 $variables['fields'] = $emailFields;
                 // loop recipients
                 foreach ($this->item['email'] as $address) {
                     // add email
                     FrontendMailer::addEmail(sprintf(FL::getMessage('FormBuilderSubject'), $this->item['name']), FRONTEND_MODULES_PATH . '/form_builder/layout/templates/mails/form.tpl', $variables, $address, $this->item['name']);
                 }
             }
             // trigger event
             FrontendModel::triggerEvent('form_builder', 'after_submission', array('form_id' => $this->item['id'], 'data_id' => $dataId, 'data' => $data, 'fields' => $fields, 'visitorId' => FrontendModel::getVisitorId()));
             // store timestamp in session so we can block excesive usage
             SpoonSession::set('formbuilder_' . $this->item['id'], time());
             // redirect
             $redirect = SITE_URL . '/' . $this->URL->getQueryString();
             $redirect .= stripos($redirect, '?') === false ? '?' : '&';
             $redirect .= 'identifier=' . $this->item['identifier'];
             // redirect with identifier
             SpoonHTTP::redirect($redirect);
         } else {
             // global form errors set
             if ($this->frm->getErrors() != '') {
                 $this->tpl->assign('formBuilderError', $this->frm->getErrors());
             } else {
                 $this->tpl->assign('formBuilderError', FL::err('FormError'));
             }
         }
     }
 }
Beispiel #26
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;
 }
Beispiel #27
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;
 }
Beispiel #28
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);
     }
     // format data
     foreach ($this->items as &$item) {
         // full url is set?
         if (!isset($item['full_url'])) {
             continue;
         }
         // build utm array
         $utm['utm_source'] = SpoonFilter::urlise(FrontendModel::getModuleSetting('core', 'site_title_' . FRONTEND_LANGUAGE, SITE_DEFAULT_TITLE));
         $utm['utm_medium'] = 'fork-search';
         $utm['utm_term'] = $this->term;
         // get parameters in url already
         if (strpos($item['full_url'], '?') !== false) {
             $glue = '&';
         } else {
             $glue = '?';
         }
         // add utm to url
         $item['full_url'] .= $glue . http_build_query($utm, '', '&');
         // format description
         $item['text'] = !empty($item['text']) ? mb_strlen($item['text']) > $this->length ? mb_substr(strip_tags($item['text']), 0, $this->length, SPOON_CHARSET) . '…' : $item['text'] : '';
     }
     // output
     $this->output(self::OK, $this->items);
 }
Beispiel #29
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('email')->isEmail(FL::err('EmailIsRequired'));
         $this->frm->getField('fname')->isFilled(BL::err('FirstNameIsRequired'));
         $this->frm->getField('lname')->isFilled(BL::err('LastNameIsRequired'));
         $this->frm->getField('address')->isFilled(BL::err('AddressIsRequired'));
         $this->frm->getField('hnumber')->isFilled(BL::err('HouseNumberIsRequired'));
         $this->frm->getField('postal')->isFilled(BL::err('PostalIsRequired'));
         $this->frm->getField('hometown')->isFilled(BL::err('HometownIsRequired'));
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $order['id'] = $this->id;
             $order['email'] = $this->frm->getField('email')->getValue();
             $order['fname'] = $this->frm->getField('fname')->getValue();
             $order['lname'] = $this->frm->getField('lname')->getValue();
             $order['address'] = $this->frm->getField('address')->getValue();
             $order['hnumber'] = $this->frm->getField('hnumber')->getValue();
             $order['postal'] = $this->frm->getField('postal')->getValue();
             $order['hometown'] = $this->frm->getField('hometown')->getValue();
             // insert the item
             BackendCatalogModel::updateOrder($order);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_order', array('item' => $order));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('orders') . '&report=edited-order&id=' . $order['id'] . '&highlight=row-' . $order['id'] . '#tab' . ucwords($this->record['status']));
         }
     }
 }
Beispiel #30
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())) {
                 $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());
             // 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');
         }
     }
 }