/** * Constructor * * @param object An optional KConfig object with configuration options. */ public function __construct(KConfig $config) { parent::__construct($config); // Set the view identifier $this->_modules = KConfig::toData($config->modules); }
/** * Generates an HTML editor * * @param array An optional array with configuration options * @return string Html */ public function display($config = array()) { $config = new KConfig($config); $config->append(array( 'editor' => null, 'name' => 'description', 'width' => '100%', 'height' => '500', 'cols' => '75', 'rows' => '20', 'buttons' => true, 'options' => array() )); $editor = KFactory::get('joomla:editor', array($config->editor)); $options = KConfig::toData($config->options); if (version_compare(JVERSION, '1.6.0', 'ge')) { $result = $editor->display($config->name, $config->{$config->name}, $config->width, $config->height, $config->cols, $config->rows, KConfig::toData($config->buttons), $config->name, null, null, $options); } else { $result = $editor->display($config->name, $config->{$config->name}, $config->width, $config->height, $config->cols, $config->rows, KConfig::toData($config->buttons), $options); } return $result; }
/** * Add an element * * @param NinjaFormElementInterface $elem * @return this */ public function addElement(comNinjaFormElementInterface $elem) { $data = $this->_data; $data[] = $elem; $this->_data = KConfig::toData($data); return $this; }
/** * Constructor * * @param object An optional KConfig object with configuration options */ public function __construct(KConfig $config) { parent::__construct($config); // set the auto assign state $this->_auto_assign = $config->auto_assign; //set the data $this->_data = KConfig::toData($config->data); // user-defined escaping callback $this->setEscape($config->escape); // set the template object $this->_template = $config->template; //Set the template filters if(!empty($config->template_filters)) { $this->getTemplate()->addFilter($config->template_filters); } // Set base and media urls for use by the view $this->assign('baseurl' , $config->base_url) ->assign('mediaurl', $config->media_url); //Add alias filter for media:// namespace $this->getTemplate()->getFilter('alias')->append( array('media://' => $config->media_url.'/'), KTemplateFilter::MODE_READ | KTemplateFilter::MODE_WRITE ); //Add alias filter for base:// namespace $this->getTemplate()->getFilter('alias')->append( array('base://' => $config->base_url.'/'), KTemplateFilter::MODE_READ | KTemplateFilter::MODE_WRITE ); }
/** * Constructor * * @param object An optional KConfig object with configuration options */ public function __construct(KConfig $config) { parent::__construct($config); $this->_encdoing = $config->encoding; $this->_config = KConfig::toData($config->config); }
/** * Generates an HTML editor * * @param array An optional array with configuration options * @return string Html */ public function display($config = array()) { $config = new KConfig($config); $config->append(array('editor' => null, 'name' => 'description', 'width' => '100%', 'height' => '500', 'cols' => '75', 'rows' => '20', 'buttons' => true, 'options' => array())); $editor = KFactory::get('lib.joomla.editor', array($config->editor)); $options = KConfig::toData($config->options); return $editor->display($config->name, $config->{$config->name}, $config->width, $config->height, $config->cols, $config->rows, $config->buttons, $options); }
/** * Constructor * * @param object An optional KConfig object with configuration options. */ public function __construct(KConfig $config) { parent::__construct($config); // Set the view identifier $this->_menubar = $config->menubar; $this->_render = KConfig::toData($config->render); }
/** * Constructor. * * @param object An optional KConfig object with configuration options */ public function __construct( KConfig $config = null) { parent::__construct($config); $this->_title = $config->title; $this->_class = $config->class; $this->_styles = KConfig::toData($config->styles); $this->_attribs = KConfig::toData($config->attribs); }
/** * Constructor. * * @param object An optional KConfig object with configuration options */ public function __construct(KConfig $config = null) { //If no config is passed create it if (!isset($config)) { $config = new KConfig(); } parent::__construct($config); $this->_data = KConfig::toData($config->data); }
/** * Constructor * * Prevent creating instances of this class by making the contructor private * * @param object An optional KConfig object with configuration options */ public function __construct(KConfig $config) { parent::__construct($config); // Set the table indentifier if (isset($config->view)) { $this->setView($config->view); } //Register the template stream wrapper KTemplateStream::register(); //Set the template search paths $this->_paths = KConfig::toData($config->paths); // Mixin a command chain $this->mixin(new KMixinCommandchain($config->append(array('mixer' => $this)))); }
/** * Creates a pane and creates the javascript object for it * * @param array An optional array with configuration options * @return string Html */ public function startPane($config = array()) { $config = new KConfig($config); $config->append(array('id' => 'pane', 'attribs' => array(), 'options' => array())); $html = ''; // Load the necessary files if they haven't yet been loaded if (!isset($this->_loaded['tabs'])) { $this->_loaded['tabs'] = true; } $id = strtolower($config->id); $attribs = KHelperArray::toString($config->attribs); $html .= "\n\t\t\t<script>\n\t\t\t\twindow.addEvent('domready', function(){ new KTabs('tabs-" . $id . "', " . json_encode($config->toData($config->options)) . "); });\n\t\t\t</script>"; $html .= '<dl class="tabs" id="tabs-' . $id . '" ' . $attribs . '>'; return $html; }
/** * Constructor. * * @param object An optional KConfig object with configuration options. */ public function __construct(KConfig $config = null) { //If no config is passed create it if (!isset($config)) { $config = new KConfig(); } parent::__construct($config); //Set the action $this->_action = $config->action; //Set the dispatched state $this->_dispatched = $config->dispatched; // Mixin the command chain $this->mixin(new KMixinCommandchain($config->append(array('mixer' => $this)))); //Set the request $this->setRequest((array) KConfig::toData($config->request)); }
/** * Sanitize a value * * If the value passed for sanitisation is a json encoding string it will be decoded, * otherwise the value will be encoded. * * @param scalar Value to be sanitized * @return string */ protected function _sanitize($value) { $result = null; //Try to decode the string if(is_string($value)) { $result = json_decode($value); } //Encode the data if it could not be decode if(is_null($result)) { if($value instanceof KConfig) { $value = KConfig::toData($value); } $result = json_encode($value); } return $result; }
public function __construct(KConfig $config) { parent::__construct($config); $this->_database = $config->database; $this->_name = $config->name; // Set the identity column $this->_identity_column = $config->identity_column; //Set the default column mappings $this->_column_map = $config->column_map ? $config->column_map->toArray() : array(); if (!isset($this->_column_map['id']) && isset($this->_identity_column)) { $this->_column_map['id'] = $this->_identity_column; } // TODO: Set the column filters if (!empty($config->filters) && false) { foreach ($config->filters as $column => $filter) { $this->getColumn($column, true)->filter = KConfig::toData($filter); } } // Mixin a command chain $this->mixin(new KMixinCommand($config->append(array('mixer' => $this)))); // Mixin the behavior interface $this->mixin(new KMixinBehavior($config)); }
/** * Dispatch the controller * * @param object A command context object * @return mixed */ protected function _actionDispatch(KCommandContext $context) { //Set the default controller if ($context->data) { $this->_controller_default = KConfig::toData($context->data); } //Set the date in the context $context->data = $this->getData(); //Execute the controller $result = $this->getController()->execute($this->getAction(), $context); //Set the response header if ($context->status) { header(KHttpResponse::getHeader($context->status)); } return $result; }
/** * Generic delete function * * @param KCommandContext A command context object * @return KDatabaseRowset A rowset object containing the deleted rows */ protected function _actionDelete(KCommandContext $context) { $data = $this->getModel()->getData(); if(count($data)) { $data->setData(KConfig::toData($context->data)); //Only throw an error if the action explicitly failed. if($data->delete() === false) { $error = $data->getStatusMessage(); $context->setError(new KControllerException( $error ? $error : 'Delete Action Failed', KHttpResponse::INTERNAL_SERVER_ERROR )); } else $context->status = KHttpResponse::NO_CONTENT; } else $context->setError(new KControllerException('Resource Not Found', KHttpResponse::NOT_FOUND)); return $data; }
/** * Registers a callback function * * If the callback has already been registered. It will not be re-registered. * If params are passed those will be merged with the existing paramaters. * * @param string|array The command name to register the callback for or an array of command names * @param callback The callback function to register * @param array|object An associative array of config parameters or a KConfig object * @return KObject The mixer object */ public function registerCallback($commands, $callback, $params = array()) { $commands = (array) $commands; $params = (array) KConfig::toData($params); foreach ($commands as $command) { $command = strtolower($command); if (!isset($this->_callbacks[$command])) { $this->_callbacks[$command] = array(); $this->_params[$command] = array(); } //Don't re-register commands. $index = array_search($callback, $this->_callbacks[$command], true); if ($index === false) { $this->_callbacks[$command][] = $callback; $this->_params[$command][] = $params; } else { $this->_params[$command][$index] = array_merge($this->_params[$command][$index], $params); } } return $this->_mixer; }
/** * Generic delete function * * @param KCommandContext A command context object * @return KDatabaseRowset A rowset object containing the deleted rows */ protected function _actionDelete(KCommandContext $context) { $rowset = $this->getModel()->getList(); if (count($rowset)) { $rowset->setData(KConfig::toData($context->data)); if ($rowset->delete()) { $context->status = KHttpResponse::NO_CONTENT; } else { $context->status = KHttpResponse::INTERNAL_SERVER_ERROR; } } else { $context->status = KHttpResponse::NOT_FOUND; } return $rowset; }
/** * Register one or more behaviors to the controller * * @param array Array of one or more behaviors to add. * @return KControllerAbstract */ public function addBehavior($behaviors) { $behaviors = (array) KConfig::toData($behaviors); foreach($behaviors as $behavior) { if (!($behavior instanceof KControllerBehaviorInterface)) { $behavior = $this->getBehavior($behavior); } //Add the behaviors $this->_behaviors[$behavior->getIdentifier()->name] = $behavior; if($this->getCommandChain()->enqueue($behavior)) { $this->_actions = null; //reset the actions } } return $this; }
/** * Render a toolbar command * * @param array An optional array with configuration options * @return string Html */ public function command($config = array()) { $config = new KConfig($config); $config->append(array( 'command' => NULL )); $command = $config->command; //Add a toolbar class $command->attribs->class->append(array('toolbar')); //Create the id $id = 'toolbar-'.$command->id; $command->attribs->class = implode(" ", KConfig::toData($command->attribs->class)); $html = '<td class="button" id="'.$id.'">'; $html .= ' <a '.KHelperArray::toString($command->attribs).'>'; $html .= ' <span class="'.$command->icon.'" title="'.JText::_($command->title).'"></span>'; $html .= JText::_($command->label); $html .= ' </a>'; $html .= '</td>'; return $html; }
public function select($query = null, $mode = KDatabase::FETCH_ROWSET) { if (!($query instanceof ComLearnDatabaseTableSelectorDefault)) { throw new ComLearnDatabaseTableException('Query Builder must be an instance of ComLearnDatabaseTableSelectorDefault'); } $result = $query->find($this->getStorage()); switch($mode) { case KDatabase::FETCH_ROW : { $data = $this->getRow(); if(!empty($result)) { $data->setData($result[0], false)->setStatus(KDatabase::STATUS_LOADED); } break; } case KDatabase::FETCH_ROWSET : { $data = $this->getRowset(); if(!empty($result)) { $data->addData($result, false); } break; } } return KConfig::toData($data); }
/** * Preforms a show query * * @param string|object A full SQL query to run. Data inside the query should be properly escaped. * @param integer The fetch mode. Controls how the result will be returned to the caller. This * value must be one of the KDatabase::FETCH_* constants. * @return mixed The return value of this function on success depends on the fetch type. * In all cases, FALSE is returned on failure. */ public function show($query, $mode = KDatabase::FETCH_ARRAY_LIST) { $context = $this->getCommandContext(); $context->query = $query; $context->operation = KDatabase::OPERATION_SHOW; $context->mode = $mode; // Excute the insert operation if($this->getCommandChain()->run('before.show', $context) !== false) { if($result = $this->execute( $context->query, KDatabase::RESULT_USE)) { switch($context->mode) { case KDatabase::FETCH_ARRAY : $context->result = $this->_fetchArray($result); break; case KDatabase::FETCH_ARRAY_LIST : $context->result = $this->_fetchArrayList($result); break; case KDatabase::FETCH_FIELD : $context->result = $this->_fetchField($result); break; case KDatabase::FETCH_FIELD_LIST : $context->result = $this->_fetchFieldList($result); break; case KDatabase::FETCH_OBJECT : $context->result = $this->_fetchObject($result); break; case KDatabase::FETCH_OBJECT_LIST : $context->result = $this->_fetchObjectList($result); break; default : $result->free(); } } $this->getCommandChain()->run('after.show', $context); } return KConfig::toData($context->result); }
/** * Adds one or multiple filters for template transformation * * @param array Array of one or more behaviors to add. * @return KTemplate */ public function addFilter($filters) { $filters = (array) KConfig::toData($filters); foreach($filters as $filter) { if(!($filter instanceof KTemplateFilterInterface)) { $identifier = (string) $filter; $filter = KTemplateFilter::factory($filter); } else $identifier = (string) $filter->getIdentifier(); //Enqueue the filter in the command chain $this->getCommandChain()->enqueue($filter); //Store the filter $this->_filters[$identifier] = $filter; } return $this; }
protected function _afterAdapterSelect(KCommandContext $context) { //Get the data $rows = KConfig::toData($context->result); if(is_array($rows)) { $children = array(); $result = array(); /* * Create the children array */ foreach($rows as $key => $row) { $path = array(); $parent = $row['parent_id']; //Store node by parent if(!empty($parent) && isset($rows[$parent])) { $children[$parent][] = $key; } } /* * Create the result array */ foreach($rows as $key => $row) { if(empty($row['parent_id'])) { $result[$key] = $row; if(isset($children[$key])) { $this->_getChildren($rows, $children, $key, $result); } } } /* * If we have not been able to match all children to their parents don't perform * the path enumeration for the children. */ if(count($result) == count($rows)) { if($context->limit) { $result = array_slice( $result, $context->offset, $context->limit, true); } /* * Create the paths of each node */ foreach($result as $key => $row) { $path = array(); $parent = $row['parent_id']; if(!empty($parent)) { $table = $this->_table; //Create node path $path = $result[$parent]['path']; $id = $result[$parent][$table->getIdentityColumn()]; $path[] = $id; } //Set the node path $result[$key]['path'] = $path; } } else $result = $rows; $context->result = $result; } }
/** * Table select method * * The name of the resulting row(set) class is based on the table class name * eg <Mycomp>Table<Tablename> -> <Mycomp>Row(set)<Tablename> * * This function will return an empty rowset if called without a parameter. * * @param mixed KDatabaseQuery, query string, array of row id's, or an id or null * @param integer The database fetch style. Default FETCH_ROWSET. * @return KDatabaseRow or KDatabaseRowset depending on the mode. By default will * return a KDatabaseRowset */ public function select($query = null, $mode = KDatabase::FETCH_ROWSET) { //Create query object if (is_string($query) || is_array($query) && is_numeric(key($query))) { $key = $this->getIdentityColumn(); $values = (array) $query; $query = $this->_database->getQuery()->where($key, 'IN', $values); } if (is_array($query) && !is_numeric(key($query))) { $columns = $this->mapColumns($query); $query = $this->_database->getQuery(); foreach ($columns as $column => $value) { $query->where($column, '=', $value); } } if ($query instanceof KDatabaseQuery) { if (!is_null($query->columns) && !count($query->columns)) { $query->select('*'); } if (!count($query->from)) { $query->from($this->getName() . ' AS tbl'); } } //Create commandchain context $context = $this->getCommandContext(); $context->operation = KDatabase::OPERATION_SELECT; $context->query = $query; $context->table = $this->getBase(); $context->mode = $mode; if ($this->getCommandChain()->run('before.select', $context) !== false) { //Fetch the data based on the fecthmode if ($context->query) { $data = $this->_database->select($context->query, $context->mode, $this->getIdentityColumn()); //Map the columns if ($context->mode != KDatabase::FETCH_FIELD || $context->mode != KDatabase::FETCH_FIELD_LIST) { if ($context->mode % 2) { foreach ($data as $key => $value) { $data[$key] = $this->mapColumns($value, true); } } else { $data = $this->mapColumns(KConfig::toData($data), true); } } } switch ($context->mode) { case KDatabase::FETCH_ROW: $context->data = $this->getRow(); if (isset($data) && !empty($data)) { $context->data->setData($data)->setStatus(KDatabase::STATUS_LOADED); } break; case KDatabase::FETCH_ROWSET: $context->data = $this->getRowset(); if (isset($data) && !empty($data)) { $context->data->addData($data, false); } break; default: $context->data = $data; } $this->getCommandChain()->run('after.select', $context); } return KConfig::toData($context->data); }
/** * * Method to read child nodes of a folder * * @param array $config */ public static function getNodes($config = array()) { $config = new KConfig($config); $config->append(array( 'path' => null, // path to the directory 'type' => null, // folders or files, null for both 'recurse' => false, // boolean or integer to specify the depth 'fullpath' => false, // true to return full paths, false to return basename only 'filter' => null, // either an array of file extensions, a regular expression or a callback function 'map' => null, // a callback to return values from items in the iterator 'exclude' => array('.svn', '.git', 'CVS') // an array of values to exclude from results )); $exclude = KConfig::toData($config->exclude); $filter = KConfig::toData($config->filter); $map = KConfig::toData($config->map); $recurse = $config->recurse; $results = array(); foreach (new self($config->path) as $file) { if ($file->isDot() || in_array($file->getFilename(), $exclude) ) continue; if ($file->isDir() && !$file->isDot() && $recurse) { $clone = clone $config; $clone->path = $file->getPathname(); $clone->recurse = is_int($config->recurse) ? $config->recurse - 1 : $config->recurse; $child_results = self::getNodes($clone); } if ($config->type) { $method = 'is'.ucfirst($config->type === 'files' ? 'file' : 'dir'); if (!$file->$method()) { continue; } } if ($filter) { if (is_callable($filter)) { $ignore = call_user_func($filter, $file) === false; } else if (is_array($filter)) { $ignore = !in_array($file->getExtension(), $filter); } else if (is_string($filter)) { $ignore = !preg_match("/$filter/", $file->getFilename()); } if ($ignore) { continue; } } if (is_callable($map)) { $result = call_user_func($map, $file); } else { $result = $config->fullpath ? $file->getPathname() : $file->getFilename(); } $results[] = $result; if (!empty($child_results)) { $results = array_merge($results, $child_results); } } return $results; }
/** * Utility function to map an array to a string * * @static * @param array|object The array or object to transform into a string * @param string The inner glue to use, default '=' * @param string The outer glue to use, default ' ' * @param boolean * @return string The string mapped from the given array */ public static function toString($array = null, $inner_glue = '=', $outer_glue = ' ', $keepOuterKey = false) { $output = array(); if($array instanceof KConfig) { $data = array(); foreach($array as $key => $item) { $data[$key] = (string) $item; } $array = $data; } if(is_object($array)) { $array = (array) KConfig::toData($array); } if(is_array($array)) { foreach($array as $key => $item) { if(is_array($item)) { if($keepOuterKey) { $output[] = $key; } // This is value is an array, go and do it again! $output[] = KHelperArray::toString($item, $inner_glue, $outer_glue, $keepOuterKey); } else $output[] = $key.$inner_glue.'"'.str_replace('"', '"', $item).'"'; } } return implode($outer_glue, $output); }
/** * Set the model state properties * * This function overloads the KObject::set() function and only acts on state properties it * will reset (unsets) the $_list, $_item and $_total model properties when a state changes. * * @param string|array|object The name of the property, an associative array or an object * @param mixed The value of the property * @return KModelAbstract */ public function set( $property, $value = null ) { $changed = false; if(is_object($property)) { $property = (array) KConfig::toData($property); } if(is_array($property)) { foreach($property as $key => $value) { if(isset($this->_state->$key) && $this->_state->$key != $value) { $changed = true; break; } } $this->_state->setData($property); } else { if(isset($this->_state->$property) && $this->_state->$property != $value) { $changed = true; } $this->_state->$property = $value; } if($changed) { unset($this->_list); unset($this->_item); unset($this->_total); } return $this; }
/** * Render a menubar command * * @param array An optional array with configuration options * @return string Html */ public function command($config = array()) { $config = new KConfig($config); $config->append(array( 'command' => null )); $command = $config->command; //Add a nolink class if the command is disabled if($command->disabled) { $command->attribs->class->append(array('nolink')); } if($command->active) { $command->attribs->class->append(array('active')); } //Explode the class array $command->attribs->class = implode(" ", KConfig::toData($command->attribs->class)); if ($command->disabled) { $html = '<span '.KHelperArray::toString($command->attribs).'>'.JText::_($command->label).'</span>'; } else { $html = '<a href="'.$command->href.'" '.KHelperArray::toString($command->attribs).'>'.JText::_($command->label).'</a>'; } return $html; }
/** * Utility function to map an array to a string * * @static * @param array|object The array or object to transform into a string * @param string The inner glue to use, default '=' * @param string The outer glue to use, default ' ' * @param boolean * @return string The string mapped from the given array */ public static function toString($array = null, $inner_glue = '=', $outer_glue = ' ', $keepOuterKey = false) { $output = array(); if (is_object($array)) { $array = (array) KConfig::toData($array); } if (is_array($array)) { foreach ($array as $key => $item) { if (is_array($item)) { if ($keepOuterKey) { $output[] = $key; } // This is value is an array, go and do it again! $output[] = KHelperArray::toString($item, $inner_glue, $outer_glue, $keepOuterKey); } else { $output[] = $key . $inner_glue . '"' . $item . '"'; } } } return implode($outer_glue, $output); }