/** * Adds an image * * @param object $query * @param string $content * * @return object */ public function scopeCreateFromApi($query, $entry) { $newEntry = new Dbox(); $newEntry->tid = $entry['tid']; $newEntry->type = $entry['type']; $newEntry->content = $entry['content']; $newEntry->log = $entry['log']; $newEntry->save(); return $newEntry; }
public function getDropbox(&$contents, $tid) { $user = User::getVlasmarktUser(); $images = Dbox::getRelated(); foreach ($images as $image) { $data = $image->toArray(); if (!isset($tid)) { $tid = 0; } $contents[$data['tid'] != $tid ? (string) $data['tid'] : 0] = array('tid' => $data['tid'], 'content' => '/store/dropbox/' . $data['content'], 'user' => $user[0]->name, 'url' => $user[0]->url); } ksort($contents); }
public function delete(Request $request) { $list = json_decode($request->input('list')); foreach ($list as $item) { $remove[$item->type][] = $item->tid; } if (array_key_exists('tweets', $remove)) { Tweet::markAsInactive($remove['tweets']); } if (array_key_exists('twitpics', $remove)) { Image::markAsInactive($remove['twitpics']); } if (array_key_exists('instagram', $remove)) { Image::markAsInactive($remove['instagram']); } if (array_key_exists('dropbox', $remove)) { Dbox::markAsInactive($remove['dropbox']); } // return? }
/** * Store images & save to DB */ public function storeAndSave($collect) { foreach ($collect as $path => $image) { $dbTid = Dbox::getByContent($image[0])->get(); if ($dbTid->isEmpty()) { Dbox::insert($image[2]); $write = true; } else { if ($dbTid->first()->tid != $image[1]) { Dbox::getByContent($image[0])->update(['tid' => $image[1]]); $write = true; } else { $write = false; } } // Save file to local folder if ($write) { $fd = fopen(env('STORE_PATH') . $image[0], "wb"); Dropbox::getFile($path, $fd); fclose($fd); } } }
/** * Get the most recent images in the DBs */ public function getRecentImages($amount, $selector) { $types = array('instagram', 'instatag'); # add 'facebook' to get the facebook images $fields = array('tid', 'user', 'content AS image', 'type'); $dbFields = array('tid', 'content AS image', 'type'); $images = Image::recentByTypes($types, $fields, $amount)->get(); $dbImages = Dbox::recent($dbFields, $amount)->get(); $dbImages->each(function ($item, $key) { if ($item->type == 'dropbox') { $item->image = "http://campingvlasmarkt.be/store/dropbox/" . $item->image; $item->user = "******"; } }); $images->each(function ($item, $key) { if ($item->type == 'instatag') { $item->type = "instagram"; } }); $merged = array_merge($images->toArray(), $dbImages->toArray()); shuffle($merged); return response()->json(['contents' => $merged, 'selector' => $selector]); }