/** * Loads the given class or interface. * * @param string $class The name of the class * * @throws RokCommon_ClassLoader_Exception * @return bool|null True, if loaded */ public function loadClass($class) { if ($this->hasBeenChecked($class)) { return false; } if (!$this->container->hasParameter($this->classpath_key)) { error_log(sprintf('Classpath parameter %s does not exist.', $this->classpath_key)); return false; } $classpath = RokCommon_Utils_ArrayHelper::fromObject($this->container->getParameter($this->classpath_key)); foreach ($classpath as $prefix => $priorityPaths) { if (preg_match('/^' . $prefix . '/i', $class)) { $striped_name = str_ireplace($prefix, '', $class); $filename_checks = array($striped_name . self::FILE_EXTENSION, strtolower($striped_name . self::FILE_EXTENSION), ucfirst(strtolower($striped_name . self::FILE_EXTENSION)), strtoupper($striped_name . self::FILE_EXTENSION)); krsort($priorityPaths); // highest priority is loaded first foreach ($priorityPaths as $priority => $paths) { foreach ($paths as $path) { foreach ($filename_checks as $filename) { $full_file_path = $path . DIRECTORY_SEPARATOR . strtolower($filename); if (($full_file_path = $this->fileExists($full_file_path, false)) !== false && is_readable($full_file_path)) { require_once $full_file_path; if (class_exists($class, false)) { return true; } } } } } } } $this->addChecked($class); return false; }
/** * @param RokSprocket_ItemCollection $items * * @param $module_id * * @throws RokSprocket_Exception */ protected function mapPerItemData(RokSprocket_ItemCollection &$items, $module_id) { global $wpdb; $query = 'SELECT i.provider_id as id, i.order, i.params'; $query .= ' FROM #__roksprocket_items as i'; $query .= ' WHERE i.widget_id = "' . $module_id . '"'; $query .= ' AND i.provider = "' . RokSprocket_Provider_Simple_Storage_Interface::PROVIDER_NAME . '"'; $query = str_replace('#__', $wpdb->prefix, $query); //add wp db prefix $sprocket_items = $wpdb->get_results($query, OBJECT_K); if ($sprocket_items === false) { throw new RokSprocket_Exception($wpdb->last_error); } /** @var $items RokSprocket_Item[] */ foreach ($items as $item_id => &$item) { list($provider, $id) = explode('-', $item_id); if (array_key_exists($id, $sprocket_items)) { $items[$item_id]->setOrder((int) $sprocket_items[$id]->order); if (!is_null($sprocket_items[$id]->params)) { $items[$item_id]->setParams(RokCommon_Utils_ArrayHelper::fromObject(RokCommon_JSON::decode($sprocket_items[$id]->params))); } else { $items[$item_id]->setParams(array()); } } } }
/** * @param RokSprocket_ItemCollection $items * * @param string $module_id * * @throws RokSprocket_Exception */ protected function mapPerItemData(RokSprocket_ItemCollection &$items, $module_id) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('i.provider_id as id, i.order, i.params')->from('#__roksprocket_items as i'); $query->where('i.module_id = ' . $db->quote($module_id)); $query->where('i.provider = ' . $db->quote(RokSprocket_Provider_Simple_Storage_Interface::PROVIDER_NAME)); $db->setQuery($query); $sprocket_items = $db->loadObjectList('id'); if ($error = $db->getErrorMsg()) { throw new RokSprocket_Exception($error); } /** @var $items RokSprocket_Item[] */ foreach ($items as $item_id => &$item) { list($provider, $id) = explode('-', $item_id); if (array_key_exists($id, $sprocket_items)) { $items[$item_id]->setOrder((int) $sprocket_items[$id]->order); if (null != $sprocket_items[$id]->params) { $decoded = null; try { $decoded = RokCommon_Utils_ArrayHelper::fromObject(RokCommon_JSON::decode($sprocket_items[$id]->params)); } catch (RokCommon_JSON_Exception $jse) { } $items[$item_id]->setParams($decoded); } else { $items[$item_id]->setParams(array()); } } } }
protected function parseParameters($xml, $file) { if (!$xml->parameters) { return array(); } $parameters = $xml->parameters->getArgumentsAsPhp('parameter'); // replace and %current.path% with the real current path $parameters = RokCommon_Utils_ArrayHelper::replaceTree('%current.path%', dirname($file), $parameters); return $parameters; }
public function __construct($classpath_key, $package) { $this->package = $package; parent::__construct($classpath_key); $classpath = RokCommon_Utils_ArrayHelper::fromObject($this->container->getParameter($this->classpath_key)); $append_path = $this->container->getParameter('form.assets.appendpath', 'assets'); foreach ($classpath as $prefix => $priorityPaths) { krsort($priorityPaths); // highest priority is loaded first foreach ($priorityPaths as $priority => $paths) { foreach ($paths as $path) { RokCommon_Composite::addPackagePath($this->package, $path . DS . $append_path, $priority); } } } }
/** * Finds the path to the file where the class is defined. * * @param string $class The name of the class * * @return bool|null|string The path, if found */ public function find($class) { $classpath = get_object_vars($this->container->getParameter($this->classpath_key)); krsort($classpath); $current_md5 = md5(RokCommon_Utils_ArrayHelper::toString($classpath)); if ($this->last_md5 != $current_md5) { $this->last_md5 = $current_md5; $found_maps = array(); foreach ($classpath as $priority => $priority_paths) { foreach ($priority_paths as $path) { if (!in_array($path, $this->checked_paths)) { $this->checked_paths[] = $path; if (is_dir($path)) { $path = $path . DIRECTORY_SEPARATOR . self::MAP_FILE_DEFAULT_NAME; } if (!in_array($path, $this->checked_paths) && is_file($path)) { if (($path_map = @(include $path)) && is_array($path_map)) { $found_maps[] = $path_map; } else { if (defined('ROKCOMMON_CORE_DEBUG') && ROKCOMMON_CORE_DEBUG) { error_log(sprintf('%s: Unable to load map file %s as a valid class map', get_class($this), $path)); } } } } } if (isset($this->maps[$priority]) && !empty($found_maps)) { $this->maps[$priority] = array_merge($this->maps[$priority], (array) $found_maps); } elseif (!empty($found_maps)) { $this->maps[$priority] = (array) $found_maps; } } krsort($this->maps); } if ('\\' === $class[0]) { $class = substr($class, 1); } foreach ($this->maps as $priority_maps) { foreach ($priority_maps as $map) { if (isset($map[$class])) { return $map[$class]; } } } return false; }
/** * @param string $class * * @return bool|string */ public function find($class) { $paths = RokCommon_Utils_ArrayHelper::fromObject($this->container->getParameter($this->classpath_key)); ksort($paths); if ('\\' == $class[0]) { $class = substr($class, 1); } if (false !== ($pos = strrpos($class, '\\'))) { // namespaced class name $classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)) . DIRECTORY_SEPARATOR; $className = substr($class, $pos + 1); } else { // PEAR-like class name $classPath = null; $className = $class; } $classPathParts = array(); if (!empty($classPath)) { $classPathParts = explode(DIRECTORY_SEPARATOR, $classPath); } $nameStartPosition = count($classPathParts); $classNameParts = explode('_', $className); $classPathParts = array_merge($classPathParts, $classNameParts); $partsCount = count($classPathParts); if (count($classPathParts) > 1) { // check for compiled first $iter = new RecursiveArrayIterator($paths); foreach (new RecursiveIteratorIterator($iter) as $dir) { $pos = $partsCount - 1; do { $path = $dir . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array_slice($classPathParts, 0, $pos)) . '.compiled.php'; if (file_exists($path)) { return $path; } } while (--$pos > $nameStartPosition); } } return false; }
public function getInput() { $container = RokCommon_Service::getContainer(); $empty_button_text = rc__('Create New Filter'); $filter_file = $container[(string) $this->element['filterlocationparam']] . '/' . (string) $this->element['filterfile']; if (!file_exists($filter_file)) { throw new RokSprocket_Exception(rc__('Unable to find filter file %s', $filter_file)); } $xmlfile = simplexml_load_file($filter_file); $this->filter = new RokCommon_Filter($xmlfile); if (isset($this->element['emptybuttontext'])) { $empty_button_text = rc__((string) $this->element['emptybuttontext']); } if (!self::$base_js_loaded) { RokCommon_Header::addInlineScript(' var RokSprocketFilters = { filters: {}, template: \'<li><span data-filter-container="true"></span> <span class="controls"> <i class="icon tool minus" data-filter-action="removeRow"></i> <i class="icon tool plus" data-filter-action="addRow"></i></span></li>\' }; '); self::$base_js_loaded = true; } $html = array(); /* After everything fine, i'll handle via js and domready the call to filters ajax model Something along these lines: model: 'Filters', action: 'getData', params: JSON.encoded( [{ id1: {pathrefs: .., file: ..} }], [{ id2: {pathrefs: .., file: ..} }], [{ id3: {pathrefs: .., file: ..} }], ... ) */ /* // OLD Script RokCommon_Header::addInlineScript(' window.addEvent(\'load\', function(){ RokSprocket.filters.addDataSet(\'' . $this->id . '\', { pathsref: \''. (string)$this->element['filterlocationparam'] .'\', file: \'' . (string)$this->element['filterfile'] .'\', template: \'<li><span data-filter-container="true"></span> <span class="controls"> <i class="icon tool minus" data-filter-action="removeRow"></i> <i class="icon tool plus" data-filter-action="addRow"></i></span></li>\' }); }); ');*/ RokCommon_Header::addInlineScript("\n\t \t\t\t RokSprocketFilters.filters['" . $this->id . "'] = {\n\t \t\t\t pathsref: '" . (string) $this->element['filterlocationparam'] . "',\n\t \t\t\t file: '" . (string) $this->element['filterfile'] . "'\n\t \t\t\t }"); $classes = explode(' ', $this->element['class']); $classes[] = 'roksprocket-filters'; if (!is_array($this->value)) { $classes[] = 'empty'; } $classes = implode(' ', $classes); $html[] = '<ul class="' . $classes . '" data-filter="' . $this->id . '" data-filter-name="' . $this->name . '">'; $html[] = ' <li class="create-new"><div class="btn btn-primary" data-filter-action="addRow">' . $empty_button_text . '</div></li>'; if (is_array($this->value)) { foreach ($this->value as $rownum => $row) { $firstRow = $rownum == 1 ? ' class="first"' : ''; RokCommon_Utils_ArrayHelper::fromObject($row); $html[] = ' <li data-row="true"' . $firstRow . '><span data-filter-container="true">' . $this->filter->renderLine($row, $this->name . '[' . $rownum . ']') . '</span><span class="controls"><i data-filter-action="removeRow" class="icon tool minus"></i><i data-filter-action="addRow" class="icon tool plus"></i></span></li>'; } } $html[] = ' </ul>'; if ($this->element['notice'] && strlen($this->element['notice'])) { $html[] = '<div data-cookie="' . $this->id . '" class="roksprocket-filters-description alert alert-info"><a class="close" data-dismiss="alert">×</a>' . JText::_($this->element['notice']) . '</div>'; } return implode("\n", $html); }
/** * Generates an HTML radio list. * * @param array An array of objects * @param string The value of the HTML name attribute * @param string Additional HTML attributes for the <select> tag * @param mixed The key that is selected * @param string The name of the object variable for the option value * @param string The name of the object variable for the option text * @return string HTML for the select list */ public static function radiolist($data, $name, $attribs = null, $optKey = 'value', $optText = 'text', $selected = null, $idtag = false, $translate = false) { reset($data); $html = ''; if (is_array($attribs)) { $attribs = RokCommon_Utils_ArrayHelper::toString($attribs); } $id_text = $idtag ? $idtag : $name; foreach ($data as $ind => $obj) { $k = $obj->{$optKey}; $t = $translate ? rc__($obj->{$optText}) : $obj->{$optText}; $id = isset($obj->id) ? $obj->id : null; $extra = ''; $extra .= $id ? ' id="' . $obj->id . '"' : ''; if (is_array($selected)) { foreach ($selected as $val) { $k2 = is_object($val) ? $val->{$optKey} : $val; if ($k == $k2) { $extra .= ' selected="selected"'; break; } } } else { $extra .= (string) $k == (string) $selected ? ' checked="checked"' : ''; } $html .= "\n\t" . '<input type="radio" name="' . $name . '"' . ' id="' . $id_text . $k . '" value="' . $k . '"' . ' ' . $extra . ' ' . $attribs . '/>' . "\n\t" . '<label for="' . $id_text . $k . '" id="' . $id_text . $k . '-lbl" class="radiobtn_' . strtolower($obj->{$optText}) . '">' . $t . '</label>'; } $html .= "\n"; return $html; }
/** * Get the items for the module and provider based on the filters passed and paginated * $params object should be a json like * <code> * { * "page": 3, * "items_per_page":6, * "module_id": 5, * "provider":"joomla", * "filters": {"1":{"root":{"access":"1"}},"2":{"root":{"author":"43"}}}, * "sortby":"date", * "get_remaining": true * } * </code> * * @param $params * * @throws Exception * @throws RokCommon_Ajax_Exception * @return \RokCommon_Ajax_Result */ public function getItems($params) { $result = new RokCommon_Ajax_Result(); try { $html = ''; $provider_filters = null; $provider_articles = null; if (isset($params->filters)) { $provider_filters = RokCommon_JSON::decode($params->filters); } if (isset($params->articles)) { $provider_articles = RokCommon_JSON::decode($params->articles); } $decoded_sort_parameters = array(); try { $decoded_sort_parameters = RokCommon_Utils_ArrayHelper::fromObject(RokCommon_JSON::decode($params->sort)); } catch (RokCommon_JSON_Exception $jse) { throw new RokCommon_Ajax_Exception('Invalid Sort Parameters passed in.'); } $sort_params = new RokCommon_Registry($decoded_sort_parameters); $sort_filters = RokCommon_Utils_ArrayHelper::fromObject($sort_params->get('rules')); $sort_append = $sort_params->get('append', 'after'); $sort_type = $sort_params->get('type'); $extras = array(); if (isset($params->extras)) { $extras = $params->extras; } if ($params->uuid != '0') { $params->module_id = $params->uuid; } $items = RokSprocket::getItemsWithFilters($params->module_id, $params->provider, $provider_filters, $provider_articles, $sort_filters, $sort_type, $sort_append, new RokCommon_Registry($extras), false, true); $container = RokCommon_Service::getContainer(); $template_path_param = sprintf('roksprocket.providers.registered.%s.templatepath', strtolower($params->provider)); if ($container->hasParameter($template_path_param)) { RokCommon_Composite::addPackagePath('roksprocket', $container->getParameter($template_path_param), 30); } $total_items_count = $items->count(); $page = $params->page; $more = false; $limit = 10; $offset = ($page - 1) * $limit; if ($params->load_all) { $limit = $total_items_count - $offset; } $items = $items->slice($offset, $limit); $page = (int) $page == 0 ? 1 : $page; $next_page = $page; if ($total_items_count > $offset + $limit) { $more = true; $next_page = $page + 1; } $order = 0; $this->loadLayoutLanguage($params->layout); ob_start(); foreach ($items as $article) { $per_item_form = $this->getPerItemsForm($params->layout); $per_item_form->setFormControl(sprintf('items[%s]', $article->getArticleId())); $per_item_form->bind(array('params' => $article->getParams())); echo RokCommon_Composite::get('roksprocket.module.edit')->load('edit_article.php', array('itemform' => $per_item_form, 'article' => $article, 'order' => $order)); $order++; } $html .= ob_get_clean(); $result->setPayload(array('more' => $more, 'page' => $page, 'next_page' => $next_page, 'amount' => $total_items_count, 'html' => $html)); } catch (Exception $e) { throw $e; } return $result; }
/** * Sets a service container parameter. * * @param string $name The parameter name * @param $value * * @internal param mixed $parameters The parameter value */ public function setParameter($name, $value) { $cleaned_name = strtolower($name); if (is_array($value) && RokCommon_Utils_ArrayHelper::isAssociative($value)) { foreach ($value as $key => $subvalue) { $subname = $cleaned_name . RokCommon_Registry::SEPARATOR . strtolower($key); $this->setParameter($subname, $subvalue); } } elseif (is_array($value) && $this->parameters->exists($cleaned_name)) { $current = $this->parameters->get($cleaned_name); if (is_array($current)) { $merged = array_merge($current, $value); $this->parameters->set($cleaned_name, $merged); } else { $this->parameters->set($cleaned_name, $value); } } else { $this->parameters->set($cleaned_name, $value); } }
/** * Utility function to map an object to an array * * @static * @param object The source object * @param boolean True to recurve through multi-level objects * @param string An optional regular expression to match on field names * @return array The array mapped from the given object * @since 1.5 */ static function fromObject($p_obj, $recurse = true, $regex = null) { $result = null; if (is_object($p_obj)) { $result = array(); foreach (get_object_vars($p_obj) as $k => $v) { if ($regex) { if (!preg_match($regex, $k)) { continue; } } if (is_object($v)) { if ($recurse) { $result[$k] = RokCommon_Utils_ArrayHelper::fromObject($v, $recurse, $regex); } } else { $result[$k] = $v; } } } return $result; }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 1.6 */ public function save($data) { $original_data = $data; // Initialise variables; $app = JFactory::getApplication(); $dispatcher = JDispatcher::getInstance(); $table = $this->getTable(); $pk = !empty($data['id']) ? $data['id'] : (int) $this->getState('module.id'); $isNew = true; $input = $app->input; $task = $input->get('task', null, 'cmd'); // Include the content modules for the onSave events. JPluginHelper::importPlugin('extension'); // Load the row if saving an existing record. if ($pk > 0) { $table->load($pk); $isNew = false; } // Alter the title and published state for Save as Copy if ($task == 'save2copy') { $orig_data = $input->post->get('jform', array(), 'array'); $orig_table = clone $this->getTable(); $orig_table->load((int) $orig_data['id']); if ($data['title'] == $orig_table->title) { $data['title'] .= ' ' . JText::_('JGLOBAL_COPY'); $data['published'] = 0; } } // Bind the data. if (!$table->bind($data)) { $this->setError($table->getError()); return false; } // Prepare the row for saving $this->prepareTable($table); // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Trigger the onExtensionBeforeSave event. $result = $dispatcher->trigger('onExtensionBeforeSave', array('com_modules.module', &$table, $isNew)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } // // Process the menu link mappings. // $assignment = isset($data['assignment']) ? $data['assignment'] : 0; // Delete old module to menu item associations // $db->setQuery( // 'DELETE FROM #__modules_menu'. // ' WHERE moduleid = '.(int) $table->id // ); $db = $this->getDbo(); $query = $db->getQuery(true); $query->delete(); $query->from('#__modules_menu'); $query->where('moduleid = ' . (int) $table->id); $db->setQuery((string) $query); $db->query(); if (!$db->query()) { $this->setError($db->getErrorMsg()); return false; } // If the assignment is numeric, then something is selected (otherwise it's none). if (is_numeric($assignment)) { // Variable is numeric, but could be a string. $assignment = (int) $assignment; // Logic check: if no module excluded then convert to display on all. if ($assignment == -1 && empty($data['assigned'])) { $assignment = 0; } // Check needed to stop a module being assigned to `All` // and other menu items resulting in a module being displayed twice. if ($assignment === 0) { // assign new module to `all` menu item associations // $this->_db->setQuery( // 'INSERT INTO #__modules_menu'. // ' SET moduleid = '.(int) $table->id.', menuid = 0' // ); $query->clear(); $query->insert('#__modules_menu'); $query->columns(array($db->quoteName('moduleid'), $db->quoteName('menuid'))); $query->values((int) $table->id . ', 0'); $db->setQuery((string) $query); if (!$db->query()) { $this->setError($db->getErrorMsg()); return false; } } elseif (!empty($data['assigned'])) { // Get the sign of the number. $sign = $assignment < 0 ? -1 : +1; // Preprocess the assigned array. $tuples = array(); foreach ($data['assigned'] as &$pk) { $tuples[] = '(' . (int) $table->id . ',' . (int) $pk * $sign . ')'; } $this->_db->setQuery('INSERT INTO #__modules_menu (moduleid, menuid) VALUES ' . implode(',', $tuples)); if (!$db->query()) { $this->setError($db->getErrorMsg()); return false; } } } // Trigger the onExtensionAfterSave event. $dispatcher->trigger('onExtensionAfterSave', array('com_modules.module', &$table, $isNew)); // Compute the extension id of this module in case the controller wants it. $query = $db->getQuery(true); $query->select('extension_id'); $query->from('#__extensions AS e'); $query->leftJoin('#__modules AS m ON e.element = m.module'); $query->where('m.id = ' . (int) $table->id); $db->setQuery($query); $extensionId = $db->loadResult(); if ($error = $db->getErrorMsg()) { JError::raiseWarning(500, $error); return; } $this->setState('module.extension_id', $extensionId); $this->setState('module.id', $table->id); // Add the per item custom settings $items = $input->post->get('items', array(), 'array'); $old_moduleid = (int) $table->id; if ($task == 'save2copy') { $old_moduleid = (int) $orig_table->id; } // get the old set of items for the module $query = $db->getQuery(true); $item_table = JTable::getInstance('Item', 'RokSprocketTable'); $query->select("*")->from("#__roksprocket_items")->where('module_id = ' . $old_moduleid); $db->setQuery((string) $query); $raw_old_items = $db->loadAssocList(); if ($db->getErrorNum()) { $this->setError($db->getErrorMsg()); return false; } $old_items = array(); foreach ($raw_old_items as $raw_old_item) { /** @var $old_item_table RokSprocketTableItem */ $old_item_table = JTable::getInstance('Item', 'RokSprocketTable'); $old_item_table->bind($raw_old_item); if (isset($old_item_table->params)) { $old_item_table->params = RokCommon_Utils_ArrayHelper::fromObject(RokCommon_JSON::decode($old_item_table->params)); } else { $old_item_table->params = array(); } $old_items[$old_item_table->provider . '-' . $old_item_table->provider_id] = $old_item_table; } $all_new_items = $this->getArticles((int) $table->id, $table->params); if ($task != 'save2copy') { // delete old items per module $query = $db->getQuery(true); $query->delete(); $query->from('#__roksprocket_items'); $query->where('module_id = ' . (int) $table->id); $db->setQuery((string) $query); if (!$db->query()) { $this->setError($db->getErrorMsg()); return false; } // Pass to addons to save if needed if (empty($original_data['id'])) { $original_data['id'] = (int) $table->id; } $event = new RokCommon_Event($this, 'roksprocket.module.save'); $this->dispatcher->filter($event, array('data' => $original_data, 'save_result' => null)); $addonreturn = $event->getReturnValue(); if ($event->isProcessed()) { if (!$addonreturn['save_result']) { return false; } } } $per_item_form = $this->getPerItemsForm(); // Save the Showing Items $last_ordernumber = 0; foreach ($items as $item_id => $item_settings) { $item_settings['module_id'] = (int) $table->id; list($item_settings['provider'], $item_settings['provider_id']) = explode('-', $item_id); /** @var $item_table RokSprocketTableItem */ $item_table = JTable::getInstance('Item', 'RokSprocketTable'); $fields = $per_item_form->getFieldsetWithGroup('peritem'); foreach ($fields as $field) { if (!array_key_exists($field->fieldname, $item_settings['params'])) { if (!empty($old_items) && isset($old_items[$item_id]) && array_key_exists($field->fieldname, $old_items[$item_id]->params)) { $item_settings['params'][$field->fieldname] = $old_items[$item_id]->params[$field->fieldname]; } else { $item_settings['params'][$field->fieldname] = $per_item_form->getFieldAttribute($field->fieldname, 'default', null, 'params'); } } } // Bind the data. if (!$item_table->bind($item_settings)) { $this->setError($item_table->getError()); return false; } // Trigger the onExtensionBeforeSave event. $result = $dispatcher->trigger('onExtensionBeforeSave', array('com_roksprocket.module', &$item_table, true)); if (in_array(false, $result, true)) { $this->setError($item_table->getError()); return false; } // Store the data. if (!$item_table->store()) { $this->setError($item_table->getError()); return false; } $last_ordernumber = $item_table->order; if (isset($old_items[$item_id])) { unset($old_items[$item_id]); } if (isset($all_new_items[$item_id])) { unset($all_new_items[$item_id]); } } //Save the remaining items (Not Shown) foreach ($all_new_items as $item_id => $unseen_item) { $item_settings = array(); $item_settings['module_id'] = (int) $table->id; list($item_settings['provider'], $item_settings['provider_id']) = explode('-', $item_id); $item_settings['order'] = ++$last_ordernumber; if (isset($old_items[$item_id]) && $old_items[$item_id]->params != null) { $item_settings['params'] = $old_items[$item_id]->params; } elseif (isset($all_new_items[$item_id]) && $all_new_items[$item_id]->getParams() != null) { $item_settings['params'] = RokCommon_JSON::encode($all_new_items[$item_id]->getParams()); } /** @var $item_table RokSprocketTableItem */ $item_table = JTable::getInstance('Item', 'RokSprocketTable'); // Bind the data. if (!$item_table->bind($item_settings)) { $this->setError($item_table->getError()); return false; } // Trigger the onExtensionBeforeSave event. $result = $dispatcher->trigger('onExtensionBeforeSave', array('com_roksprocket.module', &$item_table, true)); if (in_array(false, $result, true)) { $this->setError($item_table->getError()); return false; } // Store the data. if (!$item_table->store()) { $this->setError($item_table->getError()); return false; } } // Clear modules cache $this->cleanCache(); // Clean module cache parent::cleanCache($table->module, $table->client_id); $app->setUserState('com_roksprocket.module_id', $table->id); return true; }
/** * Method to recursively bind data to a parent object. * * @param object $parent The parent object on which to attach the data values. * @param mixed $data An array or object of data to bind to the parent object. * * @return void * @since 1.6 */ protected function bindData(&$parent, $data) { // Ensure the input data is an array. if (is_object($data)) { $data = get_object_vars($data); } else { $data = (array) $data; } foreach ($data as $k => $v) { if (is_array($v) && RokCommon_Utils_ArrayHelper::isAssociative($v) || is_object($v)) { $parent->{$k} = new stdClass(); $this->bindData($parent->{$k}, $v); } else { $parent->{$k} = $v; } } }
/** * Method to apply an input filter to a value based on field data. * * @param string $element The XML element object representation of the form field. * @param mixed $value The value to filter for the field. * * @return mixed The filtered value. * * @since 11.1 */ protected function filterField($element, $value) { // Make sure there is a valid RokCommon_XMLElement. if (!$element instanceof RokCommon_XMLElement) { return false; } // Get the field filter type. $filter = (string) $element['filter']; // Process the input value based on the filter. $return = null; switch (strtoupper($filter)) { // Access Control Rules. case 'RULES': $return = array(); foreach ((array) $value as $action => $ids) { // Build the rules array. $return[$action] = array(); foreach ($ids as $id => $p) { if ($p !== '') { $return[$action][$id] = $p == '1' || $p == 'true' ? true : false; } } } break; // Do nothing, thus leaving the return value as null. // Do nothing, thus leaving the return value as null. case 'UNSET': break; // No Filter. // No Filter. case 'RAW': $return = $value; break; // Filter the input as an array of integers. // Filter the input as an array of integers. case 'INT_ARRAY': // Make sure the input is an array. if (is_object($value)) { $value = get_object_vars($value); } $value = is_array($value) ? $value : array($value); RokCommon_Utils_ArrayHelper::toInteger($value); $return = $value; break; // Filter safe HTML. // Filter safe HTML. case 'SAFEHTML': $return = JFilterInput::getInstance(null, null, 1, 1)->clean($value, 'string'); break; // Convert a date to UTC based on the server timezone offset. // Convert a date to UTC based on the server timezone offset. case 'SERVER_UTC': if (intval($value) > 0) { // Get the server timezone setting. $offset = JFactory::getConfig()->get('offset'); // Return an SQL formatted datetime string in UTC. $return = JFactory::getDate($value, $offset)->toSql(); } else { $return = ''; } break; // Convert a date to UTC based on the user timezone offset. // Convert a date to UTC based on the user timezone offset. case 'USER_UTC': if (intval($value) > 0) { // Get the user timezone setting defaulting to the server timezone setting. $offset = JFactory::getUser()->getParam('timezone', JFactory::getConfig()->get('offset')); // Return a MySQL formatted datetime string in UTC. $return = JFactory::getDate($value, $offset)->toSql(); } else { $return = ''; } break; case 'TEL': $value = trim($value); // Does it match the NANP pattern? if (preg_match('/^(?:\\+?1[-. ]?)?\\(?([2-9][0-8][0-9])\\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/', $value) == 1) { $number = (string) preg_replace('/[^\\d]/', '', $value); if (substr($number, 0, 1) == 1) { $number = substr($number, 1); } if (substr($number, 0, 2) == '+1') { $number = substr($number, 2); } $result = '1.' . $number; } elseif (preg_match('/^\\+(?:[0-9] ?){6,14}[0-9]$/', $value) == 1) { $countrycode = substr($value, 0, strpos($value, ' ')); $countrycode = (string) preg_replace('/[^\\d]/', '', $countrycode); $number = strstr($value, ' '); $number = (string) preg_replace('/[^\\d]/', '', $number); $result = $countrycode . '.' . $number; } elseif (preg_match('/^\\+[0-9]{1,3}\\.[0-9]{4,14}(?:x.+)?$/', $value) == 1) { if (strstr($value, 'x')) { $xpos = strpos($value, 'x'); $value = substr($value, 0, $xpos); } $result = str_replace('+', '', $value); } elseif (preg_match('/[0-9]{1,3}\\.[0-9]{4,14}$/', $value) == 1) { $result = $value; } else { $value = (string) preg_replace('/[^\\d]/', '', $value); if ($value != null && strlen($value) <= 15) { $length = strlen($value); // if it is fewer than 13 digits assume it is a local number if ($length <= 12) { $result = '.' . $value; } else { // If it has 13 or more digits let's make a country code. $cclen = $length - 12; $result = substr($value, 0, $cclen) . '.' . substr($value, $cclen); } } else { $result = ''; } } $return = $result; break; default: // Check for a callback filter. if (strpos($filter, '::') !== false && is_callable(explode('::', $filter))) { $return = call_user_func(explode('::', $filter), $value); } elseif (function_exists($filter)) { $return = call_user_func($filter, $value); } else { $return = JFilterInput::getInstance()->clean($value, $filter); } break; } return $return; }
/** * @static * * @param string $moduleId * @param string $provider_type * @param array $provider_filters * @param array $provider_articles * @param array $sort_filters * @param string $sort_type * @param string $sort_append * @param RokCommon_Registry $extra_parameters * @param bool $apply_random * * @param bool $unpublished * * @return RokSprocket_ItemCollection */ public static function getItemsWithFilters($moduleId, $provider_type, $provider_filters, $provider_articles, $sort_filters, $sort_type, $sort_append, &$extra_parameters, $apply_random = false, $unpublished = false) { $container = RokCommon_Service::getContainer(); /** @var $provider RokSprocket_IProvider */ $provider_service = $container['roksprocket.providers.registered.' . $provider_type . '.service']; $provider = $container->{$provider_service}; $provider->setParams($extra_parameters); $filters = array(); if (!empty($provider_filters)) { $filters = array_merge($filters, RokCommon_Utils_ArrayHelper::fromObject($provider_filters)); } if (!empty($provider_articles)) { $filters = array_merge($filters, RokCommon_Utils_ArrayHelper::fromObject($provider_articles)); } return self::getItems($provider, $moduleId, $filters, $sort_filters, $sort_type, $sort_append, $apply_random, $unpublished); }
/** * Method to apply an input filter to a value based on field data. * * @param string $element The XML element object representation of the form field. * @param mixed $value The value to filter for the field. * * @return mixed The filtered value. * @since 1.6 */ protected function filterField($element, $value) { gantry_import('core.utilities.gantryfilterinput'); // Make sure there is a valid RokCommon_XMLElement. if (!$element instanceof RokCommon_XMLElement) { return false; } // Get the field filter type. $filter = (string) $element['filter']; // Process the input value based on the filter. $return = null; switch (strtoupper($filter)) { // Access Control Rules. case 'RULES': $return = array(); foreach ((array) $value as $action => $ids) { // Build the rules array. $return[$action] = array(); foreach ($ids as $id => $p) { if ($p !== '') { $return[$action][$id] = $p == '1' || $p == 'true' ? true : false; } } } break; // Do nothing, thus leaving the return value as null. // Do nothing, thus leaving the return value as null. case 'UNSET': break; // No Filter. // No Filter. case 'RAW': $return = $value; break; // Filter the input as an array of integers. // Filter the input as an array of integers. case 'INT_ARRAY': // Make sure the input is an array. if (is_object($value)) { $value = get_object_vars($value); } $value = is_array($value) ? $value : array($value); RokCommon_Utils_ArrayHelper::toInteger($value); $return = $value; break; // Filter safe HTML. // Filter safe HTML. case 'SAFEHTML': $return = GantryFilterInput::getInstance(null, null, 1, 1)->clean($value, 'string'); break; // Convert a date to UTC based on the server timezone offset. // Convert a date to UTC based on the server timezone offset. case 'SERVER_UTC': if (intval($value) > 0) { // Get the server timezone setting. $offset = JFactory::getConfig()->get('offset'); // Return a MySQL formatted datetime string in UTC. $return = JFactory::getDate($value, $offset)->toMySQL(); } else { $return = ''; } break; // Convert a date to UTC based on the user timezone offset. // Convert a date to UTC based on the user timezone offset. case 'USER_UTC': if (intval($value) > 0) { // Get the user timezone setting defaulting to the server timezone setting. $offset = JFactory::getUser()->getParam('timezone', JFactory::getConfig()->get('offset')); // Return a MySQL formatted datetime string in UTC. $return = JFactory::getDate($value, $offset)->toMySQL(); } else { $return = ''; } break; default: // Check for a callback filter. if (strpos($filter, '::') !== false && is_callable(explode('::', $filter))) { $return = call_user_func(explode('::', $filter), $value); } else { if (function_exists($filter)) { $return = call_user_func($filter, $value); } else { $return = GantryFilterInput::getInstance()->clean($value, $filter); } } break; } return $return; }