Ejemplo n.º 1
0
 /**
  * Add a new page action
  */
 public function actionCreate()
 {
     // Check Access
     checkAccessThrowException('op_blog_addposts');
     $model = new BlogPost();
     if (isset($_POST['BlogPost'])) {
         $model->attributes = $_POST['BlogPost'];
         if (isset($_POST['submit'])) {
             if ($model->save()) {
                 fok(at('Page Created.'));
                 alog(at("Created Blog Post '{name}'.", array('{name}' => $model->title)));
                 $this->redirect(array('blog/index'));
             }
         } else {
             if (isset($_POST['preview'])) {
                 $model->attributes = $_POST['BlogPost'];
             }
         }
     }
     $roles = AuthItem::model()->findAll(array('order' => 'type DESC, name ASC'));
     $_roles = array();
     if (count($roles)) {
         foreach ($roles as $role) {
             $_roles[AuthItem::model()->types[$role->type]][$role->name] = $role->name;
         }
     }
     // Add Breadcrumb
     $this->addBreadCrumb(at('Creating New Post'));
     $this->title[] = at('Creating New Post');
     // Display form
     $this->render('form', array('roles' => $_roles, 'model' => $model));
 }
Ejemplo n.º 2
0
 public function testClone()
 {
     $this->expectDocumentSaved(array('title' => 'Hello World', 'views' => 0, 'comments' => array()));
     $post = new BlogPost(array('title' => 'Hello World', 'views' => 0));
     $post->save();
     $this->assertEquals($post->saved(), true);
     $clone = clone $post;
     $this->assertEquals($clone->saved(), false);
     $post->_id = null;
     $this->assertEquals($clone, $post);
 }
Ejemplo n.º 3
0
    function atomAddPost($request)
    {
        header("Content-Type: application/atomserv+xml; charset=utf-8");
        // parse submitted data
        $xml = new SimpleXMLElement($request->content);
        $author = (object) array('name' => (string) $xml->author->name, 'email' => (string) $xml->author->email, 'uri' => (string) $xml->author->uri);
        $tags = array();
        foreach ($xml->category as $category) {
            $tags[] = (string) $category['term'];
        }
        $draft = isset($xml->draft);
        // create blog post
        $filesystem = new Minim_Model_Backend_Sqlite($GLOBALS['database']['dsn']);
        $post = new BlogPost();
        $post->setBackend($filesystem);
        $post->title = (string) $xml->title;
        $post->content = (string) $xml->content;
        $post->draft = $draft;
        $post->save();
        $location = "/blog/" . date("Y/m/d", $post->created) . "/{$post->title}";
        $primaryKey = $post->getPrimaryKeyValue();
        header("Content-Location: {$location}");
        header("Location: {$location}");
        echo <<<XML
<?xml version="1.0" ?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <id>{$primaryKey}</id>
  <title>{$post->title}</title>
  <link rel="edit" href="/blog/posts/{$post->id}" />
  <updated>{$post->created}</updated>
  <author><name>{$author->name}</name></author>
  <content>{$post->content}</summary>
</entry>
XML;
        exit;
    }
Ejemplo n.º 4
0
 /**
  * 登録日を更新する
  *
  * @return boolean
  * @access	protected
  */
 function _updateEntryDate()
 {
     $db =& $this->_connectDb($this->_readDbSettingFromSession());
     $db =& $this->_connectDb($this->_readDbSettingFromSession(), 'plugin');
     App::import('Model', 'Blog.BlogPost');
     $BlogPost = new BlogPost();
     $blogPosts = $BlogPost->find('all');
     if ($blogPosts) {
         $ret = true;
         foreach ($blogPosts as $blogPost) {
             $blogPost['BlogPost']['posts_date'] = date('Y-m-d H:i:s');
             if (!$BlogPost->save($blogPost)) {
                 $ret = false;
             }
         }
         return $ret;
     } else {
         return false;
     }
 }
Ejemplo n.º 5
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     // Declare the rules for the form validation
     $rules = array('title' => 'required|min:3', 'content' => 'required|min:3|not_in:<p></p>', 'image' => 'image|max:30000000');
     // Create a new validator instance from our validation rules
     $validator = Validator::make(Input::all(), $rules);
     // If validation fails, we'll exit the operation now.
     if ($validator->fails()) {
         // Ooops.. something went wrong
         return Redirect::back()->withInput()->withErrors($validator);
     }
     // Create a new blog post
     $post = new BlogPost();
     // Update the blog post data
     $post->title = e(Input::get('title'));
     if (empty($post->slug)) {
         $post->slug = e(Str::slug(Input::get('title')));
     } else {
         $post->slug = e(Str::slug(Input::get('slug')));
     }
     $post->content = e(Input::get('content'));
     $post->draft = e(Input::get('draft'));
     $post->lang = e(Input::get('lang'));
     $post->content = e(Input::get('content'));
     $post->meta_title = e(Input::get('meta-title'));
     $post->meta_description = e(Input::get('meta-description'));
     $post->meta_keywords = e(Input::get('meta-keywords'));
     $post->user_id = Sentry::getId();
     $image = Input::file('image');
     if (!empty($image)) {
         $filename = $post->slug . '_' . date('d-m-Y') . '.' . $image->getClientOriginalExtension();
         $uploadSuccess = Input::file('image')->move($this->destinationPath, $filename);
         $post->image = e($filename);
     }
     // Was the blog post created?
     if ($post->save()) {
         $tags = explode(',', Input::get('blogtags'));
         foreach ($tags as $tag) {
             if (BlogTag::where('name', '=', $tag)->count() == 0) {
                 $newTag = new BlogTag();
                 $newTag->name = ucwords($tag);
                 $newTag->slug = Str::slug($tag);
                 $newTag->save();
             } else {
                 $newTag = BlogTag::where('name', '=', $tag)->first();
             }
             $post->tags()->attach($newTag->id);
         }
         // Redirect to the new blog post page
         return Redirect::route('blog.show', array('blog' => $post->slug))->with('success', Lang::get('modules/blog/messages.success.create'));
     }
     // Redirect to the blog post create page
     return Redirect::route('blog.create')->with('error', Lang::get('modules/blog/messages.error.create'));
 }
Ejemplo n.º 6
0
 public static function save_blogpost($cid, $uid, $title, $body, $track, $tags, $ccid = 0, $is_active = 1, $display_on = 0, $is_default_content = FALSE)
 {
     global $path_prefix;
     $errors = array();
     // ensure integers here
     $cid = (int) $cid;
     $uid = (int) $uid;
     $ccid = (int) $ccid;
     // if a new post, make one, otherwise load the existing one
     if ($cid) {
         $post = Content::load_content($cid, $uid);
         // ignore $ccid passed to function if the post already exists
         // - we don't allow users to move posts between
         // ContentCollections.
         $ccid = (int) $post->parent_collection_id;
     } else {
         $post = new BlogPost();
         $post->author_id = $uid;
         if ($ccid) {
             $post->parent_collection_id = $ccid;
         }
     }
     if ($ccid && $ccid != -1) {
         $g = ContentCollection::load_collection($ccid, $uid);
         $g->assert_user_access($uid);
     } else {
         $g = NULL;
     }
     $post->title = $title;
     $post->body = $body;
     $post->allow_comments = 1;
     $post->is_active = $is_active;
     $post->display_on = $display_on;
     if ($track) {
         $post->trackbacks = implode(",", $track);
     }
     //TODO; remove this
     $post->type = 1;
     $post->is_default_content = $is_default_content;
     $post->save();
     //if ($tags) {
     Tag::add_tags_to_content($post->content_id, $tags);
     //}
     if ($track) {
         foreach ($track as $t) {
             if (!$post->send_trackback($t)) {
                 $errors[] = array("code" => "trackback_failed", "msg" => "Failed to send trackback", "url" => $t);
             }
         }
     }
     if ($g && !$cid) {
         // new post - post it to the group as well
         $g->post_content($post->content_id, $uid);
     }
     return array("cid" => (int) $post->content_id, "moderation_required" => $g ? $g->is_moderated == 1 && $g->author_id != $uid : FALSE, "errors" => $errors);
 }
Ejemplo n.º 7
0
 public function actionEdit($post_id = 0)
 {
     $post_id = (int) $post_id;
     if ($post_id != 0) {
         $post = BlogPost::model()->findByPk($post_id);
         if (!$post) {
             throw new CHttpException(404, "Поста не существует. Возможно, его удалили");
         }
         if ($post->user_id != Yii::app()->user->id and !Yii::app()->user->can("blog_moderate")) {
             throw new CHttpException(403, "Вы можете редактировать только собственные посты");
         }
         if ($post->book_id != 0) {
             $this->redirect("/book/{$post->book_id}/blog/{$post->id}/edit");
         }
     } else {
         $post = new BlogPost();
         $post->user_id = Yii::app()->user->id;
         $post->topics = (int) $_GET["topic"];
     }
     if (isset($_POST["BlogPost"])) {
         $post->attributes = $_POST["BlogPost"];
         $post->lastcomment = date("Y-m-d H:i:s");
         if ($post->save()) {
             $post->setTrack();
             $this->redirect($post->url);
         }
     }
     $this->render("edit", array("post" => $post));
 }
Ejemplo n.º 8
0
 public function executeSettag(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod('post'));
     $post = Doctrine::getTable('Post')->find(array($request->getParameter('id')));
     $this->forward404Unless($post, $this->getUser()->getGuardUser());
     $tags = split("[,;:]", str_replace("*", "", str_replace("#", "", trim($request->getParameter('tag')))));
     if ($post->getUser() == $this->getUser()->getGuardUser() || $this->getUser()->getGuardUser()->getIsSuperAdmin()) {
         $post->deleteBlogs();
     }
     foreach ($tags as $tag) {
         $tag = trim($tag);
         $blog = Blog::getOrCreateByTag($tag, $this->getUser()->getGuardUser());
         if ($blog) {
             $bp = new BlogPost();
             $bp->setBlogId($blog->getId());
             $bp->setPostId($post->getId());
             $bp->save();
         }
     }
     return $this->renderPartial('post/post', array('post' => $post));
 }
Ejemplo n.º 9
0
 public function testValidation()
 {
     $this->assertThrown('TipyValidationException', "Post should belongs to user", function () {
         $post = new BlogPost();
         $post->title = 'This is a title';
         $post->message = 'This is a message!';
         $post->save();
         $this->assertEqual($post->isNewRecord(), true);
         $this->assertEqual($post->id, null);
         $post->userId = 2;
         $this->assertEqual($post->save(), true);
         $this->assertEqual($post->isNewRecord(), false);
         $this->assertNotEqual($post->id, null);
     });
 }
 function testAddDeleteContentComments()
 {
     //    Dal::register_query_callback("explain_query");
     echo "getting a user\n";
     $user = Test::get_test_user();
     echo "test user = {$user->first_name} {$user->last_name}\n";
     echo "adding some content\n";
     $post = new BlogPost();
     $post->author_id = $user->user_id;
     $post->parent_collection_id = -1;
     $post->title = "Test blog post (from testAddDeleteContentComments)";
     $post->body = "<p>This is the post body!</p><p>Foo <b>foo</b> foo</p>";
     $post->allow_comments = 1;
     $post->is_active = 1;
     $post->display_on = DISPLAY_ON_HOMEPAGE;
     $post->save();
     echo "... saved as content_id={$post->content_id}\n";
     echo "testing that it is retrievable\n";
     $post_retr = Content::load_content($post->content_id, $user->user_id);
     $this->assertEquals($post_retr->content_id, $post->content_id);
     $this->assertEquals($post_retr->title, $post->title);
     $this->assertEquals($post_retr->body, $post->body);
     $this->assertEquals($post_retr->author_id, $user->user_id);
     $this->assertEquals($post_retr->is_active, 1);
     echo "posting a comment\n";
     $cmt = new Comment();
     $cmt->content_id = $post->content_id;
     $cmt_comment = "This is an automatic comment - on an autogenerated post";
     $cmt->comment = $cmt_comment;
     $cmt->user_id = $user->user_id;
     $cmt->name = $cmt->email = $cmt->homepage = '';
     $cmt->ip_addr = '127.0.0.1';
     $cmt->referrer = 'http://example.com/';
     $cmt->user_agent = 'phpunit auto-test';
     $cmt->save();
     echo "... saved as comment_id={$cmt->comment_id}\n";
     echo "testing that the comment is retrievable\n";
     $cmt_retr = new Comment();
     $cmt_retr->load($cmt->comment_id);
     $this->assertEquals($cmt_retr->comment_id, $cmt->comment_id);
     $this->assertEquals($cmt_retr->content_id, $post->content_id);
     $this->assertEquals($cmt_retr->comment, $cmt_comment);
     $this->assertEquals($cmt_retr->is_active, 1);
     echo "testing that we see one comment on the post\n";
     $comments = Comment::get_comment_for_content($post->content_id);
     echo count($comments) . " comments\n";
     //var_dump($comments);
     $this->assertEquals(count($comments), 1);
     echo "testing that we have no trackbacks on the post\n";
     $trackbacks = Content::get_trackbacks_for_content($post->content_id);
     echo count($trackbacks) . " trackbacks\n";
     //var_dump($trackbacks);
     $this->assertEquals(count($trackbacks), 0);
     echo "posting ANOTHER comment\n";
     $cmt2 = new Comment();
     $cmt2->content_id = $post->content_id;
     $cmt2_comment = "This is ANOTHER automatic comment - on the same autogenerated post";
     $cmt2->comment = $cmt_comment;
     $cmt2->user_id = $user->user_id;
     $cmt2->name = $cmt2->email = $cmt2->homepage = '';
     $cmt2->ip_addr = '127.0.0.1';
     $cmt2->referrer = 'http://example.com/';
     $cmt2->user_agent = 'phpunit auto-test';
     $cmt2->save();
     echo "... saved as comment_id={$cmt2->comment_id}\n";
     echo "testing that we see two comments on the post\n";
     $comments = Comment::get_comment_for_content($post->content_id);
     $this->assertEquals(count($comments), 2);
     echo "deleting the first comment\n";
     $cmt_retr->delete();
     echo "testing that we see one comment on the post again (not seeing the deleted one)\n";
     $comments = Comment::get_comment_for_content($post->content_id);
     $this->assertEquals(count($comments), 1);
     echo "testing that the first comment (now deleted) is not retrievable\n";
     $cmt_retr_fail = new Comment();
     try {
         $cmt_retr_fail->load($cmt->comment_id);
         $this->assertTrue(FALSE);
         // shouldn't get here
     } catch (PAException $e) {
         $this->assertEquals($e->getCode(), COMMENT_NOT_EXIST);
     }
     echo "deleting the post\n";
     Content::delete_by_id($post->content_id);
     echo "testing that the post is not retrievable\n";
     try {
         $post_retr_fail = Content::load_content($post->content_id, $user->user_id);
         $this->assertTrue(FALSE);
         // shouldn't get here
     } catch (PAException $e) {
         $this->assertEquals($e->getCode(), CONTENT_NOT_FOUND);
     }
     echo "testing that the last comment is not retrievable\n";
     $cmt_retr_fail = new Comment();
     try {
         $cmt_retr_fail->load($cmt->comment_id);
         $this->assertTrue(FALSE);
         // shouldn't get here
     } catch (PAException $e) {
         $this->assertEquals($e->getCode(), COMMENT_NOT_EXIST);
     }
     //    summarize_timed_queries();
 }
Ejemplo n.º 11
0
 public function actionEdit($book_id, $post_id = 0)
 {
     $this->loadBook($book_id);
     $post_id = (int) $post_id;
     if (!$this->book->can("blog_r") || !$this->book->can("blog_w")) {
         throw new CHttpException(403, "Вы не можете писать и редактировать посты в блоге этого перевода. " . $this->book->getWhoCanDoIt("blog_w"));
     }
     if ($post_id != 0) {
         $post = BlogPost::model()->findByPk($post_id);
         if (!$post) {
             throw new CHttpException(404, "Поста не существует. Возможно, его удалили.");
         }
         if ($post->user_id != Yii::app()->user->id and !Yii::app()->user->can("blog_moderate")) {
             throw new CHttpException(403, "Вы можете редактировать только собственные посты.");
         }
         if ($post->book_id == 0) {
             $this->redirect("/blog/{$post->id}/edit");
         }
         if ($post->book_id != $this->book->id) {
             $this->redirect("/book/{$post->book_id}/blog/{$post->id}/edit");
         }
         if ($post->isAnnounce) {
             throw new CHttpException(404, "Поста не существует. Возможно, его удалили.");
         }
     } else {
         $post = new BlogPost();
         $post->user_id = Yii::app()->user->id;
         $post->book_id = $this->book->id;
         $post->topics = isset($_GET["topic"]) ? (int) $_GET["topic"] : 3;
     }
     $post->book = $this->book;
     if (isset($_POST["BlogPost"])) {
         $post->attributes = $_POST["BlogPost"];
         if ($post->save()) {
             // Добавляем пост в мои обсуждения
             $post->setTrack();
             $this->redirect($post->url);
         }
     }
     $this->render("//blog/edit", array("post" => $post));
 }
Ejemplo n.º 12
0
 /**
  * 登録日を更新する
  *
  * @return boolean
  */
 public function updateBlogEntryDate($dbConfig)
 {
     $this->connectDb($dbConfig, 'plugin');
     CakePlugin::load('Blog');
     App::uses('BlogPost', 'Blog.Model');
     $BlogPost = new BlogPost();
     $BlogPost->contentSaving = false;
     $datas = $BlogPost->find('all', array('recursive' => -1));
     if ($datas) {
         $ret = true;
         foreach ($datas as $data) {
             $data['BlogPost']['posts_date'] = date('Y-m-d H:i:s');
             unset($data['BlogPost']['eye_catch']);
             $BlogPost->set($data);
             if (!$BlogPost->save($data)) {
                 $ret = false;
             }
         }
         return $ret;
     } else {
         return false;
     }
 }
Ejemplo n.º 13
0
    $this->setMessage('blog_contents テーブルのデータ更新に成功しました。');
} else {
    $this->setMessage('blog_contents テーブルのデータ更新に失敗しました。', true);
}
/**
 * blog_posts 更新
 *
 * 保存処理を行う事で contents テーブルに検索データを追加
 */
App::import('Model', 'Blog.BlogPost');
$BlogPost = new BlogPost();
// contents テーブルに登録する際、ClassRegistry::init() で、BlogCategoryを呼び出すが
// なぜか、既に登録されている BlogCategory は、actAs が空になっている為、
// getPath が呼び出せずエラーとなってしまう。
// 再インスタンス化する為に、一旦削除する
ClassRegistry::removeObject('BlogCategory');
$blogPosts = $BlogPost->find('all');
$result = true;
foreach ($blogPosts as $blogPost) {
    if ($BlogPost->save($blogPost)) {
        continue;
    } else {
        $result = false;
        break;
    }
}
if ($result) {
    $this->setMessage('blog_contents > contents テーブルのデータ更新に成功しました。');
} else {
    $this->setMessage('blog_contents > contents テーブルのデータ更新に失敗しました。', true);
}