[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/quickicon/joomlaupdate/src/Extension/ -> Joomlaupdate.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  Quickicon.Joomlaupdate
   6   *
   7   * @copyright   (C) 2011 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\Plugin\Quickicon\Joomlaupdate\Extension;
  12  
  13  use Joomla\CMS\Document\Document;
  14  use Joomla\CMS\Language\Text;
  15  use Joomla\CMS\Plugin\CMSPlugin;
  16  use Joomla\CMS\Session\Session;
  17  use Joomla\CMS\Uri\Uri;
  18  use Joomla\Event\DispatcherInterface;
  19  use Joomla\Event\SubscriberInterface;
  20  use Joomla\Module\Quickicon\Administrator\Event\QuickIconsEvent;
  21  
  22  // phpcs:disable PSR1.Files.SideEffects
  23  \defined('_JEXEC') or die;
  24  // phpcs:enable PSR1.Files.SideEffects
  25  
  26  /**
  27   * Joomla! update notification plugin
  28   *
  29   * @since  2.5
  30   */
  31  class Joomlaupdate extends CMSPlugin implements SubscriberInterface
  32  {
  33      /**
  34       * Load the language file on instantiation.
  35       *
  36       * @var    boolean
  37       * @since  3.1
  38       */
  39      protected $autoloadLanguage = true;
  40  
  41      /**
  42       * The document.
  43       *
  44       * @var Document
  45       *
  46       * @since  4.0.0
  47       */
  48      private $document;
  49  
  50      /**
  51       * Returns an array of events this subscriber will listen to.
  52       *
  53       * @return  array
  54       *
  55       * @since   4.0.0
  56       */
  57      public static function getSubscribedEvents(): array
  58      {
  59          return [
  60              'onGetIcons' => 'getCoreUpdateNotification',
  61          ];
  62      }
  63  
  64      /**
  65       * Constructor
  66       *
  67       * @param   DispatcherInterface  $subject   The object to observe
  68       * @param   Document             $document  The document
  69       * @param   array                $config    An optional associative array of configuration settings.
  70       *                                          Recognized key values include 'name', 'group', 'params', 'language'
  71       *                                          (this list is not meant to be comprehensive).
  72       *
  73       * @since   4.0.0
  74       */
  75      public function __construct($subject, Document $document, $config = array())
  76      {
  77          parent::__construct($subject, $config);
  78  
  79          $this->document = $document;
  80      }
  81  
  82      /**
  83       * This method is called when the Quick Icons module is constructing its set
  84       * of icons. You can return an array which defines a single icon and it will
  85       * be rendered right after the stock Quick Icons.
  86       *
  87       * @param   QuickIconsEvent  $event  The event object
  88       *
  89       * @return  void
  90       *
  91       * @since   4.0.0
  92       */
  93      public function getCoreUpdateNotification(QuickIconsEvent $event)
  94      {
  95          $context = $event->getContext();
  96  
  97          if (
  98              $context !== $this->params->get('context', 'update_quickicon')
  99              || !$this->getApplication()->getIdentity()->authorise('core.manage', 'com_joomlaupdate')
 100          ) {
 101              return;
 102          }
 103  
 104          Text::script('PLG_QUICKICON_JOOMLAUPDATE_ERROR');
 105          Text::script('PLG_QUICKICON_JOOMLAUPDATE_UPDATEFOUND');
 106          Text::script('PLG_QUICKICON_JOOMLAUPDATE_UPTODATE');
 107          Text::script('MESSAGE');
 108          Text::script('ERROR');
 109          Text::script('INFO');
 110          Text::script('WARNING');
 111  
 112          $this->document->addScriptOptions(
 113              'js-joomla-update',
 114              [
 115                  'url'     => Uri::base() . 'index.php?option=com_joomlaupdate',
 116                  'ajaxUrl' => Uri::base() . 'index.php?option=com_joomlaupdate&task=update.ajax&'
 117                      . Session::getFormToken() . '=1',
 118                  'version' => JVERSION,
 119              ]
 120          );
 121  
 122          $this->document->getWebAssetManager()
 123              ->registerAndUseScript('plg_quickicon_joomlaupdate', 'plg_quickicon_joomlaupdate/jupdatecheck.min.js', [], ['defer' => true], ['core']);
 124  
 125          // Add the icon to the result array
 126          $result = $event->getArgument('result', []);
 127  
 128          $result[] = [
 129              [
 130                  'link'  => 'index.php?option=com_joomlaupdate',
 131                  'image' => 'icon-joomla',
 132                  'icon'  => '',
 133                  'text'  => Text::_('PLG_QUICKICON_JOOMLAUPDATE_CHECKING'),
 134                  'id'    => 'plg_quickicon_joomlaupdate',
 135                  'group' => 'MOD_QUICKICON_MAINTENANCE',
 136              ],
 137          ];
 138  
 139          $event->setArgument('result', $result);
 140      }
 141  }


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