コード例 #1
0
ファイル: Comment_Helper_Test.php プロジェクト: xafr/gallery3
 public function create_comment_for_user_test()
 {
     $rand = rand();
     $root = ORM::factory("item", 1);
     $admin = user::lookup(2);
     $comment = comment::create($root, $admin, "text_{$rand}", "name_{$rand}", "email_{$rand}", "url_{$rand}");
     $this->assert_equal($admin->full_name, $comment->author_name());
     $this->assert_equal($admin->email, $comment->author_email());
     $this->assert_equal($admin->url, $comment->author_url());
     $this->assert_equal("text_{$rand}", $comment->text);
     $this->assert_equal(1, $comment->item_id);
     $this->assert_equal("REMOTE_ADDR", $comment->server_remote_addr);
     $this->assert_equal("HTTP_USER_AGENT", $comment->server_http_user_agent);
     $this->assert_equal("HTTP_ACCEPT", $comment->server_http_accept);
     $this->assert_equal("HTTP_ACCEPT_CHARSET", $comment->server_http_accept_charset);
     $this->assert_equal("HTTP_ACCEPT_ENCODING", $comment->server_http_accept_encoding);
     $this->assert_equal("HTTP_ACCEPT_LANGUAGE", $comment->server_http_accept_language);
     $this->assert_equal("HTTP_CONNECTION", $comment->server_http_connection);
     $this->assert_equal("HTTP_HOST", $comment->server_http_host);
     $this->assert_equal("HTTP_REFERER", $comment->server_http_referer);
     $this->assert_equal("HTTP_USER_AGENT", $comment->server_http_user_agent);
     $this->assert_equal("QUERY_STRING", $comment->server_query_string);
     $this->assert_equal("REMOTE_ADDR", $comment->server_remote_addr);
     $this->assert_equal("REMOTE_HOST", $comment->server_remote_host);
     $this->assert_equal("REMOTE_PORT", $comment->server_remote_port);
     $this->assert_true(!empty($comment->created));
 }
コード例 #2
0
 /**
  * Add a new comment to the collection.
  * @see REST_Controller::_create($resource)
  */
 public function _create($comment)
 {
     $item = ORM::factory("item", $this->input->post("item_id"));
     access::required("view", $item);
     $form = comment_3nids::get_add_form($item);
     $valid = $form->validate();
     if ($valid) {
         if (user::active()->guest && !$form->add_comment->inputs["name"]->value) {
             $form->add_comment->inputs["name"]->add_error("missing", 1);
             $valid = false;
         }
         if (!$form->add_comment->text->value) {
             $form->add_comment->text->add_error("missing", 1);
             $valid = false;
         }
     }
     if ($valid) {
         $comment = comment::create($item, user::active(), $form->add_comment->text->value, $form->add_comment->inputs["name"]->value, $form->add_comment->email->value, $form->add_comment->url->value);
         $active = user::active();
         if ($active->guest) {
             $form->add_comment->inputs["name"]->value("");
             $form->add_comment->email->value("");
             $form->add_comment->url->value("");
         } else {
             $form->add_comment->inputs["name"]->value($active->full_name);
             $form->add_comment->email->value($active->email);
             $form->add_comment->url->value($active->url);
         }
     }
     url::redirect(url::site("comments_3nids?item_id=" . $item->id));
 }
コード例 #3
0
ファイル: comments.php プロジェクト: Okat/gallery3
 /**
  * Add a new comment to the collection.
  * @see REST_Controller::_create($resource)
  */
 public function _create($comment)
 {
     $item = ORM::factory("item", $this->input->post("item_id"));
     access::required("view", $item);
     $form = comment::get_add_form($item);
     $valid = $form->validate();
     if ($valid) {
         if (user::active()->guest && !$form->add_comment->inputs["name"]->value) {
             $form->add_comment->inputs["name"]->add_error("missing", 1);
             $valid = false;
         }
         if (!$form->add_comment->text->value) {
             $form->add_comment->text->add_error("missing", 1);
             $valid = false;
         }
     }
     if ($valid) {
         $comment = comment::create($item, user::active(), $form->add_comment->text->value, $form->add_comment->inputs["name"]->value, $form->add_comment->email->value, $form->add_comment->url->value);
         $active = user::active();
         if ($active->guest) {
             $form->add_comment->inputs["name"]->value("");
             $form->add_comment->email->value("");
             $form->add_comment->url->value("");
         } else {
             $form->add_comment->inputs["name"]->value($active->full_name);
             $form->add_comment->email->value($active->email);
             $form->add_comment->url->value($active->url);
         }
         $form->add_comment->text->value("");
         print json_encode(array("result" => "success", "resource" => $comment->state == "published" ? url::site("comments/{$comment->id}") : null, "form" => $form->__toString()));
     } else {
         print json_encode(array("result" => "error", "form" => $form->__toString()));
     }
 }
コード例 #4
0
 public function deleting_an_item_deletes_its_comments_too_test()
 {
     $rand = rand();
     $album = album::create(ORM::factory("item", 1), "test_{$rand}", "test_{$rand}");
     $comment = comment::create($album, identity::guest(), "text_{$rand}", "name_{$rand}", "email_{$rand}", "url_{$rand}");
     $album->delete();
     $deleted_comment = ORM::factory("comment", $comment->id);
     $this->assert_false($deleted_comment->loaded);
 }
コード例 #5
0
ファイル: Comment_Model_Test.php プロジェクト: Okat/gallery3
 public function cant_view_comments_for_unviewable_items_test()
 {
     $root = ORM::factory("item", 1);
     $album = album::create($root, rand(), rand(), rand());
     $comment = comment::create($album, user::guest(), "text", "name", "email", "url");
     user::set_active(user::guest());
     // We can see the comment when permissions are granted on the album
     access::allow(group::everybody(), "view", $album);
     $this->assert_equal(1, ORM::factory("comment")->viewable()->where("comments.id", $comment->id)->count_all());
     // We can't see the comment when permissions are denied on the album
     access::deny(group::everybody(), "view", $album);
     $this->assert_equal(0, ORM::factory("comment")->viewable()->where("comments.id", $comment->id)->count_all());
 }
コード例 #6
0
ファイル: Akismet_Helper_Test.php プロジェクト: xafr/gallery3
 public function setup()
 {
     Input::instance()->ip_address = "1.1.1.1";
     Kohana::$user_agent = "Akismet_Helper_Test";
     $root = ORM::factory("item", 1);
     $this->_comment = comment::create($root, user::guest(), "This is a comment", "John Doe", "*****@*****.**", "http://gallery2.org");
     foreach ($this->_comment->list_fields("comments") as $name => $field) {
         if (strpos($name, "server_") === 0) {
             $this->_comment->{$name} = substr($name, strlen("server_"));
         }
     }
     $this->_comment->save();
     module::set_var("akismet", "api_key", "TEST_KEY");
 }
コード例 #7
0
ファイル: comments.php プロジェクト: viosca/gallery3
 /**
  * Add a new comment to the collection.
  */
 public function create($id)
 {
     $item = ORM::factory("item", $id);
     access::required("view", $item);
     $form = comment::get_add_form($item);
     $valid = $form->validate();
     if ($valid) {
         if (identity::active_user()->guest && !$form->add_comment->inputs["name"]->value) {
             $form->add_comment->inputs["name"]->add_error("missing", 1);
             $valid = false;
         }
         if (!$form->add_comment->text->value) {
             $form->add_comment->text->add_error("missing", 1);
             $valid = false;
         }
     }
     if ($valid) {
         $comment = comment::create($item, identity::active_user(), $form->add_comment->text->value, $form->add_comment->inputs["name"]->value, $form->add_comment->email->value, $form->add_comment->url->value);
         $active = identity::active_user();
         if ($active->guest) {
             $form->add_comment->inputs["name"]->value("");
             $form->add_comment->email->value("");
             $form->add_comment->url->value("");
         } else {
             $form->add_comment->inputs["name"]->value($active->full_name);
             $form->add_comment->email->value($active->email);
             $form->add_comment->url->value($active->url);
         }
         $form->add_comment->text->value("");
         $view = new Theme_View("comment.html", "other", "comment-fragment");
         $view->comment = $comment;
         print json_encode(array("result" => "success", "view" => $view->__toString(), "form" => $form->__toString()));
     } else {
         print json_encode(array("result" => "error", "form" => $form->__toString()));
     }
 }
コード例 #8
0
 private static function _add_comment()
 {
     srand(time());
     $photos = ORM::factory("item")->where("type", "photo")->find_all()->as_array();
     $users = ORM::factory("user")->find_all()->as_array();
     if (empty($photos)) {
         return;
     }
     if (module::is_active("akismet")) {
         akismet::$test_mode = 1;
     }
     $photo = $photos[array_rand($photos)];
     $author = $users[array_rand($users)];
     $guest_name = ucfirst(self::_random_phrase(rand(1, 3)));
     $guest_email = sprintf("%s@%s.com", self::_random_phrase(1), self::_random_phrase(1));
     $guest_url = sprintf("http://www.%s.com", self::_random_phrase(1));
     comment::create($photo, $author, self::_random_phrase(rand(8, 500)), $guest_name, $guest_email, $guest_url);
 }
コード例 #9
0
ファイル: scaffold.php プロジェクト: xafr/gallery3
 function add_comments($count)
 {
     srand(time());
     $photos = ORM::factory("item")->where("type", "photo")->find_all()->as_array();
     $users = ORM::factory("user")->find_all()->as_array();
     if (empty($photos)) {
         url::redirect("scaffold");
     }
     if (module::is_active("akismet")) {
         akismet::$test_mode = 1;
     }
     for ($i = 0; $i < $count; $i++) {
         $photo = $photos[array_rand($photos)];
         $author = $users[array_rand($users)];
         $guest_name = ucfirst($this->random_phrase(rand(1, 3)));
         $guest_email = sprintf("%s@%s.com", $this->random_phrase(1), $this->random_phrase(1));
         $guest_url = sprintf("http://www.%s.com", $this->random_phrase(1));
         comment::create($photo, $author, $this->random_phrase(rand(8, 500)), $guest_name, $guest_email, $guest_url);
     }
     url::redirect("scaffold");
 }