primo commit
This commit is contained in:
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\Language\Associations;
|
||||
use Joomla\CMS\Language\LanguageHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\Response\JsonResponse;
|
||||
use Joomla\CMS\Session\Session;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* The newsfeed controller for ajax requests
|
||||
*
|
||||
* @since 3.9.0
|
||||
*/
|
||||
class AjaxController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Method to fetch associations of a newsfeed
|
||||
*
|
||||
* The method assumes that the following http parameters are passed in an Ajax Get request:
|
||||
* token: the form token
|
||||
* assocId: the id of the newsfeed whose associations are to be returned
|
||||
* excludeLang: the association for this language is to be excluded
|
||||
*
|
||||
* @return null
|
||||
*
|
||||
* @since 3.9.0
|
||||
*/
|
||||
public function fetchAssociations()
|
||||
{
|
||||
if (!Session::checkToken('get')) {
|
||||
echo new JsonResponse(null, Text::_('JINVALID_TOKEN'), true);
|
||||
} else {
|
||||
$assocId = $this->input->getInt('assocId', 0);
|
||||
|
||||
if ($assocId == 0) {
|
||||
echo new JsonResponse(null, Text::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', 'assocId'), true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$excludeLang = $this->input->get('excludeLang', '', 'STRING');
|
||||
|
||||
$associations = Associations::getAssociations('com_newsfeeds', '#__newsfeeds', 'com_newsfeeds.item', (int) $assocId);
|
||||
|
||||
unset($associations[$excludeLang]);
|
||||
|
||||
// Add the title to each of the associated records
|
||||
$newsfeedsTable = $this->factory->createTable('Newsfeed', 'Administrator');
|
||||
|
||||
foreach ($associations as $association) {
|
||||
$newsfeedsTable->load($association->id);
|
||||
$association->title = $newsfeedsTable->name;
|
||||
}
|
||||
|
||||
$countContentLanguages = \count(LanguageHelper::getContentLanguages([0, 1], false));
|
||||
|
||||
if (\count($associations) == 0) {
|
||||
$message = Text::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE');
|
||||
} elseif ($countContentLanguages > \count($associations) + 2) {
|
||||
$tags = implode(', ', array_keys($associations));
|
||||
$message = Text::sprintf('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME', $tags);
|
||||
} else {
|
||||
$message = Text::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_ALL');
|
||||
}
|
||||
|
||||
echo new JsonResponse($associations, $message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\Router\Route;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Newsfeeds display controller.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class DisplayController extends BaseController
|
||||
{
|
||||
/**
|
||||
* The default view.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $default_view = 'newsfeeds';
|
||||
|
||||
/**
|
||||
* Method to display a view.
|
||||
*
|
||||
* @param boolean $cachable If true, the view output will be cached
|
||||
* @param array $urlparams An array of safe URL parameters and their variable types.
|
||||
* @see \Joomla\CMS\Filter\InputFilter::clean() for valid values.
|
||||
*
|
||||
* @return static|boolean This object to support chaining.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function display($cachable = false, $urlparams = [])
|
||||
{
|
||||
$view = $this->input->get('view', 'newsfeeds');
|
||||
$layout = $this->input->get('layout', 'default');
|
||||
$id = $this->input->getInt('id');
|
||||
|
||||
// Check for edit form.
|
||||
if ($view == 'newsfeed' && $layout == 'edit' && !$this->checkEditId('com_newsfeeds.edit.newsfeed', $id)) {
|
||||
// Somehow the person just went to the form - we don't allow that.
|
||||
if (!\count($this->app->getMessageQueue())) {
|
||||
$this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error');
|
||||
}
|
||||
|
||||
$this->setRedirect(Route::_('index.php?option=com_newsfeeds&view=newsfeeds', false));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return parent::display();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\MVC\Controller\FormController;
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Versioning\VersionableControllerTrait;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Newsfeed controller class.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class NewsfeedController extends FormController
|
||||
{
|
||||
use VersionableControllerTrait;
|
||||
|
||||
/**
|
||||
* Method override to check if you can add a new record.
|
||||
*
|
||||
* @param array $data An array of input data.
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function allowAdd($data = [])
|
||||
{
|
||||
$categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('filter_category_id'), 'int');
|
||||
$allow = null;
|
||||
|
||||
if ($categoryId) {
|
||||
// If the category has been passed in the URL check it.
|
||||
$allow = $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId);
|
||||
}
|
||||
|
||||
if ($allow === null) {
|
||||
// In the absence of better information, revert to the component permissions.
|
||||
return parent::allowAdd($data);
|
||||
}
|
||||
|
||||
return $allow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check if you can edit a record.
|
||||
*
|
||||
* @param array $data An array of input data.
|
||||
* @param string $key The name of the key for the primary key.
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function allowEdit($data = [], $key = 'id')
|
||||
{
|
||||
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
|
||||
|
||||
// Since there is no asset tracking, fallback to the component permissions.
|
||||
if (!$recordId) {
|
||||
return parent::allowEdit($data, $key);
|
||||
}
|
||||
|
||||
// Get the item.
|
||||
$item = $this->getModel()->getItem($recordId);
|
||||
|
||||
// Since there is no item, return false.
|
||||
if (empty($item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = $this->app->getIdentity();
|
||||
|
||||
// Check if can edit own core.edit.own.
|
||||
$canEditOwn = $user->authorise('core.edit.own', $this->option . '.category.' . (int) $item->catid) && $item->created_by == $user->id;
|
||||
|
||||
// Check the category core.edit permissions.
|
||||
return $canEditOwn || $user->authorise('core.edit', $this->option . '.category.' . (int) $item->catid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to run batch operations.
|
||||
*
|
||||
* @param object $model The model.
|
||||
*
|
||||
* @return boolean True if successful, false otherwise and internal error is set.
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
public function batch($model = null)
|
||||
{
|
||||
$this->checkToken();
|
||||
|
||||
// Set the model
|
||||
$model = $this->getModel('Newsfeed', '', []);
|
||||
|
||||
// Preset the redirect
|
||||
$this->setRedirect(Route::_('index.php?option=com_newsfeeds&view=newsfeeds' . $this->getRedirectToListAppend(), false));
|
||||
|
||||
return parent::batch($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to cancel an edit.
|
||||
*
|
||||
* @param string $key The name of the primary key of the URL variable.
|
||||
*
|
||||
* @return boolean True if access level checks pass, false otherwise.
|
||||
*
|
||||
* @since 5.1.0
|
||||
*/
|
||||
public function cancel($key = null)
|
||||
{
|
||||
$result = parent::cancel($key);
|
||||
|
||||
// When editing in modal then redirect to modalreturn layout
|
||||
if ($result && $this->input->get('layout') === 'modal') {
|
||||
$id = $this->input->get('id');
|
||||
$return = 'index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($id)
|
||||
. '&layout=modalreturn&from-task=cancel';
|
||||
|
||||
$this->setRedirect(Route::_($return, false));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that allows child controller access to model data
|
||||
* after the data has been saved.
|
||||
*
|
||||
* @param BaseDatabaseModel $model The data model object.
|
||||
* @param array $validData The validated data.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 5.1.0
|
||||
*/
|
||||
protected function postSaveHook(BaseDatabaseModel $model, $validData = [])
|
||||
{
|
||||
// When editing in modal then redirect to modalreturn layout
|
||||
if ($this->input->get('layout') === 'modal' && $this->task === 'save') {
|
||||
$id = $model->getState('newsfeed.id', '');
|
||||
$return = 'index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($id)
|
||||
. '&layout=modalreturn&from-task=save';
|
||||
|
||||
$this->setRedirect(Route::_($return, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\AdminController;
|
||||
use Joomla\CMS\Response\JsonResponse;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Newsfeeds list controller class.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class NewsfeedsController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Method to get a model object, loading it if required.
|
||||
*
|
||||
* @param string $name The model name. Optional.
|
||||
* @param string $prefix The class prefix. Optional.
|
||||
* @param array $config Configuration array for model. Optional.
|
||||
*
|
||||
* @return object The model.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getModel($name = 'Newsfeed', $prefix = 'Administrator', $config = ['ignore_request' => true])
|
||||
{
|
||||
return parent::getModel($name, $prefix, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the number of published newsfeeds for quickicons
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
public function getQuickiconContent()
|
||||
{
|
||||
$model = $this->getModel('newsfeeds');
|
||||
|
||||
$model->setState('filter.published', 1);
|
||||
|
||||
$amount = (int) $model->getTotal();
|
||||
|
||||
$result = [];
|
||||
|
||||
$result['amount'] = $amount;
|
||||
$result['sronly'] = Text::plural('COM_NEWSFEEDS_N_QUICKICON_SRONLY', $amount);
|
||||
$result['name'] = Text::plural('COM_NEWSFEEDS_N_QUICKICON', $amount);
|
||||
|
||||
echo new JsonResponse($result);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Extension;
|
||||
|
||||
use Joomla\CMS\Association\AssociationServiceInterface;
|
||||
use Joomla\CMS\Association\AssociationServiceTrait;
|
||||
use Joomla\CMS\Categories\CategoryServiceInterface;
|
||||
use Joomla\CMS\Categories\CategoryServiceTrait;
|
||||
use Joomla\CMS\Component\Router\RouterServiceInterface;
|
||||
use Joomla\CMS\Component\Router\RouterServiceTrait;
|
||||
use Joomla\CMS\Extension\BootableExtensionInterface;
|
||||
use Joomla\CMS\Extension\MVCComponent;
|
||||
use Joomla\CMS\HTML\HTMLRegistryAwareTrait;
|
||||
use Joomla\CMS\Tag\TagServiceInterface;
|
||||
use Joomla\CMS\Tag\TagServiceTrait;
|
||||
use Joomla\Component\Newsfeeds\Administrator\Service\HTML\AdministratorService;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Component class for com_newsfeeds
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class NewsfeedsComponent extends MVCComponent implements
|
||||
BootableExtensionInterface,
|
||||
CategoryServiceInterface,
|
||||
AssociationServiceInterface,
|
||||
RouterServiceInterface,
|
||||
TagServiceInterface
|
||||
{
|
||||
use AssociationServiceTrait;
|
||||
use HTMLRegistryAwareTrait;
|
||||
use RouterServiceTrait;
|
||||
use CategoryServiceTrait, TagServiceTrait {
|
||||
CategoryServiceTrait::getTableNameForSection insteadof TagServiceTrait;
|
||||
CategoryServiceTrait::getStateColumnForSection insteadof TagServiceTrait;
|
||||
}
|
||||
|
||||
/**
|
||||
* Booting the extension. This is the function to set up the environment of the extension like
|
||||
* registering new class loaders, etc.
|
||||
*
|
||||
* If required, some initial set up can be done from services of the container, eg.
|
||||
* registering HTML services.
|
||||
*
|
||||
* @param ContainerInterface $container The container
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function boot(ContainerInterface $container)
|
||||
{
|
||||
$this->getRegistry()->register('newsfeedsadministrator', new AdministratorService());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the table for the count items functions for the given section.
|
||||
*
|
||||
* @param ?string $section The section
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function getTableNameForSection(?string $section = null)
|
||||
{
|
||||
return $section === 'category' ? 'categories' : 'newsfeeds';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state column for the count items functions for the given section.
|
||||
*
|
||||
* @param ?string $section The section
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function getStateColumnForSection(?string $section = null)
|
||||
{
|
||||
return 'published';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Field\Modal;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Field\ModalSelectField;
|
||||
use Joomla\CMS\Language\LanguageHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Layout\FileLayout;
|
||||
use Joomla\CMS\Session\Session;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\Database\ParameterType;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Supports a modal newsfeeds picker.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class NewsfeedField extends ModalSelectField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $type = 'Modal_Newsfeed';
|
||||
|
||||
/**
|
||||
* Method to attach a Form object to the field.
|
||||
*
|
||||
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
|
||||
* @param mixed $value The form field value to validate.
|
||||
* @param string $group The field name group control value.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @see FormField::setup()
|
||||
* @since 5.1.0
|
||||
*/
|
||||
public function setup(\SimpleXMLElement $element, $value, $group = null)
|
||||
{
|
||||
// Check if the value consist with id:alias, extract the id only
|
||||
if ($value && str_contains($value, ':')) {
|
||||
[$id] = explode(':', $value, 2);
|
||||
$value = (int) $id;
|
||||
}
|
||||
|
||||
$result = parent::setup($element, $value, $group);
|
||||
|
||||
if (!$result) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
Factory::getApplication()->getLanguage()->load('com_newsfeeds', JPATH_ADMINISTRATOR);
|
||||
|
||||
$languages = LanguageHelper::getContentLanguages([0, 1], false);
|
||||
$language = (string) $this->element['language'];
|
||||
|
||||
// Prepare enabled actions
|
||||
$this->canDo['propagate'] = ((string) $this->element['propagate'] == 'true') && \count($languages) > 2;
|
||||
|
||||
// Prepare Urls
|
||||
$linkitems = (new Uri())->setPath(Uri::base(true) . '/index.php');
|
||||
$linkitems->setQuery([
|
||||
'option' => 'com_newsfeeds',
|
||||
'view' => 'newsfeeds',
|
||||
'layout' => 'modal',
|
||||
'tmpl' => 'component',
|
||||
Session::getFormToken() => 1,
|
||||
]);
|
||||
$linkItem = clone $linkitems;
|
||||
$linkItem->setVar('view', 'newsfeed');
|
||||
$linkCheckin = (new Uri())->setPath(Uri::base(true) . '/index.php');
|
||||
$linkCheckin->setQuery([
|
||||
'option' => 'com_newsfeeds',
|
||||
'task' => 'newsfeeds.checkin',
|
||||
'format' => 'json',
|
||||
Session::getFormToken() => 1,
|
||||
]);
|
||||
|
||||
if ($language) {
|
||||
$linkitems->setVar('forcedLanguage', $language);
|
||||
$linkItem->setVar('forcedLanguage', $language);
|
||||
|
||||
$modalTitle = Text::_('COM_NEWSFEEDS_SELECT_A_FEED') . ' — ' . $this->getTitle();
|
||||
|
||||
$this->dataAttributes['data-language'] = $language;
|
||||
} else {
|
||||
$modalTitle = Text::_('COM_NEWSFEEDS_SELECT_A_FEED');
|
||||
}
|
||||
|
||||
$urlSelect = $linkitems;
|
||||
$urlEdit = clone $linkItem;
|
||||
$urlEdit->setVar('task', 'newsfeed.edit');
|
||||
$urlNew = clone $linkItem;
|
||||
$urlNew->setVar('task', 'newsfeed.add');
|
||||
|
||||
$this->urls['select'] = (string) $urlSelect;
|
||||
$this->urls['new'] = (string) $urlNew;
|
||||
$this->urls['edit'] = (string) $urlEdit;
|
||||
$this->urls['checkin'] = (string) $linkCheckin;
|
||||
|
||||
// Prepare titles
|
||||
$this->modalTitles['select'] = $modalTitle;
|
||||
$this->modalTitles['new'] = Text::_('COM_NEWSFEEDS_NEW_NEWSFEED');
|
||||
$this->modalTitles['edit'] = Text::_('COM_NEWSFEEDS_EDIT_NEWSFEED');
|
||||
|
||||
$this->hint = $this->hint ?: Text::_('COM_NEWSFEEDS_SELECT_A_FEED');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve the title of selected item.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 5.1.0
|
||||
*/
|
||||
protected function getValueTitle()
|
||||
{
|
||||
$value = (int) $this->value ?: '';
|
||||
$title = '';
|
||||
|
||||
if ($value) {
|
||||
try {
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('name'))
|
||||
->from($db->quoteName('#__newsfeeds'))
|
||||
->where($db->quoteName('id') . ' = :value')
|
||||
->bind(':value', $value, ParameterType::INTEGER);
|
||||
$db->setQuery($query);
|
||||
|
||||
$title = $db->loadResult();
|
||||
} catch (\Throwable $e) {
|
||||
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
return $title ?: $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data to be passed to the layout for rendering.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 5.1.0
|
||||
*/
|
||||
protected function getLayoutData()
|
||||
{
|
||||
$data = parent::getLayoutData();
|
||||
$data['language'] = (string) $this->element['language'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the renderer
|
||||
*
|
||||
* @param string $layoutId Id to load
|
||||
*
|
||||
* @return FileLayout
|
||||
*
|
||||
* @since 5.1.0
|
||||
*/
|
||||
protected function getRenderer($layoutId = 'default')
|
||||
{
|
||||
$layout = parent::getRenderer($layoutId);
|
||||
$layout->setComponent('com_newsfeeds');
|
||||
$layout->setClient(1);
|
||||
|
||||
return $layout;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Field;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Field\ListField;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* News Feed List field.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class NewsfeedsField extends ListField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $type = 'Newsfeeds';
|
||||
|
||||
/**
|
||||
* Method to get the field options.
|
||||
*
|
||||
* @return array The field option objects.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
$options = [];
|
||||
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true)
|
||||
->select(
|
||||
[
|
||||
$db->quoteName('id', 'value'),
|
||||
$db->quoteName('name', 'text'),
|
||||
]
|
||||
)
|
||||
->from($db->quoteName('#__newsfeeds', 'a'))
|
||||
->order($db->quoteName('a.name'));
|
||||
|
||||
// Get the options.
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$options = $db->loadObjectList();
|
||||
} catch (\RuntimeException $e) {
|
||||
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
|
||||
}
|
||||
|
||||
// Merge any additional options in the XML definition.
|
||||
$options = array_merge(parent::getOptions(), $options);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Helper;
|
||||
|
||||
use Joomla\CMS\Association\AssociationExtensionHelper;
|
||||
use Joomla\CMS\Language\Associations;
|
||||
use Joomla\CMS\Table\Table;
|
||||
use Joomla\Component\Newsfeeds\Site\Helper\AssociationHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Content associations helper.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
class AssociationsHelper extends AssociationExtensionHelper
|
||||
{
|
||||
/**
|
||||
* The extension name
|
||||
*
|
||||
* @var array $extension
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
protected $extension = 'com_newsfeeds';
|
||||
|
||||
/**
|
||||
* Array of item types
|
||||
*
|
||||
* @var array $itemTypes
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
protected $itemTypes = ['newsfeed', 'category'];
|
||||
|
||||
/**
|
||||
* Has the extension association support
|
||||
*
|
||||
* @var boolean $associationsSupport
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
protected $associationsSupport = true;
|
||||
|
||||
/**
|
||||
* Method to get the associations for a given item.
|
||||
*
|
||||
* @param integer $id Id of the item
|
||||
* @param string $view Name of the view
|
||||
*
|
||||
* @return array Array of associations for the item
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getAssociationsForItem($id = 0, $view = null)
|
||||
{
|
||||
return AssociationHelper::getAssociations($id, $view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the associated items for an item
|
||||
*
|
||||
* @param string $typeName The item type
|
||||
* @param int $id The id of item for which we need the associated items
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
public function getAssociations($typeName, $id)
|
||||
{
|
||||
$type = $this->getType($typeName);
|
||||
|
||||
$context = $this->extension . '.item';
|
||||
$catidField = 'catid';
|
||||
|
||||
if ($typeName === 'category') {
|
||||
$context = 'com_categories.item';
|
||||
$catidField = '';
|
||||
}
|
||||
|
||||
// Get the associations.
|
||||
$associations = Associations::getAssociations(
|
||||
$this->extension,
|
||||
$type['tables']['a'],
|
||||
$context,
|
||||
$id,
|
||||
'id',
|
||||
'alias',
|
||||
$catidField
|
||||
);
|
||||
|
||||
return $associations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item information
|
||||
*
|
||||
* @param string $typeName The item type
|
||||
* @param int $id The id of item for which we need the associated items
|
||||
*
|
||||
* @return Table|null
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
public function getItem($typeName, $id)
|
||||
{
|
||||
if (empty($id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$table = null;
|
||||
|
||||
switch ($typeName) {
|
||||
case 'newsfeed':
|
||||
$table = Table::getInstance('NewsfeedTable', 'Joomla\\Component\\Newsfeeds\\Administrator\\Table\\');
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
$table = Table::getInstance('Category');
|
||||
break;
|
||||
}
|
||||
|
||||
if (empty($table)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$table->load($id);
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about the type
|
||||
*
|
||||
* @param string $typeName The item type
|
||||
*
|
||||
* @return array Array of item types
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
public function getType($typeName = '')
|
||||
{
|
||||
$fields = $this->getFieldsTemplate();
|
||||
$tables = [];
|
||||
$joins = [];
|
||||
$support = $this->getSupportTemplate();
|
||||
$title = '';
|
||||
|
||||
if (\in_array($typeName, $this->itemTypes)) {
|
||||
switch ($typeName) {
|
||||
case 'newsfeed':
|
||||
$fields['title'] = 'a.name';
|
||||
$fields['state'] = 'a.published';
|
||||
|
||||
$support['state'] = true;
|
||||
$support['acl'] = true;
|
||||
$support['checkout'] = true;
|
||||
$support['category'] = true;
|
||||
$support['save2copy'] = true;
|
||||
|
||||
$tables = [
|
||||
'a' => '#__newsfeeds',
|
||||
];
|
||||
$title = 'newsfeed';
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
$fields['created_user_id'] = 'a.created_user_id';
|
||||
$fields['ordering'] = 'a.lft';
|
||||
$fields['level'] = 'a.level';
|
||||
$fields['catid'] = '';
|
||||
$fields['state'] = 'a.published';
|
||||
|
||||
$support['state'] = true;
|
||||
$support['acl'] = true;
|
||||
$support['checkout'] = true;
|
||||
$support['level'] = true;
|
||||
|
||||
$tables = [
|
||||
'a' => '#__categories',
|
||||
];
|
||||
|
||||
$title = 'category';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'fields' => $fields,
|
||||
'support' => $support,
|
||||
'tables' => $tables,
|
||||
'joins' => $joins,
|
||||
'title' => $title,
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Helper;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Helper\ContentHelper;
|
||||
use Joomla\Database\ParameterType;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Newsfeeds component helper.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class NewsfeedsHelper extends ContentHelper
|
||||
{
|
||||
/**
|
||||
* Name of the extension
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $extension = 'com_newsfeeds';
|
||||
|
||||
/**
|
||||
* Adds Count Items for Category Manager.
|
||||
*
|
||||
* @param \stdClass[] &$items The banner category objects
|
||||
*
|
||||
* @return \stdClass[]
|
||||
*
|
||||
* @since 3.5
|
||||
*/
|
||||
public static function countItems(&$items)
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$query->select(
|
||||
[
|
||||
$db->quoteName('published', 'state'),
|
||||
'COUNT(*) AS ' . $db->quoteName('count'),
|
||||
]
|
||||
)
|
||||
->from($db->quoteName('#__newsfeeds'))
|
||||
->where($db->quoteName('catid') . ' = :id')
|
||||
->bind(':id', $id, ParameterType::INTEGER)
|
||||
->group($db->quoteName('state'));
|
||||
$db->setQuery($query);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$item->count_trashed = 0;
|
||||
$item->count_archived = 0;
|
||||
$item->count_unpublished = 0;
|
||||
$item->count_published = 0;
|
||||
|
||||
$id = (int) $item->id;
|
||||
$newfeeds = $db->loadObjectList();
|
||||
|
||||
foreach ($newfeeds as $newsfeed) {
|
||||
if ($newsfeed->state == 1) {
|
||||
$item->count_published = $newsfeed->count;
|
||||
}
|
||||
|
||||
if ($newsfeed->state == 0) {
|
||||
$item->count_unpublished = $newsfeed->count;
|
||||
}
|
||||
|
||||
if ($newsfeed->state == 2) {
|
||||
$item->count_archived = $newsfeed->count;
|
||||
}
|
||||
|
||||
if ($newsfeed->state == -2) {
|
||||
$item->count_trashed = $newsfeed->count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Count Items for Tag Manager.
|
||||
*
|
||||
* @param \stdClass[] &$items The newsfeed tag objects
|
||||
* @param string $extension The name of the active view.
|
||||
*
|
||||
* @return \stdClass[]
|
||||
*
|
||||
* @since 3.6
|
||||
*/
|
||||
public static function countTagItems(&$items, $extension)
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$parts = explode('.', $extension);
|
||||
$section = null;
|
||||
|
||||
if (\count($parts) > 1) {
|
||||
$section = $parts[1];
|
||||
}
|
||||
|
||||
$query->select(
|
||||
[
|
||||
$db->quoteName('published', 'state'),
|
||||
'COUNT(*) AS ' . $db->quoteName('count'),
|
||||
]
|
||||
)
|
||||
->from($db->quoteName('#__contentitem_tag_map', 'ct'));
|
||||
|
||||
if ($section === 'category') {
|
||||
$query->join('LEFT', $db->quoteName('#__categories', 'c'), $db->quoteName('ct.content_item_id') . ' = ' . $db->quoteName('c.id'));
|
||||
} else {
|
||||
$query->join('LEFT', $db->quoteName('#__newsfeeds', 'c'), $db->quoteName('ct.content_item_id') . ' = ' . $db->quoteName('c.id'));
|
||||
}
|
||||
|
||||
$query->where(
|
||||
[
|
||||
$db->quoteName('ct.tag_id') . ' = :id',
|
||||
$db->quoteName('ct.type_alias') . ' = :extension',
|
||||
]
|
||||
)
|
||||
->bind(':id', $id, ParameterType::INTEGER)
|
||||
->bind(':extension', $extension)
|
||||
->group($db->quoteName('state'));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$item->count_trashed = 0;
|
||||
$item->count_archived = 0;
|
||||
$item->count_unpublished = 0;
|
||||
$item->count_published = 0;
|
||||
|
||||
// Update ID used in database query.
|
||||
$id = (int) $item->id;
|
||||
$newsfeeds = $db->loadObjectList();
|
||||
|
||||
foreach ($newsfeeds as $newsfeed) {
|
||||
if ($newsfeed->state == 1) {
|
||||
$item->count_published = $newsfeed->count;
|
||||
}
|
||||
|
||||
if ($newsfeed->state == 0) {
|
||||
$item->count_unpublished = $newsfeed->count;
|
||||
}
|
||||
|
||||
if ($newsfeed->state == 2) {
|
||||
$item->count_archived = $newsfeed->count;
|
||||
}
|
||||
|
||||
if ($newsfeed->state == -2) {
|
||||
$item->count_trashed = $newsfeed->count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,429 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Model;
|
||||
|
||||
use Joomla\CMS\Application\ApplicationHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use Joomla\CMS\Language\Associations;
|
||||
use Joomla\CMS\Language\LanguageHelper;
|
||||
use Joomla\CMS\MVC\Model\AdminModel;
|
||||
use Joomla\CMS\Versioning\VersionableModelTrait;
|
||||
use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Newsfeed model.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class NewsfeedModel extends AdminModel
|
||||
{
|
||||
use VersionableModelTrait;
|
||||
|
||||
/**
|
||||
* The type alias for this content type.
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2
|
||||
*/
|
||||
public $typeAlias = 'com_newsfeeds.newsfeed';
|
||||
|
||||
/**
|
||||
* The context used for the associations table
|
||||
*
|
||||
* @var string
|
||||
* @since 3.4.4
|
||||
*/
|
||||
protected $associationsContext = 'com_newsfeeds.item';
|
||||
|
||||
/**
|
||||
* @var string The prefix to use with controller messages.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $text_prefix = 'COM_NEWSFEEDS';
|
||||
|
||||
/**
|
||||
* Method to test whether a record can be deleted.
|
||||
*
|
||||
* @param object $record A record object.
|
||||
*
|
||||
* @return boolean True if allowed to delete the record. Defaults to the permission set in the component.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function canDelete($record)
|
||||
{
|
||||
if (empty($record->id) || $record->published != -2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($record->catid)) {
|
||||
return $this->getCurrentUser()->authorise('core.delete', 'com_newsfeed.category.' . (int) $record->catid);
|
||||
}
|
||||
|
||||
return parent::canDelete($record);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to test whether a record can have its state changed.
|
||||
*
|
||||
* @param object $record A record object.
|
||||
*
|
||||
* @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function canEditState($record)
|
||||
{
|
||||
if (!empty($record->catid)) {
|
||||
return $this->getCurrentUser()->authorise('core.edit.state', 'com_newsfeeds.category.' . (int) $record->catid);
|
||||
}
|
||||
|
||||
return parent::canEditState($record);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data Data for the form.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
*
|
||||
* @return Form|bool A Form object on success, false on failure
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = [], $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_newsfeeds.newsfeed', 'newsfeed', ['control' => 'jform', 'load_data' => $loadData]);
|
||||
|
||||
if (empty($form)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Modify the form based on access controls.
|
||||
if (!$this->canEditState((object) $data)) {
|
||||
// Disable fields for display.
|
||||
$form->setFieldAttribute('ordering', 'disabled', 'true');
|
||||
$form->setFieldAttribute('published', 'disabled', 'true');
|
||||
$form->setFieldAttribute('publish_up', 'disabled', 'true');
|
||||
$form->setFieldAttribute('publish_down', 'disabled', 'true');
|
||||
|
||||
// Disable fields while saving.
|
||||
// The controller has already verified this is a record you can edit.
|
||||
$form->setFieldAttribute('ordering', 'filter', 'unset');
|
||||
$form->setFieldAttribute('published', 'filter', 'unset');
|
||||
$form->setFieldAttribute('publish_up', 'filter', 'unset');
|
||||
$form->setFieldAttribute('publish_down', 'filter', 'unset');
|
||||
}
|
||||
|
||||
// Don't allow to change the created_by user if not allowed to access com_users.
|
||||
if (!$this->getCurrentUser()->authorise('core.manage', 'com_users')) {
|
||||
$form->setFieldAttribute('created_by', 'filter', 'unset');
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return mixed The data for the form.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
// Check the session for previously entered form data.
|
||||
$data = Factory::getApplication()->getUserState('com_newsfeeds.edit.newsfeed.data', []);
|
||||
|
||||
if (empty($data)) {
|
||||
$data = $this->getItem();
|
||||
|
||||
// Prime some default values.
|
||||
if ($this->getState('newsfeed.id') == 0) {
|
||||
$app = Factory::getApplication();
|
||||
$data->set('catid', $app->getInput()->get('catid', $app->getUserState('com_newsfeeds.newsfeeds.filter.category_id'), 'int'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->preprocessData('com_newsfeeds.newsfeed', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save the form data.
|
||||
*
|
||||
* @param array $data The form data.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
$input = Factory::getApplication()->getInput();
|
||||
|
||||
// Create new category, if needed.
|
||||
$createCategory = true;
|
||||
|
||||
// If category ID is provided, check if it's valid.
|
||||
if (is_numeric($data['catid']) && $data['catid']) {
|
||||
$createCategory = !CategoriesHelper::validateCategoryId($data['catid'], 'com_newsfeeds');
|
||||
}
|
||||
|
||||
// Save New Category
|
||||
if ($createCategory && $this->canCreateCategory()) {
|
||||
$category = [
|
||||
// Remove #new# prefix, if exists.
|
||||
'title' => strpos($data['catid'], '#new#') === 0 ? substr($data['catid'], 5) : $data['catid'],
|
||||
'parent_id' => 1,
|
||||
'extension' => 'com_newsfeeds',
|
||||
'language' => $data['language'],
|
||||
'published' => 1,
|
||||
];
|
||||
|
||||
/** @var \Joomla\Component\Categories\Administrator\Model\CategoryModel $categoryModel */
|
||||
$categoryModel = Factory::getApplication()->bootComponent('com_categories')
|
||||
->getMVCFactory()->createModel('Category', 'Administrator', ['ignore_request' => true]);
|
||||
|
||||
// Create new category.
|
||||
if (!$categoryModel->save($category)) {
|
||||
$this->setError($categoryModel->getError());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the Category ID.
|
||||
$data['catid'] = $categoryModel->getState('category.id');
|
||||
}
|
||||
|
||||
// Alter the name for save as copy
|
||||
if ($input->get('task') == 'save2copy') {
|
||||
$origTable = clone $this->getTable();
|
||||
$origTable->load($input->getInt('id'));
|
||||
|
||||
if ($data['name'] == $origTable->name) {
|
||||
list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']);
|
||||
$data['name'] = $name;
|
||||
$data['alias'] = $alias;
|
||||
} else {
|
||||
if ($data['alias'] == $origTable->alias) {
|
||||
$data['alias'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
$data['published'] = 0;
|
||||
}
|
||||
|
||||
return parent::save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a single record.
|
||||
*
|
||||
* @param integer $pk The id of the primary key.
|
||||
*
|
||||
* @return mixed Object on success, false on failure.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItem($pk = null)
|
||||
{
|
||||
if ($item = parent::getItem($pk)) {
|
||||
// Convert the params field to an array.
|
||||
$registry = new Registry($item->metadata);
|
||||
$item->metadata = $registry->toArray();
|
||||
|
||||
// Convert the images field to an array.
|
||||
$registry = new Registry($item->images);
|
||||
$item->images = $registry->toArray();
|
||||
}
|
||||
|
||||
// Load associated newsfeeds items
|
||||
$assoc = Associations::isEnabled();
|
||||
|
||||
if ($assoc) {
|
||||
$item->associations = [];
|
||||
|
||||
if ($item->id != null) {
|
||||
$associations = Associations::getAssociations('com_newsfeeds', '#__newsfeeds', 'com_newsfeeds.item', $item->id);
|
||||
|
||||
foreach ($associations as $tag => $association) {
|
||||
$item->associations[$tag] = $association->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($item->id)) {
|
||||
$item->tags = new TagsHelper();
|
||||
$item->tags->getTagIds($item->id, 'com_newsfeeds.newsfeed');
|
||||
|
||||
// @todo: We probably don't need this in any client - but needs careful validation
|
||||
if (!Factory::getApplication()->isClient('api')) {
|
||||
$item->metadata['tags'] = $item->tags;
|
||||
}
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare and sanitise the table prior to saving.
|
||||
*
|
||||
* @param \Joomla\CMS\Table\Table $table The table object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareTable($table)
|
||||
{
|
||||
$date = Factory::getDate();
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
$table->name = htmlspecialchars_decode($table->name, ENT_QUOTES);
|
||||
$table->alias = ApplicationHelper::stringURLSafe($table->alias, $table->language);
|
||||
|
||||
if (empty($table->alias)) {
|
||||
$table->alias = ApplicationHelper::stringURLSafe($table->name, $table->language);
|
||||
}
|
||||
|
||||
if (empty($table->id)) {
|
||||
// Set the values
|
||||
$table->created = $date->toSql();
|
||||
|
||||
// Set ordering to the last item if not set
|
||||
if (empty($table->ordering)) {
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true)
|
||||
->select('MAX(' . $db->quoteName('ordering') . ')')
|
||||
->from($db->quoteName('#__newsfeeds'));
|
||||
$db->setQuery($query);
|
||||
$max = $db->loadResult();
|
||||
|
||||
$table->ordering = $max + 1;
|
||||
}
|
||||
} else {
|
||||
// Set the values
|
||||
$table->modified = $date->toSql();
|
||||
$table->modified_by = $user->id;
|
||||
}
|
||||
|
||||
// Increment the content version number.
|
||||
$table->version++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to change the published state of one or more records.
|
||||
*
|
||||
* @param array &$pks A list of the primary keys to change.
|
||||
* @param integer $value The value of the published state.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function publish(&$pks, $value = 1)
|
||||
{
|
||||
$result = parent::publish($pks, $value);
|
||||
|
||||
// Clean extra cache for newsfeeds
|
||||
$this->cleanCache('feed_parser');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* A protected method to get a set of ordering conditions.
|
||||
*
|
||||
* @param object $table A record object.
|
||||
*
|
||||
* @return array An array of conditions to add to ordering queries.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getReorderConditions($table)
|
||||
{
|
||||
return [
|
||||
$this->getDatabase()->quoteName('catid') . ' = ' . (int) $table->catid,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* A protected method to get a set of ordering conditions.
|
||||
*
|
||||
* @param Form $form The form object.
|
||||
* @param array $data The data to be injected into the form
|
||||
* @param string $group The plugin group to process
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function preprocessForm(Form $form, $data, $group = 'content')
|
||||
{
|
||||
if ($this->canCreateCategory()) {
|
||||
$form->setFieldAttribute('catid', 'allowAdd', 'true');
|
||||
|
||||
// Add a prefix for categories created on the fly.
|
||||
$form->setFieldAttribute('catid', 'customPrefix', '#new#');
|
||||
}
|
||||
|
||||
// Association newsfeeds items
|
||||
if (Associations::isEnabled()) {
|
||||
$languages = LanguageHelper::getContentLanguages(false, false, null, 'ordering', 'asc');
|
||||
|
||||
if (\count($languages) > 1) {
|
||||
$addform = new \SimpleXMLElement('<form />');
|
||||
$fields = $addform->addChild('fields');
|
||||
$fields->addAttribute('name', 'associations');
|
||||
$fieldset = $fields->addChild('fieldset');
|
||||
$fieldset->addAttribute('name', 'item_associations');
|
||||
|
||||
foreach ($languages as $language) {
|
||||
$field = $fieldset->addChild('field');
|
||||
$field->addAttribute('name', $language->lang_code);
|
||||
$field->addAttribute('type', 'modal_newsfeed');
|
||||
$field->addAttribute('language', $language->lang_code);
|
||||
$field->addAttribute('label', $language->title);
|
||||
$field->addAttribute('translate_label', 'false');
|
||||
$field->addAttribute('select', 'true');
|
||||
$field->addAttribute('new', 'true');
|
||||
$field->addAttribute('edit', 'true');
|
||||
$field->addAttribute('clear', 'true');
|
||||
$field->addAttribute('propagate', 'true');
|
||||
}
|
||||
|
||||
$form->load($addform, false);
|
||||
}
|
||||
}
|
||||
|
||||
parent::preprocessForm($form, $data, $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the user allowed to create an on the fly category?
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @since 3.6.1
|
||||
*/
|
||||
private function canCreateCategory()
|
||||
{
|
||||
return $this->getCurrentUser()->authorise('core.create', 'com_newsfeeds');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,321 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Model;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Associations;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
use Joomla\CMS\MVC\Model\ListModel;
|
||||
use Joomla\Database\ParameterType;
|
||||
use Joomla\Database\QueryInterface;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Methods supporting a list of newsfeed records.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class NewsfeedsModel extends ListModel
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
* @param ?MVCFactoryInterface $factory The factory.
|
||||
*
|
||||
* @see \Joomla\CMS\MVC\Model\BaseDatabaseModel
|
||||
* @since 3.2
|
||||
*/
|
||||
public function __construct($config = [], ?MVCFactoryInterface $factory = null)
|
||||
{
|
||||
if (empty($config['filter_fields'])) {
|
||||
$config['filter_fields'] = [
|
||||
'id', 'a.id',
|
||||
'name', 'a.name',
|
||||
'alias', 'a.alias',
|
||||
'checked_out', 'a.checked_out',
|
||||
'checked_out_time', 'a.checked_out_time',
|
||||
'catid', 'a.catid', 'category_id', 'category_title',
|
||||
'published', 'a.published',
|
||||
'access', 'a.access', 'access_level',
|
||||
'created', 'a.created',
|
||||
'created_by', 'a.created_by',
|
||||
'ordering', 'a.ordering',
|
||||
'language', 'a.language', 'language_title',
|
||||
'publish_up', 'a.publish_up',
|
||||
'publish_down', 'a.publish_down',
|
||||
'cache_time', 'a.cache_time',
|
||||
'numarticles',
|
||||
'tag',
|
||||
'level', 'c.level',
|
||||
'tag',
|
||||
];
|
||||
|
||||
if (Associations::isEnabled()) {
|
||||
$config['filter_fields'][] = 'association';
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct($config, $factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @param string $ordering An optional ordering field.
|
||||
* @param string $direction An optional direction (asc|desc).
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = 'a.name', $direction = 'asc')
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
|
||||
$forcedLanguage = $app->getInput()->get('forcedLanguage', '', 'cmd');
|
||||
|
||||
// Adjust the context to support modal layouts.
|
||||
if ($layout = $app->getInput()->get('layout')) {
|
||||
$this->context .= '.' . $layout;
|
||||
}
|
||||
|
||||
// Adjust the context to support forced languages.
|
||||
if ($forcedLanguage) {
|
||||
$this->context .= '.' . $forcedLanguage;
|
||||
}
|
||||
|
||||
// Load the parameters.
|
||||
$params = ComponentHelper::getParams('com_newsfeeds');
|
||||
$this->setState('params', $params);
|
||||
|
||||
// List state information.
|
||||
parent::populateState($ordering, $direction);
|
||||
|
||||
// Force a language.
|
||||
if (!empty($forcedLanguage)) {
|
||||
$this->setState('filter.language', $forcedLanguage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string $id A prefix for the store id.
|
||||
*
|
||||
* @return string A store id.
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
// Compile the store id.
|
||||
$id .= ':' . $this->getState('filter.search');
|
||||
$id .= ':' . $this->getState('filter.published');
|
||||
$id .= ':' . $this->getState('filter.category_id');
|
||||
$id .= ':' . $this->getState('filter.access');
|
||||
$id .= ':' . $this->getState('filter.language');
|
||||
$id .= ':' . $this->getState('filter.level');
|
||||
$id .= ':' . serialize($this->getState('filter.tag'));
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an SQL query to load the list data.
|
||||
*
|
||||
* @return QueryInterface
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
// Create a new query object.
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true);
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
// Select the required fields from the table.
|
||||
$query->select(
|
||||
$this->getState(
|
||||
'list.select',
|
||||
[
|
||||
$db->quoteName('a.id'),
|
||||
$db->quoteName('a.name'),
|
||||
$db->quoteName('a.alias'),
|
||||
$db->quoteName('a.checked_out'),
|
||||
$db->quoteName('a.checked_out_time'),
|
||||
$db->quoteName('a.catid'),
|
||||
$db->quoteName('a.numarticles'),
|
||||
$db->quoteName('a.cache_time'),
|
||||
$db->quoteName('a.created_by'),
|
||||
$db->quoteName('a.published'),
|
||||
$db->quoteName('a.access'),
|
||||
$db->quoteName('a.ordering'),
|
||||
$db->quoteName('a.language'),
|
||||
$db->quoteName('a.publish_up'),
|
||||
$db->quoteName('a.publish_down'),
|
||||
]
|
||||
)
|
||||
)
|
||||
->select(
|
||||
[
|
||||
$db->quoteName('l.title', 'language_title'),
|
||||
$db->quoteName('l.image', 'language_image'),
|
||||
$db->quoteName('uc.name', 'editor'),
|
||||
$db->quoteName('ag.title', 'access_level'),
|
||||
$db->quoteName('c.title', 'category_title'),
|
||||
]
|
||||
)
|
||||
->from($db->quoteName('#__newsfeeds', 'a'))
|
||||
->join('LEFT', $db->quoteName('#__languages', 'l'), $db->quoteName('l.lang_code') . ' = ' . $db->quoteName('a.language'))
|
||||
->join('LEFT', $db->quoteName('#__users', 'uc'), $db->quoteName('uc.id') . ' = ' . $db->quoteName('a.checked_out'))
|
||||
->join('LEFT', $db->quoteName('#__viewlevels', 'ag'), $db->quoteName('ag.id') . ' = ' . $db->quoteName('a.access'))
|
||||
->join('LEFT', $db->quoteName('#__categories', 'c'), $db->quoteName('c.id') . ' = ' . $db->quoteName('a.catid'));
|
||||
|
||||
// Join over the associations.
|
||||
if (Associations::isEnabled()) {
|
||||
$subQuery = $db->getQuery(true)
|
||||
->select('COUNT(' . $db->quoteName('asso1.id') . ') > 1')
|
||||
->from($db->quoteName('#__associations', 'asso1'))
|
||||
->join('INNER', $db->quoteName('#__associations', 'asso2'), $db->quoteName('asso1.key') . ' = ' . $db->quoteName('asso2.key'))
|
||||
->where(
|
||||
[
|
||||
$db->quoteName('asso1.id') . ' = ' . $db->quoteName('a.id'),
|
||||
$db->quoteName('asso1.context') . ' = ' . $db->quote('com_newsfeeds.item'),
|
||||
]
|
||||
);
|
||||
|
||||
$query->select('(' . $subQuery . ') AS ' . $db->quoteName('association'));
|
||||
}
|
||||
|
||||
// Filter by access level.
|
||||
if ($access = (int) $this->getState('filter.access')) {
|
||||
$query->where($db->quoteName('a.access') . ' = :access')
|
||||
->bind(':access', $access, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
// Implement View Level Access
|
||||
if (!$user->authorise('core.admin')) {
|
||||
$query->whereIn($db->quoteName('a.access'), $user->getAuthorisedViewLevels());
|
||||
}
|
||||
|
||||
// Filter by published state.
|
||||
$published = (string) $this->getState('filter.published');
|
||||
|
||||
if (is_numeric($published)) {
|
||||
$published = (int) $published;
|
||||
$query->where($db->quoteName('a.published') . ' = :published')
|
||||
->bind(':published', $published, ParameterType::INTEGER);
|
||||
} elseif ($published === '') {
|
||||
$query->where($db->quoteName('a.published') . ' IN (0, 1)');
|
||||
}
|
||||
|
||||
// Filter by category.
|
||||
$categoryId = $this->getState('filter.category_id');
|
||||
|
||||
if (is_numeric($categoryId)) {
|
||||
$categoryId = (int) $categoryId;
|
||||
$query->where($db->quoteName('a.catid') . ' = :categoryId')
|
||||
->bind(':categoryId', $categoryId, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
// Filter on the level.
|
||||
if ($level = (int) $this->getState('filter.level')) {
|
||||
$query->where($db->quoteName('c.level') . ' <= :level')
|
||||
->bind(':level', $level, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
// Filter by search in title
|
||||
if ($search = $this->getState('filter.search')) {
|
||||
if (stripos($search, 'id:') === 0) {
|
||||
$search = (int) substr($search, 3);
|
||||
$query->where($db->quoteName('a.id') . ' = :search')
|
||||
->bind(':search', $search, ParameterType::INTEGER);
|
||||
} else {
|
||||
$search = '%' . str_replace(' ', '%', trim($search)) . '%';
|
||||
$query->where('(' . $db->quoteName('a.name') . ' LIKE :search1 OR ' . $db->quoteName('a.alias') . ' LIKE :search2)')
|
||||
->bind([':search1', ':search2'], $search);
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on the language.
|
||||
if ($language = $this->getState('filter.language')) {
|
||||
$query->where($db->quoteName('a.language') . ' = :language')
|
||||
->bind(':language', $language);
|
||||
}
|
||||
|
||||
// Filter by a single or group of tags.
|
||||
$tag = $this->getState('filter.tag');
|
||||
|
||||
// Run simplified query when filtering by one tag.
|
||||
if (\is_array($tag) && \count($tag) === 1) {
|
||||
$tag = $tag[0];
|
||||
}
|
||||
|
||||
if ($tag && \is_array($tag)) {
|
||||
$tag = ArrayHelper::toInteger($tag);
|
||||
|
||||
$subQuery = $db->getQuery(true)
|
||||
->select('DISTINCT ' . $db->quoteName('content_item_id'))
|
||||
->from($db->quoteName('#__contentitem_tag_map'))
|
||||
->where(
|
||||
[
|
||||
$db->quoteName('tag_id') . ' IN (' . implode(',', $query->bindArray($tag)) . ')',
|
||||
$db->quoteName('type_alias') . ' = ' . $db->quote('com_newsfeeds.newsfeed'),
|
||||
]
|
||||
);
|
||||
|
||||
$query->join(
|
||||
'INNER',
|
||||
'(' . $subQuery . ') AS ' . $db->quoteName('tagmap'),
|
||||
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
|
||||
);
|
||||
} elseif ($tag = (int) $tag) {
|
||||
$query->join(
|
||||
'INNER',
|
||||
$db->quoteName('#__contentitem_tag_map', 'tagmap'),
|
||||
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
|
||||
)
|
||||
->where(
|
||||
[
|
||||
$db->quoteName('tagmap.tag_id') . ' = :tag',
|
||||
$db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_newsfeeds.newsfeed'),
|
||||
]
|
||||
)
|
||||
->bind(':tag', $tag, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
// Add the list ordering clause.
|
||||
$orderCol = $this->state->get('list.ordering', 'a.name');
|
||||
$orderDirn = $this->state->get('list.direction', 'ASC');
|
||||
|
||||
if ($orderCol == 'a.ordering' || $orderCol == 'category_title') {
|
||||
$ordering = [
|
||||
$db->quoteName('c.title') . ' ' . $db->escape($orderDirn),
|
||||
$db->quoteName('a.ordering') . ' ' . $db->escape($orderDirn),
|
||||
];
|
||||
} else {
|
||||
$ordering = $db->escape($orderCol) . ' ' . $db->escape($orderDirn);
|
||||
}
|
||||
|
||||
$query->order($ordering);
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Service\HTML;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Associations;
|
||||
use Joomla\CMS\Language\LanguageHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Layout\LayoutHelper;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\Database\ParameterType;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Utility class for creating HTML Grids.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class AdministratorService
|
||||
{
|
||||
/**
|
||||
* Get the associated language flags
|
||||
*
|
||||
* @param int $newsfeedid The item id to search associations
|
||||
*
|
||||
* @return string The language HTML
|
||||
*
|
||||
* @throws \Exception Throws a 500 Exception on Database failure
|
||||
*/
|
||||
public function association($newsfeedid)
|
||||
{
|
||||
// Defaults
|
||||
$html = '';
|
||||
|
||||
// Get the associations
|
||||
if ($associations = Associations::getAssociations('com_newsfeeds', '#__newsfeeds', 'com_newsfeeds.item', $newsfeedid)) {
|
||||
foreach ($associations as $tag => $associated) {
|
||||
$associations[$tag] = (int) $associated->id;
|
||||
}
|
||||
|
||||
// Get the associated newsfeed items
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$query
|
||||
->select(
|
||||
[
|
||||
$db->quoteName('c.id'),
|
||||
$db->quoteName('c.name', 'title'),
|
||||
$db->quoteName('cat.title', 'category_title'),
|
||||
$db->quoteName('l.sef', 'lang_sef'),
|
||||
$db->quoteName('l.lang_code'),
|
||||
$db->quoteName('l.image'),
|
||||
$db->quoteName('l.title', 'language_title'),
|
||||
]
|
||||
)
|
||||
->from($db->quoteName('#__newsfeeds', 'c'))
|
||||
->join('LEFT', $db->quoteName('#__categories', 'cat'), $db->quoteName('cat.id') . ' = ' . $db->quoteName('c.catid'))
|
||||
->join('LEFT', $db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code'))
|
||||
->where(
|
||||
[
|
||||
$db->quoteName('c.id') . ' IN (' . implode(',', $query->bindArray(array_values($associations))) . ')',
|
||||
$db->quoteName('c.id') . ' != :id',
|
||||
]
|
||||
)
|
||||
->bind(':id', $newsfeedid, ParameterType::INTEGER);
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$items = $db->loadObjectList('id');
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new \Exception($e->getMessage(), 500);
|
||||
}
|
||||
|
||||
if ($items) {
|
||||
$languages = LanguageHelper::getContentLanguages([0, 1]);
|
||||
$content_languages = array_column($languages, 'lang_code');
|
||||
|
||||
foreach ($items as &$item) {
|
||||
if (\in_array($item->lang_code, $content_languages)) {
|
||||
$text = $item->lang_code;
|
||||
$url = Route::_('index.php?option=com_newsfeeds&task=newsfeed.edit&id=' . (int) $item->id);
|
||||
$tooltip = '<strong>' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '</strong><br>'
|
||||
. htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '<br>' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title);
|
||||
$classes = 'badge bg-secondary';
|
||||
|
||||
$item->link = '<a href="' . $url . '" class="' . $classes . '">' . $text . '</a>'
|
||||
. '<div role="tooltip" id="tip-' . (int) $newsfeedid . '-' . (int) $item->id . '">' . $tooltip . '</div>';
|
||||
} else {
|
||||
// Display warning if Content Language is trashed or deleted
|
||||
Factory::getApplication()->enqueueMessage(Text::sprintf('JGLOBAL_ASSOCIATIONS_CONTENTLANGUAGE_WARNING', $item->lang_code), 'warning');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$html = LayoutHelper::render('joomla.content.associations', $items);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Table;
|
||||
|
||||
use Joomla\CMS\Application\ApplicationHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\String\PunycodeHelper;
|
||||
use Joomla\CMS\Table\Table;
|
||||
use Joomla\CMS\Tag\TaggableTableInterface;
|
||||
use Joomla\CMS\Tag\TaggableTableTrait;
|
||||
use Joomla\CMS\User\CurrentUserInterface;
|
||||
use Joomla\CMS\User\CurrentUserTrait;
|
||||
use Joomla\CMS\Versioning\VersionableTableInterface;
|
||||
use Joomla\Database\DatabaseDriver;
|
||||
use Joomla\Event\DispatcherInterface;
|
||||
use Joomla\String\StringHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Newsfeed Table class.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class NewsfeedTable extends Table implements VersionableTableInterface, TaggableTableInterface, CurrentUserInterface
|
||||
{
|
||||
use TaggableTableTrait;
|
||||
use CurrentUserTrait;
|
||||
|
||||
/**
|
||||
* Indicates that columns fully support the NULL value in the database
|
||||
*
|
||||
* @var boolean
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $_supportNullValue = true;
|
||||
|
||||
/**
|
||||
* Ensure the params, metadata and images are json encoded in the bind method
|
||||
*
|
||||
* @var array
|
||||
* @since 3.3
|
||||
*/
|
||||
protected $_jsonEncode = ['params', 'metadata', 'images'];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DatabaseDriver $db Database connector object
|
||||
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct(DatabaseDriver $db, ?DispatcherInterface $dispatcher = null)
|
||||
{
|
||||
$this->typeAlias = 'com_newsfeeds.newsfeed';
|
||||
parent::__construct('#__newsfeeds', 'id', $db, $dispatcher);
|
||||
$this->setColumnAlias('title', 'name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded check method to ensure data integrity.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
try {
|
||||
parent::check();
|
||||
} catch (\Exception $e) {
|
||||
$this->setError($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for valid name.
|
||||
if (trim($this->name) == '') {
|
||||
$this->setError(Text::_('COM_NEWSFEEDS_WARNING_PROVIDE_VALID_NAME'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($this->alias)) {
|
||||
$this->alias = $this->name;
|
||||
}
|
||||
|
||||
$this->alias = ApplicationHelper::stringURLSafe($this->alias, $this->language);
|
||||
|
||||
if (trim(str_replace('-', '', $this->alias)) == '') {
|
||||
$this->alias = Factory::getDate()->format('Y-m-d-H-i-s');
|
||||
}
|
||||
|
||||
// Check for a valid category.
|
||||
if (!$this->catid = (int) $this->catid) {
|
||||
$this->setError(Text::_('JLIB_DATABASE_ERROR_CATEGORY_REQUIRED'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the publish down date is not earlier than publish up.
|
||||
if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up) {
|
||||
$this->setError(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clean up description -- eliminate quotes and <> brackets
|
||||
if (!empty($this->metadesc)) {
|
||||
// Only process if not empty
|
||||
$bad_characters = ["\"", '<', '>'];
|
||||
$this->metadesc = StringHelper::str_ireplace($bad_characters, '', $this->metadesc);
|
||||
}
|
||||
|
||||
if (!$this->hits) {
|
||||
$this->hits = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden \Joomla\CMS\Table\Table::store to set modified data.
|
||||
*
|
||||
* @param boolean $updateNulls True to update fields even if they are null.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function store($updateNulls = true)
|
||||
{
|
||||
$date = Factory::getDate();
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
// Set created date if not set.
|
||||
if (!(int) $this->created) {
|
||||
$this->created = $date->toSql();
|
||||
}
|
||||
|
||||
if ($this->id) {
|
||||
// Existing item
|
||||
$this->modified_by = $user->id;
|
||||
$this->modified = $date->toSql();
|
||||
} else {
|
||||
// Field created_by can be set by the user, so we don't touch it if it's set.
|
||||
if (empty($this->created_by)) {
|
||||
$this->created_by = $user->id;
|
||||
}
|
||||
|
||||
if (!(int) $this->modified) {
|
||||
$this->modified = $this->created;
|
||||
}
|
||||
|
||||
if (empty($this->modified_by)) {
|
||||
$this->modified_by = $this->created_by;
|
||||
}
|
||||
}
|
||||
|
||||
// Set publish_up, publish_down to null if not set
|
||||
if (!$this->publish_up) {
|
||||
$this->publish_up = null;
|
||||
}
|
||||
|
||||
if (!$this->publish_down) {
|
||||
$this->publish_down = null;
|
||||
}
|
||||
|
||||
// Verify that the alias is unique
|
||||
$table = Table::getInstance('NewsfeedTable', __NAMESPACE__ . '\\', ['dbo' => $this->_db]);
|
||||
|
||||
if ($table->load(['alias' => $this->alias, 'catid' => $this->catid]) && ($table->id != $this->id || $this->id == 0)) {
|
||||
// Is the existing newsfeed trashed?
|
||||
$this->setError(Text::_('COM_NEWSFEEDS_ERROR_UNIQUE_ALIAS'));
|
||||
|
||||
if ($table->published === -2) {
|
||||
$this->setError(Text::_('COM_NEWSFEEDS_ERROR_UNIQUE_ALIAS_TRASHED'));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Save links as punycode.
|
||||
$this->link = PunycodeHelper::urlToPunycode($this->link);
|
||||
|
||||
return parent::store($updateNulls);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type alias for the history table
|
||||
*
|
||||
* @return string The alias as described above
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getTypeAlias()
|
||||
{
|
||||
return $this->typeAlias;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\View\Newsfeed;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Helper\ContentHelper;
|
||||
use Joomla\CMS\Language\Associations;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\View\GenericDataException;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use Joomla\CMS\Toolbar\Toolbar;
|
||||
use Joomla\CMS\Toolbar\ToolbarHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* View to edit a newsfeed.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
/**
|
||||
* The item object for the newsfeed
|
||||
*
|
||||
* @var \Joomla\Registry\Registry
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $item;
|
||||
|
||||
/**
|
||||
* The form object for the newsfeed
|
||||
*
|
||||
* @var \Joomla\CMS\Form\Form
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $form;
|
||||
|
||||
/**
|
||||
* The model state of the newsfeed
|
||||
*
|
||||
* @var \Joomla\Registry\Registry
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* Array of fieldsets not to display
|
||||
*
|
||||
* @var string[]
|
||||
*
|
||||
* @since 5.2.0
|
||||
*/
|
||||
public $ignore_fieldsets = [];
|
||||
|
||||
/**
|
||||
* Execute and display a template script.
|
||||
*
|
||||
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$this->state = $this->get('State');
|
||||
$this->item = $this->get('Item');
|
||||
$this->form = $this->get('Form');
|
||||
|
||||
if ($this->getLayout() === 'modalreturn') {
|
||||
parent::display($tpl);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for errors.
|
||||
if (\count($errors = $this->get('Errors'))) {
|
||||
throw new GenericDataException(implode("\n", $errors), 500);
|
||||
}
|
||||
|
||||
// If we are forcing a language in modal (used for associations).
|
||||
if ($this->getLayout() === 'modal' && $forcedLanguage = Factory::getApplication()->getInput()->get('forcedLanguage', '', 'cmd')) {
|
||||
// Set the language field to the forcedLanguage and disable changing it.
|
||||
$this->form->setValue('language', null, $forcedLanguage);
|
||||
$this->form->setFieldAttribute('language', 'readonly', 'true');
|
||||
|
||||
// Only allow to select categories with All language or with the forced language.
|
||||
$this->form->setFieldAttribute('catid', 'language', '*,' . $forcedLanguage);
|
||||
|
||||
// Only allow to select tags with All language or with the forced language.
|
||||
$this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage);
|
||||
}
|
||||
|
||||
if ($this->getLayout() !== 'modal') {
|
||||
$this->addToolbar();
|
||||
} else {
|
||||
$this->addModalToolbar();
|
||||
}
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the page title and toolbar.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function addToolbar()
|
||||
{
|
||||
Factory::getApplication()->getInput()->set('hidemainmenu', true);
|
||||
|
||||
$user = $this->getCurrentUser();
|
||||
$isNew = ($this->item->id == 0);
|
||||
$checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $user->id);
|
||||
$toolbar = $this->getDocument()->getToolbar();
|
||||
|
||||
// Since we don't track these assets at the item level, use the category id.
|
||||
$canDo = ContentHelper::getActions('com_newsfeeds', 'category', $this->item->catid);
|
||||
|
||||
$title = $isNew ? Text::_('COM_NEWSFEEDS_MANAGER_NEWSFEED_NEW') : Text::_('COM_NEWSFEEDS_MANAGER_NEWSFEED_EDIT');
|
||||
ToolbarHelper::title($title, 'rss newsfeeds');
|
||||
|
||||
// If not checked out, can save the item.
|
||||
if (!$checkedOut && ($canDo->get('core.edit') || \count($user->getAuthorisedCategories('com_newsfeeds', 'core.create')) > 0)) {
|
||||
$toolbar->apply('newsfeed.apply');
|
||||
}
|
||||
|
||||
$saveGroup = $toolbar->dropdownButton('save-group');
|
||||
|
||||
$saveGroup->configure(
|
||||
function (Toolbar $childBar) use ($checkedOut, $canDo, $user, $isNew) {
|
||||
// If not checked out, can save the item.
|
||||
if (!$checkedOut && ($canDo->get('core.edit') || \count($user->getAuthorisedCategories('com_newsfeeds', 'core.create')) > 0)) {
|
||||
$childBar->save('newsfeed.save');
|
||||
}
|
||||
|
||||
if (!$checkedOut && \count($user->getAuthorisedCategories('com_newsfeeds', 'core.create')) > 0) {
|
||||
$childBar->save2new('newsfeed.save2new');
|
||||
}
|
||||
|
||||
// If an existing item, can save to a copy.
|
||||
if (!$isNew && $canDo->get('core.create')) {
|
||||
$childBar->save2copy('newsfeed.save2copy');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (empty($this->item->id)) {
|
||||
$toolbar->cancel('newsfeed.cancel', 'JTOOLBAR_CANCEL');
|
||||
} else {
|
||||
$toolbar->cancel('newsfeed.cancel');
|
||||
|
||||
if (ComponentHelper::isEnabled('com_contenthistory') && $this->state->params->get('save_history', 0) && $canDo->get('core.edit')) {
|
||||
$toolbar->versions('com_newsfeeds.newsfeed', $this->item->id);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$isNew && Associations::isEnabled() && ComponentHelper::isEnabled('com_associations')) {
|
||||
$toolbar->standardButton('associations', 'JTOOLBAR_ASSOCIATIONS', 'newsfeed.editAssociations')
|
||||
->icon('icon-contract')
|
||||
->listCheck(false);
|
||||
}
|
||||
|
||||
$toolbar->divider();
|
||||
$toolbar->help('News_Feeds:_Edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the modal toolbar.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 5.1.0
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function addModalToolbar()
|
||||
{
|
||||
$user = $this->getCurrentUser();
|
||||
$isNew = ($this->item->id == 0);
|
||||
$toolbar = $this->getDocument()->getToolbar();
|
||||
|
||||
// Since we don't track these assets at the item level, use the category id.
|
||||
$canDo = ContentHelper::getActions('com_newsfeeds', 'category', $this->item->catid);
|
||||
|
||||
$title = $isNew ? Text::_('COM_NEWSFEEDS_MANAGER_NEWSFEED_NEW') : Text::_('COM_NEWSFEEDS_MANAGER_NEWSFEED_EDIT');
|
||||
ToolbarHelper::title($title, 'rss newsfeeds');
|
||||
|
||||
$canCreate = $isNew && (\count($user->getAuthorisedCategories('com_newsfeeds', 'core.create')) > 0);
|
||||
$canEdit = $canDo->get('core.edit');
|
||||
|
||||
// For new records, check the create permission.
|
||||
if ($canCreate || $canEdit) {
|
||||
$toolbar->apply('newsfeed.apply');
|
||||
$toolbar->save('newsfeed.save');
|
||||
}
|
||||
|
||||
$toolbar->cancel('newsfeed.cancel');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\View\Newsfeeds;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Helper\ContentHelper;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\View\GenericDataException;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use Joomla\CMS\Toolbar\Button\DropdownButton;
|
||||
use Joomla\CMS\Toolbar\ToolbarHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* View class for a list of newsfeeds.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
/**
|
||||
* The list of newsfeeds
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $items;
|
||||
|
||||
/**
|
||||
* The pagination object
|
||||
*
|
||||
* @var \Joomla\CMS\Pagination\Pagination
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $pagination;
|
||||
|
||||
/**
|
||||
* The model state
|
||||
*
|
||||
* @var \Joomla\Registry\Registry
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* Is this view an Empty State
|
||||
*
|
||||
* @var boolean
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $isEmptyState = false;
|
||||
|
||||
/**
|
||||
* Form object for search filters
|
||||
*
|
||||
* @var \Joomla\CMS\Form\Form
|
||||
*/
|
||||
public $filterForm;
|
||||
|
||||
/**
|
||||
* The active search filters
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $activeFilters;
|
||||
|
||||
/**
|
||||
* Execute and display a template script.
|
||||
*
|
||||
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$this->items = $this->get('Items');
|
||||
$this->pagination = $this->get('Pagination');
|
||||
$this->state = $this->get('State');
|
||||
$this->filterForm = $this->get('FilterForm');
|
||||
$this->activeFilters = $this->get('ActiveFilters');
|
||||
|
||||
if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
|
||||
$this->setLayout('emptystate');
|
||||
}
|
||||
|
||||
// Check for errors.
|
||||
if (\count($errors = $this->get('Errors'))) {
|
||||
throw new GenericDataException(implode("\n", $errors), 500);
|
||||
}
|
||||
|
||||
// We don't need toolbar in the modal layout.
|
||||
if ($this->getLayout() !== 'modal') {
|
||||
$this->addToolbar();
|
||||
|
||||
// We do not need to filter by language when multilingual is disabled
|
||||
if (!Multilanguage::isEnabled()) {
|
||||
unset($this->activeFilters['language']);
|
||||
$this->filterForm->removeField('language', 'filter');
|
||||
}
|
||||
} else {
|
||||
// In article associations modal we need to remove language filter if forcing a language.
|
||||
// We also need to change the category filter to show show categories with All or the forced language.
|
||||
if ($forcedLanguage = Factory::getApplication()->getInput()->get('forcedLanguage', '', 'CMD')) {
|
||||
// If the language is forced we can't allow to select the language, so transform the language selector filter into a hidden field.
|
||||
$languageXml = new \SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />');
|
||||
$this->filterForm->setField($languageXml, 'filter', true);
|
||||
|
||||
// Also, unset the active language filter so the search tools is not open by default with this filter.
|
||||
unset($this->activeFilters['language']);
|
||||
|
||||
// One last changes needed is to change the category filter to just show categories with All language or with the forced language.
|
||||
$this->filterForm->setFieldAttribute('category_id', 'language', '*,' . $forcedLanguage, 'filter');
|
||||
}
|
||||
}
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the page title and toolbar.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function addToolbar()
|
||||
{
|
||||
$state = $this->get('State');
|
||||
$canDo = ContentHelper::getActions('com_newsfeeds', 'category', $state->get('filter.category_id'));
|
||||
$user = $this->getCurrentUser();
|
||||
$toolbar = $this->getDocument()->getToolbar();
|
||||
|
||||
ToolbarHelper::title(Text::_('COM_NEWSFEEDS_MANAGER_NEWSFEEDS'), 'rss newsfeeds');
|
||||
|
||||
if ($canDo->get('core.create') || \count($user->getAuthorisedCategories('com_newsfeeds', 'core.create')) > 0) {
|
||||
$toolbar->addNew('newsfeed.add');
|
||||
}
|
||||
|
||||
if (!$this->isEmptyState && ($canDo->get('core.edit.state') || $user->authorise('core.admin'))) {
|
||||
/** @var DropdownButton $dropdown */
|
||||
$dropdown = $toolbar->dropdownButton('status-group', 'JTOOLBAR_CHANGE_STATUS')
|
||||
->toggleSplit(false)
|
||||
->icon('icon-ellipsis-h')
|
||||
->buttonClass('btn btn-action')
|
||||
->listCheck(true);
|
||||
|
||||
$childBar = $dropdown->getChildToolbar();
|
||||
|
||||
$childBar->publish('newsfeeds.publish')->listCheck(true);
|
||||
$childBar->unpublish('newsfeeds.unpublish')->listCheck(true);
|
||||
$childBar->archive('newsfeeds.archive')->listCheck(true);
|
||||
|
||||
if ($user->authorise('core.admin')) {
|
||||
$childBar->checkin('newsfeeds.checkin')->listCheck(true);
|
||||
}
|
||||
|
||||
if ($this->state->get('filter.published') != -2) {
|
||||
$childBar->trash('newsfeeds.trash')->listCheck(true);
|
||||
}
|
||||
|
||||
// Add a batch button
|
||||
if (
|
||||
$user->authorise('core.create', 'com_newsfeeds')
|
||||
&& $user->authorise('core.edit', 'com_newsfeeds')
|
||||
&& $user->authorise('core.edit.state', 'com_newsfeeds')
|
||||
) {
|
||||
$childBar->popupButton('batch', 'JTOOLBAR_BATCH')
|
||||
->popupType('inline')
|
||||
->textHeader(Text::_('COM_NEWSFEEDS_BATCH_OPTIONS'))
|
||||
->url('#joomla-dialog-batch')
|
||||
->modalWidth('800px')
|
||||
->modalHeight('fit-content')
|
||||
->listCheck(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->isEmptyState && $state->get('filter.published') == -2 && $canDo->get('core.delete')) {
|
||||
$toolbar->delete('newsfeeds.delete', 'JTOOLBAR_DELETE_FROM_TRASH')
|
||||
->message('JGLOBAL_CONFIRM_DELETE')
|
||||
->listCheck(true);
|
||||
}
|
||||
|
||||
if ($user->authorise('core.admin', 'com_newsfeeds') || $user->authorise('core.options', 'com_newsfeeds')) {
|
||||
$toolbar->preferences('com_newsfeeds');
|
||||
}
|
||||
|
||||
$toolbar->help('News_Feeds');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user