/** * Get the images for an album * * @param int $id * * @return bool */ public static function getImagesForAlbum($id, $limit = 0, $random = false) { if ($random == true) { $orderBy = "RAND()"; } else { $orderBy = "sequence"; } if ($limit > 0) { $records = (array) FrontendModel::getContainer()->get('database')->getRecords('SELECT i.* FROM gallery_images AS i WHERE i.language = ? AND i.album_id = ? ORDER BY ' . $orderBy . ' LIMIT ?', array(FRONTEND_LANGUAGE, (int) $id, $limit)); } else { $records = (array) FrontendModel::getContainer()->get('database')->getRecords('SELECT i.* FROM gallery_images AS i WHERE i.language = ? AND i.album_id = ? ORDER BY ' . $orderBy, array(FRONTEND_LANGUAGE, (int) $id)); } //--Loop records if (!empty($records)) { //--Get the thumbnail-folders $folders = FrontendModel::getThumbnailFolders(FRONTEND_FILES_PATH . '/Gallery/Images', true); //--Create the image-links to the thumbnail folders foreach ($records as &$row) { foreach ($folders as $folder) { $row['image_' . $folder['dirname']] = $folder['url'] . '/' . $folder['dirname'] . '/' . $row['filename']; } } //--Destroy the last $image (because of the reference) -- sugested by http://php.net/manual/en/control-structures.foreach.php unset($row); } return $records; }
/** * Stores a value in a cookie, by default the cookie will expire in one day. * * @param string $key A name for the cookie. * @param mixed $value The value to be stored. Keep in mind that they will be serialized. * @param int $time The number of seconds that this cookie will be available, 30 days is the default. * @param string $path The path on the server in which the cookie will * be available. Use / for the entire domain, /foo * if you just want it to be available in /foo. * @param string $domain The domain that the cookie is available on. Use * .example.com to make it available on all * subdomains of example.com. * @param bool $secure Should the cookie be transmitted over a * HTTPS-connection? If true, make sure you use * a secure connection, otherwise the cookie won't be set. * @param bool $httpOnly Should the cookie only be available through * HTTP-protocol? If true, the cookie can't be * accessed by Javascript, ... * @return bool If set with success, returns true otherwise false. */ public static function set($key, $value, $time = 2592000, $path = '/', $domain = null, $secure = null, $httpOnly = true) { // redefine $key = (string) $key; $value = serialize($value); $time = time() + (int) $time; $path = (string) $path; $httpOnly = (bool) $httpOnly; // when the domain isn't passed and the url-object is available we can set the cookies for all subdomains if ($domain === null && FrontendModel::getContainer()->has('request')) { $domain = '.' . FrontendModel::getContainer()->get('request')->getHost(); } // when the secure-parameter isn't set if ($secure === null) { /* detect if we are using HTTPS, this wil only work in Apache, if you are using nginx you should add the code below into your config: ssl on; fastcgi_param HTTPS on; for lighttpd you should add: setenv.add-environment = ("HTTPS" => "on") */ $secure = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on'; } // set cookie $cookie = setcookie($key, $value, $time, $path, $domain, $secure, $httpOnly); // problem occurred return $cookie === false ? false : true; }
/** * Get an item. * * @param string $id The id of the item to fetch. * * @return array * * @deprecated use doctrine instead */ public static function get($id) { trigger_error('Frontend\\Modules\\ContentBlocks\\Engine is deprecated. Switch to doctrine instead.', E_USER_DEPRECATED); return (array) FrontendModel::getContainer()->get('database')->getRecord('SELECT i.title, i.text, i.template FROM content_blocks AS i WHERE i.id = ? AND i.status = ? AND i.hidden = ? AND i.language = ?', array((int) $id, 'active', 'N', LANGUAGE)); }
public static function getRoom($room_id) { $room = (array) FrontendModel::getContainer()->get('database')->getRecord('SELECT hr.id, hr.title, hr.price, hr.image, hr.count FROM hotels_rooms AS hr WHERE hr.id = ?', array($room_id)); if ($room) { $room['image'] = HOTELS_API_URL . FRONTEND_FILES_URL . '/rooms/images/source/' . $room['image']; } return $room; }
/** * Deletes one or more cookies. * * This overwrites the spoon cookie method and adds the same functionality * as in the set method to automatically set the domain. */ public static function delete() { $domain = null; if (FrontendModel::getContainer()->has('request')) { $domain = '.' . FrontendModel::getContainer()->get('request')->getHost(); } foreach (func_get_args() as $argument) { // multiple arguments are given if (is_array($argument)) { foreach ($argument as $key) { self::delete($key); } } else { // delete the given cookie unset($_COOKIE[(string) $argument]); setcookie((string) $argument, null, 1, '/', $domain); } } }
/** * @param string $name Name of the form. * @param string $action The action (URL) whereto the form will be submitted, if not provided it will * be auto generated. * @param string $method The method to use when submitting the form, default is POST. * @param string $hash The id of the anchor to append to the action-URL. * @param bool $useToken Should we automagically add a form token? */ public function __construct($name, $action = null, $method = 'post', $hash = null, $useToken = true) { $this->URL = Model::getContainer()->get('url'); $this->header = Model::getContainer()->get('header'); $name = (string) $name; if ($hash !== null && strlen($hash) > 0) { $hash = (string) $hash; // check if the # is present if ($hash[0] !== '#') { $hash = '#' . $hash; } } else { $hash = null; } $useToken = (bool) $useToken; $action = $action === null ? '/' . $this->URL->getQueryString() : (string) $action; // call the real form-class parent::__construct((string) $name, $action . $hash, $method, (bool) $useToken); // add default classes $this->setParameter('id', $name); $this->setParameter('class', 'forkForms submitWithLink'); }
/** * The constructor will store the instance in the reference, preset some settings and map the custom modifiers. */ public function __construct() { parent::__construct(func_get_arg(0), func_get_arg(1), func_get_arg(2)); $this->debugMode = Model::getContainer()->getParameter('kernel.debug'); $this->forkSettings = Model::get('fork.settings'); // fork has been installed if ($this->forkSettings) { $this->themePath = FRONTEND_PATH . '/Themes/' . $this->forkSettings->get('Core', 'theme', 'default'); $loader = $this->environment->getLoader(); $loader = new \Twig_Loader_Chain(array($loader, new \Twig_Loader_Filesystem($this->getLoadingFolders()))); $this->environment->setLoader($loader); // connect symphony forms $formEngine = new TwigRendererEngine($this->getFormTemplates('FormLayout.html.twig')); $formEngine->setEnvironment($this->environment); $this->environment->addExtension(new SymfonyFormExtension(new TwigRenderer($formEngine, Model::get('security.csrf.token_manager')))); } $this->environment->disableStrictVariables(); // init Form extension new FormExtension($this->environment); // start the filters / globals TwigFilters::getFilters($this->environment, 'Frontend'); $this->startGlobals($this->environment); }
public static function get($id) { $db = FrontendModel::getContainer()->get('database'); return $db->getRecord("SELECT * FROM media WHERE id = ?", array($id)); }
/** * Load a profile by URL * * @param string $url */ public function loadProfileByUrl($url) { // get profile data $profileData = (array) FrontendModel::getContainer()->get('database')->getRecord('SELECT p.id, p.email, p.status, p.display_name, UNIX_TIMESTAMP(p.registered_on) AS registered_on FROM profiles AS p WHERE p.url = ?', (string) $url); // set properties $this->setId($profileData['id']); $this->setEmail($profileData['email']); $this->setStatus($profileData['status']); $this->setDisplayName($profileData['display_name']); $this->setRegisteredOn($profileData['registered_on']); // get the groups (only the ones we still have access to) $this->groups = (array) FrontendModel::getContainer()->get('database')->getPairs('SELECT pg.id, pg.name FROM profiles_groups AS pg INNER JOIN profiles_groups_rights AS pgr ON pg.id = pgr.group_id WHERE pgr.profile_id = :id AND (pgr.expires_on IS NULL OR pgr.expires_on >= NOW())', array(':id' => (int) $this->getId())); $this->settings = (array) FrontendModel::getContainer()->get('database')->getPairs('SELECT i.name, i.value FROM profiles_settings AS i WHERE i.profile_id = ?', $this->getId()); foreach ($this->settings as &$value) { $value = unserialize($value); } }
/** * Logout a profile. */ public static function logout() { // delete session records FrontendModel::getContainer()->get('database')->delete('profiles_sessions', 'session_id = ?', array(\SpoonSession::getSessionId())); // set is_logged_in to false \SpoonSession::set('frontend_profile_logged_in', false); // delete cookie CommonCookie::delete('frontend_profile_secret_key'); }
/** * Get an item. * * @param string $id The id of the item to fetch. * @return array */ public static function get($id) { return (array) FrontendModel::getContainer()->get('database')->getRecord('SELECT i.title, i.text, i.template FROM content_blocks AS i WHERE i.id = ? AND i.status = ? AND i.hidden = ? AND i.language = ?', array((int) $id, 'active', 'N', FRONTEND_LANGUAGE)); }
/** * Update a profile. * * @param int $id The profile id. * @param array $values The values to update. * @return int */ public static function update($id, array $values) { return (int) FrontendModel::getContainer()->get('database')->update('profiles', $values, 'id = ?', (int) $id); }
/** * Validate searches: check everything that has been marked as 'inactive', if should still be inactive */ public static function validateSearch() { // we'll iterate through the inactive search indices in little batches $offset = 0; $limit = 50; while (1) { // get the inactive indices $searchResults = (array) FrontendModel::getContainer()->get('database')->getRecords('SELECT module, other_id FROM search_index WHERE language = ? AND active = ? GROUP BY module, other_id LIMIT ?, ?', array(FRONTEND_LANGUAGE, 'N', $offset, $limit)); // none found? good news! if (!$searchResults) { return; } // prepare to send to modules $moduleResults = array(); // loop the result set 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 $class = 'Frontend\\Modules\\' . $module . '\\Engine\\Model'; if (is_callable(array($class, 'search'))) { $moduleResults[$module] = call_user_func(array($class, 'search'), $otherIds); // update the ones that are allowed to be searched through self::statusIndex($module, array_keys($moduleResults[$module]), true); } } // didn't even get the amount of result we asked for? no need to ask again! if (count($searchResults) < $offset) { return; } $offset += $limit; } }
/** * Insert data fields. * * @param array $data The data to insert. * @return int */ public static function insertDataField(array $data) { return FrontendModel::getContainer()->get('database')->insert('forms_data_fields', $data); }
/** * Set the language * * @param string $value The (interface-)language, will be used to parse labels. */ public function setLanguage($value) { // get the possible languages $possibleLanguages = Language::getActiveLanguages(); // validate if (!in_array($value, $possibleLanguages)) { // only 1 active language? if (!Model::getContainer()->getParameter('site.multilanguage') && count($possibleLanguages) == 1) { $this->language = array_shift($possibleLanguages); } else { // multiple languages available but none selected throw new Exception('Language invalid.'); } } else { // language is valid: set property $this->language = (string) $value; } // define constant defined('FRONTEND_LANGUAGE') || define('FRONTEND_LANGUAGE', $this->language); // set the locale (we need this for the labels) Language::setLocale($this->language); }
/** * Converts all css to inline styles * * @param string $html * @return string */ private function cssToInlineStyles($html) { $charset = Model::getContainer()->getParameter('kernel.charset'); $cssToInlineStyles = new CssToInlineStyles(); $cssToInlineStyles->setHTML($html); $cssToInlineStyles->setUseInlineStylesBlock(true); $cssToInlineStyles->setEncoding($charset); return (string) $cssToInlineStyles->convert(); }
/** * Check if record exists * * @param string $table Database table name. * @param array $whereValues Values for where query * @param string $where Where query * * @return bool */ public static function exists($table, $whereValues, $where = 'id = ?') { return (bool) FrontendModel::getContainer()->get('database')->getVar('SELECT 1 FROM ' . $table . ' WHERE ' . $where, $whereValues); }
/** * Get all the messages * * @return array */ public static function getMessages() { return Model::getContainer()->getParameter('kernel.debug') === true ? self::$msg : array_merge(self::$fallbackMsg, self::$msg); }
public static function getAllTopGroups() { $groups = FrontendModel::getContainer()->get('database')->getPairs("SELECT i.id, i.title\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM addresses_groups AS i\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/*WHERE i.id = 1 OR i.id = 2*/"); return $groups; }
/** * 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 * * * @param array $ids The ids of the found results. * @return array */ public static function search(array $ids) { $items = (array) FrontendModel::getContainer()->get('database')->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 $detailUrl = FrontendNavigation::getURLForBlock('Blog', 'Detail'); foreach ($items as &$item) { $item['full_url'] = $detailUrl . '/' . $item['url']; } // return return $items; }
/** * Increase the number of views for this item * * @param int $id * @param bool $useful * @param mixed $previousFeedback * * @return array */ public static function updateFeedback($id, $useful, $previousFeedback = null) { // feedback hasn't changed so don't update the counters if ($previousFeedback !== null && $useful == $previousFeedback) { return; } $db = FrontendModel::getContainer()->get('database'); // update counter with current feedback (increase) if ($useful) { $db->execute('UPDATE faq_questions SET num_usefull_yes = num_usefull_yes + 1 WHERE id = ?', array((int) $id)); } else { $db->execute('UPDATE faq_questions SET num_usefull_no = num_usefull_no + 1 WHERE id = ?', array((int) $id)); } // update counter with previous feedback (decrease) if ($previousFeedback) { $db->execute('UPDATE faq_questions SET num_usefull_yes = num_usefull_yes - 1 WHERE id = ?', array((int) $id)); } elseif ($previousFeedback !== null) { $db->execute('UPDATE faq_questions SET num_usefull_no = num_usefull_no - 1 WHERE id = ?', array((int) $id)); } }
/** * 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 * * * @param array $ids The ids of the found results. * @return array */ public static function search(array $ids) { $items = (array) FrontendModel::getContainer()->get('database')->getRecords('SELECT i.title AS title, m.url FROM agenda AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.language = ? AND i.id IN (' . implode(',', $ids) . ')', array(FRONTEND_LANGUAGE), 'id'); // get detail action url $detailUrl = FrontendNavigation::getURLForBlock('Agenda', 'Detail'); // prepare items for search foreach ($items as &$item) { $item['full_url'] = $detailUrl . '/' . $item['url']; } // return return $items; }
/** * Get URL for a given pageId * * @param int $pageId The pageID wherefore you want the URL. * @param string $language The language wherein the URL should be retrieved, * if not provided we will load the language that was provided in the URL. * @return string */ public static function getURL($pageId, $language = null) { $pageId = (int) $pageId; $language = $language !== null ? (string) $language : FRONTEND_LANGUAGE; // init URL $URL = FrontendModel::getContainer()->getParameter('site.multilanguage') ? '/' . $language . '/' : '/'; // get the menuItems $keys = self::getKeys($language); // get the URL, if it doesn't exist return 404 if (!isset($keys[$pageId])) { return self::getURL(404, $language); } else { $URL .= $keys[$pageId]; } // return the URL return urldecode($URL); }
/** * Get all related items * * @param int $id The id of the item in the source-module. * @param int $module The source module. * @param int $otherModule The module wherein the related items should appear. * @param int $limit The maximum of related items to grab. * * @return array */ public static function getRelatedItemsByTags($id, $module, $otherModule, $limit = 5) { return (array) FrontendModel::getContainer()->get('database')->getColumn('SELECT t2.other_id FROM modules_tags AS t INNER JOIN modules_tags AS t2 ON t.tag_id = t2.tag_id WHERE t.other_id = ? AND t.module = ? AND t2.module = ? AND (t2.module != t.module OR t2.other_id != t.other_id) GROUP BY t2.other_id ORDER BY COUNT(t2.tag_id) DESC LIMIT ?', array((int) $id, (string) $module, (string) $otherModule, (int) $limit)); }
/** * Get all items (at least a chunk) * * @param int [optional] $limit The number of items to get. * @param int [optional] $offset The offset. * @return array */ public static function getAllForFrontpage() { $items = (array) FrontendModel::getContainer()->get('database')->getRecords('SELECT i.*,l.* FROM catalog_products AS i INNER JOIN catalog_products_lang AS l ON l.id = i.id AND l.language = ? INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.frontpage = 1 ORDER BY RAND()', array(FRONTEND_LANGUAGE)); // no results? if (empty($items)) { return array(); } // get detail action url $detailUrl = FrontendNavigation::getURLForBlock('Catalog', 'Detail'); // prepare items for search foreach ($items as &$item) { $item['full_url'] = $detailUrl . '/' . $item['url']; } // return return $items; }
/** * * Get the send-mail * * @param $id * * @return array */ public static function getSend($id) { $return = (array) FrontendModel::getContainer()->get('database')->getRecord(' SELECT i.id, i.subject, UNIX_TIMESTAMP(i.start_time) AS start_time, i.text FROM mailengine_send_mails AS i WHERE id = ? AND show_on_website = ?', array($id, 'Y')); $return['text'] = str_replace('[USERID]', self::encryptId(0), $return['text']); return $return; }
/** * Unsubscribes an e-mail address * * @param string $email The mail address to unsubscribe. * @param string $groupId The id of the group to unsubscribe from. * @return bool */ public static function unsubscribe($email, $groupId = null) { // get objects $db = FrontendModel::getContainer()->get('database'); // set groupID $groupId = !empty($groupId) ? $groupId : self::getDefaultGroupID(); // unsubscribe the user in CM if (self::existsGroup($groupId)) { // set variables $subscriber['status'] = 'unsubscribed'; $subscriber['unsubscribed_on'] = FrontendModel::getUTCDate('Y-m-d H:i:s'); // unsubscribe the user $db->update('mailmotor_addresses_groups', $subscriber, 'email = ? AND group_id = ?', array($email, $groupId)); // user unsubscribed return true; } // user not unsubscribed return false; }
/** * Unsubscribes an e-mail address from CampaignMonitor and our database * * @param string $email The e-mail address to unsubscribe. * @param string $groupId The id of the group to unsubscribe from. * @return bool */ public static function unsubscribe($email, $groupId = null) { // get objects $db = FrontendModel::getContainer()->get('database'); $cm = self::getCM(); // set group ID $groupId = !empty($groupId) ? $groupId : FrontendMailmotorModel::getDefaultGroupID(); // get group CM ID $groupCMId = self::getCampaignMonitorID('list', $groupId); // group exists if (FrontendMailmotorModel::existsGroup($groupId)) { try { // unsubscribe the email from this group $cm->unsubscribe($email, $groupCMId); } catch (\Exception $e) { // for the unsubscribe function we ignore any errors // stop here if something went wrong with CM return false; } // set variables $subscriber['status'] = 'unsubscribed'; $subscriber['unsubscribed_on'] = FrontendModel::getUTCDate('Y-m-d H:i:s'); // unsubscribe the user $db->update('mailmotor_addresses_groups', $subscriber, 'email = ? AND group_id = ?', array($email, $groupId)); // user unsubscribed return true; } // user not unsubscribed return false; }
/** * 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 * * @param array $ids The ids of the found results. * @return array */ public static function search(array $ids) { // get db $db = FrontendModel::getContainer()->get('database'); // define ids 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 themes_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 = ?', array($item['text']))); $item['full_url'] = FrontendNavigation::getURL($item['id']); } return $items; }
/** * Fetch all the settings for a specific map * * @param int $mapId * * @return array */ public static function getMapSettings($mapId) { $mapSettings = (array) FrontendModel::getContainer()->get('database')->getPairs('SELECT s.name, s.value FROM location_settings AS s WHERE s.map_id = ?', array((int) $mapId)); foreach ($mapSettings as $key => $value) { $mapSettings[$key] = unserialize($value); } return $mapSettings; }