コード例 #1
0
ファイル: ak_asset_tag_helper.php プロジェクト: bermi/akelos
 /**
  * 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);
 }
コード例 #2
0
ファイル: ak_form_tag_helper.php プロジェクト: bermi/akelos
 /**
  * Displays an image which when clicked will submit the form.
  *
  * <tt>source</tt> is passed to AssetTagHelper#image_path
  */
 public function image_submit_tag($source, $options = array())
 {
     return AkTagHelper::tag('input', array_merge(array('type' => 'image', 'src' => $this->_controller->ak_asset_tag_helper->image_path($source)), $options));
 }
コード例 #3
0
ファイル: ak_url_helper.php プロジェクト: bermi/akelos
 /**
  * Generates a form containing a sole button that submits to the
  * URL given by _$options_.  Use this method instead of +link_to+
  * for actions that do not have the safe HTTP GET semantics
  * implied by using a hypertext link.
  *
  * The parameters are the same as for +link_to+.  Any _html_options_
  * that you pass will be applied to the inner +input+ element.
  * In particular, pass
  * 
  *   'disabled' => true/false
  *
  * as part of _html_options_ to control whether the button is
  * disabled.  The generated form element is given the class
  * 'button-to', to which you can attach CSS styles for display
  * purposes.
  *
  * Example 1:
  *
  *   // inside of controller for "feeds"
  *   $url_helper->button_to('Edit', array('action' => 'edit', 'id' => 3));
  *
  * Generates the following HTML (sans formatting):
  *
  *   <form method="post" action="/feeds/edit/3" class="button-to">
  *     <div><input type="submit" value="Edit"  /></div>
  *   </form>
  *
  * Example 2:
  *
  *   $url_helper->button_to('Destroy', array('action' => 'destroy', 'id' => 3 , 'confirm' => 'Are you sure?'));
  *
  * Generates the following HTML (sans formatting):
  *
  *   <form method="post" action="/feeds/destroy/3" class="button-to">
  *     <div><input onclick="return confirm('Are you sure?');" value="Destroy" type="submit" /></div>
  *   </form>
  *
  * Note: This method generates HTML code that represents a form.
  * Forms are "block" content, which means that you should not try to
  * insert them into your HTML where only inline content is expected.
  * For example, you can legally insert a form inside of a <div> or
  * <td> element or in between <p> elements, but not in the middle of
  * a run of text, nor can you place a form within another form.
  * (Bottom line: Always validate your HTML before going public.)
  */
 public function button_to($name, $options = array(), $html_options = array())
 {
     $html_options = $this->_convert_boolean_attributes($html_options, 'disabled');
     if (!empty($html_options['confirm'])) {
         $html_options['onclick'] = 'return ' . $this->_confirm_javascript_function($html_options['confirm']) . ';';
         unset($html_options['confirm']);
     }
     $url = is_string($options) ? $options : $this->url_for($options);
     $name = !empty($name) ? $name : (is_string($options) ? $options : AkTagHelper::escape_once($this->url_for($options)));
     $html_options = array_merge($html_options, array('type' => 'submit', 'value' => $name));
     return '<form method="post" action="' . $url . '" class="button-to"><div>' . AkTagHelper::tag('input', $html_options) . '</div></form>';
 }
コード例 #4
0
ファイル: ak_javascript_helper.php プロジェクト: bermi/akelos
 /**
  * Returns a link that'll trigger a JavaScript +function+ using the 
  * onclick handler.
  *
  * Examples:
  *   $javascript_helper->button_to_function("Greeting", "alert('Hello world!')");
  *   $javascript_helper->button_to_function("Delete", "if confirm('Really?'){ do_delete(); }"));
  */
 static function button_to_function($name, $function, $html_options = array())
 {
     $default_html_options = array('type' => 'button', 'value' => $name, 'onclick' => (!empty($html_options['onclick']) ? "{$html_options['onclick']}; " : "") . "{$function};");
     $html_options = array_merge($default_html_options, $html_options);
     return AkTagHelper::tag('input', $html_options);
 }
コード例 #5
0
ファイル: ak_form_helper.php プロジェクト: bermi/akelos
 public function to_check_box_tag($options = array(), $checked_value = '1', $unchecked_value = '0')
 {
     $options['type'] = 'checkbox';
     $options['value'] = $checked_value;
     $value = $this->getValue();
     if (is_numeric($value)) {
         $checked = $value != 0;
     } elseif (is_string($value)) {
         $checked = $value == $checked_value;
     } else {
         $checked = !empty($value);
     }
     if ($checked || isset($options['checked']) && $options['checked'] == 'checked') {
         $options['checked'] = 'checked';
     } else {
         unset($options['checked']);
     }
     $this->add_default_name_and_id($options);
     return AkTagHelper::tag('input', array('name' => $options['name'], 'type' => 'hidden', 'value' => $unchecked_value)) . AkTagHelper::tag('input', $options);
 }