public static function getFeedStructureFromXML($oRssFeed, $sXMLString, $sStopAt) { // called when parsing rss feeds, tries to convert a mixed xml string into a structured object $oParsedFeed = self::oXMLStringToFeedObject($sXMLString); // go through each feed item and save into our system foreach ($oParsedFeed->aoItems as $oDataOnlyFeedItem) { $oFeedItem = new FeedItem(); $oFeedItem->title = $oDataOnlyFeedItem->title; $oFeedItem->url = $oDataOnlyFeedItem->url; $oFeedItem->guid = $oDataOnlyFeedItem->guid; $oFeedItem->pubDate = $oDataOnlyFeedItem->pubDate; $oFeedItem->feed_id = $oRssFeed->id; /* if ($oParsedFeed->bPic) { $oFeedItem->thumb = $oDataOnlyFeedItem->thumb; } */ $oFeedItem->save(); // schedule crunching our scraping thumb.. if (!$oParsedFeed->bPic) { // schedule for image scrape Feeds::scheduleFeedItemImageScrape($oFeedItem->id); } else { // we have a thumbnail but need to make sure it's the correct size Feeds::scheduleThumbCrunch($oFeedItem->sPicURL, $oFeedItem->id); } $oFeedItem->save(); } return $oParsedFeed; }
public function create() { //Let's first run the validation with all provided input $validation = Validator::make(Input::all(), Feeds::$form_rules); //If the validation passes, we add the values to the database and return to the form if ($validation->passes()) { //We try to insert a new row with Eloquent $create = Feeds::create(array('feed' => Input::get('feed'), 'title' => Input::get('title'), 'active' => Input::get('active'), 'category' => Input::get('category'))); //We return to the form with success or error message due to state of the if ($create) { return Redirect::to('feeds/create')->with('message', 'The feed added to the database successfully!'); } else { return Redirect::to('feeds/create')->withInput()->with('message', 'The feed could not be added, please try again later!'); } } else { //If the validation does not pass, we return to the form with first error message as flash data return Redirect::to('feeds/create')->withInput()->with('message', $validation->errors()->first()); } }
/** * Display a listing of the resource. * * @return Response */ public function process() { /* hit every minute via laravel cron proxy */ // start timer $cdStarted = Carbon::now(); $iSecondsCutOff = 40; $bJobsRemain = true; // while less than a minute (or part there of) has past, keep pulling a task to process while ($cdStarted->diffInSeconds(Carbon::now()) < $iSecondsCutOff && $bJobsRemain) { //echo $cdStarted->diffInSeconds(Carbon::now()), "<br/>"; $tJobToProcess = Task::next(); // if no more jobs, escape loop if (!isset($tJobToProcess)) { $bJobsRemain = false; } else { switch ($tJobToProcess->job) { case "pull-feed": $iFeedId = (int) $tJobToProcess->detail; Feeds::pullFeed($iFeedId); $tJobToProcess->delete(); // and reschedule for fifteen minbutes Feeds::scheduleFeedPull($iFeedId, 15); break; case "scrape-feed-item-image": Feeds::scrapeThumbFromFeedItem((int) $tJobToProcess->detail); $tJobToProcess->delete(); break; case "crunch-feed-image": $oFeed = FeedItem::find((int) $tJobToProcess->detail); Feeds::storeThumbForFeedItem($oFeed, (string) $tJobToProcess->name); $tJobToProcess->delete(); break; } } } echo "no more tasks available", "<br/>"; }