Exemplo n.º 1
0
 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'>&nbsp;</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;
 }
Exemplo n.º 2
0
 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'));
 }
Exemplo n.º 3
0
 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 &gt;&gt; &quot;HERE&quot;" />');
     $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"]]>');
 }
Exemplo n.º 4
0
 public static function javascript_include_tag($sources)
 {
     $urls = self::expand_asset_sources('javascript', $sources);
     $tags = array();
     foreach ($urls as $url) {
         $tags[] = TagHelper::content_tag('script', '', array('src' => $url, 'type' => 'text/javascript'));
     }
     return implode("\n", $tags);
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
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'));
}
Exemplo n.º 8
0
 /**
  * Creates a text input area.
  *
  * Options:
  * * <tt>'size'</tt> - A string specifying the dimensions of the textarea.
  *     # Outputs <textarea name="body" id="body" cols="25" rows="10"></textarea>
  *     <?= $form->text_area_tag('body', null, array('size'=>'25x10')); ?>
  */
 function text_area_tag($name, $content = null, $options = array())
 {
     if (!empty($options['size'])) {
         list($options['cols'], $options['rows']) = split('x|X| ', trim(str_replace(' ', '', $options['size'])));
         unset($options['size']);
     }
     return TagHelper::content_tag('textarea', $content, array_merge(array('name' => $name, 'id' => $name), $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');
 }
Exemplo n.º 10
0
 /**
  * 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))));
 }
Exemplo n.º 11
0
 /**
  * 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)));
     }
 }
Exemplo n.º 12
0
 /**
  * Returns a JavaScript tag with the '$content' inside.
  * Example:
  *   JsHelper::javascript_tag("alert('All is good')");
  *   => <script type="text/javascript">alert('All is good')</script>
  *
  * @param type <description>
  *
  * @return type <description>
  */
 function javascript_tag($content)
 {
     return TagHelper::content_tag('script', JsHelper::js_cdata_section($content), array('type' => 'text/javascript'));
 }
Exemplo n.º 13
0
 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);
 }
Exemplo n.º 14
0
 /**
  * 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 = "&#109;&#97;&#105;&#108;&#116;&#111;&#58;";
         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)));
     }
 }
Exemplo n.º 15
0
 /**
  * Returns a script include tag per source given as argument. Examples:
  *
  *   $asset_tag_helper->javascript_include_tag ("xmlhr"); # =>
  *     <script type="text/javascript" src="/javascripts/xmlhr.js"></script>
  *
  *   $asset_tag_helper->javascript_include_tag('common.javascript', '/elsewhere/cools'); # =>
  *     <script type="text/javascript" src="/javascripts/common.javascript"></script>
  *     <script type="text/javascript" src="/elsewhere/cools.js"></script>
  *
  *   $asset_tag_helper->javascript_include_tag('defaults'); # =>
  *     <script type="text/javascript" src="/javascripts/prototype.js"></script>
  *     <script type="text/javascript" src="/javascripts/effects.js"></script>
  *     ...
  *     <script type="text/javascript" src="/javascripts/application.js"></script> *see below
  *   
  * If there's an <tt>application.js</tt> file in your <tt>public/javascripts</tt> directory,
  * <tt>$asset_tag_helper->javascript_include_tag('defaults')</tt> will automatically include it. This file
  * facilitates the inclusion of small snippets of JavaScript code, along the lines of
  * <tt>controllers/application.php</tt> and <tt>helpers/application_helper.php</tt>.
  */
 function javascript_include_tag()
 {
     $sources = func_get_args();
     $num_args = func_num_args();
     $options = !empty($sources[$num_args - 1]) && is_array($sources[$num_args - 1]) ? array_pop($sources) : array();
     if (empty($sources) || $sources[0] == 'defaults') {
         $sources = $this->_get_javascript_included_defaults();
     }
     $javascript_include_tags = '';
     foreach ($sources as $source) {
         $source = $this->javascript_path($source);
         $javascript_include_tags .= TagHelper::content_tag('script', '', array_merge($options, array('type' => 'text/javascript', 'src' => $source))) . "\n";
     }
     return $javascript_include_tags;
 }
Exemplo n.º 16
0
 /**
  * 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;
 }
Exemplo n.º 17
0
    /**
       * @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
);
    }
Exemplo n.º 18
0
function javascript_tag($js)
{
    return TagHelper::content_tag('script', $js, array('type' => 'text/javascript'));
}
Exemplo n.º 19
0
 /**
  * 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'));
     }
 }
Exemplo n.º 20
0
 function test_content_tag()
 {
     $foo = TagHelper::content_tag('a', '#', array('href' => '#'));
     $this->assertEqual('<a href="#">#</a>', $foo);
 }
Exemplo n.º 21
0
 public static function pagination($collection, $options = array())
 {
     $pagination_options = array('class' => 'pagination', 'previous_label' => '&laquo; Previous', 'next_label' => 'Next &raquo;', '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']));
 }
Exemplo n.º 22
0
 /**
 * 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'));
 }
Exemplo n.º 23
0
 /**
  * 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;
 }
Exemplo n.º 24
0
 function to_content_tag($tag_name, $options = array())
 {
     return TagHelper::content_tag($tag_name, $this->getValue(), $options);
 }