/** * Get the list of commands * * Will attempt to use information from the xml manifest if possible * * @return array */ public function getCommands() { $name = $this->getController()->getIdentifier()->name; $package = $this->_identifier->package; $manifest = JPATH_ADMINISTRATOR.'/components/com_'.$package.'/manifest.xml'; if(file_exists($manifest)) { $xml = simplexml_load_file($manifest); if(isset($xml->administration->submenu)) { foreach($xml->administration->submenu->children() as $menu) { $view = (string)$menu['view']; $this->addCommand(JText::_((string)$menu), array( 'href' => JRoute::_('index.php?option=com_'.$package.'&view='.$view), 'active' => ($name == KInflector::singularize($view)) )); } } } return parent::getCommands(); }
public function render() { $name = $this->getName(); $img = KTemplateAbstract::loadHelper('admin::com.ninja.helper.default.img', '/32/' . $name . '.png'); if ($img) { KTemplateAbstract::loadHelper('admin::com.ninja.helper.default.css', '.toolbar .icon-32-' . $name . ' { background-image: url(' . $img . '); }'); } $text = JText::_($this->_options['text']); $view = KRequest::get('get.view', 'cmd'); $link = ' href="' . JRoute::_($this->getLink()) . '"'; $html = array(); // Sanitize the url since we can't trust the server var $url = KFactory::get('lib.koowa.filter.url')->sanitize($this->getLink()); // Create the URI object $uri = KFactory::tmp('lib.koowa.http.uri', array('uri' => $url)); $query = $uri->getQuery(1); $html[] = '<td class="button" id="' . $this->getId() . '">'; $active = $view == KInflector::variablize(KInflector::pluralize($query['view'])) || $view == KInflector::variablize(KInflector::singularize($query['view'])); $hide = !KInflector::isPlural($view); if ($active || $hide || !$this->modal) { $html[] = '<a class="toolbar inactive">'; } else { $html[] = '<a' . $link . ' onclick="' . $this->getOnClick() . '" class="toolbar">'; } $html[] = '<span class="' . $this->getClass() . '" title="' . $text . '">'; $html[] = '</span>'; $html[] = $text; if (!$active && !$hide || $this->modal) { $html[] = '</a>'; } else { $html[] = '</a>'; } $html[] = '</td>'; return implode(PHP_EOL, $html); }
/** * Initializes the options for the object * * Called from {@link __construct()} as a first step of object instantiation. * * @param object An optional KConfig object with configuration options. * @return void */ protected function _initialize(KConfig $config) { $package = $this->_identifier->package; $name = KInflector::singularize($this->_identifier->name); $config->append(array('xml_path' => JPATH_ADMINISTRATOR . '/components/com_' . $package . '/views/' . $name . '/tmpl/' . $name . '.xml')); parent::_initialize($config); }
public function humanize($config = array()) { $config = new KConfig($config); $config->append(array( 'sizes' => array('Bytes', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb') )); $bytes = $config->size; $result = ''; $format = (($bytes > 1024*1024 && $bytes % 1024 !== 0) ? '%.2f' : '%d').' %s'; foreach ($config->sizes as $s) { $size = $s; if ($bytes < 1024) { $result = $bytes; break; } $bytes /= 1024; } if ($result == 1) { $size = KInflector::singularize($size); } return sprintf($format, $result, JText::_($size)); }
/** * @param array $options * @return object */ public function getRow(array $options = array()) { $identifier = clone $this->getIdentifier(); $identifier->path = array('database', 'row'); $identifier->name = 'api_' . KInflector::singularize($this->getIdentifier()->name); return $this->getService($identifier, $options); }
/** * Initializes the options for the object. * * Called from {@link __construct()} as a first step of object instantiation. * * @param object An optional KConfig object with configuration options. */ protected function _initialize(KConfig $config) { $child = clone $this->_parent; $child->name = KInflector::singularize($config->name); $config->append(array('entityset' => 'anahita:domain.entityset.onetomany', 'cardinality' => 'many', 'child_key' => $this->_parent->name, 'parent_delete' => AnDomain::DELETE_CASCADE, 'child' => $child)); parent::_initialize($config); }
public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { if ($text) { $rows = array(); $rowset = KService::get('com://admin/kutafuta.model.terms')->type($phrase)->search($text)->getList(); foreach ($rowset as $row) { // We have table and row. // Row is always multiple but we check non the less. $parts = explode('_', $row->table); $data = KService::get('com://site/' . $parts[0] . '.model.' . KInflector::pluralize($parts[1]))->id($row->row)->getItem(); if (empty($data->id)) { continue; } $result = new stdClass(); $result->title = $data->title; $result->metadesc = $data->meta_description; $result->metakey = $data->meta_keywords; $result->created = $data->created_on; $result->text = $data->introtext . $data->fulltext; $result->href = 'index.php?option=com_' . $parts[0] . '&view=' . KInflector::singularize($parts[1]) . '&id=' . $row->row; $rows[] = $result; } return $rows; } }
protected function _commandNew(KControllerToolbarCommand $command) { $option = $this->getIdentifier()->package; $view = KInflector::singularize($this->getIdentifier()->name); $section = $this->getController()->getModel()->get('section'); $command->attribs->href = JRoute::_('index.php?option=com_' . $option . '&view=' . $view . '§ion=' . $section); }
/** * @param KDatabaseQuery $query */ protected function _buildQueryJoins(KDatabaseQuery $query) { $state = $this->_state; parent::_buildQueryJoins($query); $iso_code = substr(JFactory::getLanguage()->getTag(), 0, 2); if ($iso_code != 'en') { $prefix = $iso_code . '_'; } if (is_array($state->type)) { $subquery = '('; $i = 1; foreach ($state->type as $type) { $subquery .= 'SELECT ' . KInflector::pluralize($type) . '_' . KInflector::singularize($type) . '_id AS id, LOWER("' . strtoupper(KInflector::pluralize($type)) . '_' . strtoupper(KInflector::pluralize($type)) . '") AS test FROM #__' . $prefix . KInflector::pluralize($type) . '_' . KInflector::pluralize($type) . ' AS ' . KInflector::pluralize($type) . ' WHERE enabled = 1 AND frontpage = 1'; if (KInflector::singularize($type) == 'event') { $subquery .= ' AND start_date >= CURDATE()'; } if ($i < count($state->type)) { $subquery .= ' UNION ALL '; } $i++; } $subquery .= ')'; $query->join[] = array('type' => 'INNER', 'table' => $subquery . 'AS b', 'condition' => array('tbl.row = b.id AND tbl.table = b.test')); } }
public function translations($config = array()) { $config = new KConfig($config); $config->append(array('row' => null, 'table' => '')); // First for our knowledge we get the original language (if exists.) $original = $this->_getOriginalLanguage($config->row, $config->table); $html = '<style src="media://com_translations/css/translations.css" />'; $view = KInflector::singularize(KRequest::get('get.view', 'string')); foreach ($this->_getLanguages() as $language) { $relation = $this->_getLanguage($config, $language->lang_code); if ($language->lang_code == $original->iso_code) { $html .= ' <a href="' . $this->getTemplate()->getView()->createRoute('view=' . $view . '&id=' . $config->row . '&backendlanguage=' . $language->lang_code) . '"><div class="badge badge-info">' . strtoupper(substr($language->lang_code, 0, 2)) . '</a></div>'; } else { if ($relation->translated) { $html .= ' <a href="' . $this->getTemplate()->getView()->createRoute('view=' . $view . '&id=' . $config->row . '&backendlanguage=' . $language->lang_code) . '"><div class="badge badge-success">' . strtoupper(substr($language->lang_code, 0, 2)) . '</a></div>'; } else { if (strtotime('+ 2 weeks', strtotime($original->created_on)) > strtotime(date('d-m-Y H:i:s'))) { $html .= ' <a href="' . $this->getTemplate()->getView()->createRoute('view=' . $view . '&id=' . $config->row . '&backendlanguage=' . $language->lang_code) . '"><div class="badge badge-warning">' . strtoupper(substr($language->lang_code, 0, 2)) . '</a></div>'; } else { if (strtotime('+ 2 weeks', strtotime($original->created_on)) < strtotime(date('d-m-Y H:i:s'))) { $html .= ' <a href="' . $this->getTemplate()->getView()->createRoute('view=' . $view . '&id=' . $config->row . '&backendlanguage=' . $language->lang_code) . '"><div class="badge badge-important">' . strtoupper(substr($language->lang_code, 0, 2)) . '</a></div>'; } } } } } return $html; }
/** * Generates an HTML optionlist based on the distinct data from a model column. * * The column used will be defined by the name -> value => column options in * cascading order. * * If no 'model' name is specified the model identifier will be created using * the helper identifier. The model name will be the pluralised package name. * * If no 'value' option is specified the 'name' option will be used instead. * If no 'text' option is specified the 'value' option will be used instead. * * @param array An optional array with configuration options * @return string Html * @see __call() */ protected function _splitview($config = array()) { $config = new KConfig($config); $config->append(array('id' => 'splitview', 'name' => '', 'package' => 'com_' . $this->getIdentifier()->package))->append(array('master_view' => KInflector::pluralize($config->name), 'detail_view' => KInflector::singularize($config->name)))->append(array('options' => array('master_url' => '?option=' . $config->package . '&view=' . $config->master_view . '&format=json&sort=created_on&direction=desc', 'detail_url' => '?option=' . $config->package . '&view=' . $config->detail_view . '&format=raw', 'label' => array('empty' => JText::_('No ' . KInflector::humanize($config->master_view) . '.'), 'select' => JText::_('No ' . KInflector::humanize($config->detail_view) . ' selected.'))))); KFactory::get('admin::com.ninja.helper.default')->js('/splitview.js'); KFactory::get('admin::com.ninja.helper.default')->js("\njQuery(function(\$){\n\t\t\t\$('#" . $config->id . "').splitview(" . json_encode($config->options->toArray()) . ");\n\t\t});\n"); return '<div id="' . $config->id . '" class="splitview"></div>'; }
public function getOnClick() { $option = KRequest::get('get.option', 'cmd'); $view = KInflector::singularize(KRequest::get('get.view', 'cmd')); $json = "{method:'get', url:'index.php', params:{option:'{$option}',view:'{$view}',id:id}}"; $msg = JText::_('Please select an item from the list'); return 'var id = Koowa.Grid.getFirstSelected();' . 'if(id){new Koowa.Form(' . $json . ').submit();} ' . 'else { alert(\'' . $msg . '\'); return false; }'; }
public function render() { $option = KRequest::get('get.option', 'cmd'); $view = KInflector::singularize(KRequest::get('get.view', 'cmd')); $link = 'index.php?option=' . $option . '&view=' . $view; $this->attribs->set(array('class' => 'toolbar', 'href' => $this->_parent->createRoute($link))); return parent::render(); }
/** * Search the mixin method map and call the method or trigger an error * * This function check to see if the method exists in the mixing map if not * it will call the 'listbox' function. The method name will become the 'name' * in the config array. * * This can be used to auto-magically create select filters based on the * function name. * * @param string The function name * @param array The function arguments * @throws BadMethodCallException If method could not be found * @return mixed The result of the function */ public function __call($method, array $arguments) { if (!in_array($method, $this->getMethods())) { $config = $arguments[0]; $config['name'] = KInflector::singularize(strtolower($method)); return $this->_listbox($config); } return parent::__call($method, $arguments); }
/** * Return a scope using a key or not if not found. * * @param string $scope * * @return ComSearchDomainScope */ public function find($scope) { if (strpos($scope, '.') === false) { $scope = $scope . '.' . KInflector::singularize($scope); } if (isset($this[$scope])) { return $this[$scope]; } return; }
/** * Initializes the options for the object. * * Called from {@link __construct()} as a first step of object instantiation. * * @param object An optional KConfig object with configuration options. */ protected function _initialize(KConfig $config) { $identifier = clone $this->_parent; $identifier->name = KInflector::singularize($this->_name); $config->append(array('entityset' => 'anahita:domain.entityset.manytomany', 'target' => $identifier, 'target_child_key' => KInflector::variablize($identifier->name), 'target_parent_key' => 'id')); if (!$config->as) { //keep the as always the same for the two many to many relationship $names = array($config->parent->name, KInflector::singularize($config->name)); sort($names); $config->as = $names[0] . ucfirst(KInflector::pluralize($names[1])); } parent::_initialize($config); }
/** * Method to set a view object attached to the controller * * @param mixed An object that implements KObjectServiceable, KServiceIdentifier object * or valid identifier string * @throws KControllerException If the identifier is not a view identifier * @return KControllerAbstract */ public function setView($view) { if (is_string($view) && strpos($view, '.') === false) { if (!isset($this->_request->view)) { if ($this->getModel()->getState()->isUnique()) { $view = KInflector::singularize($view); } else { $view = KInflector::pluralize($view); } } } return parent::setView($view); }
/** * @param $context */ protected function _saveCache($context) { if ($context->data->getModified()) { $redis = $this->_getRedis(); $identifier = clone $context->caller->getIdentifier(); $identifier->path = array('model'); $row = $this->getService($identifier)->id($context->data->id)->cache(0)->getItem(); $filter = $this->getService('koowa:filter.slug'); $redis->set(KInflector::singularize($identifier->name) . ':' . $row->id, serialize($row->toArray())); $redis->lpush(KInflector::pluralize($identifier->name), $row->id); $redis->sadd('ctas_involvement:' . $filter->sanitize($row->ctas_involvement), $row->id); } }
public function __construct(KConfig $options) { $this->setMethod('edit'); parent::__construct($options); $this->attribs->class .= ' invalid'; $url = clone KRequest::url(); $query = $url->getQuery(1); if (empty($query['view'])) { return; } $query['view'] = KInflector::singularize($query['view']); $url->setQuery($query); $this->attribs->href = (string) $url; }
/** * Saves the current row and redirects to a new edit form * * @param KCommandContext $context * * @return KDatabaseRowInterface A row object containing the saved data */ protected function _actionSave2new(KCommandContext $context) { // Cache and lock the referrer since _ActionSave would unset it $referrer = $this->getReferrer(); $this->lockReferrer(); $result = $this->save($context); // Re-set the referrer KRequest::set('cookie.referrer', (string) $referrer); $identifier = $this->getMixer()->getIdentifier(); $view = KInflector::singularize($identifier->name); $url = sprintf('index.php?option=com_%s&view=%s', $identifier->package, $view); $this->setRedirect($this->getService('koowa:http.url', array('url' => $url))); return $result; }
public function getLink() { $option = $this->_options['option']; $view = KInflector::singularize(KRequest::get('get.view', 'cmd')); //return 'index.php?option='.$option.'&view=plugins&layout=default'; // modify url $url = clone KRequest::url(); $query = $url->getquery(1); //$query['view'] = KInflector::singularize(KRequest::get('get.view', 'cmd')); $query['view'] = 'dashboard'; $query['tmpl'] = 'component'; $url->setQuery($query); // render html return $url; }
/** * Adds a resource to the set the set of resources. * * @param string|array $config */ public function insert($config) { if (is_string($config)) { $config = array('name' => $config); } $config = new KConfig($config); if (empty($config->link) && !empty($this->_resources)) { $name = KInflector::singularize($this->main()->getName()); $config->link = array('child' => $name . '_id', 'parent' => 'id'); } $config->append(array('columns' => $this->_store->getColumns($config->name))); $resource = new AnDomainResource($config); $this->_resources[$resource->getAlias()] = $resource; return $this; }
public function _createToolbar() { $identifier = $this->getToolbar(); $name = $identifier->name; $package = $identifier->package; KFactory::get('admin::com.ninja.helper.default')->css('/toolbar.css'); $img = KInflector::isPLural($name) ? KFactory::get('admin::com.ninja.helper.default')->img('/48/' . $name . '.png') : KFactory::get('admin::com.ninja.helper.default')->img('/48/' . KInflector::pluralize($name) . '.png'); if (!$img) { $img = KInflector::isSingular($name) ? KFactory::get('admin::com.ninja.helper.default')->img('/48/' . $name . '.png') : KFactory::get('admin::com.ninja.helper.default')->img('/48/' . KInflector::singularize($name) . '.png'); } if ($img) { KFactory::get('admin::com.ninja.helper.default')->css('.header.icon-48-' . $name . ' { background-image: url(' . $img . '); }'); } return KFactory::get($identifier, array('icon' => $name)); }
/** * Parse the segments of a URL. * * @param array The segments of the URL to parse. * * @return array The URL attributes to be used by the application. */ public function parse(&$segments) { $vars = array(); if (empty($segments)) { $vars['view'] = $this->getIdentifier()->package; } elseif (count($segments) == 1) { $identifier = array_pop($segments); if (is_numeric($identifier)) { $vars['id'] = (int) $identifier; } else { $vars['alias'] = $identifier; } $vars['view'] = KInflector::singularize($this->getIdentifier()->package); } return $vars; }
/** * Returns a controller object. * * @param string $name Controller name * * @return KControllerAbstract */ public function getController($name) { $name = KInflector::singularize($name); if (!isset(self::$_controllers['controller.' . $name])) { if (strpos($name, '.') == false) { $identifier = clone $this->getIdentifier(); $identifier->name = $name; $identifier->path = array('controller'); } else { $identifier = $this->getIdentifier($name); } $controller = $this->getService($identifier, array('request' => array())); self::$_controllers['controller.' . $name] = $controller; } return self::$_controllers['controller.' . $name]; }
/** * Sortables * * @param array An optional array with configuration options * @return string html */ public function sortable($config = array()) { $config = new KConfig($config); $config->append(array('option' => KRequest::get('get.option', 'cmd'), 'view' => KInflector::singularize(KRequest::get('get.view', 'cmd')), 'selector' => 'table tbody.sortable'))->append(array('options' => array('handle' => 'td.handle', 'numcolumn' => '.grid-count', 'adapter' => array('type' => 'koowa', 'options' => array('url' => '?option=' . $config->option . '&view=' . $config->view . '&format=json', 'data' => array('_token' => JUtility::getToken(), 'action' => 'edit'), 'key' => 'order', 'offset' => 'relative'))))); // Load the necessary files if they haven't yet been loaded if (!isset($this->_loaded['sortable'])) { KFactory::get('admin::com.ninja.helper.default')->js('/sortables.js'); KFactory::get('admin::com.ninja.helper.default')->css('/sortables.css'); $this->_loaded['sortable'] = true; } $signature = md5(serialize(array($config->selector, $config->options))); if (!isset($this->_loaded[$signature])) { $options = !empty($config->options) ? $config->options->toArray() : array(); KFactory::get('admin::com.ninja.helper.default')->js("\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"); $this->_loaded[$signature] = true; } }
function BlogParseRoute($segments) { $item = JSite::getMenu()->getActive(); //We are using the alias, circonvent the auto-segment decoding $segments = str_replace(':', '-', $segments); $vars = array(); $vars['view'] = $item->query['view']; if (count($segments) > 0) { $vars['view'] = KInflector::singularize($item->query['view']); if ($id = (int) $segments[0]) { $vars['id'] = $id; } else { $vars['slug'] = $segments[0]; } } return $vars; }
/** * Sets the * * @return string */ public function display() { //Get the view name $name = $this->getName(); //set the state data to the view $this->_data = array_merge($this->_state->toArray(), $this->_data); //Assign the data of the model to the view if ($items = $this->_state->getList()) { $this->_data[KInflector::pluralize($name)] = $items; $this->_data['items'] = $items; } if ($item = $this->_state->getItem()) { $this->_data[KInflector::singularize($name)] = $item; $this->_data['item'] = $item; } return parent::display(); }
/** * @param KConfig $config */ public function __construct(KConfig $config) { parent::__construct($config); //Dynamic state injection based on relations. if ($this->getTable()->hasBehavior('relationable')) { $relations = $this->getTable()->getBehavior('relationable')->getRelations(); foreach ($relations as $children) { foreach ($children as $name => $relation) { if (KInflector::isPlural($name)) { $this->_state->insert($name, 'raw'); } $this->_state->insert(KInflector::singularize($name), 'int'); } } } $this->_state->insert('ancestors', 'raw'); }
public function __construct(array $options = array()) { // Initialize the options $options = $this->_initialize($options); // Mixin the KClass $this->mixin(new KMixinClass($this, 'FilterArray')); // Assign the classname with values from the config $this->setClassName($options['name']); $classname = $this->getClassName(); if (empty($classname['suffix'])) { throw new KFilterArrayExeption('Incorrect classname: ' . get_class($this)); } if (!isset($options['filter'])) { $filtername = ucfirst($classname['prefix']) . 'Filter' . ucfirst(KInflector::singularize($classname['suffix'])); $options['filter'] = new $filtername($options); } $this->_filter = $options['filter']; }