コード例 #1
0
 static function fetchIDListByUserID($userID)
 {
     if ($userID == eZUser::anonymousId()) {
         $userCache = eZUSer::getUserCacheByAnonymousId();
         $ruleArray = $userCache['discount_rules'];
     } else {
         $http = eZHTTPTool::instance();
         $handler = eZExpiryHandler::instance();
         $expiredTimeStamp = 0;
         if ($handler->hasTimestamp('user-discountrules-cache')) {
             $expiredTimeStamp = $handler->timestamp('user-discountrules-cache');
         }
         $ruleTimestamp =& $http->sessionVariable('eZUserDiscountRulesTimestamp');
         $ruleArray = false;
         // check for cached version in session
         if ($ruleTimestamp > $expiredTimeStamp) {
             if ($http->hasSessionVariable('eZUserDiscountRules' . $userID)) {
                 $ruleArray =& $http->sessionVariable('eZUserDiscountRules' . $userID);
             }
         }
         if (!is_array($ruleArray)) {
             $ruleArray = self::generateIDListByUserID((int) $userID);
             $http->setSessionVariable('eZUserDiscountRules' . $userID, $ruleArray);
             $http->setSessionVariable('eZUserDiscountRulesTimestamp', time());
         }
     }
     $rules = array();
     foreach ($ruleArray as $ruleRow) {
         $rules[] = $ruleRow['id'];
     }
     return $rules;
 }
コード例 #2
0
 public function setUp()
 {
     parent::setUp();
     $currentUser = eZUser::currentUser();
     $anonymousID = eZUser::anonymousId();
     if ($currentUser->isRegistered()) {
         self::$previousUserID = $currentUser->attribute('contentobject_id');
         eZUser::setCurrentlyLoggedInUser(eZUser::fetch($anonymousID), $anonymousID);
     }
 }
コード例 #3
0
 function addNews(eZContentObjectTreeNode $node)
 {
     $ini = eZINI::instance('xrowsitemap.ini');
     $news = new xrowSitemapItemNews();
     $images = array();
     // Adding the root node
     $object = $node->object();
     $news->publication_date = new DateTime('@' . $object->attribute('published'));
     $news->title = $object->attribute('name');
     $user = eZUser::fetch(eZUser::anonymousId());
     if (!xrowSitemapTools::checkAccess($object, $user, 'read')) {
         $news->access = 'Subscription';
     }
     // Get Genres, if enable
     if ((!$ini->hasVariable('NewsSitemapSettings', 'UseGenres') || $ini->hasVariable('NewsSitemapSettings', 'UseGenres') && $ini->variable('NewsSitemapSettings', 'UseGenres') != 'disable') && $ini->hasVariable('NewsSitemapSettings', 'Genres')) {
         $genres_array = $ini->variable('NewsSitemapSettings', 'Genres');
         // set genre if set
         if (isset($genres_array[$node->ClassIdentifier])) {
             $news->genres = array($genres_array[$node->ClassIdentifier]);
         }
     }
     $dm = $node->dataMap();
     $news->keywords = array();
     foreach ($dm as $attribute) {
         switch ($attribute->DataTypeString) {
             case 'xrowmetadata':
                 if ($attribute->hasContent()) {
                     $keywordattribute = $attribute->content();
                     $news->keywords = array_merge($news->keywords, $keywordattribute->keywords);
                 }
                 break;
             case 'ezkeyword':
                 if ($attribute->hasContent()) {
                     $keywordattribute = $attribute->content();
                     $news->keywords = array_merge($news->keywords, $keywordattribute->KeywordArray);
                 }
                 break;
         }
     }
     if ($ini->hasVariable('NewsSitemapSettings', 'AdditionalKeywordList')) {
         $news->keywords = array_merge($news->keywords, $ini->variable('NewsSitemapSettings', 'AdditionalKeywordList'));
     }
     return $news;
 }
コード例 #4
0
 /**
  * Gets the id of the anonymous user.
  *
  * @static
  * @return int User id of anonymous user.
  */
 public static function anonymousId()
 {
     if (self::$anonymousId === null) {
         $ini = eZINI::instance();
         self::$anonymousId = (int) $ini->variable('UserSettings', 'AnonymousUserID');
         $GLOBALS['eZUserBuiltins'] = array(self::$anonymousId);
     }
     return self::$anonymousId;
 }
コード例 #5
0
ファイル: ezflowoperations.php プロジェクト: netbliss/ezflow
 /**
  * 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
     $currentUser = eZUser::currentUser();
     if ($currentUser->isLoggedIn()) {
         $loggedInUser = $currentUser;
         $anonymousUserId = eZUser::anonymousId();
         $anonymousUser = eZUser::instance($anonymousUserId);
         eZUser::setCurrentlyLoggedInUser($anonymousUser, $anonymousUserId);
         unset($currentUser, $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\n                         FROM ezm_block\n                         WHERE is_removed=1");
     foreach ($res as $row) {
         $blockID = $row['id'];
         $db->begin();
         $db->query("DELETE FROM ezm_pool\n                 WHERE block_id='{$blockID}'");
         $db->query("DELETE FROM ezm_block\n                 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) {
         $time = time() - 5;
         // a safety margin
         $nodeChanged = false;
         $blocks = $db->arrayQuery("SELECT *\n                                FROM ezm_block\n                                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\n                                             FROM ezm_pool\n                                             WHERE block_id='{$blockID}'\n                                               AND ts_visible=0\n                                               AND ts_hidden=0\n                                               AND ts_publication<={$time}\n                                             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\n                                                       FROM ezm_pool\n                                                       WHERE block_id='{$blockID}'\n                                                         AND ts_visible>0\n                                                         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\n                             SET ts_visible={$time}, priority={$priority}\n                             WHERE block_id='{$blockID}'\n                               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\n                                           FROM ezm_pool\n                                           WHERE block_id='{$blockID}'\n                                             AND ts_visible>0\n                                             AND ts_hidden=0\n                                           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\n                                         SET ts_visible=0,\n                                             ts_publication=-{$time},\n                                             priority={$priority}\n                                         WHERE block_id='{$blockID}'\n                                           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\n                                                                    FROM ezm_pool\n                                                                    WHERE block_id='{$overflowID}'\n                                                                      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)\n                                                 VALUES ('{$overflowID}',{$itemObjectID},{$itemNodeID},{$time},{$priority})");
                                         $priority++;
                                     }
                                 }
                                 $db->query("UPDATE ezm_pool\n                                         SET ts_hidden={$time},\n                                             moved_to='{$overflowID}',\n                                             priority=0\n                                         WHERE block_id='{$blockID}'\n                                           AND " . $db->generateSQLINStatement($itemArray, 'object_id'));
                             } else {
                                 $db->query("UPDATE ezm_pool\n                                         SET ts_hidden={$time},\n                                             priority=0\n                                         WHERE block_id='{$blockID}'\n                                           AND " . $db->generateSQLINStatement($itemArray, 'object_id'));
                             }
                         }
                     }
                 }
                 // Cleanup in archived items
                 $countArchived = $db->arrayQuery("SELECT count(*) AS count\n                                               FROM ezm_pool\n                                               WHERE block_id='{$blockID}'\n                                                 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\n                                           FROM ezm_pool\n                                           WHERE block_id='{$blockID}'\n                                             AND ts_hidden>0\n                                           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\n                                 WHERE block_id='{$blockID}'\n                                   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'));
     }
 }
コード例 #6
0
 /**
  * Figgure out if current user has rated, since eZ Publish changes session id as of 4.1
  * on login / logout, a couple of things needs to be checked.
  * 1. Session variable 'ezsrRatedAttributeIdList' for list of attribute_id's
  * 2a. (annonymus user) check against session key
  * 2b. (logged in user) check against user id
  *
  * @param bool $returnRatedObject Return object if user has rated and [eZStarRating]AllowChangeRating=enabled
  * @return bool|ezsrRatingDataObject
  */
 function userHasRated($returnRatedObject = false)
 {
     if ($this->currentUserHasRated === null) {
         $http = eZHTTPTool::instance();
         if ($http->hasSessionVariable('ezsrRatedAttributeIdList')) {
             $attributeIdList = explode(',', $http->sessionVariable('ezsrRatedAttributeIdList'));
         } else {
             $attributeIdList = array();
         }
         $ini = eZINI::instance();
         $contentobjectAttributeId = $this->attribute('contentobject_attribute_id');
         if (in_array($contentobjectAttributeId, $attributeIdList) && $ini->variable('eZStarRating', 'UseUserSession') === 'enabled') {
             $this->currentUserHasRated = true;
         }
         $returnRatedObject = $returnRatedObject && $ini->variable('eZStarRating', 'AllowChangeRating') === 'enabled';
         if ($this->currentUserHasRated === null || $returnRatedObject) {
             $sessionKey = $this->attribute('session_key');
             $userId = $this->attribute('user_id');
             if ($userId == eZUser::anonymousId()) {
                 $cond = array('user_id' => $userId, 'session_key' => $sessionKey, 'contentobject_id' => $this->attribute('contentobject_id'), 'contentobject_attribute_id' => $contentobjectAttributeId);
             } else {
                 $cond = array('user_id' => $userId, 'contentobject_id' => $this->attribute('contentobject_id'), 'contentobject_attribute_id' => $contentobjectAttributeId);
             }
             if ($returnRatedObject) {
                 $this->currentUserHasRated = eZPersistentObject::fetchObject(self::definition(), null, $cond);
                 if ($this->currentUserHasRated === null) {
                     $this->currentUserHasRated = false;
                 }
             } else {
                 $this->currentUserHasRated = eZPersistentObject::count(self::definition(), $cond, 'id') != 0;
             }
         }
     }
     return $this->currentUserHasRated;
 }
コード例 #7
0
 /**
  * Fetches all variables from the object
  *
  * @return bool true if fetching of class attributes are successfull, false if not
  */
 function fetchObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
 {
     $contentObjectID = $contentObjectAttribute->attribute("contentobject_id");
     // check if paex object for the current coID exists, create if needed.
     $paex = $contentObjectAttribute->content();
     if ($paex === null) {
         $paex = eZPaEx::create($contentObjectID);
     }
     // Set current values as default ones
     $passwordvalidationregexp = $paex->attribute('passwordvalidationregexp');
     $passwordlifetime = $paex->attribute('passwordlifetime');
     $expirationnotification = $paex->attribute('expirationnotification');
     $passwordLastUpdated = $paex->attribute('password_last_updated');
     $updatechildren = $paex->attribute('updatechildren');
     $expirationnotificationSent = $paex->attribute('expirationnotification_sent');
     // Update current values with new ones entered in the form if there are any
     if ($http->hasPostVariable($base . "_data_paex_passwordvalidationregexp_" . $contentObjectAttribute->attribute("id"))) {
         $passwordvalidationregexp = $http->postVariable($base . "_data_paex_passwordvalidationregexp_" . $contentObjectAttribute->attribute("id"));
     }
     if ($http->hasPostVariable($base . "_data_paex_passwordlifetime_" . $contentObjectAttribute->attribute("id"))) {
         $passwordlifetime = $http->postVariable($base . "_data_paex_passwordlifetime_" . $contentObjectAttribute->attribute("id"));
     }
     if ($http->hasPostVariable($base . "_data_paex_expirationnotification_" . $contentObjectAttribute->attribute("id"))) {
         $expirationnotification = $http->postVariable($base . "_data_paex_expirationnotification_" . $contentObjectAttribute->attribute("id"));
     }
     // Be sure passwordlifetime is set
     if (trim($passwordlifetime) == '') {
         $passwordlifetime = eZPaEx::NOT_DEFINED;
     }
     // Be sure expirationnotification is set
     if (trim($expirationnotification) == '') {
         $expirationnotification = eZPaEx::NOT_DEFINED;
     }
     // If we are editing a user account set it's password_last_updated as needed.
     if ($paex->isUser()) {
         // Search for password entered in the form
         $newPassword = "";
         foreach ($http->postVariable($base . '_id') as $coaid) {
             if ($http->hasPostVariable($base . '_data_user_password_' . $coaid)) {
                 $newPassword = $http->postVariable($base . '_data_user_password_' . $coaid);
                 break;
             }
         }
         // Check if the password has changed
         if (trim($newPassword) && $newPassword != "_ezpassword") {
             $currentUserID = eZUser::currentUserID();
             if ($currentUserID == $contentObjectID) {
                 // If self editing, set last_updated to current time
                 $passwordLastUpdated = time();
                 // if audit is enabled password changes should be logged
                 eZAudit::writeAudit('user-password-change-self', array());
             } else {
                 if ($currentUserID == eZUser::anonymousId()) {
                     // register, @see http://issues.ez.no/15391
                     $passwordLastUpdated = time();
                 } else {
                     // If changing other user's password, set last_updated to 0 to force
                     // password change in the next connection
                     $passwordLastUpdated = 0;
                     // if audit is enabled password changes should be logged
                     $targetUser = eZUser::fetch($contentObjectID);
                     eZAudit::writeAudit('user-password-change', array('User id' => $targetUser->attribute('contentobject_id'), 'User login' => $targetUser->attribute('login')));
                 }
             }
             // Password has changed, reset expirationnotification_sent flag to send again a notification when this new password be about to expire
             $expirationnotificationSent = 0;
         }
     } else {
         // If we are updating a user group and don't have the updatechildren post var, set updatechildren flag to disabled
         if ($http->hasPostVariable($base . "_data_paex_updatechildren_" . $contentObjectAttribute->attribute("id"))) {
             $updatechildren = $http->postVariable($base . "_data_paex_updatechildren_" . $contentObjectAttribute->attribute("id"));
         } else {
             $updatechildren = 0;
         }
     }
     if ($paex->canEdit()) {
         // If user has permission, update full paex object with possible new values
         $paex->setInformation($contentObjectID, $passwordvalidationregexp, $passwordlifetime, $expirationnotification, $passwordLastUpdated, $updatechildren, $expirationnotificationSent);
     } else {
         // If user don't have permission to update paex data, only update the password_last_updated and expirationnotification_sent fields
         $paex->setAttribute('password_last_updated', $passwordLastUpdated);
         $paex->setAttribute('expirationnotification_sent', $expirationnotificationSent);
     }
     $contentObjectAttribute->setContent($paex);
     return true;
 }
コード例 #8
0
ファイル: ezsurveyresult.php プロジェクト: heliopsis/ezsurvey
 static function definition()
 {
     $def = array('fields' => array('id' => array('name' => 'ID', 'datatype' => 'integer', 'default' => 0, 'required' => true), 'survey_id' => array('name' => 'SurveyID', 'datatype' => 'integer', 'default' => 0, 'required' => true), 'user_id' => array('name' => 'UserID', 'datatype' => 'integer', 'default' => eZUser::anonymousId(), 'required' => false), 'tstamp' => array('name' => 'TStamp', 'datatype' => 'integer', 'default' => 0, 'required' => false), 'user_session_id' => array('name' => 'UserSessionID', 'datatype' => 'string', 'default' => '', 'required' => false)), 'keys' => array('id'), 'function_attributes' => array('question_results' => 'fetchQuestionResultList'), 'increment_key' => 'id', 'class_name' => 'eZSurveyResult', 'sort' => array('id' => 'asc'), 'name' => 'ezsurveyresult');
     return $def;
 }
コード例 #9
0
ファイル: session.php プロジェクト: CG77/ezpublish-legacy
function eZFetchActiveSessionCount($params = array())
{
    $filterType = $params['filter_type'];
    switch ($filterType) {
        case 'registered':
            $filterSQL = ' ezsession.user_id != ' . eZUser::anonymousId();
            break;
        case 'anonymous':
            $filterSQL = ' ezsession.user_id = ' . eZUser::anonymousId();
            break;
        case 'everyone':
        default:
            $filterSQL = '';
            break;
    }
    $expirationFilterType = $params['expiration_filter'];
    $userID = $params['user_id'];
    if ($userID) {
        $filterSQL = ' ezsession.user_id = ' . (int) $userID;
    }
    switch ($expirationFilterType) {
        case 'active':
            $ini = eZINI::instance();
            $time = time();
            $activityTimeout = $ini->variable('Session', 'ActivityTimeout');
            $sessionTimeout = $ini->variable('Session', 'SessionTimeout');
            $time = $time + $sessionTimeout - $activityTimeout;
            $expirationFilterSQL = '';
            if (strlen($filterSQL) > 0) {
                $expirationFilterSQL .= ' AND ';
            }
            $expirationFilterSQL .= ' ezsession.expiration_time > ' . $time;
            break;
        case 'all':
        default:
            $expirationFilterSQL = '';
            break;
    }
    $whereSQL = '';
    if (strlen($filterSQL) + strlen($expirationFilterSQL) > 0) {
        $whereSQL = 'WHERE';
    }
    $db = eZDB::instance();
    $query = "SELECT count( DISTINCT ezsession.user_id ) AS count\n              FROM ezsession\n              {$whereSQL}\n              {$filterSQL}\n              {$expirationFilterSQL}";
    $rows = $db->arrayQuery($query);
    return $rows[0]['count'];
}
コード例 #10
0
ファイル: view.php プロジェクト: jjohnsen/jaj_newsletter
}
// Check if content class for newsletter exists
$setup["content_classes_ok"] = is_object(eZContentClass::fetchByIdentifier('jaj_newsletter'));
// Check for newsletter folder
$newsletter_id = $newsletter_ini->variable('NewsletterSettings', 'RootFolderNodeId');
$newsletter_node = eZContentObject::fetchByNodeID($newsletter_id);
$setup["newsletter_folder_ok"] = $newsletter_id && is_object($newsletter_node);
$setup["newsletter_settings_ok"] = $newsletter_ini->variable('NewsletterSettings', 'FromEmail') && $newsletter_ini->variable('NewsletterSettings', 'FromName') && $newsletter_ini->variable('NewsletterSettings', 'ReplyEmail');
// Check for newsletter section
// And check that newsletter node is assigned to section
//$section = eZSection::fetchByIdentifier("jaj_newsletter");
$sections = eZSection::fetchList();
foreach ($sections as $s) {
    if ($s->attribute("identifier") == "jaj_newsletter") {
        $section = $s;
        break;
    }
}
if (is_object($newsletter_node) && is_object($section)) {
    $setup["newsletter_section_ok"] = $newsletter_node->SectionID == $section->ID;
} else {
    $setup["newsletter_section_ok"] = false;
}
// TODO: Add check for access rights for section
$anonymous = eZUser::fetch(eZUser::anonymousId());
//var_dump( $anonymous );
$jaj_subscription_access = $anonymous->hasAccessTo('jaj_newsletter', 'manage_subscription');
$setup["newsletter_sub_access_ok"] = $jaj_subscription_access["accessWord"] == "yes";
$tpl = eZTemplate::factory();
$tpl->setVariable('setup', $setup);
$Result = array('content' => $tpl->fetch('design:jaj_newsletter/settings/view.tpl'), 'path' => array(array('url' => 'jaj_newsletter/index', 'text' => ezpI18n::tr('jaj_newsletter/navigation', 'Newsletter')), array('url' => false, 'text' => ezpI18n::tr('jaj_newsletter/navigation', 'Settings'))));
コード例 #11
0
 /**
  * @todo we should return an error if the scalar values are queried without a .0 appendeded...
  */
 function get($oid)
 {
     // warm up list of existing oids, if not yet done
     $this->oidList();
     $internaloid = preg_replace('/\\.0$/', '', $oid);
     if (array_key_exists($internaloid, self::$simplequeries)) {
         $count = -1;
         if (strpos($internaloid, '2.1.4.') === 0) {
             // session-related queries: return -1 if not using db-based storage
             $ini = eZINI::instance();
             $sessionHandler = $ini->variable('Session', 'Handler');
             if ($sessionHandler != 'ezpSessionHandlerDB') {
                 return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $count);
             }
         }
         if (strpos($internaloid, '2.1.6.') === 0) {
             // async-publication-related queries: return -1 if not using it
             $ini = eZINI::instance('content.ini');
             if ($ini->variable('PublishingSettings', 'AsynchronousPublishing') != 'enabled') {
                 return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $count);
             }
         }
         $db = self::eZDBinstance();
         if ($db) {
             $results = $db->arrayQuery(str_replace('/*anonymousId*/', eZUser::anonymousId(), self::$simplequeries[$internaloid]));
             $db->close();
             if (is_array($results) && count($results)) {
                 $count = $results[0]['count'];
             }
         }
         return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $count);
     }
     if (array_key_exists($internaloid, self::$orderstatuslist)) {
         $oids = explode('.', $internaloid);
         switch ($oids[5]) {
             case '1':
                 return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => self::$orderstatuslist[$internaloid]);
             case '2':
                 return array('oid' => $oid, 'type' => eZSNMPd::TYPE_STRING, 'value' => self::$orderstatuslist[$internaloid]);
             case '3':
             case '4':
                 $count = -1;
                 $db = self::eZDBinstance();
                 if ($db) {
                     $status = $db->arrayQuery('select count(*) as num from ezorder where is_temporary=0 and is_archived=' . ($oids[5] + 1) % 2 . ' and status_id=' . self::$orderstatuslist[$internaloid], array('column' => 'num'));
                     $db->close();
                     if (is_array($status) && count($status)) {
                         $count = $status[0];
                     }
                 }
                 return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $count);
         }
     }
     if (array_key_exists($internaloid, self::$cachelist)) {
         $cacheinfo = eZCache::fetchByID(self::$cachelist[$internaloid]);
         $oids = explode('.', $internaloid);
         switch ($oids[3]) {
             case '1':
                 return array('oid' => $oid, 'type' => eZSNMPd::TYPE_STRING, 'value' => $cacheinfo['name']);
             case '2':
                 return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => (int) $cacheinfo['enabled']);
             case '3':
             case '4':
                 $fileINI = eZINI::instance('file.ini');
                 $handlerName = $fileINI->variable('ClusteringSettings', 'FileHandler');
                 switch ($handlerName) {
                     case 'ezfs':
                     case 'eZFSFileHandler':
                     case 'eZFS2FileHandler':
                         break;
                     default:
                         // the db-based filehandlers + dfs one not yet supported
                         return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => -1);
                 }
                 // take care: this is hardcoded from knowledge of cache structure...
                 if (strpos($cacheinfo['path'], 'var/cache/') === 0) {
                     $cachedir = $cacheinfo['path'];
                 } else {
                     $cachedir = eZSys::cacheDirectory() . '/' . $cacheinfo['path'];
                 }
                 if ($oids[3] == '3') {
                     $out = (int) eZsnmpdTools::countFilesInDir($cachedir);
                 } else {
                     $out = (int) eZsnmpdTools::countFilesSizeInDir($cachedir);
                 }
                 return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $out);
         }
     }
     if (array_key_exists($internaloid, self::$storagedirlist)) {
         $oids = explode('.', $internaloid);
         switch ($oids[3]) {
             case '1':
                 return array('oid' => $oid, 'type' => eZSNMPd::TYPE_STRING, 'value' => self::$storagedirlist[$internaloid]);
             case '2':
             case '3':
                 $fileINI = eZINI::instance('file.ini');
                 $handlerName = $fileINI->variable('ClusteringSettings', 'FileHandler');
                 switch ($handlerName) {
                     case 'ezfs':
                     case 'eZFSFileHandler':
                     case 'eZFS2FileHandler':
                         break;
                     default:
                         // the db-based filehandlers + dfs one not yet supported
                         return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => -1);
                 }
                 if ($oids[3] == '2') {
                     $out = (int) eZsnmpdTools::countFilesInDir(self::$storagedirlist[$internaloid]);
                 } else {
                     $out = (int) eZsnmpdTools::countFilesSizeInDir(self::$storagedirlist[$internaloid]);
                 }
                 return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $out);
         }
     }
     switch ($internaloid) {
         case '2.1.1':
             // verify if db can be connected to
             $ok = 1;
             $db = self::eZDBinstance();
             if (!$db) {
                 $ok = 0;
             } else {
                 $db->close();
             }
             return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $ok);
             /*case '2.2.1': // cache-blocks
                             /// @todo ...
                             $handlerName = $fileINI->variable( 'ClusteringSettings', 'FileHandler' );
                             switch( $handlerName )
                             {
                                 case 'ezfs':
                                     break;
                                 case 'ezdb':
                                     break;
                                 default:
                             }
             
                         case '2.2.2': // view-cache
                             /// @todo ...
                             $handlerName = $fileINI->variable( 'ClusteringSettings', 'FileHandler' );
                             switch( $handlerName )
                             {
                                 case 'ezfs':
                                     break;
                                 case 'ezdb':
                                     break;
                                 default:
                             }*/
         /*case '2.2.1': // cache-blocks
                         /// @todo ...
                         $handlerName = $fileINI->variable( 'ClusteringSettings', 'FileHandler' );
                         switch( $handlerName )
                         {
                             case 'ezfs':
                                 break;
                             case 'ezdb':
                                 break;
                             default:
                         }
         
                     case '2.2.2': // view-cache
                         /// @todo ...
                         $handlerName = $fileINI->variable( 'ClusteringSettings', 'FileHandler' );
                         switch( $handlerName )
                         {
                             case 'ezfs':
                                 break;
                             case 'ezdb':
                                 break;
                             default:
                         }*/
         case '2.4.1':
             // ldap connection
             $ini = eZINI::instance('ldap.ini');
             if ($ini->variable('LDAPSettings', 'LDAPEnabled') == 'true' && $ini->variable('LDAPSettings', 'LDAPServer') != '') {
                 $ok = 0;
                 // code copied over from ezldapuser class...
                 $LDAPVersion = $ini->variable('LDAPSettings', 'LDAPVersion');
                 $LDAPServer = $ini->variable('LDAPSettings', 'LDAPServer');
                 $LDAPPort = $ini->variable('LDAPSettings', 'LDAPPort');
                 $LDAPBindUser = $ini->variable('LDAPSettings', 'LDAPBindUser');
                 $LDAPBindPassword = $ini->variable('LDAPSettings', 'LDAPBindPassword');
                 $ds = ldap_connect($LDAPServer, $LDAPPort);
                 if ($ds) {
                     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $LDAPVersion);
                     if ($LDAPBindUser == '') {
                         $r = ldap_bind($ds);
                     } else {
                         $r = ldap_bind($ds, $LDAPBindUser, $LDAPBindPassword);
                     }
                     if ($r) {
                         $ok = 1;
                     }
                     // added: release resources, be ready for next test
                     ldap_close($ds);
                 }
             } else {
                 $ok = -1;
             }
             return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $ok);
         case '2.4.2':
             // web connection
             $ini = eZINI::instance('snmpd.ini');
             $websites = $ini->variable('StatusHandler', 'WebBeacons');
             $ok = 0;
             if (is_string($websites)) {
                 $websites = array($websites);
             }
             foreach ($websites as $key => $site) {
                 if (trim($site) == '') {
                     unset($websites[$key]);
                 }
             }
             if (count($websites)) {
                 foreach ($websites as $site) {
                     // current eZ code is broken if no curl is installed, as it does not check for 404 or such.
                     // besides, it does not even support proxies...
                     if (extension_loaded('curl')) {
                         if (eZHTTPTool::getDataByURL($site, true)) {
                             $ok = 1;
                             break;
                         }
                     } else {
                         $data = eZHTTPTool::getDataByURL($site, false);
                         if ($data !== false && sysInfoTools::isHTTP200($data)) {
                             $ok = 1;
                             break;
                         }
                     }
                 }
             } else {
                 $ok = -1;
             }
             return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $ok);
         case '2.4.3':
             // email connection
             $ini = eZINI::instance('snmpd.ini');
             $recipient = $ini->variable('StatusHandler', 'MailReceiver');
             $ok = 0;
             $mail = new eZMail();
             if (trim($recipient) != '' && $mail->validate($recipient)) {
                 $mail->setReceiver($recipient);
                 $ini = eZINI::instance();
                 $sender = $ini->variable('MailSettings', 'EmailSender');
                 $mail->setSender($sender);
                 $mail->setSubject("Test email");
                 $mail->setBody("This email was automatically sent while testing eZ Publish connectivity to the mail server. Please do not reply.");
                 $mailResult = eZMailTransport::send($mail);
                 if ($mailResult) {
                     $ok = 1;
                 }
             } else {
                 $ok = -1;
             }
             return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $ok);
         case '2.5.1':
             $fileINI = eZINI::instance('file.ini');
             $clusterhandler = $fileINI->variable('ClusteringSettings', 'FileHandler');
             if ($clusterhandler == 'ezdb' || $clusterhandler == 'eZDBFileHandler') {
                 $ok = 0;
                 $dbFileHandler = eZClusterFileHandler::instance();
                 if ($dbFileHandler instanceof eZDBFileHandler) {
                     // warning - we dig into the private parts of the cluster file handler,
                     // as no real API are provided for it (yet)
                     if (is_resource($dbFileHandler->backend->db)) {
                         $ok = 1;
                     }
                 }
             } else {
                 if ($clusterhandler == 'eZDFSFileHandler') {
                     // This is even worse: we have no right to know if db connection is ok.
                     // So we replicate some code here...
                     $dbbackend = eZExtension::getHandlerClass(new ezpExtensionOptions(array('iniFile' => 'file.ini', 'iniSection' => 'eZDFSClusteringSettings', 'iniVariable' => 'DBBackend')));
                     try {
                         $dbbackend->_connect();
                         $ok = 1;
                     } catch (exception $e) {
                         $ok = 0;
                     }
                 } else {
                     $ok = -1;
                 }
             }
             return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $ok);
     }
     return self::NO_SUCH_OID;
     // oid not managed
 }