Exemple #1
0
 /**
  * Create a text field with Autocomplete.
  *
  * Creates an autocomplete field with the given ID and options.
  *
  * options['with'] defaults to "Form.Element.serialize('$field')",
  * but can be any valid javascript expression defining the additional fields.
  *
  * @param string $field DOM ID of field to observe
  * @param string $url URL for the autocomplete action
  * @param array $options Ajax options
  * @return string Ajax script
  * @link http://book.cakephp.org/1.3/en/The-Manual/Core-Helpers/AJAX.html#autoComplete
  */
 function autoComplete($field, $url = "", $options = array())
 {
     $var = '';
     if (isset($options['var'])) {
         $var = 'var ' . $options['var'] . ' = ';
         unset($options['var']);
     }
     if (!isset($options['id'])) {
         $options['id'] = Inflector::camelize(str_replace(".", "_", $field));
     }
     $divOptions = array('id' => $options['id'] . "_autoComplete", 'class' => isset($options['class']) ? $options['class'] : 'auto_complete');
     if (isset($options['div_id'])) {
         $divOptions['id'] = $options['div_id'];
         unset($options['div_id']);
     }
     $htmlOptions = $this->__getHtmlOptions($options);
     $htmlOptions['autocomplete'] = "off";
     foreach ($this->autoCompleteOptions as $opt) {
         unset($htmlOptions[$opt]);
     }
     if (isset($options['tokens'])) {
         if (is_array($options['tokens'])) {
             $options['tokens'] = $this->Javascript->object($options['tokens']);
         } else {
             $options['tokens'] = '"' . $options['tokens'] . '"';
         }
     }
     $options = $this->_optionsToString($options, array('paramName', 'indicator'));
     $options = $this->_buildOptions($options, $this->autoCompleteOptions);
     $text = $this->Form->text($field, $htmlOptions);
     $div = $this->Html->div(null, '', $divOptions);
     $script = "{$var}new Ajax.Autocompleter('{$htmlOptions['id']}', '{$divOptions['id']}', '";
     $script .= $this->Html->url($url) . "', {$options});";
     return "{$text}\n{$div}\n" . $this->Javascript->codeBlock($script);
 }
 /**
  * (non-PHPdoc)
  * @see GalleryHelper::get_markup()
  */
 public function get_markup()
 {
     if (empty($this->images)) {
         return '';
     }
     if (empty($this->unid)) {
         $this->calculate_unique();
     }
     $this->load_assets();
     $list = array();
     foreach ($this->images as $k => $image) {
         $list[] = $this->render_element($k);
     }
     $first_image = array_shift($list);
     /*$src = '/images/ajax-loader.gif';
     		if(file_exists(get_stylesheet_directory().$src))
     			$src = get_stylesheet_directory_uri().$src;
     		
     		if(file_exists(get_template_directory().$src))
     			$src = get_template_directory_uri().$src;
     		
     		$first_image = HtmlHelper::image($src, array('id'=>'loading-gif'));*/
     $script = HtmlHelper::script(json_encode($list), array('id' => 'script_' . $this->unid));
     $defaults = array('id' => $this->unid, 'class' => 'cycle-slideshow', 'data-cycle-loader' => 'true', 'data-cycle-progressive' => '#script_' . $this->unid);
     return HtmlHelper::div($first_image . $script, wp_parse_args($this->cycle_attrs, $defaults));
 }
 public function get_markup()
 {
     $slides = '';
     $indicators = '';
     $slide_sub = new SubstitutionTemplate();
     $slide_sub->set_tpl($this->tpl_slide);
     foreach ($this->images as $k => $v) {
         $active = $k == 0 ? 'active' : '';
         $caption = '';
         $style = 'width: 100%; height: 100%; background: url(\'' . $this->get_image_src($k) . '\') no-repeat center center scroll transparent;';
         if ($this->get_image_title($k)) {
             $caption .= HtmlHelper::standard_tag('h2', $this->get_image_title($k));
         }
         if ($this->get_image_caption($k)) {
             $caption .= HtmlHelper::paragraph($this->get_image_caption($k));
         }
         $image = $slide_sub->set_markup('class', implode(' ', array('item', $active)))->set_markup('image', HtmlHelper::div('', array('alt' => $this->get_image_alt($k), 'style' => $style)))->set_markup('caption', HtmlHelper::div($caption, array('class' => 'carousel-caption')))->replace_markup();
         $indicator = HtmlHelper::list_item($inner_html, array('data-target' => '#' . $this->unid, 'data-slide-to' => $k, 'class' => $active));
         $slides .= $image . "\n";
         $indicators .= $indicator . "\n";
     }
     $subs = new SubstitutionTemplate();
     return $subs->set_tpl($this->tpl)->set_markup('id', $this->unid)->set_markup('container_classes', $this->container_classes)->set_markup('indicators', HtmlHelper::ordered_list($indicators, array('class' => 'carousel-indicators')))->set_markup('slides', HtmlHelper::div($slides, array('class' => 'carousel-inner')))->replace_markup();
 }
 /**
  * Prints the HTML markup for the metabox
  */
 public static function metabox_html($post)
 {
     if (is_null($post)) {
         global $post;
     }
     $template = self::get_template($post);
     if (count(self::$media_list)) {
         $is_first = true;
         foreach (self::$media_list as $k => $elem) {
             $template_checker = new TemplateChecker($elem['include'], $elem['exclude']);
             if (!$template_checker->check($template)) {
                 continue;
             }
             $name = self::META_KEY_NAME . '-' . $elem['id'];
             wp_nonce_field(__FILE__, $name . '_nonce');
             $value = get_post_meta($post->ID, $name, true);
             // main edit button
             $edit_button = HtmlHelper::anchor('javascript:;', HtmlHelper::span('', array('class' => 'wp-media-buttons-icon')) . __('Manage Media', 'wtu_framework'), array('id' => 'wtu-media-manager-button-' . $elem['id'], 'class' => 'button media-manager-button', 'data-target' => '#wtu-media-manager-element-' . $elem['id'], 'data-target-undo' => '#wtu-media-manager-undo-' . $elem['id'], 'data-target-delete' => '#wtu-media-manager-delete-' . $elem['id'], 'data-counter' => '#wtu-media-manager-counter-' . $elem['id'], 'data-frame-id' => 'wtu-media-manager-' . $elem['id'], 'data-title' => sprintf(__('Manage Media for %s', 'wtu_framework'), $elem['label']), 'data-button-label' => sprintf(__('Add selected media to %s set', 'wtu_framework'), $elem['label']), 'data-multiple' => 'true', 'data-elem-id' => $elem['id'], 'data-shortcode' => $elem['shortcode'], 'title' => sprintf(__('Manage Media for %s', 'wtu_framework'), $elem['label'])));
             // input to store temp values, use text instead of hidden to debug
             $input = HtmlHelper::input($name, 'hidden', array('id' => 'wtu-media-manager-element-' . $elem['id'], 'value' => $value));
             // Counter
             $number = 0;
             if (isset($value) && $value != '') {
                 $number = count(explode(',', $value));
             }
             $counter = ' ' . HtmlHelper::span($number > 0 ? sprintf(_n('1 element', '%s elements', $number, 'wtu_framework'), $number) : __('Empty', 'wtu_framework'), array('id' => 'wtu-media-manager-counter-' . $elem['id'], 'data-label-no-images' => __('Empty', 'wtu_framework'), 'data-label-one-image' => __('1 element', 'wtu_framework'), 'data-label-more-images' => __('%s elements', 'wtu_framework')));
             // delete button
             $delete = HtmlHelper::anchor('javascript:;', __('Delete', 'wtu_framework'), array('id' => 'wtu-media-manager-delete-' . $elem['id'], 'style' => $value ? '' : 'display:none;', 'class' => 'delete-media-manager-gallery submitdelete', 'data-counter' => '#wtu-media-manager-counter-' . $elem['id'], 'data-gallery' => $elem['id'], 'data-target' => '#wtu-media-manager-element-' . $elem['id'], 'data-target-undo' => '#wtu-media-manager-undo-' . $elem['id'], 'data-target-origin' => '#wtu-media-manager-button-' . $elem['id'], 'title' => __('Delete Media Set', 'wtu_framework')));
             // undo button
             $undo = HtmlHelper::anchor('javascript:;', __('Undo', 'wtu_framework'), array('id' => 'wtu-media-manager-undo-' . $elem['id'], 'style' => 'display:none;', 'class' => 'undo-media-manager-gallery', 'data-gallery' => $elem['id'], 'data-target' => '#wtu-media-manager-element-' . $elem['id'], 'data-elem-id' => $elem['id'], 'data-target-origin' => '#wtu-media-manager-button-' . $elem['id'], 'data-target-delete' => '#wtu-media-manager-delete-' . $elem['id'], 'data-counter' => '#wtu-media-manager-counter-' . $elem['id'], 'title' => __('Restore Media Set', 'wtu_framework')));
             $title = HtmlHelper::paragraph(HtmlHelper::strong($elem['label']));
             $inner_html = '';
             if (!$is_first) {
                 $inner_html .= HtmlHelper::br();
             }
             $inner_html .= '<table class="widefat"><thead>';
             $inner_html .= '<td width="33%">' . $title . '</td>';
             $inner_html .= '<td width="33%">&nbsp;</td>';
             $inner_html .= '<td width="33%">' . $edit_button . '</td></thead>';
             $inner_html .= '<tbody><tr style="line-height: 25px;"><td class="submitbox">' . $delete . $undo . '</td>';
             $inner_html .= '<td>&nbsp;</td>';
             $inner_html .= '<td>' . $counter . '</td>';
             $inner_html .= '</tr></tbody></table>';
             $inner_html .= $input;
             echo HtmlHelper::div($inner_html, array('class' => ''));
             $is_first = false;
         }
     }
     //var_dump($value);
 }
 /**
  * Create a column element.
  * 
  * Use example:
  * <code>
  * <?php
  *   // Tell to create a 6 size column with offset of 1.
  *   $this->Bs->col([GA_6, GA_OF1]);
  * ?>
  * </code>
  *
  * @param array $classes Size and offset classes.
  * @param array $options Options of the div element
  * @return string DIV tag element 
  */
 public function col(array $classes, array $options = [])
 {
     $validClasses = [GA_1, GA_2, GA_3, GA_4, GA_5, GA_6, GA_7, GA_8, GA_9, GA_10, GA_11, GA_12, GA_OF1, GA_OF2, GA_OF3, GA_OF4, GA_OF5, GA_OF6, GA_OF7, GA_OF8, GA_OF9, GA_OF10, GA_OF11, GA_OF12];
     $class = array_intersect($classes, $validClasses);
     $class = implode(' ', $class);
     if (isset($options['class'])) {
         $class .= ' ' . $options['class'];
         unset($options['class']);
     }
     return parent::div($class, null, $options) . PHP_EOL;
 }
 /**
  * Create a <div class="col"> element.
  *
  * Differents layouts with options.
  *
  * ### Construction
  *
  * $this->Bs->col('xs3 of1 ph9', 'md3');
  *
  * It means : - For XS layout, a column size of 3, offset of 1 and push of 9.
  *			  - For MD layout, a column size of 3.
  *
  * You can give all parameters you want before $attributes. The rule of params is :
  *
  * 'LAYOUT+SIZE OPTIONS+SIZE'
  *
  * LAYOUT -> not obligatory for the first param ('xs' by default) .
  * SIZE -> size of the column in a grid of 12 columns.
  * OPTIONS -> Not obligatory. Offset, push or pull. Called like this : 'of', 'ph' or 'pl'.
  * SIZE -> size of the option.
  *
  *
  * ### Attributes
  *
  * Same options that HtmlHelper::div();
  *
  * @return string DIV tag element
  */
 public function col()
 {
     $class = '';
     $devices = array();
     $attributes = array();
     $args = func_get_args();
     foreach ($args as $arg) {
         if (!is_array($arg)) {
             $devices[] = $arg;
         } else {
             $attributes = $arg;
         }
     }
     $arrayDevice = array('xs', 'sm', 'md', 'lg');
     $arrayOptions = array('of', 'ph', 'pl');
     foreach ($devices as $device) {
         $ecran = null;
         $taille = null;
         $opt = null;
         $replace = array('(', ')', '-', '_', '/', '\\', ';', ',', ':', ' ');
         $device = str_replace($replace, '.', $device);
         $device = explode('.', $device);
         // Sould define the device in first
         foreach ($device as $elem) {
             if (!$ecran) {
                 $nom = substr($elem, 0, 2);
                 if (in_array($nom, $arrayDevice)) {
                     $ecran = $nom;
                     $taille = substr($elem, 2);
                 }
             } else {
                 if ($opt) {
                     $opt .= ' ' . $this->__optCol($elem, $ecran);
                 } else {
                     $opt = $this->__optCol($elem, $ecran);
                 }
             }
         }
         if (isset($ecran) && $taille) {
             if ($opt) {
                 $class .= 'col-' . $ecran . '-' . $taille . ' ' . $opt . ' ';
             } else {
                 $class .= 'col-' . $ecran . '-' . $taille . ' ';
             }
         }
     }
     $class = substr($class, 0, -1);
     if (isset($attributes['class'])) {
         $class .= ' ' . $attributes['class'];
     }
     $out = parent::div($class, null, $attributes);
     return $out;
 }