/** * 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); } }
/** * 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)); }
/** * @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 ''; }
/** * 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(); } } } }
/** * 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()); }
/** * 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(); }
/** * 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'); } } }
public static function get_src_settings(FTL_Binding $tag) { $setting_keys = array('method', 'size', 'watermark', 'unsharp', 'start', 'color', 'refresh'); $settings = array_fill_keys($setting_keys, ''); $global_unsharp = Settings::get('media_thumb_unsharp'); // <ion:medias /> parent $parent = $tag->getParent('medias'); if (!is_null($parent)) { $unsharp = $parent->getAttribute('unsharp'); if ($unsharp == NULL) { $settings['unsharp'] = $global_unsharp; } $settings = array_merge($settings, $parent->getAttributes()); } // <ion:media /> parent $parent = $tag->getParent('media'); if (!is_null($parent)) { $unsharp = $parent->getAttribute('unsharp'); if ($unsharp == NULL) { $settings['unsharp'] = $global_unsharp; } $settings = array_merge($settings, $parent->getAttributes()); } $settings = array_merge($settings, $tag->getAttributes()); if (empty($settings['method'])) { $settings['method'] = self::$default_resize_method; } return $settings; }
/** * More logical key for 'group_name' in group table. * @TODO : Correct 'group_name' in DB and replace it by 'title' * * @param FTL_Binding $tag * * @return string * */ public static function tag_user_group_title(FTL_Binding $tag) { $group_name = $tag->getValue('group_name', 'group'); return self::output_value($tag, $group_name); }
protected static function get_lang_swap(FTL_Binding $tag, $swap) { // $swap = $tag->getAttribute('swap'); if (!is_null($swap)) { $swap = explode(',', $swap); $swap = array_map('trim', $swap); // Try to get internal swap values foreach ($swap as &$str) { if (strpos($str, '::') !== FALSE) { $seg = explode('::', $str); // The asked key must be set if (!empty($seg[1])) { // Get from global value if ($seg[0] == 'global') { $str = self::$context->get_global($seg[1]); } else { $parent = NULL; // Parent not set : current parent if ($seg[0] == '') { $parent = $tag->getDataParent(); } else { $parent = $tag->getParent($seg[0]); } if (!is_null($parent)) { $str = $parent->getValue($seg[1], $parent->name); } else { $str = ''; } } } } } } return $swap; }
/** * 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)); }
/** * 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; }
/** * 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(); } }
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; }
/** * Returns language's direction : 'ltr' or 'rtl' * * @param FTL_Binding $tag * * @return string * */ public static function tag_language_dir(FTL_Binding $tag) { $dir = $tag->getValue('direction'); $dir = ($dir == 1 or empty($dir)) ? 'ltr' : 'rtl'; return self::output_value($tag, $dir); }
/** * @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; }
/** * 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; }
/** * Returns the number of results * * @param FTL_Binding * @return string */ public static function tag_search_results_count(FTL_Binding $tag) { $tag->getParent()->setAttribute('loop', FALSE); return self::tag_simple_value($tag); }
/** * Pagination tag * * Main class name, id, open tag, close tag, every options from cI in fact ! * * @configuration * /themes/<my_theme>/config/pagination.php * Set the open / close HTML tags for each tag * * /themes/<my_theme>/language/xx/pagination_lang.php * Set the translations items : * - first_link * - last_link * - prev_link * - next_link * */ public static function tag_pagination(FTL_Binding $tag) { if ($tag->getParent()->get('__loop__') === FALSE) { return ''; } // Avoid loop in this tag $tag->getParent()->set('__loop__', FALSE); // Tag cache if (($str = self::get_cache($tag)) !== FALSE) { return $str; } // Current page : 1. Asked page, 2. Down to current $page = $tag->get('page'); if (is_null($page)) { $page = self::registry('page'); } // Number of displayed articles : tag attribute has priority 1. $nb_to_display = $tag->getAttribute('pagination'); if (is_null($nb_to_display)) { $nb_to_display = $page['pagination']; } // Load CI Pagination Lib isset(self::$ci->pagination) or self::$ci->load->library('pagination'); // Current pagination page $args = self::get_special_uri_array('pagination'); $cur_page = isset($args[0]) ? $args[0] : NULL; // Pagination tag config init $pagination_config = array_merge(self::get_pagination_config($tag), array('base_url' => self::get_pagination_base_url($tag), 'per_page' => $nb_to_display, 'total_rows' => $tag->get('nb_total_items'), 'num_links' => 3, 'cur_page' => $cur_page, 'first_link' => lang('first_link'), 'last_link' => lang('last_link'), 'next_link' => lang('next_link'), 'prev_link' => lang('prev_link'))); // Pagination initialization self::$ci->pagination->initialize($pagination_config); // Create the links $page['pagination_links'] = self::$ci->pagination->create_links(); // Tag cache self::set_cache($tag, $page['pagination_links']); return $page['pagination_links']; }
/** * @param FTL_Binding $tag * * @return mixed * */ public static function get_tags(FTL_Binding $tag) { // Categories model self::$ci->load->model('tag_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::$tags[$lsk])) { // CSS class to use for the current tag $active_class = $tag->getAttribute('active_class', 'active'); // Asked tag $asked_tag_name = self::get_asked_tag_uri(); // Check if the element has one tag array (eg. for Articles) if (isset($element['tags'])) { $tags = $element['tags']; // Fix the 'nb' key (nb_articles using this category) foreach ($tags as $key => $category) { $tags[$key]['nb'] = '1'; } } else { if ($element_name == 'page') { $id_page = !is_null($page) ? $page['id_page'] : NULL; } else { $id_page = NULL; } $tags = self::$ci->tag_model->get_page_articles_list($id_page); } $page_url = !is_null($page) ? trim($page['absolute_url'], '/') . '/' : Pages::get_home_page_url(); $tag_uri_segment = self::get_config_special_uri_segment('tag'); // Add the URL to the tag to each tag row // Also add the active class foreach ($tags as $key => $t) { $tags[$key]['url'] = $page_url . $tag_uri_segment . '/' . $t['tag_name']; $tags[$key]['lang_url'] = $page_url . $tag_uri_segment . '/' . $t['tag_name']; // Active tag ? $tags[$key]['active_class'] = $t['tag_name'] == $asked_tag_name ? $active_class : ''; $tags[$key]['is_active'] = $t['tag_name'] == $asked_tag_name; } self::$tags[$lsk] = array_values($tags); } return self::$tags[$lsk]; }
/** * 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(); } }
/** * 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 ''; }
/** * Find and parses the page view * * @param FTL_Binding * @param array * * @return string * */ private static function find_and_parse_page_view(FTL_Binding $tag, $page) { // Default page view if (empty($page['view'])) { $page['view'] = Theme::get_default_view('page'); } // View path $view_path = Theme::get_theme_path() . 'views/' . $page['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('page') . EXT; if (!file_exists($view_path)) { $view_path = APPPATH . 'views/' . Theme::get_default_view('page') . EXT; } } return $tag->parse_as_nested(file_get_contents($view_path)); }
/** * 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()); }