[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_newsfeeds/src/Controller/ -> AjaxController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_newsfeeds
   6   *
   7   * @copyright   (C) 2005 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\Newsfeeds\Administrator\Controller;
  12  
  13  use Joomla\CMS\Language\Associations;
  14  use Joomla\CMS\Language\LanguageHelper;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\MVC\Controller\BaseController;
  17  use Joomla\CMS\Response\JsonResponse;
  18  use Joomla\CMS\Session\Session;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * The newsfeed controller for ajax requests
  26   *
  27   * @since  3.9.0
  28   */
  29  class AjaxController extends BaseController
  30  {
  31      /**
  32       * Method to fetch associations of a newsfeed
  33       *
  34       * The method assumes that the following http parameters are passed in an Ajax Get request:
  35       * token: the form token
  36       * assocId: the id of the newsfeed whose associations are to be returned
  37       * excludeLang: the association for this language is to be excluded
  38       *
  39       * @return  null
  40       *
  41       * @since  3.9.0
  42       */
  43      public function fetchAssociations()
  44      {
  45          if (!Session::checkToken('get')) {
  46              echo new JsonResponse(null, Text::_('JINVALID_TOKEN'), true);
  47          } else {
  48              $assocId = $this->input->getInt('assocId', 0);
  49  
  50              if ($assocId == 0) {
  51                  echo new JsonResponse(null, Text::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', 'assocId'), true);
  52  
  53                  return;
  54              }
  55  
  56              $excludeLang = $this->input->get('excludeLang', '', 'STRING');
  57  
  58              $associations = Associations::getAssociations('com_newsfeeds', '#__newsfeeds', 'com_newsfeeds.item', (int) $assocId);
  59  
  60              unset($associations[$excludeLang]);
  61  
  62              // Add the title to each of the associated records
  63              $newsfeedsTable = $this->factory->createTable('Newsfeed', 'Administrator');
  64  
  65              foreach ($associations as $lang => $association) {
  66                  $newsfeedsTable->load($association->id);
  67                  $associations[$lang]->title = $newsfeedsTable->name;
  68              }
  69  
  70              $countContentLanguages = count(LanguageHelper::getContentLanguages(array(0, 1), false));
  71  
  72              if (count($associations) == 0) {
  73                  $message = Text::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE');
  74              } elseif ($countContentLanguages > count($associations) + 2) {
  75                  $tags    = implode(', ', array_keys($associations));
  76                  $message = Text::sprintf('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME', $tags);
  77              } else {
  78                  $message = Text::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_ALL');
  79              }
  80  
  81              echo new JsonResponse($associations, $message);
  82          }
  83      }
  84  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer