/** * Execute the console command. * * @return mixed */ public function handle() { $sources = Source::all(); foreach ($sources as $source) { $feed = Feeds::make($source->feed_url); $items = $feed->get_items(); foreach ($items as $item) { $article = Article::firstOrNew(['link' => $item->get_permalink()]); $article->source_id = $source->id; $article->title = $item->get_title(); $article->content = $item->get_description(); if ($item->get_date()) { $article->date = Carbon::createFromFormat('j F Y, g:i a', $item->get_date()); } else { $article->date = Carbon::now(); } if (!empty($article->content)) { // Disable HTML 5 related errors libxml_use_internal_errors(true); $doc = new DOMDocument(); $doc->loadHTML($article->content); $imageTags = $doc->getElementsByTagName('img'); foreach ($imageTags as $tag) { $src = $tag->getAttribute('src'); if (strpos($src, ".jpg") or strpos($src, ".png") or strpos($src, ".jpeg")) { $article->image_url = $src; break; } } } $article->save(); } } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $item = Source::find($id); $item->status = "deleted"; $item->save(); Log::create(array("user_id" => Auth::user()->id, "action" => "Delete Source named " . $item->name)); }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $categories = Category::forLoggedInUser()->lists('name', 'id'); $units = Unit::forLoggedInUser()->lists('name', 'id'); $sources = Source::forLoggedInUser()->lists('name', 'id'); return view('books.create', compact('categories', 'units', 'sources')); }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(AdminSourcesRequest $request, $id) { $source = Source::findOrFail($id); // if a thumbnail is uploaded send file to be processed (cropped, resized ..etc) using our custom handler if ($request->hasFile('thumb')) { $this->dispatchFrom('\\App\\Jobs\\processUploadedThumbs', $request); } $source->update($request->All()); return Redirect::Route('admin.sources.index')->withMessage('Success!'); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit(Lead $lead) { // Edit an exisiting lead $stages = Stage::lists('name', 'id'); $sources = Source::lists('name', 'id'); $genders = Gender::lists('name', 'id'); $titles = Title::lists('name', 'id'); $users = User::lists('name', 'id'); return view('leads.edit', compact('lead', 'stages', 'sources', 'users', 'titles', 'genders')); }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $id) { $source = Source::find($id); $source->feed_url = $request->input('feed_url'); $feed = Feeds::make($source->feed_url); $source->name = $feed->get_title(); $source->website_url = $feed->get_permalink(); $source->save(); $source->categories()->sync($request->input('category_id')); Flash::success('Source updated !'); return redirect()->route('admin.source.index'); }
public function getPostsFromSource($source) { $this->info("Getting posts from [ " . $source . " ]"); // Check if it's a valid source if (!Source::has($source)) { throw new Exception("Given Shorthand is not for a valid source", 1); } // If exists, proceed $source = Source::where('shorthand', $source)->first(); // get post links $postLinks = (new PostListGetter($source))->getList(); // get details for each link foreach ($postLinks as $key => $link) { $this->info('Getting details for link: ' . $link); $details = (new PostDetailsGetter($source, $link))->getDetails(); if ($details) { if (!$source->hasPublished($details['url'])) { // save // queue image for processing // save the post $post = Post::create($details); // associate the post to a source $post->source()->associate($source)->save(); // extract and process images (if any); (new \App\ContentProcessors\ImageProcessors\MainProcessor($post))->process(); // process text (new \App\ContentProcessors\TextProcessors\MainProcessor($post))->process(); } else { $this->info('This post is already in the database'); } } else { $this->info('could not extract content from this url'); } // if Post::has($details), skip // otherwise, // 1- Post::store($details) (without image) // 2- Cache Image and Store in Image model, with post ID; } }
/** * Execute the console command. * * @return mixed */ public function handle() { // get sources from the old Lebanese blogs $sources = @file_get_contents('http://lebaneseblogs.com/sources/' . getenv('PASS')); $sources = json_decode($sources); foreach ($sources as $key => $source) { $this->info('Adding Source [ ' . $source->blog_name . ' ]'); // map old columns to new columns $newSource = Source::create(['shorthand' => $source->blog_id, 'name' => $source->blog_name, 'description' => $source->blog_description, 'url' => $source->blog_url, 'author' => $source->blog_author, 'author_twitter' => $source->blog_author_twitter_username, 'rss_feed' => $source->blog_rss_feed, 'active' => $source->blog_RSSCrawl_active]); // channels $oldChannels = preg_split('#\\s*,\\s*#', $source->blog_tags); $newChannels = []; foreach ($oldChannels as $key => $oldChannel) { // If this channel exists, add it. if (Channel::where('shorthand', $oldChannel)->get()->count()) { $newChannels[] = Channel::where('shorthand', $oldChannel)->first()->id; } } // Now associate source with list of channels; $newSource->channels()->sync($newChannels); } $this->comment('Import complete: Total Sources Added: ' . count($sources)); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // $source = Source::findOrFail($id); $source->delete(); return \Redirect::route('manage.sources.index')->with('warning', 'The source has been deleted!'); }
/** * Display a list of all of the products * * @param Request $request * @return Response */ public function index(Request $request) { $stores = Store::orderBy('name')->lists('name', 'id'); $sources = Source::orderBy('name')->lists("name", 'id'); $query = Product::orderBy('name', 'asc'); if ($request->store) { $query->where('store_id', $request->store); } if (isset($request->status) && $request->status != '') { if ($request->status == 3) { $query->where('quantity_sold', '>', 0); } else { $query->where('product_status', $request->status); } } if ($request->source) { $query->where('source_id', $request->source); } if ($request->from_date) { $query->where('updated_at', '>=', date('Y-m-d', strtotime($request->from_date))); } if ($request->to_date) { $query->where('updated_at', '<=', date('Y-m-d', strtotime('+1 day', strtotime($request->to_date)))); } $products = $query->get(); return view('products.index', ['products' => $products, 'statuses' => $this->product_statuses, 'stores' => $stores, 'sources' => $sources]); }
public function postSources() { return Source::all(); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(Source $source) { // Delete a source $source->delete(); flash()->success('Source has been deleted!'); return redirect('sources'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { Source::destroy($id); return redirect(route('admin.source.index')); }
/** * This is used to add NEW sources not already in our sources table * */ private function syncSources($post, $request) { if (!$request->has('source_list')) { $post->sources()->detach(); return; } $allSourceIds = array(); foreach ($request->source_list as $sourceId) { if (substr($sourceId, 0, 4) == 'new:') { $newSource = Source::create(['name' => substr($sourceId, 4)]); $allSourceIds[] = $newSource->id; continue; } $allSourceIds[] = $sourceId; } $post->sources()->sync($allSourceIds); }
/** * Destroy the given task. * * @param Request $request * @param Task $task * @return Response */ public function destroy(Request $request, Source $source) { //$this->authorize('destroy', $source); $source->delete(); return redirect('/sources'); }
static function has($shorthand) { return Source::where('shorthand', $shorthand)->count() > 0; }
public function confirmEmailByToken($token) { $source = Source::whereEmailToken($token)->with(['customers', 'customers.samples' => function ($query) { $query->orderBy('created_at', 'desc'); }])->first(); if ($source) { $source->email_token = null; $source->email_confirmed = true; $source->save(); } return $source; }
/** * Display a list of all of the purchases * * @param Request $request * @return Response */ public function index(Request $request) { $sources = Source::orderBy('name')->lists('name', 'id'); $query = Purchase::orderBy('purchase_date', 'desc'); if ($request->source) { $query->where('source_id', $request->source); } if ($request->from_date) { $query->where('purchase_date', '>=', date('Y-m-d', strtotime($request->from_date))); } if ($request->to_date) { $query->where('purchase_date', '<=', date('Y-m-d', strtotime($request->to_date))); } $purchases = $query->get(); return view('purchases.index', ['purchases' => $purchases, 'sources' => $sources]); }