Esempio n. 1
0
    /**
     * @param ChannelBlock $block
     * @return mixed
     */
    private function getLimit(ChannelBlock $block)
    {
        if(contextTool::instance()->isMobile())
        {
            if($block->attribute("mobile_limit"))
            {
                return $block->attribute("mobile_limit");
            }
        }
        else
        {
            if($block->attribute("desktop_limit"))
            {
                return $block->attribute("desktop_limit");
            }
        }

        return 100;
    }
Esempio n. 2
0
	    'fl'           => 'attr_headline_s',
	    'qt'           => 'ezpublish',
	    'explainOther' => '',
	    'hl.fl'        => '',
	    'sort'         => 'score desc',
	);

	$additionalParams = $resultHandler->solrHighlightParams();
	$params = array_merge( $params, $additionalParams );

	$results = solrTool::rawSearch( $params );

	$response = array(
		'term'       => $keyword,
		'count'      => $results['response']['numFound'],
		'result_url' => contextTool::instance()->domain() . '/' . $globalSearchURi . '/#?q=' . urlencode( $keyword )
	);

    ob_clean();

	switch( $responseFormat )
	{
		case 'xml':
			header( 'Content-Type: application/xml' );
			$xml = new SimpleXMLElement( '<response/>' );
			$xml->addChild( 'term', $response['term'] );
			$xml->addChild( 'count', $response['count'] );
			$xml->addChild( 'result_url', $response['result_url'] );
			print $xml->asXML();
			break;
		case 'json':
    /**
     * Create token and send password reset request email
     *
     * @return array
     */
    public function t()
    {
        $http = BlockDefault::http();
        $isConsult = (bool) $http->postVariable('consult');

        $token = $http->postVariable('token');
        if(!SecurityTool::isUserTokenValid($token))
        {
            return array(
                'errorCode' =>  ResponseError::ERROR_REQUEST_EXECUTION,
                'msg'       =>  'Invalid token',
            );
        }

        $username = $http->postVariable('Username');
        if (empty($username))
        {
            return array(
                'errorCode' => ResponseError::ERROR_USERNAME_MISSING,
                'msg' => 'Username missing'
            );
        }
        eZLog::write(var_export('We have username.', true) , 'resetpass.log');
        $countryOfRegistration = eZINI::instance('site.ini')->variable('RegionalSettings', 'CountryOfRegistration');
        if (empty($countryOfRegistration))
        {
            return array(
                'errorCode' => ResponseError::ERROR_COUNTRY_NOT_SPECIFIED,
                'msg' => 'Country of registration not set'
            );
        }
        eZLog::write(var_export('We have countrycode.', true) , 'resetpass.log');

        try
        {
            eZLog::write(var_export('Sending request for token.', true) , 'resetpass.log');
            $esbClient = self::getEsbClient();
            $response = $esbClient->createToken($username, $countryOfRegistration);

            eZLog::write(var_export('We got response:.', true) , 'resetpass.log');
            eZLog::write(var_export($response, true) , 'resetpass.log');
        }
        catch(\Exception $e)
        {
            return array(
                'errorCode' => ResponseError::ERROR_REQUEST_EXECUTION,
                'msg' => $e->getMessage()
            );
        }
        eZLog::write(var_export('We have token.', true) , 'resetpass.log');

        $token = self::encryptToken($response);

        eZLog::write("TOKEN: {$token}", 'esb_uump.log');
        eZLog::write("TOKEN: {$token}", 'resetpass.log');
        eZLog::write(var_export('Consult status: ' . $isConsult, true) , 'resetpass.log');
        eZLog::write(var_export('Sending an email with pass reset.', true) , 'resetpass.log');

        self::sendResetPasswordMail($token, $response['userId'], $response['email'], $isConsult);

        if($isConsult)
        {
            $confirmationUrl = $this->getCustomParameter('ConsultEmailSentUrl');
        }
        else
        {
            $confirmationUrl = $this->getCustomParameter('EmailSentUrl');
        }
        if( !preg_match('#^https?://[^/]+#', $confirmationUrl) )
        {
            $confirmationUrl = contextTool::instance()->domain().$confirmationUrl;
        }

        eZLog::write(var_export('After email.', true) , 'resetpass.log');
        eZLog::write(var_export(array(
            'errorCode' => ResponseError::SUCCESS,
            'redirectUrl' => $confirmationUrl
        ), true) , 'resetpass.log');

        return array(
            'errorCode' => ResponseError::SUCCESS,
            'redirectUrl' => $confirmationUrl
        );
    }
    /**
     * Logs the user in eZPublish taking the data from the ESB
     * /!\ Does not check login / password. This check needs to be done before!!!!!
     *
     * @param string $uuid
     * @param ESBResult $esbResult
     * @param boolean $rememberMe
     * @param boolean $context
     * @return array destUrl or null if error
     */
    public static function esbLogin( $uuid, $esbResult, $rememberMe = false, $context = false )
    {
        $localizedLoginApplication = CacheApplicationTool::buildLocalizedApplicationByIdentifier( 'login' );

        $validationStatus = $esbResult->getValidationStatus();
        if ( $validationStatus == 'PV' && $localizedLoginApplication->getCustomParameter( 'RestrictPendingUsers' ) == 1 )
        {
            UserLog::instance()->esb_status('Pending')->store();
            
            $redirectURL = eZINI::instance( 'site.ini' )->variable( 'SiteSettings', 'PendingUserStaticPage' );
            if( SolrSafeOperatorHelper::featureIsActive( 'GoogleAnalytics' ) )
            {
                $redirectURL = $redirectURL . '#?vs=PV';
            }
            header( "Location: $redirectURL" );
            eZExecution::cleanExit();
        }
        else if ( $validationStatus == 'RP' && $localizedLoginApplication->getCustomParameter( 'RestrictRejectedUsers' ) == 1 )
        {
            UserLog::instance()->esb_status('Rejected')->store();
            
            $redirectURL = eZINI::instance( 'site.ini' )->variable( 'SiteSettings', 'RejectedUserStaticPage' );
            if( SolrSafeOperatorHelper::featureIsActive( 'GoogleAnalytics' ) )
            {
                $redirectURL = $redirectURL . '#?vs=RP';
            }
            header( "Location: $redirectURL" );
            eZExecution::cleanExit();
        }

        if( is_null($esbResult->countryOfRegistration))
            $esbResult->countryOfRegistration = eZINI::instance()->variable( 'RegionalSettings', 'CountryOfRegistration' );

        if( is_null($esbResult->userSpecialty) )
        {
            self::logError( $uuid, null, $esbResult->toTicket(), 'Missing main specialty' );
            return null;
        }

        if( is_null( $esbResult->customerType ) )
        {
            self::logError( $uuid, null, $esbResult->toTicket(), 'Missing Customer type' );
            return null;
        }

        // temporary fix to parse forced string prepended with A
        $userSpeciality = $esbResult->userSpecialty = preg_replace( '#^A#', '', $esbResult->userSpecialty );
        $customerType = $esbResult->customerType = preg_replace( '#^A#', '', $esbResult->customerType );

        if( !preg_match('#^216\.#', $userSpeciality) )
        {
            self::logError( $uuid, null, $esbResult->toTicket(), "Invalid User specialty: $userSpeciality" );
            return null;
        }
        if( !preg_match( '#^102\.#', $customerType ) )
        {
            self::logError( $uuid, null, $esbResult->toTicket(), "Invalid Customer type: $customerType" );
            return null;
        }

        $esbResult->userName = $uuid;
        $esbResult->rememberMe = $rememberMe;
        $decodedContext = urldecode(urldecode($context));

        // If we need to check the Terms of Use for the cluster, we need to skip my-newsletters app for legal reasons (1-click unsubscribe).
        $toUToCheck = (    eZINI::instance( 'merck.ini')->hasVariable( 'LoginSettings', 'ToUCheck')
            && eZINI::instance( 'merck.ini' )->variable( 'LoginSettings', 'ToUCheck') == 'enabled'
            && !strpos($decodedContext, 'my-newsletters')
        );

        if( $toUToCheck ){
            $toUValidated = ( $esbResult->termsOfUse );
            $toUValidated &= ( $esbResult->privacyPolicy );

            if( $esbResult->forceToUValidated )
                $toUValidated = true;

            $esbResult->toUValidated = (bool)$toUValidated;
        }

        // Check if we need to check the autologin status for the cluster
        if( SolrSafeOperatorHelper::featureIsActive('RestrictAutologgedInUsers') && SolrSafeOperatorHelper::feature('RestrictAutologgedInUsers', 'Restricted')
            && in_array( $esbResult->autologin, array( 1, "yes" ) ))
        {
            $esbResult->autologin = true;
        }
        else
        {
            $esbResult->autologin = false;
        }

        if ( self::loginUser( $esbResult->toTicket() ) )
        {
            $user = MMUsers::getCurrentUserObject();

            $destUrl = ContextTool::instance()->contextUrl( $context );

            if( $toUToCheck && !$user->toUValidated() )
            {
                if( preg_match('#^(?:https?://[^/]+)'.eZINI::instance()->variable('SiteSettings', 'ToUAgreementPage').'?#', $destUrl) )
                    $destUrl = '/';
                $destUrl = preg_replace('#^https?://([^?]+)//#', '\1', $destUrl);
                $destUrl = eZINI::instance()->variable('SiteSettings', 'ToUAgreementPage')
                    .'?context='.urlencode($destUrl);
            }

            // Store user action in mm_front_user_action table
            $mmFrontUserAction = MMFrontUserAction::fetchByUsername( $esbResult->userName );
            if ( $mmFrontUserAction instanceof MMFrontUserAction )
            {
                $mmFrontUserAction->LastVisitDate = date( 'Y-m-d H:i:s' );
                $mmFrontUserAction->Processed = MMFrontUserAction::PROCESSED;
                $mmFrontUserAction->store(array('processed', 'last_visit_date'));
            }
            else
            {
                $mmFrontUserAction = MMFrontUserAction::create( array(
                        'id' => null,
                        'username' => $esbResult->userName,
                        'country_registration' => $esbResult->countryOfRegistration,
                        'processed' => MMFrontUserAction::PROCESSED,
                        'last_visit_date' => date( 'Y-m-d H:i:s' ),
                ) );
                $mmFrontUserAction->store();
            }

            if ( $rememberMe )
            {
                $userKey = !is_null($esbResult->userId) ? $esbResult->userId : $uuid;
                $cookieExpiration = time() + eZINI::instance( 'merck.ini' )->variable( 'TIBCOCookieSettings', 'TIBCOCookieExpiration' );
               
                //fix to remove the old cookie for new sso cluster #39800
                $splitDepth = eZINI::instance('merck.ini')->variable( 'CookieSettings', 'CookieDomainSplitDepth' );
                $splitDepth= 0;
                if( $splitDepth == 0 ) {
                    $cookieDomain = preg_replace('#^(https?://)?([^.]+.){1}#', '', contextTool::instance()->domain() );
                    $cookieExpirationToDelete = time() - 2000;
                    setcookie( 'remember_me', '', self::encryptText(json_encode($userKey)), $cookieExpirationToDelete, '/', $cookieDomain );
                }//end fix
                setcookie( 'remember_me', self::encryptText(json_encode($userKey)), $cookieExpiration, '/', CookieTool::getCookieDomain() );
            }
            else
            {
                $cookieExpiration = 0;
            }

            // Set cookie
            $esbSessionId = $esbResult->sessionID;
            $countryCode = '';
            if ( !empty( $esbSessionId ) )
            {
                $cookieName   = eZINI::instance( 'merck.ini' )->variable( 'TIBCOCookieSettings', 'TIBCOCookieName' );
                $esbSessionId = str_replace( ' ', '+', '"'.urldecode($esbSessionId).'"' );
                setrawcookie( $cookieName, $esbSessionId, $cookieExpiration, '/', CookieTool::getCookieDomain() );
            }
            
            // set residenceCountry country code for google tag manager
            $countryOfResidence = $esbResult->othersParams['countryOfResidence'] ? $esbResult->othersParams['countryOfResidence'] : ($esbResult->othersParams['Country_of_residence'] ? $esbResult->othersParams['Country_of_residence'] : null );
            if($countryOfResidence)
            {
                if($countryOfResidence > 2)
                {
                    $countries = SolrSafeOperatorHelper::clusterIni('CountryCode','CountryCode','merck.ini');
                    $countryCode = $countries[$esbResult->othersParams['Country_of_residence']];
                }
            }
            else
            {
                $countryCode = $esbResult->countryOfRegistration;
            }
            
            $esbResult -> setResidenceCountry($countryCode);
              
            return array(
                'destUrl' => $destUrl,
                'params'  => $esbResult->toTicket(),
            );
        }

        return null;
    }