예제 #1
0
 /**
  * Creates a tab panel with title and starts that panel
  *
  * @param 	array 	$config An optional array with configuration options
  * @return  string  Html
  */
 public function startPanel($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('title' => '', 'attribs' => array(), 'options' => array(), 'translate' => true));
     $title = $config->translate ? $this->translate($config->title) : $config->title;
     $attribs = $this->buildAttributes($config->attribs);
     return '<dt ' . $attribs . '><span>' . $title . '</span></dt><dd>';
 }
예제 #2
0
 /**
  * Creates a tab panel with title and starts that panel
  *
  * @param 	array 	$config An optional array with configuration options
  * @return 	string	Html
  */
 public function startPanel($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('title' => 'Slide', 'attribs' => array(), 'translate' => true));
     $title = $config->translate ? \JText::_($config->title) : $config->title;
     $attribs = $this->_buildAttributes($config->attribs);
     $html = '<div class="panel"><h3 class="jpane-toggler title" ' . $attribs . '><span>' . $title . '</span></h3><div class="jpane-slider content">';
     return $html;
 }
예제 #3
0
 public function script($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('strings' => array()));
     $strings = ObjectConfig::unbox($config->strings);
     $translator = $this->getObject('translator');
     $translations = array();
     foreach ($strings as $string) {
         $translations[$string] = $translator->translate($string);
     }
     $html = '';
     $html .= $this->createHelper('behavior')->kodekit() . "<script>\n            if (typeof Kodekit === 'object' && Kodekit !== null) {\n                if (typeof Kodekit.translator === 'object' && Kodekit.translator !== null) {\n                    Kodekit.translator.loadTranslations(" . json_encode($translations) . ");\n                }\n            }\n            </script>\n            ";
     return $html;
 }
예제 #4
0
 /**
  * Test existence of a manifest option
  *
  * @param string $name
  * @return bool
  */
 public final function __isset($name)
 {
     $result = false;
     if ($this->__manifest !== false) {
         $result = $this->__manifest->has($name);
     }
     return $result;
 }
예제 #5
0
 /**
  * Render a select box with limit values
  *
  * @param   array|ObjectConfig     $config An optional array with configuration options
  * @return  string  Html select box
  */
 public function limit($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('limit' => 0, 'attribs' => array(), 'page_rows' => array(10, 20, 50, 100)));
     $html = '';
     $selected = 0;
     $options = array();
     $values = ObjectConfig::unbox($config->page_rows);
     if ($config->limit && !in_array($config->limit, $values)) {
         $values[] = $config->limit;
         sort($values);
     }
     foreach ($values as $value) {
         if ($value == $config->limit) {
             $selected = $value;
         }
         $options[] = $this->option(array('label' => $value, 'value' => $value));
     }
     if ($config->limit == $config->total) {
         $options[] = $this->option(array('label' => $this->getObject('translator')->translate('All'), 'value' => 0));
     }
     $html .= $this->optionlist(array('options' => $options, 'name' => 'limit', 'attribs' => $config->attribs, 'selected' => $selected));
     return $html;
 }
예제 #6
0
 /**
  * Get the locked information
  *
  * @param  array|ObjectConfig $config An optional configuration array.
  * @throws \UnexpectedValueException
  * @return string The locked by "name" "date" message
  */
 public function lock_message($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('entity' => null));
     if (!$config->entity instanceof ModelEntityInterface) {
         throw new \UnexpectedValueException('$config->entity should be a ModelEntityInterface instance');
     }
     $entity = $config->entity;
     $message = '';
     if ($entity->isLockable() && $entity->isLocked()) {
         $user = $entity->getLocker();
         $date = $this->getObject('date', array('date' => $entity->locked_on));
         $message = $this->getObject('translator')->translate('Locked by {name} {date}', array('name' => $user->getName(), 'date' => $date->humanize()));
     }
     return $message;
 }
예제 #7
0
 /**
  * Render an access field
  *
  * @param 	array 	$config An optional array with configuration options
  * @return	string	Html
  */
 public function access($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('row' => null, 'field' => 'access'))->append(array('data' => array($config->field => $config->row->{$config->field})));
     switch ($config->row->{$config->field}) {
         case 0:
             $color = 'green';
             $group = $this->translate('Public');
             $access = 1;
             break;
         case 1:
             $color = 'red';
             $group = $this->translate('Registered');
             $access = 2;
             break;
     }
     $config->data->{$config->field} = $access;
     $data = str_replace('"', '&quot;', $config->data);
     $html = '<span style="color:' . $color . '" data-action="edit" data-data="' . $data . '">' . $group . '</span>';
     return $html;
 }
예제 #8
0
 /**
  * Drag and Drop Sortables Behavior
  *
  * @param 	array 	$config An optional array with configuration options
  * @return	string 	Html
  */
 public function sortable($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('option' => 'com_' . $this->getIdentifier()->getPackage(), 'view' => StringInflector::singularize($this->getTemplate()->getView()->getName()), 'selector' => 'table tbody.sortable', 'direction' => 'asc', 'url' => '?format=json'))->append(array('options' => array('handle' => 'td.handle', 'numcolumn' => '.grid-count', 'direction' => $config->direction, 'adapter' => array('type' => 'koowa', 'options' => array('url' => $config->url, 'data' => array('_token' => $this->getObject('user')->getSession()->getToken(), '_action' => 'edit'), 'key' => 'order', 'offset' => 'relative')))));
     $html = '';
     $signature = md5(serialize(array($config->selector, $config->options)));
     if (!isset($this->_loaded[$signature])) {
         $options = !empty($config->options) ? $config->options->toArray() : array();
         $html .= "\n                <script src=\"/administrator/theme/default/js/sortables.js\" />\n                <style src=\"/administrator/theme/default/stylesheets/sortables.css\" />\n\t\t\t\t<script>\n\t\t\t\t(function(){\n\t\t\t\t\tvar sortable = function() {\n\t\t\t\t\t\t\$\$('" . $config->selector . "').sortable(" . json_encode($options) . ");\n\t\t\t\t\t};\n\t\t\t\t\twindow.addEvents({domready: sortable, request: sortable});\n\t\t\t\t})();\n\t\t\t\t</script>\n\t\t\t";
         $this->_loaded[$signature] = true;
     }
     return $html;
 }
예제 #9
0
 /**
  * Render a separator
  *
  * @param   array   $config An optional array with configuration options
  * @return  string  Html
  */
 public function separator($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('attribs' => array('class' => array('button__group'))));
     $html = '</div><div ' . $this->buildAttributes($config->attribs) . '>';
     return $html;
 }
예제 #10
0
 /**
  * Returns an array of HTML strings that represent each step in the backtrace.
  *
  * @param   array   $config An optional array with configuration options
  * @return  string  Html
  */
 public function trace($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('trace' => null, 'statements' => array('include', 'include_once', 'require', 'require_once')));
     $trace = $config->trace;
     // Start a new trace
     if ($trace === NULL) {
         $trace = debug_backtrace();
     }
     $output = array();
     foreach ($trace as $step) {
         // Invalid trace step
         if (!isset($step['function'])) {
             continue;
         }
         // Include the source of this step
         if (isset($step['file']) and isset($step['line'])) {
             $source = $this->source(array('file' => $step['file'], 'line' => $step['line']));
         }
         if (isset($step['file'])) {
             $file = $step['file'];
             if (isset($step['line'])) {
                 $line = $step['line'];
             }
         }
         // function()
         $function = $step['function'];
         // Non-standard function calls
         if (in_array($step['function'], $config->statements->toArray())) {
             // No arguments
             if (empty($step['args'])) {
                 $args = array();
             } else {
                 $args = array($step['args'][0]);
             }
         } elseif (isset($step['args'])) {
             $params = NULL;
             // Introspection on closures or language constructs in a stack trace is impossible
             if (function_exists($step['function']) || strpos($step['function'], '{closure}') === FALSE) {
                 if (isset($step['class'])) {
                     if (method_exists($step['class'], $step['function'])) {
                         $reflection = new \ReflectionMethod($step['class'], $step['function']);
                     } else {
                         $reflection = new \ReflectionMethod($step['class'], '__call');
                     }
                 } else {
                     $reflection = new \ReflectionFunction($step['function']);
                 }
                 // Get the function parameters
                 $params = $reflection->getParameters();
             }
             $args = array();
             foreach ($step['args'] as $i => $arg) {
                 if (isset($params[$i])) {
                     $args[$params[$i]->name] = $arg;
                     // Assign the argument by the parameter name
                 } else {
                     $args[$i] = $arg;
                     // Assign the argument by number
                 }
             }
         }
         // Class->method() or Class::method()
         if (isset($step['class'])) {
             $type = $step['type'];
             //Support for xdebug
             if ($step['type'] == "dynamic") {
                 $type = '->';
             }
             //Support for xdebug
             if ($step['type'] == "static") {
                 $type = '::';
             }
             $function = $step['class'] . $type . $step['function'];
         }
         $output[] = array('function' => $function, 'args' => isset($args) ? $args : NULL, 'file' => isset($file) ? $file : NULL, 'line' => isset($line) ? $line : NULL, 'source' => isset($source) ? $source : NULL);
         unset($function, $args, $file, $line, $source);
     }
     return $output;
 }
예제 #11
0
 /**
  * Loads the inline editor behavior and attaches it to a specified element
  *
  * @see http://mootools.net/forge/p/meio_autocomplete
  *
  * @param 	array 	$config An optional array with configuration options
  * @return string    The html output
  *
  */
 public function inline_editing($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('url' => '', 'options' => array(), 'attribs' => array()));
     $html = '';
     // Load the necessary files if they haven't yet been loaded
     if (!isset(self::$_loaded['inline_editing'])) {
         $html .= '<script src="assets://application/js/jquery.js" />';
         $html .= '<script src="assets://ckeditor/ckeditor/ckeditor.js" />';
         self::$_loaded['inline_editing'] = true;
     }
     $url = $this->getObject('lib:http.url', array('url' => $config->url));
     $html .= "<script>window.addEvent('domready', function(){\n                    CKEDITOR.on( 'instanceCreated', function( event ) {\n                        var editor = event.editor,\n                            element = editor.element;\n\n                        if ( element.is( 'h1', 'h2', 'h3' ) || element.getAttribute( 'id' ) == 'taglist' ) {\n                            editor.on( 'configLoaded', function() {\n                                editor.config.toolbar = 'title';\n                            });\n                        }else{\n                            editor.on( 'configLoaded', function() {\n                                editor.config.toolbar = 'standard';\n                            });\n                        }\n                        editor.on('blur', function (ev) {\n                            var data = {};\n\n                            // Need to do this because we don't know what field there is being edited....\n                            data[editor.element.getId()] = editor.getData();\n                            data['_token'] = '" . $this->getObject('user')->getSession()->getToken() . "';\n\n                            jQuery.post('" . $url . "', data);\n                        });\n                    });\n            });</script>";
     return $html;
 }
예제 #12
0
 /**
  * Renders a listbox with autocomplete behavior
  *
  * @param  array|ObjectConfig    $config
  * @return string   The html output
  */
 private function __autocomplete($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('name' => '', 'attribs' => array('id' => 'select2-element-' . mt_rand(1000, 100000)), 'validate' => true, 'prompt' => '- ' . $this->getObject('translator')->translate('Select') . ' -', 'deselect' => true))->append(array('element' => '#' . $config->attribs->id, 'options' => array('multiple' => (bool) $config->attribs->multiple), 'value' => $config->name, 'selected' => $config->{$config->name}))->append(array('label' => $config->value))->append(array('text' => $config->label, 'filter' => array('sort' => $config->label)));
     if (!$config->url) {
         $identifier = $config->model->getIdentifier();
         $parts = array('component' => $identifier->package, 'view' => $identifier->name, 'format' => 'json');
         if ($config->filter) {
             $parts = array_merge($parts, ObjectConfig::unbox($config->filter));
         }
         $config->url = $this->getObject('lib:dispatcher.router.route')->setQuery($parts);
     }
     $html = '';
     $html .= $this->createHelper('behavior')->autocomplete($config);
     $config->attribs->name = $config->name;
     $options = array();
     if (is_scalar($config->selected) && $config->selected || count($config->selected)) {
         $selected = $config->selected;
         if (!$selected instanceof ModelEntityInterface) {
             $selected = $config->model->setState(ObjectConfig::unbox($config->filter))->setState(array($config->value => ObjectConfig::unbox($selected)))->fetch();
         }
         foreach ($selected as $entity) {
             $options[] = $this->option(array('value' => $entity->{$config->value}, 'label' => $entity->{$config->label}, 'attribs' => array('selected' => true)));
         }
     }
     $html .= $this->optionlist(array('name' => $config->name, 'id' => $config->id, 'options' => $options, 'deselect' => false, 'select2' => false, 'attribs' => $config->attribs));
     return $html;
 }
예제 #13
0
 /**
  * Generates an HTML boolean radio list
  *
  * @param   array|ObjectConfig     $config An optional array with configuration options
  * @return  string  Html
  */
 public function booleanlist($config = array())
 {
     $translator = $this->getObject('translator');
     $config = new ObjectConfigJson($config);
     $config->append(array('name' => '', 'attribs' => array(), 'true' => $translator->translate('Yes'), 'false' => $translator->translate('No'), 'selected' => null, 'translate' => true));
     $name = $config->name;
     $attribs = $this->buildAttributes($config->attribs);
     $html = array();
     $extra = $config->selected ? 'checked="checked"' : '';
     $text = $config->translate ? $translator->translate($config->true) : $config->true;
     $html[] = '<label for="' . $name . '1" class="btn">';
     $html[] = '<input type="radio" name="' . $name . '" id="' . $name . '1" value="1" ' . $extra . ' ' . $attribs . ' />';
     $html[] = $text . '</label>';
     $extra = !$config->selected ? 'checked="checked"' : '';
     $text = $config->translate ? $translator->translate($config->false) : $config->false;
     $html[] = '<label for="' . $name . '0" class="btn">';
     $html[] = '<input type="radio" name="' . $name . '" id="' . $name . '0" value="0" ' . $extra . ' ' . $attribs . ' />';
     $html[] = $text . '</label>';
     return implode(PHP_EOL, $html);
 }
예제 #14
0
 /**
  * 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;
 }