* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved. * @license GNU General Public License version 3 or later; see LICENSE */ namespace Joomla\Component\MokoSuiteBackup\Administrator\View\Backups; defined('_JEXEC') or die; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\CMS\Router\Route; use Joomla\CMS\Toolbar\ToolbarHelper; class HtmlView extends BaseHtmlView { protected $items; protected $pagination; protected $state; public $filterForm; public $activeFilters = []; public function display($tpl = null): void { $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'); $this->checkUpdateSite(); $this->addToolbar(); parent::display($tpl); } /** * Show an info notice linking to the update site record so the user * can configure their download key for automatic updates. */ protected function checkUpdateSite(): void { try { $db = Factory::getDbo(); // Find the update site linked to pkg_mokosuitebackup $query = $db->getQuery(true) ->select([ $db->quoteName('us.update_site_id'), $db->quoteName('us.extra_query'), ]) ->from($db->quoteName('#__update_sites', 'us')) ->join( 'INNER', $db->quoteName('#__update_sites_extensions', 'use') . ' ON ' . $db->quoteName('use.update_site_id') . ' = ' . $db->quoteName('us.update_site_id') ) ->join( 'INNER', $db->quoteName('#__extensions', 'e') . ' ON ' . $db->quoteName('e.extension_id') . ' = ' . $db->quoteName('use.extension_id') ) ->where($db->quoteName('e.element') . ' = ' . $db->quote('pkg_mokosuitebackup')) ->where($db->quoteName('e.type') . ' = ' . $db->quote('package')) ->setLimit(1); $db->setQuery($query); $site = $db->loadObject(); if (!$site) { Factory::getApplication()->enqueueMessage( Text::_('COM_MOKOJOOMBACKUP_UPDATE_SITE_MISSING'), 'warning' ); } elseif (empty($site->extra_query) || strpos($site->extra_query, 'dlid=') === false) { // Update site exists but no download key configured $editUrl = Route::_( 'index.php?option=com_installer&view=updatesites&filter[search]=mokosuitebackup' ); Factory::getApplication()->enqueueMessage( Text::sprintf('COM_MOKOJOOMBACKUP_UPDATE_SITE_NOTICE', $editUrl), 'info' ); } // If key is present, show nothing — all good } catch (\Throwable $e) { // Non-critical — silently ignore } } protected function addToolbar(): void { $user = Factory::getApplication()->getIdentity(); ToolbarHelper::title(Text::_('COM_MOKOJOOMBACKUP_BACKUPS_TITLE'), 'database'); if ($user->authorise('mokosuitebackup.backup.restore', 'com_mokosuitebackup')) { ToolbarHelper::custom('backups.restore', 'upload', '', 'COM_MOKOJOOMBACKUP_TOOLBAR_RESTORE', true); } if ($user->authorise('core.manage', 'com_mokosuitebackup')) { ToolbarHelper::custom('backups.verify', 'shield', '', 'COM_MOKOJOOMBACKUP_TOOLBAR_VERIFY', true); } if ($user->authorise('mokosuitebackup.backup.compare', 'com_mokosuitebackup')) { ToolbarHelper::custom('backups.compare', 'copy', '', 'COM_MOKOJOOMBACKUP_TOOLBAR_COMPARE', true); } if ($user->authorise('mokosuitebackup.backup.cancel', 'com_mokosuitebackup')) { ToolbarHelper::custom('backups.cancelStalled', 'stop-circle', '', 'COM_MOKOJOOMBACKUP_TOOLBAR_CANCEL_STALLED', true); } if ($user->authorise('core.delete', 'com_mokosuitebackup')) { ToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'backups.delete'); } if ($user->authorise('mokosuitebackup.backup.purge', 'com_mokosuitebackup')) { ToolbarHelper::custom('backups.purgeModal', 'trash', '', 'COM_MOKOJOOMBACKUP_TOOLBAR_PURGE', false); } if ($user->authorise('core.admin', 'com_mokosuitebackup')) { ToolbarHelper::preferences('com_mokosuitebackup'); } } }