Page MenuHomeIn-Portal Phabricator

D180.id471.diff
No OneTemporary

File Metadata

Created
Mon, Jan 6, 5:17 AM

D180.id471.diff

Index: core/install/cache/class_structure.php
===================================================================
--- core/install/cache/class_structure.php
+++ core/install/cache/class_structure.php
@@ -36,6 +36,7 @@
'ConfigurationItem' => '/core/units/configuration/configuration.php',
'ConfigurationTagProcessor' => '/core/units/configuration/configuration_tag_processor.php',
'ConfigurationValidator' => '/core/units/configuration/configuration_validator.php',
+ 'ConsoleApplication' => '/core/kernel/console_application.php',
'ContentEventHandler' => '/core/units/content/content_eh.php',
'ContentTagProcessor' => '/core/units/content/content_tp.php',
'CoreUpgrades' => '/core/install/upgrades.php',
@@ -548,6 +549,13 @@
0 => 'kValidator',
),
),
+ 'ConsoleApplication' => array(
+ 'type' => 1,
+ 'modifiers' => 0,
+ 'extends' => array(
+ 0 => 'kApplication',
+ ),
+ ),
'ContentEventHandler' => array(
'type' => 1,
'modifiers' => 0,
Index: core/kernel/application.php
===================================================================
--- core/kernel/application.php
+++ core/kernel/application.php
@@ -216,6 +216,15 @@
public $siteDomain = null;
/**
+ * Web Request, that is being processed currently.
+ *
+ * Will be null, when no request is being processed (e.g. application is used from CLI).
+ *
+ * @var \Symfony\Component\HttpFoundation\Request
+ */
+ public $request;
+
+ /**
* Prevent kApplication class to be created directly, only via Instance method
*
* @access private
@@ -256,7 +265,14 @@
static $instance = false;
if ( !$instance ) {
- $class = defined('APPLICATION_CLASS') ? APPLICATION_CLASS : 'kApplication';
+ $class = APPLICATION_CLASS;
+
+ // FIXME: Handle case, when custom application class is specified.
+ if ( PHP_SAPI === 'cli' ) {
+ kUtil::includeOnce(__DIR__ . '/console_application.php');
+ $class = 'ConsoleApplication';
+ }
+
$instance = new $class();
}
@@ -279,6 +295,11 @@
return false;
}
+ // FIXME: Assign Symfony Request object provided from outside.
+ if ( PHP_SAPI !== 'cli' ) {
+ $this->request = true;
+ }
+
if ( preg_match('/utf-8/i', CHARSET) ) {
setlocale(LC_ALL, 'en_US.UTF-8');
mb_internal_encoding('UTF-8');
@@ -323,6 +344,43 @@
define('MOD_REWRITE', $this->ConfigValue('UseModRewrite') && !$this->isAdmin ? 1 : 0);
+ $this->initBeforeOnAfterConfigRead();
+
+ $site_timezone = $this->ConfigValue('Config_Site_Time');
+
+ if ( $site_timezone ) {
+ date_default_timezone_set($site_timezone);
+ }
+
+ // Must be called before AfterConfigRead, because current user should be available there.
+ $this->ValidateLogin();
+
+ $this->UnitConfigReader->AfterConfigRead();
+
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ $this->Debugger->appendTimestamp('Processed AfterConfigRead');
+ }
+
+ $this->initAfterOnAfterConfigRead();
+
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ $this->Debugger->profileFinish('kernel4_startup');
+ }
+
+ $this->InitDone = true;
+
+ $this->HandleEvent(new kEvent('adm:OnStartup'));
+
+ return true;
+ }
+
+ /**
+ * Handles initialization part before "OnAfterConfigRead" events are called.
+ *
+ * @return void
+ */
+ protected function initBeforeOnAfterConfigRead()
+ {
// start processing request
$this->HttpQuery = $this->recallObject('kHTTPQuery');
$this->HttpQuery->process();
@@ -345,24 +403,18 @@
$this->cacheManager->LoadApplicationCache();
- $site_timezone = $this->ConfigValue('Config_Site_Time');
-
- if ( $site_timezone ) {
- date_default_timezone_set($site_timezone);
- }
-
if ( defined('DEBUG_MODE') && $this->isDebugMode() ) {
$this->Debugger->appendTimestamp('Loaded cache and phrases');
}
+ }
- $this->ValidateLogin(); // must be called before AfterConfigRead, because current user should be available there
-
- $this->UnitConfigReader->AfterConfigRead();
-
- if ( defined('DEBUG_MODE') && $this->isDebugMode() ) {
- $this->Debugger->appendTimestamp('Processed AfterConfigRead');
- }
-
+ /**
+ * Handles initialization part after "OnAfterConfigRead" events are called.
+ *
+ * @return void
+ */
+ protected function initAfterOnAfterConfigRead()
+ {
if ( $this->GetVar('m_cat_id') === false ) {
$this->SetVar('m_cat_id', 0);
}
@@ -376,16 +428,16 @@
if ( $visit_id !== false ) {
$this->SetVar('visits_id', $visit_id);
}
+ }
- if ( defined('DEBUG_MODE') && $this->isDebugMode() ) {
- $this->Debugger->profileFinish('kernel4_startup');
- }
-
- $this->InitDone = true;
-
- $this->HandleEvent(new kEvent('adm:OnStartup'));
-
- return true;
+ /**
+ * Detects if this is a web request.
+ *
+ * @return boolean
+ */
+ public function isWebRequest()
+ {
+ return isset($this->request);
}
/**
@@ -2450,7 +2502,7 @@
array_unshift($prefixes, $current_prefix);
}
- if ( $real_top ) {
+ if ( $real_top || !$this->isWebRequest() ) {
return $current_prefix;
}
@@ -2531,6 +2583,22 @@
}
/**
+ * Determines if access permissions should not be checked.
+ *
+ * @param integer|null $user_id User ID.
+ *
+ * @return boolean
+ */
+ public function permissionCheckingDisabled($user_id = null)
+ {
+ if ( !isset($user_id) ) {
+ $user_id = $this->RecallVar('user_id');
+ }
+
+ return $user_id == USER_ROOT;
+ }
+
+ /**
* Check current user permissions based on it's group permissions in specified category
*
* @param string $name permission name
Index: core/kernel/console_application.php
===================================================================
--- /dev/null
+++ core/kernel/console_application.php
@@ -0,0 +1,538 @@
+<?php
+
+class ConsoleApplication extends kApplication
+{
+
+ /**
+ * Store for query data emulation.
+ *
+ * @var Params
+ */
+ private $_queryStorage;
+
+ /**
+ * Allowed query vars.
+ *
+ * @var array
+ */
+ private $_allowedQueryVars = array(
+ 'pass_through',
+ 'passed',
+ 'all_passed',
+ 'm_lang',
+ 'm_theme',
+ 'm_cat_id',
+ 'm_cat_page',
+ 'm_opener',
+ 'm_wid',
+ 'lang.current_id',
+ 'theme.current_id',
+ 'admin',
+ );
+
+ /**
+ * Storage for session emulation.
+ *
+ * @var Params
+ */
+ private $_sessionStorage;
+
+ /**
+ * Allowed session vars.
+ *
+ * @var array
+ */
+ private $_allowedSessionVars = array(
+ 'curr_iso',
+ 'visit_id',
+ 'user_id',
+ );
+
+ /**
+ * Handles initialization part before "OnAfterConfigRead" events are called.
+ *
+ * @return void
+ */
+ protected function initBeforeOnAfterConfigRead()
+ {
+ $this->_queryStorage = $this->makeClass('Params');
+ $this->_sessionStorage = $this->makeClass('Params');
+
+ $this->SetVar('passed', 'm');
+ $this->SetVar('all_passed', 'm');
+ $this->SetVar('m_cat_page', 1);
+ $this->SetVar('m_opener', 's');
+
+ $this->StoreVar('user_id', USER_CLI);
+
+ $this->VerifyThemeId();
+ $this->VerifyLanguageId();
+ }
+
+ /**
+ * Returns site domain field. When none of site domains are found false is returned.
+ *
+ * @param string $field Field name.
+ * @param boolean $formatted Value should be formatted.
+ * @param string $format Format to be used.
+ *
+ * @return mixed
+ * @todo Move into separate module.
+ */
+ public function siteDomainField($field, $formatted = false, $format = null)
+ {
+ if ( !$this->isWebRequest() ) {
+ return false;
+ }
+
+ return parent::siteDomainField($field, $formatted, $format);
+ }
+
+ /**
+ * Returns current session id (SID)
+ *
+ * @return integer
+ */
+ public function GetSID()
+ {
+ // Used mostly for creating temp tables, that needs to be different in different process runs.
+ if ( !$this->isWebRequest() ) {
+ return 'cli' . getmypid();
+ }
+
+ return parent::GetSID();
+ }
+
+ /**
+ * Destroys current session
+ *
+ * @return void
+ * @see UserHelper::logoutUser()
+ */
+ public function DestroySession()
+ {
+ if ( !$this->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
+ parent::DestroySession();
+ }
+
+ /**
+ * Returns variable passed to the script as GET/POST/COOKIE
+ *
+ * @param string $name Name of variable to retrieve.
+ * @param mixed $default Default value returned in case if variable not present.
+ *
+ * @return mixed
+ */
+ public function GetVar($name, $default = false)
+ {
+ if ( !$this->isWebRequest() ) {
+ return $this->_queryStorage->Get($name, $default);
+ }
+
+ return parent::GetVar($name, $default);
+ }
+
+ /**
+ * Removes forceful escaping done to the variable upon Front-End submission.
+ *
+ * @param string|array $value Value.
+ *
+ * @return string|array
+ * @see kHttpQuery::StripSlashes
+ * @todo Temporary method for marking problematic places to take care of, when forceful escaping will be removed.
+ */
+ public function unescapeRequestVariable($value)
+ {
+ if ( !$this->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
+ return parent::unescapeRequestVariable($value);
+ }
+
+ /**
+ * Returns variable passed to the script as $type
+ *
+ * @param string $name Name of variable to retrieve.
+ * @param string $type Get/Post/Cookie.
+ * @param mixed $default Default value returned in case if variable not present.
+ *
+ * @return mixed
+ */
+ public function GetVarDirect($name, $type, $default = false)
+ {
+ if ( !$this->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
+ return parent::GetVarDirect($name, $type, $default);
+ }
+
+ /**
+ * Returns ALL variables passed to the script as GET/POST/COOKIE
+ *
+ * @return array
+ *
+ * @deprecated
+ */
+ public function GetVars()
+ {
+ if ( !$this->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
+ return parent::GetVars();
+ }
+
+ /**
+ * Set the variable 'as it was passed to the script through GET/POST/COOKIE'
+ *
+ * This could be useful to set the variable when you know that
+ * other objects would relay on variable passed from GET/POST/COOKIE
+ * or you could use SetVar() / GetVar() pairs to pass the values between different objects.<br>
+ *
+ * @param string $var Variable name to set.
+ * @param mixed $val Variable value.
+ *
+ * @return void
+ */
+ public function SetVar($var, $val)
+ {
+ if ( !$this->isWebRequest() ) {
+ $this->_queryStorage->Set($var, $val);
+
+ return;
+ }
+
+ parent::SetVar($var, $val);
+ }
+
+ /**
+ * Deletes kHTTPQuery variable
+ *
+ * @param string $var Variable name.
+ *
+ * @return void
+ * @todo Think about method name.
+ */
+ public function DeleteVar($var)
+ {
+ if ( !$this->isWebRequest() ) {
+ $this->_queryStorage->Remove($var);
+
+ return;
+ }
+
+ parent::DeleteVar($var);
+ }
+
+ /**
+ * Deletes Session variable
+ *
+ * @param string $var Variable name.
+ *
+ * @return void
+ */
+ public function RemoveVar($var)
+ {
+ if ( !$this->isWebRequest() ) {
+ $this->_sessionStorage->Remove($var);
+
+ return;
+ }
+
+ parent::RemoveVar($var);
+ }
+
+ /**
+ * Removes variable from persistent session
+ *
+ * @param string $var Variable name.
+ *
+ * @return void
+ */
+ public function RemovePersistentVar($var)
+ {
+ if ( !$this->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
+ parent::RemovePersistentVar($var);
+ }
+
+ /**
+ * Restores Session variable to it's db version
+ *
+ * @param string $var Variable name.
+ *
+ * @return void
+ */
+ public function RestoreVar($var)
+ {
+ if ( !$this->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
+ parent::RestoreVar($var);
+ }
+
+ /**
+ * Returns session variable value
+ *
+ * Return value of $var variable stored in Session. An optional default value could be passed as second parameter.
+ *
+ * @param string $var Variable name.
+ * @param mixed $default Default value to return if no $var variable found in session.
+ *
+ * @return mixed
+ * @see Session::RecallVar()
+ */
+ public function RecallVar($var, $default = false)
+ {
+ if ( !$this->isWebRequest() ) {
+ return $this->_sessionStorage->Get($var, $default);
+ }
+
+ return parent::RecallVar($var, $default);
+ }
+
+ /**
+ * Returns variable value from persistent session
+ *
+ * @param string $var Variable name.
+ * @param mixed $default Default value to return if no $var variable found in persistent session.
+ *
+ * @return mixed
+ * @see Session::RecallPersistentVar()
+ */
+ public function RecallPersistentVar($var, $default = false)
+ {
+ if ( !$this->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
+ return parent::RecallPersistentVar($var, $default);
+ }
+
+ /**
+ * Stores variable $val in session under name $var
+ * Use this method to store variable in session. Later this variable could be recalled.
+ *
+ * @param string $var Variable name.
+ * @param mixed $val Variable value.
+ * @param boolean $optional Is value optional.
+ *
+ * @return void
+ * @see kApplication::RecallVar()
+ */
+ public function StoreVar($var, $val, $optional = false)
+ {
+ if ( !$this->isWebRequest() ) {
+ $this->_sessionStorage->Set($var, $val);
+
+ return;
+ }
+
+ parent::StoreVar($var, $val, $optional);
+ }
+
+ /**
+ * Stores variable to persistent session
+ *
+ * @param string $var Variable name.
+ * @param mixed $val Variable value.
+ * @param boolean $optional Is value optional.
+ *
+ * @return void
+ */
+ public function StorePersistentVar($var, $val, $optional = false)
+ {
+ if ( !$this->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
+ parent::StorePersistentVar($var, $val, $optional);
+ }
+
+ /**
+ * Stores default value for session variable
+ *
+ * @param string $var Variable name.
+ * @param string $val Variable value.
+ * @param boolean $optional Is value optional.
+ *
+ * @return void
+ * @see Session::RecallVar()
+ * @see Session::StoreVar()
+ */
+ public function StoreVarDefault($var, $val, $optional = false)
+ {
+ if ( !$this->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
+ parent::StoreVarDefault($var, $val, $optional);
+ }
+
+ /**
+ * Links HTTP Query variable with session variable
+ *
+ * If variable $var is passed in HTTP Query it is stored in session for later use. If it's not passed it's
+ * recalled from session. This method could be used for making sure that GetVar will return query or session
+ * value for given variable, when query variable should overwrite session (and be stored there for later use).<br>
+ * This could be used for passing item's ID into popup with multiple tab -
+ * in popup script you just need to call LinkVar('id', 'current_id') before first use of GetVar('id').
+ * After that you can be sure that GetVar('id') will return passed id or id passed earlier and stored in session
+ *
+ * @param string $var HTTP Query (GPC) variable name.
+ * @param mixed $ses_var Session variable name.
+ * @param mixed $default Default variable value.
+ * @param boolean $optional Is value optional.
+ *
+ * @return void
+ */
+ public function LinkVar($var, $ses_var = null, $default = '', $optional = false)
+ {
+ if ( !$this->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
+ parent::LinkVar($var, $ses_var, $default, $optional);
+ }
+
+ /**
+ * Returns variable from HTTP Query, or from session if not passed in HTTP Query
+ * The same as LinkVar, but also returns the variable value taken from HTTP Query if passed, or
+ * from session if not passed. Returns the default value if variable does not exist in session
+ * and was not passed in HTTP Query
+ *
+ * @param string $var HTTP Query (GPC) variable name.
+ * @param mixed $ses_var Session variable name.
+ * @param mixed $default Default variable value.
+ *
+ * @return mixed
+ * @see LinkVar
+ */
+ public function GetLinkedVar($var, $ses_var = null, $default = '')
+ {
+ if ( !$this->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
+ return parent::GetLinkedVar($var, $ses_var, $default);
+ }
+
+ /**
+ * Checks if user is logged in, and creates
+ * user object if so. User object can be recalled
+ * later using "u.current" prefix_special. Also you may
+ * get user id by getting "u.current_id" variable.
+ *
+ * @return void
+ */
+ protected function ValidateLogin()
+ {
+ if ( $this->isWebRequest() ) {
+ parent::ValidateLogin();
+ }
+
+ // Do nothing for CLI requests.
+ }
+
+ /**
+ * Loads current user persistent session data
+ *
+ * @return void
+ */
+ public function LoadPersistentVars()
+ {
+ if ( !$this->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
+ parent::LoadPersistentVars();
+ }
+
+ /**
+ * Allows to check if user in this session is logged in or not
+ *
+ * @return boolean
+ */
+ public function LoggedIn()
+ {
+ if ( !$this->isWebRequest() ) {
+ return false;
+ }
+
+ return parent::LoggedIn();
+ }
+
+ /**
+ * Determines if access permissions should not be checked.
+ *
+ * @param integer|null $user_id User ID.
+ *
+ * @return boolean
+ */
+ public function permissionCheckingDisabled($user_id = null)
+ {
+ // Any user in CLI mode is allowed to do anything.
+ if ( !$this->isWebRequest() ) {
+ return true;
+ }
+
+ return parent::permissionCheckingDisabled($user_id);
+ }
+
+ /**
+ * Returns Window ID of passed prefix main prefix (in edit mode)
+ *
+ * @param string $prefix Prefix.
+ *
+ * @return integer
+ */
+ public function GetTopmostWid($prefix)
+ {
+ // No editing popups in CLI.
+ if ( !$this->isWebRequest() ) {
+ return '';
+ }
+
+ return parent::GetTopmostWid($prefix);
+ }
+
+ /**
+ * Checks, that given prefix is in temp mode
+ *
+ * @param string $prefix Prefix.
+ * @param string $special Special.
+ *
+ * @return boolean
+ */
+ public function IsTempMode($prefix, $special = '')
+ {
+ if ( !$this->isWebRequest() ) {
+ return false;
+ }
+
+ return parent::IsTempMode($prefix, $special);
+ }
+
+ /**
+ * Returns the client IP address.
+ *
+ * @return string The client IP address
+ */
+ public function getClientIp()
+ {
+ if ( !$this->isWebRequest() ) {
+ return '';
+ }
+
+ return parent::getClientIp();
+ }
+
+}
Index: core/kernel/db/cat_event_handler.php
===================================================================
--- core/kernel/db/cat_event_handler.php
+++ core/kernel/db/cat_event_handler.php
@@ -683,7 +683,7 @@
return;
}
- if ( $this->Application->RecallVar('user_id') == USER_ROOT ) {
+ if ( $this->Application->permissionCheckingDisabled() ) {
// for "root" CATEGORY.VIEW permission is checked for items lists too
$view_perm = 1;
}
@@ -1863,6 +1863,12 @@
// get PerPage (forced -> session -> config -> 10)
$object->SetPerPage($this->getPerPage($event));
+ if ( !$this->Application->isWebRequest() ) {
+ $object->SetPage(1);
+
+ return;
+ }
+
// main lists on Front-End have special get parameter for page
$page = $object->isMainList() ? $this->Application->GetVar('page') : false;
@@ -2752,8 +2758,13 @@
}
}
else {
- $sorting_settings = $this->getListSetting($event, 'Sortings');
- $sort_by = trim(getArrayValue($sorting_settings, 'Sort1') . ',' . getArrayValue($sorting_settings, 'Sort1_Dir'), ',');
+ if ( $this->Application->isWebRequest() ) {
+ $sorting_settings = $this->getListSetting($event, 'Sortings');
+ $sort_by = trim(getArrayValue($sorting_settings, 'Sort1') . ',' . getArrayValue($sorting_settings, 'Sort1_Dir'), ',');
+ }
+ else {
+ $sort_by = '';
+ }
if ( !$sort_by ) {
$event->setEventParam('sort_by', 'Relevance,desc|' . $default_sorting);
@@ -2861,14 +2872,16 @@
$config->addGrids($grid_data, $process_grid . 'ShowAll');
}
- // add options for CategoryId field (quick way to select item's primary category)
- $category_helper = $this->Application->recallObject('CategoryHelper');
- /* @var $category_helper CategoryHelper */
-
- $virtual_fields = $config->getVirtualFields();
- $virtual_fields['CategoryId']['default'] = (int)$this->Application->GetVar('m_cat_id');
- $virtual_fields['CategoryId']['options'] = $category_helper->getStructureTreeAsOptions();
- $config->setVirtualFields($virtual_fields);
+ if ( $this->Application->isWebRequest() ) {
+ // Add options for CategoryId field (quick way to select item's primary category).
+ $category_helper = $this->Application->recallObject('CategoryHelper');
+ /* @var $category_helper CategoryHelper */
+
+ $virtual_fields = $config->getVirtualFields();
+ $virtual_fields['CategoryId']['default'] = (int)$this->Application->GetVar('m_cat_id');
+ $virtual_fields['CategoryId']['options'] = $category_helper->getStructureTreeAsOptions();
+ $config->setVirtualFields($virtual_fields);
+ }
}
/**
Index: core/kernel/db/cat_tag_processor.php
===================================================================
--- core/kernel/db/cat_tag_processor.php
+++ core/kernel/db/cat_tag_processor.php
@@ -946,7 +946,7 @@
*/
function AllowedCategoriesJSON($params)
{
- if ( $this->Application->RecallVar('user_id') == USER_ROOT ) {
+ if ( $this->Application->permissionCheckingDisabled() ) {
$categories = true;
}
else {
@@ -962,4 +962,4 @@
return json_encode($categories);
}
- }
\ No newline at end of file
+ }
Index: core/kernel/db/db_event_handler.php
===================================================================
--- core/kernel/db/db_event_handler.php
+++ core/kernel/db/db_event_handler.php
@@ -236,6 +236,12 @@
return $main_object->GetDBField($event->getUnitConfig()->getIDField());
}
+ if ( !$this->Application->isWebRequest() ) {
+ throw new LogicException(
+ 'The "' . $event->getPrefixSpecial() . '" object can\'t be auto-loaded from CLI request.'
+ );
+ }
+
// 1. get id from post (used in admin)
$ret = $this->Application->GetVar($event->getPrefixSpecial(true) . '_id');
if ( ($ret !== false) && ($ret != '') ) {
@@ -277,6 +283,10 @@
*/
protected function StoreSelectedIDs(kEvent $event, $direct_ids = NULL)
{
+ if ( !$this->Application->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
$wid = $this->Application->GetTopmostWid($event->Prefix);
$session_name = rtrim($event->getPrefixSpecial() . '_selected_ids_' . $wid, '_');
@@ -349,6 +359,10 @@
*/
protected function getSelectedIDs(kEvent $event, $from_session = false)
{
+ if ( !$this->Application->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
if ( $from_session ) {
$wid = $this->Application->GetTopmostWid($event->Prefix);
$var_name = rtrim($event->getPrefixSpecial() . '_selected_ids_' . $wid, '_');
@@ -407,6 +421,10 @@
*/
protected function clearSelectedIDs(kEvent $event)
{
+ if ( !$this->Application->isWebRequest() ) {
+ throw new LogicException('Web Request related method "' . __METHOD__ . '" was called from CLI mode.');
+ }
+
$prefix_special = $event->getPrefixSpecial();
$ids = implode(',', $this->getSelectedIDs($event, true));
@@ -437,10 +455,13 @@
if ( $event->getEventParam('form_name') !== false ) {
$form_name = $event->getEventParam('form_name');
}
- else {
+ elseif ( $this->Application->isWebRequest() ) {
$request_forms = $this->Application->GetVar('forms', Array ());
$form_name = (string)getArrayValue($request_forms, $object->getPrefixSpecial());
}
+ else {
+ $form_name = null;
+ }
$object->Configure($event->getEventParam('populate_ml_fields') || $event->getUnitConfig()->getPopulateMlFields(), $form_name);
$this->PrepareObject($object, $event);
@@ -460,8 +481,18 @@
$this->Application->setEvent($event->getPrefixSpecial(), '');
- $save_event = $this->UseTempTables($event) && $this->Application->GetTopmostPrefix($event->Prefix) == $event->Prefix ? 'OnSave' : 'OnUpdate';
- $this->Application->SetVar($event->getPrefixSpecial() . '_SaveEvent', $save_event);
+ if ( $this->Application->isWebRequest() ) {
+ if ( $this->UseTempTables($event)
+ && $this->Application->GetTopmostPrefix($event->Prefix) == $event->Prefix
+ ) {
+ $save_event = 'OnSave';
+ }
+ else {
+ $save_event = 'OnUpdate';
+ }
+
+ $this->Application->SetVar($event->getPrefixSpecial() . '_SaveEvent', $save_event);
+ }
}
/**
@@ -545,15 +576,18 @@
$event->setEventParam('top_prefix', $this->Application->GetTopmostPrefix($event->Prefix, true));
$status_checked = false;
- if ( $user_id == USER_ROOT || $this->CheckPermission($event) ) {
- // don't autoload item, when user doesn't have view permission
+ if ( $this->Application->permissionCheckingDisabled($user_id) || $this->CheckPermission($event) ) {
+ // Don't autoload item, when user doesn't have view permission.
$this->LoadItem($event);
$status_checked = true;
$editing_mode = defined('EDITING_MODE') ? EDITING_MODE : false;
- if ( $user_id != USER_ROOT && !$this->Application->isAdmin && !($editing_mode || $this->checkItemStatus($event)) ) {
- // non-root user AND on front-end AND (not editing mode || incorrect status)
+ if ( !$this->Application->permissionCheckingDisabled($user_id)
+ && !$this->Application->isAdmin
+ && !($editing_mode || $this->checkItemStatus($event))
+ ) {
+ // Permissions are being checked AND on Front-End AND (not editing mode || incorrect status).
$perm_status = false;
}
}
@@ -638,7 +672,8 @@
$object->setParentEvent($parent_event);
}
- $object->BuildTables($event->Prefix, $this->getSelectedIDs($event));
+ $ids = $this->Application->isWebRequest() ? $this->getSelectedIDs($event) : array();
+ $object->BuildTables($event->Prefix, $ids);
}
/**
@@ -726,7 +761,10 @@
$object->linkToParent($this->getMainSpecial($event));
}
- $this->AddFilters($event);
+ if ( $this->Application->isWebRequest() ) {
+ $this->AddFilters($event);
+ }
+
$this->SetCustomQuery($event); // new!, use this for dynamic queries based on specials for ex.
$this->SetPagination($event);
$this->SetSorting($event);
@@ -878,6 +916,12 @@
// get PerPage (forced -> session -> config -> 10)
$object->SetPerPage($this->getPerPage($event));
+ if ( !$this->Application->isWebRequest() ) {
+ $object->SetPage(1);
+
+ return;
+ }
+
// main lists on Front-End have special get parameter for page
$page = $object->isMainList() ? $this->Application->GetVar('page') : false;
@@ -955,33 +999,35 @@
return $per_page;
}
- if ( !$per_page && $object->isMainList() ) {
- // main lists on Front-End have special get parameter for per-page
- $per_page = $this->Application->GetVar('per_page');
- }
+ if ( $this->Application->isWebRequest() ) {
+ if ( !$per_page && $object->isMainList() ) {
+ // Main lists on Front-End have special get parameter for per-page.
+ $per_page = $this->Application->GetVar('per_page');
+ }
- if ( !$per_page ) {
- // per-page is given in "env" variable for given prefix
- $per_page = $this->Application->GetVar($event->getPrefixSpecial() . '_PerPage');
- }
+ if ( !$per_page ) {
+ // Per-page is given in "env" variable for given prefix.
+ $per_page = $this->Application->GetVar($event->getPrefixSpecial() . '_PerPage');
+ }
- if ( !$per_page && $event->Special ) {
- // when not part of env, then variables like "prefix.special_PerPage" are
- // replaced (by PHP) with "prefix_special_PerPage", so check for that too
- $per_page = $this->Application->GetVar($event->getPrefixSpecial(true) . '_PerPage');
- }
+ if ( !$per_page && $event->Special ) {
+ // When not part of env, then variables like "prefix.special_PerPage" are
+ // replaced (by PHP) with "prefix_special_PerPage", so check for that too.
+ $per_page = $this->Application->GetVar($event->getPrefixSpecial(true) . '_PerPage');
+ }
- if ( !$object->isMainList() ) {
- // per-page given in env and not in main list
- $view_name = $this->Application->RecallVar($event->getPrefixSpecial() . '_current_view');
+ if ( !$object->isMainList() ) {
+ // Per-page given in env and not in main list.
+ $view_name = $this->Application->RecallVar($event->getPrefixSpecial() . '_current_view');
- if ( $per_page ) {
- // per-page found in request -> store in session and persistent session
- $this->setListSetting($event, 'PerPage', $per_page);
- }
- else {
- // per-page not found in request -> get from pesistent session (or session)
- $per_page = $this->getListSetting($event, 'PerPage');
+ if ( $per_page ) {
+ // Per-page found in request -> store in session and persistent session.
+ $this->setListSetting($event, 'PerPage', $per_page);
+ }
+ else {
+ // Per-page not found in request -> get from pesistent session (or session).
+ $per_page = $this->getListSetting($event, 'PerPage');
+ }
}
}
@@ -1018,41 +1064,44 @@
$object = $event->getObject();
/* @var $object kDBList */
- if ( $object->isMainList() ) {
- $sort_by = $this->Application->GetVar('sort_by');
- $cur_sort1 = $cur_sort1_dir = $cur_sort2 = $cur_sort2_dir = false;
+ $cur_sort1 = $cur_sort1_dir = $cur_sort2 = $cur_sort2_dir = false;
- if ( $sort_by ) {
- $sortings = explode('|', $sort_by);
- list ($cur_sort1, $cur_sort1_dir) = explode(',', $sortings[0]);
+ if ( $this->Application->isWebRequest() ) {
+ if ( $object->isMainList() ) {
+ $sort_by = $this->Application->GetVar('sort_by');
+
+ if ( $sort_by ) {
+ $sortings = explode('|', $sort_by);
+ list ($cur_sort1, $cur_sort1_dir) = explode(',', $sortings[0]);
- if ( isset($sortings[1]) ) {
- list ($cur_sort2, $cur_sort2_dir) = explode(',', $sortings[1]);
+ if ( isset($sortings[1]) ) {
+ list ($cur_sort2, $cur_sort2_dir) = explode(',', $sortings[1]);
+ }
}
}
- }
- else {
- $sorting_settings = $this->getListSetting($event, 'Sortings');
+ else {
+ $sorting_settings = $this->getListSetting($event, 'Sortings');
- $cur_sort1 = getArrayValue($sorting_settings, 'Sort1');
- $cur_sort1_dir = getArrayValue($sorting_settings, 'Sort1_Dir');
- $cur_sort2 = getArrayValue($sorting_settings, 'Sort2');
- $cur_sort2_dir = getArrayValue($sorting_settings, 'Sort2_Dir');
- }
+ $cur_sort1 = getArrayValue($sorting_settings, 'Sort1');
+ $cur_sort1_dir = getArrayValue($sorting_settings, 'Sort1_Dir');
+ $cur_sort2 = getArrayValue($sorting_settings, 'Sort2');
+ $cur_sort2_dir = getArrayValue($sorting_settings, 'Sort2_Dir');
+ }
- $tag_sort_by = $event->getEventParam('sort_by');
+ $tag_sort_by = $event->getEventParam('sort_by');
- if ( $tag_sort_by ) {
- if ( $tag_sort_by == 'random' ) {
- $object->AddOrderField('RAND()', '');
- }
- else {
- // multiple sortings could be specified at once
- $tag_sort_by = explode('|', $tag_sort_by);
+ if ( $tag_sort_by ) {
+ if ( $tag_sort_by == 'random' ) {
+ $object->AddOrderField('RAND()', '');
+ }
+ else {
+ // Multiple sortings could be specified at once.
+ $tag_sort_by = explode('|', $tag_sort_by);
- foreach ($tag_sort_by as $sorting_element) {
- list ($by, $dir) = explode(',', $sorting_element);
- $object->AddOrderField($by, $dir);
+ foreach ( $tag_sort_by as $sorting_element ) {
+ list ($by, $dir) = explode(',', $sorting_element);
+ $object->AddOrderField($by, $dir);
+ }
}
}
}
@@ -1883,6 +1932,11 @@
*/
public function SaveLoggedChanges($changes_var_name, $save = true)
{
+ // Nothing needs to be saved > exit immediately.
+ if ( !$save ) {
+ return;
+ }
+
// 1. get changes, that were made
$changes = $this->Application->RecallVar($changes_var_name);
$changes = $changes ? unserialize($changes) : Array ();
Index: core/kernel/db/db_tag_processor.php
===================================================================
--- core/kernel/db/db_tag_processor.php
+++ core/kernel/db/db_tag_processor.php
@@ -486,8 +486,12 @@
$block_empty_cell_params['name'] = $this->SelectParam($params, 'empty_cell_render_as,block_empty_cell,empty_cell_block');
$i = 0;
+ $is_web_request = $this->Application->isWebRequest();
+
+ if ( $is_web_request ) {
+ $backup_id = $this->Application->GetVar($this->Prefix . '_id');
+ }
- $backup_id = $this->Application->GetVar($this->Prefix . '_id');
$displayed = Array ();
$column_number = 1;
@@ -496,8 +500,12 @@
$limit = isset($params['limit']) ? $params['limit'] : false;
while (!$list->EOL() && (!$limit || $i<$limit)) {
- $this->Application->SetVar($this->getPrefixSpecial() . '_id', $list->GetDBField($id_field)); // for edit/delete links using GET
- $this->Application->SetVar($this->Prefix . '_id', $list->GetDBField($id_field));
+ if ( $is_web_request ) {
+ // For edit/delete links using GET.
+ $this->Application->SetVar($this->getPrefixSpecial() . '_id', $list->GetDBField($id_field));
+ $this->Application->SetVar($this->Prefix . '_id', $list->GetDBField($id_field));
+ }
+
$block_params['is_last'] = ($i == $list->GetSelectedCount() - 1);
$block_params['last_row'] = ($i + (($i + 1) % $columns) >= $list->GetSelectedCount() - 1);
$block_params['not_last'] = !$block_params['is_last']; // for front-end
@@ -575,19 +583,22 @@
$i++;
}
- $cur_displayed = $this->Application->GetVar($this->Prefix . '_displayed_ids');
- if ( !$cur_displayed ) {
- $cur_displayed = Array ();
- }
- else {
- $cur_displayed = explode(',', $cur_displayed);
- }
+ if ( $is_web_request ) {
+ $cur_displayed = $this->Application->GetVar($this->Prefix . '_displayed_ids');
+
+ if ( !$cur_displayed ) {
+ $cur_displayed = array();
+ }
+ else {
+ $cur_displayed = explode(',', $cur_displayed);
+ }
- $displayed = array_unique(array_merge($displayed, $cur_displayed));
- $this->Application->SetVar($this->Prefix . '_displayed_ids', implode(',', $displayed));
+ $displayed = array_unique(array_merge($displayed, $cur_displayed));
+ $this->Application->SetVar($this->Prefix . '_displayed_ids', implode(',', $displayed));
- $this->Application->SetVar($this->Prefix . '_id', $backup_id);
- $this->Application->SetVar($this->getPrefixSpecial() . '_id', '');
+ $this->Application->SetVar($this->Prefix . '_id', $backup_id);
+ $this->Application->SetVar($this->getPrefixSpecial() . '_id', '');
+ }
if ( isset($params['more_link_render_as']) ) {
$block_params = $params;
Index: core/kernel/db/dbitem.php
===================================================================
--- core/kernel/db/dbitem.php
+++ core/kernel/db/dbitem.php
@@ -568,6 +568,10 @@
*/
public function getPendingActions($id = null)
{
+ if ( !$this->Application->isWebRequest() ) {
+ return array();
+ }
+
if ( !isset($id) ) {
$id = $this->GetID();
}
@@ -601,6 +605,10 @@
*/
public function setPendingActions($new_pending_actions = null, $id = null)
{
+ if ( !$this->Application->isWebRequest() ) {
+ return;
+ }
+
if ( !isset($new_pending_actions) ) {
$new_pending_actions = Array ();
}
@@ -1188,6 +1196,10 @@
*/
public function setModifiedFlag($mode = null)
{
+ if ( !$this->Application->isWebRequest() ) {
+ return;
+ }
+
$main_prefix = $this->Application->GetTopmostPrefix($this->Prefix);
$this->Application->StoreVar($main_prefix . '_modified', '1', true); // true for optional
@@ -1212,6 +1224,10 @@
*/
public function ShouldLogChanges($log_changes = null)
{
+ if ( !$this->Application->isWebRequest() ) {
+ return false;
+ }
+
$config = $this->getUnitConfig();
if ( !isset($log_changes) ) {
Index: core/kernel/kbase.php
===================================================================
--- core/kernel/kbase.php
+++ core/kernel/kbase.php
@@ -687,7 +687,7 @@
$allowed_modifiers[] = 'upload_dir';
}
- if ( !isset($field_modifiers) ) {
+ if ( !isset($field_modifiers) && $this->Application->isWebRequest() ) {
$field_modifiers = $this->Application->GetVar('field_modifiers');
if ( !$field_modifiers ) {
Index: core/kernel/managers/cache_manager.php
===================================================================
--- core/kernel/managers/cache_manager.php
+++ core/kernel/managers/cache_manager.php
@@ -340,7 +340,12 @@
$this->getToCache()
);
- $cache_rebuild_by = SERVER_NAME . ' (' . $this->Application->getClientIp() . ') - ' . date('d/m/Y H:i:s');
+ if ( $this->Application->isWebRequest() ) {
+ $cache_rebuild_by = SERVER_NAME . ' (' . $this->Application->getClientIp() . ') - ' . date('d/m/Y H:i:s');
+ }
+ else {
+ $cache_rebuild_by = 'CLI - ' . date('d/m/Y H:i:s');
+ }
if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
$this->Application->setCache('master:configs_parsed', serialize($cache));
Index: core/kernel/managers/hook_manager.php
===================================================================
--- core/kernel/managers/hook_manager.php
+++ core/kernel/managers/hook_manager.php
@@ -139,6 +139,8 @@
return ;
}
+ $is_web_request = $this->Application->isWebRequest();
+
foreach ($hooks as $hook) {
if ($hook['DoSpecial'] == '*') {
// use same special as master event
@@ -147,7 +149,7 @@
$prefix_special = rtrim($hook['DoPrefix'].'_'.$hook['DoSpecial'], '_');
- if ( $hook['Conditional'] && !$this->Application->GetVar($prefix_special) ) {
+ if ( $hook['Conditional'] && $is_web_request && !$this->Application->GetVar($prefix_special) ) {
continue;
}
@@ -182,4 +184,4 @@
return $hooks[ strtolower($event_key.'.'.$event->Name) ];
}
-}
\ No newline at end of file
+}
Index: core/kernel/managers/request_manager.php
===================================================================
--- core/kernel/managers/request_manager.php
+++ core/kernel/managers/request_manager.php
@@ -150,7 +150,7 @@
$event_handler = $this->Application->recallObject($event->Prefix . '_EventHandler');
/* @var $event_handler kEventHandler */
- if ( ($this->Application->RecallVar('user_id') == USER_ROOT) || $event_handler->CheckPermission($event) ) {
+ if ( $this->Application->permissionCheckingDisabled() || $event_handler->CheckPermission($event) ) {
$this->Application->HandleEvent($event);
$this->Application->notifyEventSubscribers($event);
}
@@ -475,4 +475,4 @@
$opener_stack->push($template, $params, $index_file);
$opener_stack->save();
}
-}
\ No newline at end of file
+}
Index: core/kernel/managers/scheduled_task_manager.php
===================================================================
--- core/kernel/managers/scheduled_task_manager.php
+++ core/kernel/managers/scheduled_task_manager.php
@@ -116,8 +116,12 @@
$events_source = $this->getAll();
- $user_id = $this->Application->RecallVar('user_id');
- $this->Application->StoreVar('user_id', USER_ROOT, true); // to prevent permission checking inside events, true for optional storage
+ if ( $this->Application->isWebRequest() ) {
+ $user_id = $this->Application->RecallVar('user_id');
+
+ // To prevent permission checking inside events, true for optional storage.
+ $this->Application->StoreVar('user_id', USER_ROOT, true);
+ }
$site_helper = $this->Application->recallObject('SiteHelper');
/* @var $site_helper SiteHelper */
@@ -148,7 +152,9 @@
$this->run($event_data);
}
- $this->Application->StoreVar('user_id', $user_id, $user_id == USER_GUEST);
+ if ( $this->Application->isWebRequest() ) {
+ $this->Application->StoreVar('user_id', $user_id, $user_id == USER_GUEST);
+ }
}
/**
Index: core/kernel/managers/url_manager.php
===================================================================
--- core/kernel/managers/url_manager.php
+++ core/kernel/managers/url_manager.php
@@ -130,8 +130,9 @@
unset($params['_auto_prefix_']); // this is parser-related param, do not need to pass it here
}
- $ssl = isset($params['__SSL__']) ? $params['__SSL__'] : NULL;
- if ( $ssl !== NULL ) {
+ $ssl = isset($params['__SSL__']) ? $params['__SSL__'] : null;
+
+ if ( $ssl !== null && $this->Application->isWebRequest() ) {
$session = $this->Application->recallObject('Session');
/* @var $session Session */
@@ -199,10 +200,12 @@
// append pass through variables to each link to be build
$params = array_merge($this->getPassThroughVariables($params), $params);
- $session = $this->Application->recallObject('Session');
+ if ( $this->Application->isWebRequest() ) {
+ $session = $this->Application->recallObject('Session');
- if ( $session->NeedQueryString() && !$force_no_sid ) {
- $params['sid'] = $this->Application->GetSID();
+ if ( $session->NeedQueryString() && !$force_no_sid ) {
+ $params['sid'] = $this->Application->GetSID();
+ }
}
if ( $force_rewrite || ($this->Application->RewriteURLs($ssl) && $rewrite) ) {
@@ -524,4 +527,4 @@
$this->Application->Done();
exit;
}
-}
\ No newline at end of file
+}
Index: core/kernel/processors/main_processor.php
===================================================================
--- core/kernel/processors/main_processor.php
+++ core/kernel/processors/main_processor.php
@@ -20,6 +20,10 @@
{
parent::__construct();
+ if ( !$this->Application->isWebRequest() ) {
+ return;
+ }
+
$actions = $this->Application->recallObject('kActions');
/* @var $actions Params */
@@ -1289,4 +1293,16 @@
return false;
}
+ /**
+ * Determines if this is the Web Request.
+ *
+ * @param array $params Tag params.
+ *
+ * @return string
+ */
+ protected function IsWebRequest(array $params)
+ {
+ return $this->Application->isWebRequest();
+ }
+
}
Index: core/kernel/session/session.php
===================================================================
--- core/kernel/session/session.php
+++ core/kernel/session/session.php
@@ -248,10 +248,6 @@
{
parent::Init($prefix, $special);
- if ( php_sapi_name() == 'cli' ) {
- $this->SetMode(self::smGET_ONLY);
- }
-
$this->CheckIfCookiesAreOn();
$this->Checkers = Array();
Index: core/kernel/startup.php
===================================================================
--- core/kernel/startup.php
+++ core/kernel/startup.php
@@ -203,3 +203,4 @@
// system users
define('USER_ROOT', -1);
define('USER_GUEST', -2);
+ define('USER_CLI', -3);
Index: core/kernel/utility/email.php
===================================================================
--- core/kernel/utility/email.php
+++ core/kernel/utility/email.php
@@ -744,9 +744,8 @@
$language_id = $restore ? $prev_language_id : $this->params['language_id'];
$this->Application->SetVar('m_lang', $language_id);
- $language = $this->Application->recallObject('lang.current');
- /* @var $language LanguagesItem */
-
+ /** @var LanguagesItem $language */
+ $language = $this->Application->recallObject('lang.current', null, array('skip_autoload' => true));
$language->Load($language_id);
$this->Application->Phrases->LanguageId = $language_id;
Index: core/kernel/utility/formatters/multilang_formatter.php
===================================================================
--- core/kernel/utility/formatters/multilang_formatter.php
+++ core/kernel/utility/formatters/multilang_formatter.php
@@ -251,7 +251,14 @@
$lang = $this->Application->GetVar('m_lang');
$def_lang = $this->Application->GetDefaultLanguageId();
- if ( !$this->Application->GetVar('allow_translation') && ($lang != $def_lang) && $object->isRequired($field) ) {
+ if ( $this->Application->isWebRequest() ) {
+ $allow_translation = $this->Application->GetVar('allow_translation');
+ }
+ else {
+ $allow_translation = false;
+ }
+
+ if ( !$allow_translation && ($lang != $def_lang) && $object->isRequired($field) ) {
$def_lang_field = 'l' . $def_lang . '_' . $master_field;
if ( !$object->ValidateRequired($def_lang_field, $options) ) {
@@ -313,4 +320,4 @@
return $value;
}
-}
\ No newline at end of file
+}
Index: core/kernel/utility/logger.php
===================================================================
--- core/kernel/utility/logger.php
+++ core/kernel/utility/logger.php
@@ -120,14 +120,9 @@
const LI_ADMIN = 2;
/**
- * Log interface: Cron (Front)
+ * Log interface: CLI
*/
- const LI_CRON_FRONT = 3;
-
- /**
- * Log interface: Cron (Admin)
- */
- const LI_CRON_ADMIN = 4;
+ const LI_CLI = 3;
/**
* Log interface: API
@@ -310,16 +305,19 @@
'LogNotificationStatus' => self::LNS_DISABLED,
);
- if ( $this->Application->isAdmin ) {
- $this->_logRecord['LogInterface'] = defined('CRON') && CRON ? self::LI_CRON_ADMIN : self::LI_ADMIN;
+ if ( $this->Application->isWebRequest() ) {
+ $this->_logRecord['LogInterface'] = $this->Application->isAdmin ? self::LI_ADMIN : self::LI_FRONT;
}
else {
- $this->_logRecord['LogInterface'] = defined('CRON') && CRON ? self::LI_CRON_FRONT : self::LI_FRONT;
+ $this->_logRecord['LogInterface'] = self::LI_CLI;
}
if ( $this->Application->InitDone ) {
$this->_logRecord['LogUserId'] = $this->Application->RecallVar('user_id');
- $this->_logRecord['LogSessionKey'] = $this->Application->GetSID();
+
+ if ( $this->Application->isWebRequest() ) {
+ $this->_logRecord['LogSessionKey'] = $this->Application->GetSID();
+ }
}
return $this;
Index: core/units/admin/admin_events_handler.php
===================================================================
--- core/units/admin/admin_events_handler.php
+++ core/units/admin/admin_events_handler.php
@@ -196,7 +196,7 @@
$this->Application->DeleteUnitCache();
- if ( $this->Application->GetVar('validate_configs') ) {
+ if ( $this->Application->isWebRequest() && $this->Application->GetVar('validate_configs') ) {
$event->SetRedirectParam('validate_configs', 1);
}
Index: core/units/categories/categories_event_handler.php
===================================================================
--- core/units/categories/categories_event_handler.php
+++ core/units/categories/categories_event_handler.php
@@ -565,7 +565,7 @@
return;
}
- if ( $this->Application->RecallVar('user_id') == USER_ROOT ) {
+ if ( $this->Application->permissionCheckingDisabled() ) {
// for "root" CATEGORY.VIEW permission is checked for items lists too
$view_perm = 1;
}
@@ -1550,7 +1550,7 @@
{
parent::SetPagination($event);
- if ( !$this->Application->isAdmin ) {
+ if ( !$this->Application->isAdmin && $this->Application->isWebRequest() ) {
$page_var = $event->getEventParam('page_var');
if ( $page_var !== false ) {
@@ -1683,8 +1683,13 @@
}
}
else {
- $sorting_settings = $this->getListSetting($event, 'Sortings');
- $sort_by = trim(getArrayValue($sorting_settings, 'Sort1') . ',' . getArrayValue($sorting_settings, 'Sort1_Dir'), ',');
+ if ( $this->Application->isWebRequest() ) {
+ $sorting_settings = $this->getListSetting($event, 'Sortings');
+ $sort_by = trim(getArrayValue($sorting_settings, 'Sort1') . ',' . getArrayValue($sorting_settings, 'Sort1_Dir'), ',');
+ }
+ else {
+ $sort_by = '';
+ }
if ( !$sort_by ) {
$event->setEventParam('sort_by', 'Relevance,desc|' . $default_sorting);
@@ -2209,25 +2214,33 @@
)
));
- // prepare structure dropdown
- $category_helper = $this->Application->recallObject('CategoryHelper');
- /* @var $category_helper CategoryHelper */
+ if ( $this->Application->isWebRequest() ) {
+ $category_helper = $this->Application->recallObject('CategoryHelper');
+ /* @var $category_helper CategoryHelper */
- $fields = $config->getFields();
+ $fields = $config->getFields();
- $fields['ParentId']['default'] = (int)$this->Application->GetVar('m_cat_id');
- $fields['ParentId']['options'] = $category_helper->getStructureTreeAsOptions();
+ // Prepare structure dropdown.
+ $fields['ParentId']['default'] = (int)$this->Application->GetVar('m_cat_id');
+ $fields['ParentId']['options'] = $category_helper->getStructureTreeAsOptions();
- // limit design list by theme
- $theme_id = $this->_getCurrentThemeId();
- $design_sql = $fields['Template']['options_sql'];
- $design_sql = str_replace('(tf.FilePath = "/designs")', '(' . implode(' OR ', $this->getDesignFolders()) . ')' . ' AND (t.ThemeId = ' . $theme_id . ')', $design_sql);
- $fields['Template']['options_sql'] = $design_sql;
+ // Limit design list by theme.
+ $theme_id = $this->_getCurrentThemeId();
+ $design_sql = $fields['Template']['options_sql'];
+ $design_sql = str_replace(
+ '(tf.FilePath = "/designs")',
+ '(' . implode(' OR ', $this->getDesignFolders()) . ') AND (t.ThemeId = ' . $theme_id . ')',
+ $design_sql
+ );
+ $fields['Template']['options_sql'] = $design_sql;
- // adds "Inherit From Parent" option to "Template" field
- $fields['Template']['options'] = Array (CATEGORY_TEMPLATE_INHERIT => $this->Application->Phrase('la_opt_InheritFromParent'));
+ // Adds "Inherit From Parent" option to "Template" field.
+ $fields['Template']['options'] = array(
+ CATEGORY_TEMPLATE_INHERIT => $this->Application->Phrase('la_opt_InheritFromParent'),
+ );
- $config->setFields($fields);
+ $config->setFields($fields);
+ }
if ($this->Application->isAdmin) {
// don't sort by Front-End sorting fields
Index: core/units/categories/categories_tag_processor.php
===================================================================
--- core/units/categories/categories_tag_processor.php
+++ core/units/categories/categories_tag_processor.php
@@ -2213,7 +2213,7 @@
*/
function AllowedCategoriesJSON($params)
{
- if ($this->Application->RecallVar('user_id') == USER_ROOT) {
+ if ( $this->Application->permissionCheckingDisabled() ) {
$categories = true;
}
else {
Index: core/units/email_templates/email_template_eh.php
===================================================================
--- core/units/email_templates/email_template_eh.php
+++ core/units/email_templates/email_template_eh.php
@@ -243,7 +243,7 @@
$ml_helper->replaceMLCalculatedFields($event);
- if ( $this->Application->GetVar('regional') ) {
+ if ( $this->Application->isWebRequest() && $this->Application->GetVar('regional') ) {
$config->setPopulateMlFields(true);
}
}
Index: core/units/forms/form_submissions/form_submissions_eh.php
===================================================================
--- core/units/forms/form_submissions/form_submissions_eh.php
+++ core/units/forms/form_submissions/form_submissions_eh.php
@@ -83,6 +83,10 @@
protected function OnBuildFormFields(kEvent $event)
{
+ if ( !$this->Application->isWebRequest() ) {
+ return;
+ }
+
$form_id = $this->Application->GetVar('form_id');
if ( !$form_id ) {
Index: core/units/helpers/file_helper.php
===================================================================
--- core/units/helpers/file_helper.php
+++ core/units/helpers/file_helper.php
@@ -139,7 +139,13 @@
*/
public function createItemFiles($prefix, $is_image = false)
{
- $items_info = $this->Application->GetVar($prefix);
+ if ( $this->Application->isWebRequest() ) {
+ $items_info = $this->Application->GetVar($prefix);
+ }
+ else {
+ $items_info = false;
+ }
+
if ($items_info) {
list (, $fields_values) = each($items_info);
$this->createUploadFields($prefix, $fields_values, $is_image);
Index: core/units/helpers/permissions_helper.php
===================================================================
--- core/units/helpers/permissions_helper.php
+++ core/units/helpers/permissions_helper.php
@@ -584,8 +584,7 @@
{
$user_id = (int)$user_id;
- if ( $user_id == USER_ROOT ) {
- // "root" is allowed anywhere
+ if ( $this->Application->permissionCheckingDisabled($user_id) ) {
return substr($name, -5) == '.deny' || $name == 'SYSTEM_ACCESS.READONLY' ? 0 : 1;
}
@@ -844,4 +843,4 @@
return 0;
}
- }
\ No newline at end of file
+ }
Index: core/units/helpers/upload_helper.php
===================================================================
--- core/units/helpers/upload_helper.php
+++ core/units/helpers/upload_helper.php
@@ -137,7 +137,7 @@
$admin_session = $this->Application->recallObject('Session.admin');
/* @var $admin_session Session */
- if ( $admin_session->RecallVar('user_id') == USER_ROOT ) {
+ if ( $this->Application->permissionCheckingDisabled($admin_session->RecallVar('user_id')) ) {
return true;
}
Index: core/units/languages/languages_event_handler.php
===================================================================
--- core/units/languages/languages_event_handler.php
+++ core/units/languages/languages_event_handler.php
@@ -96,6 +96,8 @@
$this->Application->SetVar('m_lang', $language_id);
$this->Application->SetVar($event->getPrefixSpecial() . '_id', $language_id);
+
+ return $language_id;
}
return parent::getPassedID($event);
Index: core/units/logs/system_logs/system_logs_config.php
===================================================================
--- core/units/logs/system_logs/system_logs_config.php
+++ core/units/logs/system_logs/system_logs_config.php
@@ -144,8 +144,7 @@
'formatter' => 'kOptionsFormatter', 'options' => Array (
kLogger::LI_FRONT => 'Front',
kLogger::LI_ADMIN => 'Admin',
- kLogger::LI_CRON_FRONT => 'Cron (Front)',
- kLogger::LI_CRON_ADMIN => 'Cron (Admin)',
+ kLogger::LI_CLI => 'CLI',
kLogger::LI_API => 'API',
),
'not_null' => 1, 'default' => 0
@@ -202,4 +201,4 @@
),
),
),
-);
\ No newline at end of file
+);
Index: core/units/modules/modules_event_handler.php
===================================================================
--- core/units/modules/modules_event_handler.php
+++ core/units/modules/modules_event_handler.php
@@ -151,7 +151,7 @@
$new_modules = $modules_helper->getModules(kModulesHelper::NOT_INSTALLED);
- if ( !$new_modules || $this->Application->RecallVar('user_id') != USER_ROOT ) {
+ if ( !$new_modules || !$this->Application->permissionCheckingDisabled() ) {
return;
}
Index: core/units/modules/modules_tag_processor.php
===================================================================
--- core/units/modules/modules_tag_processor.php
+++ core/units/modules/modules_tag_processor.php
@@ -23,7 +23,7 @@
function _hasPrivileges()
{
- return $this->Application->RecallVar('user_id') == USER_ROOT;
+ return $this->Application->permissionCheckingDisabled();
}
function AlreadyInstalled($params)
Index: core/units/phrases/phrases_event_handler.php
===================================================================
--- core/units/phrases/phrases_event_handler.php
+++ core/units/phrases/phrases_event_handler.php
@@ -487,7 +487,7 @@
$ml_helper->replaceMLCalculatedFields($event);
- if ( $this->Application->GetVar('regional') ) {
+ if ( $this->Application->isWebRequest() && $this->Application->GetVar('regional') ) {
$event->getUnitConfig()->setPopulateMlFields(true);
}
}
Index: core/units/scheduled_tasks/scheduled_task_eh.php
===================================================================
--- core/units/scheduled_tasks/scheduled_task_eh.php
+++ core/units/scheduled_tasks/scheduled_task_eh.php
@@ -265,10 +265,10 @@
$config->setFields($fields);
}
- $cron_helper = $this->Application->recallObject('kCronHelper');
- /* @var $cron_helper kCronHelper */
-
- $cron_helper->initUnit($event->Prefix, 'RunSchedule');
-
+ if ( $this->Application->isWebRequest() ) {
+ /** @var kCronHelper $cron_helper */
+ $cron_helper = $this->Application->recallObject('kCronHelper');
+ $cron_helper->initUnit($event->Prefix, 'RunSchedule');
+ }
}
}
Index: core/units/themes/themes_eh.php
===================================================================
--- core/units/themes/themes_eh.php
+++ core/units/themes/themes_eh.php
@@ -87,6 +87,8 @@
$this->Application->SetVar('m_theme', $theme_id);
$this->Application->SetVar($event->getPrefixSpecial() . '_id', $theme_id);
+
+ return $theme_id;
}
return parent::getPassedID($event);
Index: core/units/users/users_event_handler.php
===================================================================
--- core/units/users/users_event_handler.php
+++ core/units/users/users_event_handler.php
@@ -247,7 +247,9 @@
return ;
}
- $this->Application->Session->DeleteExpired();
+ /** @var SessionStorage $session_storage */
+ $session_storage = $this->Application->recallObject('SessionStorage');
+ $session_storage->DeleteExpired();
}
/**
Index: in-portal
===================================================================
--- in-portal
+++ in-portal
@@ -20,7 +20,7 @@
$start = microtime(true);
-define('CRON', 1);
+define('CRON', 1); // Means 'used in CLI' (name kept for BC reasons).
define('INDEX_FILE', 'index.php');
define('DBG_SKIP_REPORTING', 1);
$_SERVER['REQUEST_URI'] = 'CRON';
@@ -31,11 +31,6 @@
$application =& kApplication::Instance();
$application->Init();
-
-// Assume user with all privileges, because nobody is doing authentication from CLI.
-$application->StoreVar('user_id', USER_ROOT, true);
-
$application->getConsoleApplication()->run();
-$application->Done();
$end = microtime(true);
Index: modules/custom/install.php
===================================================================
--- modules/custom/install.php
+++ modules/custom/install.php
@@ -27,7 +27,7 @@
$application =& kApplication::Instance();
$application->Init();
-if ( $application->RecallVar('user_id') != USER_ROOT ) {
+if ( !$application->permissionCheckingDisabled() ) {
die('restricted access!');
}
@@ -35,4 +35,4 @@
$toolkit->RunSQL('/' . $module_folder . '/install/install_data.sql');
$toolkit->ImportLanguage('/' . $module_folder . '/install/english');
-$toolkit->finalizeModuleInstall($module_folder, false);
\ No newline at end of file
+$toolkit->finalizeModuleInstall($module_folder, false);
Index: modules/in-bulletin/install.php
===================================================================
--- modules/in-bulletin/install.php
+++ modules/in-bulletin/install.php
@@ -39,7 +39,7 @@
$application =& kApplication::Instance();
$application->Init();
-if ( $application->RecallVar('user_id') != USER_ROOT ) {
+if ( !$application->permissionCheckingDisabled() ) {
die('restricted access!');
}
Index: modules/in-bulletin/units/posts/post_eh.php
===================================================================
--- modules/in-bulletin/units/posts/post_eh.php
+++ modules/in-bulletin/units/posts/post_eh.php
@@ -399,6 +399,10 @@
{
parent::OnAfterConfigRead($event);
+ if ( !$this->Application->LoggedIn() ) {
+ return;
+ }
+
$config = $event->getUnitConfig();
$virtual_fields = $config->getVirtualFields();
@@ -451,4 +455,4 @@
$object->SetDBField('PostingText', '[quote id=' . $reply_to . ']' . $source_post->GetDBField('PostingText') . '[/quote]');
}
}
- }
\ No newline at end of file
+ }
Index: modules/in-bulletin/units/private_messages/private_message_eh.php
===================================================================
--- modules/in-bulletin/units/private_messages/private_message_eh.php
+++ modules/in-bulletin/units/private_messages/private_message_eh.php
@@ -236,6 +236,10 @@
{
parent::OnAfterConfigRead($event);
+ if ( !$this->Application->LoggedIn() ) {
+ return;
+ }
+
$config = $event->getUnitConfig();
$virtual_fields = $config->getVirtualFields();
Index: modules/in-bulletin/units/topics/topics_event_handler.php
===================================================================
--- modules/in-bulletin/units/topics/topics_event_handler.php
+++ modules/in-bulletin/units/topics/topics_event_handler.php
@@ -217,6 +217,10 @@
{
parent::OnAfterConfigRead($event);
+ if ( !$this->Application->LoggedIn() ) {
+ return;
+ }
+
$config = $event->getUnitConfig();
$fields = $config->getFields();
@@ -303,4 +307,4 @@
$manager->subscribe();
}
}
- }
\ No newline at end of file
+ }
Index: modules/in-commerce/install.php
===================================================================
--- modules/in-commerce/install.php
+++ modules/in-commerce/install.php
@@ -38,7 +38,7 @@
$application =& kApplication::Instance();
$application->Init();
-if ( $application->RecallVar('user_id') != USER_ROOT ) {
+if ( !$application->permissionCheckingDisabled() ) {
die('restricted access!');
}
Index: modules/in-commerce/units/addresses/addresses_event_handler.php
===================================================================
--- modules/in-commerce/units/addresses/addresses_event_handler.php
+++ modules/in-commerce/units/addresses/addresses_event_handler.php
@@ -330,7 +330,8 @@
*/
protected function checkItemStatus(kEvent $event)
{
- if ( $this->Application->isAdminUser ) {
+ // Check for Web Request here, because method is called directly from OnBefore/OnAfter events.
+ if ( $this->Application->isAdminUser || !$this->Application->isWebRequest() ) {
return true;
}
@@ -455,4 +456,4 @@
)
));
}
- }
\ No newline at end of file
+ }
Index: modules/in-commerce/units/orders/orders_event_handler.php
===================================================================
--- modules/in-commerce/units/orders/orders_event_handler.php
+++ modules/in-commerce/units/orders/orders_event_handler.php
@@ -3712,7 +3712,7 @@
$fields['BillingCountry']['default'] = $site_helper->getDefaultCountry('Billing');
$fields['ShippingCountry']['default'] = $site_helper->getDefaultCountry('Shipping');
- if (!$this->Application->isAdminUser) {
+ if ( !$this->Application->isAdminUser && $this->Application->isWebRequest() ) {
$user_groups = explode(',', $this->Application->RecallVar('UserGroups'));
$default_group = $this->Application->ConfigValue('User_LoggedInGroup');
if (!in_array($default_group, $user_groups)){
Index: modules/in-commerce/units/reports/reports_event_handler.php
===================================================================
--- modules/in-commerce/units/reports/reports_event_handler.php
+++ modules/in-commerce/units/reports/reports_event_handler.php
@@ -334,6 +334,10 @@
function OnUpdateConfig(kEvent $event)
{
+ if ( !$this->Application->isWebRequest() ) {
+ return;
+ }
+
$report = $this->Application->RecallVar('report_options');
if ( !$report ) {
Index: modules/in-link/install.php
===================================================================
--- modules/in-link/install.php
+++ modules/in-link/install.php
@@ -39,7 +39,7 @@
$application =& kApplication::Instance();
$application->Init();
-if ( $application->RecallVar('user_id') != USER_ROOT ) {
+if ( !$application->permissionCheckingDisabled() ) {
die('restricted access!');
}
Index: modules/in-link/units/link_validation/link_validation_eh.php
===================================================================
--- modules/in-link/units/link_validation/link_validation_eh.php
+++ modules/in-link/units/link_validation/link_validation_eh.php
@@ -502,7 +502,7 @@
function OnPrepareLinkEditing($event)
{
// hook to OnAfterConfigRead instead of OnEdit, because fake ids should be available in CheckPermission
- if ( $this->Application->GetVar('l_event') != 'OnEdit' ) {
+ if ( !$this->Application->isWebRequest() || $this->Application->GetVar('l_event') != 'OnEdit' ) {
return;
}
@@ -582,4 +582,4 @@
));
}
- }
\ No newline at end of file
+ }
Index: modules/in-news/install.php
===================================================================
--- modules/in-news/install.php
+++ modules/in-news/install.php
@@ -39,7 +39,7 @@
$application =& kApplication::Instance();
$application->Init();
-if ( $application->RecallVar('user_id') != USER_ROOT ) {
+if ( !$application->permissionCheckingDisabled() ) {
die('restricted access!');
}

Event Timeline