예제 #1
0
 /**
  * View a blog post.
  *
  * @param  string   $slug
  * @return Redirect
  */
 public function postView($slug)
 {
     // The user needs to be logged in, make that check please
     if (!Sentry::check()) {
         return Redirect::to("blog/{$slug}#comments")->with('error', Lang::get('post.messages.login'));
     }
     // Get this blog post data
     $post = $this->post->where('slug', $slug)->first();
     // get the  data
     $new = Input::all();
     $comment = new Comment();
     // If validation fails, we'll exit the operation now
     if ($comment->validate($new)) {
         // Save the comment
         $comment->user_id = Sentry::getUser()->id;
         $comment->content = e(Input::get('comment'));
         // Was the comment saved with success?
         if ($post->comments()->save($comment)) {
             // Redirect to this blog post page
             return Redirect::to("blog/{$slug}#comments")->with('success', 'Your comment was successfully added.');
         }
     } else {
         // failure, get errors
         return Redirect::to("blog/{$slug}#comments")->withInput()->withErrors($comment->errors());
     }
     // Redirect to this blog post page
     return Redirect::to("blog/{$slug}#comments")->with('error', Lang::get('post.messages.generic'));
 }
예제 #2
0
 public function postComment($id)
 {
     $input = Input::all();
     Log::info($input);
     $validator = Comment::validate($input);
     if ($validator->fails()) {
         FlashHelper::message("Null title", FlashHelper::DANGER);
         return;
     }
     $post = Post::findOrFail($id);
     if (!$post->can_comment || !PrivacyHelper::checkPermission(Auth::user(), $post)) {
         throw new Exception("Don't have permision");
     }
     $comment = new Comment();
     $Parsedown = new Parsedown();
     $comment->post_id = $id;
     $comment->parrent_id = $input['parrent_id'];
     $comment->markdown = $input['markdown'];
     Log::info($comment);
     $comment->HTML = $Parsedown->text($comment->markdown);
     $comment->save();
     $comment->comments = array();
     $data['html'] = View::make('posts._comment')->with('data', $comment)->with('level', count($comment->parents()))->with('can_comment', true)->render();
     $data['status'] = true;
     $data['parent_id'] = $comment->parrent_id;
     return Response::json($data);
 }
예제 #3
0
 /**
  * @param $model
  * @return Comment
  */
 public function processRequest($model)
 {
     $comment = new Comment();
     if (Yii::app()->request->isPostRequest) {
         $comment->attributes = Yii::app()->request->getPost('Comment');
         if (!Yii::app()->user->isGuest) {
             $comment->name = Yii::app()->user->name;
             $comment->email = Yii::app()->user->email;
         }
         if ($comment->validate()) {
             $pkAttr = $model->getObjectPkAttribute();
             $comment->class_name = $model->getClassName();
             $comment->object_pk = $model->{$pkAttr};
             $comment->user_id = Yii::app()->user->isGuest ? 0 : Yii::app()->user->id;
             $comment->save();
             $url = Yii::app()->getRequest()->getUrl();
             if ($comment->status == Comment::STATUS_WAITING) {
                 $url .= '#';
                 Yii::app()->user->setFlash('messages', Yii::t('CommentsModule.core', 'Ваш комментарий успешно добавлен. Он будет опубликован после проверки администратором.'));
             } elseif ($comment->status == Comment::STATUS_APPROVED) {
                 $url .= '#comment_' . $comment->id;
             }
             // Refresh page
             Yii::app()->request->redirect($url, true);
         }
     }
     return $comment;
 }
 /** 
  * Controller action for viewing a questions.
  * Also provides functionality for creating an answer,
  * adding a comment and voting.
  */
 public function actionView()
 {
     error_reporting(E_ALL);
     ini_set("display_errors", 1);
     $question = Question::model()->findByPk(Yii::app()->request->getParam('id'));
     if (isset($_POST['Answer'])) {
         $answerModel = new Answer();
         $answerModel->attributes = $_POST['Answer'];
         $answerModel->created_by = Yii::app()->user->id;
         $answerModel->post_type = "answer";
         $answerModel->question_id = $question->id;
         if ($answerModel->validate()) {
             $answerModel->save();
             $this->redirect($this->createUrl('//questionanswer/main/view', array('id' => $question->id)));
         }
     }
     if (isset($_POST['Comment'])) {
         $commentModel = new Comment();
         $commentModel->attributes = $_POST['Comment'];
         $commentModel->created_by = Yii::app()->user->id;
         $commentModel->post_type = "comment";
         $commentModel->question_id = $question->id;
         if ($commentModel->validate()) {
             $commentModel->save();
             $this->redirect($this->createUrl('//questionanswer/main/view', array('id' => $question->id)));
         }
     }
     // User has just voted on a question
     if (isset($_POST['QuestionVotes'])) {
         $questionVotesModel = new QuestionVotes();
         $questionVotesModel->attributes = $_POST['QuestionVotes'];
         QuestionVotes::model()->castVote($questionVotesModel, $question->id);
     }
     $this->render('view', array('author' => $question->user->id, 'question' => $question, 'answers' => Answer::model()->overview($question->id), 'related' => Question::model()->related($question->id)));
 }
예제 #5
0
	/**
	 * @param $model
	 * @return Comment
	 */
	public function processRequest($model)
	{
        Yii::import('application.modules.users.models.User');
        Yii::import('application.modules.catalog.models.Orgs');
		$comment = new Comment;
		if(Yii::app()->request->getPost('Comment'))
		{
			$comment->attributes = Yii::app()->request->getPost('Comment');
			$ratingAjax = null;
			if(isset($_POST['Comment']['rating'])){
				$ratingAjax = (int)$_POST['Comment']['rating'];
				if($ratingAjax == 0) $ratingAjax = null;
			}
			$comment->rating = $ratingAjax;

			if(!Yii::app()->user->isGuest)
			{
				$comment->name = Yii::app()->user->username;
				$comment->email = Yii::app()->user->email;
			}
			
			$comment->status = Comment::STATUS_WAITING;
			if($comment->validate())
			{
				// $pkAttr = $model->getObjectPkAttribute();
				// $comment->class_name = $model->getClassName();
				$comment->object_pk = $model->id;
				$comment->user_id = Yii::app()->user->isGuest ? 0 : Yii::app()->user->id;
				if(!$comment->save()){
					// VarDumper::dump($comment->errors); die(); // Ctrl + X  Delete line
				}

				$url = Yii::app()->getRequest()->getUrl();
			//	if($comment->rating) {
			//		$this->starRating($comment->object_pk, $comment->rating);
			//	}
				

				if($comment->status==Comment::STATUS_WAITING)
				{
					$url.='#';
					Yii::app()->user->setFlash('messages', 'Ваш комментарий успешно добавлен. ');
              
				} elseif($comment->status==Comment::STATUS_APPROVED){
					$url.='#comment_'.$comment->id;
				}
               
	                if(Yii::app()->request->isAjaxRequest){
	                	echo '[]';
	                	Yii::app()->end();
	                } else {
					// Refresh page
					Yii::app()->request->redirect($url, true);
					}
			} 
		}
		return $comment;
	}
예제 #6
0
 /**
  * To add comments into a particular thread
  * @param $comment
  **/
 public function write(Comment $comment)
 {
     if (!$comment->validate()) {
         throw new ValidationException('invalid comment');
     }
     $db = DB::conn();
     $params = array('thread_id' => $this->id, 'username' => $comment->username, 'body' => $comment->body);
     $db->insert('comment', $params);
 }
예제 #7
0
 public function post_add()
 {
     $id = Input::get('id');
     //Find the id of the post
     $post = Post::find($id);
     $validation = Comment::validate(Input::all());
     if ($validation->fails()) {
         return Redirect::to_route('post_view', $post->slug)->with_errors($validation)->with_input();
     } else {
         Comment::create(array('user' => Input::get('user'), 'post_id' => Input::get('id'), 'comment_msg' => Input::get('comment_msg')));
         return Redirect::to_route('post_view', $post->slug)->with('message', 'Comment Posted successfully!');
     }
 }
예제 #8
0
 /**
  * create new thread
  * @param Comment $comment
  * @throws ValidationException
  */
 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();
     $db->query('INSERT INTO thread SET title = ?, created = NOW()', array($this->title));
     $this->id = $db->lastInsertId();
     // write first comment at the same time
     $this->write($comment);
     $db->commit();
 }
예제 #9
0
 public function edit(Comment &$comment)
 {
     $this->validate();
     $comment->validate();
     if ($this->hasError() || $comment->hasError()) {
         throw new ValidationException('Invalid thread or comment.');
     }
     $db = DB::conn();
     $db->begin();
     try {
         $db->query("UPDATE thread SET title=?, category_name=?,\n                last_modified=NOW() WHERE id=?", array($this->title, $this->category, $this->id));
         $comment->edit();
         $db->commit();
     } catch (PDOException $e) {
         $db->rollback();
     }
 }
예제 #10
0
 public function actionCreate()
 {
     if (Yii::app()->user->isGuest) {
         $this->forbidden();
     }
     if (!isset($_POST['Comment'])) {
         $this->badRequest();
     }
     $comment = new Comment(ActiveRecord::SCENARIO_CREATE);
     $comment->attributes = $_POST['Comment'];
     if ($comment->validate()) {
         if (isset($_POST['Comment']['parent_id']) && is_numeric($_POST['Comment']['parent_id'])) {
             $root = Comment::model()->findByPk($_POST['Comment']['parent_id']);
             $comment->appendTo($root);
         } else {
             $comment->saveNode();
         }
     }
 }
예제 #11
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;
     }
 }
require_once '../database_access.php';
$comment = new Comment();
if (isset($_POST['creation_date'])) {
    $comment->setCreationDate($_POST['creation_date']);
}
if (isset($_POST['edit_date'])) {
    $comment->setEditDate($_POST['edit_date']);
}
if (isset($_POST['author_user_id'])) {
    $comment->setAuthorUserId($_POST['author_user_id']);
}
if (isset($_POST['target_event_id'])) {
    $comment->setTargetEventId($_POST['target_event_id']);
}
if (isset($_POST['comment_text'])) {
    $comment->setCommentText($_POST['comment_text']);
}
if (!$comment->validate()) {
    foreach ($comment->getValidationFailures() as $failure) {
        echo '<p><strong>Error in ' . $failure->getPropertyPath() . ' field!</strong> ' . $failure->getMessage() . '</p>';
    }
    unset($failure);
} else {
    $comment->save();
    // add the author name and return the JSON
    $comment_json = json_decode($comment->toJSON());
    $author = $comment->getAuthor();
    $comment_json->authorFirstName = $author->getFirstName();
    $comment_json->authorLastName = $author->getLastName();
    echo json_encode($comment_json);
}
예제 #13
0
<?php

// Error reporting:
error_reporting(E_ALL ^ E_NOTICE);
include "application/connect.php";
include "application/comment/comment.class.php";
/*
/	This array is going to be populated with either
/	the data that was sent to the script, or the
/	error messages.
/*/
$arr = array();
$validates = Comment::validate($arr);
if ($validates) {
    /* Everything is OK, insert to database: */
    mysql_query("\tINSERT INTO comments(commentID,uID,commentText)\n\t\t\t\t\tVALUES (\n\t\t\t\t\t\t'" . $arr['commentID'] . "',\n\t\t\t\t\t\t'" . $arr['uID'] . "'\n\t\t\t\t\t\t'" . $arr['commentText'] . "'\n\t\t\t\t\t)");
    $arr['date'] = date('r', time());
    $arr['commentID'] = mysql_insert_id();
    /*
    	/	The data in $arr is escaped for the mysql query,
    	/	but we need the unescaped variables, so we apply,
    	/	stripslashes to all the elements in the array:
    	/*/
    $arr = array_map('stripslashes', $arr);
    $insertedComment = new Comment($arr);
    /* Outputting the markup of the just-inserted comment: */
    echo json_encode(array('status' => 1, 'html' => $insertedComment->markup()));
} else {
    /* Outputtng the error messages */
    echo '{"status":0,"errors":' . json_encode($arr) . '}';
}
예제 #14
0
 public function actionComment()
 {
     $comment = new Comment();
     if (isset($_POST['Comment'])) {
         $comment->shareId = $_POST['Comment']['shareId'];
         $comment->createTime = time();
         $comment->replyId = $_POST['Comment']['replyId'];
         $comment->content = $_POST['Comment']['content'];
         $comment->userId = Yii::app()->user->userId;
         $clientFlash = new ClientFlash();
         if ($comment->validate() && $comment->save()) {
             $clientFlash->setFlash(0, 'comment', '评论成功');
         } else {
             $clientFlash->setFlash(1, 'comment', '评论失败');
         }
     }
     $this->render('comment', array('commentForm' => $comment));
 }
예제 #15
0
 function newComment()
 {
     foreach ($_POST as $k => $v) {
         $_POST[$k] = trim($v);
     }
     if ($_POST['url'] == 'http://' || empty($_POST['url'])) {
         unset($_POST['url']);
     }
     //strip html tags in comment
     if (!empty($_POST['content'])) {
         $_POST['content'] = strip_tags($_POST['content']);
     }
     Doo::loadModel('Comment');
     $c = new Comment($_POST);
     $this->prepareSidebar();
     // 'skip' is same as DooValidator::CHECK_SKIP
     if ($error = $c->validate('skip')) {
         $this->data['rootUrl'] = Doo::conf()->APP_URL;
         $this->data['title'] = 'Oops! Error Occured!';
         $this->data['content'] = '<p style="color:#ff0000;">' . $error . '</p>';
         $this->data['content'] .= '<p>Go <a href="javascript:history.back();">back</a> to post.</p>';
         $this->render('error', $this->data);
     } else {
         Doo::autoload('DooDbExpression');
         $c->createtime = new DooDbExpression('NOW()');
         $c->insert();
         $this->data['rootUrl'] = Doo::conf()->APP_URL;
         $this->render('comment', $this->data);
     }
 }
예제 #16
0
파일: thread.php 프로젝트: rdaitan/dc-board
 public function update(Comment $comment)
 {
     if (!$this->validate() | !$comment->validate()) {
         throw new ValidationException();
     }
     $db = DB::conn();
     try {
         $db->begin();
         $db->update('thread', array('title' => $this->title, 'category_id' => $this->category_id), array('id' => $this->id));
         $comment->update();
         $db->commit();
     } catch (PDOException $e) {
         if ($e->errorInfo[1] == self::ERR_CATEGORY) {
             throw new CategoryException();
         }
         $db->rollback();
     }
 }
 /**
  * Creates a new comment.
  * This method attempts to create a new comment based on the user input.
  * If the comment is successfully created, the browser will be redirected
  * to show the created comment.
  * @param Post the post that the new comment belongs to
  * @return Comment the comment instance
  */
 protected function newComment($post)
 {
     $comment = new Comment();
     if (isset($_POST['Comment'])) {
         $comment->attributes = $_POST['Comment'];
         $comment->postId = $post->id;
         if (Yii::app()->params['commentNeedApproval']) {
             $comment->status = Comment::STATUS_PENDING;
         } else {
             $comment->status = Comment::STATUS_APPROVED;
         }
         if (isset($_POST['previewComment'])) {
             $comment->validate('insert');
         } else {
             if (isset($_POST['submitComment']) && $comment->save()) {
                 if ($comment->status == Comment::STATUS_PENDING) {
                     Yii::app()->user->setFlash('commentSubmitted', 'Thank you for your comment. Your comment will be posted once it is approved.');
                     $this->refresh();
                 } else {
                     $this->redirect(array('show', 'id' => $post->id, '#' => 'c' . $comment->id));
                 }
             }
         }
     }
     return $comment;
 }
예제 #18
0
 protected function OnInput()
 {
     $this->user = $this->mUsers->Get();
     if (isset($_POST['page'])) {
         $page = addslashes($_POST['page']);
         //Настройки
         $cur_page = $page;
         $page -= 1;
         $per_page = 5;
         $previous_btn = true;
         $next_btn = true;
         $first_btn = true;
         $last_btn = true;
         $start = $page * $per_page;
         //Вывод 5ти комментариев
         $arrComments = $this->mRasp->get_comments();
         $insertedComment = new Comment();
         foreach ($arrComments as $comment) {
             $user = $this->mUsers->Get($comment['author_id']);
             $comment_body = $comment['body'];
             $commentData = array("body" => $comment_body, "id" => $comment['id'], "id_role" => $this->user['id_role'], "id_role_a" => $user['id_role'], "id_vk" => $user['id_vk'], "photo" => $user['photo_200'], "full_name" => $user['first_name'] . ' ' . $user['last_name']);
             $insertedComment->setData($commentData);
             $htmlComments .= $insertedComment->markup();
         }
         //Вывод разметки комментариев с этой страницы
         $this->code_msg = $htmlComments;
     } else {
         if ($this->user !== null) {
             if (isset($_POST['comment'])) {
                 $this->arr = array();
                 $this->arr['body'] = $_POST['comment'];
                 $this->validates = Comment::validate($this->arr);
                 $this->code_msg = '';
                 if ($this->validates) {
                     /* Все в порядке, вставляем данные в базу: */
                     $this->mComm->addComment($this->user['id_user'], $this->arr['body']);
                     $this->arr['dt'] = date('r', time());
                     $this->arr['id'] = mysql_insert_id();
                     $this->arr['photo'] = $this->user['photo_200'];
                     $this->arr['full_name'] = $this->user['first_name'] . ' ' . $this->user['last_name'];
                     //$this->arr['full_name'] = iconv("WINDOWS-1251", "UTF-8", $this->user['first_name'].' '.$this->user['last_name']);
                     /*
                     						/	Данные в $arr подготовлены для запроса mysql,
                     						/	но нам нужно делать вывод на экран, поэтому 
                     						/	готовим все элементы в массиве:
                     						/*/
                     $this->arr = array_map('stripslashes', $this->arr);
                     $commentData = array("body" => $this->arr['body'], "id" => $this->arr['id'], "id_vk" => $this->user['id_vk'], "id_role" => $this->user['id_role'], "photo" => $this->arr['photo'], "full_name" => $this->arr['full_name']);
                     $insertedComment = new Comment($commentData);
                     $htmlComment = $insertedComment->markup();
                     //$htmlComment = iconv("WINDOWS-1251","UTF-8", $htmlComment);
                     /* Вывод разметки только-что вставленного комментария: */
                     $this->code_msg = json_encode(array('status' => 1, 'html' => $htmlComment));
                 } else {
                     /* Вывод сообщений об ошибке */
                     $this->code_msg = '{"status":0,"errors":' . json_encode($this->arr) . '}';
                 }
             } else {
                 if (isset($_POST['delete'])) {
                     if ($this->user['id_role'] == 4) {
                         if ($_POST['delete'] !== 'all') {
                             $this->mComm->removeComment($_POST['delete']);
                             $this->code_msg = '{"status":1}';
                         } else {
                             if ($_POST['delete'] == 'all') {
                                 $this->mComm->removeAllComments();
                                 $this->code_msg = '{"status":1}';
                             }
                         }
                     }
                 }
             }
         } else {
             //$this->code_msg = '{"status":0,"errors":{"body":"'.iconv("WINDOWS-1251", "UTF-8",'Авторизируйтесь, чтобы добавлять комментарии.').'"}}';
             $this->code_msg = '{"status":0,"errors":{"body":"Авторизируйтесь, чтобы добавлять комментарии."}}';
         }
     }
 }
예제 #19
0
 public function postProduct($id = "")
 {
     if (Request::ajax()) {
         if (isset($_POST['buypid'])) {
             $optionprice = $name = DB::table('products_options')->where('product_id', $_POST['buypid'])->where("option_value", $_POST['buyoption'])->pluck('price');
             return $optionprice;
             exit;
         }
         if (isset($_POST['pid'])) {
             $item = Product::find((int) $_POST['pid']);
             if (isset($_POST['buying']) && $_POST['buying'] != "") {
                 $item->price = DB::table('products_options')->where('product_id', (int) $_POST['pid'])->where("option_value", $_POST['buying'])->pluck('price');
             }
             Cart::add(array('id' => $item->id, 'name' => $item->title, 'qty' => Input::get("qty"), 'price' => $item->price, 'options' => array("size" => Input::get("size"), "buying" => Input::get("buying"), "volume" => Input::get("volume"))));
             $content = Cart::content();
             $total = Cart::total();
             $itemHtml = "";
             $itemHtml .= "<div class='beta-select'><i class='fa fa-shopping-cart'></i><span id='cart-count'> Cart (" . Cart::count() . ")</span> <i class='fa fa-chevron-down'></i></div>\n                     <div class='beta-dropdown cart-body'>";
             if ($content) {
                 foreach ($content as $itemRow) {
                     $product = Product::find($itemRow->id);
                     if (public_path()) {
                         $source_folder = public_path() . '/uploads/images/';
                         $destination_folder = public_path() . '/uploads/images/';
                     } else {
                         $source_folder = '/home/medicalng/public_html/uploads/images/';
                         $destination_folder = '/home/medicalng/public_html/uploads/images/';
                     }
                     $image_info = pathinfo($source_folder . $product->image);
                     $image_extension = strtolower($image_info["extension"]);
                     //image extension
                     $image_name_only = strtolower($image_info["filename"]);
                     //file name only, no extension
                     $imgName = $image_name_only . "-50x50" . "." . $image_extension;
                     $itemHtml .= "<div class='cart-item'>\n                             <!--<a class='cart-item-edit' pid='" . $itemRow->rowid . "' href=\"javascript:void(0);\"><i class='fa fa-pencil'></i></a>-->\n                             <a class='cart-item-delete' pid='" . $itemRow->rowid . "' href=\"javascript:void(0);\"><i class='fa fa-times'></i></a>\n                             <div class='media'>\n                                 <a class='pull-left' href=\"javascript:void(0);\"><img src='" . url() . "/uploads/images/thumbs/{$imgName}' alt=''></a>\n                                 <div class='media-body'>\n                                     <span class='cart-item-title'>" . $itemRow->name . "</span>";
                     $itemHtml .= "<span class='cart-item-options'>";
                     $thml = "";
                     if ($itemRow->options) {
                         foreach ($itemRow->options as $key => $value) {
                             if ($value != "") {
                                 $thml .= " —" . $value;
                             }
                         }
                         $thml = preg_replace("/^ —/", "", $thml);
                     }
                     $itemHtml .= $thml . "</span>";
                     $itemHtml .= "<span class='cart-item-amount'>{$itemRow->qty}*<span>&#8358;" . number_format($itemRow->price, 2, '.', ',') . "</span>\n                                 </div>\n                             </div>\n                         </div>\n                         ";
                 }
                 $itemHtml .= "<div class='cart-caption'>\n                             <div class='cart-total text-right'>Subtotal: <span class='cart-total-value'>&#8358;" . number_format($total, 2, ".", ",") . "</span></div>\n                             <div class='clearfix'></div>\n\n                             <div class='center'>\n                                 <div class='space10'>&nbsp;</div>\n                                 <a href='" . url() . "/cart' class='beta-btn primary text-center'>Checkout <i class='fa fa-chevron-right'></i></a>\n                             </div></div>";
             } else {
                 $itemHtml .= "Cart is empty";
             }
             $itemHtml .= "</div>";
             echo $itemHtml;
         }
         if (isset($_POST['delid'])) {
             //$item = Product::find($_POST['delid']);
             Cart::remove($_POST['delid']);
             //(array('id' => $item->id, 'name' => $item->title, 'qty' => 1, 'price' => $item->price));
             $content = Cart::content();
             Session::put("cartItems", $content);
             $total = Cart::total();
             $itemHtml = "";
             $itemHtml .= "<div class='beta-select'><i class='fa fa-shopping-cart'></i><span id='cart-count'> Cart (" . Cart::count() . ")</span> <i class='fa fa-chevron-down'></i></div>\n                     <div class='beta-dropdown cart-body'>";
             if ($content) {
                 foreach ($content as $itemRow) {
                     $product = Product::find($itemRow->id);
                     if ($itemRow->options->has('buying') && $itemRow->options->buying != "") {
                         $itemRow->price = DB::table('products_options')->where("product_option_value_id", $itemRow->optionid)->pluck('price');
                     }
                     if (public_path()) {
                         $source_folder = public_path() . '/uploads/images/';
                         $destination_folder = public_path() . '/uploads/images/';
                     } else {
                         $source_folder = '/home/medicalng/public_html/uploads/images/';
                         $destination_folder = '/home/medicalng/public_html/uploads/images/';
                     }
                     $image_info = pathinfo($source_folder . $product->image);
                     $image_extension = strtolower($image_info["extension"]);
                     //image extension
                     $image_name_only = strtolower($image_info["filename"]);
                     //file name only, no extension
                     $imgName = $image_name_only . "-50x50" . "." . $image_extension;
                     $itemHtml .= "<div class='cart-item'>\n                             <!--<a class='cart-item-edit' pid='" . $itemRow->rowid . "' href=\"javascript:void(0);\"><i class='fa fa-pencil'></i></a>-->\n                             <a class='cart-item-delete' pid='" . $itemRow->rowid . "' href=\"javascript:void(0);\"><i class='fa fa-times'></i></a>\n                             <div class='media'>\n                                 <a class='pull-left' href=\"javascript:void(0);\"><img src='" . url() . "/uploads/images/thumbs/{$imgName}' alt=''></a>\n                                 <div class='media-body'>\n                                     <span class='cart-item-title'>" . $itemRow->name . "</span>";
                     $itemHtml .= "<span class='cart-item-options'>";
                     $itemHtml .= $itemRow->options->has('size') ? " - Size: " . $itemRow->options->size : '';
                     $itemHtml .= $itemRow->options->has('buying') ? " - Buying Option: " . $itemRow->options->buying : '';
                     $itemHtml .= $itemRow->options->has('volume') ? " - Volume: " . $itemRow->options->volume : '';
                     $itemHtml .= "</span>";
                     $itemHtml .= "\n                                     <span class='cart-item-amount'>{$itemRow->qty}*<span>&#8358;" . number_format($itemRow->price, 2, '.', ',') . "</span>\n                                 </div>\n                             </div>\n                         </div>\n\n                         ";
                 }
                 $itemHtml .= "<div class='cart-caption'>\n                             <div class='cart-total text-right'>Subtotal: <span class='cart-total-value'>&#8358;" . number_format($total, 2, ".", ",") . "</span></div>\n                             <div class='clearfix'></div>\n\n                             <div class='center'>\n                                 <div class='space10'>&nbsp;</div>\n                                 <a href='" . url() . "/cart' class='beta-btn primary text-center'>Checkout <i class='fa fa-chevron-right'></i></a>\n                             </div></div>";
             } else {
                 $itemHtml .= "Cart is empty";
             }
             $itemHtml .= "</div>";
             echo $itemHtml;
         }
         if (isset($_POST['comment_content'])) {
             try {
                 $input = Input::all();
                 $validation = Comment::validate(Input::all());
                 if ($validation->fails()) {
                     echo " <div class='alert alert-danger fade in'>\n                    <button class='close' data-dismiss='alert'>×</button>\n                   ensure that required fields are filled\n                </div>";
                 } else {
                     $comment = new Comment();
                     $comment->comment_post_id = $input['comment_post_id'];
                     $comment->comment_author_email = $input['email'];
                     $comment->comment_author = $input['comment_author'];
                     $comment->comment_content = $input['comment_content'];
                     $comment->comment_subject = $input['summary'];
                     $comment->comment_author_ip = $this->get_ip();
                     $comment->comment_approved = 0;
                     if ($comment->save()) {
                         echo " <div class='alert alert-success fade in'>\n                    <button class='close' data-dismiss='alert'>×</button>\n                   Your review awaits approval\n                </div>";
                     }
                 }
             } catch (Exception $e) {
                 echo " <div class='alert alert-success fade in'>\n                    <button class='close' data-dismiss='alert'>×</button>\n                   " . $e->getMessage() . "\n                </div>";
             } catch (ValidationException $e) {
                 echo " <div class='alert alert-success fade in'>\n                    <button class='close' data-dismiss='alert'>×</button>\n                   " . $e->getMessage() . "\n                </div>";
             } catch (Swift_RfcComplianceException $e) {
                 echo " <div class='alert alert-success fade in'>\n                    <button class='close' data-dismiss='alert'>×</button>\n                   " . $e->getMessage() . "\n                </div>";
             }
         }
     }
 }
예제 #20
0
 /**
  * Creates a new comment.
  * This method attempts to create a new comment based on the user input.
  * If the comment is successfully created, the browser will be redirected
  * to show the created comment.
  * @param Post the post that the new comment belongs to
  * @return Comment the comment instance
  */
 protected function newComment($model)
 {
     $comment = new Comment();
     if (isset($_POST['Comment'])) {
         $comment->attributes = $_POST['Comment'];
         if (!Yii::app()->user->isGuest) {
             $comment->authorName = Yii::app()->user->username;
             $comment->email = Yii::app()->user->email;
             $comment->authorId = Yii::app()->user->id;
         }
         if (Yii::app()->user->isGuest && Yii::app()->params['commentNeedApproval']) {
             $comment->status = Comment::STATUS_PENDING;
         } else {
             $comment->status = Comment::STATUS_APPROVED;
         }
         $comment->postId = $model->id;
         if (isset($_POST['previewComment'])) {
             $comment->validate();
         } else {
             if (isset($_POST['submitComment']) && $comment->save()) {
                 if ($comment->status == Comment::STATUS_PENDING) {
                     Yii::app()->user->setFlash('commentSubmittedMessage', Yii::t('lan', 'Thank you for your comment. Your comment will be posted once it is approved.'));
                     $this->refresh();
                 } else {
                     $this->redirect(array('show', 'slug' => $model->slug, '#' => 'c' . $comment->id));
                 }
             }
         }
     }
     return $comment;
 }