/** * Get the path based on a class name * * @param string The class name * @return string|false Returns the path on success FALSE on failure */ public function findPath($classname, $basepath = null) { $path = false; if (strpos($classname, $this->_prefix) === 0) { $word = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $classname)); $parts = explode('_', $word); if (array_shift($parts) == 'tmpl') { $name = array_shift($parts); $file = array_pop($parts); if (count($parts)) { if ($parts[0] != 'view') { foreach ($parts as $key => $value) { $parts[$key] = KInflector::pluralize($value); } } else { $parts[0] = KInflector::pluralize($parts[0]); } $path = implode('/', $parts) . '/' . $file; } else { $path = $file; } $path = $this->_basepath . '/templates/' . $name . '/' . $path . '.php'; } } return $path; }
/** * 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); }
/** * 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 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; } }
/** * Delete Command for an entity. * * @param LibBaseTemplateObject $command The action object */ protected function _commandDelete($command) { $entity = $this->getController()->getItem(); $name = KInflector::pluralize($this->getController()->getIdentifier()->name); $redirect = 'option=com_' . $this->getIdentifier()->package . '&view=' . $name; $command->append(array('label' => JText::_('LIB-AN-ACTION-DELETE')))->href(JRoute::_($entity->getURL()))->setAttribute('data-action', 'delete')->setAttribute('data-redirect', JRoute::_($redirect))->class('action-delete'); }
/** * Get the path based on an identifier * * @param object An Identifier object - com:[//application/]component.view.[.path].name * @return string|false Returns the path on success FALSE on failure */ protected function _pathFromIdentifier($identifier) { $path = false; if($identifier->type == 'yaml') { $parts = $identifier->path; $component = 'com_'.strtolower($identifier->package); //Store the basepath for re-use if($identifier->basepath) { $this->_basepath = $identifier->basepath; } if(!empty($identifier->name)) { if(count($parts)) { $path = KInflector::pluralize(array_shift($parts)); $path .= count($parts) ? '/'.implode('/', $parts) : ''; $path .= '/'.strtolower($identifier->name); } else $path = strtolower($identifier->name); } $path = $this->_basepath.'/components/'.$component.'/'.$path.'.yaml'; } return $path; }
/** * Generic function for setting the permissions * * @return void */ public function setPermissions($context) { //Temp fix if (KInflector::isPlural(KRequest::get('get.view', 'cmd')) || KRequest::type() == 'AJAX') { return; } $model = KFactory::get($this->getModel()); $table = KFactory::tmp(KFactory::get(KFactory::get('admin::com.ninja.helper.access')->models->assets)->getTable()); $query = $table->getDatabase()->getQuery(); $item = $model->getItem(); $identifier = $this->getIdentifier(); $id = $identifier->type . '_' . $identifier->package . '.' . $identifier->name . '.' . $item->id . '.'; $permissions = (array) KRequest::get('post.permissions', 'int'); $editable = KRequest::get('post.editpermissions', 'boolean', false); if (!$permissions && $editable) { $query->where('tbl.name', 'LIKE', $id . '%'); $table->select($query)->delete(); } $safe = array(); $query = $table->getDatabase()->getQuery()->where('name', 'like', $id . '%'); foreach ((array) KRequest::get('post.params.permissions', 'raw') as $group => $other) { $safe[] = $id . $group; } if ($safe) { $query->where('name', 'not in', $safe); } $table->select($query, KDatabase::FETCH_ROWSET)->delete(); foreach ($permissions as $usergroup => $rules) { foreach ($rules as $name => $permission) { KFactory::tmp(KFactory::get('admin::com.ninja.helper.access')->models->assets)->name($id . $usergroup . '.' . $name)->getItem()->setData(array('name' => $id . $usergroup . '.' . $name, 'level' => $permission))->save(); } } }
/** * @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 _updateLanguages($id, $items) { foreach ($items as $language => $item) { $model_identifier = clone $item->getIdentifier(); $model_identifier->path = array('model'); $model_identifier->name = KInflector::pluralize($model_identifier->name); // Original Data $data = $item->getData(); unset($data['id']); if (isset($data['featured'])) { unset($data['featured']); } $this->_checkName($item, false); $title = $item->title . ' (' . $this->count . ')'; $slug = $item->slug . '-' . $this->count; JFactory::getLanguage()->setLanguage($language); $row = $this->getService($model_identifier)->id($id)->getItem(); $row->setData($data); $row->title = $title; $row->enabled = 0; $row->slug = $slug; $row->translated = 0; if ($row->isRelationable()) { $row->setData(json_decode($row->ancestors)); $row->setData(json_decode($row->descendants)); } $row->save(); } }
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; }
/** * 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(); }
/** * Helper for creating DOM element ids used by javascript behaviors * * If no type and package identifiers were supplied, * uses the current option $_GET variable, and changing com_foo_bar to com-foo_bar. * '-' are used as separators, and in our javascript used to parse identifier strings. * If a form got the id com-foo_bar-people, * then we can assume that the toolbar will have the id toolbar-people, * * @author Stian Didriksen <*****@*****.**> * @param array | int $parts * @return string */ public function id($parts = array()) { if (!is_array($parts) && is_int($parts)) { $parts['id'] = (int) $parts; } // If we pass a string, set $parts back as an array in order to proceed. if (!is_array($parts)) { settype($parts, 'array'); } // Set the defaults, if needed $defaults = array(); if (!isset($parts['type.package'])) { // We only want to replace the first underscore, not the rest. $defaults['type_package'] = str_replace('com_', 'com-', KRequest::get('get.option', 'cmd')); } if (!isset($parts['view'])) { $view = KRequest::get('get.view', 'cmd'); // The view part always needs to be plural to allow ajax BREAD. if (KInflector::isSingular($view)) { $view = KInflector::pluralize($view); } $defaults['view'] = $view; } if (!isset($parts['id']) && KRequest::has('get.id', 'int')) { $defaults['id'] = KRequest::get('get.id', 'int'); } // Filter away parts that are unset on purpose using a null value, or a negative boolean. return implode('-', array_filter(array_merge($defaults, $parts))); }
public function setModel($model) { $model = parent::setModel($model); $model->package = KInflector::pluralize($this->_identifier->name); return $model; }
/** * Load the file for a class * * @param string $class The class that will be loaded * @return boolean True on success */ public static function loadClass($class) { // pre-empt further searching for the named class or interface. // do not use autoload, because this method is registered with // spl_autoload already. if (class_exists($class, false) || interface_exists($class, false)) { return; } // if class start with a 'Nooku' it is a Nooku class. // create the path and register it with the loader. switch (substr($class, 0, 6)) { case 'Picman': $word = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', substr_replace($class, '', 0, 6))); $parts = explode('_', $word); if (count($parts) > 1) { $path = KInflector::pluralize(array_shift($parts)) . DS . implode(DS, $parts); } else { $path = $word; } if (is_file(dirname(__FILE__) . DS . $path . '.php')) { KLoader::register($class, dirname(__FILE__) . DS . $path . '.php'); } break; } $classes = KLoader::register(); if (array_key_exists(strtolower($class), $classes)) { include $classes[strtolower($class)]; return true; } return false; }
public function order($config = array()) { $config = new KConfig($config); $config->append(array( 'name' => 'order', 'state' => null, 'attribs' => array(), 'model' => null, 'package' => $this->getIdentifier()->package, 'selected' => 0 )); //@TODO can be removed when name collisions fixed $config->name = 'order'; $app = $this->getIdentifier()->application; $identifier = 'com://'.$app.'/'.$config->package.'.model.'.($config->model ? $config->model : KInflector::pluralize($config->package)); $list = KFactory::get($identifier)->limit(0)->set($config->filter)->getList(); $options = array(); foreach($list as $item) { $options[] = $this->option(array('text' => $item->ordering, 'value' => $item->ordering - $config->ordering)); } $list = $this->optionlist(array( 'options' => $options, 'name' => $config->name, 'attribs' => $config->attribs, 'selected' => $config->selected )); return $list; }
/** * Get action. * * @param KCommandContext $context Context parameter * * @return string */ protected function _actionGet(KCommandContext $context) { $action = null; if ($this->_request->get) { $action = strtolower('get' . $this->_request->get); } else { $action = KInflector::isPlural($this->view) ? 'browse' : 'read'; } $result = null; if (in_array($action, $this->getActions())) { $result = $this->execute($action, $context); if (is_string($result) || $result === false) { $context->response->setContent($result . ' '); } } $view = $this->getView(); if (!$context->response->getContent()) { if ($context->params) { foreach ($context->params as $key => $value) { $view->set($key, $value); } } $content = $view->display(); //Set the data in the response $context->response->setContent($content); } $context->response->setContentType($view->mimetype); return $context->response->getContent(); }
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); }
/** * Get the list of commands * * Prepending a special command not found in the manifest.xml * * @return array */ public function getCommands() { $option = $this->getController()->getRequest()->option; //@TODO figure out why option=com_installer&view=components sets $request->option to NULL $active = !$option || $option == 'com_installer'; $view = $active ? 'components' : KInflector::pluralize($this->getController()->getIdentifier()->name); $this->addCommand('Install/Uninstall', array( 'href' => JRoute::_('index.php?option=com_installer&view='.$view), 'active' => $active )); $commands = parent::getCommands(); //If the com_installer command is active, then following commands cannot be active if($commands['Install/Uninstall']->active) { foreach($commands as $key => $command) { if($key != 'Install/Uninstall') $command->active = false; } } return $commands; }
public function display() { $targets = KFactory::tmp('site::com.stream.model.targets')->getList()->getData(); $thing = reset($targets); $string = substr($thing['title'], 3); $option = strtolower(substr($string, 0, stripos($string, 'controller'))); $view = strtolower(substr($string, stripos($string, 'controller') + 10)); $model = KInflector::pluralize($view); $list = KFactory::tmp('site::com.' . $option . '.model.' . $model)->getList()->getData(); $array = array(); foreach ($list as $item) { $array[] = $item['id']; } //Get the list of posts $activities = KFactory::get($this->getModel())->set('parent_target_id', KRequest::get('get.parent_target_id', 'int'))->getList(); $myactivities = array(); foreach (@$activities as $activity) { if (!in_array($activity->parent_target_id, $array)) { continue; } else { $myactivities[] = $activity; } } $this->assign('myactivities', $myactivities); $this->assign('pagination', KFactory::get($this->getModel())->getState()->pagination); return parent::display(); }
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); }
/** * Initializes the default configuration for the object * * Called from {@link __construct()} as a first step of object instantiation. * * @param KConfig $config An optional KConfig object with configuration options. * * @return void */ protected function _initialize(KConfig $config) { $package = KInflector::humanize($this->getIdentifier()->package); $name = KInflector::humanize(KInflector::pluralize($this->getName())); $config->append(array('title' => $package . ' - ' . $name)); parent::_initialize($config); }
/** * Sets the document title */ public function setDocumentTitle() { if (!KInflector::isPlural($this->getName())) { $item = $this->getModel()->getItem(); JFactory::getDocument()->setTitle($item->title); } }
/** * Deletes dependent rows. * * This performs an intelligent delete * * @return KDatabaseRowAbstract */ protected function _beforeTableDelete(KCommandContext $context) { $result = true; $section = $this->section; if (is_numeric($section) || !$section) { $section = 'com_articles'; } $parts = explode('_', $section); //@TODO : Remove when refactoring is completed switch ($parts[1]) { case 'contact': $name = 'contacts'; $package = 'contact'; break; default: $name = KInflector::pluralize($parts[1]); $package = $name; } $identifier = 'com://admin/' . $package . '.model.' . $name; $rowset = $this->getService($identifier)->category($this->id)->getList(); if ($rowset->count()) { $result = $rowset->delete(); } return $result; }
/** * Return the views output * * This function will auto assign the model data to the view if the auto_assign * property is set to TRUE. * * @return string The output of the view */ public function display() { if(empty($this->output)) { $model = $this->getModel(); //Auto-assign the state to the view $this->assign('state', $model->getState()); //Auto-assign the data from the model if($this->_auto_assign) { //Get the view name $name = $this->getName(); //Assign the data of the model to the view if(KInflector::isPlural($name)) { $this->assign($name, $model->getList()) ->assign('total', $model->getTotal()); } else $this->assign($name, $model->getItem()); } } return parent::display(); }
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); }
/** * Get the path based on a class name * * @param string The class name * @return string|false Returns the path on success FALSE on failure */ public function findPath($classname, $basepath = null) { $path = false; $word = strtolower(preg_replace('/(?<=\\w)([A-Z])/', ' \\1', $classname)); $parts = explode(' ', $word); if (array_shift($parts) == 'com') { //Switch the basepath if (!empty($basepath)) { $this->_basepath = $basepath; } $component = 'com_' . strtolower(array_shift($parts)); $file = array_pop($parts); if (count($parts)) { if ($parts[0] != 'view') { foreach ($parts as $key => $value) { $parts[$key] = KInflector::pluralize($value); } } else { $parts[0] = KInflector::pluralize($parts[0]); } $path = implode('/', $parts); $path = $path . '/' . $file; } else { $path = $file; } $path = $this->_basepath . '/components/' . $component . '/' . $path . '.php'; } return $path; }
/** * Command handler * * @param string $name The command name * @param mixed $args The command arguments * * @return boolean */ public function execute($name, $args) { $parts = explode('.', $name); $event = 'on' . KInflector::implode($parts); $dispatcher = KFactory::get('lib.koowa.event.dispatcher'); return $dispatcher->dispatch($event, $args); }
/** * Method to get a table object, load it if necessary. * * @param array Options array for view. Optional. * @return object The table object */ public function getPath(array $options = array()) { if (!is_object($this->_path)) { $package = $this->_identifier->package; $this->_path = JPATH_ROOT . DS . 'components' . DS . 'com_' . $package . DS . KInflector::pluralize($this->_identifier->name); } return $this->_path; }
/** * Initializes the configuration for the object * * Called from {@link __construct()} as a first step of object instantiation. * * @param array Configuration settings */ protected function _initialize(KConfig $config) { $config->append(array( 'layout' => KInflector::isSingular($this->getName()) ? 'form' : 'default' )); parent::_initialize($config); }