Esempio n. 1
0
 private function AddComment(sfWebRequest $request)
 {
     $text = $request->getParameter('comment_text');
     if ($request->isMethod("GET")) {
         $text = urldecode($text);
     }
     if ($this->getRequestParameter('comment_picture_url')) {
         $filename = jrFileUploader::UploadRemote($request->getParameter('comment_picture_url'));
         if ($text) {
             $text .= "<br/>";
         }
         $text .= "<img src='http://" . $request->getHost() . "/uploads/" . $filename . "' />";
     }
     if (!trim($text)) {
         return;
     }
     sfApplicationConfiguration::getActive()->loadHelpers(array('Parse', 'Text', 'Tag', 'I18N', 'Url'));
     $user = $this->getUser()->getGuardUser();
     $comment = new PostComment();
     $comment->setUser($user);
     $comment->setPost($this->post);
     if ($this->parent) {
         $comment->setParent($this->parent);
     }
     $comment->setComment(parsetext($text));
     $comment->setCommentOriginal($text);
     $comment->save();
     $this->curUser = $this->getUser()->getGuardUser();
     if ($this->curUser) {
         Cookie::setCookie($this->curUser, "comments" . $this->post->getId(), $this->post->getAllComments('count'), time() + 24 * 60 * 60);
         Cookie::setCookie($this->curUser, "comments" . $this->post->getId() . "Time", date("Y-m-d H:i:s"), time() + 24 * 60 * 60);
     }
 }
Esempio n. 2
0
 public function executeUploadUrl(sfWebRequest $request)
 {
     $this->filename = '';
     if ($request->getParameter('picture_url') != null) {
         try {
             $filename = jrFileUploader::UploadRemote($request->getParameter('picture_url'));
             $this->filename = 'http://' . $request->getHost() . '/uploads/' . $filename;
         } catch (Exception $e) {
         }
     }
     return $this->renderPartial('upload', array('filename' => $this->filename));
 }
Esempio n. 3
0
 public function executeCreate(sfWebRequest $request)
 {
     sfApplicationConfiguration::getActive()->loadHelpers(array('Parse', 'Text', 'Tag', 'I18N', 'Url'));
     $this->forward404Unless($request->isMethod('post'));
     $user = $this->getUser()->getGuardUser();
     try {
         $text = trim($this->getRequestParameter('text'));
         $blogs = array();
         $pictures = array();
         $moodNo = 0;
         $doWork = false;
         $useMoodNo = false;
         do {
             $doWork = false;
             if (substr($text, 0, 2) == ":D") {
                 $moodNo = 1;
                 $text = trim(substr($text, 2));
                 $doWork = true;
                 $useMoodNo = true;
             }
             if (substr($text, 0, 2) == ":(") {
                 $moodNo = -1;
                 $text = trim(substr($text, 2));
                 $doWork = true;
                 $useMoodNo = true;
             }
             if (substr($text, 0, 2) == ":)") {
                 $moodNo = 0;
                 $text = trim(substr($text, 2));
                 $doWork = true;
                 $useMoodNo = true;
             }
             if (substr($text, 0, 1) == "#" || substr($text, 0, 1) == "*") {
                 $tags = split("[,;:|\n]", $text);
                 $blog = Blog::getOrCreateByTag(trim(substr($tags[0], 1)), $user);
                 if ($blog) {
                     $text = trim(substr($text, strlen($tags[0]) + 1));
                     $blogs[] = $blog;
                     $doWork = true;
                 }
             }
         } while ($doWork);
         $post = new Post();
         $post->setTextOriginal($text);
         $post->setText(parsetext($text));
         if ($useMoodNo) {
             $post->setMood($moodNo);
         } else {
             $post->setMoodName($this->getRequestParameter('mood'));
         }
         $post->setUser($user);
         if ($this->getRequestParameter('picture_url')) {
             $filename = jrFileUploader::UploadRemote($request->getParameter('picture_url'));
             $pictures[] = array('value' => '/uploads/' . $filename, 'origin' => $request->getParameter('picture_url'));
         }
         $uploaded_file = $request->getFiles('picture');
         if ($uploaded_file['tmp_name']) {
             $pathinfo = pathinfo($uploaded_file['name']);
             $name = time() . rand(1, 999999);
             $extension = $pathinfo["extension"] ? $pathinfo["extension"] : "jpg";
             $filename = $name . "." . $extension;
             $origin = $name . "_origin." . $extension;
             $thumbnail = new sfThumbnail(811, 0, true, false, 100, sfConfig::get('app_sfThumbnailPlugin_adapter', 'sfGDAdapter'));
             $thumbnail->loadFile($uploaded_file['tmp_name']);
             $thumbnail->save(sfConfig::get('sf_upload_dir') . '/' . $filename);
             move_uploaded_file($uploaded_file['tmp_name'], sfConfig::get('sf_upload_dir') . '/' . $origin);
             $pictures[] = array('value' => '/uploads/' . $filename, 'origin' => '/uploads/' . $origin);
         }
         foreach ($blogs as $blog) {
             $post->getBlogs()->add($blog);
         }
         foreach ($pictures as $pic) {
             $postAttr = new PostAttribute();
             $postAttr->setType('picture');
             $postAttr->setValue($pic['value']);
             $postAttr->setOrigin($pic['origin']);
             $post->getAttributes()->add($postAttr);
         }
         $post->save();
         /*if(!$this->getRequestParameter('noajax')) {
               if($this->getRequestParameter('mypage'))
                   $post_list = $user->getLine();
               else
                   $post_list = Post::getNewLine();
               return $this->renderPartial('post/postList', array('posts' => $post_list));
           }
           else
               $this->redirect(url_for('post/new'));*/
         if ($this->getRequestParameter('mypage')) {
             $this->redirect(url_for('post/user'));
         } else {
             $this->redirect(url_for('post/new'));
         }
     } catch (Exception $e) {
         echo $e;
         echo "Возникла ошибка при создании поста.<br/>\n";
         if ($this->getRequestParameter('text')) {
             echo "Текст поста был такой:<br/>\n";
             echo "<hr/>" . nl2br(htmlentities(trim($this->getRequestParameter('text')))) . "<hr/><br/>\n";
         }
         if ($this->getRequestParameter('noajax')) {
             echo "<a href='" . $this->getRequest()->getReferer() . "'>назад</a>";
         }
         die;
     }
 }