Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu plugin #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 47 additions & 15 deletions articles/articles/article.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -25,6 +27,7 @@ class ArticlesApiResourceArticle extends ApiResource
*/
public function get()
{

$this->plugin->setResponse($this->getArticles());
}

Expand All @@ -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);

Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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);
Expand Down
33 changes: 33 additions & 0 deletions articles/articles/helper/articlehelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* @package API plugins
* @copyright Copyright (C) 2009 2014 Techjoomla, Tekdi Technologies Pvt. Ltd. All rights reserved.
* @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
* @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();
}
}


38 changes: 38 additions & 0 deletions menu/menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Menu
*
* @copyright Copyright (C) 2016 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die( 'Restricted access' );

jimport('joomla.plugin.plugin');

/**
* Importer Plugin.
*
* @since 3.0
*/
class PlgAPIMenu extends ApiPlugin
{
/**
* Constructor
*
* @param string &$subject The name of the Plugin group.
* @param array $config Config params array.
*
* @since 3.0
*/
public function __construct(&$subject, $config = array())
{
parent::__construct($subject = 'api', $config = array());

ApiResource::addIncludePath(dirname(__FILE__) . '/menu');

$this->setResourceAccess('menus', 'public', 'get');

}
}
16 changes: 16 additions & 0 deletions menu/menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="1.0" type="plugin" group="api" method="upgrade">
<name>Api - Joomla Menu</name>
<author>Techjoomla</author>
<creationDate>November 2017</creationDate>
<copyright>Copyright (C) 2017 - 2019 Open Source Matters. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>[email protected]</authorUrl>
<version>1.0.0</version>
<description>Joomla Menu API</description>
<files>
<filename plugin="menu">menu.php</filename>
<folder>menu</folder>
</files>
</extension>
62 changes: 62 additions & 0 deletions menu/menu/menus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Menu
*
* @copyright Copyright (C) 2016 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');

/**
* Menus Resource for Joomla Menu Plugin.
*
* @since 2.5
*/
class MenuApiResourceMenus extends ApiResource
{
/**
* GET function fetch batches or batch based on passed param
*
* ***INPUT PARAMS***
* *menutype - type of menu to get filtered items (not mandatory)
* *component - assigned component of menu to get filtered items (not mandatory)
*
* @return JSON batch details
*
* @since 3.0
**/
public function get()
{
$app = JFactory::getApplication();
$menu = $app->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);
}
}