/** * 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()); } } } }
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); } } } }
/** * @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); }
/** * 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; }
/** * @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); }
/** * 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; }