Пример #1
0
 {
     if (is_array($data) || is_object($data)) {
         $result = array();
         foreach ($data as $key => $value) {
             $result[$key] = object_to_array($value);
         }
         return $result;
     }
     return $data;
 }
 View::composer(array('leftsidebar'), function ($view) {
     $query = Thread::order_by('last_message_at', 'desc')->take(30)->get();
     $data = array();
     if (Sentry::check()) {
         foreach ($query as $title) {
             $tms = ThreadsMember::where('thread_id', '=', $title->id)->where('user_id', '=', Sentry::user()->id)->first();
             $x = array();
             if ($tms != null) {
                 $status = true;
                 $x['mark_read'] = true;
             } else {
                 $x['mark_read'] = false;
             }
             $arrayZ = $title->to_array();
             $arrayZ['mark_read'] = $x['mark_read'];
             $arrayZ['today_count'] = DB::only('select count(id) as ct from xr_posts where datetime > date_sub(now(), interval 1 day) and thread_id = ' . $title->id);
             array_push($data, $arrayZ);
         }
         $view->threads = json_decode(json_encode($data), FALSE);
     } else {
         $view->threads = $query;
Пример #2
0
 public function get_index($threadID = '', $threadAlias = '', $page = 1)
 {
     $ajaxRequest = false;
     $thread = false;
     $numbered = false;
     if (Request::ajax()) {
         $ajaxRequest = true;
     }
     //we need to check the threadID.
     if (is_numeric($threadID)) {
         $threadLookup = Thread::where("id", '=', $threadID)->first();
         if ($threadLookup) {
             $thread = true;
             //we got it right... //we got at least ONE thread!
             if (empty($threadAlias)) {
                 return Redirect::to($threadLookup->id . '/' . $threadLookup->alias);
             } else {
                 //we dont have to do anything if we have /id/alias/ schema.
             }
         }
     }
     /*
      * In above if condition corrects if there is no alias given to URL.
      * Above also correts the URL and returns it as corrected way.
      */
     if (!$thread) {
         $threadLookup = Thread::where('title', '=', $threadID)->first();
         if ($threadLookup) {
             /*
             We got the thread by looking at its raw format. "bla bla bla".
             This is usually false. browsers dont like spaces and special characters
             So we need to put them to a true format and redirect it.
             */
             return Redirect::to($threadLookup->id . '/' . $threadLookup->alias);
         }
         $threadLookup = Thread::where('alias', '=', $threadID)->first();
         if ($threadLookup) {
             /*
             We got the thread by looking at its alias format. "bla-bla-bla".
             This is usually false. Because we also need ID
             So we need to put them to a true format and redirect it.
             */
             return Redirect::to($threadLookup->id . '/' . $threadLookup->alias);
         }
         /*
         if we are still going on with !$thread that means there is no thread! so
         do the suggestion!
         
         TODO :: Suggestion!
         */
     }
     if (Sentry::check()) {
         $tms = ThreadsMember::where('thread_id', '=', $threadID)->where('user_id', '=', Sentry::user()->id)->first();
         if ($tms == null) {
             ThreadsMember::create(array('thread_id' => $threadID, 'user_id' => Sentry::user()->id, 'read_flag' => 1));
         }
     }
     $total = Post::where('thread_id', '=', $threadID)->count();
     $Query = Post::with('author')->where('thread_id', '=', $threadID)->order_by('id', 'asc')->paginate(static::$per_page);
     print_r($threadLookup);
     $paginator = Paginator::make($Query, $total, static::$per_page);
     if ($ajaxRequest) {
         //json returns if we get ajax request
         $view = View::make('entry.entryajax');
         $view->title = $threadLookup->title;
         $view->threadinfo = $threadLookup;
         $view->posts = $Query;
         $view->paginate = $paginator;
         return $view;
     } else {
         $view = View::make('entry.entry');
         $view->title = $threadLookup->title;
         $view->threadinfo = $threadLookup;
         $view->posts = $Query;
         $view->paginate = $paginator;
         return $view;
     }
 }