public function build() { if (empty($this->callback) && empty($this->td)) { throw new NimbleException('You must set the td or callback variable'); } if (empty($this->collection) || count($this->collection) == 0) { return ""; } $i = 0; foreach ($this->collection as $obj) { if ($i % $this->cols == 0) { if ($i != 0) { $this->content .= '</tr>'; } $this->content .= "<tr class=\"{$this->tr_class_name}\">"; } if (!empty($this->callback)) { $var = $this->callback; $this->content .= $var($obj); } else { $this->content .= $this->process_td($obj); } $i++; } $remainder = count($this->collection) % $this->cols; for ($i = 0; $i < $remainder - 1; $i++) { $this->content .= "<td class='empty'> </td>"; } $this->content .= "</tr>"; $this->content = TagHelper::content_tag('tbody', $this->content); $this->content = TagHelper::content_tag('table', $this->content, $this->table_options); unset($this->callback); unset($var); return $this->content; }
function menu_for_controllers($menu_options = array()) { $menu_options = empty($menu_options) ? $this->_get_default_full_menu() : $menu_options; $menu = ''; foreach ($menu_options as $controller => $actions) { $controller_name = AkInflector::classify($controller); $current_controller_name = $this->_controller->getControllerName(); $current_action_name = $this->_controller->Request->getAction(); $controller_class_name = $controller_name . 'Controller'; $controller_human_name = AkInflector::humanize($controller); $controller_file_name = AkInflector::toControllerFilename($controller); if (file_exists($controller_file_name)) { include_once $controller_file_name; if (class_exists($controller_class_name)) { $menu_header = TagHelper::content_tag('h2', TagHelper::content_tag('a', $controller_human_name, array('href' => $this->_controller->urlFor(array('controller' => $controller)))), array('class' => $current_controller_name == $controller_name ? 'current' : '')); $submenu = ''; foreach ((array) $actions as $action) { if ($action[0] == '_') { continue; } $submenu .= TagHelper::content_tag('li', TagHelper::content_tag('a', AkInflector::humanize($action), array('href' => $this->_controller->urlFor(array('controller' => $controller, 'action' => $action)))), array('class' => $current_controller_name == $controller_name && $current_action_name == $action ? 'current' : '')); } $menu .= !empty($submenu) ? TagHelper::content_tag('ul', TagHelper::content_tag('li', $menu_header . TagHelper::content_tag('ul', $submenu))) : ''; } } } return TagHelper::content_tag('div', $menu, array('id' => 'menu')); }
function test_TagHelper() { $this->assertEqual(TagHelper::tag('br'), '<br />'); $this->assertEqual(TagHelper::tag('input', array('type' => 'text', 'value' => 'Insert your text >> "HERE"')), '<input type="text" value="Insert your text >> "HERE"" />'); $this->assertEqual(TagHelper::tag('hr', array('style' => '', 1234 => 'This is not possible')), '<hr />'); $this->assertEqual(TagHelper::content_tag('p', 'Have a look "HERE"'), '<p>Have a look "HERE"</p>'); $this->assertEqual(TagHelper::content_tag('textarea', 'Have a look "HERE"', array('name' => 'details')), '<textarea name="details">Have a look "HERE"</textarea>'); $this->assertEqual(TagHelper::cdata_section('Have a look "HERE"'), '<![CDATA[Have a look "HERE"]]>'); }
public function testBuildTable2() { $users = User::find('all'); $table = new SmartTable($users, $cols = 4); $table->callback = function ($object) { return TagHelper::content_tag('td', "name: {$object->name} --- <br/>"); }; $b = $table->build(); $e = !empty($b); $this->assertTrue($e); }
function sortable_link($column, $url_options = array(), $link_options = array()) { $default_url_options = array('sort' => $column, 'direction' => empty($this->_controller->params['sort']) ? 'desc' : ($this->_controller->params['sort'] == $column ? empty($this->_controller->params['direction']) ? 'desc' : ($this->_controller->params['direction'] == 'desc' ? 'asc' : 'desc') : 'desc')); $page_var_on_url = empty($url_options['page_var_on_url']) ? 'page' : $url_options['page_var_on_url']; unset($url_options['page_var_on_url']); $url_options = array_merge($default_url_options, $url_options); $link_options['href'] = html_entity_decode($this->_controller->url_helper->modify_current_url($url_options, array($page_var_on_url))); if (empty($link_options['title'])) { $link_options['title'] = $this->_controller->t("Sort by {$column} ({$url_options['direction']})"); } return TagHelper::content_tag('a', $this->_controller->t(AkInflector::humanize($column)), $link_options); }
public function permission_check_box(&$Permission, &$Extenssion, &$Role) { $options = array('id' => 'permissions_' . $Permission->getId() . '_' . $Role->getId(), 'name' => 'permissions[' . $Permission->getId() . '][' . $Role->getId() . ']', 'type' => 'checkbox'); $Role->permission->load(); if (in_array($Permission->getId(), $Permission->collect($Role->permissions, 'id', 'id'))) { $options['checked'] = 'checked'; } if (!$Role->get('is_enabled')) { $options['disabled'] = 'disabled'; } return TagHelper::tag('input', array('name' => $options['name'], 'type' => 'hidden', 'value' => 0)) . TagHelper::tag('input', $options); }
function error_messages_for($class) { if (empty($class->errors)) { return; } $errors = $class->errors; $out = array(TagHelper::tag('ul', array('class' => 'errors'))); foreach ($errors as $col => $error) { array_push($out, TagHelper::content_tag('li', TagHelper::content_tag('p', $error))); } array_push($out, TagHelper::close_tag('ul')); $message = TagHelper::content_tag('h2', "Errors occured saving this record", array('class' => 'error_message')); return TagHelper::content_tag('div', $message . join("\n", $out), array('class' => 'error_container')); }
/** * Output an <abbr> tag as defined by the Datetime Design Pattern, * which is described at http://microformats.org/wiki/datetime-design-pattern * * @param mixed $date Something that can be converted to a DateTime object * @param string $viewable_format Format for visible date text * @return string HTML tag */ public static function datetime_tag($date, $viewable_format = \DateTime::RFC822, $html_attributes = array()) { return TagHelper::content_tag('abbr', self::format_date($date, $viewable_format), array_merge((array) $html_attributes, array('title' => self::format_date($date, \DateTime::ISO8601)))); }
/** * Creates a link tag for starting an email to the specified <tt>email_address</tt>, which is also used as the name of the * link unless +name+ is specified. Additional HTML options, such as class or id, can be passed in the * <tt>html_options</tt> array. * * You can also make it difficult for spiders to harvest email address by obfuscating them. * Examples: * $url->mail_to('*****@*****.**', 'My email', array('encode' => 'javascript')) => * <script type="text/javascript" language="javascript">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script> * * $url->mail_to('*****@*****.**', 'My email', array('encode' => 'hex')) => * <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a> * * You can also specify the cc address, bcc address, subject, and body parts of the message header to create a complex e-mail * using the corresponding +cc+, +bcc+, +subject+, and +body+ <tt>html_options</tt> keys. Each of these options are URI escaped * and then appended to the <tt>email_address</tt> before being output. <b>Be aware that javascript keywords will not be * escaped and may break this feature when encoding with javascript.</b> * * Examples: * mail_to "*****@*****.**", "My email", :cc => "*****@*****.**", :bcc => "*****@*****.**", :subject => "This is an example email", :body => "This is the body of the message." # => * <a href="mailto:me@domain.com?cc="*****@*****.**"&bcc="*****@*****.**"&body="This%20is%20the%20body%20of%20the%20message."&subject="This%20is%20an%20example%20email">My email</a> */ function mail_to($email_address, $name = null, $html_options = array()) { $name = empty($name) ? $email_address : $name; $default_options = array('cc' => null, 'bcc' => null, 'subject' => null, 'body' => null, 'encode' => ''); $options = array_merge($default_options, $html_options); $encode = $options['encode']; $string = ''; $extras = ''; $extras .= !empty($options['cc']) ? "cc=" . urlencode(trim($options['cc'])) . '&' : ''; $extras .= !empty($options['bcc']) ? "bcc=" . urlencode(trim($options['bcc'])) . '&' : ''; $extras .= !empty($options['body']) ? "body=" . urlencode(trim($options['body'])) . '&' : ''; $extras .= !empty($options['subject']) ? "subject=" . urlencode(trim($options['subject'])) . '&' : ''; $extras = empty($extras) ? '' : '?' . str_replace('+', '%20', rtrim($extras, '&')); $html_options = Ak::delete($html_options, 'cc', 'bcc', 'subject', 'body', 'encode'); if ($encode == 'javascript') { $tmp = "document.write('" . TagHelper::content_tag('a', $name, array_merge($html_options, array('href' => 'mailto:' . $email_address . $extras))) . "');"; for ($i = 0; $i < strlen($tmp); $i++) { $string .= '%' . dechex(ord($tmp[$i])); } return "<script type=\"text/javascript\">eval(unescape('{$string}'))</script>"; } elseif ($encode == 'hex') { $encoded_email_address = ''; $encoded_email_for_name = ''; for ($i = 0; $i < strlen($email_address); $i++) { if (preg_match('/\\w/', $email_address[$i])) { $encoded_email_address .= sprintf('%%%x', ord($email_address[$i])); } else { if ($email_address[$i] == '@') { $encoded_email_address .= '%40'; } elseif ($email_address[$i] == '.') { $encoded_email_address .= '%2e'; } else { $encoded_email_address .= $email_address[$i]; } } $encoded_email_for_name .= rand(1, 2) % 2 ? '&#' . ord($email_address[$i]) . ';' : '&#x' . dechex(ord($email_address[$i])) . ';'; } $name = str_replace($email_address, $encoded_email_for_name, $name); return TagHelper::content_tag('a', $name, array_merge($html_options, array('href' => 'mailto:' . $encoded_email_address . $extras))); } else { return TagHelper::content_tag('a', $name, array_merge($html_options, array('href' => 'mailto:' . $email_address . $extras))); } }
/** * Returns an image tag converting the +options+ into html options on the tag, but with these special cases: * * * <tt>alt</tt> - If no alt text is given, the file name part of the +src+ is used (capitalized and without the extension) * * <tt>size</tt> - Supplied as "XxY", so "30x45" becomes width="30" and height="45" * * The +src+ can be supplied as a... * * full path, like "/my_images/image.gif" * * file name, like "rss.gif", that gets expanded to "/images/rss.gif" * * file name without extension, like "logo", that gets expanded to "/images/logo.png" */ function image_tag($source, $options = array()) { if (!empty($options['size'])) { list($options['width'], $options['height']) = split('x|X| ', trim(str_replace(' ', '', $options['size']))); unset($options['size']); } $options['src'] = $this->image_path($source); $options['alt'] = !empty($options['alt']) ? $options['alt'] : AkInflector::titleize(substr(basename($options['src']), 0, strpos(basename($options['src']), '.')), 'first'); return TagHelper::tag('img', $options); }
function to_time_zone_select_tag($priority_zones = array(), $options = array(), $html_options = array()) { $this->add_default_name_and_id($html_options); return TagHelper::content_tag('select', $this->_addOptions($this->_template_object->time_zone_options_for_select($this->getValue(), $priority_zones, empty($options['model']) ? 'AkTimeZone' : $options['model']), $options, $this->getValue()), $html_options); }
/** * Create an HTML link to an e-mail address. * * Valid options (for the last parameter) are: * * encode - Set to "hex" to hex-encode the e-mail address in the link * cc - Add recipients to the CC (carbon copy) of the email * bcc - Add recipients to the BCC (blind carbon copy) of the email * subject - Preset the subject line of the resulting email * body - Preset the body of the resulting email * * Other options will be passed as HTML attributes on the link tag. * * @param string $address E-mail address of recipient * @param string $label String to show in link, defaults to e-mail address * @param array $html_options Options for outputting link * @return string HTML mailto: link tag */ public static function mail_to($address, $label = null, $html_options = array()) { $encode = $html_options['encode']; $url_params = array(); if ($html_options['cc']) { $url_params['cc'] = $cc; } if ($html_options['bcc']) { $url_params['bcc'] = $bcc; } if ($html_options['subject']) { $url_params['subject'] = $subject; } if ($html_options['body']) { $url_params['body'] = $body; } unset($html_options['encode'], $html_options['cc'], $html_options['bcc'], $html_options['subject'], $html_options['body']); $address = strval($address); $url_params = count($url_params) == 0 ? '' : '?' . http_build_query($url_params); if ($encode == 'hex') { $address_encoded = ''; for ($i = 0; $i < strlen($address); $i++) { if (preg_match('/\\w/', $address[$i])) { $address_encoded .= '%' . bin2hex($address[$i]); } else { $address_encoded .= $address[$i]; } } $label = $label ? $label : $address; for ($i = 0; $i < strlen($label); $i++) { $label_encoded .= '&#x' . bin2hex($label[$i]) . ';'; } $mailto = "mailto:"; return TagHelper::content_tag('a', $label_encoded, array_merge($html_options, array('href' => $mailto . $address_encoded . $url_params))); } else { return TagHelper::content_tag('a', $label ? $label : $address, array_merge($html_options, array('href' => 'mailto:' . $address . $url_params))); } }
/** * Generate a list of <option> tags from an array, using the array keys as * the value attributes, and the corresponding array values as the labels. * * If arrays are nested, an <optgroup> tag will be generated using the array * key as its label, and containing <option> tags for each element of the * nested array. * * @param array $choices Set of $value=>$label choices * @param mixed $selected Single value or array of values that indicate keys of * options to mark as selected. * @return string Set of <option> tags */ public static function options_for_select($choices, $selected = null) { $selected_reversed = array_flip(array_map('strval', array_values((array) $selected))); $option_tags = ''; foreach ($choices as $key => $value) { if (is_array($value)) { $option_tags .= TagHelper::content_tag('optgroup', self::options_for_select($value, $selected), array('label' => $key)) . "\n"; } else { $html_attributes = array('value' => $key); if (isset($selected_reversed[strval($key)])) { $html_attributes['selected'] = 'selected'; } $option_tags .= TagHelper::content_tag('option', TagHelper::escape_once($value), $html_attributes) . "\n"; } } return $option_tags; }
protected function showTags() { $this->loadLanguageFile('tl_module'); $strUrl = ampersand(\Environment::get('request'), ENCODE_AMPERSANDS); // Get target page $objPageObject = $this->Database->prepare("SELECT id, alias FROM tl_page WHERE id=?")->limit(1)->execute($this->tag_jumpTo); global $objPage; $default = $objPage != null ? $objPage->row() : array(); $pageArr = $objPageObject->numRows ? $objPageObject->fetchAssoc() : $default; $strParams = ''; if ($this->keep_url_params) { $strParams = \TagHelper::getSavedURLParams($this->Input); } foreach ($this->arrTags as $idx => $tag) { if (count($pageArr)) { if ($tag['tag_name'] != \Input::get('tag') && $tag['tag_name'] != str_replace('|slash|', '/', \Input::get('tag'))) { $strUrl = ampersand($this->generateFrontendUrl($pageArr, '/tag/' . str_replace('/', '|slash|', \System::urlencode($tag['tag_name'])))); } else { $strUrl = ampersand($this->generateFrontendUrl($pageArr)); } if (strlen($strParams)) { if (strpos($strUrl, '?') !== false) { $strUrl .= '&' . $strParams; } else { $strUrl .= '?' . $strParams; } } } $this->arrTags[$idx]['tag_url'] = $strUrl; if ($tag['tag_name'] == \Input::get('tag') || $tag['tag_name'] == str_replace('|slash|', '/', \Input::get('tag'))) { $this->arrTags[$idx]['tag_class'] .= ' active'; } if ($this->checkForArticleOnPage) { global $objPage; // get articles on page $arrArticles = $this->Database->prepare("SELECT id FROM tl_article WHERE pid = ?")->execute($objPage->id)->fetchEach('id'); $arrTagIds = $this->Database->prepare("SELECT tid FROM " . $this->tag_tagtable . " WHERE from_table = ? AND tag = ?")->execute('tl_article', $tag['tag_name'])->fetchEach('tid'); if (count(array_intersect($arrArticles, $arrTagIds))) { $this->arrTags[$idx]['tag_class'] .= ' here'; } } if ($this->checkForContentElementOnPage) { global $objPage; // get articles on page $arrArticles = $this->Database->prepare("SELECT id FROM tl_article WHERE pid = ?")->execute($objPage->id)->fetchEach('id'); if (count($arrArticles)) { $arrCE = $this->Database->prepare("SELECT id FROM tl_content WHERE pid IN (" . implode(",", $arrArticles) . ")")->execute()->fetchEach('id'); $arrTagIds = $this->Database->prepare("SELECT tid FROM " . $this->tag_tagtable . " WHERE from_table = ? AND tag = ?")->execute('tl_content', $tag['tag_name'])->fetchEach('tid'); if (count(array_intersect($arrCE, $arrTagIds))) { $this->arrTags[$idx]['tag_class'] .= ' here'; } } } } $relatedlist = strlen(\Input::get('related')) ? preg_split("/,/", \Input::get('related')) : array(); foreach ($this->arrRelated as $idx => $tag) { if (count($pageArr)) { if ($tag['tag_name'] != \Input::get('tag')) { $strUrl = ampersand($this->generateFrontendUrl($pageArr, '/tag/' . str_replace('/', '|slash|', \System::urlencode(\Input::get('tag'))) . '/related/' . str_replace('/', '|slash|', \System::urlencode(join(array_merge($relatedlist, array($tag['tag_name'])), ','))))); } else { $strUrl = ampersand($this->generateFrontendUrl($pageArr)); } } $this->arrRelated[$idx]['tag_url'] = $strUrl; } $this->Template->pageID = $this->id; $this->Template->tags = $this->arrTags; $this->Template->jumpTo = $this->jumpTo; $this->Template->relatedtags = $this->arrRelated; $this->Template->strRelatedTags = $GLOBALS['TL_LANG']['tl_module']['tag_relatedtags']; $this->Template->strAllTags = $GLOBALS['TL_LANG']['tl_module']['tag_alltags']; $this->Template->strTopTenTags = sprintf($GLOBALS['TL_LANG']['tl_module']['top_tags'], $this->tag_topten_number); $this->Template->tagcount = count($this->arrTags); $this->Template->selectedtags = strlen(\Input::get('tag')) ? count($this->arrRelated) + 1 : 0; if ($this->tag_show_reset) { $strEmptyUrl = ampersand($this->generateFrontendUrl($pageArr, '')); if (strlen($strParams)) { if (strpos($strUrl, '?') !== false) { $strEmptyUrl .= '&' . $strParams; } else { $strEmptyUrl .= '?' . $strParams; } } $this->Template->empty_url = $strEmptyUrl; $this->Template->lngEmpty = $GLOBALS['TL_LANG']['tl_module']['tag_clear_tags']; } $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/tags/assets/tagcloud.js'; if (count($pageArr)) { $this->Template->topten = $this->tag_topten; if ($this->tag_topten) { foreach ($this->arrTopTenTags as $idx => $tag) { if (count($pageArr)) { if ($tag['tag_name'] != \Input::get('tag')) { $strUrl = ampersand($this->generateFrontendUrl($pageArr, '/tag/' . str_replace('/', '|slash|', \System::urlencode($tag['tag_name'])))); } else { $strUrl = ampersand($this->generateFrontendUrl($pageArr)); } if (strlen($strParams)) { if (strpos($strUrl, '?') !== false) { $strUrl .= '&' . $strParams; } else { $strUrl .= '?' . $strParams; } } } if ($this->arrTopTenTags[$idx]['tag_name'] == str_replace('|slash|', '/', \Input::get('tag'))) { $this->arrTopTenTags[$idx]['tag_class'] .= ' active'; } $this->arrTopTenTags[$idx]['tag_url'] = $strUrl; } $ts = deserialize(\Input::cookie('tagcloud_states'), true); // $ts = $this->Session->get('tagcloud_states'); $this->Template->expandedTopTen = strlen($ts[$this->id]['topten']) ? strcmp($ts[$this->id]['topten'], 'none') == 0 ? 0 : 1 : $this->tag_topten_expanded; $this->Template->expandedAll = strlen($ts[$this->id]['alltags']) ? strcmp($ts[$this->id]['alltags'], 'none') == 0 ? 0 : 1 : $this->tag_all_expanded; $this->Template->expandedRelated = strlen($ts[$this->id]['related']) ? strcmp($ts[$this->id]['related'], 'none') == 0 ? 0 : 1 : 1; $this->Template->toptentags = $this->arrTopTenTags; } } }
function contentTag($name, $content, $options = array()) { return "<{$name}" . TagHelper::_tag_options($options) . '>' . htmlspecialchars($content, ENT_QUOTES) . "</{$name}>"; }
public static function feed_link_tag($url, $type = 'rss', $options = array()) { $options = array_merge(array('title' => strtoupper($type)), $options); unset($options['href'], $options['rel'], $options['type']); return TagHelper::tag('link', array_merge(array('rel' => 'alternate', 'href' => $url, 'type' => self::$feed_types[$type]), $options)); }
function javascript_tag($js) { return TagHelper::content_tag('script', $js, array('type' => 'text/javascript')); }
/** * Returns a button input tag that will submit form using XMLHttpRequest in * the background instead of regular reloading POST arrangement. The '$opt' * argument is the same as in 'form_remote_tag()'. * * @param type <description> * @param type <description> * @param type <description> * * @return type <description> */ function submit_to_remote($name, $value, $options = array()) { if (!isset($options['with'])) { $options['with'] = 'Form.serialize(this.form)'; } if (!isset($options['html'])) { $options['html'] = array(); } $options['html']['type'] = 'button'; $options['html']['onclick'] = PrototypeHelper::remote_function($options) . '; return false;'; $options['html']['name'] = $name; $options['html']['value'] = $value; return TagHelper::tag('input', $options['html']); }
/** * Returns a string with a div containing all the error messages for the object located as an instance variable by the name * of <tt>object_name</tt>. This div can be tailored by the following options: * * * <tt>header_tag</tt> - Used for the header of the error div (default: h2) * * <tt>id</tt> - The id of the error div (default: errorExplanation) * * <tt>class</tt> - The class of the error div (default: errorExplanation) * * NOTE: This is a pre-packaged presentation of the errors with embedded strings and a certain HTML structure. If what * you need is significantly different from the default presentation, it makes plenty of sense to access the $object->getErrors() * instance yourself and set it up. View the source of this method to see how easy it is. */ function error_messages_for($object_name, $options = array()) { $object =& $this->_controller->{$object_name}; if ($object->hasErrors()) { $error_list = '<ul>'; foreach ($object->getFullErrorMessages() as $field => $errors) { foreach ($errors as $error) { $error_list .= TagHelper::content_tag('li', $error); } } $error_list .= '</ul>'; return TagHelper::content_tag('div', TagHelper::content_tag(!empty($options['header_tag']) ? $options['header_tag'] : 'h2', Ak::t('%number_of_errors %errors prohibited this %object_name from being saved', array('%number_of_errors' => $object->countErrors(), '%errors' => Ak::t(AkInflector::conditionalPlural($object->countErrors(), 'error'), array(), 'helpers/active_record'), '%object_name' => Ak::t(AkInflector::humanize($object->getModelName()), array(), 'helpers/active_record')), 'helpers/active_record')) . TagHelper::content_tag('p', Ak::t('There were problems with the following fields:', array(), 'helpers/active_record')) . $error_list, array('id' => !empty($options['id']) ? $options['id'] : 'errorExplanation', 'class' => !empty($options['class']) ? $options['class'] : 'errorExplanation')); } }
function test_string_to_array() { $array = TagHelper::string_to_array('id="anId" class=\'aClass\''); $this->assertEqual(array('id' => 'anId', 'class' => 'aClass'), $array); }
/** * Displays an image which when clicked will submit the form. * * <tt>source</tt> is passed to AssetTagHelper#image_path */ function image_submit_tag($source, $options = array()) { return TagHelper::tag('input', array_merge(array('type' => 'image', 'src' => $this->_controller->asset_tag_helper->image_path($source)), $options)); }
/** * Returns a JavaScript tag with the +content+ inside. Example: * javascript_tag("alert('All is good')") => <script type="text/javascript">alert('All is good')</script> */ function javascript_tag($content) { return TagHelper::content_tag("script", JavascriptHelper::javascript_cdata_section($content), array('type' => 'text/javascript')); }
public function test_for_not_double_escaping_entities() { $this->assertEqual(TagHelper::escape_once("1 > 2 & 3"), "1 > 2 & 3"); }
public static function pagination($collection, $options = array()) { $pagination_options = array('class' => 'pagination', 'previous_label' => '« Previous', 'next_label' => 'Next »', 'param_name' => 'page'); $pagination_options = array_merge($pagination_options, $options); if (!isset($collection->total_count) && isset($collection->page) && isset($collection->per_page)) { throw new NimbleException('You must pass a paginated result set to the pagination helper'); } $url = $_SERVER['REQUEST_URI']; $total_buttons = ceil($collection->total_count / $collection->per_page) + 1; if ($total_buttons == 1) { return ''; } if (isset($_GET[$pagination_options['param_name']]) && !empty($_GET[$pagination_options['param_name']])) { $url = str_replace($pagination_options['param_name'] . '=' . (string) $_GET[$pagination_options['param_name']], $pagination_options['param_name'] . '={page}', $url); } else { if (strpos('?', $url) === false) { $url = $url . '?page={page}'; } else { $url = $url . '&page={page}'; } } //Build List $out = array(); if ((int) $collection->page != 1) { $prev_page = $collection->page <= 1 ? 1 : $collection->page - 1; $link = TagHelper::content_tag('a', $pagination_options['previous_label'], array('href' => str_replace('{page}', $prev_page, $url))); $out[] = TagHelper::content_tag('li', $link); } for ($i = 1; $i < $total_buttons; $i++) { $myurl = str_replace('{page}', $i, $url); $link = (int) $collection->page == $i ? $i : TagHelper::content_tag('a', $i, array('href' => $myurl)); $out[] = TagHelper::content_tag('li', $link); } if ((int) $collection->page != $total_buttons - 1) { $next_page = (int) $collection->page >= (int) $total_buttons ? $total_buttons : (int) $collection->page + 1; $link = TagHelper::content_tag('a', $pagination_options['next_label'], array('href' => str_replace('{page}', $next_page, $url))); $out[] = TagHelper::content_tag('li', $link); } return TagHelper::content_tag('ul', implode('', $out), array('class' => $pagination_options['class'])); }
function linkTo(&$controller, $text, $href, $html_options = null) { $href = urlHelper::urlFor($controller, $href); if (!$href) { return $text ? $text : ''; } if (isset($html_options['confirm'])) { $confirm = $html_options['confirm']; $confirm = htmlspecialchars($confirm, ENT_NOQUOTES); $confirm = str_replace("'", "\\'", $confirm); $confirm = str_replace('"', '"', $confirm); $html_options['onclick'] = "return confirm('{$confirm}');"; unset($html_options['confirm']); } if (isset($html_options['referer']) && $html_options['referer']) { $href .= (preg_match('|\\?|', $href) ? '&' : '?') . '_referer=' . urlencode($_SERVER['REQUEST_URI']); } $html_options['href'] = $href; return TagHelper::contentTag('a', $text, $html_options); }
public function testAutoUrl() { $url = 'http://githu.com/fgrehm/pearfarm'; $out = autolink('bar ' . $url . ' foo'); $this->assertEquals($out, 'bar ' . TagHelper::content_tag('a', $url, array('href' => $url, 'title' => $url, 'target' => '_blank')) . ' foo'); }
/** * Use this function to automatically handle flash messages. * * Examples: * * <?=$text_helper->flash();?> * //will handle all flash messages automatically * * <?=$text_helper->flash(null,array('secconds_to_close'=>5));?> * //will handle all flash messages automatically and will close in 5 secconds. NOTE. you need to include javascript dependencies for using interactive options * */ function flash($message = null, $options = array(), $html_options = array()) { if (empty($message) && empty($this->_controller->flash)) { return ''; } $options = empty($options) ? empty($this->_controller->flash_options) ? array() : $this->_controller->flash_options : $options; $default_options = array('close_button' => false, 'seconds_to_close' => false, 'animate' => true, 'effects' => array()); $options = array_merge($default_options, $options); if (empty($options['seconds_to_close']) && isset($options['close_in'])) { $options['seconds_to_close'] = strtotime($options['close_in']) - time(); } $options['effects'] = empty($options['effects']) ? array() : $options['effects']; $effects = !empty($options['effect']) && is_string($options['effect']) ? array_merge(array($options['effect']), $options['effects']) : $options['effects']; $options['seconds_to_close'] = empty($options['seconds_to_close']) && !empty($options['seconds']) ? $options['seconds'] : $options['seconds_to_close']; $html_options = array_merge(array('id' => 'flash', 'class' => 'flash'), $html_options); $close_button = !empty($options['close_button']) ? $this->_controller->asset_tag_helper->image_tag($options['close_button']) . ' ' : ''; if (empty($message)) { $message = ''; foreach ($this->_controller->flash as $k => $v) { if (is_string($v) && !empty($v)) { $message .= TagHelper::content_tag('div', $v, array('id' => 'flash_' . $k)); } } } elseif (is_array($message)) { $message = ''; foreach ($this->_controller->flash as $k => $v) { if (is_string($v) && !empty($v)) { $message .= TagHelper::content_tag('div', $v, array('id' => 'flash_' . $k)); } } } if (empty($message)) { return ''; } $flash_message = TagHelper::content_tag('div', $close_button . $message, $html_options); if ($options['animate']) { $animation_effects = ''; if (!empty($effects)) { foreach ($effects as $name => $effect_options) { if (is_numeric($name)) { $animation_effects .= $this->_controller->scriptaculous_helper->visual_effect($effect_options, $html_options['id']); } else { $animation_effects .= $this->_controller->scriptaculous_helper->visual_effect($name, $html_options['id'], $effect_options); } } } if (!empty($options['seconds_to_close'])) { $animation_effects .= 'setTimeout(\'new Effect.Fade($("' . $html_options['id'] . '"));\', ' . $options['seconds_to_close'] * 1000 . ');'; } if (!empty($animation_effects)) { $flash_message .= $this->_controller->javascript_helper->javascript_tag($animation_effects); } } elseif (!empty($options['seconds_to_close'])) { $flash_message .= $this->_controller->javascript_helper->javascript_tag('setTimeout(\'$("' . $html_options['id'] . '").hide();\', ' . $options['seconds_to_close'] * 1000 . ');'); } return $flash_message; }
function to_content_tag($tag_name, $options = array()) { return TagHelper::content_tag($tag_name, $this->getValue(), $options); }
function _tag_options($options) { $formated_options = array(); foreach ($options as $key=>$value){ if(empty($value) && !is_string($value)){ continue; } if(!is_numeric($key) && !is_array($value) && !is_object($value)){ $formated_options[$key] = $key.'="'.TagHelper::escape_once($value).'"'; } } ksort($formated_options); return empty($formated_options) ? '' : ' '.join(' ',$formated_options); }
/** * @deprecated */ function _auto_complete_stylesheet() { return TagHelper::content_tag('style', <<<EOT div.auto_complete { width: 350px; background: #fff; } div.auto_complete ul { border:1px solid #888; margin:0; padding:0; width:100%; list-style-type:none; } div.auto_complete ul li { margin:0; padding:3px; } div.auto_complete ul li.selected { background-color: #ffb; } div.auto_complete ul strong.highlight { color: #800; margin:0; padding:0; } EOT ); }