/** * Return the Pagination lib config array * * @param FTL_Binding $tag * * @return array * */ public static function get_pagination_config(FTL_Binding $tag) { $pagination_config = array(); // CSS class / id $html_class = $tag->getAttribute('class'); if (!is_null($html_class)) { $html_class = ' class="' . $html_class . '" '; } $html_id = $tag->getAttribute('id'); if (!is_null($html_id)) { $html_id = ' class="' . $html_id . '" '; } $cf = Theme::get_theme_path() . 'config/pagination' . '.php'; if (!is_file($cf)) { $cf = APPPATH . 'config/pagination' . '.php'; } if (is_file($cf)) { $config = array(); require $cf; $pagination_config = $config['pagination']; unset($config); } // Pagination config from tag if (!is_null($ptag = $tag->getAttribute('full_tag'))) { $pagination_config['full_tag_open'] = '<' . $ptag . $html_id . $html_class . '>'; $pagination_config['full_tag_close'] = '</' . $ptag . '>'; } if (!is_null($ptag = $tag->getAttribute('first_tag'))) { $pagination_config['first_tag_open'] = '<' . $ptag . '>'; $pagination_config['first_tag_close'] = '</' . $ptag . '>'; } if (!is_null($ptag = $tag->getAttribute('last_tag'))) { $pagination_config['last_tag_open'] = '<' . $ptag . '>'; $pagination_config['last_tag_close'] = '</' . $ptag . '>'; } if (!is_null($ptag = $tag->getAttribute('cur_tag'))) { $pagination_config['cur_tag_open'] = '<' . $ptag . '>'; $pagination_config['cur_tag_close'] = '</' . $ptag . '>'; } if (!is_null($ptag = $tag->getAttribute('next_tag'))) { $pagination_config['next_tag_open'] = '<' . $ptag . '>'; $pagination_config['next_tag_close'] = '</' . $ptag . '>'; } if (!is_null($ptag = $tag->getAttribute('prev_tag'))) { $pagination_config['prev_tag_open'] = '<' . $ptag . '>'; $pagination_config['prev_tag_close'] = '</' . $ptag . '>'; } if (!is_null($ptag = $tag->getAttribute('num_tag'))) { $pagination_config['num_tag_open'] = '<' . $ptag . '>'; $pagination_config['num_tag_close'] = '</' . $ptag . '>'; } return $pagination_config; }
/** * @param FTL_Binding $tag * * @return string */ public static function tag_authority_can(FTL_Binding $tag) { $action = $tag->getAttribute('action'); $resource = $tag->getAttribute('resource'); if (empty($action) && empty($resource)) { return self::show_tag_error($tag, 'Feed the "action" and "resource" attributes'); } if (Authority::can($action, $resource)) { return $tag->expand(); } else { // Else self::$trigger_else++; } return ''; }
/** * 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(); } } } }
/** * Displays the form * Inherits from TagManager_Form the form displaying methods * so the view can be slightly the same than the one used for one classical form * * @param FTL_Binding $tag * * @return string */ public static function tag_form(FTL_Binding $tag) { $ajax = $tag->getAttribute('ajax'); // Ajax form if ($ajax == TRUE) { // Get form string $str = parent::tag_form($tag); // No JS The user will add the JS part in his own JS script $nojs = $tag->getAttribute('nojs'); $form_name = $tag->getAttribute('name'); $form_submit_id = $tag->getAttribute('submit'); // $error_tag = $tag->getAttribute('error_tag'); // $error_tag_class = $tag->getAttribute('error_tag_class'); // Module settings self::$config = Modules()->get_module_config('Ajaxform'); if (!$nojs) { // Add the JS part of the module if ($form_name && $form_submit_id) { $data = array('form_name' => $form_name, 'form_submit_id' => $form_submit_id, 'url' => base_url() . Settings::get_lang() . '/' . self::$config['uri'] . '/post'); $str .= self::$ci->load->view('ajaxform_js', $data, TRUE); } else { log_message('error', 'Ajaxform ERROR : Set the name & submit attributes of the <ion:form name="formName" submit="submitButtonID"> tag'); } } return $str; } else { return parent::tag_form($tag); } }
/** * 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 the categories * * @param FTL_Binding * @param array/null * * @return array * */ public static function get_categories(FTL_Binding $tag) { // Categories model self::$ci->load->model('category_model'); // Current page $page = $tag->get('page'); // Local storage key $lsk = '__all__'; // Get the local cache data $element_name = $tag->getParentName(); $element = $tag->get($element_name); if (!is_null($element)) { $lsk = '__' . $element_name . '__' . $element['name']; } // Set the local cache data if (!isset(self::$categories[$lsk])) { // CSS class to use for the current category $active_class = $tag->getAttribute('active_class', 'active'); // Asked category $asked_category_name = self::get_asked_category_uri(); // Check if the element has one category array (eg. for Articles) if (isset($element['categories'])) { $categories = $element['categories']; // Fix the 'nb' key (nb_articles using this category) foreach ($categories as $key => $category) { $categories[$key]['nb'] = '1'; } } else { if ($element_name == 'page') { $id_page = !is_null($page) ? $page['id_page'] : NULL; } else { $id_page = NULL; } $categories = self::$ci->category_model->get_categories_list($id_page, Settings::get_lang()); } $page_url = !is_null($page) ? trim($page['absolute_url'], '/') . '/' : Pages::get_home_page_url(); $category_uri_segment = self::get_config_special_uri_segment('category'); // Add the URL to the category to each category row // Also add the active class foreach ($categories as $key => $category) { $categories[$key]['url'] = $page_url . $category_uri_segment . '/' . $category['name']; $categories[$key]['lang_url'] = $page_url . $category_uri_segment . '/' . $category['name']; // Active category ? $categories[$key]['active_class'] = $category['name'] == $asked_category_name ? $active_class : ''; $categories[$key]['is_active'] = !empty($categories[$key]['active_class']) ? TRUE : FALSE; } self::$categories[$lsk] = array_values($categories); } return self::$categories[$lsk]; }
/** * Evaluates one expression * * @param FTL_Binding * @param $expression * * @return bool|null TRUE if the evaluation returns TRUE * FALSE if the evaluation returns FALSE * NULL if the evaluation can't be done (error in expression or $value NULL) */ protected static function eval_expression(FTL_Binding $tag, $expression) { // Result and return $return = NULL; $result = FALSE; // If no key, we compare the value of the tag name $keys = $tag->getAttribute('key'); if (is_null($keys)) { $keys = $tag->name; } // Make an array from keys $keys = explode(',', $keys); $test_value = NULL; foreach ($keys as $idx => $key) { $key = trim($key); // 1. Try to get the value from tag's data array $value = $tag->getValue($key); $expression = str_replace('.gt', '>', $expression); $expression = str_replace('.lt', '<', $expression); $expression = str_replace('.eq', '==', $expression); $expression = str_replace('.neq', '!=', $expression); // Not convinced... // $expression = str_replace('.leqt', '<=', $expression); // $expression = str_replace('.geqt', '>=', $expression); // 2. Fall down to to tag's locals if (is_null($value)) { $value = $tag->get($key); } if ($idx == 0 && strpos($expression, $key) === FALSE) { $expression = $key . $expression; } $test_value = (!$value == (string) (double) $value or is_null($value) or $value == '') ? "'" . $value . "'" : $value; // if (gettype($test_value) == 'string' && $test_value == '') $test_value = "'".$test_value."'"; $expression = str_replace($key, $test_value, $expression); } // If at least one tested value was not NULL if (!is_null($test_value)) { $return = @eval("\$result = (" . $expression . ") ? TRUE : FALSE;"); } if ($return === NULL or is_null($test_value)) { if ($result) { return TRUE; } else { return FALSE; } } else { return NULL; } }
/** * Author tag * * @param FTL_Binding Tag object * @return String Tag attribute or '' * * @usage <ion:demo:authors> * <ion:author field="name" /> * </ion:demo:authors> * */ public static function tag_author(FTL_Binding $tag) { // Returns the field value or NULL if the attribute is not set $field = $tag->getAttribute('field'); if (!is_null($field)) { // Get the local tag var "author" $author = $tag->get('author'); if (!empty($author[$field])) { return self::output_value($tag, $author[$field]); } } // Here we have the choice : // - Ether return nothing if the field attribute isn't set or doesn't exist // - Ether silently return '' return self::show_tag_error($tag, 'The attribute <b>"field"</b> is not set or the field doesn\'t exists.'); // return ''; }
/** * Processes one string by adding text helper attributes * * @param FTL_Binding $tag * @param String $value * * @usage <ion:content /> * */ public function process_string(FTL_Binding $tag, $value) { // paragraph & words limit ? $paragraph = $tag->getAttribute('paragraph'); $words = $tag->getAttribute('words'); $chars = $tag->getAttribute('characters'); $ellipsize = $tag->getAttribute('ellipsize'); // Limit to x paragraph if the attribute is set if (!is_null($paragraph)) { $value = tag_limiter($value, 'p', intval($paragraph)); } // Limit to x words if (!is_null($words)) { $value = word_limiter($value, $words); } // Limit to x characters if (!is_null($chars)) { $value = character_limiter($value, $chars); } // Ellipsize the text // See : http://codeigniter.com/user_guide/helpers/text_helper.html if (!is_null($ellipsize)) { $ellipsize = explode(',', $ellipsize); if (!isset($ellipsize[0])) { $ellipsize[0] = 32; } if (!isset($ellipsize[1])) { $ellipsize[1] = 0.5; } if (floatval($ellipsize[1]) > 0.99) { $ellipsize[1] = 0.99; } $value = ellipsize($value, intval($ellipsize[0]), floatval($ellipsize[1])); } return $value; }
/** * Languages tag * * @param FTL_Binding * * @return null|string * * @usage <ion:languages [helper="helper:helper_method"]> * ... * <ion:languages> * */ public static function tag_languages(FTL_Binding $tag) { $languages = Authority::can('access', 'admin') && Settings::get('display_front_offline_content') == 1 ? Settings::get_languages() : Settings::get_online_languages(); $page = self::registry('page'); $article = self::registry('article'); // Current active language class $active_class = $tag->getAttribute('active_class', 'active'); // Ignore current language in output $ignore_current = $tag->getAttribute('ignore_current'); // helper $helper = $tag->getAttribute('helper'); $str = ''; $tag->set('count', count($languages)); foreach ($languages as $idx => &$lang) { $lang_code = $lang['lang']; $p_data = $page['languages'][$lang_code]; if ($ignore_current == TRUE && $lang_code == Settings::get_lang('current')) { continue; } // Correct the Home page URL if ($p_data['online'] == 1 or $p_data['online'] == 0 && Authority::can('access', 'admin') && Settings::get('display_front_offline_content') == 1) { if ($page['home'] != 1) { $lang['absolute_url'] = !empty($page['absolute_urls'][$lang_code]) ? $page['absolute_urls'][$lang_code] : base_url() . $lang_code; } else { $lang['absolute_url'] = base_url() . $lang_code; } } else { $lang['absolute_url'] = NULL; } $lang['active_class'] = $lang_code == Settings::get_lang('current') ? $active_class : ''; $lang['is_active'] = $lang_code == Settings::get_lang('current'); $lang['id'] = $lang_code; if (!is_null($article)) { $a_data = $article['languages'][$lang_code]; if (!is_null($a_data['url']) && $a_data['online'] == 1 or $a_data['online'] == 0 && Authority::can('access', 'admin') && Settings::get('display_front_offline_content') == 1) { if ($page['home'] != 1) { $lang['absolute_url'] .= '/' . $a_data['url']; } else { $lang['absolute_url'] .= '/' . $page['urls'][$lang_code] . '/' . $a_data['url']; } } else { $lang['absolute_url'] = NULL; } } // Tag locals $tag->set('language', $lang); $tag->set('id', $lang_code); $tag->set('absolute_url', $lang['absolute_url']); $tag->set('active_class', $lang['active_class']); $tag->set('is_active', $lang['is_active']); $tag->set('index', $idx); if (!is_null($lang['absolute_url'])) { $str .= $tag->expand(); } } // Try to return the helper function result if ($str != '' && !is_null($helper)) { $helper_function = substr(strrchr($helper, ':'), 1) ? substr(strrchr($helper, ':'), 1) : 'get_language_navigation'; $helper = strpos($helper, ':') !== FALSE ? substr($helper, 0, strpos($helper, ':')) : $helper; self::$ci->load->helper($helper); if (function_exists($helper_function)) { $nav = call_user_func($helper_function, $languages); return self::wrap($tag, $nav); } } return self::wrap($tag, $str); }
/** * Find and parses the article view * * @param FTL_Binding * @param array * * @return string * */ private static function find_and_parse_article_view(FTL_Binding $tag, $article) { // Registered page $page = self::registry('page'); // Local articles $articles = $tag->get('articles'); // Try to get the view defined for article $tag_view = $tag->getAttribute('view'); $article_view = !is_null($tag_view) ? $tag_view : (!empty($article['view']) ? $article['view'] : NULL); if (!is_null($article_view)) { // Force first the view defined by the tag if (!is_null($tag_view)) { $article['view'] = $tag_view; } else { if (count($articles) == 1) { $article['view'] = $page['article_view']; } else { $article['view'] = $page['article_list_view']; } } } // Default article view if (empty($article['view'])) { $article['view'] = Theme::get_default_view('article'); } // View path $view_path = Theme::get_theme_path() . 'views/' . $article['view'] . EXT; // Return the Ionize default's theme view if (!file_exists($view_path)) { $view_path = Theme::get_theme_path() . 'views/' . Theme::get_default_view('article') . EXT; if (!file_exists($view_path)) { $view_path = APPPATH . 'views/' . Theme::get_default_view('article') . EXT; } } return $tag->parse_as_nested(file_get_contents($view_path)); }
/** * 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(); } }
/** * @param FTL_Binding $tag * * @return string * */ public function tag_media(FTL_Binding $tag) { $parentName = $tag->getDataParentName(); // Standalone tag : Only one media is wished if ($parentName != 'medias') { $index = $tag->getAttribute('index', 0); $medias = $media = NULL; // Try to find medias if (!is_null($parentName)) { $medias = $tag->getParent()->getValue('medias', $parentName); } else { $article = self::registry('article'); $page = self::registry('page'); if (!empty($article['medias'])) { $medias = $article['medias']; } else { if (!empty($page['medias'])) { $medias = $article['medias']; } } } // Filter them, as usual if (!empty($medias)) { $medias = self::filter_medias($tag, $medias); } // Set the asked media if (!empty($medias) && isset($medias[$index])) { $tag->set('media', $medias[$index]); } } return $tag->expand(); }
/** * Expands the children if the user is logged in. * * @param FTL_Binding $tag * * @return string */ public static function tag_user_logged(FTL_Binding $tag) { $tag->setAsProcessTag(); $is = $tag->getAttribute('is'); if (is_null($is)) { $is = TRUE; } if (User()->logged_in() == $is) { if (self::$trigger_else > 0) { self::$trigger_else--; } return $tag->expand(); } else { self::$trigger_else++; return ''; } }
/** * 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; }
/** * 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; }
public static function get_archives(FTL_Binding $tag) { // Categories model self::$ci->load->model('article_model'); // Page $page = $tag->get('page'); if (is_null($page)) { $page = self::registry('page'); } // Period format. see : http://php.net/manual/fr/function.date.php $format = $tag->getAttribute('format', 'F'); // Attribute : active class $active_class = $tag->getAttribute('active_class', 'active'); // filter $filter = $tag->getAttribute('filter', FALSE); if ($filter != FALSE) { $filter = self::process_filter($filter); } // month $with_month = $tag->getAttribute('month'); // order $order = $tag->getAttribute('order'); $order = $order == 'ASC' ? 'period ASC' : 'period DESC'; // Archive string : 'yyyy' or 'yyyy.mm'. Used for CSS active class $_archive_string = ''; // Archive URI args $args = self::get_special_uri_array('archives'); if (!empty($args)) { $_archive_string = isset($args[0]) ? $args[0] : ''; $_archive_string .= isset($args[1]) ? '.' . $args[1] : ''; } // Archives URI segment, as set in the config file $archives_uri_segment = self::get_config_special_uri_segment('archives'); // Get the archives $archives = self::$ci->article_model->get_archives_list(array('id_page' => $page['id_page']), Settings::get_lang(), $filter, $with_month, $order); // Translated period array $month_formats = array('D', 'l', 'F', 'M'); $page_url = !is_null($page) ? $page['absolute_url'] . '/' : Pages::get_home_page_url(); foreach ($archives as &$row) { $year = substr($row['period'], 0, 4); $month = substr($row['period'], 4); if ($month != '') { $month = strlen($month) == 1 ? '0' . $month : $month; $timestamp = mktime(0, 0, 0, $month, 1, $year); // Get date in the wished format $period = (string) date($format, $timestamp); // Translate the period month if (in_array($format, $month_formats)) { $period = lang(strtolower($period)); } $row['period'] = $period . ' ' . $year; $row['url'] = $page_url . $archives_uri_segment . '/' . $year . '/' . $month; $row['active_class'] = $year . '.' . $month == $_archive_string ? $active_class : ''; } else { $row['period'] = $year; $row['url'] = $page_url . $archives_uri_segment . '/' . $year; $row['active_class'] = $year == $_archive_string ? $active_class : ''; } $row['is_active'] = !empty($row['active_class']) ? TRUE : FALSE; } return $archives; }
/** * @param FTL_Binding $tag * * @usage <ion:media:download class="download" /> * * @return string */ public function tag_media_download(FTL_Binding $tag) { // get media attributes $media = $tag->locals->media; $mediaTitle = empty($media['title']) ? $media['file_name'] : $media['title']; // get CSS classname (optional) $class = trim($tag->getAttribute('class')); // generate SHA-1 hash to verify valid (= intentionally public) downloads $hash = urlencode(sha1($media['id_media'] . config_item('encryption_key'))); // render output $url = base_url() . 'media/download/' . $media['id_media'] . '/' . $hash; return '<a' . (empty($class) ? '' : ' class="' . $class . '"') . ' href="' . $url . '">' . $mediaTitle . '</a>'; }
/** * Displays the complete error string * (containing all errors) * * @param FTL_Binding * * @return string * * @usage <ion:form:form_name:validation:error /> * * Example with the form called 'profile' : * <ion:form:profile:validation:error /> * */ public static function tag_form_validation_error(FTL_Binding $tag) { $is = $tag->getAttribute('is'); $key = $tag->getAttribute('key'); $delimiter = $tag->getAttribute('delimiter', 'span'); $form_name = $tag->getParent('validation')->getParentName(); // 'additional_error' values $values = NULL; $fd = self::$ci->session->flashdata($form_name); if (!empty($fd['additional_error'])) { $values = $fd['additional_error']; } else { // Adds additional errors to the CI Validation error array self::check_additional_errors($form_name); if (self::$posting_form_name == $form_name) { // We're not in 'redirect mode' : Remove the flash session data self::$ci->session->unset_flashdata($form_name); // Validate the form if it wasn't done self::validate(self::$posting_form_name); // No key : Get the string if (is_null($key)) { self::$ci->form_validation->set_error_delimiters('<' . $delimiter . '>', '</' . $delimiter . '>'); $values = self::$ci->form_validation->error_string(); } else { $values = self::$ci->form_validation->_error_array; } } } if (!is_null($values)) { // Expand mode if (!is_null($is)) { // No key ask : Check against the additional success array if (is_null($key)) { if (!$is == empty($values)) { return self::wrap($tag, $tag->expand()); } } else { if (!$is == empty($values[$key])) { return self::wrap($tag, $tag->expand()); } } } else { if (is_null($key)) { if (!empty($values)) { $str = ''; if (is_string($values)) { $values = array($values); } foreach ($values as $val) { $str .= "<span>" . $val . "</span>"; } return self::wrap($tag, $str); } } else { if (!empty($values[$key])) { return self::wrap($tag, $fd[$key]); } } } } // No posted form : No errors if ($is == FALSE) { return $tag->expand(); } return ''; }
/** * Displays the breacrumb : You are here ! * * @param FTL_Binding object * @return String The parsed view * * @usage <ion:breadcrumb [level="2" separator=" • " tag="ul" class="breadcrumb" child-tag="li" child-class="breadcrump-item"] /> * */ public static function tag_breadcrumb(FTL_Binding $tag) { // Child tag : HTML tag for each element $child_tag = $tag->getAttribute('child-tag'); $child_class = $tag->getAttribute('child-class'); $child_class = !is_null($child_class) ? ' class="' . $child_class . '"' : ''; // Child tag cosmetic $child_tag_open = !is_null($child_tag) ? '<' . $child_tag . $child_class . '>' : ''; $child_tag_close = !is_null($child_tag) ? '</' . $child_tag . '>' : ''; $separator = $tag->getAttribute('separator', ' » '); $separator_tag = $tag->getAttribute('separator_tag'); $separator_class = $tag->getAttribute('separator_class'); $separator_class = !is_null($separator_class) ? ' class="' . $separator_class . '"' : ''; if (!is_null($separator_tag)) { $separator = '<' . $separator_tag . $separator_class . '>' . $separator . '</' . $separator_tag . '>'; } $level = $tag->getAttribute('level', FALSE); // Pages && page $pages = self::$context->registry('pages'); $page = self::$context->registry('page'); // Get the Breadcrumbs array $lang = Settings::get_lang(); $breadcrumb = self::get_breadcrumb_array($page, $pages, $lang); // Filter appearing pages $breadcrumb = array_values(array_filter($breadcrumb, array(__CLASS__, '_filter_appearing_pages'))); if ($level != FALSE) { $new_breadcrumb = array(); foreach ($breadcrumb as $b) { if ($b['level'] >= $level) { $new_breadcrumb[] = $b; } } $breadcrumb = $new_breadcrumb; } // Build the links $return = ''; // Add Home page ? if ($tag->getAttribute('home') == TRUE && $page['home'] == 0) { $home_page = self::get_home_page(); $url = $home_page['absolute_url']; $return .= $child_tag_open . '<a href="' . $url . '">' . $home_page['title'] . '</a>' . $separator . $child_tag_close; } // Pages $nb_pages = count($breadcrumb); for ($i = 0; $i < $nb_pages; $i++) { $url = $breadcrumb[$i]['absolute_url']; // Adds the suffix if defined if (config_item('url_suffix') != '') { $url .= config_item('url_suffix'); } $return .= $child_tag_open . '<a href="' . $url . '">' . $breadcrumb[$i]['title'] . '</a>'; if ($i < $nb_pages - 1) { $return .= $separator; } $return .= $child_tag_close; } // Current Article ? if ($tag->getAttribute('article') == TRUE) { $article = self::registry('article'); if ($article) { $separator = $return != '' ? $separator : ''; $return .= $child_tag_open . $separator . $article['title'] . $child_tag_close; } } // Prefix process $return = self::prefix_suffix_process($return, $tag->getAttribute('prefix')); return self::wrap($tag, $return); }
/** * 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; }