Beispiel #1
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);
 }
Beispiel #2
0
 public static function defaultSetting($user)
 {
     $settings = PrivacyHelper::defaultPrivacy();
     $settings += array('gadget_container_0_sort' => 'about,friends', 'gadget_container_1_sort' => 'scheduler,newpost');
     foreach ($settings as $key => $value) {
         $setting = new Setting();
         $setting->key = $key;
         $setting->value = $value;
         $setting->created_by = $user->id;
         $setting->save();
     }
 }
Beispiel #3
0
 public function run()
 {
     $usersData = array(array('username' => 'yuyu', 'full_name' => 'Clicia Scarlet', 'email' => '*****@*****.**', 'password' => Hash::make('123456'), 'is_active' => 1, 'bio' => 'Nothing to say', 'website' => 'http://google.com', 'location' => 'Hanoi', 'language' => 'English, Vietnamese, Japanese'), array('username' => 'abc', 'full_name' => 'Abc Xyz', 'email' => '*****@*****.**', 'password' => Hash::make('123456'), 'is_active' => 1, 'bio' => null, 'website' => null, 'location' => null, 'language' => null), array('username' => 'huyvq', 'full_name' => 'Vu Quoc Huy', 'email' => '*****@*****.**', 'password' => Hash::make('123456'), 'is_active' => 1, 'bio' => null, 'website' => 'http://cloma.clicia.me', 'location' => 'Vietnam', 'language' => 'English'), array('username' => 'quang', 'full_name' => 'Bui Van Quang', 'email' => '*****@*****.**', 'password' => Hash::make('123456'), 'is_active' => 1, 'bio' => null, 'website' => 'http://cloma.com', 'location' => 'Earth', 'language' => 'Japanese'));
     $settingsData = array();
     $settings = PrivacyHelper::defaultPrivacy() + array('gadget_container_0_sort' => 'about,friends', 'gadget_container_1_sort' => 'scheduler,newpost');
     foreach ($settings as $key => $value) {
         foreach ($usersData as $id => $userData) {
             $settingsData[] = array('key' => $key, 'value' => $value, 'created_by' => $id + 1);
         }
     }
     DB::table('users')->truncate();
     DB::table('settings')->truncate();
     DB::table('users')->insert($usersData);
     DB::table('settings')->insert($settingsData);
 }
Beispiel #4
0
 public function getProfile($username)
 {
     $user = User::where('username', $username)->first();
     if (is_null($user)) {
         throw new Exception("User not found");
     }
     /*if(is_null($user))
     		$user = User::findOrFail($username);*/
     $gadgetContainers = array();
     for ($i = 0; $i < 2; $i++) {
         $gadgetContainer = array();
         $gadgets = explode(",", $user->getSetting("gadget_container_" . $i . "_sort"));
         foreach ($gadgets as $gadget) {
             if (PrivacyHelper::canReadThis($user, "gadget_" . $gadget . "_privacy")) {
                 $gadgetContainer[] = View::make('profile.gadget._' . $gadget)->with('data', $user);
             }
         }
         $gadgetContainers[] = $gadgetContainer;
     }
     $this->layout->content = View::make('profile.dashboard')->with('data', $user)->with('gadgets', $gadgetContainers);
 }
Beispiel #5
0
 public function postSearch()
 {
     $query = Input::get('query');
     // find from user
     $data = $user_result = User::where('username', 'LIKE', '%' . $query . '%')->orWhere('full_name', 'LIKE', '%' . $query . '%')->get();
     // find from blog post
     $post_result = Post::where('makrdown', 'LIKE', '%' . $query . '%')->orWhere('title', 'LIKE', '%' . $query . '%')->get();
     foreach ($post_result as $k => $post) {
         if (!PrivacyHelper::checkPermission(Auth::user(), $post)) {
             unset($post_result[$k]);
         } else {
             $post->makrdown = str_limit($post->makrdown, $limit = 500, $end = '...');
             $Parsedown = new Parsedown();
             $post->HTML = $Parsedown->text($post->makrdown);
         }
     }
     $data = $data->merge($post_result);
     // find from task card
     if (Auth::check()) {
         $task_result = Taskcard::where('created_by', Auth::user()->id)->where(function ($q) use($query) {
             $q->where('title', 'LIKE', '%' . $query . '%')->orWhere('content', 'LIKE', '%' . $query . '%');
         })->get();
         foreach ($task_result as $k => $task) {
             $task->content = str_limit($task->content, $limit = 500, $end = '...');
         }
         $data = $data->merge($task_result);
     }
     //$result = json_encode(array_merge(json_decode($user_result, true),json_decode($post_result, true)));
     return View::make('posts.list')->with('data', $data);
     return Response::json($result);
 }