protected function getDiaryCommentFormParameter(sfWebRequest $request, $memberId)
 {
     $form = array('diary_id' => null, 'body' => null, 'image' => null);
     $form['diary_id'] = $request->getParameter('diary_id');
     if (!$form['diary_id']) {
         throw new opDiaryPluginAPIException('diary_id parameter is not specified.');
     }
     $diary = Doctrine::getTable('Diary')->findOneById($form['diary_id']);
     if (!$diary || !$diary->isViewable($memberId)) {
         throw new opDiaryPluginAPIException('invalid diary_id');
     }
     try {
         $validator = new opValidatorString(array('trim' => true, 'required' => true));
         $form['body'] = $validator->clean($request->getParameter('body'));
     } catch (sfValidatorError $e) {
         throw new opDiaryPluginAPIException('invalid body');
     }
     $limit = sfConfig::get('app_smt_comment_post_limit');
     if ($limit && mb_strlen($request['body']) > $limit) {
         throw new opDiaryPluginAPIException('body parameter is too long');
     }
     $images = $this->getImageFiles($request->getFiles());
     $form['image'] = $images['comment-image'];
     return $form;
 }
 public function validatePluginName($validator, $value, $arguments)
 {
     $_validator = new opValidatorString(array('max_length' => 64));
     $value = $_validator->clean($value);
     if (!preg_match('/^op.+Plugin$/', $value)) {
         throw new sfValidatorError($validator, 'invalid');
     }
     return $value;
 }
 protected function isValidNameAndBody($name, $body)
 {
     try {
         $validator = new opValidatorString(array('trim' => true, 'required' => true));
         $cleanName = $validator->clean($name);
         $cleanBody = $validator->clean($body);
     } catch (sfValidatorError $e) {
         $this->forward400Unless(isset($cleanName), 'name parameter is not specified.');
         $this->forward400Unless(isset($cleanBody), 'body parameter is not specified.');
     }
 }
 public function validatePhoto($validator, $value, $arguments)
 {
     $validatorFile = new opValidatorImageFile();
     $validatorString = new opValidatorString(array('trim' => true, 'max_length' => 140, 'required' => false));
     try {
         $value['file'] = $validatorFile->clean($value['file']);
         $value['description'] = $validatorString->clean($value['description']);
     } catch (sfValidatorError $e) {
         if ('required' !== $e->getCode()) {
             throw $e;
         }
         $value['description'] = '';
         $value['file'] = null;
     }
     return $value;
 }
 protected function doClean($value)
 {
     if ($this->getOption('shortenUrl')) {
         $value = $this->shortenText($value);
     }
     return parent::doClean($value);
 }
Beispiel #6
0
 public function executeCreate(opMailRequest $request)
 {
     if (!Doctrine::getTable('SnsConfig')->get('op_diary_plugin_use_email_post', true)) {
         return sfView::NONE;
     }
     $member = $this->getRoute()->getMember();
     if (!$member) {
         return sfView::NONE;
     }
     $diary = Doctrine::getTable('Diary')->find($request['id']);
     if (!$diary || !$diary->isViewable($member->id)) {
         return sfView::NONE;
     }
     if ($diary->member_id !== $member->id) {
         $relation = Doctrine::getTable('MemberRelationship')->retrieveByFromAndTo($diary->member_id, $member->id);
         if ($relation && $relation->getIsAccessBlock()) {
             return sfView::NONE;
         }
     }
     $mailMessage = $request->getMailMessage();
     $validator = new opValidatorString(array('rtrim' => true));
     try {
         $body = $validator->clean($mailMessage->getContent());
     } catch (Exception $e) {
         return sfView::ERROR;
     }
     $diaryComment = new DiaryComment();
     $diaryComment->setDiary($diary);
     $diaryComment->setMember($member);
     $diaryComment->setBody($body);
     $diaryComment->save();
     if (sfConfig::get('app_diary_comment_is_upload_images', true)) {
         $num = (int) sfConfig::get('app_diary_comment_max_image_file_num', 3);
         $files = $this->getImageFiles($mailMessage, $num);
         foreach ($files as $file) {
             $image = new DiaryCommentImage();
             $image->setDiaryComment($diaryComment);
             $image->setFile($file);
             $image->save();
         }
     }
     return sfView::NONE;
 }
Beispiel #7
0
 public function executeCreate(opMailRequest $request)
 {
     $member = $this->getRoute()->getMember();
     if (!$member) {
         return sfView::NONE;
     }
     $topic = Doctrine::getTable('CommunityEvent')->find($request['id']);
     if (!$topic || !$topic->isCreatableCommunityEventComment($member->id)) {
         return sfView::NONE;
     }
     if ($topic->member_id !== $member->id) {
         $relation = Doctrine::getTable('MemberRelationship')->retrieveByFromAndTo($topic->member_id, $member->id);
         if ($relation && $relation->getIsAccessBlock()) {
             return sfView::NONE;
         }
     }
     $mailMessage = $request->getMailMessage();
     $validator = new opValidatorString(array('rtrim' => true));
     try {
         $body = $validator->clean($mailMessage->getContent());
     } catch (Exception $e) {
         return sfView::ERROR;
     }
     $topicComment = new CommunityEventComment();
     $topicComment->setCommunityEvent($topic);
     $topicComment->setMember($member);
     $topicComment->setBody($body);
     $topicComment->save();
     $num = (int) sfConfig::get('app_community_topic_comment_max_image_file_num', 3);
     $files = $this->getImageFiles($mailMessage, $num);
     $number = 0;
     foreach ($files as $file) {
         $number++;
         $image = new CommunityEventCommentImage();
         $image->setCommunityEventComment($topicComment);
         $image->setFile($file);
         $image->setNumber($number);
         $image->save();
     }
     opCommunityTopicToolkit::sendNotificationMail($topic->getCommunity(), $topic->getId(), 'event', $topicComment->getMember()->getName(), $topic->getName(), $topicComment->getBody());
     return sfView::NONE;
 }
Beispiel #8
0
 public function executeCreate(opMailRequest $request)
 {
     if (!Doctrine::getTable('SnsConfig')->get('op_diary_plugin_use_email_post', true)) {
         return sfView::NONE;
     }
     $member = $this->getRoute()->getMember();
     if (!$member) {
         return sfView::NONE;
     }
     $mailMessage = $request->getMailMessage();
     $title = $this->getSubject($mailMessage, '(no title)');
     $validator = new opValidatorString(array('rtrim' => true));
     try {
         $body = $validator->clean($mailMessage->getContent());
     } catch (Exception $e) {
         return sfView::ERROR;
     }
     $diary = new Diary();
     $diary->setMember($member);
     $diary->setTitle($title);
     $diary->setBody($body);
     $diary->setPublicFlag($this->getDefaultPublicFlag($member));
     $diaryImages = array();
     if (sfConfig::get('app_diary_is_upload_images', true)) {
         $num = (int) sfConfig::get('app_diary_max_image_file_num', 3);
         $files = $this->getImageFiles($mailMessage, $num);
         $i = 1;
         foreach ($files as $file) {
             $diaryImage = new DiaryImage();
             $diaryImage->setDiary($diary);
             $diaryImage->setFile($file);
             $diaryImage->setNumber($i++);
             $diaryImages[] = $diaryImage;
             $diary->setHasImages(true);
         }
     }
     $diary->save();
     foreach ($diaryImages as $diaryImage) {
         $diaryImage->save();
     }
     return sfView::NONE;
 }
 protected function doClean($value)
 {
     $value = parent::doClean($value);
     if ($this->isEmpty($value)) {
         return $this->getEmptyValue();
     }
     if (!in_array($value, sfImageHandler::getAllowedSize())) {
         throw new sfValidatorError($this, 'Not allowed');
     }
     return $value;
 }
 public static function validateTerms($validator, $values)
 {
     foreach (self::getAvailableTerms() as $name => $config) {
         if (!isset($values[$name])) {
             $error = new sfValidatorError($validator, 'required');
             throw new sfValidatorErrorSchema($validator, array($name => $error));
         }
         foreach ($values[$name] as $application => $value) {
             if (!isset(self::$availableApplications[$application])) {
                 $error = new sfValidatorError($validator, 'The specified application is not supported.');
                 throw new sfValidatorErrorSchema($validator, array($name => $error));
             }
             $validator = new opValidatorString(array('trim' => true));
             try {
                 $values[$name][$application] = $validator->clean($value);
             } catch (sfValidatorError $e) {
                 throw new sfValidatorErrorSchema($validator, array($name => $e));
             }
         }
     }
     return $values;
 }
 protected function save($data)
 {
     $event = new sfEvent(null, 'op_csv.import_filter_data');
     sfContext::getInstance()->getEventDispatcher()->filter($event, $data);
     $fields = $event->getReturnValue();
     $member = new Member();
     $memberConfigs = array();
     $memberProfiles = array();
     foreach ($data as $key => $col) {
         $field = $this->fields[$key];
         if ($field['is_profile']) {
             $validator = $field['validator'];
             $memberProfiles[$field['name']] = $validator->clean($col);
             continue;
         } else {
             switch ($field['name']) {
                 case "nickname":
                     $validator = new opValidatorString(array('max_length' => 64, 'trim' => true, 'required' => true));
                     $member->name = $validator->clean($col);
                     break;
                 case "mail_address":
                     $validator = new sfValidatorEmail(array('trim' => true, 'required' => true));
                     $address = $validator->clean($col);
                     if (opToolkit::isMobileEmailAddress($address)) {
                         $memberConfigs['mobile_address'] = $address;
                     }
                     $memberConfigs['pc_address'] = $address;
                     break;
                 case "pc_mail_address":
                     $validator = new sfValidatorEmail(array('trim' => true, 'required' => true));
                     $address = $validator->clean($col);
                     if (opToolkit::isMobileEmailAddress($address)) {
                         throw new opCsvPluginImportException("'pc_mail_address' is mobile address.");
                     }
                     $memberConfigs['pc_address'] = $address;
                     break;
                 case "mobile_mail_address":
                     $validator = new sfValidatorEmail(array('trim' => true, 'required' => true));
                     $address = $validator->clean($col);
                     if (!opToolkit::isMobileEmailAddress($address)) {
                         throw new opCsvPluginImportException("'mobile_mail_address' is not support mobile address.");
                     }
                     $memberConfigs['mobile_address'] = $address;
                     break;
                 case "password":
                     $validator = new sfValidatorPassword(array('trim' => true, 'required' => true));
                     $memberConfigs['password'] = $validator->clean($col);
                     break;
             }
         }
     }
     // check unique for member config
     foreach ($this->uniqueMemberConfigFields as $name) {
         if (isset($memberConfigs[$name]) && Doctrine::getTable('MemberConfig')->retrieveByNameAndValue($name, $memberConfigs[$name])) {
             throw new opCsvPluginImportException("'" . $name . "' duplicated.");
         }
     }
     $member->setIsActive(true);
     $member->save();
     foreach ($memberConfigs as $key => $value) {
         $member->setConfig($key, $value);
     }
     foreach ($memberProfiles as $key => $value) {
         $profile = $this->field[$key]['profile'];
     }
 }