function testCommenterURLWrite()
 {
     $comment = new Comment();
     // We only care about the CommenterURL, so only set that
     // Check a http and https URL. Add more test urls here as needed.
     $protocols = array('Http', 'Https');
     $url = '://example.com';
     foreach ($protocols as $protocol) {
         $comment->CommenterURL = $protocol . $url;
         // The protocol should stay as if, assuming it is valid
         $comment->write();
         $this->assertEquals($comment->CommenterURL, $protocol . $url, $protocol . ':// is a valid protocol');
     }
 }
Example #2
0
 public function create(Comment &$comment)
 {
     $this->validate();
     $comment->validate();
     if ($this->hasError() || $comment->hasError()) {
         throw new ValidationException('Invalid thread or comment.');
     }
     $db = DB::conn();
     $db->begin();
     try {
         $params = array('title' => $this->title, 'user_id' => $this->user_id, 'category_name' => $this->category);
         $db->insert(self::TABLE_NAME, $params);
         $comment->id = $db->lastInsertId();
         $comment->write();
         $db->commit();
     } catch (PDOException $e) {
         $db->rollback();
     }
 }
Example #3
0
 /**
  * Migrates the old {@link PageComment} objects to {@link Comment}
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (DB::getConn()->hasTable('PageComment')) {
         $comments = DB::query("SELECT * FROM \"PageComment\"");
         if ($comments) {
             while ($pageComment = $comments->nextRecord()) {
                 // create a new comment from the older page comment
                 $comment = new Comment();
                 $comment->update($pageComment);
                 // set the variables which have changed
                 $comment->BaseClass = 'SiteTree';
                 $comment->URL = isset($pageComment['CommenterURL']) ? $pageComment['CommenterURL'] : "";
                 $comment->write();
             }
         }
         DB::alteration_message("Migrated PageComment to Comment", "changed");
         DB::getConn()->dontRequireTable('PageComment');
     }
 }
Example #4
0
 /** 
  * Validate first the Thread & Comment.
  * If both hasError() -> throw Exception
  * Get title of Thread, Get Comment
  * Insert to the Database.
  * @param $comment
  */
 public function create(Comment $comment)
 {
     $this->validate();
     $comment->validate();
     if ($this->hasError() || $comment->hasError()) {
         throw new ValidationException('Invalid thread or comment');
     }
     $db = DB::conn();
     try {
         $db->begin();
         $params = array('user_id' => $this->user_id, 'title' => $this->title);
         $db->insert('thread', $params);
         $this->id = $db->lastInsertId();
         $comment->write($this->id);
         $db->commit();
     } catch (ValidationException $e) {
         $db->rollback();
         throw $e;
     }
 }
 public function write()
 {
     $thread = Thread::getById(Param::get('thread_id'));
     $comment = new Comment();
     $page = Param::get('page_next', 'write');
     switch ($page) {
         case self::CURRENT_PAGE_WRITE:
             break;
         case self::RENDER_PAGE_AFTER_WRITE:
             $comment->id = $thread->id;
             $comment->user_id = get_authenticated_user_id($_SESSION['userid']);
             $comment->body = Param::get('body');
             try {
                 $comment->write();
             } catch (ValidationException $e) {
                 $page = self::CURRENT_PAGE_WRITE;
             }
             break;
         default:
             throw new NotFoundException("{$page} is not found");
     }
     $this->set(get_defined_vars());
     $this->render($page);
 }
 /**
  * Get Thread thru id
  * Write comment to existing Thread
  */
 public function write()
 {
     $comment = new Comment();
     $thread = Thread::get(Param::get('thread_id'));
     $page = Param::get('page_next', 'write');
     switch ($page) {
         case 'write':
             break;
         case 'write_end':
             try {
                 $comment->username = $_SESSION['username'];
                 $comment->body = Param::get('body');
                 $comment->write($thread->id);
             } catch (ValidationException $a) {
                 $page = 'write';
             }
             break;
         default:
             throw new PageNotFoundException("{$page} is not found");
             break;
     }
     $this->set(get_defined_vars());
     $this->render($page);
 }
 /**
  * @param Comment $comment Comment to generate this token for
  */
 public function __construct($comment)
 {
     if (!$comment->SecretToken) {
         $comment->SecretToken = $this->generate();
         $comment->write();
     }
     $this->secret = $comment->SecretToken;
 }
 protected function importComments($item, $post)
 {
     $source = $item->getSource();
     $client = $source->getClient();
     $struct = new Struct(array('post_id' => $item->PostID, 'number' => 999999));
     $comments = $client->call('wp.getComments', array($source->BlogId, $source->Username, $source->Password, $struct));
     if ($comments) {
         foreach ($comments as $data) {
             $comment = new Comment();
             $comment->BaseClass = "SiteTree";
             $comment->Name = $data['author'];
             $comment->Comment = $data['content'];
             $comment->CommenterURL = $data['author_url'];
             $comment->ParentID = $post->ID;
             $comment->write();
             $comment->Created = date('Y-m-d H:i:s', strtotime($data['date_created_gmt']));
             $comment->write();
         }
     }
 }
Example #9
0
 public function testDefaultTemplateRendersHtmlWithAllowHtml()
 {
     if (!class_exists('HTMLPurifier')) {
         $this->markTestSkipped('HTMLPurifier class not found');
     }
     $origAllowed = Commenting::get_config_value('CommentableItem', 'html_allowed');
     $item = new CommentableItem();
     $item->write();
     // Without HTML allowed
     $comment = new Comment();
     $comment->Comment = '<p>my comment</p>';
     $comment->ParentID = $item->ID;
     $comment->BaseClass = 'CommentableItem';
     $comment->write();
     $html = $item->customise(array('CommentsEnabled' => true))->renderWith('CommentsInterface');
     $this->assertContains('&lt;p&gt;my comment&lt;/p&gt;', $html);
     Commenting::set_config_value('CommentableItem', 'html_allowed', true);
     $html = $item->customise(array('CommentsEnabled' => true))->renderWith('CommentsInterface');
     $this->assertContains('<p>my comment</p>', $html);
     Commenting::set_config_value('CommentableItem', 'html_allowed', $origAllowed);
 }