Ejemplo n.º 1
0
 public function actionCreate()
 {
     //$data = (array)json_decode( file_get_contents('php://input') );
     //echo (var_dump($data));
     $model = new Post();
     $model->setAttributes($this->getJsonInput());
     //$model->setAttributes($data);
     if (!$model->validate()) {
         $this->sendResponse(400, CHtml::errorSummary($model));
     } else {
         if (!$model->save(false)) {
             throw new CException('Cannot create a record');
         }
     }
     $model->refresh();
     echo CJSON::encode($model);
     /*
     		if(isset($_GET['id']))
                 $id=$_GET['id'];
     		$posts = Post::model()->findAllByAttributes(array("author"=>1));
     		foreach($posts as $p) {
     			$author = User::model()->findByPk($p['author']);
     			$p['author'] = $author['name'];
     		}
     		echo CJSON::encode($posts);*/
 }
Ejemplo n.º 2
0
 /**
  * This function performs the validation work for complex object models.
  *
  * In addition to checking the current object, all related objects will
  * also be validated.  If all pass then <code>true</code> is returned; otherwise
  * an aggreagated array of ValidationFailed objects will be returned.
  *
  * @param      array $columns Array of column names to validate.
  * @return     mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  */
 protected function doValidate($columns = null)
 {
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $failureMap = array();
         // We call the validate method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aUser !== null) {
             if (!$this->aUser->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aUser->getValidationFailures());
             }
         }
         if ($this->aPost !== null) {
             if (!$this->aPost->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aPost->getValidationFailures());
             }
         }
         if (($retval = CommentPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
Ejemplo n.º 3
0
 public function postit()
 {
     $post = new Post(array("from_user" => $this->user->id, "title" => RequestMethods::post('title'), "content" => RequestMethods::post('content'), "category" => RequestMethods::post('category')));
     if ($post->validate()) {
         $post->save();
         return "success";
     } else {
         return "validation not good";
     }
 }
 public function post_create()
 {
     $validation = Post::validate(Input::all());
     if ($validation->fails()) {
         return Redirect::to_route('post_new')->with_errors($validation)->with_input();
     } else {
         Post::create(array('title' => Input::get('title'), 'body' => Input::get('body'), 'author' => Input::get('author'), 'category_id' => Input::get('category')));
         return Redirect::to_route('post_new')->with('message', 'New Post has been added!');
     }
 }
Ejemplo n.º 5
0
 public function testRelatedContentRecord()
 {
     // Create Post
     $post = new Post();
     $post->message = "Test";
     $post->content->container = Yii::app()->user->getModel();
     $this->assertTrue(isset($post->content) && $post->content instanceof Content);
     $this->assertTrue($post->validate());
     $this->assertTrue($post->save());
     $this->assertEquals(1, Content::model()->countByAttributes(array('object_model' => 'Post', 'object_id' => $post->getPrimaryKey())));
 }
Ejemplo n.º 6
0
 public function put_update()
 {
     $validation = Post::validate(Input::all());
     $s = Input::get('title');
     $t = Str::slug($s);
     $post = Post::find(Input::get('id'));
     if ($validation->fails()) {
         return Redirect::to_route('post_edit', $post->slug)->with_errors($validation)->with_input();
     } else {
         Post::update(Input::get('id'), array('title' => Input::get('title'), 'body' => Input::get('body'), 'author' => Input::get('author'), 'category_id' => Input::get('category')));
         return Redirect::to_route('post_view', $post->slug)->with('message', 'Post has been updated successfully!');
     }
 }
Ejemplo n.º 7
0
 /**
  * Store a newly created post in DB.
  *
  */
 public function store()
 {
     $validator = Post::validate($data = Input::all());
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     // We remove quotes from tag_ids with array_map intval
     $tag_ids = array_map('intval', $data['tags']);
     $post = Post::create(['user_id' => $data['user_id'], 'title' => $data['title'], 'content' => $data['content'], 'status' => $data['status']]);
     $post->tags()->sync($tag_ids);
     $post->categories()->attach($data['category']);
     Event::fire('post.created', array($data));
     return Redirect::route('posts.index')->withSuccess(Lang::get('larabase.post_created'));
 }
Ejemplo n.º 8
0
 public function actionCreate()
 {
     $model = new Post();
     $model->setAttributes($this->getJsonInput());
     if (!$model->validate()) {
         $this->sendResponse(400, CHtml::errorSummary($model));
     } else {
         if (!$model->save(false)) {
             throw new CException('Cannot create a record');
         }
     }
     $model->refresh();
     $this->sendResponse(200, CJSON::encode($model));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $validator = Post::validate(Input::all());
     if ($validator->fails()) {
         return Redirect::to('posts/' . $id . '/edit')->withErrors($validator)->withInput(Input::all());
     } else {
         // store
         $post = Post::find($id);
         $post->title = Input::get('title');
         $post->body = Input::get('body');
         $post->save();
         // redirect
         return Redirect::to('posts')->with('message', 'Successfully updated');
     }
 }
 /**
  * Creates a new post.
  * If creation is successful, the browser will be redirected to the 'show' page.
  */
 public function actionCreate()
 {
     $post = new Post();
     if (isset($_POST['Post'])) {
         $post->attributes = $_POST['Post'];
         if (isset($_POST['previewPost'])) {
             $post->validate();
         } else {
             if (isset($_POST['submitPost']) && $post->save()) {
                 $this->redirect(array('show', 'id' => $post->id));
             }
         }
     }
     $this->render('create', array('post' => $post));
 }
Ejemplo n.º 11
0
 public function update()
 {
     $content = Input::all();
     $post = new Post();
     foreach ($content['data'] as $object) {
         if ($post->validate($object)) {
             $posts = Post::find($object['id']);
             $posts->title = $object['title'];
             $posts->content = $object['content'];
             $posts->save();
         } else {
             return Response::json(array('error' => $post->errors()), 500);
         }
     }
     return Response::json(array('error' => false, 'msg' => 'post update'));
 }
Ejemplo n.º 12
0
 /**
  * Tests SlugBehavior validation.
  *
  * @return void
  * @since 0.1.0
  */
 public function testValidation()
 {
     $defaultAttributes = array('name' => 'Test post post post', 'content' => 'Long enough to conform validation', 'user_id' => 1, 'category_id' => 1, 'slug' => 'admin');
     $post = new \Post();
     $post->setAttributes($defaultAttributes, false);
     if ($post->save(false)) {
         $message = 'Restricted slug hasn\'t been detected by SlugBehavior ' . '(resulting slug: [' . $post->slug . '])';
         $this->fail($message);
     }
     $this->assertTrue(in_array('slugBehavior.restrictedSlug', $post->getErrors('slug'), true));
     $post->setAttributes(array('slug' => '', 'name' => ''), false);
     $post->validate(array());
     if ($post->save(false)) {
         $this->fail('Empty slug hasn\'t been detected by SlugBehavior');
     }
     $this->assertTrue(in_array('slugBehavior.emptySlug', $post->getErrors('slug'), true));
 }
Ejemplo n.º 13
0
 public function actionPost()
 {
     $this->forcePostRequest();
     $_POST = Yii::app()->input->stripClean($_POST);
     $post = new Post();
     $post->content->populateByForm();
     $post->message = Yii::app()->request->getParam('message');
     if ($post->validate()) {
         $post->save();
         // Experimental: Auto attach found images urls in message as files
         if (isset(Yii::app()->params['attachFilesByUrlsToContent']) && Yii::app()->params['attachFilesByUrlsToContent'] == true) {
             File::attachFilesByUrlsToContent($post, $post->message);
         }
         $this->renderJson(array('wallEntryId' => $post->content->getFirstWallEntryId()));
     } else {
         $this->renderJson(array('errors' => $post->getErrors()), false);
     }
 }
Ejemplo n.º 14
0
 public static function newPost()
 {
     if (Request::isMethod('get')) {
         $groups = DB::table('gsubs')->join('groups', 'groups.group_name', '=', 'gsubs.group_name')->where('gsubs.is_member', 1)->where('gsubs.user_fp', self::userFp())->select('gsubs.*', 'groups.group_title')->get();
         return View::make('board.new_post', ['groups' => $groups]);
     } else {
         $user_fp = self::userFp();
         $input = Input::only('parent_id', 'chan', 'group_name', 'message', 'title', 'source_link');
         Post::validate($input);
         Post::antiflood($user_fp);
         Post::checkDoublePost($user_fp);
         $post = Post::createPost($user_fp, $input);
         if ($post->parent_id == 0) {
             return Redirect::to("p/{$post->id}");
         } else {
             return Redirect::to("p/{$post->parent_id}#p{$post->id}");
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'show' page.
  */
 public function actionCreate()
 {
     $model = new Post();
     if (isset($_POST['Post'])) {
         $model->attributes = $_POST['Post'];
         if (isset($_POST['previewPost'])) {
             $model->validate();
         } else {
             if (isset($_POST['submitPost']) && $model->save()) {
                 if (Yii::app()->user->status == User::STATUS_VISITOR) {
                     Yii::app()->user->setFlash('message', 'Thank you for your post. Your post will be posted once it is approved.');
                     $this->redirect(Yii::app()->homeUrl);
                 }
                 $this->redirect(array('show', 'slug' => $model->slug));
             }
         }
     }
     $this->pageTitle = Yii::t('lan', 'New Post');
     $this->render('create', array('model' => $model));
 }
Ejemplo n.º 16
0
 public function actionAdd()
 {
     $model = new Post();
     $categories = $this->getAllCategories();
     // uncomment the following code to enable ajax-based validation
     /*http://130.164.10.138/trac/newticket
     		if(isset($_POST['ajax']) && $_POST['ajax']==='post-add-form')
     		{
     			echo CActiveForm::validate($model);
     			Yii::app()->end();
     		}
     		*/
     if (isset($_POST['Post'])) {
         $model->attributes = $_POST['Post'];
         $categories = $this->getCategoriesfromPost();
         $model->userid = Yii::app()->user->id;
         $model->dateUpdated = new CDbExpression("now()");
         //THis is the one to use for MySql
         $model->clicks = 1;
         if ($model->validate()) {
             // form inputs are valid, do something here
             //$model->dateUpdated=new CDbExpression("datetime('now')"); //This is the one to use for SQl Lite
             $model->dateUpdated = new CDbExpression("now()");
             //THis is the one to use for MySql
             $model->clicks = 1;
             //$model->categories=$categories;
             //$model->addRelatedRecord('categories',$categories,true);
             if ($model->save()) {
                 $model->addCategories($model->id, $categories);
                 $this->redirect(array('view', 'id' => $model->id));
             }
             //return;
         }
     }
     $this->render('add', array('model' => $model, 'categories' => $categories));
 }
Ejemplo n.º 17
0
 public function postEditPost($id)
 {
     $input = Input::all();
     $validator = Post::validate($input);
     if ($validator->fails()) {
         FlashHelper::message("Null title", FlashHelper::DANGER);
         return Redirect::to(URL::action('BlogController@getNewPost'))->withInput();
     }
     // Post
     $Parsedown = new Parsedown();
     $post = Post::findOrFail($id);
     if ($post->created_by != Auth::id()) {
         return View::make('error.Unauthorized');
     }
     $post->title = Input::get('title');
     $post->makrdown = Input::get('makrdown');
     if (!is_null($post->makrdown)) {
         $post->HTML = $Parsedown->text($post->makrdown);
     }
     $post->privacy_level = Input::get('privacy_level');
     $post->can_comment = Input::get('can_comment');
     // tags
     $topics = trim(Input::get('tags'));
     if ($topics != "") {
         $topics = explode(";", $topics);
         $tagIds = array();
         // Topic Tags
         foreach ($topics as $topic) {
             $tag = Tag::firstOrCreate(array('name' => trim($topic)));
             $tagIds[] = $tag->id;
         }
         // post <=> Tags
         $post->tags()->sync($tagIds);
     }
     // privacy
     if ($post->privacy_level == Post::_CUSTOM) {
         $friends = trim(Input::get('friends'));
         if ($friends == "") {
             $post->privacy_level = Post::_PRIVATE;
         } else {
             $friends = explode(",", $friends);
             $post->friends()->sync($friends);
         }
     }
     $post->save();
     return Redirect::to($post->getShowLink());
 }
Ejemplo n.º 18
0
// ha van bármi a POST-ban akkor abból csinálunk egy objektumot
if (!empty($textarea) || !empty($tags)) {
    $post = new Post(['text' => $textarea, 'tags' => $tags]);
} else {
    // blogpost id-je, ami alapján behozta a blogpostot a list.php
    if (isset($_REQUEST['id'])) {
        $post = Post::getObject($_GET['id']);
    }
}
//létrehozunk egy üres objektumot, hogy ne legyen notice az echozásnál
if (!isset($post)) {
    $post = new Post();
}
//classPost példányosítás
//$connect = new PDO ('mysql:host=localhost;dbname=blog','root','4fhc9imz'); //nemtudom jó ez e itt, szükség van rá a 65 sorhoz.
if ($post->validate()) {
    /*var_dump ($post);*/
}
/*var_dump ($post->tags);*/
/*if(isset($_POST['Előnézet']) && ($_POST['textarea']) && ($_POST['tags']))
{
echo ($_POST['textarea']), "<br />";
echo ($_POST['tags']);
}
*/
//Deklarálja a $connect változót. Ez egy PDO segítségével kapcsolatot hoz létre az adatbázissal.
//$connect = new PDO ('mysql:host=localhost;dbname=blog','root','4fhc9imz');
/*
Ha le lett nyomva a közzétesz gomb ÉS validált két változót a validate függvény
*/
//if (isset($_POST['Közzétesz']) && ($post->validate()))
Ejemplo n.º 19
0
 public function actionCreate()
 {
     $lang = $this->getLanguageCode();
     //dùng để lấy danh sách category theo ngon ngữ đả chọn
     $errorArray = NULL;
     $PostLanguage = NULL;
     //tạo quyền để người dùng có thể upload ảnh
     if (!isset($_SESSION['filemanager'])) {
         $_SESSION['filemanager'] = true;
     }
     $_SESSION['currentFolder'] = 'post/';
     //tạo array để hiện thị trên dropDownList category
     $listCategory_Array = CategoryLanguage::model()->getListCategoryWithLanguage($lang);
     $model = new Post();
     if (Yii::app()->request->getParam('id')) {
         //nếu không tồn tại thì lấy phần tử đầu tiên trong category
         $model->category_id = Yii::app()->request->getParam('id');
     }
     unset($listCategory_Array[1]);
     //get danh sách ngôn ngữ trong csdl
     $modellanguage = Language::model()->findAll();
     if (Yii::app()->request->getPost('Post')) {
         $Post = Yii::app()->request->getPost('Post');
         $Post['start_date'] = Yii::app()->extraFunctions->setFormatDate($Post['start_date']);
         $Post['end_date'] = Yii::app()->extraFunctions->setFormatDate($Post['end_date']);
         $model->attributes = $Post;
         $model->created_date = date('Y-m-d H:i:s');
         $model->modified_date = date('Y-m-d H:i:s');
         if ($model->start_date == '') {
             $model->start_date = date('Y-m-d H:i:s');
         }
         $model->created_by = Yii::app()->user->id;
         $model->modified_by = Yii::app()->user->id;
         //cắt chuỗi lấy tên ảnh
         $thumbnailArray = explode('/', $Post['thumbnail']);
         $thumbnail_text = '';
         //            for ($i = 0; $i < count($thumbnailArray) - 1; $i++)
         //            {
         //                if ($thumbnailArray[$i] != '' && $thumbnailArray[$i] != 'images' && $thumbnailArray[$i] != 'post')
         //                    $thumbnail_text = $thumbnail_text . $thumbnailArray[$i] . '/';
         //            }
         if (count($thumbnailArray) > 3) {
             for ($i = 3; $i < count($thumbnailArray) - 1; $i++) {
                 $thumbnail_text = $thumbnail_text . $thumbnailArray[$i] . '/';
             }
         }
         $thumbnail_text = $thumbnail_text . $thumbnailArray[count($thumbnailArray) - 1];
         $model->thumbnail = $thumbnail_text;
         $model->post_params = CJSON::encode($_POST['Post']['post_params']);
         $model->featured = $Post['featured'];
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $PostLanguage = Yii::app()->request->getPost('Postlanguage');
             if ($model->validate()) {
                 //kiểm tra save vào table post trước
                 if ($model->save()) {
                     //save thành công vào table Post
                     //kiểm tra save vào table post_language
                     $this->checkPostlanguage($PostLanguage, $errorArray);
                     if ($errorArray != null) {
                         throw new Exception('error');
                         //tạo ra 1 thông báo lỗi để $transaction phía trên rollback lại
                     } else {
                         if (count($PostLanguage) == 0) {
                             //nếu không nhập bất kỳ 1 language nào thì báo lỗi
                             Yii::app()->user->setFlash('Failure', Yii::t('post', 'title, intro_text, full_text cannot be blank.'));
                             $transaction->rollback();
                         } else {
                             //nếu $errorArray==null tức là ko có lỗi
                             foreach ($PostLanguage as $value) {
                                 $modelpostlanguage = new PostLanguage();
                                 $languageid = Language::model()->find('code=:lang', array(':lang' => $value['code']))->id;
                                 $modelpostlanguage->post_id = $model->id;
                                 //save post success, get post_id
                                 $modelpostlanguage->language_id = $languageid;
                                 $modelpostlanguage->title = $value['title'];
                                 $modelpostlanguage->intro_text = $value['intro_text'];
                                 $modelpostlanguage->full_text = $value['full_text'];
                                 $modelpostlanguage->save();
                             }
                             $transaction->commit();
                             Yii::app()->user->setFlash('Success', Yii::t('post', 'Add Success Post with id') . $model->id);
                             //Xóa cache redis
                             // $this->deleteCacheRedis('post:' . $model->category_id);
                             $this->redirect(array('/' . backend . '/post/admin/id/' . $model->category_id));
                         }
                     }
                 }
             }
         } catch (Exception $e) {
             Yii::app()->user->setFlash('Failure', Yii::t('post', 'Add Post Failure'));
             $transaction->rollback();
         }
     }
     $this->render('create', array('model' => $model, 'modellanguage' => $modellanguage, 'modelpostlanguage' => $PostLanguage, 'listCategory_Array' => $listCategory_Array, 'errorArray' => $errorArray));
 }
Ejemplo n.º 20
0
 public function postSlideHome($type)
 {
     if (\Request::ajax()) {
         if (isset($_POST["action"]) && $_POST["action"] == "delete") {
             $post = \Post::find($_POST["id"]);
             $isparent = \Post::where("parent_id", $post->id);
             if (count($isparent) > 0) {
                 echo "You cannot delete this record it is associated with a page or pageblock";
             } else {
                 if ($post->delete()) {
                     \Session::put("success_message", $post->title . " Succesfully Deleted");
                     if ($_POST['type'] == "slideshow") {
                         $image = \Slideshow::where("img_name", $_POST["image"])->first();
                         $image->status = 0;
                         $image->update();
                     }
                     echo "record successfully deleted";
                 } else {
                     \Session::put("error_message", $post->title . " Unexpected Error! Record could not be deleted");
                     echo "Unexpected Error! Record could not be deleted";
                 }
             }
         }
         if ($type == "slideimage") {
             $ds = DIRECTORY_SEPARATOR;
             //1
             $storeFolder = './uploads/slideshow';
             //stores file in slider folder in uploads
             if (!empty($_FILES)) {
                 $tempFile = $_FILES['file']['tmp_name'];
                 //3
                 $targetPath = $storeFolder . $ds;
                 //4
                 $targetFile = $targetPath . $_FILES['file']['name'];
                 //5
                 if (move_uploaded_file($tempFile, $targetFile)) {
                     $image = new \Slideshow();
                     $image->img_name = basename($_FILES['file']['name']);
                     $image->size = $_FILES['file']['size'];
                     $image->save();
                 }
             }
         }
         exit;
     }
     if ($type == "slidepost") {
         //not longeer function all post route through postAddPage method
         $validation = \Post::validate(\Input::all());
         $input = \Input::all();
         if ($validation->fails()) {
             if ($input['type'] == "page") {
                 return \Redirect::back()->withErrors($validation)->withInput();
             } elseif ($input['type'] == "post") {
                 return \Redirect::back()->withErrors($validation)->withInput();
             } elseif ($input['type'] == "category") {
                 return \Redirect::back()->withErrors($validation)->withInput();
             } elseif ($input['type'] == "custom menu") {
                 return \Redirect::back()->withErrors($validation)->withInput();
             }
         } else {
             $post = new \Post();
             isset($_POST['description']) ? $post->description = \Input::get("description") : "";
             $post->title = $input['title'];
             $post->p_content = $input['p_content'];
             $post->permalink = $input['permalink'];
             $post->type = $input['type'];
             $post->parent_id = $input['parent_id'];
             $post->image = isset($_POST['image']) ? $input['image'] : "";
             //$post->view_status      =   $input['view_status'];
             $post->created_by = "Admin";
             $post->meta_keyword = $input['meta_keyword'];
             $post->meta_description = $input['meta_description'];
             $post->meta_title = $input['meta_title'];
             //$post->image            =   (isset($file) && $file != "") ? $file : "";
             //var_dump($post);
             try {
                 $post = $post->save();
                 // $redirect = (isset($input['form_save'])) ? "backend/{$input['type']}s" : "backend/{$input['type']}s/create";
                 return \Redirect::back()->with('success_message', 'The ' . $input["type"] . ' was created.');
             } catch (ValidationException $e) {
                 return \Redirect::back()->withInput()->withErrors($e->getErrors());
             }
         }
     } elseif ($type == "pageblockimage") {
         // this procedure is used to add page block image
         $ds = DIRECTORY_SEPARATOR;
         //1
         $storeFolder = './uploads';
         //stores file in slider folder in image
         if (!empty($_FILES)) {
             $tempFile = $_FILES['file']['tmp_name'];
             //3
             $targetPath = $storeFolder . $ds;
             //4
             $targetFile = $targetPath . $_FILES['file']['name'];
             //5
             if (move_uploaded_file($tempFile, $targetFile)) {
                 echo "Image Uploaded";
                 exit;
             }
         }
     }
 }
Ejemplo n.º 21
0
<?php

include 'post.class.php';
include 'db_connect.php';
include 'debug.php';
$arr = array();
// this are is going to be populated with data or errors
$validate = Post::validate($arr);
if ($validate) {
    /* data is ready for database insertion */
    $query_insert_post_data = "INSERT INTO posts(title,body,country,user,votes) VALUES('" . $arr['title'] . "','" . $arr['body'] . "','" . $arr['country'] . "','" . $arr['user'] . "','0')";
    mysqli_query($mysqli, $query_insert_post_data);
    $arr = array_map('stripslashes', $arr);
    $arr['date_time'] = date('r', time());
    $insert_post = new Post($arr);
    echo json_encode(array('status' => 1, 'html' => $insert_post->markup()));
} else {
    /* outputing error messages */
    echo '{"status":0,"errors":' . json_encode($arr) . '}';
}
Ejemplo n.º 22
0
 public function actionEditBlog($id)
 {
     $model = new Post();
     $rec = Post::model()->findByPk($id);
     $r = Lookup::model()->findAll(array('condition' => 'type=:t', 'params' => array(':t' => 'PostStatus')));
     //echo "<pre>";print_r($r);die;
     foreach ($r as $type) {
         //echo "<pre>";print_r($type);
         $i[] = $type->id;
         $n[] = $type->name;
         $op = array_combine($i, $n);
     }
     //die;
     //echo "<pre>";print_r($rec);die;
     if (isset($_POST['Post'])) {
         $model->attributes = $_POST['Post'];
         if ($model->validate()) {
             $res = Post::model()->findByPk($id);
             $res->title = $_REQUEST['Post']['title'];
             $res->content = $_REQUEST['Post']['content'];
             $res->tags = $_REQUEST['Post']['tags'];
             $res->status = $_REQUEST['Post']['status'];
             $res->update_time = date('Y-m-d');
             if ($res->save(false)) {
                 $this->redirect(array('postlisting'));
             }
         } else {
             $errors = $model->getErrors();
         }
     }
     $this->render('editblog', array('edit' => $rec, 'model' => $model, 'type' => $op, 'i' => $i));
 }
Ejemplo n.º 23
0
 public function testValidation()
 {
     $post = new Post();
     $post->val('text', 'TEXT is text');
     $post->val('num', 10);
     $error_list = $post->validate();
     $this->assertEquals(0, count($error_list));
     $post = new Post();
     $post->val('text', 'bad text');
     $post->val('num', 10);
     $error_list = $post->validate();
     $this->assertEquals(1, count($error_list));
     $post = new Post();
     $post->val('text', 'TEXT is text');
     $post->val('num', 'NaN');
     $error_list = $post->validate();
     $this->assertEquals(1, count($error_list));
     $post = new Post();
     $post->val('text', 'TEXT is text');
     $post->val('num', -1);
     $error_list = $post->validate();
     $this->assertEquals(1, count($error_list));
     $post = new Post();
     $post->val('text', 'bad text');
     $post->val('num', 'bad number');
     $error_list = $post->validate();
     $this->assertEquals(2, count($error_list));
     $post = new Post();
     $post->val('text', '');
     $post->val('num', '');
     $error_list = $post->validate();
     $this->assertEquals(1, count($error_list));
 }
Ejemplo n.º 24
0
 public function createPost()
 {
     $user_fp = self::userFp();
     $input = Input::only('parent_id', 'chan', 'group_name', 'message', 'title', 'source_link');
     Post::validate($input);
     Post::antiflood($user_fp);
     Post::checkDoublePost($user_fp);
     $post = Post::createPost($user_fp, $input);
     return Response::json(["status" => "ok", "parent_id" => $post->parent_id, "post_id" => $post->id]);
 }
Ejemplo n.º 25
0
 private function write_to_db($blogshop_id, $rss_item, $hash_filename)
 {
     $post = new Post();
     $post->dateUpdated = $rss_item->get_date();
     $post->title = $rss_item->get_title();
     //$post->url=$rss_item->get_link();
     $post->url = 'http://www.stephen.com';
     $post->remarks = 'Hello';
     $post->file_hash = $hash_filename;
     $post->blogid = $blogshop_id;
     if (!$post->validate(null, true)) {
         $error_string = '';
         throw new CHttpException(500, 'Error in validation ' . print_r($post->getErrors()));
     }
     if (!$post->save()) {
         throw new CHttpException(500, 'Error in saving');
     }
 }
 public function test_validation_of_post_with_valid_parameters()
 {
     $post_params = array("title" => "My blog is live now", "body" => "Some desc");
     $validator = Post::validate($post_params);
     $this->assertFalse($validator->fails(), false);
 }