Exemple #1
0
 /**
  * Helper function for content tags.
  *
  * @param type <description>
  * @param type <description>
  * @param type <description>
  *
  * @return type <description>
  */
 function content_tag($name, $content = '', $options = array())
 {
     if (!$name) {
         return '';
     }
     return '<' . $name . TagHelper::_tag_options($options) . '>' . $content . '</' . $name . '>';
 }
Exemple #2
0
 /**
  * Creates a link tag of the given +name+ using an URL created by the set of +options+. See the valid options in
  * the documentation for ActionController::Base*url_for. It's also possible to pass a string instead of an array of options
  * to get a link tag that just points without consideration. If null is passed as a name, the link itself will become 
  * the name.
  *
  * The html_options has three special features. One for creating javascript confirm alerts where if you pass
  * 'confirm' => 'Are you sure?', the link will be guarded with a JS popup asking that question. 
  * If the user accepts, the link is processed, otherwise not.
  *
  * Another for creating a popup window, which is done by either passing 'popup' with true or the options of the window in 
  * Javascript form.
  *
  * And a third for making the link do a POST request (instead of the regular GET) through a dynamically added form 
  * element that is instantly submitted. Note that if the user has turned off Javascript, the request will fall back on 
  * the GET. So its your responsibility to determine what the action should be once it arrives at the controller. 
  * The POST form is turned on by passing 'post' as true. Note, it's not possible to use POST requests and popup targets 
  * at the same time (an exception will be thrown).
  *
  * Examples:
  *   $url->link_to('Delete this page', array('action' => 'destroy', 'id' => $page->id ), array('confirm' => 'Are you sure?'));
  *   $url->link_to('Help', array('action' => 'help'), array('popup' => true));
  *   $url->link_to('Busy loop', array('action' => 'busy'), array('popup' => ['new_window', 'height=300,width=600']));
  *   $url->link_to('Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true));
  */
 function link_to($name = null, $options = array(), $html_options = array(), $parameters_for_method_reference = null)
 {
     if (!empty($html_options)) {
         $this->convert_options_to_javascript($html_options);
         $tag_options = TagHelper::_tag_options($html_options);
     } else {
         $tag_options = null;
     }
     $url = is_string($options) ? $options : $this->url_for($options, $parameters_for_method_reference);
     $name = empty($name) ? $url : $name;
     return "<a href=\"{$url}\"{$tag_options}>{$name}</a>";
 }
Exemple #3
0
 /**
 *  Returns an HTML block tag of type *name* surrounding the *content*. Add
 * HTML attributes by passing an attributes array to *options*. For attributes
 * with no value like (disabled and readonly), give it a value of true in
 * the *options* array. You can use symbols or strings for the attribute names.
 *
 *   <%= content_tag 'p', 'Hello world!' %>
 *    # => <p>Hello world!</p>
 *   <%= content_tag('div', content_tag('p', "Hello world!"), :class => "strong") %>
 *    # => <div class="strong"><p>Hello world!</p></div>
 *   <%= content_tag("select", options, :multiple => true) %>
 *    # => <select multiple="multiple">...options...</select>
 */
 function content_tag($name, $content, $options = null)
 {
     return '<'.$name.(!empty($options) ? TagHelper::_tag_options($options) : '').'>'.$content.'</'.$name.'>';
 }
Exemple #4
0
 /**
  * Turns all urls into clickable links.  
  * 
  * Example:
  *  <?=$text_helper->auto_link_urls($post->body, array('all', 'target' => '_blank'));?>
  */
 function auto_link_urls($text, $href_options = array())
 {
     $extra_options = TagHelper::_tag_options($href_options);
     $extra_options_array = var_export($extra_options, true);
     return preg_replace_callback(AK_AUTO_LINK_REGEX, create_function('$matched', 'return TextHelper::_replace_url_with_link_callback($matched,' . $extra_options_array . ');'), $text);
 }
Exemple #5
0
 function to_boolean_select_tag($options = array())
 {
     $this->add_default_name_and_id($options);
     return '<select' . TagHelper::_tag_options($options) . '><option value="false"' . ($this->getValue() == false ? ' selected' : '') . '>' . Ak::t('False', array(), 'helpers/form') . '</option><option value="true"' . ($this->getValue() ? ' selected' : '') . '>' . Ak::t('True', array(), 'helpers/form') . '</option></select>';
 }
Exemple #6
0
 function contentTag($name, $content, $options = array())
 {
     return "<{$name}" . TagHelper::_tag_options($options) . '>' . htmlspecialchars($content, ENT_QUOTES) . "</{$name}>";
 }
Exemple #7
0
 /**
  * Turns all urls into clickable links.  
  * 
  * Example:
  *  <?=$text_helper->auto_link_urls($post->body, array('all', 'target' => '_blank'));?>
  */
 function auto_link_urls($text, $href_options = array())
 {
     $extra_options = TagHelper::_tag_options($href_options);
     $links = TextHelper::get_urls_from_text($text);
     $linked_urls = TextHelper::get_linked_urls_from_text($text);
     $urls_to_replace = array_diff(array_keys($links), $linked_urls);
     $find = array();
     $replace = array();
     foreach ($urls_to_replace as $url_to_replace) {
         $find[] = '@' . preg_quote($url_to_replace) . '@';
         $replace[] = '<a href="' . $links[$url_to_replace] . '"' . $extra_options . '>' . $url_to_replace . '</a>';
     }
     return preg_replace($find, $replace, $text);
 }