コード例 #1
0
ファイル: select.php プロジェクト: nooku/nooku-framework
 /**
  * Generates an HTML select list
  *
  * @param   array|ObjectConfig     $config An optional array with configuration options
  * @return  string  Html
  */
 public function optionlist($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('options' => array(), 'name' => 'id', 'selected' => null, 'disabled' => null, 'translate' => false, 'attribs' => array('size' => 1)));
     $html = array();
     $html[] = '<select name="' . $config->name . '" ' . $this->buildAttributes($config->attribs) . '>';
     foreach ($config->options as $group => $options) {
         if (is_numeric($group)) {
             $options = array($options);
         } else {
             $html[] = '<optgroup label="' . StringEscaper::attr($group) . '">';
         }
         foreach ($options as $option) {
             $value = $option->value;
             $label = $config->translate ? $this->getObject('translator')->translate($option->label) : $option->label;
             $extra = '';
             if (isset($option->disabled) && $option->disabled) {
                 $extra .= 'disabled="disabled"';
             }
             if (isset($option->attribs)) {
                 $extra .= ' ' . $this->buildAttributes($option->attribs);
             }
             if (!is_null($config->selected)) {
                 if ($config->selected instanceof ObjectConfig) {
                     foreach ($config->selected as $selected) {
                         $sel = is_object($selected) ? $selected->value : $selected;
                         if ((string) $value == (string) $sel) {
                             $extra .= 'selected="selected"';
                             break;
                         }
                     }
                 } else {
                     $extra .= (string) $value == (string) $config->selected ? ' selected="selected"' : '';
                 }
             }
             $html[] = '<option value="' . $value . '" ' . $extra . '>' . $label . '</option>';
         }
         if (!is_numeric($group)) {
             $html[] = '</optgroup>';
         }
     }
     $html[] = '</select>';
     return implode(PHP_EOL, $html);
 }
コード例 #2
0
ファイル: form.php プロジェクト: nooku/nooku-framework
 /**
  * Add query parameters as hidden fields to the GET forms
  *
  * @param string $text Template text
  * @return TemplateFilterForm
  */
 protected function _addQueryParameters(&$text)
 {
     $matches = array();
     if (preg_match_all('#<form.*action="[^"]*\\?(.*)".*method="get".*>(.*)</form>#siU', $text, $matches)) {
         foreach ($matches[1] as $key => $query) {
             parse_str(str_replace('&amp;', '&', $query), $query);
             $input = '';
             foreach ($query as $name => $value) {
                 if (is_array($value)) {
                     $name = $name . '[]';
                 }
                 if (strpos($matches[2][$key], 'name="' . $name . '"') !== false) {
                     continue;
                 }
                 $name = StringEscaper::attr($name);
                 if (is_array($value)) {
                     foreach ($value as $k => $v) {
                         if (!is_scalar($v) || !is_numeric($k)) {
                             continue;
                         }
                         $v = StringEscaper::attr($v);
                         $input .= PHP_EOL . '<input type="hidden" name="' . $name . '" value="' . $v . '" />';
                     }
                 } else {
                     $value = StringEscaper::attr($value);
                     $input .= PHP_EOL . '<input type="hidden" name="' . $name . '" value="' . $value . '" />';
                 }
             }
             $text = str_replace($matches[2][$key], $input . $matches[2][$key], $text);
         }
     }
     return $this;
 }
コード例 #3
0
ファイル: grid.php プロジェクト: nooku/nooku-framework
    /**
     * Render a search box
     *
     * @param   array   $config An optional array with configuration options
     * @return  string  Html
     */
    public function search($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array('search' => null, 'submit_on_clear' => true, 'placeholder' => $this->getObject('translator')->translate('Find by title or description&hellip;')));
        $html = '';
        if ($config->submit_on_clear) {
            $html .= $this->createHelper('behavior')->jquery();
            $html .= '
            <script>
            (function() {
            var value = ' . json_encode($config->search) . ',
                submitForm = function(form) {
                    if (form.length) {
                        var controller = form.data("controller");
                        if (typeof controller === "object" && controller !== null
                                && controller.grid && typeof controller.grid.uncheckAll !== "undefined") {
                            controller.grid.uncheckAll();
                        }

                        form[0].submit();
                    }
                },
                send = function(event) {
                    if (event.which === 13 || event.type === "blur") {
                        submitForm(kQuery(this).parents("form"));
                    }
                };

            kQuery(function($) {
                $(".search_button").keypress(send).blur(send);
                $(".search_button--empty").click(function(event) {
                    event.preventDefault();

                    var input = $(this).siblings("input");
                    input.val("");

                    if (value) {
                        submitForm(input.parents("form"));
                    }
                });
            });
            })();
            </script>';
        }
        $html .= '<div class="search__container search__container--has_empty_button">';
        $html .= '<label for="search"><i class="icon-search"></i></label>';
        $html .= '<input type="search" name="search" class="search_button" placeholder="' . $config->placeholder . '" value="' . StringEscaper::attr($config->search) . '" />';
        $html .= '<a class="search_button--empty"><span>X</span></a>';
        $html .= '</div>';
        return $html;
    }
コード例 #4
0
ファイル: debug.php プロジェクト: nooku/nooku-framework
 /**
  * Dump an object
  *
  * @param   mixed         $var    Variable to dump
  * @param   ObjectConfig $config The configuration options
  * @param   integer       $level  Current recursion level (internal usage only)
  * @return  string
  */
 protected function _dumpResource($var, ObjectConfig $config, $level = 0)
 {
     $type = get_resource_type($var);
     $result = '<span class="koowa-dump-resource">' . StringEscaper::html($type) . ' resource</span>';
     if (isset($config->resources[$type])) {
         $result = '<span class="koowa-toggle koowa-collapsed">' . $result . '</span>';
         $result .= '<div class="koowa-collapsed">';
         foreach (call_user_func($config->resources[$type], $var) as $key => $value) {
             $result .= '<span class="koowa-dump-indent">   ' . str_repeat('|  ', $level) . '</span>';
             $result .= '<span class="koowa-dump-key">' . StringEscaper::html($key) . "</span> => " . $this->_dumpVar($value, $config, $level + 1);
         }
         $result .= '</div>';
         return $result;
     }
     $result .= "\n";
     return $result;
 }
コード例 #5
0
ファイル: behavior.php プロジェクト: nooku/nooku-framework
 /**
  * Loads the calendar behavior and attaches it to a specified element
  *
  * @param array|ObjectConfig $config
  * @return string   The html output
  */
 public function calendar($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('debug' => \Kodekit::getInstance()->isDebug(), 'offset' => 'UTC', 'user_offset' => $this->getObject('user')->getParameter('timezone'), 'server_offset' => date_default_timezone_get(), 'offset_seconds' => 0, 'value' => gmdate("M d Y H:i:s"), 'name' => '', 'format' => '%Y-%m-%d %H:%M:%S', 'first_week_day' => 0, 'attribs' => array('size' => 25, 'maxlength' => 19, 'placeholder' => '')))->append(array('id' => 'datepicker-' . $config->name, 'options_callback' => null, 'options' => array('todayBtn' => 'linked', 'todayHighlight' => true, 'language' => 'en-GB', 'autoclose' => true, 'keyboardNavigation' => false)));
     if ($config->offset) {
         if (strtoupper($config->offset) === 'SERVER_UTC') {
             $config->offset = $config->server_offset;
         } else {
             if (strtoupper($config->offset) === 'USER_UTC') {
                 $config->offset = $config->user_offset ?: $config->server_offset;
             }
         }
         $timezone = new \DateTimeZone($config->offset);
         $config->offset_seconds = $timezone->getOffset(new \DateTime());
     }
     if ($config->value && $config->value != '0000-00-00 00:00:00' && $config->value != '0000-00-00') {
         if (strtoupper($config->value) == 'NOW') {
             $config->value = strftime($config->format);
         }
         $date = new \DateTime($config->value, new \DateTimeZone('UTC'));
         $config->value = strftime($config->format, (int) $date->format('U') + $config->offset_seconds);
     } else {
         $config->value = '';
     }
     $attribs = $this->buildAttributes($config->attribs);
     $value = StringEscaper::attr($config->value);
     if ($config->attribs->readonly === 'readonly' || $config->attribs->disabled === 'disabled') {
         $html = '<div>';
         $html .= '<input type="text" name="' . $config->name . '" id="' . $config->id . '" value="' . $value . '" ' . $attribs . ' />';
         $html .= '</div>';
     } else {
         $html = $this->_loadCalendarScripts($config);
         if (!isset(self::$_loaded['calendar-triggers'])) {
             self::$_loaded['calendar-triggers'] = array();
         }
         // Only display the triggers once for each control.
         if (!in_array($config->id, self::$_loaded['calendar-triggers'])) {
             $options = (string) $config->options;
             if ($config->options_callback) {
                 $options = $config->options_callback . '(' . $options . ')';
             }
             $html .= "<script>\n                    kQuery(function(\$){\n                        \$('#" . $config->id . "').kodekitDatepicker(" . $config->options . ");\n                    });\n                </script>";
             if ($config->offset_seconds) {
                 $html .= "<script>\n                        kQuery(function(\$){\n                            \$('.-koowa-form').on('koowa:submit', function() {\n                                var element = kQuery('#" . $config->id . "'),\n                                    picker  = element.data('datepicker'),\n                                    offset  = {$config->offset_seconds};\n\n                                if (picker && element.children('input').val()) {\n                                    picker.setDate(new Date(picker.getDate().getTime() + (-1*offset*1000)));\n                                }\n                            });\n                        });\n                    </script>";
             }
             self::$_loaded['calendar-triggers'][] = $config->id;
         }
         $format = str_replace(array('%Y', '%y', '%m', '%d', '%H', '%M', '%S'), array('yyyy', 'yy', 'mm', 'dd', 'hh', 'ii', 'ss'), $config->format);
         $html .= '<div class="input-group date datepicker" data-date-format="' . $format . '" id="' . $config->id . '">';
         $html .= '<input class="input-group-form-control" type="text" name="' . $config->name . '" value="' . $value . '"  ' . $attribs . ' />';
         $html .= '<span class="input-group-btn">';
         $html .= '<span class="btn" >';
         $html .= '<span class="koowa_icon--calendar"><i>calendar</i></span>';
         $html .= '</span>';
         $html .= '</span>';
         $html .= '</div>';
     }
     return $html;
 }
コード例 #6
0
ファイル: title.php プロジェクト: nooku/nooku-framework
 /**
  * Render the tag
  *
  * @param   array   $attribs Associative array of attributes
  * @param   string  $content The tag content
  * @return string
  */
 protected function _renderTag($attribs = array(), $content = null)
 {
     unset($attribs['content']);
     unset($attribs['separator']);
     $attribs = $this->buildAttributes($attribs);
     if ($this->getConfig()->escape) {
         $content = StringEscaper::html($content);
     }
     $html = '<title ' . $attribs . '>' . $content . '</title>' . "\n";
     return $html;
 }