primo commit
This commit is contained in:
		| @ -0,0 +1,67 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_finder | ||||
|  * | ||||
|  * @copyright   (C) 2011 Open Source Matters, Inc. <https://www.joomla.org> | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| namespace Joomla\Component\Finder\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 | ||||
|  | ||||
| /** | ||||
|  * Base controller class for Finder. | ||||
|  * | ||||
|  * @since  2.5 | ||||
|  */ | ||||
| class DisplayController extends BaseController | ||||
| { | ||||
|     /** | ||||
|      * The default view. | ||||
|      * | ||||
|      * @var    string | ||||
|      * @since  2.5 | ||||
|      */ | ||||
|     protected $default_view = 'index'; | ||||
|  | ||||
|     /** | ||||
|      * 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   A Controller object to support chaining or false on failure. | ||||
|      * | ||||
|      * @since   2.5 | ||||
|      */ | ||||
|     public function display($cachable = false, $urlparams = []) | ||||
|     { | ||||
|         $view     = $this->input->get('view', 'index', 'word'); | ||||
|         $layout   = $this->input->get('layout', 'index', 'word'); | ||||
|         $filterId = $this->input->get('filter_id', null, 'int'); | ||||
|  | ||||
|         // Check for edit form. | ||||
|         if ($view === 'filter' && $layout === 'edit' && !$this->checkEditId('com_finder.edit.filter', $filterId)) { | ||||
|             // 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', $filterId), 'error'); | ||||
|             } | ||||
|  | ||||
|             $this->setRedirect(Route::_('index.php?option=com_finder&view=filters', false)); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         return parent::display(); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,230 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_finder | ||||
|  * | ||||
|  * @copyright   (C) 2011 Open Source Matters, Inc. <https://www.joomla.org> | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| namespace Joomla\Component\Finder\Administrator\Controller; | ||||
|  | ||||
| use Joomla\CMS\Application\CMSWebApplicationInterface; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\MVC\Controller\FormController; | ||||
| use Joomla\CMS\Router\Route; | ||||
| use Joomla\Utilities\ArrayHelper; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Indexer controller class for Finder. | ||||
|  * | ||||
|  * @since  2.5 | ||||
|  */ | ||||
| class FilterController extends FormController | ||||
| { | ||||
|     /** | ||||
|      * Method to save a record. | ||||
|      * | ||||
|      * @param   string  $key     The name of the primary key of the URL variable. | ||||
|      * @param   string  $urlVar  The name of the URL variable if different from the primary key (sometimes required to avoid router collisions). | ||||
|      * | ||||
|      * @return  boolean  True if successful, false otherwise. | ||||
|      * | ||||
|      * @since   2.5 | ||||
|      */ | ||||
|     public function save($key = null, $urlVar = null) | ||||
|     { | ||||
|         // Check for request forgeries. | ||||
|         $this->checkToken(); | ||||
|  | ||||
|         /** @var \Joomla\Component\Finder\Administrator\Model\FilterModel $model */ | ||||
|         $model   = $this->getModel(); | ||||
|         $table   = $model->getTable(); | ||||
|         $data    = $this->input->post->get('jform', [], 'array'); | ||||
|         $checkin = $table->hasField('checked_out'); | ||||
|         $context = "$this->option.edit.$this->context"; | ||||
|         $task    = $this->getTask(); | ||||
|  | ||||
|         // Determine the name of the primary key for the data. | ||||
|         if (empty($key)) { | ||||
|             $key = $table->getKeyName(); | ||||
|         } | ||||
|  | ||||
|         // To avoid data collisions the urlVar may be different from the primary key. | ||||
|         if (empty($urlVar)) { | ||||
|             $urlVar = $key; | ||||
|         } | ||||
|  | ||||
|         $recordId = $this->input->get($urlVar, '', 'int'); | ||||
|  | ||||
|         if (!$this->checkEditId($context, $recordId)) { | ||||
|             // Somehow the person just went to the form and tried to save it. We don't allow that. | ||||
|             $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $recordId), 'error'); | ||||
|             $this->setRedirect(Route::_('index.php?option=' . $this->option . '&view=' . $this->view_list . $this->getRedirectToListAppend(), false)); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Populate the row id from the session. | ||||
|         $data[$key] = $recordId; | ||||
|  | ||||
|         // The save2copy task needs to be handled slightly differently. | ||||
|         if ($task === 'save2copy') { | ||||
|             // Check-in the original row. | ||||
|             if ($checkin && $model->checkin($data[$key]) === false) { | ||||
|                 // Check-in failed. Go back to the item and display a notice. | ||||
|                 if (!\count($this->app->getMessageQueue())) { | ||||
|                     $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError()), 'error'); | ||||
|                 } | ||||
|  | ||||
|                 $this->setRedirect('index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($recordId, $urlVar)); | ||||
|  | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
|             // Reset the ID and then treat the request as for Apply. | ||||
|             $data[$key] = 0; | ||||
|             $task       = 'apply'; | ||||
|         } | ||||
|  | ||||
|         // Access check. | ||||
|         if (!$this->allowSave($data, $key)) { | ||||
|             $this->setMessage(Text::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'), 'error'); | ||||
|             $this->setRedirect(Route::_('index.php?option=' . $this->option . '&view=' . $this->view_list . $this->getRedirectToListAppend(), false)); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Validate the posted data. | ||||
|         // Sometimes the form needs some posted data, such as for plugins and modules. | ||||
|         $form = $model->getForm($data, false); | ||||
|  | ||||
|         if (!$form) { | ||||
|             $this->app->enqueueMessage($model->getError(), 'error'); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Test whether the data is valid. | ||||
|         $validData = $model->validate($form, $data); | ||||
|  | ||||
|         // Check for validation errors. | ||||
|         if ($validData === false) { | ||||
|             // Get the validation messages. | ||||
|             $errors = $model->getErrors(); | ||||
|  | ||||
|             // Push up to three validation messages out to the user. | ||||
|             for ($i = 0, $n = \count($errors); $i < $n && $i < 3; $i++) { | ||||
|                 if ($errors[$i] instanceof \Exception) { | ||||
|                     $this->app->enqueueMessage($errors[$i]->getMessage(), CMSWebApplicationInterface::MSG_ERROR); | ||||
|                 } else { | ||||
|                     $this->app->enqueueMessage($errors[$i], CMSWebApplicationInterface::MSG_ERROR); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             // Save the data in the session. | ||||
|             $this->app->setUserState($context . '.data', $data); | ||||
|  | ||||
|             // Redirect back to the edit screen. | ||||
|             $this->setRedirect( | ||||
|                 Route::_('index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($recordId, $key), false) | ||||
|             ); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Get and sanitize the filter data. | ||||
|         $validData['data'] = $this->input->post->get('t', [], 'array'); | ||||
|         $validData['data'] = array_unique($validData['data']); | ||||
|         $validData['data'] = ArrayHelper::toInteger($validData['data']); | ||||
|  | ||||
|         // Remove any values of zero. | ||||
|         if (array_search(0, $validData['data'], true)) { | ||||
|             unset($validData['data'][array_search(0, $validData['data'], true)]); | ||||
|         } | ||||
|  | ||||
|         // Attempt to save the data. | ||||
|         if (!$model->save($validData)) { | ||||
|             // Save the data in the session. | ||||
|             $this->app->setUserState($context . '.data', $validData); | ||||
|  | ||||
|             // Redirect back to the edit screen. | ||||
|             $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()), 'error'); | ||||
|             $this->setRedirect( | ||||
|                 Route::_('index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($recordId, $key), false) | ||||
|             ); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         // Save succeeded, so check-in the record. | ||||
|         if ($checkin && $model->checkin($validData[$key]) === false) { | ||||
|             // Save the data in the session. | ||||
|             $this->app->setUserState($context . '.data', $validData); | ||||
|  | ||||
|             // Check-in failed, so go back to the record and display a notice. | ||||
|             $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError()), 'error'); | ||||
|             $this->setRedirect('index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($recordId, $key)); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         $this->setMessage( | ||||
|             Text::_( | ||||
|                 ($this->app->getLanguage()->hasKey($this->text_prefix . ($recordId === 0 && $this->app->isClient('site') ? '_SUBMIT' : '') . '_SAVE_SUCCESS') | ||||
|                 ? $this->text_prefix : 'JLIB_APPLICATION') . ($recordId === 0 && $this->app->isClient('site') ? '_SUBMIT' : '') . '_SAVE_SUCCESS' | ||||
|             ) | ||||
|         ); | ||||
|  | ||||
|         // Redirect the user and adjust session state based on the chosen task. | ||||
|         switch ($task) { | ||||
|             case 'apply': | ||||
|                 // Set the record data in the session. | ||||
|                 $recordId = $model->getState($this->context . '.id'); | ||||
|                 $this->holdEditId($context, $recordId); | ||||
|                 $this->app->setUserState($context . '.data', null); | ||||
|                 $model->checkout($recordId); | ||||
|  | ||||
|                 // Redirect back to the edit screen. | ||||
|                 $this->setRedirect( | ||||
|                     Route::_('index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($recordId, $key), false) | ||||
|                 ); | ||||
|  | ||||
|                 break; | ||||
|  | ||||
|             case 'save2new': | ||||
|                 // Clear the record id and data from the session. | ||||
|                 $this->releaseEditId($context, $recordId); | ||||
|                 $this->app->setUserState($context . '.data', null); | ||||
|  | ||||
|                 // Redirect back to the edit screen. | ||||
|                 $this->setRedirect( | ||||
|                     Route::_('index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend(null, $key), false) | ||||
|                 ); | ||||
|  | ||||
|                 break; | ||||
|  | ||||
|             default: | ||||
|                 // Clear the record id and data from the session. | ||||
|                 $this->releaseEditId($context, $recordId); | ||||
|                 $this->app->setUserState($context . '.data', null); | ||||
|  | ||||
|                 // Redirect to the list screen. | ||||
|                 $this->setRedirect( | ||||
|                     Route::_('index.php?option=' . $this->option . '&view=' . $this->view_list . $this->getRedirectToListAppend(), false) | ||||
|                 ); | ||||
|  | ||||
|                 break; | ||||
|         } | ||||
|  | ||||
|         // Invoke the postSave method to allow for the child class to access the model. | ||||
|         $this->postSaveHook($model, $validData); | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,49 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_finder | ||||
|  * | ||||
|  * @copyright   (C) 2011 Open Source Matters, Inc. <https://www.joomla.org> | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| namespace Joomla\Component\Finder\Administrator\Controller; | ||||
|  | ||||
| use Joomla\CMS\MVC\Controller\AdminController; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Filters controller class for Finder. | ||||
|  * | ||||
|  * @since  2.5 | ||||
|  */ | ||||
| class FiltersController extends AdminController | ||||
| { | ||||
|     /** | ||||
|      * The prefix to use with controller messages. | ||||
|      * | ||||
|      * @var    string | ||||
|      * @since  4.0.0 | ||||
|      */ | ||||
|     protected $text_prefix = 'COM_FINDER_FILTERS'; | ||||
|  | ||||
|     /** | ||||
|      * 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  \Joomla\CMS\MVC\Model\BaseDatabaseModel  The model. | ||||
|      * | ||||
|      * @since   2.5 | ||||
|      */ | ||||
|     public function getModel($name = 'Filter', $prefix = 'Administrator', $config = ['ignore_request' => true]) | ||||
|     { | ||||
|         return parent::getModel($name, $prefix, $config); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,107 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_finder | ||||
|  * | ||||
|  * @copyright   (C) 2011 Open Source Matters, Inc. <https://www.joomla.org> | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| namespace Joomla\Component\Finder\Administrator\Controller; | ||||
|  | ||||
| use Joomla\CMS\Event\Finder\GarbageCollectionEvent; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\MVC\Controller\AdminController; | ||||
| use Joomla\CMS\Plugin\PluginHelper; | ||||
| use Joomla\Component\Finder\Administrator\Indexer\Indexer; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Index controller class for Finder. | ||||
|  * | ||||
|  * @since  2.5 | ||||
|  */ | ||||
| class IndexController 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  \Joomla\CMS\MVC\Model\BaseDatabaseModel  The model. | ||||
|      * | ||||
|      * @since   2.5 | ||||
|      */ | ||||
|     public function getModel($name = 'Index', $prefix = 'Administrator', $config = ['ignore_request' => true]) | ||||
|     { | ||||
|         return parent::getModel($name, $prefix, $config); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to optimise the index by removing orphaned entries. | ||||
|      * | ||||
|      * @return  boolean  True on success. | ||||
|      * | ||||
|      * @since   4.2.0 | ||||
|      */ | ||||
|     public function optimise() | ||||
|     { | ||||
|         $this->checkToken(); | ||||
|  | ||||
|         $dispatcher = $this->getDispatcher(); | ||||
|  | ||||
|         // Optimise the index by first running the garbage collection | ||||
|         PluginHelper::importPlugin('finder', null, true, $dispatcher); | ||||
|         $dispatcher->dispatch('onFinderGarbageCollection', new GarbageCollectionEvent('onFinderGarbageCollection', [])); | ||||
|  | ||||
|         // Now run the optimisation method from the indexer | ||||
|         $indexer = new Indexer(); | ||||
|         $indexer->optimize(); | ||||
|  | ||||
|         $message = Text::_('COM_FINDER_INDEX_OPTIMISE_FINISHED'); | ||||
|         $this->setRedirect('index.php?option=com_finder&view=index', $message); | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to purge all indexed links from the database. | ||||
|      * | ||||
|      * @return  boolean  True on success. | ||||
|      * | ||||
|      * @since   2.5 | ||||
|      */ | ||||
|     public function purge() | ||||
|     { | ||||
|         $this->checkToken(); | ||||
|  | ||||
|         // Remove the script time limit. | ||||
|         if (\function_exists('set_time_limit')) { | ||||
|             set_time_limit(0); | ||||
|         } | ||||
|  | ||||
|         /** @var \Joomla\Component\Finder\Administrator\Model\IndexModel $model */ | ||||
|         $model = $this->getModel('Index', 'Administrator'); | ||||
|  | ||||
|         // Attempt to purge the index. | ||||
|         $return = $model->purge(); | ||||
|  | ||||
|         if (!$return) { | ||||
|             $message = Text::_('COM_FINDER_INDEX_PURGE_FAILED', $model->getError()); | ||||
|             $this->setRedirect('index.php?option=com_finder&view=index', $message); | ||||
|  | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         $message = Text::_('COM_FINDER_INDEX_PURGE_SUCCESS'); | ||||
|         $this->setRedirect('index.php?option=com_finder&view=index', $message); | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,424 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_finder | ||||
|  * | ||||
|  * @copyright   (C) 2011 Open Source Matters, Inc. <https://www.joomla.org> | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| namespace Joomla\Component\Finder\Administrator\Controller; | ||||
|  | ||||
| use Joomla\CMS\Component\ComponentHelper; | ||||
| use Joomla\CMS\Event\Finder\BeforeIndexEvent; | ||||
| use Joomla\CMS\Event\Finder\BuildIndexEvent; | ||||
| use Joomla\CMS\Event\Finder\StartIndexEvent; | ||||
| use Joomla\CMS\Factory; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\Log\Log; | ||||
| use Joomla\CMS\MVC\Controller\BaseController; | ||||
| use Joomla\CMS\Plugin\PluginHelper; | ||||
| use Joomla\CMS\Session\Session; | ||||
| use Joomla\Component\Finder\Administrator\Indexer\Adapter; | ||||
| use Joomla\Component\Finder\Administrator\Indexer\DebugAdapter; | ||||
| use Joomla\Component\Finder\Administrator\Indexer\DebugIndexer; | ||||
| use Joomla\Component\Finder\Administrator\Indexer\Indexer; | ||||
| use Joomla\Component\Finder\Administrator\Response\Response; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Indexer controller class for Finder. | ||||
|  * | ||||
|  * @since  2.5 | ||||
|  */ | ||||
| class IndexerController extends BaseController | ||||
| { | ||||
|     /** | ||||
|      * Method to start the indexer. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   2.5 | ||||
|      */ | ||||
|     public function start() | ||||
|     { | ||||
|         // Check for a valid token. If invalid, send a 403 with the error message. | ||||
|         if (!Session::checkToken('request')) { | ||||
|             static::sendResponse(new \Exception(Text::_('JINVALID_TOKEN_NOTICE'), 403)); | ||||
|  | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         $params     = ComponentHelper::getParams('com_finder'); | ||||
|         $dispatcher = $this->getDispatcher(); | ||||
|  | ||||
|         if ($params->get('enable_logging', '0')) { | ||||
|             $options['format']    = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}'; | ||||
|             $options['text_file'] = 'indexer.php'; | ||||
|             Log::addLogger($options); | ||||
|         } | ||||
|  | ||||
|         // Log the start | ||||
|         try { | ||||
|             Log::add('Starting the indexer', Log::INFO); | ||||
|         } catch (\RuntimeException $exception) { | ||||
|             // Informational log only | ||||
|         } | ||||
|  | ||||
|         // We don't want this form to be cached. | ||||
|         $this->app->allowCache(false); | ||||
|  | ||||
|         // Put in a buffer to silence noise. | ||||
|         ob_start(); | ||||
|  | ||||
|         // Reset the indexer state. | ||||
|         Indexer::resetState(); | ||||
|  | ||||
|         // Import the finder plugins. | ||||
|         PluginHelper::importPlugin('finder', null, true, $dispatcher); | ||||
|  | ||||
|         // Add the indexer language to \JS | ||||
|         Text::script('COM_FINDER_AN_ERROR_HAS_OCCURRED'); | ||||
|         Text::script('COM_FINDER_NO_ERROR_RETURNED'); | ||||
|  | ||||
|         // Start the indexer. | ||||
|         try { | ||||
|             // Trigger the onStartIndex event. | ||||
|             $dispatcher->dispatch('onStartIndex', new StartIndexEvent('onStartIndex', [])); | ||||
|  | ||||
|             // Get the indexer state. | ||||
|             $state        = Indexer::getState(); | ||||
|             $state->start = 1; | ||||
|  | ||||
|             $output = ob_get_contents(); | ||||
|  | ||||
|             // Finder plugins should not create output of any kind. If there is output, that very likely is the result of a PHP error. | ||||
|             if (trim($output)) { | ||||
|                 throw new \Exception(Text::_('COM_FINDER_AN_ERROR_HAS_OCCURRED')); | ||||
|             } | ||||
|  | ||||
|             // Send the response. | ||||
|             static::sendResponse($state); | ||||
|         } catch (\Exception $e) { | ||||
|             // Catch an exception and return the response. | ||||
|             static::sendResponse($e); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to run the next batch of content through the indexer. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   2.5 | ||||
|      */ | ||||
|     public function batch() | ||||
|     { | ||||
|         // Check for a valid token. If invalid, send a 403 with the error message. | ||||
|         if (!Session::checkToken('request')) { | ||||
|             static::sendResponse(new \Exception(Text::_('JINVALID_TOKEN_NOTICE'), 403)); | ||||
|  | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         $params     = ComponentHelper::getParams('com_finder'); | ||||
|         $dispatcher = $this->getDispatcher(); | ||||
|  | ||||
|         if ($params->get('enable_logging', '0')) { | ||||
|             $options['format']    = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}'; | ||||
|             $options['text_file'] = 'indexer.php'; | ||||
|             Log::addLogger($options); | ||||
|         } | ||||
|  | ||||
|         // Log the start | ||||
|         try { | ||||
|             Log::add('Starting the indexer batch process', Log::INFO); | ||||
|         } catch (\RuntimeException $exception) { | ||||
|             // Informational log only | ||||
|         } | ||||
|  | ||||
|         // We don't want this form to be cached. | ||||
|         $this->app->allowCache(false); | ||||
|  | ||||
|         // Put in a buffer to silence noise. | ||||
|         ob_start(); | ||||
|  | ||||
|         // Remove the script time limit. | ||||
|         if (\function_exists('set_time_limit')) { | ||||
|             set_time_limit(0); | ||||
|         } | ||||
|  | ||||
|         // Get the indexer state. | ||||
|         $state = Indexer::getState(); | ||||
|  | ||||
|         // Reset the batch offset. | ||||
|         $state->batchOffset = 0; | ||||
|  | ||||
|         // Update the indexer state. | ||||
|         Indexer::setState($state); | ||||
|  | ||||
|         // Import the finder plugins. | ||||
|         PluginHelper::importPlugin('finder', null, true, $dispatcher); | ||||
|  | ||||
|         /* | ||||
|          * We are going to swap out the raw document object with an HTML document | ||||
|          * in order to work around some plugins that don't do proper environment | ||||
|          * checks before trying to use HTML document functions. | ||||
|          */ | ||||
|         $lang = $this->app->getLanguage(); | ||||
|  | ||||
|         // Get the document properties. | ||||
|         $attributes = [ | ||||
|             'charset'   => 'utf-8', | ||||
|             'lineend'   => 'unix', | ||||
|             'tab'       => '  ', | ||||
|             'language'  => $lang->getTag(), | ||||
|             'direction' => $lang->isRtl() ? 'rtl' : 'ltr', | ||||
|         ]; | ||||
|  | ||||
|         // Start the indexer. | ||||
|         try { | ||||
|             // Trigger the onBeforeIndex event. | ||||
|             $dispatcher->dispatch('onBeforeIndex', new BeforeIndexEvent('onBeforeIndex', [])); | ||||
|  | ||||
|             // Trigger the onBuildIndex event. | ||||
|             $dispatcher->dispatch('onBuildIndex', new BuildIndexEvent('onBuildIndex', [])); | ||||
|  | ||||
|             // Get the indexer state. | ||||
|             $state           = Indexer::getState(); | ||||
|             $state->start    = 0; | ||||
|             $state->complete = 0; | ||||
|  | ||||
|             // Log batch completion and memory high-water mark. | ||||
|             try { | ||||
|                 Log::add('Batch completed, peak memory usage: ' . number_format(memory_get_peak_usage(true)) . ' bytes', Log::INFO); | ||||
|             } catch (\RuntimeException $exception) { | ||||
|                 // Informational log only | ||||
|             } | ||||
|  | ||||
|             $output = ob_get_contents(); | ||||
|  | ||||
|             // Finder plugins should not create output of any kind. If there is output, that very likely is the result of a PHP error. | ||||
|             if (trim($output)) { | ||||
|                 throw new \Exception(Text::_('COM_FINDER_INDEXER_ERROR_PLUGIN_FAILURE')); | ||||
|             } | ||||
|  | ||||
|             // Send the response. | ||||
|             static::sendResponse($state); | ||||
|         } catch (\Exception $e) { | ||||
|             // Catch an exception and return the response. | ||||
|             // Send the response. | ||||
|             static::sendResponse($e); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to optimize the index and perform any necessary cleanup. | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   2.5 | ||||
|      */ | ||||
|     public function optimize() | ||||
|     { | ||||
|         // Check for a valid token. If invalid, send a 403 with the error message. | ||||
|         if (!Session::checkToken('request')) { | ||||
|             static::sendResponse(new \Exception(Text::_('JINVALID_TOKEN_NOTICE'), 403)); | ||||
|  | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         // We don't want this form to be cached. | ||||
|         $this->app->allowCache(false); | ||||
|  | ||||
|         // Put in a buffer to silence noise. | ||||
|         ob_start(); | ||||
|  | ||||
|         // Import the finder plugins. | ||||
|         PluginHelper::importPlugin('finder', null, true, $this->getDispatcher()); | ||||
|  | ||||
|         try { | ||||
|             // Optimize the index | ||||
|             $indexer = new Indexer(); | ||||
|             $indexer->optimize(); | ||||
|  | ||||
|             // Get the indexer state. | ||||
|             $state           = Indexer::getState(); | ||||
|             $state->start    = 0; | ||||
|             $state->complete = 1; | ||||
|  | ||||
|             $output = ob_get_contents(); | ||||
|  | ||||
|             // Finder plugins should not create output of any kind. If there is output, that very likely is the result of a PHP error. | ||||
|             if (trim($output)) { | ||||
|                 throw new \Exception(Text::_('COM_FINDER_AN_ERROR_HAS_OCCURRED')); | ||||
|             } | ||||
|  | ||||
|             // Send the response. | ||||
|             static::sendResponse($state); | ||||
|         } catch (\Exception $e) { | ||||
|             // Catch an exception and return the response. | ||||
|             static::sendResponse($e); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to handle a send a \JSON response. The body parameter | ||||
|      * can be an \Exception object for when an error has occurred or | ||||
|      * a CMSObject for a good response. | ||||
|      * | ||||
|      * @param   \Joomla\CMS\Object\CMSObject|\Exception  $data  CMSObject on success, \Exception on error. [optional] | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   2.5 | ||||
|      */ | ||||
|     public static function sendResponse($data = null) | ||||
|     { | ||||
|         $app = Factory::getApplication(); | ||||
|  | ||||
|         $params = ComponentHelper::getParams('com_finder'); | ||||
|  | ||||
|         if ($params->get('enable_logging', '0')) { | ||||
|             $options['format']    = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}'; | ||||
|             $options['text_file'] = 'indexer.php'; | ||||
|             Log::addLogger($options); | ||||
|         } | ||||
|  | ||||
|         // Send the assigned error code if we are catching an exception. | ||||
|         if ($data instanceof \Exception) { | ||||
|             try { | ||||
|                 Log::add($data->getMessage(), Log::ERROR); | ||||
|             } catch (\RuntimeException $exception) { | ||||
|                 // Informational log only | ||||
|             } | ||||
|  | ||||
|             $app->setHeader('status', $data->getCode()); | ||||
|         } | ||||
|  | ||||
|         // Create the response object. | ||||
|         $response = new Response($data); | ||||
|  | ||||
|         if (\JDEBUG) { | ||||
|             // Add the buffer and memory usage | ||||
|             $response->buffer = ob_get_contents(); | ||||
|             $response->memory = memory_get_usage(true); | ||||
|         } | ||||
|         ob_clean(); | ||||
|  | ||||
|         // Send the JSON response. | ||||
|         echo json_encode($response); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method to call a specific indexing plugin and return debug info | ||||
|      * | ||||
|      * @return  void | ||||
|      * | ||||
|      * @since   5.0.0 | ||||
|      * @internal | ||||
|      */ | ||||
|     public function debug() | ||||
|     { | ||||
|         // Check for a valid token. If invalid, send a 403 with the error message. | ||||
|         if (!Session::checkToken('request')) { | ||||
|             static::sendResponse(new \Exception(Text::_('JINVALID_TOKEN_NOTICE'), 403)); | ||||
|  | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         // We don't want this form to be cached. | ||||
|         $this->app->allowCache(false); | ||||
|  | ||||
|         // Put in a buffer to silence noise. | ||||
|         ob_start(); | ||||
|  | ||||
|         // Remove the script time limit. | ||||
|         @set_time_limit(0); | ||||
|  | ||||
|         // Get the indexer state. | ||||
|         Indexer::resetState(); | ||||
|         $state = Indexer::getState(); | ||||
|  | ||||
|         // Reset the batch offset. | ||||
|         $state->batchOffset = 0; | ||||
|  | ||||
|         // Update the indexer state. | ||||
|         Indexer::setState($state); | ||||
|  | ||||
|         // Start the indexer. | ||||
|         try { | ||||
|             // Import the finder plugins. | ||||
|             class_alias(DebugAdapter::class, Adapter::class); | ||||
|             $plugin = $this->app->bootPlugin($this->app->getInput()->get('plugin'), 'finder'); | ||||
|             $plugin->setIndexer(new DebugIndexer()); | ||||
|             $plugin->debug($this->app->getInput()->get('id')); | ||||
|  | ||||
|             $output = ''; | ||||
|  | ||||
|             // Create list of attributes | ||||
|             $output .= '<fieldset><legend>' . Text::_('COM_FINDER_INDEXER_FIELDSET_ATTRIBUTES') . '</legend>'; | ||||
|             $output .= '<dl class="row">'; | ||||
|  | ||||
|             foreach (DebugIndexer::$item as $key => $value) { | ||||
|                 $output .= '<dt class="col-sm-2">' . $key . '</dt><dd class="col-sm-10 text-break">' . $value . '</dd>'; | ||||
|             } | ||||
|  | ||||
|             $output .= '</dl>'; | ||||
|             $output .= '</fieldset>'; | ||||
|  | ||||
|             $output .= '<fieldset><legend>' . Text::_('COM_FINDER_INDEXER_FIELDSET_ELEMENTS') . '</legend>'; | ||||
|             $output .= '<dl class="row">'; | ||||
|  | ||||
|             foreach (DebugIndexer::$item->getElements() as $key => $element) { | ||||
|                 $output .= '<dt class="col-sm-2">' . $key . '</dt><dd class="col-sm-10 text-break">' . $element . '</dd>'; | ||||
|             } | ||||
|  | ||||
|             $output .= '</dl>'; | ||||
|             $output .= '</fieldset>'; | ||||
|  | ||||
|             $output .= '<fieldset><legend>' . Text::_('COM_FINDER_INDEXER_FIELDSET_INSTRUCTIONS') . '</legend>'; | ||||
|             $output .= '<dl class="row">'; | ||||
|             $contexts = [ | ||||
|                 1 => 'Title context', | ||||
|                 2 => 'Text context', | ||||
|                 3 => 'Meta context', | ||||
|                 4 => 'Path context', | ||||
|                 5 => 'Misc context', | ||||
|             ]; | ||||
|  | ||||
|             foreach (DebugIndexer::$item->getInstructions() as $key => $element) { | ||||
|                 $output .= '<dt class="col-sm-2">' . $contexts[$key] . '</dt><dd class="col-sm-10 text-break">' . json_encode($element) . '</dd>'; | ||||
|             } | ||||
|  | ||||
|             $output .= '</dl>'; | ||||
|             $output .= '</fieldset>'; | ||||
|  | ||||
|             $output .= '<fieldset><legend>' . Text::_('COM_FINDER_INDEXER_FIELDSET_TAXONOMIES') . '</legend>'; | ||||
|             $output .= '<dl class="row">'; | ||||
|  | ||||
|             foreach (DebugIndexer::$item->getTaxonomy() as $key => $element) { | ||||
|                 $output .= '<dt class="col-sm-2">' . $key . '</dt><dd class="col-sm-10 text-break">' . json_encode($element) . '</dd>'; | ||||
|             } | ||||
|  | ||||
|             $output .= '</dl>'; | ||||
|             $output .= '</fieldset>'; | ||||
|  | ||||
|             // Get the indexer state. | ||||
|             $state           = Indexer::getState(); | ||||
|             $state->start    = 0; | ||||
|             $state->complete = 0; | ||||
|             $state->rendered = $output; | ||||
|  | ||||
|             echo json_encode($state); | ||||
|         } catch (\Exception $e) { | ||||
|             // Catch an exception and return the response. | ||||
|             // Send the response. | ||||
|             static::sendResponse($e); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,49 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_finder | ||||
|  * | ||||
|  * @copyright   (C) 2011 Open Source Matters, Inc. <https://www.joomla.org> | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| namespace Joomla\Component\Finder\Administrator\Controller; | ||||
|  | ||||
| use Joomla\CMS\MVC\Controller\AdminController; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Maps controller class for Finder. | ||||
|  * | ||||
|  * @since  2.5 | ||||
|  */ | ||||
| class MapsController extends AdminController | ||||
| { | ||||
|     /** | ||||
|      * The prefix to use with controller messages. | ||||
|      * | ||||
|      * @var    string | ||||
|      * @since  4.0.0 | ||||
|      */ | ||||
|     protected $text_prefix = 'COM_FINDER_MAPS'; | ||||
|  | ||||
|     /** | ||||
|      * 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  \Joomla\CMS\MVC\Model\BaseDatabaseModel  The model. | ||||
|      * | ||||
|      * @since   1.6 | ||||
|      */ | ||||
|     public function getModel($name = 'Maps', $prefix = 'Administrator', $config = ['ignore_request' => true]) | ||||
|     { | ||||
|         return parent::getModel($name, $prefix, $config); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,46 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_finder | ||||
|  * | ||||
|  * @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\Finder\Administrator\Controller; | ||||
|  | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\MVC\Controller\BaseController; | ||||
| use Joomla\CMS\Session\Session; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * Methods supporting a list of search terms. | ||||
|  * | ||||
|  * @since  4.0.0 | ||||
|  */ | ||||
| class SearchesController extends BaseController | ||||
| { | ||||
|     /** | ||||
|      * Method to reset the search log table. | ||||
|      * | ||||
|      * @return  void | ||||
|      */ | ||||
|     public function reset() | ||||
|     { | ||||
|         // Check for request forgeries. | ||||
|         Session::checkToken() or jexit(Text::_('JINVALID_TOKEN')); | ||||
|  | ||||
|         $model = $this->getModel('Searches'); | ||||
|  | ||||
|         if (!$model->reset()) { | ||||
|             $this->app->enqueueMessage($model->getError(), 'error'); | ||||
|         } | ||||
|  | ||||
|         $this->setRedirect('index.php?option=com_finder&view=searches'); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user