Ejemplo n.º 1
0
 /**
  * Search for a keyword
  *
  * @param Request $request
  * @return Response
  */
 public function search(Request $request)
 {
     $q = $request->get('q', '');
     if (empty($q)) {
         return redirect()->back();
     }
     $images = Image::whereHas('tags', function ($query) use($q) {
         $query->where('title', 'like', "%{$q}%");
     })->orWhere('title', 'like', "%{$q}%")->orWhere('filename', 'like', "%{$q}%")->orWhere('description', 'like', "%{$q}%")->get();
     return view('site.search', ['pageTitle' => $this->pageTitle([trans('site.search.page-title')]), 'q' => $q, 'images' => $images]);
 }
Ejemplo n.º 2
0
 /**
  * Update tags in database.
  *
  * @param Request $request
  * @param int $id
  *
  * @return Redirect
  */
 public function update(Request $request, $id)
 {
     $image = Image::findOrFail($id);
     $tags = DB::table('tags')->whereIn('id', $request->input('tags'))->lists('id');
     $tagsExisting = DB::table('image_tags')->where('image_id', $image->id)->lists('tag_id');
     $tagsTimestamps = [];
     foreach ($tags as $tagId) {
         $tagsTimestamps[$tagId] = ['updated_at' => date('Y-m-d H:i:s')];
         if (!in_array($tagId, $tagsExisting)) {
             $tagsTimestamps[$tagId]['created_at'] = date('Y-m-d H:i:s');
         }
     }
     $image->tags()->sync($tagsTimestamps);
     return redirect()->route('image.view', ['id' => $image->id]);
 }
Ejemplo n.º 3
0
 /**
  * Autoassign tags for images without any.
  *
  * @param Request $request
  * @return Response
  */
 public function auto(Request $request)
 {
     $image = Image::doesntHave('tags')->where('id', '=', $request->input('id'))->firstOrFail();
     return ['success' => $image->autoFindTags()];
 }
Ejemplo n.º 4
0
 /**
  * Validate file and add to database.
  *
  * @param string $absoluteFileName
  * @param string $url
  *
  * @return boolean
  */
 protected function importFromFile($absoluteFileName)
 {
     $model = null;
     try {
         $imageType = @exif_imagetype($absoluteFileName);
         if ($imageType === false) {
             Log::error('Could not read image type for feed item image ' . $this->url);
             return false;
         }
         if (!in_array($imageType, $this->validImageTypes)) {
             Log::error('Invalid image type for feed item image ' . $this->url . ': ' . $imageType);
             return false;
         }
         if (!@rename($absoluteFileName, $absoluteFileName . '.' . image_type_to_extension($imageType, false))) {
             Log::error('Could not rename downloaded feed item image ' . $absoluteFileName);
             return false;
         }
         $absoluteFileName = $absoluteFileName . '.' . image_type_to_extension($imageType, false);
         $fileInfo = new UploadedFile($absoluteFileName, basename($absoluteFileName), image_type_to_mime_type($imageType), filesize($absoluteFileName));
         $model = Image::createFromUpload($fileInfo, $this->feed->user_id);
     } catch (\Exception $e) {
         Log::error('Could not upload feed item image: ' . $e->getMessage() . '(' . $e->getFile() . ' - Line:' . $e->getLine() . ')');
         if ($model !== null) {
             $model->delete();
         }
         return false;
     } finally {
         @unlink($absoluteFileName);
     }
     $this->image_id = $model->id;
     return true;
 }
Ejemplo n.º 5
0
 /**
  * Display images without tags.
  *
  * @return Response
  */
 public function untagged()
 {
     $untagged = Image::doesntHave('tags')->paginate(30);
     return view('image/untagged', ['pageTitle' => $this->pageTitle([trans('image.untagged.page-title')]), 'untagged' => $untagged]);
 }