public function display($tpl = null) { // Get system variables $application = JFactory::getApplication(); $document = JFactory::getDocument(); // Get the item from our model $this->fetchItem(); // Set the meta-data $document->setTitle($this->item->title); $document->setMetaData('title', $this->item->title); // Initialize the parameters if ($this->item->params) { $p = clone $this->params; $this->item->params = YireoHelper::toParameter($this->item->params); $p->merge($this->item->params); $this->item->params = $p; } else { $this->item->params = $this->params; } if ($this->item->params->get('meta_author') != '') { $document->setMetaData('author', $this->item->params->get('meta_author')); } if ($this->item->params->get('meta_description') != '') { $document->setDescription($this->item->params->get('meta_description')); } if ($this->item->params->get('meta_keywords') != '') { $document->setMetadata('keywords', $this->item->params->get('meta_keywords')); } // Parse important parameters $layout = null; $this->item = $this->_prepareItem($this->item, $layout); // Check whether the item is still here if (empty($this->item)) { JError::raiseError(404, JText::_('Resource Not Found')); } // when the link was "hidden", we call the link-plugin to decide what to do if (JRequest::getCmd('task') == 'hidden') { $this->item->params->set('show_link', 0); $this->item->extra = SimplelistsPluginHelper::getPluginLinkHidden($item); } else { $this->item->extra = null; } parent::display($tpl); }
public function getList(&$params) { // Get some system variables $mainframe =& JFactory::getApplication(); $db =& JFactory::getDBO(); $user =& JFactory::getUser(); // Read the module parameters $count = (int) $params->get('count', 5); $category_id = (int) $params->get('category_id'); $ordering = $params->get('ordering'); $layout = $params->get('layout'); $Itemid = (int) $params->get('menu_id'); // Initialize some variables $aid = $user->get('aid', 0); $nullDate = $db->getNullDate(); $date =& JFactory::getDate(); $now = method_exists('JDate', 'toSql') ? $date->toSql() : $date->toMySQL(); switch ($ordering) { case 'alpha': $o = 'w.title ASC'; break; case 'ralpha': $o = 'w.title DESC'; break; case 'date': $o = 'w.created DESC, w.modified DESC'; break; case 'rdate': $o = 'w.created ASC, w.modified ASC'; break; case 'random': $o = 'RAND()'; break; default: $o = 'w.ordering'; break; } $where = 'ORDER BY ' . $o; $query = 'SELECT w.*, c.title AS category, c.id AS category_id, c.alias AS category_alias' . ' FROM #__simplelists_categories AS sc' . ' LEFT JOIN #__simplelists_items AS w ON w.id = sc.id' . ' LEFT JOIN #__categories AS c ON c.id = sc.category_id' . ' WHERE sc.category_id = ' . $category_id . ' AND c.published = 1' . ' AND w.published = 1' . ' ' . $where; $db->setQuery($query, 0, $count); $rows = $db->loadObjectList(); // Get the Itemid if ($Itemid > 0) { $menu_item = SimplelistsHelper::getMenuItemFromItemId($Itemid); if (!empty($menu_item)) { $layout = !empty($menu_item->layout) ? $menu_item->layout : 'default'; } else { $layout = null; } } else { $menu_item = SimplelistsHelper::getMenuItem($category_id, $layout); if ($menu_item != null) { if (isset($menu_item->query['layout'])) { $layout = $menu_item->query['layout']; } $Itemid = $menu_item->id; } } $i = 0; $lists = array(); if (!empty($rows)) { foreach ($rows as $row) { $needles = array('category_id' => $row->category_id, 'category_alias' => $row->category_alias, 'item_id' => $row->id, 'item_alias' => $row->alias, 'Itemid' => $Itemid, 'layout' => $layout); $row->href = $row->alias ? $row->alias : 'item' . $row->id; $row->link = SimplelistsHelper::getUrl($needles); $row->title = htmlspecialchars($row->title); $row->params = YireoHelper::toParameter($row->params); if ($params->get('show_image', 0) == 1) { $align = $row->params->get('picture_alignment'); if (empty($align)) { $align = $params->get('image_align', 'left'); } $attributes = 'alt="' . $row->title . '" title="' . $row->title . '" class="simplelists" style="float:' . $align . '"'; $image_file = JPATH_SITE . DS . str_replace('/', DS, $row->picture); if (is_file($image_file)) { $size = getimagesize($image_file); $attributes .= 'width="' . $size[0] . '" height="' . $size[1] . '"'; } $row->picture = JHTML::image($row->picture, $row->title, $attributes); } else { $row->picture = null; } $lists[$i] = $row; $i++; } } return $lists; }
public function prepareDisplay() { // Include extra component-related CSS $this->addCss('default.css'); $this->addCss('view-' . $this->_view . '.css'); if (YireoHelper::isJoomla15() == false) { $this->addCss('j16.css'); } // Include extra component-related JavaScript $this->addJs('default.js'); $this->addJs('view-' . $this->_view . '.js'); // Fetch parameters if they exist if (file_exists(JPATH_COMPONENT . '/models/' . $this->_name . '.xml')) { $file = JPATH_COMPONENT . '/models/' . $this->_name . '.xml'; $params = YireoHelper::toParameter($this->item->params, $file); } else { if (!empty($this->item->params)) { $params = YireoHelper::toParameter($this->item->params); } else { $params = null; } } // Assign parameters if (!empty($params)) { if (isset($this->item->created)) { $params->set('created', $this->item->created); } if (isset($this->item->created_by)) { $params->set('created_by', $this->item->created_by); } if (isset($this->item->modified)) { $params->set('modified', $this->item->modified); } if (isset($this->item->modified_by)) { $params->set('modified_by', $this->item->modified_by); } $this->assignRef('params', $params); } // Load the form if it's there if (YireoHelper::isJoomla15() == false) { $form = $this->get('Form'); $this->assignRef('form', $form); } // Assign common variables $this->assignRef('lists', $this->lists); $this->assignRef('user', $this->user); }
/** * Method to return the URL-value of a specific plugin */ public function getPluginLinkUrl($item) { $item->params = YireoHelper::toParameter($item->params); $return = null; if ($item->params->get('link_show', 1) == 0 && !empty($item->link)) { $url = 'index.php?option=com_simplelists&view=item&task=hidden&tmpl=component&id=' . $item->id; if ($item->alias) { $url .= ':' . $item->alias; } $return = JRoute::_($url); } else { $plugin = self::getPlugin('simplelistslink', $item->link_type); if (!empty($plugin)) { $return = $plugin->getUrl($item); } } return $return; }
/** * Method to get data * * @access public * @subpackage Yireo * @param null * @return array */ public function getData($forceNew = false) { // Load the data if they are not just set or if the force-flag is set if ($this->_data === null || $forceNew == self::FORCE_NEW) { // Load some empty data-set $this->getEmpty(); // Try to load the temporary data from this session $this->loadTmpSession(); // Singular model if ($this->isSingular() && $this->getId() > 0) { $query = $this->buildQuery(); $data = $this->getDbResult($query, 'object'); if (!empty($data)) { // Prepare the column-fields if (!empty($this->_columnFields)) { foreach ($this->_columnFields as $columnField) { if (!empty($data->{$columnField}) && !is_array($data->{$columnField})) { $data->{$columnField} = explode('|', $data->{$columnField}); } } } // Allow to modify the data if (method_exists($this, 'onDataLoad')) { $data = $this->onDataLoad($data); } // Set the ID $key = $this->getPrimaryKey(); $data->id = $data->{$key}; $data->metadata = $this->getMetadata(); $this->_data = $data; } else { $data = (object) null; } // Check to see if the data is published $stateField = $this->_tbl->getStateField(); if ($this->app->isSite() && isset($data->{$stateField}) && $data->{$stateField} == 0) { JError::raiseError(404, JText::_('LIB_YIREO_MODEL_NOT_FOUND')); return; } // Fill in non-existing fields foreach ($this->getEmptyFields() as $fieldName => $fieldValue) { if (!isset($data->{$fieldName})) { $data->{$fieldName} = $fieldValue; } } // Plural model } else { if ($this->isSingular() == false) { $query = $this->buildQuery(); $data = $this->getDbResult($query, 'objectList'); if (!empty($data)) { // Prepare these data foreach ($data as $index => $item) { // Frontend permissions if ($this->app->isSite() && isset($item->access) && is_numeric($item->access)) { $accessLevels = $this->user->getAuthorisedViewLevels(); if (YireoHelper::isJoomla25()) { if (!array_key_exists($item->access, $accessLevels) || $accessLevels[$item->access] == 0) { unset($data[$index]); continue; } } else { if ($item->access > 0 && !in_array($item->access, $accessLevels)) { unset($data[$index]); continue; } } } // Backend permissions if ($this->app->isAdmin() && (bool) $this->_tbl->hasAssetId() == true) { // Get the ID $key = $this->getPrimaryKey(); $id = $item->{$key}; // Determine the owner $owner = 0; if (!empty($item->created_by)) { $owner = (int) $item->created_by; } elseif (!empty($item->modified_by)) { $owner = (int) $item->modified_by; } elseif (!empty($item->owned_by)) { $owner = (int) $item->owned_by; } if ($owner == 0) { $owner = $this->user->id; } // Get the ACL rules $canEdit = $this->user->authorise('core.edit', $this->_option); $canEditOwn = $this->user->authorise('core.edit.own', $this->_option); // Determine authorisation $authorise = false; if ($canEdit) { $authorise = true; } elseif ($canEditOwn && $owner == $this->user->id) { $authorise = true; } // Authorise if ($authorise == false) { unset($data[$index]); continue; } } // Prepare the column-fields if (!empty($this->_columnFields)) { foreach ($this->_columnFields as $columnField) { if (!empty($item->{$columnField}) && !is_array($item->{$columnField})) { $item->{$columnField} = explode('|', $item->{$columnField}); } } } // Prepare the parameters if (isset($item->params)) { $item->params = YireoHelper::toParameter($item->params); } else { $item->params = YireoHelper::toParameter(); } // Check for publish_up and publish_down if ($this->app->isSite()) { $publish_up = $item->params->get('publish_up'); $publish_down = $item->params->get('publish_down'); if (!empty($publish_up) && strtotime($publish_up) > time()) { unset($data[$index]); continue; } else { if (!empty($publish_down) && strtotime($publish_down) < time()) { unset($data[$index]); continue; } } } // Allow to modify the data if (method_exists($this, 'onDataLoad')) { $item = $this->onDataLoad($item); } // Add the metadata $item->metadata = $this->getMetadata(); // Set the ID $key = $this->getPrimaryKey(); $item->id = $item->{$key}; // Fill in non-existing fields foreach ($this->getEmptyFields() as $fieldName => $fieldValue) { if (!isset($item->{$fieldName})) { $item->{$fieldName} = $fieldValue; } } // Re-insert this item $data[$index] = $item; } if ($this->_limit_query == false) { $this->_total = count($data); } $this->_data = $data; } } } // Allow to modify the data afterwards if (method_exists($this, 'onDataLoadAfter')) { $data = $this->onDataLoadAfter($data); } } if ($this->isSingular() == false && $this->_limit_query == false && $this->getState('limit') > 0) { $part = array_slice($this->_data, $this->getState('limitstart'), $this->getState('limit')); return $part; } return $this->_data; }
public function prepareCategory($category, $layout) { // Sanity check if (!is_object($category)) { return null; } // Convert the parameters to an object $category->params = YireoHelper::toParameter($category->params); $params = $this->params; // Override the default parameters with the category parameters foreach ($category->params->toArray() as $name => $value) { if ($value != '') { $params->set($name, $value); } } // Override the layout $layout = $category->params->get('layout'); if (!empty($layout)) { $this->setLayout($layout); } // Prepare the category URL if ($params->get('show_category_parent') && !empty($category->parent)) { $needles = array('category_id' => $category->parent->id); if (isset($category->parent->alias)) { $needles['category_alias'] = $category->parent->alias; } $category->parent->link = SimplelistsHelper::getUrl($needles); } // Loop through the child-categories if ($params->get('show_category_childs') && !empty($category->childs)) { foreach ($category->childs as $child) { $child->params = YireoHelper::toParameter($child->params); $child_layout = $child->params->get('layout', $layout); $needles = array('category_id' => $child->id, 'category_alias' => $child->alias, 'layout' => $child_layout); $child->link = SimplelistsHelper::getUrl($needles); } } // Set the correct page-title if ($params->get('show_page_title') == 1 && $params->get('page_title') != '') { $category->title = $params->get('page_title'); } // Run the category content through Content Plugins if ($params->get('show_category_description') && !empty($category->description)) { $category->text = $category->description; $this->firePlugins($category, array()); $category->description = $category->text; $category->text = null; } // Prepare the category image if ($params->get('show_category_image') && isset($category->image) && !empty($category->image)) { $category->image = JHTML::image($category->image, $category->title, array('align' => $category->image_position)); } else { $params->set('show_category_image', 0); } }
/** * Method to get data * * @access public * @subpackage Yireo * @param null * @return array */ public function getData($forceNew = false) { // Load the data if they are not just set or if the force-flag is set if ($this->_data === null || $forceNew == self::FORCE_NEW) { // Load some empty data-set $this->getEmpty(); // Try to load the temporary data from this session $this->loadTmpSession(); // Singular model if ($this->isSingular() && $this->getId() > 0) { $query = $this->buildQuery(); $this->_db->setQuery($query); if (isset($this->_debug) && $this->_debug == true) { JError::raiseNotice('Query', $this->getDbDebug()); } $data = $this->_db->loadObject(); if ($this->_db->getErrorMsg()) { JError::raiseWarning('DB error', $this->_db->getErrorMsg()); } if (!empty($data)) { // Allow to modify the data if (method_exists($this, 'onDataLoad')) { $data = $this->onDataLoad($data); } $data->metadata = $this->getMetadata(); $this->_data = $data; } // Check to see if the data is published $stateField = $this->_tbl->getStateField(); if ($this->application->isSite() && isset($data->{$stateField}) && $data->{$stateField} == 0) { JError::raiseError(404, JText::_('LIB_YIREO_MODEL_NOT_FOUND')); return; } // Check whether this items access level allows access if (YireoHelper::isJoomla15()) { if (isset($data->access) && is_numeric($data->access)) { if ($data->access > $this->user->get('aid', 0)) { JError::raiseError(403, JText::_('LIB_YIREO_MODEL_NOT_AUTHORIZED')); return; } } } // Plural model } else { if ($this->isSingular() == false) { $query = $this->buildQuery(); $this->_db->setQuery($query); if (isset($this->_debug) && $this->_debug == true) { JError::raiseNotice('LIB_YIREO_MODEL_DEBUG_QUERY', $this->getDbDebug()); } $data = $this->_db->loadObjectList(); if ($this->_db->getErrorMsg()) { JError::raiseWarning('LIB_YIREO_MODEL_DEBUG_ERROR', $this->_db->getErrorMsg()); } if (!empty($data)) { // Prepare these data foreach ($data as $index => $item) { if (YireoHelper::isJoomla15()) { if ($this->application->isSite() && isset($item->access) && is_numeric($item->access)) { if ($item->access > $this->user->get('aid', 0)) { unset($data[$index]); continue; } } } else { // @todo: Make this compatible with Joomla! 1.7 if ((bool) $this->_tbl->hasAssetId() == true) { $key = $this->getPrimaryKey(); $id = $item->{$key}; $task = $id > 0 ? 'core.manage' : 'core.create'; if ($this->user->authorise($task, '#__simplelists_items.' . $id)) { //unset($data[$index]); //continue; } } } // Prepare the parameters if (isset($item->params)) { $item->params = YireoHelper::toParameter($item->params); } else { $item->params = YireoHelper::toParameter(); } // Check for publish_up and publish_down if ($this->application->isSite()) { $publish_up = $item->params->get('publish_up'); $publish_down = $item->params->get('publish_down'); if (!empty($publish_up) && strtotime($publish_up) > time()) { unset($data[$index]); continue; } else { if (!empty($publish_down) && strtotime($publish_down) < time()) { unset($data[$index]); continue; } } } // Allow to modify the data if (method_exists($this, 'onDataLoad')) { $item = $this->onDataLoad($item); } // Add the metadata $item->metadata = $this->getMetadata(); // Re-insert this item $data[$index] = $item; } $this->_data = $data; } } } } if ($this->isSingular() == false && $this->_limit_query == false && $this->getState('limit') > 0) { return array_slice($this->_data, $this->getState('limitstart'), $this->getState('limit')); } return $this->_data; }