From 200b45daff73d9c95ff6db98e5b51fd64cee7d14 Mon Sep 17 00:00:00 2001 From: Sushan G Date: Fri, 29 Dec 2017 16:59:16 +0530 Subject: [PATCH 1/2] Task #116609 feat: Update Articles plugin of com_api --- articles/articles/article.php | 62 ++++++++++++++++------ articles/articles/helper/articlehelper.php | 33 ++++++++++++ 2 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 articles/articles/helper/articlehelper.php diff --git a/articles/articles/article.php b/articles/articles/article.php index 3aeb2ee..2d49d3e 100644 --- a/articles/articles/article.php +++ b/articles/articles/article.php @@ -8,7 +8,9 @@ defined('_JEXEC') or die( 'Restricted access' ); require_once JPATH_SITE . '/components/com_content/models/articles.php'; require_once JPATH_SITE . '/components/com_content/models/article.php'; - +require_once JPATH_SITE . '/plugins/api/articles/articles/helper/articlehelper.php'; +require_once JPATH_SITE . '/components/com_content/helpers/route.php'; +//JLoader::register('ContentHelperRoute', $com_path . 'helpers/route.php'); /** * Articles Resource * @@ -25,6 +27,7 @@ class ArticlesApiResourceArticle extends ApiResource */ public function get() { + $this->plugin->setResponse($this->getArticles()); } @@ -49,26 +52,30 @@ public function delete() */ public function getArticles() { - $app = JFactory::getApplication(); - $items = array(); - $article_id = $app->input->get('id', 0, 'INT'); - $catid = $app->input->get('category_id', 0, 'INT'); + $app = JFactory::getApplication(); + $items = array(); + + $articleHelper = new ArticleContentHelper(); + + $article_alias = $app->input->get('article_alias', '', 'STRING'); + $article_id = $app->input->get('id', 0, 'INT'); + $catid = $app->input->get('category_id', 0, 'INT'); // Featured - hide,only,show $featured = $app->input->get('featured', 0, 'INT'); $created_by = $app->input->get('created_by', 0, 'INT'); - $search = $app->input->get('search', '', 'STRING'); + $search = $app->input->get('search', '', 'STRING'); $limitstart = $app->input->get('limitstart', 0, 'INT'); - $limit = $app->input->get('limit', 0, 'INT'); + $limit = $app->input->get('limit', 0, 'INT'); $date_filtering = $app->input->get('date_filtering', '', 'STRING'); - $start_date = $app->input->get('start_date_range', '', 'STRING'); - $end_date = $app->input->get('end_date_range', '', 'STRING'); - $realtive_date = $app->input->get('relative_date', '', 'STRING'); + $start_date = $app->input->get('start_date_range', '', 'STRING'); + $end_date = $app->input->get('end_date_range', '', 'STRING'); + $realtive_date = $app->input->get('relative_date', '', 'STRING'); - $listOrder = $app->input->get('listOrder', 'ASC', 'STRING'); + $listOrder = $app->input->get('listOrder', 'ASC', 'STRING'); - $art_obj = new ContentModelArticles; + $art_obj = new ContentModelArticles; $art_obj->setState('list.direction', $listOrder); @@ -107,6 +114,19 @@ public function getArticles() $art_obj->setState('filter.article_id', $article_id); } + if($article_alias) + { + $params = JComponentHelper::getParams('com_content'); + + if (!$params->get('sef_ids', 0)) + { + $article_alias = substr($article_alias, ($pos = strpos($article_alias, '-')) !== false ? $pos + 1 : 0); + } + + $article_id = $articleHelper->getArticleIdByAlias($article_alias); + $art_obj->setState('filter.article_id', $article_id); + } + // Filtering if ($date_filtering) { @@ -119,10 +139,12 @@ public function getArticles() } } - $rows = $art_obj->getItems(); + $rows = $art_obj->getItems(); + + $num_articles = $art_obj->getTotal(); - $num_articles = $art_obj->getTotal(); - $data[] = new stdClass; + if (!empty($rows)) + $data[] = new stdClass; foreach ($rows as $subKey => $subArray) { @@ -137,7 +159,17 @@ public function getArticles() $data[$subKey]->modified = $subArray->modified; $data[$subKey]->publish_up = $subArray->publish_up; $data[$subKey]->publish_down = $subArray->publish_down; + $data[$subKey]->nonsef = 'index.php?option=com_content&view=article&id=' . $subArray->id . '&catid=' . $subArray->catid; + $data[$subKey]->puresef = $articleLink = JRoute::_('index.php?option=com_content&view=article&id=' . $subArray->id . '&catid=' . $subArray->catid); + $uribase = JURI::base(true); + + if (trim($uribase, '/') && substr($articleLink, 0, strlen($uribase)) == $uribase) + { + $articleLink = substr($articleLink, strlen($uribase)); + } + $data[$subKey]->link = $articleLink; + if ($subArray->images) { $images = json_decode($subArray->images); diff --git a/articles/articles/helper/articlehelper.php b/articles/articles/helper/articlehelper.php new file mode 100644 index 0000000..d6bcc8a --- /dev/null +++ b/articles/articles/helper/articlehelper.php @@ -0,0 +1,33 @@ + + * @link http://www.techjoomla.com +*/ + +defined('_JEXEC') or die('Restricted access'); + +class ArticleContentHelper +{ + public function __construct() + { + $this->app = JFactory::getApplication(); + $this->database = JFactory::getDBO(); + } + + public function getArticleIdByAlias($article_alias) + { + $query = $this->database->getQuery(true); + $query->select($this->database->quoteName(array('id'))); + $query->from($this->database->quoteName('#__content')); + $query->where($this->database->quoteName('alias') . ' = '. $this->database->quote(trim($article_alias))); + + $this->database->setQuery($query); + + return $this->database->loadResult(); + } +} + + From 0c411fc0db15804414c7b7807cddc4108bf8f9cd Mon Sep 17 00:00:00 2001 From: Sushan G Date: Fri, 29 Dec 2017 17:01:52 +0530 Subject: [PATCH 2/2] Task #115739 feat: Plugin for Joomla Menu --- menu/menu.php | 38 +++++++++++++++++++++++++++ menu/menu.xml | 16 ++++++++++++ menu/menu/menus.php | 62 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100755 menu/menu.php create mode 100755 menu/menu.xml create mode 100644 menu/menu/menus.php diff --git a/menu/menu.php b/menu/menu.php new file mode 100755 index 0000000..fdd85ed --- /dev/null +++ b/menu/menu.php @@ -0,0 +1,38 @@ +setResourceAccess('menus', 'public', 'get'); + + } +} diff --git a/menu/menu.xml b/menu/menu.xml new file mode 100755 index 0000000..06d1b05 --- /dev/null +++ b/menu/menu.xml @@ -0,0 +1,16 @@ + + + Api - Joomla Menu + Techjoomla + November 2017 + Copyright (C) 2017 - 2019 Open Source Matters. All rights reserved. + GNU General Public License version 2 or later; see LICENSE.txt + connnect@techjoomla.com + connnect@techjoomla.com + 1.0.0 + Joomla Menu API + + menu.php + menu + + diff --git a/menu/menu/menus.php b/menu/menu/menus.php new file mode 100644 index 0000000..d1671bc --- /dev/null +++ b/menu/menu/menus.php @@ -0,0 +1,62 @@ +getMenu(); + $jinput = $app->input; + + $filterKeys = array(); + $filterVals = array(); + + if ($menuType = $jinput->get('menutype', '', 'STRING')) + { + array_push($filterKeys, 'menutype'); + array_push($filterVals, $menuType); + } + + if ($component = $jinput->get('component', '', 'STRING')) + { + array_push($filterKeys, 'component'); + array_push($filterVals, $component); + } + + if($level = $jinput->get('level', 1, 'INT')) + { + array_push($filterKeys, 'level'); + array_push($filterVals, $level); + } + + $items = $menu->getItems($filterKeys, $filterVals); + + $this->plugin->setResponse($items); + } +}