Example #1
0
 /**
  * Parse method for URLs
  * This method is meant to transform the human readable URL back into
  * query parameters. It is only executed when SEF mode is switched on.
  *
  * @param   array &$segments The segments of the URL to parse.
  *
  * @return  array  The URL attributes to be used by the application.
  *
  * @since   3.3
  */
 public function parse(&$segments)
 {
     $vars = array();
     JLoader::register('Db8downloadFrontendHelper', JPATH_SITE . '/components/com_db8download/helpers/db8download.php');
     // view is always the first element of the array
     $vars['view'] = array_shift($segments);
     $model = Db8downloadFrontendHelper::getModel($vars['view']);
     while (!empty($segments)) {
         $segment = array_pop($segments);
         // If it's the ID, let's put on the request
         if (is_numeric($segment)) {
             $vars['id'] = $segment;
         } else {
             $id = $model->getItemIdByAlias(str_replace(':', '-', $segment));
             if (!empty($id)) {
                 $vars['id'] = $id;
             } else {
                 $vars['task'] = $vars['view'] . '.' . $segment;
             }
         }
     }
     return $vars;
 }
Example #2
0
 public function getItems()
 {
     $items = parent::getItems();
     foreach ($items as $item) {
         if (isset($item->catid)) {
             // Get the title of that particular template
             $title = Db8downloadFrontendHelper::getCategoryNameByCategoryId($item->catid);
             // Finally replace the data object with proper information
             $item->catid = !empty($title) ? $title : $item->catid;
         }
         if (isset($item->tags)) {
             // Catch the item tags (string with ',' coma glue)
             $tags = explode(",", $item->tags);
             $db = JFactory::getDbo();
             $namedTags = array();
             // Cleaning and initalization of named tags array
             // Get the tag names of each tag id
             foreach ($tags as $tag) {
                 $query = $db->getQuery(true);
                 $query->select("title");
                 $query->from('`#__tags`');
                 $query->where("id=" . intval($tag));
                 $db->setQuery($query);
                 $row = $db->loadObjectList();
                 // Read the row and get the tag name (title)
                 if (!is_null($row)) {
                     foreach ($row as $value) {
                         if ($value && isset($value->title)) {
                             $namedTags[] = trim($value->title);
                         }
                     }
                 }
             }
             // Finally replace the data object with proper information
             $item->tags = !empty($namedTags) ? implode(', ', $namedTags) : $item->tags;
         }
     }
     return $items;
 }