/** * Handle the event. * * @param Events $event * @return void */ public function handle(UnFeedableEvent $event) { // $event->getContext() : TaskCompleted Feed // $lastFeed : Comment Feed if ($event->getType() == 'CommentDeleted') { $feed = $event->getContext(); if ($feed->additional_type == 'CommentPosted') { // echo "comment count : {$feed->comments->count()}"; if ($feed->comments->count() > 1) { // samshayamaaanu $lastComment = $feed->comments->last(); // $feed->additional_subject_type = 'App\Comment'; $feed->additional_subject_id = $event->getSubject()->id; $feed->updated_at = $lastComment->updated_at; $feed->save(); } else { $feed->additional_type = ''; $feed->additional_subject_id = 0; $feed->additional_subject_type = ''; $feed->save(); } } } else { if ($event->getType() == 'ProjectDeleted') { Feed::whereProjectId($event->getSubject()->id)->delete(); // delete all project related feeds Feed::whereSubjectId($event->getSubject()->id)->whereSubjectType('App\\Project')->delete(); // create 'project created' feed } else { Feed::whereSubjectId($event->getSubject()->id)->delete(); } } }
/** * Return create tag view * * @return \Illuminate\View\View */ public function create($team, $feed_id) { $team = Team::where('slug', '=', $team)->with('feeds')->first(); $feed = Feed::with('tags.network')->where('id', '=', $feed_id)->first(); $networks = Network::all(); return view('admin.tags.create', ['feed' => $feed, 'team' => $team, 'networks' => $networks]); }
/** * Display a listing of the resource. * * @return Response */ public function index() { if (Input::get('token')) { $user = JWTAuth::parseToken()->authenticate(); return ['sidebar' => [], 'feeds' => Feed::all(), 'self' => $user]; } return response(['error' => 'wheres_the_f***ing_token'], 400); }
public function fetch() { $result = new RSS(); $url = $this->get_url_only(Feed::get()->toArray()); $feed = $result->fetch($url); $result = $feed->get_items(); return view('result', compact('result')); }
/** * Display a listing of the resource. * * @return Response */ public function index(FeedRepository $feedRepository) { $user = $this->currentUser; $feeds = $feedRepository->getPublishedByUserAndFriends($user); $friendsUserIds[] = $user->id; $feedsCount = Feed::getTotalCountFeedsForUser($friendsUserIds); return view('feeds.index', compact('user', 'feeds', 'feedsCount')); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Project $project, Request $request) { $this->validate($request, ['message' => 'required']); $user = JWTAuth::parseToken()->authenticate(); // $audience = User::whereIn('id', explode(',', $request->get('audience')))->get(); $status = $this->dispatch(new PostStatus($user, $project, $request->all())); $feed = Feed::whereType('StatusPosted')->whereSubjectId($status->id)->first(); return response()->json(['success' => true, 'message' => 'Status Posted.', 'status' => $status, 'feed' => $feed]); }
public function setUp() { parent::setUp(); Artisan::call('migrate'); Artisan::call('db:seed'); $this->project = \App\Project::firstOrFail(); $this->user = \App\User::firstOrFail(); $this->feed = \App\Feed::firstOrFail(); $this->comment = $this->feed->comments->first(); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Project $project, Request $request) { $this->validate($request, ['type' => 'required|in:owner,developer,client']); $admin = JWTAuth::parseToken()->authenticate(); // $user = User::findOrFail($request->get('user_id')); $type = $request->get('type'); $audience = User::whereIn('id', explode(',', $request->get('users')))->get(); $this->dispatch(new AddUserToProject($admin, $project, $audience, $type)); $feed = Feed::whereType('UserAddedToProject')->whereSubjectId($user->id)->whereProjectId($project->id)->first(); return response()->json(['success' => true, 'message' => 'User Joined Project.', 'feed' => $feed]); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create(); $userIds = User::lists('id'); $date = new DateTime(); $day = 1; $users = [1, 2, 3, 4, 5]; foreach ($users as $user) { foreach (range(1, 30) as $index) { $day++; $date->setDate(2015, 1, $day); Feed::create(['user_id' => $user, 'body' => $faker->sentence(), 'poster_firstname' => $faker->firstName, 'poster_profile_image' => $faker->imageUrl($width = 180, $height = 180), 'created_at' => $date->format('Y-m-d H:i:s'), 'updated_at' => $date->format('Y-m-d H:i:s')]); } } }
public function getData($table, $id) { $result = ''; try { switch ($table) { case 'feeds': $result = Feed::findOrFail($id); break; case 'meals': $result = Meal::findOrFail($id); break; case 'videos': $result = Video::findOrFail($id); break; } return $result; } catch (ModelNotFoundException $ex) { return false; } }
public function relatedFeeds() { $commonFeeds = Feed::common()->orderBy('created_at'); $myFeeds = Feed::whereIn('project_id', $this->projects->lists('id'))->orderBy('created_at'); return $commonFeeds->get()->merge($myFeeds); }
/** * Creates a filtered array of Feed models from the Provider * * @param $provider * @param null $filterString * @return array */ public function createFeedsFromProvider($provider, $filterString = null) { $feedArray = []; foreach ($provider->feed()->get_items() as $item) { if ($filterString) { if (strpos(strtolower($item->get_content()), strtolower($filterString)) !== false || strpos(strtolower($item->get_title()), strtolower($filterString)) !== false) { $feed = Feed::newInstanceFromSimplePieItem($item); array_push($feedArray, $feed); } } else { $feed = Feed::newInstanceFromSimplePieItem($item); array_push($feedArray, $feed); } } return $feedArray; }
/** * @return mixed */ public function getLastSortOrder() { $feed = Feed::orderBy('sort_order', 'DESC')->first(); return ++$feed->sort_order; }
public function stestTaskCreatedCommentPosted() { $user = User::firstOrFail(); // variable $project = Project::create($this->projectdata); // variable $task = Task::create($this->taskdata); // variable $task->project()->associate($project); $this->assertEquals($task->project->id, $project->id); // test $comment = Comment::create($this->commentdata); // variable $user->comments()->save($comment); $this->assertEquals($user->id, $comment->owner->id); // test // $comment->commentable()->associate($task); // morphTo : fails // $comment->commentable()->save($task); // morphTo : fails $task->comments()->save($comment); // morphMany : ok $this->assertEquals($task->id, $comment->commentable->id); // test event(new TaskCreated($user, $project, $task)); $this->assertEquals(1, Feed::count()); // test event(new CommentPosted($user, $comment, $task)); $this->assertEquals(2, Feed::count()); // test $this->assertEquals($comment->commentable->id, $task->id); $this->assertEquals(TaskCreated::class, $task->feed->type); $this->assertEquals(CommentPosted::class, $comment->feed->type); $this->assertEquals(1, $task->comments->count()); $this->assertEquals(1, $user->comments->count()); }
/** * Get feeds posted by current user and friends via ajax. * * @param User $user * * @param int $startingPoint * * @return mixed */ public function getPublishedByUserAndFriendsAjax(User $user, $skipQty) { $friendsUserIds = $user->friends()->lists('requester_id'); $friendsUserIds[] = $user->id; return Feed::whereIn('user_id', $friendsUserIds)->latest()->skip($skipQty)->take(10)->get(); }
public function stestDeleteFeed() { DB::table('comments')->delete(); $cd = ['comment' => 'lets bring the pain']; $feed = Feed::firstOrFail(); $user1 = User::firstOrFail(); $user2 = User::all()->last(); $comment1 = Bus::dispatch(new PostComment($user1, $cd, $feed)); $comment2 = Bus::dispatch(new PostComment($user2, $cd, $feed)); $commentFeed = Feed::whereType('App\\Events\\CommentPosted')->whereContextId($feed->id)->firstOrFail(); $this->assertEquals($user2->id, $commentFeed->origin->id); $this->assertEquals($comment2->id, $commentFeed->subject->id); Bus::dispatch(new DeleteComment($user2, $comment2)); $this->assertEquals($user1->id, $commentFeed->origin->id); $this->assertEquals($comment1->id, $commentFeed->subject->id); }
/** * Return redirect - deletes feed * * @return \Illuminate\View\View */ public function delete($team, $feed_id) { Feed::destroy($feed_id); return redirect('/team/' . $team . '/feed'); }
public function updateFeed(Request $request, $id) { $Feed = Feed::find($id); $Feed->name = $request->input('name'); $Feed->save(); return response()->json($Feed); }
public function feed($lang) { $feed = new Feed(); $posts = Post::where('lang', '=', $lang)->orderBy('created_at', 'desc')->take(20)->get(); $feed->title = Config::get('app.blog_title'); $feed->description = Config::get('app.blog_description'); $feed->logo = ''; $feed->link = URL::to('feed/' . $lang); $feed->setDateFormat('datetime'); // 'datetime', 'timestamp' or 'carbon' $feed->pubdate = $posts[0]->created_at; $feed->lang = $lang; foreach ($posts as $post) { $feed->addItem($post->title, $post->sub_title, 'URL', $post->created_at, $post->preview, $post->content); } $this->statistics->incrementPage('rss_feed'); return $feed->render('rss'); }
/** * Remove the specified resource from storage. * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { Feed::find($id)->delete(); return redirect('feed'); }
public function getFever() { /* Fever API needs strings for category_id and feed_id's */ //static for now $email = 'username'; $pass = '******'; $api_key = md5($email . ':' . $pass); //always return status 1: password and username correct $status = '1'; //latest api version is 3 $arr = ['api_version' => '3', 'auth' => $status]; //last refreshed is current system time $time = ['last_refreshed_on_time' => strtotime('now')]; $arr = array_merge($arr, $time); //when argument is groups, retrieve list with categories and id's if (isset($_GET['groups'])) { $groups = []; $Categories = Category::orderBy('category_order', 'asc')->get(); if (!empty($Categories)) { foreach ($Categories as $Category) { array_push($groups, ['id' => (string) $Category->id, 'title' => $Category->name]); } } $response_arr['groups'] = $groups; $arr = array_merge($arr, $response_arr); } //when argument is feeds, retrieve list with feeds and id's if (isset($_GET['feeds'])) { $feeds = []; $Feeds = Feed::orderBy('feed_name', 'asc')->get(); if (!empty($Feeds)) { foreach ($Feeds as $Feed) { array_push($feeds, ['id' => (int) $Feed->id, 'favicon_id' => (int) $Feed->id, 'title' => $Feed->feed_name, 'url' => $Feed->url, 'site_url' => $Feed->url, 'is_spark' => '0', 'last_updated_on_time' => strtotime($Feed->updated_at)]); } } $response_arr['feeds'] = $feeds; $arr = array_merge($arr, $response_arr); } //when argument is groups or feeds, also return feed id's linked to category id's if (isset($_GET['groups']) || isset($_GET['feeds'])) { $feeds_groups = []; //The array is composed with a group_id and feed_ids containing a string/comma-separated list of positive integers $Categories = Category::orderBy('category_order', 'asc')->get(); if (!empty($Categories)) { foreach ($Categories as $key => $Category) { $feeds_groups[$key]['group_id'] = (int) $Category->id; $Feeds = Category::find($Category->id)->feeds; if (!empty($Feeds)) { $feed_ids = []; foreach ($Feeds as $Feed) { array_push($feed_ids, $Feed->id); } $feeds_groups[$key]['feed_ids'] = implode(',', $feed_ids); } } } $response_arr['feeds_groups'] = $feeds_groups; $arr = array_merge($arr, $response_arr); } //return list with all unread article id's if (isset($_GET['unread_item_ids'])) { $unread_item_ids = []; $Articles = Article::where('status', 'unread')->orderBy('id', 'asc')->get(); if (!empty($Articles)) { foreach ($Articles as $Article) { array_push($unread_item_ids, $Article->id); } } //string/comma-separated list of positive integers instead of array $stack = implode(',', $unread_item_ids); $unreaditems = ['unread_item_ids' => $stack]; $arr = array_merge($arr, $unreaditems); } //return string/comma-separated list with id's from read and starred articles if (isset($_GET['saved_item_ids'])) { $saved_item_ids = []; $Articles = Article::where('star_ind', '1')->orderBy('id', 'asc')->get(); if (!empty($Articles)) { foreach ($Articles as $Article) { array_push($saved_item_ids, $Article->id); } } //string/comma-separated list of positive integers instead of array $stack = implode(',', $saved_item_ids); $saveditems = ['saved_item_ids' => $stack]; $arr = array_merge($arr, $saveditems); } //when argument is items, return 50 articles at a time if (isset($_GET['items'])) { $total_items = []; $total_items['total_items'] = Article::count(); $arr = array_merge($arr, $total_items); $items = []; //request specific items, a maximum of 50 specific items requested by comma-separated argument if (isset($_GET['with_ids'])) { //list with id's is comma-separated, so transform to array $ArrayIds = explode(',', $_REQUEST['with_ids']); //create empty array to store Article results $Articles = []; if (!empty($ArrayIds)) { foreach ($ArrayIds as $ArrayId) { $Article = Article::find($ArrayId); array_push($Articles, $Article); } } //request 50 additional items using the highest id of locally cached items } elseif (isset($_REQUEST['since_id'])) { $Articles = Article::where('id', '>', $_REQUEST['since_id'])->orderBy('id', 'asc')->take(50)->get(); //request 50 previous items using the lowest id of locally cached items } elseif (isset($_REQUEST['max_id'])) { $Articles = Article::where('id', '<', $_REQUEST['max_id'])->orderBy('id', 'asc')->take(50)->get(); //if no argument is given provide total_items and up to 50 items } else { $Articles = Article::take(50)->orderBy('id', 'asc')->get(); } if (!empty($Articles)) { foreach ($Articles as $Article) { array_push($items, ['id' => (int) $Article->id, 'feed_id' => (int) $Article->feed_id, 'title' => $Article->subject, 'author' => $Article->author, 'html' => $Article->content, 'url' => $Article->url, 'is_saved' => (int) $Article->star_ind, 'is_read' => $Article->status == 'read' ? 1 : 0, 'created_on_time' => strtotime($Article->published)]); } } $response_arr['items'] = $items; $arr = array_merge($arr, $response_arr); } //when argument is links, don't return anything at this moment if (isset($_GET['links'])) { $links = []; $response_arr['links'] = $links; $arr = array_merge($arr, $response_arr); } //when argument is groups, retrieve list with categories and id's if (isset($_GET['favicons'])) { $favicons = []; $Feeds = Feed::orderBy('feed_name', 'asc')->get(); if (!empty($Feeds)) { foreach ($Feeds as $Feed) { if (empty($Feed->favicon)) { //TODO: replace with Laravel's URL functionality $faviconurl = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $faviconurl = substr($faviconurl, 0, strpos($faviconurl, 'index.php/api')) . 'img/rss-default.png'; } else { $faviconurl = $Feed->favicon; } array_push($favicons, ['id' => (int) $Feed->id, 'title' => $faviconurl]); } $response_arr['favicons'] = $favicons; $arr = array_merge($arr, $response_arr); } } //return fever response return response()->json($arr); }
/** * Execute the command. * * @param FeedRepository $feedRepository * * @return void */ public function handle() { $feed = Feed::publish($this->body, $this->posterFirstname, $this->posterProfileImage); Auth::user()->feeds()->save($feed); return $feed; }