Файловый менеджер - Редактировать - /var/www/html/administrator/components/com_jchat/Framework/Controller/Controller.php
Ðазад
<?php namespace JExtstore\Component\JChat\Administrator\Framework; /** * * @package JCHAT::administrator::components::com_jchat * @subpackage framework * @subpackage controller * @author Joomla! Extensions Store * @copyright (C) 2015 - Joomla! Extensions Store * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html */ defined ( '_JEXEC' ) or die ( 'Restricted access' ); use Joomla\CMS\MVC\Factory\MVCFactoryInterface; use Joomla\CMS\MVC\Controller\BaseController as JBaseController; use Joomla\CMS\Cache\Controller\ViewController; use Joomla\Utilities\ArrayHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Factory; use Joomla\CMS\Component\ComponentHelper; /** * Base controller class * * @package JCHAT::administrator::components::com_jchat * @subpackage framework * @subpackage controller * @since 1.0 */ class Controller extends JBaseController { /** * Dispatch option * * @access protected * @var string */ protected $option; /** * Main application reference * * @access protected * @var Object */ protected $app; /** * User object for ACL authorise check * * @access protected * @var Object */ protected $user; /** * Document object, needed by controllers to instantiate * the right view object based on document format * * @access protected * @var Object */ protected $document; /** * Variables in request array * * @access protected * @var Object */ protected $requestArray; /** * Method override to check if you can add a new record. * * @param array $data * An array of input data. * * @return bool */ protected function allowDisplay(): bool { // Set a default value $allow = true; $cParams = ComponentHelper::getParams('com_jchat'); // Check for chat access level $chatAccessGids = array(); $chatAccessLevels = $cParams->get('chat_accesslevels', array('0')); if(is_array($chatAccessLevels) && !in_array(0, $chatAccessLevels, false)) { // Check for user groups current user belong to $userGroups = $this->user->getAuthorisedGroups(); $db =Factory::getContainer()->get('DatabaseDriver'); // Translate the chat access levels to Joomla users groups sum $query = $db->getQuery(true) ->select('rules') ->from($db->quoteName('#__viewlevels')) ->where('id IN (' . implode(',', $chatAccessLevels) . ')'); // Set the query for execution. $db->setQuery($query); // Build the view levels array. foreach ($db->loadColumn() as $levels) { $chatAccessGids = array_merge($chatAccessGids, (array) json_decode($levels)); } // Intersect to recognize chat admins $intersectResult = array_intersect($userGroups, $chatAccessGids); $allow = (bool)(count($intersectResult)); } // Check for menu exclusion $menu = $this->app->getMenu()->getActive(); if(is_object($menu)) { $menuItemid = $menu->id; $menuExcluded = $cParams->get('chat_exclusions'); if(is_array($menuExcluded) && !in_array(0, $menuExcluded, false) && in_array($menuItemid, $menuExcluded)) { $allow = false; } } // Check for IP multiple ranges exclusions if($cParams->get ( 'ipbanning', false)) { $ipAddressRegex = '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/i'; $clientIP = $_SERVER ['REMOTE_ADDR']; $clientIpDec = ( float ) sprintf ( "%u", ip2long ( $clientIP ) ); $ipRanges = $cParams->get ( 'iprange_multiple', null); // Check if data are not null if($ipRanges) { // Try to load every range, one per row $explodeRows = explode(PHP_EOL, $ipRanges); if(!empty($explodeRows)) { foreach ($explodeRows as $singleRange) { // Try to detect single range $explodeRange = explode('-', $singleRange); if(!empty($explodeRange) && count($explodeRange) == 2) { $ipStart = trim($explodeRange[0]); $ipEnd = trim($explodeRange[1]); $validIpRangeStart = preg_match ( $ipAddressRegex, $ipStart ); $validIpRangeEnd = preg_match ( $ipAddressRegex, $ipEnd ); if ($validIpRangeStart && $validIpRangeEnd) { $lowerIpDec = ( float ) sprintf ( "%u", ip2long ( $ipStart ) ); $upperIpDec = ( float ) sprintf ( "%u", ip2long ( $ipEnd ) ); if (($clientIpDec >= $lowerIpDec) && ($clientIpDec <= $upperIpDec)) { $allow = false; break; } } } } } } } // Check for hours activation $startHour = $cParams->get('start_at_hour', null); $stopHour = $cParams->get('stop_at_hour', null); if($startHour && $stopHour) { $jTimeZone = $this->app->getConfig ()->get ( 'offset' ); $dateObject = Factory::getDate(); $dateObject->setTimezone(new \DateTimeZone($jTimeZone)); $currentHour = $dateObject->format('G', true); if($currentHour < $startHour || $currentHour >= $stopHour) { $allow = false; } } // Check for day of the week activation $daysOfTheWeek = $cParams->get('days_of_the_week', null); if(is_array($daysOfTheWeek) && count($daysOfTheWeek) && !in_array('', $daysOfTheWeek, true)) { $jTimeZone = $this->app->getConfig ()->get ( 'offset' ); $dateObject = Factory::getDate(); $dateObject->setTimezone(new \DateTimeZone($jTimeZone)); $currentDay = $dateObject->format('w', true); if(!in_array($currentDay, $daysOfTheWeek)) { $allow = false; } } return $allow; } /** * Method override to check if you can add a new record. * * @param array $data * An array of input data. * * @return bool * * @since 1.6 */ protected function allowAdmin($assetName): bool { // Initialise variables. $allow = $this->user->authorise ( 'core.admin', $assetName ); return $allow; } /** * Method override to check if you can add a new record. * * @param array $data * An array of input data. * * @return bool * * @since 1.6 */ protected function allowAdd($assetName): bool { // Initialise variables. $allow = $this->user->authorise ( 'core.create', $assetName ); return $allow; } /** * Method override to check if you can edit an existing record. * * @param array $data * An array of input data. * @param string $key * The name of the key for the primary key. * * @return bool * * @since 1.6 */ protected function allowEdit($assetName): bool { // Initialise variables. $allow = $this->user->authorise ( 'core.edit', $assetName ); return $allow; } /** * Method override to check if you can edit an existing record. * * @param array $data * An array of input data. * @param string $key * The name of the key for the primary key. * * @return bool * * @since 1.6 */ protected function allowEditState($assetName): bool { // Initialise variables. $allow = $this->user->authorise ( 'core.edit.state', $assetName ); return $allow; } /** * Method override to check if you can edit an existing record. * * @param array $data * An array of input data. * @param string $key * The name of the key for the primary key. * * @return bool * * @since 1.6 */ protected function allowDelete($assetName): bool { // Initialise variables. $allow = $this->user->authorise ( 'core.delete', $assetName ); return $allow; } /** * Detect if a user has permissions to access a feature based on user groups * * @access protected * @param string $param The parameter to check against * @param Object $params The parameters object with eventual overrides * @return bool */ protected function hasGroupsPermissions($param, $params): bool { $hasPermission = true; // Check for live support mode active $paramGroups = $params->get($param, array('0')); // Live support active! if(is_array($paramGroups) && !in_array(0, $paramGroups, false)) { // Check for user groups current user belong to $userGroups = $this->user->getAuthorisedGroups(); // Intersect to recognize chat admins $intersectResult = array_intersect($userGroups, $paramGroups); $hasPermission = (bool)(count($intersectResult)); } return $hasPermission; } /** * Get a cache object specific for this extension models already configured and independant from global config * The cache handler is always view to cache the entire component view response * * @access protected * @return ViewController */ protected function getExtensionCache(): ViewController { // Static cache instance static $cache; if (is_object ( $cache )) { return $cache; } $conf = $this->app->getConfig (); $componentParams = ComponentHelper::getParams ( $this->option ); // days to hours to minutes (core cache multiplies by 60 secs), default 1 day $lifeTimeMinutes = ( int ) $componentParams->get ( 'lifetime_view_cache', 1 ) * 24 * 60; // Check for an RSS feed lifetime override $format = $this->app->input->get ( 'format', 'html' ); if ($format == 'rss') { $lifeTimeMinutes = ( int ) $componentParams->get ( 'rss_lifetime_view_cache', 60 ); } $options = array ( 'defaultgroup' => $this->option, 'cachebase' => $conf->get ( 'cache_path', JPATH_CACHE ), 'lifetime' => $lifeTimeMinutes, 'language' => $conf->get ( 'language', 'en-GB' ), 'storage' => $conf->get ( 'cache_handler', 'file' ) ); $cache = Factory::getContainer()->get(\Joomla\CMS\Cache\CacheControllerFactoryInterface::class)->createCacheController( 'view', $options ); $cache->setCaching ( $componentParams->get ( 'enable_view_cache', false ) ); return $cache; } /** * Setta il model state a partire dallo userstate di sessione * * @access protected * @param string $scope * @return object */ protected function setModelState($scope = 'default', $ordering = true): object { $option = $this->option; $componentParams = ComponentHelper::getParams ( $this->option ); $search = $this->getUserStateFromRequest ( "$option.$scope.searchword", 'search', '' ); $limit = $this->getUserStateFromRequest ( "$option.$scope.limit", 'limit', $componentParams->get ( 'lists_limit_pagination', 10 ), 'int' ); $limitStart = $this->getUserStateFromRequest ( "$option.$scope.limitstart", 'limitstart', 0, 'int' ); // Round del limit al change proof $limitStart = ($limit != 0 ? (floor ( $limitStart / $limit ) * $limit) : 0); // Check for ordering support if ($ordering) { $filter_order = $this->getUserStateFromRequest ( "$option.$scope.filter_order", 'filter_order', 's.ordering', 'cmd' ); $filter_order_Dir = $this->getUserStateFromRequest ( "$option.$scope.filter_order_Dir", 'filter_order_Dir', 'asc', 'word' ); } // Get default model $defaultModel = $this->getModel (); // Set model state $defaultModel->setState ( 'option', $option ); $defaultModel->setState ( 'limit', $limit ); $defaultModel->setState ( 'limitstart', $limitStart ); $defaultModel->setState ( 'searchword', $search ); // Check for ordering support if ($ordering) { $defaultModel->setState ( 'order', $filter_order ); $defaultModel->setState ( 'order_dir', $filter_order_Dir ); } return $defaultModel; } /** * Gets the value of a user state variable and sets it in the session * * This is the same as the method in JApplication except that this also can optionally * force you back to the first page when a filter has changed * * @param string $key * The key of the user state variable. * @param string $request * The name of the variable passed in a request. * @param string $default * The default value for the variable if not found. Optional. * @param string $type * Filter for the variable, for valid values see {@link \Joomla\CMS\Filter\InputFilter::clean()}. Optional. * @param boolean $resetPage * If true, the limitstart in request is set to zero * * @return The request user state. * @since 2.0 */ protected function getUserStateFromRequest($key, $request, $default = null, $type = 'none', $resetPage = true) { $app = Factory::getApplication (); $old_state = $app->getUserState ( $key ); $cur_state = (! is_null ( $old_state )) ? $old_state : $default; $new_state = $this->app->input->get ( $request, null, $type ); if ($new_state && ($cur_state != $new_state) && ($resetPage)) { $this->app->input->set ( 'limitstart', 0 ); } // Save the new value only if it is set in this request. if ($new_state !== null) { $app->setUserState ( $key, $new_state ); } else { $new_state = $cur_state; } return $new_state; } /** * 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 Model|boolean Model object on success; otherwise false on failure. * * @since 3.0 */ public function getModel($name = '', $prefix = '', $config = array()) { static $models = array (); if (empty($name)) { $name = $this->getName(); } if (array_key_exists ( $name, $models )) { return $models [$name]; } $model = parent::getModel($name, $prefix, $config); $models[$name] = $model; return $model; } /** * Edit entity * * @access public * @return bool */ public function editEntity(): bool { $this->app->input->set ( 'hidemainmenu', 1 ); $cid = $this->app->input->get ( 'cid', array ( 0 ), 'array' ); $idEntity = ( int ) $cid [0]; $model = $this->getModel (); $model->setState ( 'option', $this->option ); // Try to load record from model if (! $record = $model->loadEntity ( $idEntity )) { // Model set exceptions for something gone wrong, so enqueue exceptions and levels on application object then set redirect and exit $modelExceptions = $model->getErrors (); foreach ( $modelExceptions as $exception ) { $this->app->enqueueMessage ( $exception->getMessage (), $exception->getErrorLevel () ); } $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_ERROR_EDITING' ) ); return false; } // Additional model state setting $model->setState ( 'option', $this->option ); // Check out control on record if ($record->checked_out && $record->checked_out != $this->user->id) { $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_CHECKEDOUT_RECORD' ), 'notice' ); return false; } // Access check if ($record->id && ! $this->allowEdit ( $this->option )) { $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_ERROR_ALERT_NOACCESS' ), 'notice' ); return false; } if (! $record->id && ! $this->allowAdd ( $this->option )) { $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_ERROR_ALERT_NOACCESS' ), 'notice' ); return false; } // Check out del record if ($record->id) { $record->checkout ( $this->user->id ); } // Get view and pushing model $viewType = $this->document->getType(); $viewName = $this->input->get('view', $this->default_view); $viewLayout = $this->input->get('layout', 'default', 'string'); $view = $this->getView($viewName, $viewType, '', array('base_path' => $this->basePath, 'layout' => $viewLayout)); $view->setModel ( $model, true ); // Call edit view $view->editEntity ( $record ); return true; } /** * Manage entity apply/save after edit entity * * @access public * @return bool */ public function saveEntity(): bool { $context = implode ( '.', array ( $this->option, strtolower ( $this->getName () ), 'errordataload' ) ); // Security layer for tags html outputted fields $sanitizedFields = array ( 'name', 'description' ); foreach ( $sanitizedFields as $field ) { $this->requestArray [$field] = strip_tags ( $this->requestArray [$field] ); } // Load della model e bind store $model = $this->getModel (); if (! $result = $model->storeEntity ()) { // Model set exceptions for something gone wrong, so enqueue exceptions and levels on application object then set redirect and exit $modelException = $model->getError ( null, false ); $this->app->enqueueMessage ( $modelException->getMessage (), $modelException->getErrorLevel () ); // Store data for session recover $this->app->setUserState ( $context, $this->requestArray ); $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".editEntity&cid[]=" . $this->app->input->get ( 'id' ), Text::_ ( 'COM_JCHAT_ERROR_SAVING' ) ); return false; } // Security safe if not model record id detected if (! $id = $result->id) { $id = $this->app->input->get ( 'id' ); } // Redirects switcher switch ($this->task) { case 'saveEntity' : $redirects = array ( 'task' => 'display', 'msgsufix' => '_SAVING' ); break; case 'saveEntity2New' : $redirects = array ( 'task' => 'editEntity', 'msgsufix' => '_STORING' ); break; default : case 'applyEntity' : $redirects = array ( 'task' => 'editEntity&cid[]=' . $id, 'msgsufix' => '_APPLY' ); break; } $msg = 'COM_JCHAT_SUCCESS' . $redirects ['msgsufix']; $controllerTask = $redirects ['task']; $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . "." . $controllerTask, Text::_ ( $msg ) ); return true; } /** * Manage cancel edit for entity and unlock record checked out * * @access public * @return void */ public function cancelEntity(): void { $id = $this->app->input->get ( 'id' ); // Load della model e checkin before exit $model = $this->getModel (); if (! $model->cancelEntity ( $id )) { // Model set exceptions for something gone wrong, so enqueue exceptions and levels on application object then set redirect and exit $modelException = $model->getError ( null, false ); $this->app->enqueueMessage ( $modelException->getMessage (), $modelException->getErrorLevel () ); } $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_CANCELED_OPERATION' ) ); } /** * Copies one or more items * * @access public * @return bool */ public function copyEntity(): bool { $cids = $this->app->input->get ( 'cid', array (), 'array' ); // Load della model e checkin before exit $model = $this->getModel (); if (! $model->copyEntity ( $cids )) { // Model set exceptions for something gone wrong, so enqueue exceptions and levels on application object then set redirect and exit $modelException = $model->getError ( null, false ); $this->app->enqueueMessage ( $modelException->getMessage (), $modelException->getErrorLevel () ); $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_ERROR_DUPLICATING' ) ); return false; } $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_SUCCESS_DUPLICATING' ) ); return true; } /** * Delete a db table entity * * @access public * @return bool */ public function deleteEntity(): bool { $cids = $this->app->input->get ( 'cid', array (), 'array' ); // Access check if (! $this->allowDelete ( $this->option )) { $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_ERROR_ALERT_NOACCESS' ), 'notice' ); return false; } // Load della model e checkin before exit $model = $this->getModel (); if (! $model->deleteEntity ( $cids )) { // Model set exceptions for something gone wrong, so enqueue exceptions and levels on application object then set redirect and exit $modelException = $model->getError ( null, false ); $this->app->enqueueMessage ( $modelException->getMessage (), $modelException->getErrorLevel () ); $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_ERROR_DELETE' ) ); return false; } $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_SUCCESS_DELETE' ) ); return true; } /** * Moves the order of a record * * @access public * @param * integer The increment to reorder by * @return bool */ public function moveOrder(): bool { // Set model state $this->setModelState ( $this->name ); // ID Entity $cid = $this->app->input->get ( 'cid', array ( 0 ), 'array' ); $idEntity = $cid [0]; // Task direction $model = $this->getModel (); $orderDir = $model->getState ( 'order_dir' ); switch ($orderDir) { case 'desc' : $orderUp = 1; $orderDown = - 1; break; case 'asc' : default : $orderUp = - 1; $orderDown = 1; break; } $direction = $this->task == 'moveorder_up' ? $orderUp : $orderDown; if (! $model->changeOrder ( $idEntity, $direction )) { // Model set exceptions for something gone wrong, so enqueue exceptions and levels on application object then set redirect and exit $modelException = $model->getError ( null, false ); $this->app->enqueueMessage ( $modelException->getMessage (), $modelException->getErrorLevel () ); $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_ERROR_REORDER' ) ); return false; } $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_SUCCESS_REORDER' ) ); return true; } /** * Save ordering * * @access public * @return bool */ public function saveOrder(): bool { $cids = $this->app->input->get ( 'cid', array (), 'array' ); $order = $this->app->input->get ( 'order', array (), 'array' ); $isAjax = $this->app->input->get ( 'ajax', null ); ArrayHelper::toInteger ( $cids ); ArrayHelper::toInteger ( $order ); $model = $this->getModel (); if (! $model->saveOrder ( $cids, $order )) { // Model set exceptions for something gone wrong, so enqueue exceptions and levels on application object then set redirect and exit $modelException = $model->getError ( null, false ); $this->app->enqueueMessage ( $modelException->getMessage (), $modelException->getErrorLevel () ); $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_ERROR_REORDER' ) ); return false; } // Manage the ajax call without a redirect HTTP if ($isAjax) { echo "1"; $this->app->close (); } $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_SUCCESS_REORDER' ) ); return true; } /** * Publishing entities * * @access public * @return bool */ public function publishEntities(): bool { // Access check if (! $this->allowEditState ( $this->option )) { $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_ERROR_ALERT_NOACCESS' ), 'notice' ); return false; } $cid = $this->app->input->get ( 'cid', array ( 0 ), 'array' ); $idEntity = ( int ) $cid [0]; $model = $this->getModel (); if (! $model->publishEntities ( $idEntity, $this->task )) { // Model set exceptions for something gone wrong, so enqueue exceptions and levels on application object then set redirect and exit $modelException = $model->getError ( null, false ); $this->app->enqueueMessage ( $modelException->getMessage (), $modelException->getErrorLevel () ); $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_ERROR_STATE_CHANGE' ) ); return false; } $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_SUCCESS_STATE_CHANGE' ) ); return true; } /** * Checkin entities * * @access public * @return bool */ public function checkin(): bool { // Access check if (! $this->user->authorise ( 'core.manage', 'com_checkin' )) { $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_ERROR_ALERT_NOACCESS' ), 'notice' ); return false; } $cid = $this->app->input->get ( 'cid', array ( 0 ), 'array' ); $id = ( int ) $cid [0]; // Load della model e checkin before exit $model = $this->getModel (); if (! $model->cancelEntity ( $id )) { // Model set exceptions for something gone wrong, so enqueue exceptions and levels on application object then set redirect and exit $modelException = $model->getError ( null, false ); $this->app->enqueueMessage ( $modelException->getMessage (), $modelException->getErrorLevel () ); } $this->setRedirect ( "index.php?option=" . $this->option . "&task=" . $this->name . ".display", Text::_ ( 'COM_JCHAT_CHECKEDIN_RECORD' ) ); return true; } /** * Constructor. * * @access protected * @param * array An optional associative array of configuration settings. * Recognized key values include 'name', 'default_task', * 'model_path', and * 'view_path' (this list is not meant to be comprehensive). * @since 1.5 */ public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null) { parent::__construct($config, $factory, $app, $input); $this->user = $app->getIdentity (); $this->document = $app->getDocument (); $this->option = $this->app->input->get ( 'option' ); $this->requestArray = &$_POST; } }
| ver. 1.1 | |
.
| PHP 8.4.18 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка