/** * Set Breadcrumb * * Breadcrumbs can be overridden by using this tag inside page content * * Usage: * * {{ template:set_breadcrumb name="My Page" uri="some-page" reset="true" }} * * @return void */ public function set_breadcrumb() { $name = $this->attribute('name'); $uri = $this->attribute('uri'); $reset = str_to_bool($this->attribute('reset', false)); $this->template->set_breadcrumb($name, $uri, $reset, true); }
function parser_callback($tag, $attributes, $content, $data) { // This is a inline editable override used only for special cases if (isset($attributes['editable']) && str_to_bool($attributes['editable'])) { return $this->_inline_editable(TRUE); } else { return $this->_inline_editable(FALSE); } }
function is_str_to_bool($value, $strict = false) { if (!$strict) { $value_test = @(string) $value; if (is_numeric($value_test)) { return true; } } return !str_to_bool($value) || str_to_bool($value, true); }
public function form() { $parse_data = array(); if (str_to_bool($this->attribute('captcha'))) { $parse_data['captcha'] = '<img class="captcha_image" src="' . site_url('contact/captcha') . '" />'; $parse_data['captcha_input'] = '<input class="captcha_input" type="text" name="captcha_input" />'; } $data['id'] = $this->attribute('id'); $data['class'] = $this->attribute('class'); $data['anchor'] = $this->attribute('anchor'); $data['captcha'] = str_to_bool($this->attribute('captcha')); $data['content'] = $this->parser->parse_string($this->content(), $parse_data, TRUE); // Wrap content with form tags and add a spam check field // A theory that spam bots do not read css and will attempt to fill all fields // The form will not submit if the hidden field has been filled $content = $this->load->view('contact', $data, TRUE); if ($this->attribute('id') == '' || $this->attribute('id') == $this->input->post('form_id')) { // We need at least one validation rule for run to work $this->form_validation->set_rules('spam_check', 'Spam Check', 'trim'); // Repopulate form by default if ($this->input->post()) { $content = $this->_repopulate_form($content); } // No custom content was set, use the default form validations if ($this->content() == '') { $this->form_validation->set_rules('name', 'Name', 'trim|required'); $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); $this->form_validation->set_rules('phone', 'Phone', 'trim|required'); $this->form_validation->set_rules('message', 'Message', 'trim|required'); } // Set required fields if ($required = $this->attribute('required')) { foreach (explode('|', $required) as $name) { $this->form_validation->set_rules($name, $name, 'required'); } } if (str_to_bool($this->attribute('captcha'))) { $this->form_validation->set_rules('captcha_input', 'CAPTCHA', 'validate_captcha|required'); } // Process Form if ($this->form_validation->run() == TRUE && $this->input->post('spam_check') == '') { $this->_send_form(); if ($this->attribute('success_redirect')) { redirect($this->attribute('success_redirect')); } else { return "Your message has been sent. Thank You"; } } // Add validation errors to the content $content = validation_errors() . $content; } return array('_content' => $content); }
public function form() { $parse_data = array(); if (str_to_bool($this->attribute('captcha'))) { $parse_data['captcha'] = '<img class="captcha_image" src="' . site_url('contact/captcha') . '" />'; $parse_data['captcha_input'] = '<input class="captcha_input" type="text" name="captcha_input" />'; } $data['id'] = $this->attribute('id'); $data['class'] = $this->attribute('class'); $data['anchor'] = $this->attribute('anchor'); $data['captcha'] = str_to_bool($this->attribute('captcha')); $data['content'] = $this->parser->parse_string($this->content(), $parse_data, TRUE); // Wrap content with form tags and add a spam check field // A theory that spam bots do not read css and will attempt to fill all fields // The form will not submit if the hidden field has been filled if ($this->input->post('submit')) { $this->form_validation->set_rules('spam_check', 'Spam Check', 'trim'); $this->form_validation->set_rules('name', 'Name', 'trim|required'); $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); $this->form_validation->set_rules('phone', 'Phone', 'trim|required|format_phone|regex_match[/(\\(\\d{3}+\\)+ \\d{3}+\\-\\d{4}+)/]'); $this->form_validation->set_rules('message', 'Message', 'trim|required'); $this->form_validation->set_error_delimiters('<span class="error">', '</span>'); // Set required fields if ($required = $this->attribute('required')) { foreach (explode('|', $required) as $name) { $this->form_validation->set_rules($name, $name, 'required'); } } if (str_to_bool($this->attribute('captcha'))) { $this->form_validation->set_rules('captcha_input', 'CAPTCHA', 'validate_captcha|required'); } if ($this->form_validation->run() == FALSE) { $content = $this->load->view('contact', $data, TRUE); } else { $this->_send_form(); if ($this->attribute('success_redirect')) { $this->session->set_flashdata('message', 'Your message has been sent. Thank You'); redirect($this->attribute('success_redirect')); } else { $this->session->set_flashdata('message', 'Your message has been sent. Thank You'); redirect(site_url('contact')); } } } else { $content = $this->load->view('contact', $data, TRUE); } // Add validation errors to the content $content = $content; return array('_content' => $content); }
/** * @test */ public function it_converts_strings_to_booleans() { $this->assertFalse(str_to_bool('false')); $this->assertFalse(str_to_bool('FALSE')); $this->assertFalse(str_to_bool('0')); $this->assertFalse(str_to_bool(0)); $this->assertFalse(str_to_bool(false)); $this->assertTrue(str_to_bool('true')); $this->assertTrue(str_to_bool('TRUE')); $this->assertTrue(str_to_bool('1')); $this->assertTrue(str_to_bool(1)); $this->assertTrue(str_to_bool(true)); $this->assertFalse(str_to_bool(['biscuits'])); $this->assertFalse(str_to_bool(null)); }
/** * Set Data for the plugin. * * Avoid doing this in constructor so we do not force logic on developers. * * @param array $content Content of the tags if any * @param array $attributes Attributes passed to the plugin */ public function set_data($content, $attributes) { $content and $this->content = $content; if ($attributes) { // Let's get parse_params first since it // dictates how we handle all tags if (!isset($attributes['parse_params'])) { $attributes['parse_params'] = true; } if (str_to_bool($attributes['parse_params'])) { // For each attribute, let's see if we need to parse it. foreach ($attributes as $key => $attr) { $attributes[$key] = $this->parse_parameter($attr); } } $this->attributes = $attributes; } }
function output($attributes = array()) { $settings = $this->Field->settings; // Image thumbnail size override if (!empty($attributes['width']) || !empty($attributes['height'])) { $max_width = !empty($attributes['width']) ? $attributes['width'] : 0; $max_height = !empty($attributes['height']) ? $attributes['height'] : 0; $crop = isset($attributes['crop']) && str_to_bool($attributes['crop']) ? TRUE : FALSE; $image_src = image_thumb($this->content['src'], $max_width, $max_height, $crop); } else { if (!empty($settings['max_width']) || !empty($settings['max_height'])) { $max_width = !empty($settings['max_width']) ? $settings['max_width'] : 0; $max_height = !empty($settings['max_height']) ? $settings['max_height'] : 0; $crop = isset($settings['crop']) && $settings['crop'] == '1' ? TRUE : FALSE; $image_src = image_thumb($this->content['src'], $max_width, $max_height, $crop); } else { $image_src = base_url($this->content['src']); } } // Show output with image tags if ($settings['output'] == 'image') { // Inline editing callback override if (isset($attributes['editable'])) { if (str_to_bool($attributes['editable'])) { return $this->_inline_editable($image_src, TRUE); } else { return $this->_inline_editable($image_src, FALSE); } } else { if (!isset($settings['inline_editing']) || $settings['inline_editing']) { return $this->_inline_editable($image_src, TRUE); } else { return $this->_inline_editable($image_src, FALSE); } } } else { return $image_src; } }
/** * Set Data for the plugin. * * Avoid doing this in constructor so we do not force logic on developers. * * @param array $content Content of the tags if any * @param array $attributes Attributes passed to the plugin */ public function set_data($content, $attributes) { $content and $this->content = $content; if ($attributes) { // Let's get parse-params first since it dictates how we handle all tags // Default: true $parse_params = true; $set = false; foreach (array('parse_params', 'parse-params') as $attr) { if (isset($attributes[$attr]) and !$set) { $parse_params = str_to_bool($attributes[$attr]); $set = true; } } if ($parse_params) { // For each attribute, let's see if we need to parse it. foreach ($attributes as $key => $attr) { $attributes[$key] = $this->parse_parameter($attr); } } $this->attributes = $attributes; } }
/** * Add counting to tag loops * * @example * Usage: * * {{ blog:posts }} * {{ helper:count }} -- {{title}} * {{ /blog:posts }} * * Outputs: * * 1 -- This is an example title * 2 -- This is another title * * @example * Usage: * * {{ blog:posts }} * {{ helper:count mode="subtract" start="10" }} -- {{title}} * {{ /blog:posts }} * * Outputs: * * 10 -- This is an example title * 9 -- This is another title * * You can add a second counter to a page by setting a unique identifier: * * {{ files:listing folder="foo" }} * {{ helper:count identifier="files" return="false" }} * {{name}} -- {{slug}} * {{ /files:listing }} * You have {{ helper:show_count identifier="files" }} files. * * @return string|int */ public function count() { static $count = array(); $identifier = $this->attribute('identifier', 'default'); // Use a default of 1 if they haven't specified one and it's the first iteration if (!isset($count[$identifier])) { $count[$identifier] = $this->attribute('start', 1); } elseif (self::$_counter_increment) { // count up unless they specify to "subtract" $this->attribute('mode') == 'subtract' ? $count[$identifier]-- : $count[$identifier]++; } // set this back to continue counting again next time self::$_counter_increment = true; return str_to_bool($this->attribute('return', true)) ? $count[$identifier] : null; }
/** * Theme Favicon * * Insert a link tag for favicon from your theme * * Specs: * * http://www.w3.org/TR/html5/links.html#rel-icon * * Usage: * * {{ theme:favicon file="" [rel="foo"] [type="bar"] [sizes="16x16 72x72 …"] }} * * @return string The link HTML tag for the favicon. */ public function favicon() { $this->load->library('asset'); $file = Asset::get_filepath_img($this->attribute('file', 'favicon.ico'), true); $rel = $this->attribute('rel', 'shortcut icon'); $sizes = $this->attribute('sizes', ''); $type = $this->attribute('type', 'image/x-icon'); $is_xhtml = str_to_bool($this->attribute('xhtml', true)); $link = '<link '; $link .= 'href="' . $file . '" '; $link .= 'rel="' . $rel . '" '; $link .= $sizes ? 'sizes="' . $sizes . '" ' : ''; $link .= 'type="' . $type . '" '; $link .= ($is_xhtml ? '/' : '') . '>'; return $link; }
/** * Checks whether a given value can be a strict string * representation or a true boolean * * @author Kader Bouyakoub <*****@*****.**> * @link @bkader <github> * @link @KaderBouyakoub <twitter> * * @access public * @param string * @param boolean * @return boolean */ function is_str_to_bool($str, $strict = false) { if (!$strict) { $str_test = @(string) $str; if (is_numeric($str_test)) { return true; } } return !str_to_bool($str) or str_to_bool($str, true); }
public function counter() { static $count = array(); $key = $this->get_attribute('identifier', 'default'); if (!isset($count[$key])) { $count[$key] = $this->get_attribute('start', 1); } elseif (self::$_counter_increment) { $this->get_attribute('mode') == 'subtract' ? $count[$key]-- : $count[$key]++; } self::$_counter_increment = true; return str_to_bool($this->get_attribute('return', true)) ? $count[$key] : null; }
protected function _breadcrumb($Item, $depth = 1, $config = array()) { $crumbs = array(); // Build current on first depth if ($depth == 1) { $Item->class = trim($Item->class . ' current last'); $Item->id = trim($Item->tag_id); $Item->url = current_url(); $Item->path = current_url(); $crumbs[] = object_to_array($Item); } else { if ($Item->parent_id == 0) { $Item->class .= ' first'; } // List Item Attributes $Item->class = trim($Item->class); $Item->id = trim($Item->tag_id); $Item->url = $Item->url; $Item->path = $Item->url; $crumbs[] = object_to_array($Item); } // Check if item has a parent to process or if include_home is set true if ($Item->parent_id > 0 || isset($config['include_home']) && str_to_bool($config['include_home']) && $Item->parent_id == 0 && $Item->id != $this->CI->settings->content_module->site_homepage) { if (isset($config['include_home']) && str_to_bool($config['include_home']) && $Item->parent_id == 0) { $entry_id = $this->CI->settings->content_module->site_homepage; } else { $entry_id = $Item->parent_id; } $query = $this->CI->db->select('navigation_items.*, entries.title as entry_title, entries.slug')->from('navigation_items')->join('entries', 'entries.id = navigation_items.entry_id', 'left')->where('navigation_items.id', $entry_id)->limit(1)->get(); if ($query->num_rows() > 0) { $result = $query->row(); $result = $this->_parse_link($result); $crumbs = array_merge($this->_breadcrumb($result, $depth + 1), $crumbs); } $query->free_result(); } return $crumbs; }
public static function search($search_string) { global $db; $search_string = $db->escape_string($search_string); //$query = 'SELECT *, items.name as name, items.owner_id as owner_id, UNIX_TIMESTAMP(last_accounted_for) as last_accounted_for_unix, UNIX_TIMESTAMP(due_date) as due_date_unix ' . // 'FROM ' . TATT_PREFIX . 'attributes attr JOIN ' . TATT_PREFIX . 'items items ' . // "WHERE items.name LIKE '%$search_string%' AND attr.item_id = items.item_id"; //$result = $db->query($query); $query = 'SELECT *, items.name as name, items.owner_id as owner_id, UNIX_TIMESTAMP(last_accounted_for) as last_accounted_for_unix, UNIX_TIMESTAMP(due_date) as due_date_unix, item_types.name as type_name ' . 'FROM ' . TATT_PREFIX . 'items items JOIN ' . TATT_PREFIX . "item_types item_types USING (item_type_id) " . "WHERE items.name LIKE '%{$search_string}%'"; $result2 = $db->query($query); $items_array = array(); while ($item_data = $result2->fetch_object()) { $item = new Item(); $item->id = $item_data->item_id; $item->name = $item_data->name; $item->type_id = (int) $item_data->item_type_id; $item->type_name = $item_data->type_name; $item->owner_id = (int) $item_data->owner_id; $item->owner = new User($item->owner_id); $item->location = $item_data->location; $item->last_accounted_for = (int) $item_data->last_accounted_for_unix; $item->has_photo = str_to_bool($item_data->has_photo); $item->due_date = (int) $item_data->due_date_unix; if ($item_data->checked_out_by != NULL) { $item->checked_out_by = new User((int) $item_data->checked_out_by); } $item->attributes = Attribute::get_attributes_by_item_id($item_data->item_id); $items_array[] = $item; } return $items_array; }
/** * Extracts the looped tags so that we can parse conditionals then re-inject. * * @param string $text The text to extract from * @return string */ protected function extractLoopedTags($text, $data = array(), $callback = null) { // The commented code fails on long strings, it is not clear what couses this. // PCRE ini settings were good, preg_last_error() returned 0. /* $count = preg_match_all($this->callbackBlockRegex, $text, $matches, PREG_SET_ORDER); if ($count === false) { // Try to debug. $preg_last_error = preg_last_error(); $preg_last_error_message = preg_error_message(); } if ($count) { foreach ($matches as $match) { // Does this callback block contain parameters? if ($this->parseParameters($match[2], $data, $callback)) { // Let's extract it so it doesn't conflict with local variables when // parseVariables() is called. $text = $this->createExtraction('callback_blocks', $match[0], $match[0], $text); } else { $text = $this->createExtraction('looped_tags', $match[0], $match[0], $text); } } } return $text; */ if ($text == '') { return $text; } $count = 0; $matches = array(); $offset = 0; while ($this->findBlock($text, $m, $offset)) { $matches[] = array($m[0][0], $m[1][0], $m[2][0], $m[3][0]); $offset = $m[0][1] + strlen($m[0][0]); $count++; } if ($count) { foreach ($matches as $match) { $parameters = $this->parseParameters($match[2], $data, $callback); // Added by Ivan Tcholakov, 22-JAN-2016. $parse_content = null; foreach (array('parse_content', 'parse-content') as $attr) { if (isset($parameters[$attr])) { $parse_content = str_to_bool($parameters[$attr]); break; } } // // Does this callback block contain parameters? // Modified by Ivan Tcholakov, 22-JAN-2016. //if ($parameters) { if ($parameters || $parse_content === false) { // // Let's extract it so it doesn't conflict with local variables when // parseVariables() is called. $text = $this->createExtraction('callback_blocks', $match[0], $match[0], $text); } else { $text = $this->createExtraction('looped_tags', $match[0], $match[0], $text); } } } return $text; }
public function detect_boolean_attributes($attr_list) { if (empty($this->parsed_attributes) || !is_array($this->parsed_attributes)) { return; } if (!is_array($attr_list)) { $attr_list = (array) $attr_list; } if (empty($attr_list)) { return; } foreach ($attr_list as $key => $value) { $index = filter_var($value, FILTER_VALIDATE_INT); if ($index !== false) { $attr_list[$key] = $index; } } $i = 0; foreach ($this->parsed_attributes as $key => $value) { if (in_array($i, $attr_list, true) || in_array($key, $attr_list, true)) { $this->parsed_attributes[$key] = str_to_bool($value); } $i++; } }
/** * Parse chunk content * * @access private * @param string the chunk content * @param string parse Lex tags? - yes/no * @return string */ private function parse_chunk($content, $parse_tags) { // Lex tags are parsed by default. If you want to // turn off parsing Lex tags, just set parse_tags to 'no' if (str_to_bool($parse_tags)) { $parser = new Lex_Parser(); $parser->scope_glue(':'); return $parser->parse($content, array(), array($this->parser, 'parser_callback')); } else { return $content; } }