/** * Sets a cookie with the current user hash * * @param bool $unsetCookie controls whether to remove the cookie */ public static function setUserHashCookie($unsetCookie = false) { $wwwDir = eZSys::wwwDir(); // On host based site accesses this can be empty, causing the cookie to be set for the current dir, // but we want it to be set for the whole eZ publish site $cookiePath = $wwwDir != '' ? $wwwDir : '/'; if (eZUser::isCurrentUserRegistered()) { setcookie('vuserhash', self::getUserHash($newSession), 0, $cookiePath); } elseif ($unsetCookie) { //removes cookie setcookie('vuserhash', '0', 1, $cookiePath); } }
static function enabled() { if (isset($GLOBALS['eZHTTPHeaderCustom'])) { return $GLOBALS['eZHTTPHeaderCustom']; } $ini = eZINI::instance(); if (!$ini->hasVariable('HTTPHeaderSettings', 'CustomHeader')) { $GLOBALS['eZHTTPHeaderCustom'] = false; } else { if ($ini->variable('HTTPHeaderSettings', 'CustomHeader') === 'enabled' && $ini->hasVariable('HTTPHeaderSettings', 'OnlyForAnonymous') && $ini->variable('HTTPHeaderSettings', 'OnlyForAnonymous') === 'enabled') { $GLOBALS['eZHTTPHeaderCustom'] = !eZUser::isCurrentUserRegistered(); } else { $GLOBALS['eZHTTPHeaderCustom'] = $ini->variable('HTTPHeaderSettings', 'CustomHeader') == 'enabled'; } } return $GLOBALS['eZHTTPHeaderCustom']; }
} else { if ($http->hasPostVariable("ContentObjectID")) { $objectID = $http->postVariable("ContentObjectID"); // Check which action to perform if ($http->hasPostVariable("ActionAddToBasket")) { $shopModule = eZModule::exists("shop"); $result = $shopModule->run("basket", array()); if (isset($result['content']) && $result['content']) { return $result; } else { $module->setExitStatus($shopModule->exitStatus()); $module->setRedirectURI($shopModule->redirectURI()); } } else { if ($http->hasPostVariable("ActionAddToWishList")) { if (!eZUser::isCurrentUserRegistered()) { return $module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel'); } $shopModule = eZModule::exists("shop"); $result = $shopModule->run("wishlist", array()); $module->setExitStatus($shopModule->exitStatus()); $module->setRedirectURI($shopModule->redirectURI()); } else { if ($http->hasPostVariable("ActionPreview")) { $user = eZUser::currentUser(); $object = eZContentObject::fetch($objectID); $module->redirectTo($module->functionURI('versionview') . '/' . $objectID . '/' . $object->attribute('current_version') . '/'); return; } else { if ($http->hasPostVariable("ActionRemove")) { $viewMode = $http->postVariable('ViewMode', 'full');
/** * Figures out if current user should be protected or not * based on if (s)he has a session and is logged in. * * @return bool */ protected static function shouldProtectUser() { if (!self::$isEnabled) { return false; } if (!eZSession::hasStarted()) { return false; } if (!eZUser::isCurrentUserRegistered()) { return false; } return true; }
function verifyAccountInformation() { return eZUser::isCurrentUserRegistered(); }
/** * Execution point for controller actions */ public function run() { if ($this->mobileDeviceDetect->isEnabled()) { $this->mobileDeviceDetect->process(); if ($this->mobileDeviceDetect->isMobileDevice()) { $this->mobileDeviceDetect->redirect(); } } ob_start(); $this->requestInit(); // send header information foreach (eZHTTPHeader::headerOverrideArray($this->uri) + array('Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT', 'Last-Modified' => gmdate('D, d M Y H:i:s') . ' GMT', 'Cache-Control' => 'no-cache, must-revalidate', 'Pragma' => 'no-cache', 'X-Powered-By' => eZPublishSDK::EDITION, 'Content-Type' => 'text/html; charset=' . $this->httpCharset, 'Served-by' => isset($_SERVER["SERVER_NAME"]) ? $_SERVER['SERVER_NAME'] : null, 'Content-language' => $this->languageCode) as $key => $value) { header($key . ': ' . $value); } try { $moduleResult = $this->dispatchLoop(); } catch (Exception $e) { $this->shutdown(); throw $e; } $ini = eZINI::instance(); /** * Ouput an is_logged_in cookie when users are logged in for use by http cache solutions. * * @deprecated As of 4.5, since 4.4 added lazy session support (init on use) */ if ($ini->variable("SiteAccessSettings", "CheckValidity") !== 'true') { $wwwDir = eZSys::wwwDir(); // On host based site accesses this can be empty, causing the cookie to be set for the current dir, // but we want it to be set for the whole eZ publish site $cookiePath = $wwwDir != '' ? $wwwDir : '/'; if (eZUser::isCurrentUserRegistered()) { // Only set the cookie if it doesnt exist. This way we are not constantly sending the set request in the headers. if (!isset($_COOKIE['is_logged_in']) || $_COOKIE['is_logged_in'] !== 'true') { setcookie('is_logged_in', 'true', 0, $cookiePath); } } else { if (isset($_COOKIE['is_logged_in'])) { setcookie('is_logged_in', false, 0, $cookiePath); } } } if ($this->module->exitStatus() == eZModule::STATUS_REDIRECT) { $this->shutdown(); return $this->redirect(); } $uiContextName = $this->module->uiContextName(); // Store the last URI for access history for login redirection // Only if user has session and only if there was no error or no redirects happen if (eZSession::hasStarted() && $this->module->exitStatus() == eZModule::STATUS_OK) { $currentURI = $this->completeRequestedURI; if (strlen($currentURI) > 0 && $currentURI[0] !== '/') { $currentURI = '/' . $currentURI; } $lastAccessedURI = ""; $lastAccessedViewURI = ""; $http = eZHTTPTool::instance(); // Fetched stored session variables if ($http->hasSessionVariable("LastAccessesURI")) { $lastAccessedViewURI = $http->sessionVariable("LastAccessesURI"); } if ($http->hasSessionVariable("LastAccessedModifyingURI")) { $lastAccessedURI = $http->sessionVariable("LastAccessedModifyingURI"); } // Update last accessed view page if ($currentURI != $lastAccessedViewURI && !in_array($uiContextName, array('edit', 'administration', 'ajax', 'browse', 'authentication'))) { $http->setSessionVariable("LastAccessesURI", $currentURI); } // Update last accessed non-view page if ($currentURI != $lastAccessedURI && $uiContextName != 'ajax') { $http->setSessionVariable("LastAccessedModifyingURI", $currentURI); } } eZDebug::addTimingPoint("Module end '" . $this->module->attribute('name') . "'"); if (!is_array($moduleResult)) { eZDebug::writeError('Module did not return proper result: ' . $this->module->attribute('name'), 'index.php'); $moduleResult = array(); $moduleResult['content'] = false; } if (!isset($moduleResult['ui_context'])) { $moduleResult['ui_context'] = $uiContextName; } $moduleResult['ui_component'] = $this->module->uiComponentName(); $moduleResult['is_mobile_device'] = $this->mobileDeviceDetect->isMobileDevice(); $moduleResult['mobile_device_alias'] = $this->mobileDeviceDetect->getUserAgentAlias(); $templateResult = null; eZDebug::setUseExternalCSS($this->siteBasics['external-css']); if ($this->siteBasics['show-page-layout']) { $tpl = eZTemplate::factory(); if ($tpl->hasVariable('node')) { $tpl->unsetVariable('node'); } if (!isset($moduleResult['path'])) { $moduleResult['path'] = false; } $moduleResult['uri'] = eZSys::requestURI(); $tpl->setVariable("module_result", $moduleResult); $meta = $ini->variable('SiteSettings', 'MetaDataArray'); if (!isset($meta['description'])) { $metaDescription = ""; if (isset($moduleResult['path']) && is_array($moduleResult['path'])) { foreach ($moduleResult['path'] as $pathPart) { if (isset($pathPart['text'])) { $metaDescription .= $pathPart['text'] . " "; } } } $meta['description'] = $metaDescription; } $this->site['uri'] = $this->oldURI; $this->site['redirect'] = false; $this->site['meta'] = $meta; $this->site['version'] = eZPublishSDK::version(); $this->site['page_title'] = $this->module->title(); $tpl->setVariable("site", $this->site); if ($ini->variable('DebugSettings', 'DisplayDebugWarnings') === 'enabled') { // Make sure any errors or warnings are reported if (isset($GLOBALS['eZDebugError']) && $GLOBALS['eZDebugError']) { eZAppendWarningItem(array('error' => array('type' => 'error', 'number' => 1, 'count' => $GLOBALS['eZDebugErrorCount']), 'identifier' => 'ezdebug-first-error', 'text' => ezpI18n::tr('index.php', 'Some errors occurred, see debug for more information.'))); } if (isset($GLOBALS['eZDebugWarning']) && $GLOBALS['eZDebugWarning']) { eZAppendWarningItem(array('error' => array('type' => 'warning', 'number' => 1, 'count' => $GLOBALS['eZDebugWarningCount']), 'identifier' => 'ezdebug-first-warning', 'text' => ezpI18n::tr('index.php', 'Some general warnings occured, see debug for more information.'))); } } if ($this->siteBasics['user-object-required']) { $currentUser = eZUser::currentUser(); $tpl->setVariable("current_user", $currentUser); $tpl->setVariable("anonymous_user_id", $ini->variable('UserSettings', 'AnonymousUserID')); } else { $tpl->setVariable("current_user", false); $tpl->setVariable("anonymous_user_id", false); } $tpl->setVariable("access_type", $this->access); $tpl->setVariable('warning_list', !empty($this->warningList) ? $this->warningList : false); $resource = "design:"; if (is_string($this->siteBasics['show-page-layout'])) { if (strpos($this->siteBasics['show-page-layout'], ":") !== false) { $resource = ""; } } else { $this->siteBasics['show-page-layout'] = "pagelayout.tpl"; } // Set the navigation part // Check for navigation part settings $navigationPartString = 'ezcontentnavigationpart'; if (isset($moduleResult['navigation_part'])) { $navigationPartString = $moduleResult['navigation_part']; // Fetch the navigation part } $navigationPart = eZNavigationPart::fetchPartByIdentifier($navigationPartString); $tpl->setVariable('navigation_part', $navigationPart); $tpl->setVariable('uri_string', $this->uri->uriString()); if (isset($moduleResult['requested_uri_string'])) { $tpl->setVariable('requested_uri_string', $moduleResult['requested_uri_string']); } else { $tpl->setVariable('requested_uri_string', $this->actualRequestedURI); } // Set UI context and component $tpl->setVariable('ui_context', $moduleResult['ui_context']); $tpl->setVariable('ui_component', $moduleResult['ui_component']); $templateResult = $tpl->fetch($resource . $this->siteBasics['show-page-layout']); } else { $templateResult = $moduleResult['content']; } eZDebug::addTimingPoint("Script end"); $content = trim(ob_get_clean()); ob_start(); eZDB::checkTransactionCounter(); eZDisplayResult($templateResult); $content .= ob_get_clean(); $this->shutdown(); return new ezpKernelResult($content, array('module_result' => $moduleResult)); }
/** * Do all time based operations on block pool such as rotation, updating * the queue, overflow as well as executes fetch interfaces. * * @static */ public static function update( $nodeArray = array() ) { // log in user as anonymous if another user is logged in if ( eZUser::isCurrentUserRegistered() ) { $loggedInUser = eZUser::currentUser(); $anonymousUserId = eZUser::anonymousId(); $anonymousUser = eZUser::fetch( $anonymousUserId ); eZUser::setCurrentlyLoggedInUser( $anonymousUser, $anonymousUserId ); unset( $anonymousUser, $anonymousUserId ); } include_once( 'kernel/classes/ezcontentcache.php' ); $ini = eZINI::instance( 'block.ini' ); $db = eZDB::instance(); // Remove the blocks and items for the block if marked for removal $res = $db->arrayQuery( "SELECT id FROM ezm_block WHERE is_removed=1" ); foreach ( $res as $row ) { $blockID = $row['id']; $db->begin(); $db->query( "DELETE FROM ezm_pool WHERE block_id='$blockID'" ); $db->query( "DELETE FROM ezm_block WHERE id='$blockID'" ); $db->commit(); } if ( !$nodeArray ) { // Update pool and pages for all nodes $res = $db->arrayQuery( "SELECT DISTINCT node_id FROM ezm_block" ); foreach ( $res as $row ) { $nodeArray[] = $row['node_id']; } } foreach ( $nodeArray as $nodeID ) { // a safety margin $delay = intval( eZINI::instance( 'ezflow.ini' )->variable( 'SafetyDelay', 'DelayInSeconds' ) ); $time = time() - $delay; $nodeChanged = false; $blocks = $db->arrayQuery( "SELECT * FROM ezm_block WHERE node_id=$nodeID" ); $blockByID = array(); // Determine the order of updating $correctOrder = array(); $next = array(); foreach ( $blocks as $block ) { $next[$block['id']] = trim( $block['overflow_id'] ); // Make sure that block ID does not any have spaces $blockByID[$block['id']] = $block; } $nextIDs = array_keys( $next ); foreach ( $nextIDs as $id ) { if ( in_array( $id, $correctOrder, true ) ) { continue; } if ( !$next[$id] ) { $correctOrder[] = $id; continue; } $subCorrectOrder = array( $id ); $currentID = $id; while ( ( $nextID = $next[$currentID] ) ) { if ( !in_array( $nextID, $nextIDs, true ) ) { eZDebug::writeWarning( "Overflow for $currentID is $nextID, but no such block was found for the given node", __METHOD__ ); break; } if ( in_array( $nextID, $subCorrectOrder, true ) ) { eZDebug::writeWarning( "Loop detected, ignoring ($nextID should be after $currentID and vice versa)", __METHOD__ ); break; } if ( in_array( $nextID, $correctOrder, true ) ) { break; } $subCorrectOrder[] = $nextID; $currentID = $nextID; } if ( !$nextID || !in_array( $nextID, $correctOrder, true ) ) { foreach( $subCorrectOrder as $element ) { $correctOrder[] = $element; } } else { $newCorrectOrder = array(); foreach( $correctOrder as $element ) { if ( $element === $nextID ) { foreach( $subCorrectOrder as $element2 ) { $newCorrectOrder[] = $element2; } } $newCorrectOrder[] = $element; } $correctOrder = $newCorrectOrder; } } // Loop through all block in determined order foreach ( $correctOrder as $blockID ) { if ( $blockByID[$blockID] ) { $block = $blockByID[$blockID]; } else { continue; } // Do we need to update block? No, continue to process next block $ttl = 0; if ( $ini->hasVariable( $block['block_type'], 'TTL' ) ) { $ttl = $ini->variable( $block['block_type'], 'TTL' ); } if ( $ttl + $block['last_update'] >= $time ) { continue; } // For "rotating blocks", does the rotation_interval has passed from the last update? if ( $block['rotation_type'] != self::ROTATION_NONE && $block['last_update'] + $block['rotation_interval'] >= $time ) { continue; } $blockChanged = false; // Fetch new objects and add them to the queue of the current block eZFlowOperations::updateBlockPoolByBlockID( $block, $time ); $db->begin(); // We need to find out if there are any items to move from the queue $movingFromQueue = $db->arrayQuery( "SELECT object_id FROM ezm_pool WHERE block_id='$blockID' AND ts_visible=0 AND ts_hidden=0 AND ts_publication<=$time ORDER BY ts_publication ASC, priority ASC" ); if ( $movingFromQueue ) { $blockChanged = true; // Find out a number of items in "valid" state and the max. priority used $countMaxPriorityValid = $db->arrayQuery( "SELECT count(*) AS count, max(priority) AS priority FROM ezm_pool WHERE block_id='$blockID' AND ts_visible>0 AND ts_hidden=0" ); $countValid = $countMaxPriorityValid[0]['count']; $maxPriorityValid = $countMaxPriorityValid[0]['priority']; if ( $countValid == 0 ) { $maxPriorityValid = 0; } $priority = $maxPriorityValid + 1; // Move objects waiting in queue to the "valid ones" foreach ( $movingFromQueue as $itemToMove ) { $objectID = $itemToMove['object_id']; $db->query( "UPDATE ezm_pool SET ts_visible=$time, priority=$priority WHERE block_id='$blockID' AND object_id=$objectID" ); $priority++; } $countValid += count( $movingFromQueue ); // Compare this number to the given and archive the oldest (order by ts_visible) $numberOfValidItems = $ini->variable( $block['block_type'], 'NumberOfValidItems' ); if ( !$numberOfValidItems ) { $numberOfValidItems = 20; eZDebug::writeWarning( 'Number of valid items for ' . $block['block_type'] . ' is not set; using the default value (' . $numberOfValidItems . ')', __METHOD__ ); } $countToRemove = $countValid - $numberOfValidItems; if ( $countToRemove > 0 ) { $overflowID = $block['overflow_id']; $items = $db->arrayQuery( "SELECT node_id, object_id, rotation_until FROM ezm_pool WHERE block_id='$blockID' AND ts_visible>0 AND ts_hidden=0 ORDER BY priority ASC", array( 'limit' => $countToRemove ) ); if ( $items ) { $itemArray = array(); $priority = 0; foreach( $items as $item ) { $objectID = $item['object_id']; if ( $block['rotation_type'] != self::ROTATION_NONE && ( $item['rotation_until'] > $time || $item['rotation_until'] == 0 ) ) { if ( $block['rotation_type'] == self::ROTATION_SIMPLE ) { // Simple rotation $newPublicationTS = -$time; $priority++; } else { // Random rotation/Shuffle $newPublicationTS = 0; $priority = mt_rand(); } // Move item back to queue $db->query( "UPDATE ezm_pool SET ts_visible=0, ts_publication=-$time, priority=$priority WHERE block_id='$blockID' AND object_id=$objectID" ); } else { $itemArray[] = $objectID; } } if ( $itemArray ) { if ( $overflowID ) { // Put $itemArray items into pool of different block $priority = 0; foreach( $items as $item ) { $itemObjectID = $item['object_id']; $itemNodeID = $item['node_id']; // Check if the object_id is not already in the new block $duplicityCheck = $db->arrayQuery( "SELECT object_id FROM ezm_pool WHERE block_id='$overflowID' AND object_id=$itemObjectID", array( 'limit' => 1 ) ); if ( $duplicityCheck ) { eZDebug::writeNotice( "Object $itemObjectID is already available in the block $overflowID.", __METHOD__ ); } else { $db->query( "INSERT INTO ezm_pool(block_id,object_id,node_id,ts_publication,priority) VALUES ('$overflowID',$itemObjectID,$itemNodeID,$time,$priority)" ); $priority++; } } $db->query( "UPDATE ezm_pool SET ts_hidden=$time, moved_to='$overflowID', priority=0 WHERE block_id='$blockID' AND " . $db->generateSQLINStatement( $itemArray, 'object_id' ) ); } else { $db->query( "UPDATE ezm_pool SET ts_hidden=$time, priority=0 WHERE block_id='$blockID' AND " . $db->generateSQLINStatement( $itemArray, 'object_id' ) ); } } } } // Cleanup in archived items $countArchived = $db->arrayQuery( "SELECT count(*) AS count FROM ezm_pool WHERE block_id='$blockID' AND ts_hidden>0" ); $countArchived = $countArchived[0]['count']; // Compare this number to the given and remove the oldest ones $numberOfArchivedItems = $ini->variable( $block['block_type'], 'NumberOfArchivedItems' ); if ( $numberOfArchivedItems < 0 ) { $numberOfArchivedItems = 50; eZDebug::writeWarning( 'Number of archived items for ' . $block['block_type'] . ' is not set; using the default value (' . $numberOfArchivedItems . ')', __METHOD__ ); } $countToRemove = $countArchived - $numberOfArchivedItems; if ( $countToRemove > 0 ) { $items = $db->arrayQuery( "SELECT object_id FROM ezm_pool WHERE block_id='$blockID' AND ts_hidden>0 ORDER BY ts_hidden ASC", array( 'limit' => $countToRemove ) ); if ( $items ) { $itemArray = array(); foreach( $items as $item ) { $itemArray[] = $item['object_id']; } $db->query( "DELETE FROM ezm_pool WHERE block_id='$blockID' AND " . $db->generateSQLINStatement( $itemArray, 'object_id' ) ); } } } // If the block changed, we need to update whole node if ( $blockChanged ) { $nodeChanged = true; } $db->commit(); } if ( $nodeChanged ) { $contentObject = eZContentObject::fetchByNodeID( $nodeID ); if ( $contentObject ) eZContentCacheManager::clearContentCache( $contentObject->attribute('id') ); } } // log the previously logged in user if it was changed to anonymous earlier if ( isset( $loggedInUser ) ) { eZUser::setCurrentlyLoggedInUser( $loggedInUser, $loggedInUser->attribute( 'contentobject_id' ) ); } }