Example #1
0
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param  ObjectConfig $config An optional ObjectConfig object with configuration options
  * @return void
  */
 protected function _initialize(ObjectConfig $config)
 {
     if (empty($config->resolvers)) {
         $config->append(array('resolvers' => array('extension')));
     }
     parent::_initialize($config);
 }
 /**
  * Initializes the config for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param   ObjectConfig $config  An optional ObjectConfig object with configuration options
  * @return  void
  */
 protected function _initialize(ObjectConfig $config)
 {
     //Clone the identifier
     $identifier = clone $this->getIdentifier();
     $config->append(array('data' => array(), 'layout' => '', 'template' => $this->getName(), 'template_filters' => array('shorttag', 'function', 'url', 'decorator'), 'auto_assign' => true));
     parent::_initialize($config);
 }
Example #3
0
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param ObjectConfig $config 	An optional ObjectConfig object with configuration options.
  * @return 	void
  */
 protected function _initialize(ObjectConfig $config)
 {
     //Create permission identifier
     $permission = clone $this->getIdentifier();
     $permission->path = array('dispatcher', 'permission');
     $config->append(array('controller' => $this->getIdentifier()->package, 'request' => 'lib:dispatcher.request', 'response' => 'lib:dispatcher.response', 'user' => 'lib:dispatcher.user', 'behaviors' => array($permission)));
     parent::_initialize($config);
 }
Example #4
0
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param  ObjectConfig $config An optional ObjectConfig object with configuration options
  */
 protected function _initialize(ObjectConfig $config)
 {
     $self = $this;
     $config->append(array('autoescape' => true, 'strict_variables' => false, 'optimizations' => -1, 'functions' => array('import' => function ($url, $data) use($self) {
         return $self->renderPartial($url, $data);
     })));
     parent::_initialize($config);
 }
Example #5
0
 /**
  * Initializes the default configuration for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param ObjectConfig $config 	An optional ObjectConfig object with configuration options.
  * @return void
  */
 protected function _initialize(ObjectConfig $config)
 {
     $toolbars = array();
     if ($config->dispatched && $config->user->isAuthentic()) {
         $toolbars[] = $this->getIdentifier()->name;
     }
     $config->append(array('toolbars' => $toolbars, 'model' => $this->getIdentifier()->name));
     parent::_initialize($config);
 }
Example #6
0
 /**
  * Generates an HTML image preview listbox
  *
  * $config options:
  *
  * name			string		column name of helper
  * directory	string		image directory (relative to docroot)
  * width		int			image width
  * height		int			image height
  * border		int			border width
  * style		string		style string
  * selected		string		currently selected vallue
  *
  * @param 	array 	$config An optional array with configuration options
  * @return  string  Html
  */
 public function preview($config = array())
 {
     $config = new ObjectConfig($config);
     $config->append(array('name' => 'image_name', 'directory' => JPATH_IMAGES . '/stories', 'width' => 80, 'height' => 80, 'border' => 2, 'style' => 'margin: 10px 0;'))->append(array('selected' => $config->{$config->name}));
     $image = $this->getObject('request')->getBasePath() . str_replace(JPATH_ROOT, '', $config->directory) . '/' . $config->selected;
     $path = $config->selected ? $image : 'media://images/blank.png';
     $html = '<img ' . $this->_buildAttributes(array('src' => $path, 'id' => $config->name . '-preview', 'class' => 'preview', 'width' => $config->width, 'height' => $config->height, 'border' => $config->border, 'alt' => \JText::_('Preview'), 'style' => $config->style)) . ' />';
     return $html;
 }
Example #7
0
 /**
  * Returns human readable date.
  *
  * @param  array  $config An optional array with configuration options.
  * @return string Formatted date.
  */
 public function humanize($config = array())
 {
     $config = new ObjectConfig($config);
     $config->append(array('date' => 'now', 'timezone' => date_default_timezone_get(), 'default' => \JText::_('Never'), 'smallest_period' => 'second'));
     $result = $config->default;
     if (!in_array($config->date, array('0000-00-00 00:00:00', '0000-00-00'))) {
         $periods = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year');
         $lengths = array(60, 60, 24, 7, 4.35, 12, 10);
         $now = new \DateTime();
         try {
             $date = new Date(array('date' => $config->date, 'timezone' => 'UTC'));
             $date->setTimezone(new \DateTimeZone($config->timezone));
             if ($now != $date) {
                 // TODO: Use DateTime::getTimeStamp().
                 if ($now > $date) {
                     $difference = $now->format('U') - $date->format('U');
                     $tense = 'ago';
                 } else {
                     $difference = $date->format('U') - $now->format('U');
                     $tense = 'from now';
                 }
                 for ($i = 0; $difference >= $lengths[$i] && $i < 6; $i++) {
                     $difference /= $lengths[$i];
                 }
                 $difference = round($difference);
                 $period_index = array_search($config->smallest_period, $periods);
                 $omitted_periods = $periods;
                 array_splice($omitted_periods, $period_index);
                 if (in_array($periods[$i], $omitted_periods)) {
                     $difference = 1;
                     $i = $period_index;
                 }
                 if ($periods[$i] == 'day' && ($difference == 1 || $difference == 2)) {
                     if ($difference == 1) {
                         $result = \JText::_('Today');
                     } else {
                         $result = $tense == 'ago' ? \JText::_('Yesterday') : \JText::_('Tomorrow');
                     }
                 } else {
                     if ($difference != 1) {
                         $periods[$i] .= 's';
                     }
                     $result = sprintf(\JText::_('%d ' . $periods[$i] . ' ' . $tense), $difference);
                 }
             } else {
                 $result = \JText::_('Now');
             }
         } catch (\Exception $e) {
         }
     }
     return $result;
 }
Example #8
0
 /**
  * Generates a select option list
  *
  * @param   array   $config An optional array with configuration options
  * @return  array   An array of objects containing the option attributes
  */
 public function options($config = array())
 {
     $config = new ObjectConfig($config);
     $config->append(array('entity' => array(), 'name' => 'id', 'value' => 'id', 'label' => 'id', 'disabled' => null, 'attribs' => array()));
     $options = array();
     foreach ($config->entity as $entity) {
         $option = array('id' => isset($entity->{$config->name}) ? $entity->{$config->name} : null, 'name' => $config->name, 'disabled' => $config->disabled, 'attribs' => ObjectConfig::unbox($config->attribs), 'value' => $entity->{$config->value}, 'label' => $entity->{$config->label});
         if ($config->entity instanceof \RecursiveIteratorIterator) {
             $option['level'] = $config->entity->getDepth() + 1;
         }
         $options[] = $this->option($option);
     }
     return $options;
 }
Example #9
0
 /**
  * Returns human readable date.
  *
  * @param  array $config An optional array with configuration options.
  * @return string  Formatted date.
  */
 public function humanize($config = array())
 {
     $config = new ObjectConfig($config);
     $config->append(array('date' => 'now', 'timezone' => date_default_timezone_get(), 'default' => $this->getObject('translator')->translate('Never'), 'period' => 'second'));
     $result = $config->default;
     if (!in_array($config->date, array('0000-00-00 00:00:00', '0000-00-00'))) {
         try {
             $date = $this->getObject('date', array('date' => $config->date, 'timezone' => 'UTC'));
             $date->setTimezone(new \DateTimeZone($config->timezone));
             $result = $date->humanize($config->period);
         } catch (Exception $e) {
         }
     }
     return $result;
 }
Example #10
0
 /**
  * Implements lazy loading of the pages config property.
  *
  * @param string
  * @return mixed
  */
 public function get($name, $default = null)
 {
     if ($name == 'pages' && !isset($this->pages)) {
         $this->pages = $this->_pages();
     }
     return parent::get($name);
 }
Example #11
0
 /**
  * Build a string with xml style attributes from  an array of key/value pairs
  *
  * @param   mixed   $array The array of Key/Value pairs for the attributes
  * @return  string  String containing xml style attributes
  */
 public function buildAttributes($array)
 {
     $output = array();
     if ($array instanceof ObjectConfig) {
         $array = ObjectConfig::unbox($array);
     }
     if (is_array($array)) {
         foreach ($array as $key => $item) {
             if (is_array($item)) {
                 if (empty($item)) {
                     continue;
                 }
                 $item = implode(' ', $item);
             }
             if (is_bool($item)) {
                 if ($item === false) {
                     continue;
                 }
                 $item = $key;
             }
             $output[] = $key . '="' . str_replace('"', '&quot;', $item) . '"';
         }
     }
     return implode(' ', $output);
 }
Example #12
0
 /**
  * Invoke a template helper
  *
  * This function accepts a partial identifier, in the form of helper.method or schema:package.helper.method. If
  * a partial identifier is passed a full identifier will be created using the template identifier.
  *
  * If the state have the same string keys, then the parameter value for that key will overwrite the state.
  *
  * @param    string   $identifier Name of the helper, dot separated including the helper function to call
  * @param    array    $params     An optional associative array of functions parameters to be passed to the helper
  * @return   string   Helper output
  * @throws   \BadMethodCallException If the helper function cannot be called.
  */
 public function invokeHelper($identifier, $params = array())
 {
     //Get the function and helper based on the identifier
     $parts = explode('.', $identifier);
     $function = array_pop($parts);
     $identifier = array_pop($parts);
     //Handle schema:package.helper.function identifiers
     if (!empty($parts)) {
         $identifier = implode('.', $parts) . '.template.helper.' . $identifier;
     }
     //Create the complete identifier if a partial identifier was passed
     if (is_string($identifier) && strpos($identifier, '.') === false) {
         $helper = $this->getMixer()->getIdentifier()->toArray();
         if ($helper['type'] != 'lib') {
             $helper['path'] = array('template', 'helper');
         } else {
             $helper['path'] = array('helper');
         }
         $helper['name'] = $identifier;
     } else {
         $helper = $this->getIdentifier($identifier);
     }
     $helper = $this->getObject('template.helper.factory')->createHelper($helper, ObjectConfig::unbox($params));
     //Call the helper function
     if (!is_callable(array($helper, $function))) {
         throw new \BadMethodCallException(get_class($helper) . '::' . $function . ' not supported.');
     }
     //Merge the parameters if helper asks for it
     if ($helper instanceof TemplateHelperParameterizable) {
         $params = array_merge($this->getParameters()->toArray(), $params);
     }
     return $helper->{$function}($params);
 }
Example #13
0
 /**
  * Return the views output
  *
  * @param ViewContextTemplate  $context A view context object
  * @return string  The output of the view
  */
 protected function _actionRender(ViewContextTemplate $context)
 {
     $data = ObjectConfig::unbox($context->data);
     $path = $this->qualifyLayout($context->layout);
     //Render the template
     $content = $this->getTemplate()->setParameters($context->parameters)->render($path, $data);
     return $content;
 }
Example #14
0
 /**
  * Returns human readable date.
  *
  * @param  array  $config An optional array with configuration options.
  * @return string Formatted date.
  */
 public function humanize($config = array())
 {
     $config = new ObjectConfig($config);
     $config->append(array('date' => 'now', 'timezone' => date_default_timezone_get(), 'default' => $this->translate('Never'), 'smallest_period' => 'second'));
     $result = $config->default;
     if (!in_array($config->date, array('0000-00-00 00:00:00', '0000-00-00'))) {
         $periods = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year');
         $lengths = array(60, 60, 24, 7, 4.35, 12, 10);
         $now = new \DateTime();
         try {
             $date = new Date(array('date' => $config->date, 'timezone' => 'UTC'));
             $date->setTimezone(new \DateTimeZone($config->timezone));
             $result = $date->humanize($config->period);
         } catch (\Exception $e) {
         }
     }
     return $result;
 }
Example #15
0
 /**
  * Recalculate offset
  *
  * @param   ModelContextInterface $context A model context object
  * @return    void
  */
 protected function _afterReset(ModelContextInterface $context)
 {
     $modified = (array) ObjectConfig::unbox($context->modified);
     if (in_array('limit', $modified)) {
         $limit = $context->state->limit;
         if ($limit) {
             $context->state->offset = floor($context->state->offset / $limit) * $limit;
         }
     }
 }
Example #16
0
 /**
  * Constructor
  *
  * @param ObjectConfig $config  An optional ObjectConfig object with configuration options.
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Add the toolbars
     $toolbars = (array) ObjectConfig::unbox($config->toolbars);
     foreach ($toolbars as $key => $value) {
         if (is_numeric($key)) {
             $this->attachToolbar($value);
         } else {
             $this->attachToolbar($key, $value);
         }
     }
 }
Example #17
0
 /**
  * Constructor
  *
  * @param ObjectConfig $config An optional ObjectConfig object with configuration options.
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Add the behaviors in FIFO order
     $behaviors = (array) ObjectConfig::unbox($config->behaviors);
     foreach ($behaviors as $key => $value) {
         if (is_numeric($key)) {
             $this->addBehavior($value);
         } else {
             $this->addBehavior($key, $value);
         }
     }
 }
Example #18
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;
 }
Example #19
0
 /**
  * Constructor
  *
  * @param ObjectConfig $object An optional ObjectConfig object with configuration options.
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Set the auto mixin state
     $this->_auto_mixin = $config->auto_mixin;
     //Add the behaviors
     $behaviors = (array) ObjectConfig::unbox($config->behaviors);
     foreach ($behaviors as $key => $value) {
         if (is_numeric($key)) {
             $this->attachBehavior($value);
         } else {
             $this->attachBehavior($key, $value);
         }
     }
 }
Example #20
0
 /**
  * Constructor.
  *
  * @param ObjectConfig $config	An optional ObjectConfig object with configuration options.
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Set the filter queue
     $this->__filter_queue = $this->getObject('lib:object.queue');
     //Add the authenticators
     $filters = (array) ObjectConfig::unbox($config->filters);
     foreach ($filters as $key => $value) {
         if (is_numeric($key)) {
             $this->addFilter($value);
         } else {
             $this->addFilter($key, $value);
         }
     }
 }
Example #21
0
 /**
  * Add the toolbars to the controller
  *
  * @param ControllerContext $context
  * @return void
  */
 protected function _beforeRender(ControllerContext $context)
 {
     $controller = $context->getSubject();
     // Add toolbars on authenticated requests only.
     if ($controller->getUser()->isAuthentic()) {
         //Add the toolbars
         $toolbars = (array) ObjectConfig::unbox($this->getConfig()->toolbars);
         foreach ($toolbars as $key => $value) {
             if (is_numeric($key)) {
                 $this->addToolbar($value);
             } else {
                 $this->addToolbar($key, $value);
             }
         }
     }
     //Add the template filter and inject the toolbars
     if ($controller->getView() instanceof ViewTemplatable) {
         $controller->getView()->getTemplate()->addFilter('toolbar', array('toolbars' => $this->getToolbars()));
     }
 }
Example #22
0
 /**
  * Register a named callback
  *
  * If the callback has already been registered. It will not be re-registered.
  *
  * @param  	string      	$name       The callback name to register the callback for
  * @param 	callable		$callback   The callback function to register
  * @param   array|object    An associative array of config parameters or a KConfig object
  * @throws  \InvalidArgumentException If the callback is not a callable
  * @return  Object	The mixer object
  */
 public function registerCallback($name, $callback, $params = array())
 {
     if (!is_callable($callback)) {
         throw new \InvalidArgumentException('The callback must be a callable, "' . gettype($callback) . '" given.');
     }
     $params = (array) ObjectConfig::unbox($params);
     $name = strtolower($name);
     if (!isset($this->_callbacks[$name])) {
         $this->_callbacks[$name] = array();
         $this->_params[$name] = array();
     }
     //Don't re-register names
     $index = array_search($callback, $this->_callbacks[$name], true);
     if ($index === false) {
         $this->_callbacks[$name][] = $callback;
         $this->_params[$name][] = $params;
     } else {
         $this->_params[$name][$index] = array_merge($this->_params[$name][$index], $params);
     }
     return $this->getMixer();
 }
Example #23
0
 /**
  * Set a configuration element
  *
  * @param  string 
  * @param  mixed 
  * @return void
  */
 public function set($name, $value)
 {
     parent::set($name, $value);
     //Only calculate the limit and offset if we have a total
     if ($this->total) {
         $this->limit = (int) max($this->limit, 1);
         $this->offset = (int) max($this->offset, 0);
         if ($this->limit > $this->total) {
             $this->offset = 0;
         }
         if (!$this->limit) {
             $this->offset = 0;
             $this->limit = $this->total;
         }
         $this->count = (int) ceil($this->total / $this->limit);
         if ($this->offset > $this->total) {
             $this->offset = ($this->count - 1) * $this->limit;
         }
         $this->current = (int) floor($this->offset / $this->limit) + 1;
     }
 }
Example #24
0
 /**
  * Render the action bar
  *
  * @param   array   $config An optional array with configuration options
  * @return  string  Html
  */
 public function render($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('toolbar' => null, 'attribs' => array('class' => array('koowa-toolbar'))));
     $html = '';
     if (isset($config->toolbar)) {
         //Force the id
         $config->attribs['id'] = 'toolbar-' . $config->toolbar->getType();
         $html = '<div ' . $this->buildAttributes($config->attribs) . '>';
         $html .= '<div class="button__group">';
         foreach ($config->toolbar as $command) {
             $name = $command->getName();
             if (method_exists($this, $name)) {
                 $html .= $this->{$name}(ObjectConfig::unbox($command));
             } else {
                 $html .= $this->command(ObjectConfig::unbox($command));
             }
         }
         $html .= '</div>';
         $html .= '</div>';
     }
     return $html;
 }
Example #25
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;
 }
Example #26
0
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param   ObjectConfig $config Configuration options.
  * @return  void
  */
 protected function _initialize(ObjectConfig $config)
 {
     $config->append(array('mixins' => array(), 'decorators' => array()));
 }
Example #27
0
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param   ObjectConfig $object An optional ObjectConfig object with configuration options
  * @return  void
  */
 protected function _initialize(ObjectConfig $config)
 {
     $config->append(array('class_loader' => null, 'cache_enabled' => false, 'cache_prefix' => 'nooku-registry-object'));
 }
Example #28
0
 /**
  * Initializes the default configuration for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param   object  An optional ObjectConfig object with configuration options.
  * @return void
  */
 protected function _initialize(ObjectConfig $config)
 {
     $config->append(array('auto_register' => false));
     parent::_initialize($config);
 }
Example #29
0
 /**
  * Initializes the config for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param   object  An optional ObjectConfig object with configuration options
  * @return  void
  */
 protected function _initialize(ObjectConfig $config)
 {
     $config->append(array('encoding' => 'utf8', 'options' => array('clean' => true, 'drop-proprietary-attributes' => true, 'output-html' => true, 'show-body-only' => true, 'bare' => true, 'wrap' => 0, 'word-2000' => true)));
     parent::_initialize($config);
 }
Example #30
0
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param   ObjectConfig $config An optional ObjectConfig object with configuration options
  */
 protected function _initialize(ObjectConfig $config)
 {
     $config->append(array('model' => null, 'defaults' => array()));
     parent::_initialize($config);
 }