/** * Parse the data into the template */ private function parse() { // show message $this->tpl->assign('widgetLocationItems', FrontendLocationModel::get((int) $this->data['id'])); // hide form $this->tpl->assign('widgetLocationSettings', FrontendModel::getModuleSettings('location')); }
/** * 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 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); } } }
/** * 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); } } }
/** * 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); }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get parameters $term = SpoonFilter::getGetValue('term', null, ''); // validate if ($term == '') { $this->output(self::BAD_REQUEST, null, 'term-parameter is missing.'); } // previous search result $previousTerm = SpoonSession::exists('searchTerm') ? SpoonSession::get('searchTerm') : ''; SpoonSession::set('searchTerm', ''); // save this term? if ($previousTerm != $term) { // format data $this->statistics = array(); $this->statistics['term'] = $term; $this->statistics['language'] = FRONTEND_LANGUAGE; $this->statistics['time'] = FrontendModel::getUTCDate(); $this->statistics['data'] = serialize(array('server' => $_SERVER)); $this->statistics['num_results'] = FrontendSearchModel::getTotal($term); // save data FrontendSearchModel::save($this->statistics); } // save current search term in cookie SpoonSession::set('searchTerm', $term); // output $this->output(self::OK); }
/** * Execute the extra. */ public function execute() { // get activation key $key = $this->URL->getParameter(0); // load template $this->loadTemplate(); // do we have an activation key? if (isset($key)) { // get profile id $profileId = FrontendProfilesModel::getIdBySetting('activation_key', $key); // have id? if ($profileId != null) { // update status FrontendProfilesModel::update($profileId, array('status' => 'active')); // delete activation key FrontendProfilesModel::deleteSetting($profileId, 'activation_key'); // login profile FrontendProfilesAuthentication::login($profileId); // trigger event FrontendModel::triggerEvent('profiles', 'after_activate', array('id' => $profileId)); // show success message $this->tpl->assign('activationSuccess', true); } else { $this->redirect(FrontendNavigation::getURL(404)); } } else { $this->redirect(FrontendNavigation::getURL(404)); } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validate required fields $this->frm->getField('name')->isFilled(FL::err('NameIsRequired')); $this->frm->getField('email')->isEmail(FL::err('EmailIsInvalid')); $this->frm->getField('message')->isFilled(FL::err('QuestionIsRequired')); if ($this->frm->isCorrect()) { $spamFilterEnabled = FrontendModel::getModuleSetting('faq', 'spamfilter'); $variables['sentOn'] = time(); $variables['name'] = $this->frm->getField('name')->getValue(); $variables['email'] = $this->frm->getField('email')->getValue(); $variables['message'] = $this->frm->getField('message')->getValue(); if ($spamFilterEnabled) { // if the comment is spam alter the comment status so it will appear in the spam queue if (FrontendModel::isSpam($variables['message'], SITE_URL . FrontendNavigation::getURLForBlock('faq'), $variables['name'], $variables['email'])) { $this->status = 'errorSpam'; return; } } $this->status = 'success'; FrontendMailer::addEmail(sprintf(FL::getMessage('FaqOwnQuestionSubject'), $variables['name']), FRONTEND_MODULES_PATH . '/faq/layout/templates/mails/own_question.tpl', $variables, $variables['email'], $variables['name']); } } }
/** * Get all items in a category * * @return array * @param int $categoryId The id of the category. */ public static function getQuestions($categoryId) { return (array) FrontendModel::getDB()->getRecords('SELECT i.* FROM faq_questions AS i WHERE i.category_id = ? AND i.language = ? AND i.hidden = ? ORDER BY i.sequence', array((int) $categoryId, FRONTEND_LANGUAGE, 'N')); }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $searchTerm = SpoonFilter::getPostValue('term', null, ''); $term = SPOON_CHARSET == 'utf-8' ? SpoonFilter::htmlspecialchars($searchTerm) : SpoonFilter::htmlentities($searchTerm); // validate if ($term == '') { $this->output(self::BAD_REQUEST, null, 'term-parameter is missing.'); } // previous search result $previousTerm = SpoonSession::exists('searchTerm') ? SpoonSession::get('searchTerm') : ''; SpoonSession::set('searchTerm', ''); // save this term? if ($previousTerm != $term) { // format data $this->statistics = array(); $this->statistics['term'] = $term; $this->statistics['language'] = FRONTEND_LANGUAGE; $this->statistics['time'] = FrontendModel::getUTCDate(); $this->statistics['data'] = serialize(array('server' => $_SERVER)); $this->statistics['num_results'] = FrontendSearchModel::getTotal($term); // save data FrontendSearchModel::save($this->statistics); } // save current search term in cookie SpoonSession::set('searchTerm', $term); // output $this->output(self::OK); }
/** * Parse the data into the template */ private function parse() { // show message $this->tpl->assign('locationItems', FrontendLocationModel::getAll()); // hide form $this->tpl->assign('locationSettings', FrontendModel::getModuleSettings('location')); }
/** * Gets the active theme name * * @return string */ public static function getTheme() { // theme nama has not yet been saved, fetch and save it if (!self::$theme) { self::$theme = FrontendModel::getModuleSetting('core', 'theme', null); } // return theme name return self::$theme; }
/** * Parse the footer into the template */ public function parse() { // get footer links $footerLinks = (array) FrontendNavigation::getFooterLinks(); // assign footer links $this->tpl->assign('footerLinks', $footerLinks); // initial value for footer HTML $siteHTMLFooter = (string) FrontendModel::getModuleSetting('core', 'site_html_footer', null); // facebook admins given? if (FrontendModel::getModuleSetting('core', 'facebook_admin_ids', null) !== null || FrontendModel::getModuleSetting('core', 'facebook_app_id', null) !== null) { // build correct locale switch (FRONTEND_LANGUAGE) { case 'en': $locale = 'en_US'; break; case 'zh': $locale = 'zh_CN'; break; case 'cs': $locale = 'cs_CZ'; break; case 'el': $locale = 'el_GR'; break; case 'ja': $locale = 'ja_JP'; break; case 'sv': $locale = 'sv_SE'; break; case 'uk': $locale = 'uk_UA'; break; default: $locale = strtolower(FRONTEND_LANGUAGE) . '_' . strtoupper(FRONTEND_LANGUAGE); } // add Facebook container $siteHTMLFooter .= "\n" . '<div id="fb-root"></div>' . "\n"; // add facebook JS $siteHTMLFooter .= '<script>' . "\n"; if (FrontendModel::getModuleSetting('core', 'facebook_app_id', null) !== null) { $siteHTMLFooter .= ' window.fbAsyncInit = function() {' . "\n"; $siteHTMLFooter .= ' FB.init({ appId: \'' . FrontendModel::getModuleSetting('core', 'facebook_app_id', null) . '\', status: true, cookie: true, xfbml: true, oauth: true });' . "\n"; $siteHTMLFooter .= ' jsFrontend.facebook.afterInit();' . "\n"; $siteHTMLFooter .= ' };' . "\n"; } $siteHTMLFooter .= ' (function() {' . "\n"; $siteHTMLFooter .= ' var e = document.createElement(\'script\'); e.async = true; e.src = document.location.protocol + "//connect.facebook.net/' . $locale . '/all.js#xfbml=1";' . "\n"; $siteHTMLFooter .= ' document.getElementById(\'fb-root\').appendChild(e);' . "\n"; $siteHTMLFooter .= ' }());' . "\n"; $siteHTMLFooter .= '</script>'; } // assign site wide html $this->tpl->assign('siteHTMLFooter', $siteHTMLFooter); }
/** * 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(); }
/** * Execute the extra. * * @return void */ public function execute() { // logout if (FrontendProfilesAuthentication::isLoggedIn()) { FrontendProfilesAuthentication::logout(); } // trigger event FrontendModel::triggerEvent('profiles', 'after_logout'); // redirect $this->redirect(SITE_URL); }
/** * Parse * * @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 into the metaCustom $this->header->addLink(array('rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => FrontendModel::getModuleSetting('blog', 'rss_title_' . FRONTEND_LANGUAGE), 'href' => $rssLink), true); // assign comments $this->tpl->assign('widgetBlogRecentArticlesList', FrontendBlogModel::getAll(FrontendModel::getModuleSetting('blog', 'recent_articles_list_num_items', 5))); }
/** * 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); // assign articles $this->tpl->assign('items', $this->items); // parse the pagination $this->parsePagination(); }
/** * Load the data, don't forget to validate the incoming data */ private function getData() { $categories = FrontendFaqModel::getCategories(); $limit = FrontendModel::getModuleSetting('faq', 'overview_num_items_per_category', 10); foreach ($categories as $item) { $item['questions'] = FrontendFaqModel::getAllForCategory($item['id'], $limit); // no questions? next! if (empty($item['questions'])) { continue; } // add the category item including the questions $this->items[] = $item; } }
/** * Load the data */ protected function loadData() { $this->items = FrontendLocationModel::getAll(); $this->settings = FrontendLocationModel::getMapSettings(0); $firstMarker = current($this->items); if (empty($this->settings)) { $this->settings = FrontendModel::getModuleSettings('location'); $this->settings['center']['lat'] = $firstMarker['lat']; $this->settings['center']['lng'] = $firstMarker['lng']; } // no center point given yet, use the first occurance if (!isset($this->settings['center'])) { $this->settings['center']['lat'] = $firstMarker['lat']; $this->settings['center']['lng'] = $firstMarker['lng']; } }
/** * Get related "things" based on tags */ private function getRelated() { // loop tags foreach ($this->tags as $tag) { // fetch entries $items = (array) FrontendModel::getDB()->getRecords('SELECT mt.module, mt.other_id FROM modules_tags AS mt INNER JOIN tags AS t ON t.id = mt.tag_id WHERE t.language = ? AND t.tag = ?', array(FRONTEND_LANGUAGE, $tag)); // loop items foreach ($items as $item) { // loop existing items foreach ($this->related as $related) { // already exists if ($item == $related) { continue 2; } } // add to list of related items $this->related[] = $item; } } // loop entries foreach ($this->related as $id => $entry) { // loop excluded records foreach ($this->exclude as $exclude) { // check if this entry should be excluded if ($entry['module'] == $exclude['module'] && $entry['other_id'] == $exclude['other_id']) { unset($this->related[$id]); continue 2; } } // set module class $class = 'Frontend' . SpoonFilter::toCamelCase($entry['module']) . 'Model'; // get module record $this->related[$id] = FrontendTagsModel::callFromInterface($entry['module'], $class, 'getForTags', (array) array($entry['other_id'])); if ($this->related[$id]) { $this->related[$id] = array_pop($this->related[$id]); } // remove empty items if (empty($this->related[$id])) { unset($this->related[$id]); } } // only show 3 $this->related = array_splice($this->related, 0, 3); }
/** * Display */ private function display() { // set variables $this->requestedPage = 1; $this->limit = (int) FrontendModel::getModuleSetting('search', 'overview_num_items', 20); $this->offset = $this->requestedPage * $this->limit - $this->limit; $this->cacheFile = FRONTEND_CACHE_PATH . '/' . $this->getModule() . '/' . FRONTEND_LANGUAGE . '_' . md5($this->term) . '_' . $this->offset . '_' . $this->limit . '.php'; // load the cached data if (!$this->getCachedData()) { // ... or load the real data $this->getRealData(); } // parse $this->parse(); // output $this->output(self::OK, $this->tpl->getContent(FRONTEND_PATH . '/modules/search/layout/templates/results.tpl', false, true)); }
/** * Initialize Facebook */ private function initializeFacebook() { // get settings $facebookApplicationId = FrontendModel::getModuleSetting('core', 'facebook_app_id'); $facebookApplicationSecret = FrontendModel::getModuleSetting('core', 'facebook_app_secret'); // needed data available? if ($facebookApplicationId != '' && $facebookApplicationSecret != '') { // require require_once 'external/facebook.php'; // create instance $facebook = new Facebook($facebookApplicationSecret, $facebookApplicationId); // get the cookie, this will set the access token. $facebook->getCookie(); // store in reference Spoon::set('facebook', $facebook); // trigger event FrontendModel::triggerEvent('core', 'after_facebook_initialization'); } }
/** * Load the data */ protected function loadData() { $this->items = FrontendLocationModel::get($this->data['id']); $this->settings = FrontendLocationModel::getMapSettings($this->data['id']); if (empty($this->settings)) { $settings = FrontendModel::getModuleSettings('location'); $this->settings['width'] = $settings['width_widget']; $this->settings['height'] = $settings['height_widget']; $this->settings['map_type'] = $settings['map_type_widget']; $this->settings['zoom_level'] = $settings['zoom_level_widget']; $this->settings['center']['lat'] = $this->items['lat']; $this->settings['center']['lng'] = $this->items['lng']; } // no center point given yet, use the first occurance if (!isset($this->settings['center'])) { $this->settings['center']['lat'] = $this->items['lat']; $this->settings['center']['lng'] = $this->items['lng']; } $this->settings['maps_url'] = FrontendLocationModel::buildUrl($this->settings, array($this->items)); }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get parameters $term = SpoonFilter::getGetValue('term', null, ''); $limit = (int) FrontendModel::getModuleSetting('search', 'autocomplete_num_items', 10); // validate if ($term == '') { $this->output(self::BAD_REQUEST, null, 'term-parameter is missing.'); } // get matches $matches = FrontendSearchModel::getStartsWith($term, FRONTEND_LANGUAGE, $limit); // get search url $url = FrontendNavigation::getURLForBlock('search'); // loop items and set search url foreach ($matches as &$match) { $match['url'] = $url . '?form=search&q=' . $match['term']; } // output $this->output(self::OK, $matches); }
/** * Parse the search results for this module * * Note: a module's search function should always: * - accept an array of entry id's * - return only the entries that are allowed to be displayed, with their array's index being the entry's id * * @return array * @param array $ids The ids of the found results. */ public static function search(array $ids) { // get db $db = FrontendModel::getDB(); // define ids's to ignore $ignore = array(404); // get items $items = (array) $db->getRecords('SELECT p.id, p.title, m.url, p.revision_id AS text FROM pages AS p INNER JOIN meta AS m ON p.meta_id = m.id INNER JOIN pages_templates AS t ON p.template_id = t.id WHERE p.id IN (' . implode(', ', $ids) . ') AND p.id NOT IN (' . implode(', ', $ignore) . ') AND p.status = ? AND p.hidden = ? AND p.language = ?', array('active', 'N', FRONTEND_LANGUAGE), 'id'); // prepare items for search foreach ($items as &$item) { $item['text'] = implode(' ', (array) $db->getColumn('SELECT pb.html FROM pages_blocks AS pb WHERE pb.revision_id = ? AND pb.status = ?', array($item['text'], 'active'))); $item['full_url'] = FrontendNavigation::getURL($item['id']); } // return return $items; }
/** * 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); } } }
/** * 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(); }
/** * 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')); } } } }
/** * 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); } } }
/** * 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); } } }
/** * Parse the search results for this module * * Note: a module's search function should always: * - accept an array of entry id's * - return only the entries that are allowed to be displayed, with their array's index being the entry's id * * * @return array * @param array $ids The ids of the found results. */ public static function search(array $ids) { // get items $items = (array) FrontendModel::getDB()->getRecords('SELECT i.id, i.title, i.introduction, i.text, m.url FROM blog_posts AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.status = ? AND i.hidden = ? AND i.language = ? AND i.publish_on <= ? AND i.id IN (' . implode(',', $ids) . ')', array('active', 'N', FRONTEND_LANGUAGE, date('Y-m-d H:i') . ':00'), 'id'); // prepare items for search foreach ($items as &$item) { $item['full_url'] = FrontendNavigation::getURLForBlock('blog', 'detail') . '/' . $item['url']; } // return return $items; }