/**
  * validate field in editing comment
  * @see extension/ezcomments/classes/ezcomFormTool#validateField($field, $value)
  */
 protected function validateField($field, $value)
 {
     switch ($field) {
         case 'website':
             return ezcomUtility::validateURLString($value);
         default:
             return true;
     }
     return true;
 }
Ejemplo n.º 2
0
 public function testValidateURLString()
 {
     $url1 = 'javascript:alert();';
     $url2 = 'mailto:xc@ez.no';
     $url3 = 'JavaScript:alert()';
     $url4 = 'mAilto:xc@ez.no';
     $url5 = 'http://ez.no';
     $result = ezcomUtility::validateURLString($url1);
     $this->assertType('string', $result);
     $result = ezcomUtility::validateURLString($url2);
     $this->assertType('string', $result);
     $result = ezcomUtility::validateURLString($url3);
     $this->assertType('string', $result);
     $result = ezcomUtility::validateURLString($url4);
     $this->assertType('string', $result);
     $result = ezcomUtility::validateURLString($url5);
     $this->assertSame(true, $result);
 }
 public function testActivateSubscription()
 {
     $subscriber = ezcomSubscriber::create();
     $subscriber->setAttribute('email', '*****@*****.**');
     $subscriber->setAttribute('user_id', 10);
     $subscriber->store();
     $subscription = ezcomSubscription::create();
     $subscription->setAttribute('subscriber_id', $subscriber->attribute('id'));
     $subscription->setAttribute('subscriber_type', 'ezcomcomment');
     $subscription->setAttribute('enabled', 0);
     $subscription->setAttribute('content_id', '10_2');
     $hashString = ezcomUtility::instance()->generateSubscriptionHashString($subscription);
     $subscription->setAttribute('hash_string', $hashString);
     $subscription->store();
     $id = $subscription->attribute('id');
     $tpl = eZTemplate::factory();
     $subscriptionManager = ezcomSubscriptionManager::instance($tpl, null, null, 'ezcomSubscriptionManager');
     $subscriptionManager->activateSubscription($hashString);
     $subscriptionActivated = ezcomSubscription::fetch($id);
     $this->assertEquals(1, $subscriptionActivated->attribute('enabled'));
 }
 /**
  * Implement the validatation in adding comment
  * @see extension/ezcomments/classes/ezcomFormTool#validateField($field)
  */
 protected function validateField($field, $value)
 {
     switch ($field) {
         case 'website':
             return ezcomUtility::validateURLString($value);
         case 'email':
             // just validate anonymous's input email
             $user = eZUser::currentUser();
             if ($user->isAnonymous()) {
                 $result = eZMail::validate($value);
                 if (!$result) {
                     return ezpI18n::tr('ezcomments/comment/add', 'Not a valid email address.');
                 }
             }
             return true;
         case 'recaptcha':
             require_once 'recaptchalib.php';
             $ini = eZINI::instance('ezcomments.ini');
             $privateKey = $ini->variable('RecaptchaSetting', 'PrivateKey');
             $http = eZHTTPTool::instance();
             if ($http->hasPostVariable('recaptcha_challenge_field') && $http->hasPostVariable('recaptcha_response_field')) {
                 $ip = $_SERVER["REMOTE_ADDR"];
                 $challengeField = $http->postVariable('recaptcha_challenge_field');
                 $responseField = $http->postVariable('recaptcha_response_field');
                 $capchaResponse = recaptcha_check_answer($privateKey, $ip, $challengeField, $responseField);
                 if (!$capchaResponse->is_valid) {
                     return ezpI18n::tr('ezcomments/comment/add', 'The words you input are incorrect.');
                 }
             } else {
                 return ezpI18n::tr('ezcomments/comment/add', 'Captcha parameter error.');
             }
             return true;
         default:
             return true;
     }
 }
Ejemplo n.º 5
0
Archivo: add.php Proyecto: legende91/ez
     // missing form data
     $tpl->setVariable('error_message', ezpI18n::tr('ezcomments/comment/add/form', 'There is a problem with your comment form '));
     $tpl->setVariable('validation_messages', $formTool->messages());
     $Result['content'] = $tpl->fetch('design:comment/add.tpl');
     return $Result;
 }
 //TODO: from 63, most of the code can be implemented in a class see another TODO in edit.php
 // Build ezcomcomment object
 $comment = ezcomComment::create();
 $formTool->fillObject($comment);
 $comment->setAttribute('contentobject_id', $contentObjectId);
 $languageId = eZContentLanguage::idByLocale($languageCode);
 $comment->setAttribute('language_id', $languageId);
 $sessionKey = $http->getSessionKey();
 $comment->setAttribute('session_key', $sessionKey);
 $util = ezcomUtility::instance();
 $ip = $util->getUserIP();
 $comment->setAttribute('ip', $ip);
 $user = eZUser::currentUser();
 $comment->setAttribute('user_id', $user->attribute('contentobject_id'));
 $currentTime = time();
 $comment->setAttribute('created', $currentTime);
 $comment->setAttribute('modified', $currentTime);
 // toggle notification state on change in state
 // only when notification is enabled, the notification can be changed
 // when email is enabled or email is disabled in setting but user logged in, change notification
 $notification = $formTool->fieldValue('notificationField');
 $email = $comment->attribute('email');
 $changeNotification = false;
 if ($notification === true) {
     // email is enabled in setting
 /**
  * Add an subscription. If the subscriber is disabled, throw an exception
  * If there is no subscriber, add one.
  * If there is no subscription for the content, add one
  * @param $email: user's email
  * @return void
  */
 public function addSubscription($email, $user, $contentID, $languageID, $subscriptionType, $currentTime, $activate = true)
 {
     //1. insert into subscriber
     $ezcommentsINI = eZINI::instance('ezcomments.ini');
     $subscriber = ezcomSubscriber::fetchByEmail($email);
     //if there is no data in subscriber for same email, save it
     if (is_null($subscriber)) {
         $subscriber = ezcomSubscriber::create();
         $subscriber->setAttribute('user_id', $user->attribute('contentobject_id'));
         $subscriber->setAttribute('email', $email);
         if ($user->isAnonymous()) {
             $util = ezcomUtility::instance();
             $hashString = $util->generateSusbcriberHashString($subscriber);
             $subscriber->setAttribute('hash_string', $hashString);
         }
         $subscriber->store();
         eZDebugSetting::writeNotice('extension-ezcomments', 'Subscriber does not exist, added one', __METHOD__);
         $subscriber = ezcomSubscriber::fetchByEmail($email);
     } else {
         if ($subscriber->attribute('enabled') == false) {
             throw new Exception('Subscription can not be added because the subscriber is disabled.', self::ERROR_SUBSCRIBER_DISABLED);
         }
     }
     //3 insert into subscription table
     // if there is no data in ezcomment_subscription with given contentobject_id and subscriber_id
     $hasSubscription = ezcomSubscription::exists($contentID, $languageID, $subscriptionType, $email);
     if ($hasSubscription === false) {
         $subscription = ezcomSubscription::create();
         $subscription->setAttribute('user_id', $user->attribute('contentobject_id'));
         $subscription->setAttribute('subscriber_id', $subscriber->attribute('id'));
         $subscription->setAttribute('subscription_type', $subscriptionType);
         $subscription->setAttribute('content_id', $contentID);
         $subscription->setAttribute('language_id', $languageID);
         $subscription->setAttribute('subscription_time', $currentTime);
         $defaultActivated = $ezcommentsINI->variable('CommentSettings', 'SubscriptionActivated');
         if ($user->isAnonymous() && $defaultActivated !== 'true' && $activate === true) {
             $subscription->setAttribute('enabled', 0);
             $utility = ezcomUtility::instance();
             $subscription->setAttribute('hash_string', $utility->generateSubscriptionHashString($subscription));
             $subscription->store();
             $result = ezcomSubscriptionManager::sendActivationEmail(eZContentObject::fetch($contentID), $subscriber, $subscription);
             if (!$result) {
                 eZDebug::writeError("Error sending mail to '{$email}'", __METHOD__);
             }
         } else {
             $subscription->setAttribute('enabled', 1);
             $subscription->store();
         }
         eZDebugSetting::writeNotice('extension-ezcomments', 'No existing subscription for this content and user, added one', __METHOD__);
     }
 }