/** * Get the current URL asked tag * * @param FTL_Binding $tag * * @return string * */ public static function tag_tag_current(FTL_Binding $tag) { // Asked category $url_tag_name = self::get_asked_tag_uri(); // Category detail if (!is_null($url_tag_name)) { // Categories model self::$ci->load->model('tag_model'); $t = self::$ci->tag_model->get(array('tag_name' => urldecode($url_tag_name))); if (!empty($t)) { $t['title'] = $t['tag_name']; } $tag->set('current', $t); } else { $tag->set('current', array()); } return $tag->expand(); }
/** * Returns one article's author * * @param FTL_Binding * * @return string * * @usage <ion:article:user [who='updater']> * <ion:name /> * <ion:email /> * <ion:join_date /> * ... * </ion:article:user> * */ public static function tag_writer(FTL_Binding $tag) { self::load_model('user_model'); $parent_tag_name = $tag->getParentName(); $element = $tag->get($parent_tag_name); $user_key = $tag->getAttribute('who', 'author'); if (!is_null($element) && isset($element[$user_key])) { $user = self::$ci->user_model->get(array('username' => $element[$user_key])); $tag->set('writer', $user); } return self::wrap($tag, $tag->expand()); }
/** * Returns pages from one given parent page * * @TODO Check and finish writing * Planned for 1.0 * * @param FTL_Binding * * @return mixed */ public static function tag_pages(FTL_Binding $tag) { $cache = $tag->getAttribute('cache', TRUE); // Tag cache // if ($cache == TRUE && ($str = self::get_cache(FTL_Binding $tag)) !== FALSE) // return $str; // Returned string $str = ''; $parent = $tag->getAttribute('parent'); $mode = $tag->getAttribute('mode', 'flat'); $levels = $tag->getAttribute('levels'); $menu_name = $tag->getAttribute('menu'); $parent_page = NULL; // Display hidden navigation elements ? $display_hidden = $tag->getAttribute('display_hidden', FALSE); $limit = $tag->getAttribute('limit'); if (!is_null($parent)) { if (strval(abs((int) $parent)) == (string) $parent) { $parent_page = self::get_page_by_id($parent); } else { if (substr($parent, 0, 1) == '-') { $parent_page = self::get_relative_parent_page(self::registry('page'), $parent, $display_hidden); } else { if ($parent == 'this') { $parent_page = self::registry('page'); } else { $parent_page = self::get_page_by_code($parent); } } } } $data = self::registry('pages'); if (!empty($parent_page)) { if ($mode == 'tree') { $pages = Structure::get_tree_navigation($data, $parent_page['id_page']); } else { $pages = array(); Structure::get_nested_structure($data, $pages, $parent_page['id_page']); } } else { $pages = self::registry('pages'); } // Limit pages to a certain level if (!is_null($levels)) { $levels = (int) $levels; for ($i = count($pages) - 1; $i >= 0; $i--) { if ($pages[$i]['level'] > $levels) { unset($pages[$i]); } } $pages = array_values($pages); } // Limit pages to a certain menu if (!is_null($menu_name)) { // By default main menu $id_menu = 1; foreach (self::registry('menus') as $menu) { if ($menu_name == $menu['name']) { $id_menu = $menu['id_menu']; } } for ($i = count($pages) - 1; $i >= 0; $i--) { if ($pages[$i]['id_menu'] != $id_menu) { unset($pages[$i]); } } $pages = array_values($pages); } if ($display_hidden == FALSE) { $pages = array_values(array_filter($pages, array('TagManager_Page', '_filter_appearing_pages'))); } if (!is_null($limit)) { $pages = array_slice($pages, 0, $limit); } $count = count($pages); foreach ($pages as $key => $page) { // Render the article $tag->set('page', $page); $tag->set('index', $key); $tag->set('count', $count); $str .= $tag->expand(); } $output = self::wrap($tag, $str); // Tag cache self::set_cache($tag, $output); return $output; }
/** * Current user's group * * @param FTL_Binding $tag * * @return string * */ public static function tag_user_group(FTL_Binding $tag) { if (isset(self::$user['group'])) { $tag->set('group', self::$user['group']); } return $tag->expand(); }
/** * Browser check * Checks the browser and display or not the tag content reagarding the result. * * @param FTL_Binding Tag * @return string * * @usage <ion:browser method="is_browser|is_mobile|is_robot|..." value="Safari|Firefox..." is="true|false" return="true"> * ... * </ion:browser> * * @see http://codeigniter.com/user_guide/libraries/user_agent.html * for the method list * */ public static function tag_browser(FTL_Binding $tag) { self::$ci->load->library('user_agent'); $method = $tag->getAttribute('method'); $value = $tag->getAttribute('value'); $is = $tag->getAttribute('is'); $return = $tag->getAttribute('return') == FALSE ? FALSE : TRUE; $result = NULL; if (!is_null($method)) { if (!is_null($value)) { $result = self::$ci->agent->{$method}($value); } else { $result = self::$ci->agent->{$method}(); } } else { $result = self::$ci->agent->browser(); } // set the value $tag->set('browser', $result); $tag->expand(); return self::output_value($tag, $result); }
/** * Standalone language tag * * @param FTL_Binding $tag * * @return string * * @usage <ion:language> * <ion:code /> * <ion:name /> * <ion:url /> * <ion:is_default /> * <ion:is_active /> * </ion:language> */ public static function tag_language(FTL_Binding $tag) { if (is_null(self::$_current_language)) { $page = self::registry('page'); foreach (Settings::get_languages() as $language) { if ($language['lang'] == Settings::get_lang()) { $language['id'] = $language['lang']; $language['absolute_url'] = $page['absolute_urls'][$language['lang']]; self::$_current_language = $language; break; } } } $tag->set('language', self::$_current_language); return $tag->expand(); }
/** * Get the current URL asked category * * @param FTL_Binding $tag * * @return string * */ public static function tag_category_current(FTL_Binding $tag) { // Asked category $url_category_name = self::get_asked_category_uri(); // Category detail if (!is_null($url_category_name)) { // Categories model self::$ci->load->model('category_model'); $category = self::$ci->category_model->get(array('name' => $url_category_name), Settings::get_lang()); $tag->set('current', $category); } else { $tag->set('current', array()); } return $tag->expand(); }
/** * Search results tag * Parent tag for results * * @param FTL_Binding * @return string * @usage <ion:search:results> * */ public static function tag_search_results(FTL_Binding $tag) { $str = ''; // POST realm $realm = $tag->get('realm'); $tag->set('count', 0); if ($realm !== FALSE && $realm != '') { // Get the results if (is_null(self::$_articles)) { // Loads the serach module model self::$ci->load->model('search_model', '', TRUE); $articles = self::$ci->search_model->get_articles($realm); if (!empty($articles)) { // arrays of keys, for multisorting $knum = $kdate = array(); $unique = array(); foreach ($articles as $key => &$article) { // remove duplicates if (!in_array($article['id_article'], $unique)) { $unique[] = $article['id_article']; // set number of found words preg_match_all('#' . $realm . '#i', $article['title'] . ' ' . $article['content'], $match); $num = count($match[0]); $article['nb_words'] = $knum[$key] = $num; $kdate[$key] = strtotime($article['date']); } else { unset($articles[$key]); } } // Sort the results by realm occurences DESC first, by date DESC second. array_multisort($knum, SORT_DESC, SORT_NUMERIC, $kdate, SORT_DESC, SORT_NUMERIC, $articles); } // Init the articles URLs TagManager_Article::init_articles_urls($articles); // Adds the page URL to each article self::init_pages_urls($articles); self::$_articles = $articles; } // Add the number of result to the tag data $count = count(self::$_articles); $tag->set('count', $count); $tag->set('results', self::$_articles); foreach (self::$_articles as $key => $_article) { // The tag should at least do 1 expand to get the child "loop" attribute if ($tag->getAttribute('loop') === FALSE) { return $tag->expand(); } else { $tag->set('result', $_article); $tag->set('count', $count); $tag->set('index', $key); $str .= $tag->expand(); } } } // Expand the tag if no articles : Allows the children tags to be processed even not results were found // Must not be done if articles or this add one unwanted expand. if (empty(self::$_articles)) { $str .= $tag->expand(); } return $str; }
/** * @param FTL_Binding $tag * * @return string * */ public static function tag_static_item_field_options(FTL_Binding $tag) { $str = ''; $item = $tag->get('item'); $field_name = $tag->getParentName(); if (isset($item['fields'][$field_name])) { $field = $item['fields'][$field_name]; // All available values for this multi-value field $all_values = explode("\n", $field['value']); foreach ($all_values as $value) { $val_label = explode(':', $value); $tag->set('value', $val_label[0]); $tag->set('label', $val_label[1]); $str .= self::wrap($tag, $tag->expand()); } } return $str; }
/** * Article Core Tag Extend : Authors List tag * * @param FTL_Binding Tag object * @return String List of Authors * * @usage <ion:articles> * <ion:authors> * ... * </ion:authors> * <ion:articles> * */ public static function core_article_authors(FTL_Binding $tag) { $str = ''; // Model load self::load_model('demo_author_model', 'author_model'); // Get the article from local tag var : // The 'article' tag is a parent of this tag and has the 'article' data array set. $article = $tag->get('article'); $authors = self::$ci->author_model->get_linked_author('article', $article['id_article']); foreach ($authors as $author) { // Set the local tag var "author" $tag->set('author', $author); // Tag expand : Process of the children tags $str .= $tag->expand(); } return $str; }
/** * Sends Emails as defined in the forms.php config file. * Important : This method receives the "form" tag * * @param FTL_Binding Form tag * @param string * @param array Array of data send to the Email view. * Each key of this array will be available in the view by : * <ion:data:key /> * * The passed array should look like this : * array( * 'email' => 'user email', // Email of the user (POST, DB...) * 'key1' => 'value1, // Makes <ion:data:key1 /> available in the Email view * ); * */ public static function send_form_emails(FTL_Binding $tag, $form_name, $data = array()) { // Set the 'data' tag from the received data array self::$context->define_tag('data', array(__CLASS__, 'tag_expand')); foreach ($data as $key => $value) { if (!is_array($value) && !is_object($value)) { self::$context->define_tag('data:' . $key, array(__CLASS__, 'tag_simple_value')); } } // Get all declared emails configuration data from forms.php config file $emails = TagManager_Form::get_form_emails($form_name); // Get the 'sender' email : Must be set in Ionize : Settings > Advanced settings > Email $website_email = Settings::get('site_email') ? Settings::get('site_email') : NULL; // Send all defined emails foreach ($emails as $email_setting) { $email = $email_setting['email']; $reply_to = isset($email_setting['reply_to']) ? $email_setting['reply_to'] : NULL; // Get potential website / form email switch ($email) { case 'site': $email = Settings::get('site_email') != '' ? Settings::get('site_email') : NULL; break; case 'form': $email = isset($data['email']) ? $data['email'] : self::$ci->input->post('email'); break; case $email == 'contact' || $email == 'technical' || $email == 'info': $email = Settings::get('email_' . $email) != '' ? Settings::get('email_' . $email) : NULL; break; default: $email = $email; $_email = explode('::', $email); if (!empty($_email[1])) { $email = self::$ci->input->post($_email[1]); } break; } if (!is_null($reply_to)) { switch ($reply_to) { case 'site': $reply_to = Settings::get('site_email') != '' ? Settings::get('site_email') : NULL; break; case 'form': $reply_to = isset($data['email']) ? $data['email'] : self::$ci->input->post('email'); break; default: $reply_to = Settings::get('email_' . $email) != '' ? Settings::get('email_' . $email) : NULL; break; } } // Send the email if ($email) { // Subject, adds the website title as swap text : displayed in title if the %s key is used. $subject = lang($email_setting['subject'], Settings::get('site_title')); $data['subject'] = $subject; // Set the "data tag" array of data. $tag->set('data', $data); // Email Lib if (!isset(self::$ci->email)) { self::$ci->load->library('email'); } self::$ci->email->clear(); // Subject / From / To self::$ci->email->subject($subject); self::$ci->email->from($website_email, Settings::get("site_title")); self::$ci->email->to($email); if (!is_null($reply_to)) { self::$ci->email->reply_to($reply_to); } // View & Message content $view_content = $tag->parse_as_standalone(self::$tag_prefix, Theme::load($email_setting['view'])); self::$ci->email->message($view_content); // Send silently $result = @self::$ci->email->send(); if (!$result) { log_message('error', 'Error : Tagmanager/Email->send_form_emails() : Email was not sent.'); } } else { log_message('error', 'Error : Tagmanager/Email->send_form_emails() : Email not found'); } } }
/** * Element field generic tag * * @param FTL_Binding $tag * * @return string */ public static function tag_element_item_field(FTL_Binding $tag) { $item = $tag->get('item'); $field_key = $tag->getName(); if (isset($item['fields'][$field_key])) { $tag->set($field_key, $item['fields'][$field_key]); // Availability of field for TagManager->tag_extend_field_medias() $tag->set('extend', $item['fields'][$field_key]); } return self::wrap($tag, $tag->expand()); }