/** * 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']); } } }
/** * Returns the CampaignMonitor object * * @param int[optional] $listId The default list id to use. * @return CampaignMonitor */ public static function getCM($listId = null) { // campaignmonitor reference exists if (!Spoon::exists('campaignmonitor')) { // check if the CampaignMonitor class exists if (!SpoonFile::exists(PATH_LIBRARY . '/external/campaignmonitor.php')) { // the class doesn't exist, so throw an exception throw new SpoonFileException('The CampaignMonitor wrapper class is not found. Please locate and place it in /library/external'); } // require CampaignMonitor class require_once 'external/campaignmonitor.php'; // set login data $url = FrontendModel::getModuleSetting('mailmotor', 'cm_url'); $username = FrontendModel::getModuleSetting('mailmotor', 'cm_username'); $password = FrontendModel::getModuleSetting('mailmotor', 'cm_password'); // init CampaignMonitor object $cm = new CampaignMonitor($url, $username, $password, 5, self::getClientId()); // set CampaignMonitor object reference Spoon::set('campaignmonitor', $cm); // get the default list ID $listId = !empty($listId) ? $listId : self::getDefaultListID(); // set the default list ID $cm->setListId($listId); } // return the CampaignMonitor object return Spoon::get('campaignmonitor'); }
/** * 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(); }
/** * 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))); }
/** * 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; } }
/** * 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(); }
/** * Display */ private function display() { // set variables $this->requestedPage = $this->URL->getParameter('page', 'int', 1); $this->limit = 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(); }
/** * 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'); } }
/** * 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); }
/** * The default constructor * * @return void * @param string $title The title off the feed. * @param string $link The link of the feed. * @param string $description The description of the feed. * @param array[optional] $items An array with SpoonRSSItems. */ public function __construct($title, $link, $description, array $items = array()) { // decode $title = SpoonFilter::htmlspecialcharsDecode($title); $description = SpoonFilter::htmlspecialcharsDecode($description); // call the parent parent::__construct($title, FrontendModel::addURLParameters($link, array('utm_source' => 'feed', 'utm_medium' => 'rss', 'utm_campaign' => SpoonFilter::urlise($title))), $description, $items); // set feed properties $this->setLanguage(FRONTEND_LANGUAGE); $this->setCopyright(SpoonDate::getDate('Y') . ' ' . SpoonFilter::htmlspecialcharsDecode(FrontendModel::getModuleSetting('core', 'site_title_' . FRONTEND_LANGUAGE))); $this->setGenerator(SITE_RSS_GENERATOR); $this->setImage(SITE_URL . FRONTEND_CORE_URL . '/layout/images/rss_image.png', $title, $link); // theme was set if (FrontendModel::getModuleSetting('core', 'theme', null) != null) { // theme name $theme = FrontendModel::getModuleSetting('core', 'theme', null); // theme rss image exists if (SpoonFile::exists(PATH_WWW . '/frontend/themes/' . $theme . '/core/images/rss_image.png')) { // set rss image $this->setImage(SITE_URL . '/frontend/themes/' . $theme . '/core/images/rss_image.png', $title, $link); } } }
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); }
/** * Returns the client ID from the settings * * @return string */ public static function getClientID() { return (string) FrontendModel::getModuleSetting('mailmotor', 'cm_client_id'); }
/** * Formats a timestamp as a string that indicates the time ago * syntax: {$var|timeago} * * @param string[optional] $var A UNIX-timestamp that will be formated as a time-ago-string. * @return string */ public static function timeAgo($var = null) { $var = (int) $var; // invalid timestamp if ($var == 0) { return ''; } // return return '<abbr title="' . SpoonDate::getDate(FrontendModel::getModuleSetting('core', 'date_format_long') . ', ' . FrontendModel::getModuleSetting('core', 'time_format'), $var, FRONTEND_LANGUAGE) . '">' . SpoonDate::getTimeAgo($var, FRONTEND_LANGUAGE) . '</abbr>'; }
/** * Push a notification to Microsoft's notifications-server * * @param string $title The title for the tile to send. * @param string[optional] $count The count for the tile to send. * @param string[optional] $image The image for the tile to send. * @param string[optional] $backTitle The title for the tile backtround to send. * @param string[optional] $backText The text for the tile background to send. * @param string[optional] $backImage The image for the tile background to send. * @param string[optional] $tile The secondary tile to update. * @param string[optional] $uri The application uri to navigate to. */ public static function pushToMicrosoftApp($title, $count = null, $image = null, $backTitle = null, $backText = null, $backImage = null, $tile = null, $uri = null) { // get ForkAPI-keys $publicKey = FrontendModel::getModuleSetting('core', 'fork_api_public_key', ''); $privateKey = FrontendModel::getModuleSetting('core', 'fork_api_private_key', ''); // no keys, so stop here if ($publicKey == '' || $privateKey == '') { return; } // get all microsoft channel uri's $channelUris = (array) FrontendModel::getDB()->getColumn('SELECT s.value FROM users AS i INNER JOIN users_settings AS s WHERE i.active = ? AND i.deleted = ? AND s.name = ? AND s.value != ?', array('Y', 'N', 'microsoft_channel_uri', 'N;')); // no devices, so stop here if (empty($channelUris)) { return; } // init var $uris = array(); // loop devices foreach ($channelUris as $row) { // unserialize $row = unserialize($row); // loop and add foreach ($row as $item) { $uris[] = $item; } } // no channel uri's, so stop here if (empty($uris)) { return; } // require the class require_once PATH_LIBRARY . '/external/fork_api.php'; // create instance $forkAPI = new ForkAPI($publicKey, $privateKey); try { // push $forkAPI->microsoftPush($uris, $title, $count, $image, $backTitle, $backText, $backImage, $tile, $uri); } catch (Exception $e) { if (SPOON_DEBUG) { throw $e; } } }
/** * Parse */ private function parse() { $this->tpl->assign('widgetFaqMostRead', FrontendFaqModel::getMostRead(FrontendModel::getModuleSetting('faq', 'most_read_num_items', 10))); }
/** * Get navigation HTML * * @return string * @param string[optional] $type The type of navigation the HTML should be build for. * @param int[optional] $parentId The parentID to start of. * @param int[optional] $depth The maximum depth to parse. * @param array[optional] $excludeIds PageIDs to be excluded. * @param bool[optional] $includeChildren Children can be included regardless of whether we're at the current page. * @param int[optional] $depthCounter A counter that will hold the current depth. */ public static function getNavigationHTML($type = 'page', $parentId = 0, $depth = null, $excludeIds = array(), $includeChildren = false, $depthCounter = 1) { // get navigation $navigation = self::getNavigation(); // meta-navigation is requested but meta isn't enabled if ($type == 'meta' && !FrontendModel::getModuleSetting('pages', 'meta_navigation', true)) { return ''; } // validate if (!isset($navigation[$type])) { throw new FrontendException('This type (' . $type . ') isn\'t a valid navigation type. Possible values are: page, footer, meta.'); } if (!isset($navigation[$type][$parentId])) { throw new FrontendException('The parent (' . $parentId . ') doesn\'t exists.'); } // special construction to merge home with it's immediate children $mergedHome = false; while (true) { // loop elements foreach ($navigation[$type][$parentId] as $id => $page) { // home is a special item, it should live on the same depth if ($page['page_id'] == 1 && !$mergedHome) { // extra checks otherwise exceptions will wbe triggered. if (!isset($navigation[$type][$parentId]) || !is_array($navigation[$type][$parentId])) { $navigation[$type][$parentId] = array(); } if (!isset($navigation[$type][$page['page_id']]) || !is_array($navigation[$type][$page['page_id']])) { $navigation[$type][$page['page_id']] = array(); } // add children $navigation[$type][$parentId] = array_merge($navigation[$type][$parentId], $navigation[$type][$page['page_id']]); // mark as merged $mergedHome = true; // restart loop continue 2; } // not hidden if ($page['hidden']) { unset($navigation[$type][$parentId][$id]); continue; } // some ids should be excluded if (in_array($page['page_id'], (array) $excludeIds)) { unset($navigation[$type][$parentId][$id]); continue; } // if the item is in the selected page it should get an selected class if (in_array($page['page_id'], self::$selectedPageIds)) { $navigation[$type][$parentId][$id]['selected'] = true; } else { $navigation[$type][$parentId][$id]['selected'] = false; } // add nofollow attribute if needed if ($page['no_follow']) { $navigation[$type][$parentId][$id]['nofollow'] = true; } else { $navigation[$type][$parentId][$id]['nofollow'] = false; } // has children and is selected and is desired? if (isset($navigation[$type][$page['page_id']]) && $page['page_id'] != 1 && ($navigation[$type][$parentId][$id]['selected'] == true || $includeChildren) && ($depth == null || $depthCounter + 1 <= $depth)) { $navigation[$type][$parentId][$id]['children'] = self::getNavigationHTML($type, $page['page_id'], $depth, $excludeIds, $includeChildren, $depthCounter + 1); } else { $navigation[$type][$parentId][$id]['children'] = false; } // add parent id $navigation[$type][$parentId][$id]['parent_id'] = $parentId; // add depth $navigation[$type][$parentId][$id]['depth'] = $depth; // set link $navigation[$type][$parentId][$id]['link'] = FrontendNavigation::getURL($page['page_id']); // is this an internal redirect? if (isset($page['redirect_page_id']) && $page['redirect_page_id'] != '') { $navigation[$type][$parentId][$id]['link'] = FrontendNavigation::getURL((int) $page['redirect_page_id']); } // is this an external redirect? if (isset($page['redirect_url']) && $page['redirect_url'] != '') { $navigation[$type][$parentId][$id]['link'] = $page['redirect_url']; } } // break the loop (it is only used for the special construction with home) break; } // create template $tpl = new FrontendTemplate(false); // assign navigation to template $tpl->assign('navigation', $navigation[$type][$parentId]); // return parsed content return $tpl->getContent(self::$templatePath, true, true); }
/** * Search * The actual search will be performed by the execSearch() method. * It will then pass on the results to the specific modules, which are then responsible for returning the required data and filtering out unwanted results (entries that should not be shown) * The activation/deactivation of search indices will automatically be handled by this function to keep the search index up to date, based on the module's returned results * * This function can be called with either a string as parameter (simple search) or an array (advanced search) * Simple search: all search index fields will be searched for the given term * Advanced search: only the given fields (keys in the array) will be matched to the corresponding values (correspinding values in the array) * * @param mixed $term The searchterm (simple search) or the fields to search for (advanced search - please note that the field names may not be consistent throughout several modules). * @param int[optional] $limit The number of articles to get. * @param int[optional] $offset The offset. * @return array */ public static function search($term, $limit = 20, $offset = 0) { // revalidate searches if (FrontendModel::getModuleSetting('search', 'validate_search', true) == true) { self::validateSearch(); } // @note: on heavy sites with a lot of inactive search indices better use a cronjob (which will automatically set this module setting to N) // execute the actual search $searchResults = self::execSearch($term, $limit, $offset); // get the total amount of results (we'll get back to this later ;) ) $total = count($searchResults); // none found? return empty :( if (!$searchResults) { return array(); } // prepare to send to modules $moduleResults = array(); // loop the resultset foreach ($searchResults as $searchResult) { $moduleResults[$searchResult['module']][] = $searchResult['other_id']; } // pass the results to the modules foreach ($moduleResults as $module => $otherIds) { // check if this module actually is prepared to handle searches (well it should, because else there shouldn't be any search indices) if (is_callable(array('Frontend' . SpoonFilter::toCamelCase($module) . 'Model', 'search'))) { // get the required info from our module $moduleResults[$module] = call_user_func(array('Frontend' . SpoonFilter::toCamelCase($module) . 'Model', 'search'), $otherIds); } else { unset($moduleResults[$module]); } } // now place the prepared data back in our original resultset, which has our results in correct order foreach ($searchResults as $i => $result) { // loop parsed results for this specific module to find the one we want here foreach ($moduleResults[$result['module']] as $otherId => $moduleResult) { // that's the one.. if ($otherId == $result['other_id']) { $searchResults[$i] = array_merge(array('module' => $result['module']), $moduleResult); continue 2; } } // if we made it here, we obviously did not get this result parsed by the module, so remove it! unset($searchResults[$i]); self::statusIndex($result['module'], (array) $result['other_id'], false); } // results got removed by the module? oh noes :o have another run, because now we've deactivated those responsible for the holes :) if (count($searchResults) < $total && $total == $limit) { $searchResults = self::search($term, $limit, $offset); } // return results return $searchResults; }
/** * Set the pagetitle * * @return void * @param string $value The pagetitle to be set or to be prepended. * @param bool[optional] $overwrite Should the existing pagetitle be overwritten? */ public function setPageTitle($value, $overwrite = false) { // redefine vars $value = trim((string) $value); $overwrite = (bool) $overwrite; // overwrite? reset the current value if ($overwrite) { $this->pageTitle = $value; } else { // empty value given? if (empty($value)) { $this->pageTitle = FrontendModel::getModuleSetting('core', 'site_title_' . FRONTEND_LANGUAGE, SITE_DEFAULT_TITLE); } else { // if the current pagetitle is empty we should add the sitetitle if ($this->pageTitle == '') { $this->pageTitle = $value . SITE_TITLE_SEPERATOR . FrontendModel::getModuleSetting('core', 'site_title_' . FRONTEND_LANGUAGE, SITE_DEFAULT_TITLE); } else { $this->pageTitle = $value . SITE_TITLE_SEPERATOR . $this->pageTitle; } } } }
/** * Add a Microsoft device to a user. * * @param string $uri The uri of the channel opened for the device. * @param string $email The emailaddress for the user to link the device to. */ public static function microsoftAdddevice($uri, $email) { if (API::authorize()) { // redefine $uri = (string) $uri; // validate if ($uri == '') { API::output(API::BAD_REQUEST, array('message' => 'No uri-parameter provided.')); } if ($email == '') { API::output(API::BAD_REQUEST, array('message' => 'No email-parameter provided.')); } // we should tell the ForkAPI that we registered a device $publicKey = BackendModel::getModuleSetting('core', 'fork_api_public_key', ''); $privateKey = FrontendModel::getModuleSetting('core', 'fork_api_private_key', ''); // validate keys if ($publicKey == '' || $privateKey == '') { API::output(API::BAD_REQUEST, array('message' => 'Invalid key for the Fork API, configure them in the backend.')); } try { // load user $user = new BackendUser(null, $email); // get current uris $uris = (array) $user->getSetting('microsoft_channel_uri'); // not already in array? if (!in_array($uri, $uris)) { $uris[] = $uri; } // require the class require_once PATH_LIBRARY . '/external/fork_api.php'; // create instance $forkAPI = new ForkAPI($publicKey, $privateKey); // make the call $forkAPI->microsoftRegisterDevice($uris); // store if (!empty($uris)) { $user->setSetting('microsoft_channel_uri', $uris); } } catch (Exception $e) { API::output(API::FORBIDDEN, array('message' => 'Can\'t authenticate you.')); } } }
/** * 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); } }
/** * Remove a device from a user. * * @return void * @param string $token The token of the device. * @param string $email The emailaddress for the user to link the device to. */ public static function appleRemovedevice($token, $email) { // authorized? if (API::authorize()) { // redefine $token = str_replace(' ', '', (string) $token); // validate if ($token == '') { API::output(API::BAD_REQUEST, array('message' => 'No token-parameter provided.')); } if ($email == '') { API::output(API::BAD_REQUEST, array('message' => 'No email-parameter provided.')); } // we should tell the ForkAPI that we registered a device $publicKey = BackendModel::getModuleSetting('core', 'fork_api_public_key', ''); $privateKey = FrontendModel::getModuleSetting('core', 'fork_api_private_key', ''); // validate keys if ($publicKey == '' || $privateKey == '') { API::output(API::BAD_REQUEST, array('message' => 'Invalid key for the Fork API, configer them in the backend.')); } try { // load user $user = new BackendUser(null, $email); // get current tokens $tokens = (array) $user->getSetting('apple_device_token'); // not already in array? $index = array_search($token, $tokens); if ($index !== false) { // remove from array unset($tokens[$index]); // save it $user->setSetting('apple_device_token', $tokens); } } catch (Exception $e) { API::output(API::FORBIDDEN, array('message' => 'Can\'t authenticate you.')); } } }
/** * Process the querystring * * @return void */ private function processQueryString() { // store the querystring local, so we don't alter it. $queryString = $this->getQueryString(); // fix GET-parameters $getChunks = explode('?', $queryString); // are there GET-parameters if (isset($getChunks[1])) { // get key-value pairs $get = explode('&', $getChunks[1]); // remove from querystring $queryString = str_replace('?' . $getChunks[1], '', $this->getQueryString()); // loop pairs foreach ($get as $getItem) { // get key and value $getChunks = explode('=', $getItem, 2); // key available? if (isset($getChunks[0])) { // reset in $_GET $_GET[$getChunks[0]] = isset($getChunks[1]) ? (string) $getChunks[1] : ''; // add into parameters if (isset($getChunks[1])) { $this->parameters[(string) $getChunks[0]] = (string) $getChunks[1]; } } } } // split into chunks $chunks = (array) explode('/', $queryString); // single language if (!SITE_MULTILANGUAGE) { // set language id $language = FrontendModel::getModuleSetting('core', 'default_language', SITE_DEFAULT_LANGUAGE); } else { // default value $mustRedirect = false; // get possible languages $possibleLanguages = (array) FrontendLanguage::getActiveLanguages(); $redirectLanguages = (array) FrontendLanguage::getRedirectLanguages(); // the language is present in the URL if (isset($chunks[0]) && in_array($chunks[0], $possibleLanguages)) { // define language $language = (string) $chunks[0]; // try to set a cookie with the language try { // set cookie SpoonCookie::set('frontend_language', $language, 7 * 24 * 60 * 60, '/', '.' . $this->getDomain()); } catch (SpoonCookieException $e) { // settings cookies isn't allowed, because this isn't a real problem we ignore the exception } // set sessions SpoonSession::set('frontend_language', $language); // remove the language part array_shift($chunks); } elseif (SpoonCookie::exists('frontend_language') && in_array(SpoonCookie::get('frontend_language'), $redirectLanguages)) { // set languageId $language = (string) SpoonCookie::get('frontend_language'); // redirect is needed $mustRedirect = true; } else { // set languageId & abbreviation $language = FrontendLanguage::getBrowserLanguage(); // try to set a cookie with the language try { // set cookie SpoonCookie::set('frontend_language', $language, 7 * 24 * 60 * 60, '/', '.' . $this->getDomain()); } catch (SpoonCookieException $e) { // settings cookies isn't allowed, because this isn't a real problem we ignore the exception } // redirect is needed $mustRedirect = true; } // redirect is required if ($mustRedirect) { // build URL $URL = rtrim('/' . $language . '/' . $this->getQueryString(), '/'); // set header & redirect SpoonHTTP::redirect($URL, 301); } } // define the language define('FRONTEND_LANGUAGE', $language); // sets the localefile FrontendLanguage::setLocale($language); // list of pageIds & their full URL $keys = FrontendNavigation::getKeys(); // full URL $URL = implode('/', $chunks); $startURL = $URL; // loop until we find the URL in the list of pages while (!in_array($URL, $keys)) { // remove the last chunk array_pop($chunks); // redefine the URL $URL = implode('/', $chunks); } // remove language from querystring if (SITE_MULTILANGUAGE) { $queryString = trim(substr($queryString, strlen($language)), '/'); } // if it's the homepage AND parameters were given (not allowed!) if ($URL == '' && $queryString != '') { // get 404 URL $URL = FrontendNavigation::getURL(404); // remove language if (SITE_MULTILANGUAGE) { $URL = str_replace('/' . $language, '', $URL); } } // set pages $URL = trim($URL, '/'); // currently not in the homepage if ($URL != '') { // explode in pages $pages = explode('/', $URL); // reset pages $this->setPages($pages); // reset parameters $this->setParameters(array()); } // set parameters $parameters = trim(substr($startURL, strlen($URL)), '/'); // has at least one parameter if ($parameters != '') { // parameters will be separated by / $parameters = explode('/', $parameters); // set parameters $this->setParameters($parameters); } // pageId, parentId & depth $pageId = FrontendNavigation::getPageId(implode('/', $this->getPages())); $pageInfo = FrontendNavigation::getPageInfo($pageId); // invalid page, or parameters but no extra if ($pageInfo === false || !empty($parameters) && !$pageInfo['has_extra']) { // get 404 URL $URL = FrontendNavigation::getURL(404); // remove language if (SITE_MULTILANGUAGE) { $URL = trim(str_replace('/' . $language, '', $URL), '/'); } // currently not in the homepage if ($URL != '') { // explode in pages $pages = explode('/', $URL); // reset pages $this->setPages($pages); // reset parameters $this->setParameters(array()); } } // is this an internal redirect? if (isset($pageInfo['redirect_page_id']) && $pageInfo['redirect_page_id'] != '') { // get url for item $newPageURL = FrontendNavigation::getURL((int) $pageInfo['redirect_page_id']); $errorURL = FrontendNavigation::getURL(404); // not an error? if ($newPageURL != $errorURL) { // redirect SpoonHTTP::redirect($newPageURL, $pageInfo['redirect_code']); } } // is this an external redirect? if (isset($pageInfo['redirect_url']) && $pageInfo['redirect_url'] != '') { // redirect SpoonHTTP::redirect($pageInfo['redirect_url'], $pageInfo['redirect_code']); } }
/** * Send an email * * @return void * @param int $id The id of the mail to send. */ public static function send($id) { // redefine $id = (int) $id; // get db $db = FrontendModel::getDB(true); // get record $emailRecord = (array) $db->getRecord('SELECT * FROM emails AS e WHERE e.id = ?', array($id)); // mailer type $mailerType = FrontendModel::getModuleSetting('core', 'mailer_type', 'mail'); // create new SpoonEmail-instance $email = new SpoonEmail(); $email->setTemplateCompileDirectory(FRONTEND_CACHE_PATH . '/compiled_templates'); // send via SMTP if ($mailerType == 'smtp') { // get settings $SMTPServer = FrontendModel::getModuleSetting('core', 'smtp_server'); $SMTPPort = FrontendModel::getModuleSetting('core', 'smtp_port', 25); $SMTPUsername = FrontendModel::getModuleSetting('core', 'smtp_username'); $SMTPPassword = FrontendModel::getModuleSetting('core', 'smtp_password'); // set server and connect with SMTP $email->setSMTPConnection($SMTPServer, $SMTPPort, 10); // set authentication if needed if ($SMTPUsername !== null && $SMTPPassword !== null) { $email->setSMTPAuth($SMTPUsername, $SMTPPassword); } } // set some properties $email->setFrom($emailRecord['from_email'], $emailRecord['from_name']); $email->addRecipient($emailRecord['to_email'], $emailRecord['to_name']); $email->setReplyTo($emailRecord['reply_to_email']); $email->setSubject($emailRecord['subject']); $email->setHTMLContent($emailRecord['html']); $email->setCharset(SPOON_CHARSET); $email->setContentTransferEncoding('base64'); if ($emailRecord['plain_text'] != '') { $email->setPlainContent($emailRecord['plain_text']); } // attachments added if (isset($emailRecord['attachments']) && $emailRecord['attachments'] !== null) { // unserialize $attachments = (array) unserialize($emailRecord['attachments']); // add attachments to email foreach ($attachments as $attachment) { $email->addAttachment($attachment); } } // send the email if ($email->send()) { // remove the email $db->delete('emails', 'id = ?', array($id)); // trigger event FrontendModel::triggerEvent('core', 'after_email_sent', array('id' => $id)); } }
/** * 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(); }
/** * 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(); }
/** * 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); // get RSS-link for the comments $rssCommentsLink = FrontendNavigation::getURLForBlock('blog', 'article_comments_rss') . '/' . $this->record['url']; // add RSS-feed into the metaCustom $this->header->addLink(array('rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => vsprintf(FL::msg('CommentsOn'), array($this->record['title'])), 'href' => $rssCommentsLink), true); // build Facebook Open Graph-data if (FrontendModel::getModuleSetting('core', 'facebook_admin_ids', null) !== null || FrontendModel::getModuleSetting('core', 'facebook_app_id', null) !== null) { // add specified image if (isset($this->record['image']) && $this->record['image'] != '') { $this->header->addOpenGraphImage(FRONTEND_FILES_URL . '/blog/images/source/' . $this->record['image']); } // add images from content $this->header->extractOpenGraphImages($this->record['text']); // add additional OpenGraph data $this->header->addOpenGraphData('title', $this->record['title'], true); $this->header->addOpenGraphData('type', 'article', true); $this->header->addOpenGraphData('url', SITE_URL . FrontendNavigation::getURLForBlock('blog', 'detail') . '/' . $this->record['url'], true); $this->header->addOpenGraphData('site_name', FrontendModel::getModuleSetting('core', 'site_title_' . FRONTEND_LANGUAGE, SITE_DEFAULT_TITLE), true); $this->header->addOpenGraphData('description', $this->record['title'], true); } // when there are 2 or more categories with at least one item in it, the category will be added in the breadcrumb if (count(FrontendBlogModel::getAllCategories()) > 1) { $this->breadcrumb->addElement($this->record['category_title'], FrontendNavigation::getURLForBlock('blog', 'category') . '/' . $this->record['category_url']); } // add into breadcrumb $this->breadcrumb->addElement($this->record['title']); // set meta $this->header->setPageTitle($this->record['meta_title'], $this->record['meta_title_overwrite'] == 'Y'); $this->header->addMetaDescription($this->record['meta_description'], $this->record['meta_description_overwrite'] == 'Y'); $this->header->addMetaKeywords($this->record['meta_keywords'], $this->record['meta_keywords_overwrite'] == 'Y'); // advanced SEO-attributes if (isset($this->record['meta_data']['seo_index'])) { $this->header->addMetaData(array('name' => 'robots', 'content' => $this->record['meta_data']['seo_index'])); } if (isset($this->record['meta_data']['seo_follow'])) { $this->header->addMetaData(array('name' => 'robots', 'content' => $this->record['meta_data']['seo_follow'])); } $this->header->setCanonicalUrl(FrontendNavigation::getURLForBlock('blog', 'detail') . '/' . $this->record['url']); // assign article $this->tpl->assign('item', $this->record); // count comments $commentCount = count($this->comments); // assign the comments $this->tpl->assign('commentsCount', $commentCount); $this->tpl->assign('comments', $this->comments); // options if ($commentCount > 1) { $this->tpl->assign('blogCommentsMultiple', true); } // parse the form $this->frm->parse($this->tpl); // some options if ($this->URL->getParameter('comment', 'string') == 'moderation') { $this->tpl->assign('commentIsInModeration', true); } if ($this->URL->getParameter('comment', 'string') == 'spam') { $this->tpl->assign('commentIsSpam', true); } if ($this->URL->getParameter('comment', 'string') == 'true') { $this->tpl->assign('commentIsAdded', true); } // assign settings $this->tpl->assign('settings', $this->settings); // assign navigation $this->tpl->assign('navigation', FrontendBlogModel::getNavigation($this->record['id'])); }
/** * Parse the data into the template */ private function parse() { // parse the form $this->frm->parse($this->tpl); // no search term = no search if (!$this->term) { return; } // loop items 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, '', '&'); } // assign articles $this->tpl->assign('searchResults', $this->items); $this->tpl->assign('searchTerm', $this->term); // parse the pagination $this->parsePagination(); }