static function removeByIdentifier($collaborationIdentifier, $userID = false) { if (!$userID) { $userID = eZUser::currentUserID(); } eZPersistentObject::removeObject(eZCollaborationNotificationRule::definition(), array('collab_identifier' => $collaborationIdentifier, 'user_id' => $userID)); }
static function create( $name, $command, $userID = false ) { if ( trim( $name ) == '' ) { eZDebug::writeError( 'Empty name. You must supply a valid script name string.', 'ezscriptmonitor' ); return false; } if ( trim( $command ) == '' ) { eZDebug::writeError( 'Empty command. You must supply a valid command string.', 'ezscriptmonitor' ); return false; } if ( !$userID ) { $userID = eZUser::currentUserID(); } $scriptMonitorIni = eZINI::instance( 'ezscriptmonitor.ini' ); $scriptSiteAccess = $scriptMonitorIni->variable( 'GeneralSettings', 'ScriptSiteAccess' ); $command = str_replace( self::SCRIPT_NAME_STRING, $name, $command ); $command = str_replace( self::SITE_ACCESS_STRING, $scriptSiteAccess, $command ); // Negative progress means not started yet return new self( array( 'name' => $name, 'command' => $command, 'last_report_timestamp' => time(), 'progress' => -1, 'user_id' => $userID ) ); }
/** * @param int $objectID ContentObjectID */ public function __construct($objectID) { $userID = eZUser::currentUserID(); $message = ezpI18n::tr('design/standard/error/kernel', 'Access denied') . '. ' . ezpI18n::tr('design/standard/error/kernel', 'You do not have permission to access this area.'); eZLog::write("Access denied to content object #{$objectID} for user #{$userID}", 'error.log'); parent::__construct($message); }
function fetchList($collaborationID, $userID = false, $asObject = true) { if ($userID == false) { $userID == eZUser::currentUserID(); } return eZPersistentObject::fetchObjectList(eZCollaborationItemGroupLink::definition(), null, array('collaboration_id' => $collaborationID, 'user_id' => $userID), null, null, $asObject); }
static function setValue( $name, $value, $storeUserID = false ) { $db = eZDB::instance(); $name = $db->escapeString( $name ); $rawValue = $value; $value = $db->escapeString( $value ); $isCurrentUser = true; if ( $storeUserID === false ) { $user = eZUser::currentUser(); } else { $currentID = eZUser::currentUserID(); if ( $currentID != $storeUserID ) $isCurrentUser = false; $user = eZUser::fetch( $storeUserID ); if ( !is_object( $user ) ) { eZDebug::writeError( "Cannot set preference for user $storeUserID, the user does not exist" ); return false; } } // We must store the database changes if: // a - The current user is logged in (ie. not anonymous) // b - We have specified a specific user (not the current). // in which case isLoggedIn() will fail. if ( $storeUserID !== false or $user->isLoggedIn() ) { // Only store in DB if user is logged in or we have // a specific user ID defined $userID = $user->attribute( 'contentobject_id' ); $existingRes = $db->arrayQuery( "SELECT * FROM ezpreferences WHERE user_id = $userID AND name='$name'" ); if ( count( $existingRes ) > 0 ) { $prefID = $existingRes[0]['id']; $query = "UPDATE ezpreferences SET value='$value' WHERE id = $prefID AND name='$name'"; $db->query( $query ); } else { $query = "INSERT INTO ezpreferences ( user_id, name, value ) VALUES ( $userID, '$name', '$value' )"; $db->query( $query ); } } // We also store in session if this is the current user (anonymous or normal user) // use $rawValue as value will be escaped by session code (see #014520) if ( $isCurrentUser ) { eZPreferences::storeInSession( $name, $rawValue ); } return true; }
static function create($userID = false) { $dateTime = time(); if (!$userID) { $userID = eZUser::currentUserID(); } $row = array("id" => null, "name" => "", "creator_id" => $userID, "modifier_id" => $userID, "created" => $dateTime, "modified" => $dateTime); return new eZContentClassGroup($row); }
/** * fetch CjwNewsletterBlacklistItem object by id * return false if not found * * @param integer $id * @param boolean $asObject * @return CjwNewsletterBlacklistItem */ public static function create($email, $note) { $newsletterUserObject = CjwNewsletterUser::fetchByEmail($email); $newsletterUserId = 0; if (is_object($newsletterUserObject)) { $newsletterUserId = $newsletterUserObject->attribute('id'); } $row = array('email' => strtolower($email), 'note' => $note, 'created' => time(), 'creator_contentobject_id' => eZUser::currentUserID(), 'email_hash' => self::generateEmailHash($email), 'newsletter_user_id' => $newsletterUserId); $object = new CjwNewsletterBlacklistItem($row); return $object; }
static function updateFields($collaborationID, $userID = false, $fields) { if ($userID === false) { $userID = eZUser::currentUserID(); } eZPersistentObject::updateObjectList(array('definition' => eZCollaborationItemStatus::definition(), 'update_fields' => $fields, 'conditions' => array('collaboration_id' => $collaborationID, 'user_id' => $userID))); $statusObject =& $GLOBALS['eZCollaborationItemStatusCache'][$collaborationID][$userID]; if (isset($statusObject)) { foreach ($fields as $field => $value) { $statusObject->setAttribute($field, $value); } } }
static function setLastRead($collaborationID, $userID = false, $timestamp = false) { if ($userID === false) { $userID = eZUser::currentUserID(); } if ($timestamp === false) { $timestamp = time(); } $db = eZDB::instance(); $userID = (int) $userID; $timestamp = (int) $timestamp; $sql = "UPDATE ezcollab_item_participant_link set last_read='{$timestamp}'\n WHERE collaboration_id='{$collaborationID}' AND participant_id='{$userID}'"; $db->query($sql); if (!empty($GLOBALS["eZCollaborationItemParticipantLinkCache"][$collaborationID][$userID])) { $GLOBALS["eZCollaborationItemParticipantLinkCache"][$collaborationID][$userID]->setAttribute('last_read', $timestamp); } }
public function filter() { if (eZINI::instance('rest.ini')->variable('Authentication', 'RequireHTTPS') === 'enabled' && $this->req->isEncrypted === false) { // When an unencrypted connection is identified, we have to alter the // flag to avoid infinite loop, when the request is rerouted to the error controller. // This should be improved in the future. $this->req->isEncrypted = true; throw new ezpRestHTTPSRequiredException(); } // 0. Check if the given route needs authentication. if (!$this->shallAuthenticate()) { $this->filter = new ezpRestNoAuthStyle(); } else { if ($this->filter === null) { $opt = new ezpExtensionOptions(); $opt->iniFile = 'rest.ini'; $opt->iniSection = 'Authentication'; $opt->iniVariable = 'AuthenticationStyle'; $authFilter = eZExtension::getHandlerClass($opt); if (!$authFilter instanceof ezpRestAuthenticationStyle) { throw new ezpRestAuthStyleNotFoundException(); } $this->filter = $authFilter; } } // 1. Initialize the context needed for authenticating the user. $auth = $this->filter->setup($this->req); if ($auth instanceof ezcMvcInternalRedirect) { return $auth; } // 2.Perform the authentication // Result of authentication filter can be a valid ezp user (auth succeeded) or an internal redirect (ezcMvcInternalRedirect) $user = $this->filter->authenticate($auth, $this->req); if ($user instanceof eZUser) { $userID = $user->id(); if ($userID != eZUser::currentUserID()) { eZUser::setCurrentlyLoggedInUser($user, $userID); } $this->filter->setUser($user); } else { if ($user instanceof ezcMvcInternalRedirect) { return $user; } } }
/** * Update blocks order based on AJAX data send after D&D operation is finished * * @param mixed $args * @return array */ public static function updateblockorder($args) { $http = eZHTTPTool::instance(); $contentObjectAttributeID = (int) $http->postVariable('contentobject_attribute_id', 0); $version = (int) $http->postVariable('version', 0); $zoneID = $http->postVariable('zone', ''); $blockOrder = $http->postVariable('block_order', array()); $contentObjectAttribute = eZContentObjectAttribute::fetch($contentObjectAttributeID, $version); if (!$contentObjectAttribute instanceof eZContentObjectAttribute) { return array(); } $contentObject = $contentObjectAttribute->attribute('object'); if (!$contentObject->attribute('can_edit')) { return array(); } // checking that the version is a draft and belongs to the current user $contentVersion = $contentObjectAttribute->attribute('object_version'); if ($contentVersion->attribute('status') != eZContentObjectVersion::STATUS_DRAFT && $contentVersion->attribute('status') != eZContentObjectVersion::STATUS_INTERNAL_DRAFT) { return array(); } if ($contentVersion->attribute('creator_id') != eZUser::currentUserID()) { return array(); } $sortArray = array(); foreach ($blockOrder as $blockID) { $idArray = explode('_', $blockID); if (isset($idArray[1])) { $sortArray[] = $idArray[1]; } } if ($contentObjectAttribute) { $page = $contentObjectAttribute->content(); } if ($page) { $zone = $page->getZone($zoneID); } if ($zone) { $zone->sortBlocks($sortArray); } $contentObjectAttribute->setContent($page); $contentObjectAttribute->store(); return array(); }
function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters) { switch ($operatorName) { case 'is_bookmarked': $bookmarkList = eZPersistentObject::fetchObjectList(eZContentBrowseBookmark::definition(), null, array('user_id' => eZUser::currentUserID(), 'node_id' => $namedParameters['node_id']), array('id' => 'desc'), array('offset' => 0, 'length' => '10'), true); if (count($bookmarkList) > 0) { $operatorValue = 1; } else { $operatorValue = 0; } break; case 'is_in_subscribed_nodes': $subscriptionList = eZPersistentObject::fetchObjectList(eZSubtreeNotificationRule::definition(), array('node_id'), array('user_id' => eZUser::currentUserID(), 'node_id' => $namedParameters['node_id']), null, null, false); if (count($subscriptionList) > 0) { $operatorValue = 1; } else { $operatorValue = 0; } break; } }
function installContentObjects( $objectNodes, $topNodeListNode, &$installParameters ) { if ( isset( $installParameters['user_id'] ) ) $userID = $installParameters['user_id']; else $userID = eZUser::currentUserID(); $handlerType = $this->handlerType(); $firstInstalledID = null; foreach( $objectNodes as $objectNode ) { $realObjectNode = $this->getRealObjectNode( $objectNode ); // Cycle until we reach an element where error has occured. // If action has been choosen, try install this item again, else skip it. if ( isset( $installParameters['error']['error_code'] ) && !$this->isErrorElement( $realObjectNode->getAttribute( 'remote_id' ), $installParameters ) ) { continue; } //we are here, it means we'll try to install some object. if ( !$firstInstalledID ) { $firstInstalledID = $realObjectNode->getAttribute( 'remote_id' ); } $newObject = eZContentObject::unserialize( $this->Package, $realObjectNode, $installParameters, $userID, $handlerType ); if ( !$newObject ) { return false; } if ( is_object( $newObject ) ) { eZContentObject::clearCache( $newObject->attribute( 'id' ) ); unset( $newObject ); } unset( $realObjectNode ); if ( isset( $installParameters['error'] ) && count( $installParameters['error'] ) ) { $installParameters['error'] = array(); } } $this->installSuspendedNodeAssignment( $installParameters ); $this->installSuspendedObjectRelations( $installParameters ); // Call postUnserialize on all installed objects foreach( $objectNodes as $objectNode ) { if ( $objectNode->localName == 'object' ) { $remoteID = $objectNode->getAttribute( 'remote_id' ); } else { $remoteID = substr( $objectNode->getAttribute( 'filename' ), 7, 32 ); } // Begin from the object that we started from in the previous cycle if ( $firstInstalledID && $remoteID != $firstInstalledID ) { continue; } else { $firstInstalledID = null; } $object = eZContentObject::fetchByRemoteID( $remoteID ); if ( is_object( $object ) ) { $object->postUnserialize( $this->Package ); eZContentObject::clearCache( $object->attribute( 'id' ) ); } unset( $object ); } return true; }
function &fetchAlreadyPosted($survey_id, $user_id = false) { if ($user_id === false) { $user_id = eZUser::currentUserID(); } return array('result' => eZPersistentObject::fetchObject(eZSurveyResult::definition(), null, array('survey_id' => $survey_id, 'user_id' => $user_id)) ? true : false); }
/** * Returns an array with all the content object attributes where the keys are the attribute identifiers. * * @see eZContentObject::fetchDataMap() * @return eZContentObjectAttribute[] */ function dataMap() { $object = $this->object(); if (self::$useCurrentUserDraft) { $draft = eZContentObjectVersion::fetchLatestUserDraft($object->attribute('id'), eZUser::currentUserID(), $object->currentLanguageObject()->attribute('id'), $object->attribute('modified')); if ($draft instanceof eZContentObjectVersion) { return $object->fetchDataMap($draft->attribute('version')); } } return $object->fetchDataMap($this->attribute('contentobject_version')); }
/** * 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; }
/** * Regression test for issue #16949 * 1) Test there is no pending object in sub objects * 2) Test there is one pending object in sub objects */ public function testIssue16949() { //create object $top = new ezpObject( 'article', 2 ); $top->title = 'TOP ARTICLE'; $top->publish(); $child = new ezpObject( 'article', $top->mainNode->node_id ); $child->title = 'THIS IS AN ARTICLE'; $child->publish(); $adminUser = eZUser::fetchByName( 'admin' ); $adminUserID = $adminUser->attribute( 'contentobject_id' ); $currentUser = eZUser::currentUser(); $currentUserID = eZUser::currentUserID(); eZUser::setCurrentlyLoggedInUser( $adminUser, $adminUserID ); $result = eZContentObjectTreeNode::subtreeRemovalInformation( array( $top->mainNode->node_id ) ); $this->assertFalse( $result['has_pending_object'] ); $workflowArticle = new ezpObject( 'article', $top->mainNode->node_id ); $workflowArticle->title = 'THIS IS AN ARTICLE WITH WORKFLOW'; $workflowArticle->publish(); $version = $workflowArticle->currentVersion(); $version->setAttribute( 'status', eZContentObjectVersion::STATUS_PENDING ); $version->store(); $result = eZContentObjectTreeNode::subtreeRemovalInformation( array( $top->mainNode->node_id ) ); $this->assertTrue( $result['has_pending_object'] ); eZUser::setCurrentlyLoggedInUser( $currentUser, $currentUserID ); }
/** * Creates a RSS/ATOM Feed export for a node * * @param int $nodeID Node ID * * @since 4.3 */ public static function createFeedForNode($nodeID) { $hasExport = eZRSSFunctionCollection::hasExportByNode($nodeID); if (isset($hasExport['result']) && $hasExport['result']) { eZDebug::writeError('There is already a rss/atom export feed for this node: ' . $nodeID, __METHOD__); return array('status' => false); } $node = eZContentObjectTreeNode::fetch($nodeID); $currentClassIdentifier = $node->attribute('class_identifier'); $config = eZINI::instance('site.ini'); $feedItemClasses = $config->variable('RSSSettings', 'DefaultFeedItemClasses'); if (!$feedItemClasses || !isset($feedItemClasses[$currentClassIdentifier])) { eZDebug::writeError("EnableRSS: content class {$currentClassIdentifier} is not defined in site.ini[RSSSettings]DefaultFeedItemClasses[<class_id>].", __METHOD__); return array('status' => false); } $object = $node->object(); $objectID = $object->attribute('id'); $currentUserID = eZUser::currentUserID(); $rssExportItems = array(); $db = eZDB::instance(); $db->begin(); $rssExport = eZRSSExport::create($currentUserID); $rssExport->setAttribute('access_url', 'rss_feed_' . $nodeID); $rssExport->setAttribute('node_id', $nodeID); $rssExport->setAttribute('main_node_only', '1'); $rssExport->setAttribute('number_of_objects', $config->variable('RSSSettings', 'NumberOfObjectsDefault')); $rssExport->setAttribute('rss_version', $config->variable('RSSSettings', 'DefaultVersion')); $rssExport->setAttribute('status', eZRSSExport::STATUS_VALID); $rssExport->setAttribute('title', $object->name()); $rssExport->store(); $rssExportID = $rssExport->attribute('id'); foreach (explode(';', $feedItemClasses[$currentClassIdentifier]) as $classIdentifier) { $iniSection = 'RSSSettings_' . $classIdentifier; if ($config->hasVariable($iniSection, 'FeedObjectAttributeMap')) { $feedObjectAttributeMap = $config->variable($iniSection, 'FeedObjectAttributeMap'); $subNodesMap = $config->hasVariable($iniSection, 'Subnodes') ? $config->variable($iniSection, 'Subnodes') : array(); $rssExportItem = eZRSSExportItem::create($rssExportID); $rssExportItem->setAttribute('class_id', eZContentObjectTreeNode::classIDByIdentifier($classIdentifier)); $rssExportItem->setAttribute('title', $feedObjectAttributeMap['title']); if (isset($feedObjectAttributeMap['description'])) { $rssExportItem->setAttribute('description', $feedObjectAttributeMap['description']); } if (isset($feedObjectAttributeMap['category'])) { $rssExportItem->setAttribute('category', $feedObjectAttributeMap['category']); } if (isset($feedObjectAttributeMap['enclosure'])) { $rssExportItem->setAttribute('enclosure', $feedObjectAttributeMap['enclosure']); } $rssExportItem->setAttribute('source_node_id', $nodeID); $rssExportItem->setAttribute('status', eZRSSExport::STATUS_VALID); $rssExportItem->setAttribute('subnodes', isset($subNodesMap[$currentClassIdentifier]) && $subNodesMap[$currentClassIdentifier] === 'true'); $rssExportItem->store(); } else { eZDebug::writeError("site.ini[{$iniSection}]Source[] setting is not defined.", __METHOD__); } } $db->commit(); eZContentCacheManager::clearContentCacheIfNeeded($objectID); return array('status' => true); }
static function create($orderID, $statusID, $userID = false, $timestamp = false) { if ($timestamp === false) { $timestamp = time(); } if ($userID === false) { $userID = eZUser::currentUserID(); } $row = array('id' => null, 'order_id' => $orderID, 'status_id' => $statusID, 'modifier_id' => $userID, 'modified' => $timestamp); return new eZOrderStatusHistory($row); }
/** * remove the current subscription * @see kernel/classes/eZPersistentObject#remove($conditions, $extraConditions) */ function remove($conditions = null, $extraConditions = null) { CjwNewsletterLog::writeNotice('CjwNewsletterSubscription::remove', 'subscription', 'remove', array('nl_user' => $this->attribute('newsletter_user_id'), 'subscription_id' => $this->attribute('id'), 'modifier' => eZUser::currentUserID())); foreach ($currentNewsletterSubscriptionObjects as $subscription) { $subscription->remove(); } parent::remove($conditions, $extraConditions); }
/** * Save the draft with the provided POST fields like a click on the Store * draft button except that a validation issue on an attribute does not * prevent the others attributes to be stored. * * @param array $args array( content object id, version number, locale code ) * @return array */ public static function saveDraft($args) { // force text/plain to make IE happy... header('Content-Type: text/plain', true); $result = array('unvalidated-attributes' => array(), 'stored-attributes' => array(), 'valid' => true); $http = eZHTTPTool::instance(); // workaround to the eZContentObjectEditHandler API that needs a Module $Module = false; if (count($args) != 3) { throw new InvalidArgumentException(ezpI18n::tr('extension/ezautosave/autosave', 'This action requires 3 parameters')); } if ($_SERVER['REQUEST_METHOD'] !== 'POST') { throw new InvalidArgumentException(ezpI18n::tr('extension/ezautosave/autosave', "A POST request is expected")); } if (count($_POST) === 0) { throw new InvalidArgumentException(ezpI18n::tr('extension/ezautosave/autosave', "No POST data found, it's probably because you tried to upload a too big file")); } $contentObject = eZContentObject::fetch((int) $args[0]); if (!$contentObject instanceof eZContentObject) { throw new InvalidArgumentException(ezpI18n::tr('extension/ezautosave/autosave', 'Unable to load the content #%objectid', null, array('%objectid' => (int) $args[0]))); } if ($contentObject->attribute('status') == eZContentObject::STATUS_ARCHIVED) { throw new InvalidArgumentException(ezpI18n::tr('extension/ezautosave/autosave', 'The content #%objectid is archived', null, array('%objectid' => $contentObject->attribute('id')))); } $version = $contentObject->version((int) $args[1]); if (!$version instanceof eZContentObjectVersion) { throw new InvalidArgumentException(ezpI18n::tr('extension/ezautosave/autosave', 'Unable to load version #%versionr of content #%objectid', null, array('%versionr' => (int) $args[1], '%objectid' => $contentObject->attribute('id')))); } if ($version->attribute('status') != eZContentObjectVersion::STATUS_DRAFT && $version->attribute('status') != eZContentObjectVersion::STATUS_INTERNAL_DRAFT) { throw new RuntimeException(ezpI18n::tr('extension/ezautosave/autosave', "Version #%versionr of content #%objectid is not a draft", null, array('%versionr' => $version->attribute('version'), '%objectid' => $version->attribute('contentobject_id')))); } if ($version->attribute('creator_id') != eZUser::currentUserID()) { throw new RuntimeException(ezpI18n::tr('extension/ezautosave/autosave', "You're not allowed to store a version that is not yours")); } $editLanguage = $args[2]; $language = eZContentLanguage::fetchByLocale($editLanguage); if (!$language instanceof eZContentLanguage) { throw new InvalidArgumentException(ezpI18n::tr('extension/ezautosave/autosave', "Unable to load the language '%localeCode'", null, array('%localeCode' => $editLanguage))); } $class = eZContentClass::fetch($contentObject->attribute('contentclass_id')); $contentObjectAttributes = $version->contentObjectAttributes($editLanguage); $validationParameters = array('skip-isRequired' => true); $attributeDataBaseName = 'ContentObjectAttribute'; $validationResult = $contentObject->validateInput($contentObjectAttributes, $attributeDataBaseName, false, $validationParameters); if ($validationResult['require-fixup']) { $contentObject->fixupInput($contentObjectAttributes, $attributeDataBaseName); } $customValidationResult = eZContentObjectEditHandler::validateInputHandlers($Module, $class, $contentObject, $version, $contentObjectAttributes, $version->attribute('version'), $editLanguage, false, $validationParameters); $result['valid'] = $validationResult['input-validated'] && $customValidationResult['validated']; $invalidAttributeIds = array(); foreach ($validationResult['unvalidated-attributes'] as $info) { $invalidAttributeIds[$info['id']] = true; $result['unvalidated-attributes'][] = $info; } eZContentObjectEditHandler::executeInputHandlers($Module, $class, $contentObject, $version, $contentObjectAttributes, $version->attribute('version'), $editLanguage, false); $customActionAttributeArray = array(); $fetchResult = $contentObject->fetchInput($contentObjectAttributes, $attributeDataBaseName, $customActionAttributeArray, array()); $version->setAttribute('modified', time()); $status = eZContentObjectVersion::STATUS_INTERNAL_DRAFT; if ($http->hasPostVariable('StoreExitButton')) { $status = eZContentObjectVersion::STATUS_DRAFT; } $version->setAttribute('status', $status); $attributesToStore = array(); foreach ($fetchResult['attribute-input-map'] as $id => $value) { if (!isset($invalidAttributeIds[$id])) { $result['stored-attributes'][$id] = $id; $attributesToStore[$id] = true; } } $db = eZDB::instance(); $db->begin(); $version->store(); $contentObject->storeInput($contentObjectAttributes, $attributesToStore); $contentObject->setName($class->contentObjectName($contentObject, $version->attribute('version'), $editLanguage), $version->attribute('version'), $editLanguage); $db->commit(); $time = eZLocale::instance()->formatShortTime($version->attribute('modified')); $result['message_success'] = ezpI18n::tr('extension/ezautosave', "Draft saved at %time", null, array('%time' => $time)); $result['message_ago'] = ezpI18n::tr('extension/ezautosave', "(%min minutes ago)", null, array('%min' => 0)); $result['timestamp'] = $version->attribute('modified'); return $result; }
$createNewSubscription = 1; $newListSubscription = CjwNewsletterSubscription::create($listContentObjectId, $newsletterUserId, $outputFormatArray, CjwNewsletterSubscription::STATUS_APPROVED); $newListSubscription->setAttribute('import_id', $importId); // set new remote_id $newListSubscription->setAttribute('remote_id', 'cjwnl:csvimport:' . CjwNewsletterUtils::generateUniqueMd5Hash($newsletterUserId . $importId)); $newListSubscription->store(); $subscriptionObject = $newListSubscription; $newSubscriptionStatus = $subscriptionObject->attribute('status'); } } } $listSubscriptionArray[$rowId] = array('subscription_object' => $subscriptionObject, 'email_ok' => $emailOk, 'user_created' => $createNewUser, 'newsletter_user_id' => $newsletterUserId, 'subscription_created' => $createNewSubscription, 'user_status_old' => $existingUserStatus, 'user_status_new' => $newUserStatus, 'subscription_status_old' => $existingSubscriptionStatus, 'subscription_status_new' => $newSubscriptionStatus); } // imported timestamp + set count for imported users + subscriptions $importObject->setImported(); CjwNewsletterLog::writeNotice('subscription_list_csvimport', 'import', 'end', array('import_id' => $importObject->attribute('id'), 'current_user' => eZUser::currentUserID())); // store result to File storeImportResultToFile($importId, $listSubscriptionArray); } //} $viewParameters = array('offset' => 0, 'namefilter' => ''); $userParameters = $Params['UserParameters']; $viewParameters = array_merge($viewParameters, $userParameters); $tpl = templateInit(); $tpl->setVariable('view_parameters', $viewParameters); $tpl->setVariable('list_node', $listNode); $tpl->setVariable('import_id', $importId); $tpl->setVariable('import_object', $importObject); $tpl->setVariable('selected_output_format_array', $selectedOutputFormatArray); $tpl->setVariable('csv_data_array', $csvDataArray); $tpl->setVariable('list_subscription_array', $listSubscriptionArray);
public static function fetchPendingCount() { $userID = eZUser::currentUserID(); $pendingList = eZPersistentObject::fetchObjectList(eZContentObjectVersion::definition(), array(), array('creator_id' => $userID, 'status' => eZContentObjectVersion::STATUS_PENDING), false, null, false, false, array(array('operation' => 'count( * )', 'name' => 'count'))); return array('result' => $pendingList[0]['count']); }
/** * Create a ezsrRatingDataObject by definition data (but do not store it, thats up to you!) * NOTE: you have to provide the following attributes: * contentobject_id * contentobject_attribute_id * rating (this is only requried if you plan to store the object) * * @param array $row * @return ezsrRatingDataObject */ static function create($row = array()) { if (!isset($row['session_key'])) { $http = eZHTTPTool::instance(); $row['session_key'] = $http->sessionID(); } if (!isset($row['user_id'])) { $row['user_id'] = eZUser::currentUserID(); } if (!isset($row['created_at'])) { $row['created_at'] = time(); } if (!isset($row['contentobject_id'])) { eZDebug::writeError('Missing \'contentobject_id\' parameter!', __METHOD__); } if (!isset($row['contentobject_attribute_id'])) { eZDebug::writeError('Missing \'contentobject_attribute_id\' parameter!', __METHOD__); } $object = new self($row); return $object; }
static function create($userID = false, $optionalValues = array(), $languageLocale = false) { $dateTime = time(); if (!$userID) { $userID = eZUser::currentUserID(); } $nameList = new eZContentClassNameList(); if (isset($optionalValues['serialized_name_list'])) { $nameList->initFromSerializedList($optionalValues['serialized_name_list']); } else { if (isset($optionalValues['name'])) { $nameList->initFromString($optionalValues['name'], $languageLocale); } else { $nameList->initFromString('', $languageLocale); } } $descriptionList = new eZSerializedObjectNameList(); if (isset($optionalValues['serialized_description_list'])) { $descriptionList->initFromSerializedList($optionalValues['serialized_description_list']); } else { if (isset($optionalValues['description'])) { $descriptionList->initFromString($optionalValues['description'], $languageLocale); } else { $descriptionList->initFromString('', $languageLocale); } } $languageMask = $nameList->languageMask(); $initialLanguageID = $nameList->alwaysAvailableLanguageID(); $contentClassDefinition = eZContentClass::definition(); $row = array("id" => null, "version" => 1, "serialized_name_list" => $nameList->serializeNames(), 'serialized_description_list' => $descriptionList->serializeNames(), "identifier" => "", "contentobject_name" => "", "creator_id" => $userID, "modifier_id" => $userID, "created" => $dateTime, 'remote_id' => eZRemoteIdUtility::generate('class'), "modified" => $dateTime, "is_container" => $contentClassDefinition['fields']['is_container']['default'], "always_available" => $contentClassDefinition['fields']['always_available']['default'], 'language_mask' => $languageMask, 'initial_language_id' => $initialLanguageID, "sort_field" => $contentClassDefinition['fields']['sort_field']['default'], "sort_order" => $contentClassDefinition['fields']['sort_order']['default']); $row = array_merge($row, $optionalValues); $contentClass = new eZContentClass($row); // setting 'dirtyData' to make sure the 'NameList' will be stored into db. $contentClass->NameList->setHasDirtyData(true); return $contentClass; }
/** * Removes all old internal drafts by the specified user for the past time span given by $timeDuration * * @param int|bool $userID The ID of the user to cleanup for, if false it will use the current user. * @param int $timeDuration default time duration for internal drafts 60*60*24 seconds (1 day) */ static function cleanupAllInternalDrafts( $userID = false, $timeDuration = 86400 ) // { if ( !is_numeric( $timeDuration ) || $timeDuration < 0 ) { eZDebug::writeError( "The time duration must be a positive numeric value (timeDuration = $timeDuration)", __METHOD__ ); return; } if ( $userID === false ) { $userID = eZUser::currentUserID(); } // Remove all internal drafts $untouchedDrafts = eZContentObjectVersion::fetchForUser( $userID, eZContentObjectVersion::STATUS_INTERNAL_DRAFT ); $expiryTime = time() - $timeDuration; // only remove drafts older than time duration (default is 1 day) foreach ( $untouchedDrafts as $untouchedDraft ) { if ( $untouchedDraft->attribute( 'modified' ) < $expiryTime ) { $untouchedDraft->removeThis(); } } }
static function checkDebugByUser() { if (!isset($GLOBALS['eZDebugUserIDList']) || !is_array($GLOBALS['eZDebugUserIDList'])) { return false; } else { $currentUserID = eZUser::currentUserID(); if (!$currentUserID) { return false; } else { $GLOBALS['eZDebugAllowedByUser'] = in_array($currentUserID, $GLOBALS['eZDebugUserIDList']); if ($GLOBALS['eZDebugAllowed']) { $GLOBALS['eZDebugAllowed'] = $GLOBALS['eZDebugAllowedByUser']; } if ($GLOBALS['eZDebugEnabled']) { $GLOBALS['eZDebugEnabled'] = $GLOBALS['eZDebugAllowedByUser']; } unset($GLOBALS['eZDebugUserIDList']); return true; } } }
function modifyStatus($statusID, $userID = false) { $db = eZDB::instance(); $db->begin(); $time = time(); if ($userID === false) { $userID = eZUser::currentUserID(); } $history = eZOrderStatusHistory::create($this->OrderNr, $statusID, $userID, $time); $history->store(); $this->StatusID = $statusID; $this->StatusModified = $time; $this->StatusModifierID = $userID; $this->store(); $db->commit(); }
static function fetchListTool($parameters = array(), $asCount) { $parameters = array_merge(array('as_object' => true, 'offset' => false, 'parent_group_id' => false, 'limit' => false, 'is_active' => null, 'is_read' => null, 'status' => false, 'sort_by' => false), $parameters); $asObject = $parameters['as_object']; $offset = $parameters['offset']; $limit = $parameters['limit']; $statusTypes = $parameters['status']; $isRead = $parameters['is_read']; $isActive = $parameters['is_active']; $parentGroupID = $parameters['parent_group_id']; $sortText = ''; if (!$asCount) { $sortCount = 0; $sortList = $parameters['sort_by']; if (is_array($sortList) and count($sortList) > 0) { if (count($sortList) > 1 and !is_array($sortList[0])) { $sortList = array($sortList); } } if ($sortList !== false) { $sortingFields = ''; foreach ($sortList as $sortBy) { if (is_array($sortBy) and count($sortBy) > 0) { if ($sortCount > 0) { $sortingFields .= ', '; } $sortField = $sortBy[0]; switch ($sortField) { case 'created': $sortingFields .= 'ezcollab_item_group_link.created'; break; case 'modified': $sortingFields .= 'ezcollab_item_group_link.modified'; break; default: eZDebug::writeWarning('Unknown sort field: ' . $sortField, __METHOD__); continue; } $sortOrder = true; // true is ascending if (isset($sortBy[1])) { $sortOrder = $sortBy[1]; } $sortingFields .= $sortOrder ? ' ASC' : ' DESC'; ++$sortCount; } } } if ($sortCount == 0) { $sortingFields = ' ezcollab_item_group_link.modified DESC'; } $sortText = "ORDER BY {$sortingFields}"; } $parentGroupText = ''; if ($parentGroupID > 0) { $parentGroupText = "ezcollab_item_group_link.group_id = '{$parentGroupID}' AND"; } $isReadText = ''; if ($isRead !== null) { $isReadValue = $isRead ? 1 : 0; $isReadText = "ezcollab_item_status.is_read = '{$isReadValue}' AND"; } $isActiveText = ''; if ($isActive !== null) { $isActiveValue = $isActive ? 1 : 0; $isActiveText = "ezcollab_item_status.is_active = '{$isActiveValue}' AND"; } $userID = eZUser::currentUserID(); $statusText = ''; if ($statusTypes === false) { $statusTypes = array(self::STATUS_ACTIVE, self::STATUS_INACTIVE); } $statusText = implode(', ', $statusTypes); if ($asCount) { $selectText = 'count( ezcollab_item.id ) as count'; } else { $selectText = 'ezcollab_item.*, ezcollab_item_status.is_read, ezcollab_item_status.is_active, ezcollab_item_status.last_read'; } $sql = "SELECT {$selectText}\n FROM\n ezcollab_item,\n ezcollab_item_status,\n ezcollab_item_group_link\n WHERE ezcollab_item.status IN ( {$statusText} ) AND\n {$isReadText}\n {$isActiveText}\n ezcollab_item.id = ezcollab_item_status.collaboration_id AND\n ezcollab_item.id = ezcollab_item_group_link.collaboration_id AND\n {$parentGroupText}\n ezcollab_item_status.user_id = '{$userID}' AND\n ezcollab_item_group_link.user_id = '{$userID}'\n {$sortText}"; $db = eZDB::instance(); if (!$asCount) { $sqlParameters = array(); if ($offset !== false and $limit !== false) { $sqlParameters['offset'] = $offset; $sqlParameters['limit'] = $limit; } $itemListArray = $db->arrayQuery($sql, $sqlParameters); foreach ($itemListArray as $key => $value) { $itemData =& $itemListArray[$key]; $statusObject = eZCollaborationItemStatus::create($itemData['id'], $userID); $statusObject->setAttribute('is_read', $itemData['is_read']); $statusObject->setAttribute('is_active', $itemData['is_active']); $statusObject->setAttribute('last_read', $itemData['last_read']); $statusObject->updateCache(); } $returnItemList = eZPersistentObject::handleRows($itemListArray, 'eZCollaborationItem', $asObject); eZDebugSetting::writeDebug('collaboration-item-list', $returnItemList); return $returnItemList; } else { $itemCount = $db->arrayQuery($sql); return $itemCount[0]['count']; } }
static function temporaryExportPath() { $path = eZDir::path(array(eZSys::cacheDirectory(), 'packages', 'export' . eZUser::currentUserID())); return $path; }