/**
  * Show hub picture
  *
  * @return Response
  */
 public function picture($id)
 {
     $pic = Picture::find($id);
     if ($pic) {
         return Response::download(storage_path() . "/pictures/" . $pic->name . ".png");
     } else {
         return App::abort(404);
     }
 }
 /**
  * Show artist profile picture
  *
  * @return Response
  */
 public function profilepicture($id, $type)
 {
     $pic = Picture::find($id);
     if ($pic) {
         return Response::download(storage_path() . "/pictures/" . $pic->name . "-" . $type . $pic->extension);
     } else {
         return Response::download(storage_path() . "/no-user.png");
     }
 }
Exemple #3
0
 function test_for_has_many()
 {
     $Property =& new Property();
     $this->assertEqual($Property->picture->getType(), 'hasMany');
     $this->assertTrue(is_array($Property->pictures) && count($Property->pictures) === 0);
     $Property->picture->load();
     $this->assertEqual($Property->picture->count(), 0);
     $SeaViews =& new Picture(array('title' => 'Sea views'));
     $Property->picture->add($SeaViews);
     $this->assertEqual($Property->picture->count(), 1);
     $this->assertReference($Property->pictures[0], $SeaViews);
     $Property->picture->add($SeaViews);
     $this->assertEqual($Property->picture->count(), 1);
     $this->assertNull($Property->pictures[0]->get('property_id'));
     $MountainViews =& new Picture(array('title' => 'Mountain views'));
     $this->assertTrue($MountainViews->isNewRecord());
     $Property->picture->add($MountainViews);
     $this->assertEqual($Property->picture->count(), 2);
     $this->assertTrue($Property->save());
     $this->assertFalse($SeaViews->isNewRecord());
     $this->assertFalse($MountainViews->isNewRecord());
     $this->assertEqual($SeaViews->get('property_id'), $Property->getId());
     $this->assertEqual($MountainViews->get('property_id'), $Property->getId());
     $this->assertReference($SeaViews, $Property->pictures[0]);
     $this->assertReference($MountainViews, $Property->pictures[1]);
     $Property =& new Property($Property->getId());
     $Property->picture->load();
     $this->assertEqual($Property->picture->association_id, 'pictures');
     $this->assertEqual($Property->picture->count(), 2);
     $Property->pictures = array();
     $this->assertEqual($Property->picture->count(), 0);
     $Property->picture->load();
     $this->assertEqual($Property->picture->count(), 0);
     $Property->picture->load(true);
     $this->assertEqual($Property->picture->count(), 2);
     $this->assertEqual($Property->pictures[1]->getType(), 'Picture');
     $Property->picture->delete($Property->pictures[1]);
     $this->assertEqual($Property->picture->count(), 1);
     $Property->picture->load(true);
     $this->assertEqual($Property->picture->count(), 1);
     $Property = $Property->find('first');
     $Picture = new Picture();
     $Pictures = $Picture->find();
     $Property->picture->set($Pictures);
     $this->assertEqual($Property->picture->count(), count($Pictures));
     $Property = $Property->find('first');
     $Property->picture->load();
     $this->assertEqual($Property->picture->count(), count($Pictures));
     $Picture = $Picture->find('first');
     $Property->picture->set($Picture);
     $this->assertEqual($Property->picture->count(), 1);
     $this->assertTrue(in_array('pictures', $Property->getAssociatedIds()));
     $Property = $Property->find('first', array('include' => 'pictures'));
     $this->assertIdentical($Property->picture->count(), 1);
     $this->assertEqual($Property->pictures[0]->getId(), $Picture->getId());
     $this->assertTrue($Property->picture->delete($Property->pictures[0]));
     $this->assertIdentical($Property->picture->count(), 0);
     $Property =& $Property->find('first');
     $this->assertIdentical($Property->picture->count(), 0);
     //$this->assertTrue($Property =& $Property->find('first', array('include'=>'pictures')));
     //$this->assertIdentical($Property->picture->count(), 0);
     $Picture =& new Picture();
     $Alicia =& $Picture->create(array('title' => 'Alicia'));
     $Bermi =& $Picture->create(array('title' => 'Bermi'));
     $Hilario =& $Picture->create(array('title' => 'Hilario'));
     $Property->picture->setByIds(array($Alicia->getId(), $Bermi->getId(), $Hilario->getId()));
     $Property->set('description', 'Cool house');
     $this->assertTrue($Property->save());
     $this->assertTrue($Property =& $Property->findFirstBy('description', 'Cool house'));
     $Property->picture->load();
     $this->assertEqual($Property->picture->count(), 3);
     $FoundAlicia = $Property->picture->find('first', array('conditions' => array('title = ?', "Alicia")));
     $this->assertEqual($Alicia->get('title') . $Alicia->getId(), $FoundAlicia->get('title') . $FoundAlicia->getId());
     $FoundPals = $Property->picture->find();
     $this->assertEqual(count($FoundPals), $Property->picture->count());
     $titles = array();
     foreach ($FoundPals as $FoundPal) {
         $titles[] = $FoundPal->get('title');
     }
     sort($titles);
     $this->assertEqual($titles, array('Alicia', 'Bermi', 'Hilario'));
     $this->assertFalse($Property->picture->isEmpty());
     $this->assertEqual($Property->picture->getSize(), 3);
     $this->assertTrue($Property->picture->clear());
     $this->assertTrue($Property->picture->isEmpty());
     $this->assertEqual($Property->picture->getSize(), 0);
     $Property =& new Property();
     $PoolPicture =& $Property->picture->build(array('title' => 'Pool'));
     $this->assertReference($PoolPicture, $Property->pictures[0]);
     $this->assertTrue($Property->pictures[0]->isNewRecord());
     $this->assertEqual($PoolPicture->getType(), 'Picture');
     $Property->set('description', 'Maui Estate');
     $this->assertTrue($Property->save());
     $this->assertTrue($MauiEstate = $Property->findFirstBy('description', 'Maui Estate', array('include' => 'pictures')));
     $this->assertEqual($MauiEstate->pictures[0]->get('title'), 'Pool');
     $Property =& new Property(array('description' => 'Villa Altea'));
     $GardenPicture =& $Property->picture->create(array('title' => 'Garden'));
     $this->assertReference($GardenPicture, $Property->pictures[0]);
     $this->assertTrue($GardenPicture->isNewRecord());
     $Property =& new Property(array('description' => 'Villa Altea'));
     $this->assertTrue($Property->save());
     $GardenPicture =& $Property->picture->create(array('title' => 'Garden'));
     $this->assertReference($GardenPicture, $Property->pictures[0]);
     $this->assertFalse($GardenPicture->isNewRecord());
     $this->assertTrue($VillaAltea = $Property->findFirstBy('description', 'Villa Altea', array('include' => 'pictures')));
     $this->assertEqual($VillaAltea->pictures[0]->get('title'), 'Garden');
 }
 public function singlePost($id)
 {
     $post = Post::find($id);
     $data['date'] = $this->getBaseDateTime();
     if ($post == null) {
         return null;
     }
     if (Auth::check()) {
         if ($post->type == '0') {
             $post = Post::join('users', 'users.id', '=', 'posts.user_id')->select('posts.*')->where('posts.id', $id)->where('users.disable', '0')->whereType('0')->whereIn('posts.user_id', function ($query) {
                 $query->select('friend_id')->from('friend_list')->whereUserId(Auth::user()->id);
             })->orWhere('posts.user_id', Auth::user()->id)->where('users.disable', '0')->whereType('0')->where('posts.id', $id)->first();
             if ($post == null) {
                 return null;
             }
         }
         //
         $now = Carbon::parse($post->created_at);
         $feeling = DB::table('feelings')->find($post->feeling)->name;
         $following = Following::whereFollowerId(Auth::user()->id)->whereFollowingId($post->user_id)->get()->count();
         $confession = Confession::whereUserId($post->user_id)->first();
         if ($confession) {
             $confess_time = Carbon::parse($confession->created_at);
             $confess_time = $confess_time->diffInHours();
             //$confess_time = $confess_time->diffInSeconds();
             if ($confess_time < 24) {
                 if ($confession->updated_at < $post->created_at) {
                     $confession = $confession->confess;
                 } else {
                     $confession = null;
                 }
             } else {
                 $confession = null;
             }
         }
         $user = User::find($post->user_id);
         $url = Picture::find($user->picture);
         $url = $url->url;
         $text = htmlentities($post->post);
         // 9-2-Start
         $pos = strpos($text, 'watch?v=');
         if ($pos != 0) {
             $pos = $pos + 8;
             $str = substr($text, $pos, 11);
             # code...
         } else {
             $str = null;
         }
         // 9-2-End
         $data['post'] = array('id' => $post->id, 'post' => $text, 'user_id' => $post->user_id, 'img' => asset($url), 'confess' => $confession, 'following' => $following, 'type' => $post->type, 'like' => Like::wherePostId($post->id)->get()->count(), 'dislike' => Dislike::wherePostId($post->id)->get()->count(), 'liked' => Like::wherePostId($post->id)->whereUserId(Auth::user()->id)->get()->count(), 'disliked' => Dislike::wherePostId($post->id)->whereUserId(Auth::user()->id)->get()->count(), 'comment' => Comment::wherePostId($post->id)->get()->count(), 'feeling' => $feeling, 'vidsrc' => $str, 'ago' => $now->diffForHumans());
         $data['notifications'] = $this->getNotification();
         //
     } else {
         if ($post->type == '0') {
             return null;
         }
         //
         $now = Carbon::parse($post->created_at);
         $feeling = DB::table('feelings')->find($post->feeling)->name;
         $following = null;
         $confession = Confession::whereUserId($post->user_id)->first();
         if ($confession) {
             $confess_time = Carbon::parse($confession->created_at);
             $confess_time = $confess_time->diffInHours();
             //$confess_time = $confess_time->diffInSeconds();
             if ($confess_time < 24) {
                 if ($confession->updated_at < $post->created_at) {
                     $confession = $confession->confess;
                 } else {
                     $confession = null;
                 }
             } else {
                 $confession = null;
             }
         }
         $user = User::find($post->user_id);
         $url = Picture::find($user->picture);
         $url = $url->url;
         $text = htmlentities($post->post);
         // 9-2-Start
         $pos = strpos($text, 'watch?v=');
         if ($pos != 0) {
             $pos = $pos + 8;
             $str = substr($text, $pos, 11);
             # code...
         } else {
             $str = null;
         }
         //9-2-End
         $data['post'] = array('id' => $post->id, 'post' => $text, 'user_id' => $post->user_id, 'img' => asset($url), 'confess' => $confession, 'following' => $following, 'type' => $post->type, 'like' => Like::wherePostId($post->id)->get()->count(), 'dislike' => Dislike::wherePostId($post->id)->get()->count(), 'liked' => 0, 'disliked' => 0, 'comment' => Comment::wherePostId($post->id)->get()->count(), 'feeling' => $feeling, 'vidsrc' => $str, 'ago' => $now->diffForHumans());
         //
         $data['notifications'] = ['length' => 0, 'notifications' => null];
     }
     $data['single'] = 1;
     $data['reports'] = Report::get();
     // return json_encode($data['']);
     return View::make('single')->withData($data);
 }
Exemple #5
0
 public function test_clean_up_dependencies()
 {
     $Property = new Property(array('description' => 'Ruins in Matamon'));
     $this->assertTrue($Property->save());
     $South =& $Property->picture->create(array('title' => 'South views'));
     $this->assertReference($South, $Property->pictures[0]);
     $this->assertFalse($South->isNewRecord());
     $pic_id = $South->getId();
     $Property = new Property($Property->getId());
     $this->assertTrue($Property->destroy());
     $Picture = new Picture();
     $this->assertFalse($Picture->find($pic_id));
 }
Exemple #6
0
        return Redirect::guest('admin/login');
    }
    if (Auth::check()) {
        if (!Auth::user()->hasRole("admin") && Route::current()->getPath() != "admin/login") {
            return Redirect::guest('admin/login');
        }
    }
});
Route::filter('auth', function () {
    if (Auth::guest()) {
        return Redirect::guest('login');
    }
});
Route::filter('pic_permission', function ($route) {
    $id = $route->getParameter('id');
    $picture = Picture::find($id);
    if (!$picture) {
        App::abort(404);
    }
    // if (Auth::guest() or (!$picture->belongsToUser(Auth::user()) and !Auth::user()->hasAnyRole(array('admin','modirator'))))
    if (Auth::guest() or !($picture->belongsToUser(Auth::user()) or Auth::user()->hasAnyRole(array('admin', 'modirator')))) {
        $page_title = "page 401 :(";
        $article = Article::where('name', '=', '401')->get()->first();
        if (!$article) {
            return Response::view('frontend.article.alternative-401-page', compact('page_title'), 401);
        }
        return Response::view('frontend.article.index', compact('article', 'page_title'), 404);
    }
});
Route::filter('comment_permission', function ($route) {
    $id = $route->getParameter('id');
 /**
  * Returns art by songs id
  *
  * @param $id
  * @return Response
  */
 public function show_art($id)
 {
     $song = Song::find($id);
     $author = User::find($song->artist);
     $pic = Picture::find($author->picture);
     if ($song) {
         if (!empty($song->art)) {
             return Response::download($song->art);
         } else {
             return Response::download(storage_path() . "/pictures/" . $pic->name . "-medium" . $pic->extension);
             //return Response::download(storage_path() . "/cd.png");
         }
     }
 }
Exemple #8
0
 public function deleteImage()
 {
     if (!Auth::check()) {
         return Response::json(array('errCode' => 1, 'message' => '请登录'));
     }
     $photo_id = Input::get('photo_id');
     $picture = Picture::find($photo_id);
     if ($picture == null) {
         return Response::json(array('errCode' => 3, 'message' => '照片不存在!'));
     }
     if ($picture->Album->user_id != Auth::user()->id) {
         return Response::json(array('errCode' => 4, 'message' => '[权限禁止]只能删除自己的照片'));
     }
     if (!$picture->delete()) {
         return Response::json(array('errCode' => 2, 'message' => '照片删除失败!'));
     }
     return Response::json(array('errCode' => 0, 'message' => '照片删除成功!'));
 }
 public function postProcess($posts)
 {
     $data = null;
     $i = 0;
     foreach ($posts as $post) {
         $post = Post::find($post->id);
         //if ($i == 5) break;	///////////////////06-May-2015-Ehsan
         $now = Carbon::parse($post->created_at);
         $feeling = DB::table('feelings')->find($post->feeling)->name;
         $following = Following::whereFollowerId(Auth::user()->id)->whereFollowingId($post->user_id)->get()->count();
         $confession = Confession::whereUserId($post->user_id)->first();
         if ($confession) {
             $confess_time = Carbon::parse($confession->created_at);
             $confess_time = $confess_time->diffInHours();
             //$confess_time = $confess_time->diffInSeconds();
             if ($confess_time < 24) {
                 if ($confession->updated_at < $post->created_at) {
                     $confession_view = ConfessionView::whereConfessionId($confession->id)->whereIsValid(1)->get()->count();
                     $confession = ['id' => $confession->id, 'confess' => $confession->confess, 'view' => $confession_view];
                 } else {
                     $confession = null;
                 }
             } else {
                 $confession = null;
             }
         }
         $user = User::find($post->user_id);
         if ($user->disable == 1) {
             continue;
         }
         $url = Picture::find($user->picture);
         $url = $url->url;
         $text = htmlentities($post->post);
         // Youtube Video Searching
         $pos = strpos($text, 'watch?v=');
         if ($pos != 0) {
             $pos = $pos + 8;
             $str = substr($text, $pos, 11);
             # code...
         } else {
             $str = null;
         }
         //
         $name = null;
         if (($post->type == 1 || $post->type == 3) && !$post->hide_name) {
             $user = User::find($post->user_id);
             $name = $user->username;
         }
         $text = preg_replace('/#([a-zA-Z0-9\\x{0980}-\\x{09FF}_])+/u', '<a href="" class="tags">$0</a>', $text);
         /* Eve-26-May-Ehsan */
         $text = preg_replace('#((https?|ftp)://(\\S*?\\.\\S*?))([\\s)\\[\\]{},;"\':<]|\\.\\s|$)#i', '<a target="_blank" href="$1">$1</a>', $text);
         /* !!!!Eve-26-May-Ehsan */
         $text = nl2br($text);
         $text = Emojione::shortnameToImage($text);
         $data[$i++] = array('id' => $post->id, 'post' => $text, 'user_id' => $post->user_id, 'img' => asset($url), 'confess' => $confession, 'following' => $following, 'type' => $post->type, 'like' => Like::wherePostId($post->id)->get()->count(), 'dislike' => Dislike::wherePostId($post->id)->get()->count(), 'liked' => Like::wherePostId($post->id)->whereUserId(Auth::user()->id)->get()->count(), 'disliked' => Dislike::wherePostId($post->id)->whereUserId(Auth::user()->id)->get()->count(), 'comment' => Comment::wherePostId($post->id)->get()->count(), 'feeling' => $feeling, 'vidsrc' => $str, 'name' => $name, 'ago' => $now->diffForHumans());
     }
     return $data;
 }