[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_content 6 * 7 * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Content\Administrator\Controller; 12 13 use Joomla\CMS\Application\CMSApplication; 14 use Joomla\CMS\Language\Text; 15 use Joomla\CMS\MVC\Controller\AdminController; 16 use Joomla\CMS\MVC\Factory\MVCFactoryInterface; 17 use Joomla\CMS\Response\JsonResponse; 18 use Joomla\CMS\Router\Route; 19 use Joomla\Input\Input; 20 use Joomla\Utilities\ArrayHelper; 21 22 // phpcs:disable PSR1.Files.SideEffects 23 \defined('_JEXEC') or die; 24 // phpcs:enable PSR1.Files.SideEffects 25 26 /** 27 * Articles list controller class. 28 * 29 * @since 1.6 30 */ 31 class ArticlesController extends AdminController 32 { 33 /** 34 * Constructor. 35 * 36 * @param array $config An optional associative array of configuration settings. 37 * Recognized key values include 'name', 'default_task', 'model_path', and 38 * 'view_path' (this list is not meant to be comprehensive). 39 * @param MVCFactoryInterface $factory The factory. 40 * @param CMSApplication $app The Application for the dispatcher 41 * @param Input $input Input 42 * 43 * @since 3.0 44 */ 45 public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null) 46 { 47 parent::__construct($config, $factory, $app, $input); 48 49 // Articles default form can come from the articles or featured view. 50 // Adjust the redirect view on the value of 'view' in the request. 51 if ($this->input->get('view') == 'featured') { 52 $this->view_list = 'featured'; 53 } 54 55 $this->registerTask('unfeatured', 'featured'); 56 } 57 58 /** 59 * Method to toggle the featured setting of a list of articles. 60 * 61 * @return void 62 * 63 * @since 1.6 64 */ 65 public function featured() 66 { 67 // Check for request forgeries 68 $this->checkToken(); 69 70 $user = $this->app->getIdentity(); 71 $ids = (array) $this->input->get('cid', array(), 'int'); 72 $values = array('featured' => 1, 'unfeatured' => 0); 73 $task = $this->getTask(); 74 $value = ArrayHelper::getValue($values, $task, 0, 'int'); 75 $redirectUrl = 'index.php?option=com_content&view=' . $this->view_list . $this->getRedirectToListAppend(); 76 77 // Access checks. 78 foreach ($ids as $i => $id) { 79 // Remove zero value resulting from input filter 80 if ($id === 0) { 81 unset($ids[$i]); 82 83 continue; 84 } 85 86 if (!$user->authorise('core.edit.state', 'com_content.article.' . (int) $id)) { 87 // Prune items that you can't change. 88 unset($ids[$i]); 89 $this->app->enqueueMessage(Text::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), 'notice'); 90 } 91 } 92 93 if (empty($ids)) { 94 $this->app->enqueueMessage(Text::_('JERROR_NO_ITEMS_SELECTED'), 'error'); 95 96 $this->setRedirect(Route::_($redirectUrl, false)); 97 98 return; 99 } 100 101 // Get the model. 102 /** @var \Joomla\Component\Content\Administrator\Model\ArticleModel $model */ 103 $model = $this->getModel(); 104 105 // Publish the items. 106 if (!$model->featured($ids, $value)) { 107 $this->setRedirect(Route::_($redirectUrl, false), $model->getError(), 'error'); 108 109 return; 110 } 111 112 if ($value == 1) { 113 $message = Text::plural('COM_CONTENT_N_ITEMS_FEATURED', count($ids)); 114 } else { 115 $message = Text::plural('COM_CONTENT_N_ITEMS_UNFEATURED', count($ids)); 116 } 117 118 $this->setRedirect(Route::_($redirectUrl, false), $message); 119 } 120 121 /** 122 * Proxy for getModel. 123 * 124 * @param string $name The model name. Optional. 125 * @param string $prefix The class prefix. Optional. 126 * @param array $config The array of possible config values. Optional. 127 * 128 * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel 129 * 130 * @since 1.6 131 */ 132 public function getModel($name = 'Article', $prefix = 'Administrator', $config = array('ignore_request' => true)) 133 { 134 return parent::getModel($name, $prefix, $config); 135 } 136 137 /** 138 * Method to get the JSON-encoded amount of published articles 139 * 140 * @return void 141 * 142 * @since 4.0.0 143 */ 144 public function getQuickiconContent() 145 { 146 $model = $this->getModel('articles'); 147 148 $model->setState('filter.published', 1); 149 150 $amount = (int) $model->getTotal(); 151 152 $result = []; 153 154 $result['amount'] = $amount; 155 $result['sronly'] = Text::plural('COM_CONTENT_N_QUICKICON_SRONLY', $amount); 156 $result['name'] = Text::plural('COM_CONTENT_N_QUICKICON', $amount); 157 158 echo new JsonResponse($result); 159 } 160 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |