/** * Define the enclosing tag. * Make the <ion:fancyupload /> tag available as parent tag * * @usage <ion:fancyupload type="photoqueue" /> * type : "photoqueue" : Simple file queue uploader * "complete" : Complete Fancyupload * */ public static function index(FTL_Binding $tag) { // Get the module URI include APPPATH . 'config/modules.php'; $uri = array_search('Fancyupload', $modules); $tag->expand(); return $tag->parse_as_nested(file_get_contents(MODPATH . 'Fancyupload/views/fancyupload_' . config_item('fancyupload_type') . EXT)); }
/** * Returns a field value from a form * * @usage <ion:simpleform:field [attr="<field_name>"] [from_post_data="<form_name>"] // The wished field from the given form * */ public static function field(FTL_Binding $tag) { $ret = ''; $ci =& get_instance(); include MODPATH . 'Simpleform/config/config.php'; if (isset($tag->attr['from_post_data']) && $ci->input->post('form_name') === $tag->attr['from_post_data']) { $ret = !($ci->input->post($tag->attr['name']) === FALSE) ? $ci->input->post($tag->attr['name']) : $ret; } // If only the post data is requested if (!isset($tag->attr['is_like'])) { return $ret; } else { return $tag->attr['is_like'] === $ret ? $tag->expand() : ""; } }
/** * Check one session value * * Optionally, can check for one value AND set another value. * In this case, the check will return TRUE and set the value after * * @usage <ion:session var="session_var_name" is="session_var_value" [set="new_session_var_value"] > * ... * </ion:session> * */ public static function check(FTL_Binding $tag) { $var = $tag->getAttribute('var'); $is = $tag->getAttribute('is'); $set = $tag->getAttribute('set'); if (self::is_allowed($var) == TRUE) { if ($is !== FALSE) { if (self::$ci->session->userdata($var) == $is) { if ($set != FALSE) { self::$ci->session->set_userdata($var, $set); } return $tag->expand(); } } } }
/** * 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(); }
/** * Base search module tag * The index function of this class refers to the <ion:search /> tag * In other words, this function makes the <ion:search /> tag available as main module parent tag * for all other tags defined in this class. * * @usage <ion:demo > * ... * </ion:demo> * */ public static function index(FTL_Binding $tag) { $str = $tag->expand(); return $str; }
/** * Format the given date and return the expanded tag * * @param FTL_Binding tag * @param String date * * @return String * */ protected static function format_date(FTL_Binding $tag, $date) { // Distinguish datetime form date DB values $default_format = strlen($date) > 10 ? 'Y-m-d H:i:s' : 'Y-m-d'; $date = strtotime($date); if ($date) { $format = $tag->getAttribute('format', $default_format); if ($format != 'Y-m-d H:i:s') { if (lang('dateformat_' . $format) != '#dateformat_' . $format) { // Date translations are located in the files : /themes/your_theme/language/xx/date_lang.php $format = lang('dateformat_' . $format); } } $segments = explode(' ', $format); foreach ($segments as $key => $segment) { $tmp = (string) date($segment, $date); if (preg_match('/D|l|F|M/', $segment)) { $tmp = lang(strtolower($tmp)); } $segments[$key] = $tmp; } return implode(' ', $segments); } return $tag->expand(); }
/** * 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(); }
/** * Expands if the Form was passed through the validation process * * @param FTL_Binding $tag * * @return string * */ public static function tag_form_posted(FTL_Binding $tag) { $form_name = $tag->getParentName(); $is = $tag->getAttribute('is', TRUE); $posted = FALSE; if ($form_name == self::$posting_form_name) { $posted = TRUE; } if ($posted == $is) { return $tag->expand(); } return ''; }
/** * Browser check * Checks the browser and display or not the tag content reagarding the result. * * @param FTL_Binding Tag * * @usage <ion:browser method="is_browser|is_mobile|is_robot|..." value="Safari|Firefox..." is="true|false"> * ... * </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'); $result = NULL; if (!is_null($method)) { if (!is_null($value)) { $result = self::$ci->agent->{$method}($value); } else { $result = self::$ci->agent->{$method}(); } } if (is_bool($is) && $result == $is) { return $tag->expand(); } }
/** * Displays the content of the tag if no results * */ public static function no_results(FTL_Binding $tag) { if (empty($tag->locals->results)) { return $tag->expand(); } }
/** * Element's items tag * * @param FTL_Binding $tag * * @return string * * @usage With "stickers" as your definition name : * <ion:static:stickers:items /> */ public static function tag_static_items(FTL_Binding $tag) { $return = $tag->getAttribute('return'); $str = ''; // Limit ? $limit = $tag->getAttribute('limit') ? (int) $tag->getAttribute('limit') : FALSE; $items = $tag->get('items'); $tag->set('count', 0); // Process the elements if (!empty($items)) { if (is_null($return)) { $count = count($items); $limit = ($limit == FALSE or $limit > $count) ? $count : $limit; $tag->set('count', $limit); for ($i = 0; $i < $limit; $i++) { $item = $items[$i]; // item : One element instance $tag->set('item', $item); $tag->set('index', $i + 1); $tag->set('count', $limit); $str .= $tag->expand(); } $str = self::wrap($tag, $str); } else { if ($return == 'json') { // Ugly process of links in case // of link type extend fields // @todo: rewrite self::$ci->load->model('extend_fields_model', '', TRUE); if (count(Settings::get_online_languages()) > 1 or Settings::get('force_lang_urls') == '1') { $base_url = base_url() . Settings::get_lang('current') . '/'; } else { $base_url = base_url(); } foreach ($items as $k1 => $item) { foreach ($item['fields'] as $k2 => $field) { if ($field['html_element_type'] == 'link') { $items[$k1]['ion_urls'] = array(); $links = self::$ci->extend_fields_model->get_extend_link_list_from_content($field['content']); foreach ($links as $link) { $items[$k1]['ion_urls'][] = $base_url . $link['path']; } } } } // End @todo $str = json_encode($items, TRUE); $str = str_replace("'", "\\'", $str); } } } 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; }
public static function comments_allowed(FTL_Binding $tag) { $result = $tag->locals->article['comment_allow'] == "1" ? $result = $tag->expand() : ($result = ""); return $result; }
/** * @param FTL_Binding $tag * * @return string */ public static function tag_authority(FTL_Binding $tag) { return $tag->expand(); }
/** * 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(); }
/** * 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; }
/** * 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; }
/** * Element's items tag * * @param FTL_Binding $tag * * @return string */ public static function tag_element_items(FTL_Binding $tag) { $str = ''; // Limit ? $limit = $tag->getAttribute('limit') ? (int) $tag->getAttribute('limit') : FALSE; $items = $tag->get('items'); // Process the elements if (!empty($items['elements'])) { $count = count($items['elements']); $limit = ($limit == FALSE or $limit > $count) ? $count : $limit; $tag->set('count', $limit); for ($i = 0; $i < $limit; $i++) { $item = $items['elements'][$i]; // item : One element instance $tag->set('item', $item); $tag->set('index', $i + 1); $tag->set('count', $limit); $str .= $tag->expand(); } $str = self::wrap($tag, $str); } return $str; }