function get_menu_option($description, $url, $options = array()) { if (!empty($url['action']) && ($url['action'] == $this->C->params['action'] || $url['action'] == @$this->C->tab)) { $options['class'] = 'active'; } //<li><a href="#"><span>Contribute</span></a></li> return AkTagHelper::content_tag('li', $this->C->url_helper->link_to(AkTagHelper::content_tag('span', $description), $url, $options)); }
static 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 . '="' . AkTagHelper::escape_once($value) . '"'; } } ksort($formated_options); return empty($formated_options) ? '' : ' ' . join(' ', $formated_options); }
public 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->ak_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']})"); } if (!empty($link_options['link_text'])) { $link_text = $link_options['link_text']; unset($link_options['link_text']); } else { $link_text = $this->_controller->t(AkInflector::humanize($column)); } return AkTagHelper::content_tag('a', $link_text, $link_options); }
/** * Returns a menu for all or several actions in all or several controllers. * * Let +menu_options+ defaults and this will generate a menu with all actions in all controllers. * Set +menu_options+ to an array with keys as controller name and values as actions names. * * <?php echo $menu_helper->menu_for_controllers(array('advertiser' => array('buy', 'partial_in_template'))); ?> * will generate something like : * <div id="menu"> * <ul> * <li> * <h2><a href="/advertiser">Advertiser</a></h2> * <ul> * <li><a href="/advertiser/buy">Buy</a></li> * <li><a href="/advertiser/partial_in_template">Partial in template</a></li> * </ul> * </li> * </ul> * </div> * * +div_menu_id+: the id of the main div (default is "menu") * +current_class+: the class name of the current controller or the current action (default is "current") * +title_tag+: the tag that will contain the controller name link (default is "h2"). If it's empty, it won't be present */ public function menu_for_controllers($menu_options = array(), $div_menu_id = 'menu', $current_class = 'current', $title_tag = 'h2') { $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)) { $class = $current_controller_name == $controller_name ? array('class' => $current_class) : array(); $href = array('href' => $this->_controller->urlFor(array('controller' => $controller))); if (empty($title_tag)) { $_title_tag = 'a'; $content = $controller_human_name; $options = array_merge($class, $href); } else { $content = AkTagHelper::content_tag('a', $controller_human_name, $href); $options = $class; $_title_tag = $title_tag; } $menu_header = AkTagHelper::content_tag($_title_tag, $content, $options); $submenu = ''; foreach ((array) $actions as $action) { if ($action[0] == '_') { continue; } $submenu .= AkTagHelper::content_tag('li', AkTagHelper::content_tag('a', AkInflector::humanize($action), array('href' => $this->_controller->urlFor(array('controller' => $controller, 'action' => $action)))), $current_controller_name == $controller_name && $current_action_name == $action ? array('class' => $current_class) : array()); } $menu .= !empty($submenu) ? AkTagHelper::content_tag('ul', AkTagHelper::content_tag('li', $menu_header . AkTagHelper::content_tag('ul', $submenu))) : ''; } } } return AkTagHelper::content_tag('div', $menu, array('id' => $div_menu_id)); }
/** * 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" */ public function image_tag($source, $options = array()) { if (!empty($options['size'])) { list($options['width'], $options['height']) = preg_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 AkTagHelper::tag('img', $options); }
/** * 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. */ public 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 .= AkTagHelper::content_tag('li', $error); } } $error_list .= '</ul>'; return AkTagHelper::content_tag('div', AkTagHelper::content_tag(!empty($options['header_tag']) ? $options['header_tag'] : 'h2', $this->t('%number_of_errors %errors prohibited this %object_name from being saved', array('%number_of_errors' => $object->countErrors(), '%errors' => $this->t(AkInflector::conditionalPlural($object->countErrors(), 'error')), '%object_name' => $this->t(AkInflector::humanize($object->getModelName()))))) . AkTagHelper::content_tag('p', $this->t('There were problems with the following fields:')) . $error_list, array('id' => !empty($options['id']) ? $options['id'] : 'errorExplanation', 'class' => !empty($options['class']) ? $options['class'] : 'errorExplanation')); } }
/** * Creates a label field * * ==== Options * * Creates standard HTML attributes for the tag. * * ==== Examples * label_tag 'name' * # => <label for="name">Name</label> * * label_tag 'name', 'Your name' * # => <label for="name">Your Name</label> * * label_tag 'name', nil, :class => 'small_label' * # => <label for="name" class="small_label">Name</label> */ static function label_tag($name, $text = null, $options = array()) { return AkTagHelper::content_tag('label', empty($text) ? AkInflector::humanize($name) : $text, array_merge($options, array('for' => self::sanitize_to_id($name)))); }
/** * Returns a JavaScript tag with the +content+ inside. Example: * javascript_tag("alert('All is good')") => <script type="text/javascript">alert('All is good')</script> */ static function javascript_tag($content) { return AkTagHelper::content_tag("script", AkJavascriptHelper::javascript_cdata_section($content), array('type' => 'text/javascript')); }
/** * 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_helper->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_helper->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: * $url_helper->mail_to("*****@*****.**", "My email", array('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> */ public 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') { $html = AkTagHelper::content_tag('a', AkTextHelper::html_escape($name, null), array_merge($html_options, array('href' => 'mailto:' . $email_address . $extras))); $html = AkJavascriptHelper::escape_javascript($html); $tmp = "document.write('{$html}');"; $len = strlen($tmp); for ($i = 0; $i < $len; $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 = ''; $length = strlen($email_address); for ($i = 0; $i < $length; $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 AkTagHelper::content_tag('a', $name, array_merge($html_options, array('href' => 'mailto:' . $encoded_email_address . $extras))); } else { return AkTagHelper::content_tag('a', $name, array_merge($html_options, array('href' => 'mailto:' . $email_address . $extras))); } }
/** * 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 * */ public 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->ak_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 .= AkTagHelper::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 .= AkTagHelper::content_tag('div', $v, array('id' => 'flash_' . $k)); } } } if (empty($message)) { return ''; } $flash_message = '<!--CACHE-SKIP-START-->' . AkTagHelper::content_tag('div', $close_button . $message, $html_options) . '<!--CACHE-SKIP-END-->'; if ($options['animate']) { $animation_effects = ''; if (!empty($effects)) { foreach ($effects as $name => $effect_options) { if (is_numeric($name)) { $animation_effects .= $this->_controller->ak_scriptaculous_helper->visual_effect($effect_options, $html_options['id']); } else { $animation_effects .= $this->_controller->ak_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->ak_javascript_helper->javascript_tag($animation_effects); } } elseif (!empty($options['seconds_to_close'])) { $flash_message .= $this->_controller->ak_javascript_helper->javascript_tag('setTimeout(\'$("' . $html_options['id'] . '").hide();\', ' . $options['seconds_to_close'] * 1000 . ');'); } return $flash_message; }
public function to_content_tag($tag_name, $options = array()) { return AkTagHelper::content_tag($tag_name, $this->getValue(), $options); }
/** * @deprecated */ public function _auto_complete_stylesheet() { return AkTagHelper::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 ); }
public function to_time_zone_select_tag($priority_zones = array(), $options = array(), $html_options = array()) { $this->add_default_name_and_id($html_options); return AkTagHelper::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); }