/** * Rate content object attribute id * * @param array $args ( 0 => contentobjectattribute_id, 1 => contentobject_version, 2 => rating ) * @return array */ public static function rate($args) { $ret = array('id' => 0, 'rated' => false, 'already_rated' => false, 'stats' => false); if (isset($args[0])) { $ret['id'] = $args[0]; } if (!isset($args[2]) || !is_numeric($args[0]) || !is_numeric($args[1]) || !is_numeric($args[2]) || $args[2] > 5 || $args[2] < 1) { return $ret; } // Provide extra session protection on 4.1 (not possible on 4.0) by expecting user // to have an existing session (new session = mostlikely a spammer / hacker trying to manipulate rating) if (class_exists('eZSession') && eZSession::userHasSessionCookie() !== true) { return $ret; } // Return if parameters are not valid attribute id + version numbers $contentobjectAttribute = eZContentObjectAttribute::fetch($ret['id'], $args[1]); if (!$contentobjectAttribute instanceof eZContentObjectAttribute) { return $ret; } // Return if attribute is not a rating attribute if ($contentobjectAttribute->attribute('data_type_string') !== ezsrRatingType::DATA_TYPE_STRING) { return $ret; } // Return if rating has been disabled on current attribute if ($contentobjectAttribute->attribute('data_int')) { return $ret; } // Return if user does not have access to object $contentobject = $contentobjectAttribute->attribute('object'); if (!$contentobject instanceof eZContentObject || !$contentobject->attribute('can_read')) { return $ret; } $rateDataObj = ezsrRatingDataObject::create(array('contentobject_id' => $contentobjectAttribute->attribute('contentobject_id'), 'contentobject_attribute_id' => $ret['id'], 'rating' => $args[2])); $proiorRating = $rateDataObj->userHasRated(true); if ($proiorRating === true) { $ret['already_rated'] = true; } else { if ($proiorRating instanceof ezsrRatingDataObject) { $rateDataObj = $proiorRating; $rateDataObj->setAttribute('rating', $args[2]); $ret['already_rated'] = true; $proiorRating = false; // just to reuse code bellow } } if (!$proiorRating) { $rateDataObj->store(); $avgRateObj = $rateDataObj->getAverageRating(); $avgRateObj->updateFromRatingData(); $avgRateObj->store(); eZContentCacheManager::clearContentCacheIfNeeded($rateDataObj->attribute('contentobject_id')); $ret['rated'] = true; $ret['stats'] = array('rating_count' => $avgRateObj->attribute('rating_count'), 'rating_average' => $avgRateObj->attribute('rating_average'), 'rounded_average' => $avgRateObj->attribute('rounded_average')); } return $ret; }
$userClientValidates = true; $doValidationRedirect = false; if (!eZSession::userHasSessionCookie()) { if ($redirectNumber == '2') { $userClientValidates = false; } else { $doValidationRedirect = true; } } if ($doValidationRedirect) { $db->rollback(); return $Module->redirectTo('/user/register/2'); } else { if (!$userClientValidates) { $db->rollback(); $tpl->setVariable('user_has_cookie', eZSession::userHasSessionCookie(), 'User'); $tpl->setVariable('user_session_validates', true, 'User'); $Result = array(); $Result['content'] = $tpl->fetch('design:user/register_user_not_valid.tpl'); $Result['path'] = array(array('url' => false, 'text' => ezpI18n::tr('kernel/user', 'User')), array('url' => false, 'text' => ezpI18n::tr('kernel/user', 'Register'))); return $Result; } } // else create user object if ($http->hasSessionVariable('StartedRegistration')) { eZDebug::writeWarning('Cancel module run to protect against multiple form submits', 'user/register'); $http->removeSessionVariable("RegisterUserID"); $http->removeSessionVariable('StartedRegistration'); $db->commit(); return eZModule::HOOK_STATUS_CANCEL_RUN; } else {
/** * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 * @version //autogentag// * @package kernel */ $tpl = eZTemplate::factory(); $http = eZHTTPTool::instance(); $Offset = $Params['Offset']; if (!is_numeric($Offset)) { $Offset = 0; } $parents = array(); // Make sure user has session (if not, then this can't possible be a valid browse request) if (!eZSession::userHasSessionCookie()) { return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel'); } // Check that Browse parameters exists if (!$http->hasSessionVariable('BrowseParameters')) { return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel'); } // Check if node parameters exist $browse = new eZContentBrowse(); if (!isset($Params['NodeID']) && !isset($Params['NodeList']) && !$browse->hasAttribute('start_node')) { return $Module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel'); } // We get node list when browse is execiuted from search engine ( "search in browse" functionality ) if (isset($Params['NodeList'])) { $nodeList = $Params['NodeList']['SearchResult']; $nodeListCount = $Params['NodeList']['SearchCount'];
/** * Rate content object attribute id * * @param array $args ( 0 => contentobjectattribute_id, 1 => contentobject_version, 2 => rating ) * @return array */ public static function rate( $args ) { $ret = array( 'id' => 0, 'rated' => false, 'already_rated' => false, 'stats' => false ); if ( !isset( $args[2] ) ) throw new LengthException( 'Rating expects 3 arguments: attr_id, version, rating' ); else if ( !is_numeric( $args[0] ) ) throw new InvalidArgumentException( 'Rating argument[0] attr_id must be a number' ); else if ( !is_numeric( $args[1] ) ) throw new InvalidArgumentException( 'Rating argument[1] version must be a number' ); else if ( !is_numeric( $args[2] ) ) throw new InvalidArgumentException( 'Rating argument[2] rating must be a number' ); else if ( $args[2] > 5 || $args[2] < 1 ) throw new UnexpectedValueException( 'Rating argument[2] rating must be between 1 and 5' ); $ret['id'] = (int) $args[0]; // Provide extra session protection on 4.1 (not possible on 4.0) by expecting user // to have an existing session (new session = mostlikely a spammer / hacker trying to manipulate rating) if ( eZSession::userHasSessionCookie() !== true && eZINI::instance()->variable( 'eZStarRating', 'AllowAnonymousRating' ) === 'disabled' ) return $ret; // Return if parameters are not valid attribute id + version numbers $contentobjectAttribute = eZContentObjectAttribute::fetch( $ret['id'], $args[1] ); if ( !$contentobjectAttribute instanceof eZContentObjectAttribute ) return $ret; // Return if attribute is not a rating attribute if ( $contentobjectAttribute->attribute('data_type_string') !== ezsrRatingType::DATA_TYPE_STRING ) return $ret; // Return if rating has been disabled on current attribute if ( $contentobjectAttribute->attribute('data_int') ) return $ret; // Return if user does not have access to object $contentobject = $contentobjectAttribute->attribute('object'); if ( !$contentobject instanceof eZContentObject || !$contentobject->attribute('can_read') ) return $ret; $rateDataObj = ezsrRatingDataObject::create( array( 'contentobject_id' => $contentobjectAttribute->attribute('contentobject_id'), 'contentobject_attribute_id' => $ret['id'], 'rating' => $args[2] )); $proiorRating = $rateDataObj->userHasRated( true ); if ( $proiorRating === true ) { $ret['already_rated'] = true; } else if ( $proiorRating instanceof ezsrRatingDataObject ) { $rateDataObj = $proiorRating; $rateDataObj->setAttribute( 'rating', $args[2] ); $ret['already_rated'] = true; $proiorRating = false;// just to reuse code bellow } if ( !$proiorRating ) { $rateDataObj->store(); $avgRateObj = $rateDataObj->getAverageRating(); $avgRateObj->updateFromRatingData(); $avgRateObj->store(); eZContentCacheManager::clearContentCacheIfNeeded( $rateDataObj->attribute('contentobject_id') ); $ret['rated'] = true; $ret['stats'] = array( 'rating_count' => $avgRateObj->attribute('rating_count'), 'rating_average' => $avgRateObj->attribute('rating_average'), 'rounded_average' => $avgRateObj->attribute('rounded_average'), ); } return $ret; }