private function assignImages($model, $fileData) { if (array_key_exists($model->slug, $fileData)) { $images = $fileData[$model->slug]; // print_r($images); echo $model->slug . " ["; // echo get_class($model) . "\n"; if (!is_array($images)) { return; } foreach ($images as $key => $filePath) { if (!is_array($filePath)) { $pathinfo = pathinfo($filePath); $check = File::where('attachment_id', '=', $model->id)->where('attachment_type', '=', get_class($model))->where('file_name', '=', $pathinfo['basename'])->first(); if (!is_null($check)) { // echo $filePath . " "; // echo filemtime($filePath) . " "; // echo $check->updated_at->timestamp . "\n"; if (filemtime($filePath) > $check->updated_at->timestamp) { // echo "File " . $filePath . " is Newer. Update!" . "\n"; echo "^"; $check->delete(); } else { echo "~"; continue; } } else { // echo "File " . $filePath . " is New. Create!" . "\n"; echo "+"; } $file = new File(); $file->fromFile($filePath); switch ($key) { case 'cover': $model->cover()->save($file, null, ['title' => $model->title]); break; default: echo ' Image ' . $filePath . ' not saved.' . "\n"; break; } } } echo "]\n"; } else { // preg_match_all('#<img.+?src="(.+?)"#', $model->content, $matches); // // $images = $matches[1]; // $images = array_filter($matches[1], function ($value) { // return !preg_match('#^https?\:\/\/#', $value); // }); // if (count($images) != 0) { // $filePath = $images[0]; // // echo $model->title . " -- " . $filePath . "\n"; // $file = new File(); // $file->fromFile("./" . $filePath); // $model->cover()->save($file, null, ['title' => $model->title]); // } } }
public function loadUserInfo() { $peopleWithAvatars = []; $avatars = Avatar::where('attachment_type', 'RainLab\\User\\Models\\User')->where('field', 'avatar')->get(); foreach ($avatars as $avatr) { $this->avatars[$avatr->attachment_id] = ['t600' => $avatr->getThumb(600, 600), 't200' => $avatr->getThumb(200, 200), 'filename' => $avatr->filename]; $peopleWithAvatars[] = $avatr->attachment_id; } // Set Pagination parameters $this->perPage = $this->property('PicsPerPage', 12); $this->currentPage = input('page', 1); $sort3 = null; /* * Sorting */ switch ($this->sort) { case 'last': $sort1 = 'surname'; $sort2 = 'name'; break; case 'given': $sort1 = 'name'; $sort2 = 'surname'; break; default: $sort1 = 'primary_usergroup'; $sort2 = 'surname'; $sort3 = 'name'; } $people = user::wherein('id', $peopleWithAvatars)->orderBy($sort1)->orderBy($sort2); if ($sort3) { $people->orderBy($sort3); } $this->people = $people->paginate($this->perPage, $this->currentPage); /* * Pagination */ if ($this->people) { $queryArr = []; $queryArr['sort'] = $this->sort; $queryArr['page'] = ''; $paginationUrl = Request::url() . '?' . http_build_query($queryArr); if ($this->currentPage > ($this->lastPage = $this->people->lastPage()) && $this->currentPage > 1) { return Redirect::to($paginationUrl . $this->lastPage); } $this->firstItem = $this->people->firstItem(); $this->lastItem = $this->people->lastItem(); $this->total = $this->people->total(); $this->paginationUrl = $paginationUrl; } return $this->people; }
/** * Sample pdf layouts */ public function run() { PDFLayout::insert([['name' => 'Invoice', 'code' => 'renatio::invoice', 'content_html' => File::get(__DIR__ . '/layouts/invoice.htm'), 'content_css' => File::get(__DIR__ . '/layouts/style_invoice.css'), 'created_at' => Carbon::now()]]); $file = FileModel::where(['field' => 'background_img', 'attachment_id' => 1])->first(); if (!is_object($file)) { FileModel::insert([['disk_name' => '55428b6d4425d031778535.jpg', 'file_name' => 'invoice.jpg', 'file_size' => '47454', 'content_type' => 'image/jpeg', 'field' => 'background_img', 'attachment_id' => 1, 'attachment_type' => 'Renatio\\DynamicPDF\\Models\\PDFLayout']]); } $storage_dir = storage_path('app/uploads/public/554/28b/6d4'); $file = $storage_dir . '/55428b6d4425d031778535.jpg'; if (!File::exists($file)) { File::makeDirectory($storage_dir, 0755, true); File::copy('plugins/renatio/dynamicpdf/assets/images/invoice.jpg', $file); } }
/** * Execute the console command. * @return void */ public function fire() { // remove files without related register... $this->info(trans('genius.storageclear::lang.clear.seeking.files')); $allFiles = Storage::allFiles('uploads'); $count = 0; $total = count($allFiles); foreach ($allFiles as $file) { if (!File::where('disk_name', basename($file))->first(['id'])) { Storage::delete($file); $count++; } } $this->info(trans('genius.storageclear::lang.clear.removed.files', compact('count', 'total'))); // remove registers without file... $this->info(trans('genius.storageclear::lang.clear.seeking.registers')); $allFiles = File::all(['id', 'disk_name', 'attachment_type', 'attachment_id', 'is_public']); $count = 0; $total = $allFiles->count(); foreach ($allFiles as $file) { if (!Storage::exists($file->getDiskPath())) { $file->delete(); $count++; } else { $class = $file->attachment_type; if (!$class || !class_exists($class) || !$class::find($file->attachment_id)) { $file->delete(); $count++; } } } $this->info(trans('genius.storageclear::lang.clear.removed.registers', compact('count', 'total'))); // deletar pastas vazias $this->info(trans('genius.storageclear::lang.clear.seeking.directories')); $allFolders = array_reverse(Storage::allDirectories('uploads')); $count = 0; $total = count($allFolders); foreach ($allFolders as $directory) { if (!Storage::allFiles($directory)) { Storage::deleteDirectory($directory); $count++; } } $this->info(trans('genius.storageclear::lang.clear.removed.directories', compact('count', 'total'))); }
/** Usage example: {{ product.image | transparencyThumb(180,180, {color: [255,0,0]}) }} * @param File $originalImage * @param $width * @param $height * @param array $opts * @return string */ public function transparencyThumb($originalImage, $width, $height, $opts = []) { if ($originalImage == null) { return null; } $extension = $originalImage->getAttribute('extension'); if ($extension == 'png' || $extension == 'gif') { if (isset($opts['color']) == false) { $opts['color'] = [255, 255, 255]; } $appendix = '_trans_tmp_' . implode('-', $opts['color']) . '.jpg'; $dbDiskName = str_replace('.' . $extension, $appendix, $originalImage->getAttribute('file_name')); $dbAttachmentType = $originalImage->getAttribute('attachment_type') . '::transparency'; $dbFile = File::where('file_name', $dbDiskName)->where('attachment_type', $dbAttachmentType)->first(); if ($dbFile) { return $dbFile->getThumb($width, $height, $opts); } if ($extension == 'png') { $tmpImageData = imagecreatefrompng(base_path() . $originalImage->getPath()); } else { $tmpImageData = imagecreatefromgif(base_path() . $originalImage->getPath()); } $imageWidth = imagesx($tmpImageData); $imageHeight = imagesy($tmpImageData); $backgroundImg = imagecreatetruecolor($imageWidth, $imageHeight); $color = imagecolorallocate($backgroundImg, $opts['color'][0], $opts['color'][1], $opts['color'][2]); imagefill($backgroundImg, 0, 0, $color); imagecopy($backgroundImg, $tmpImageData, 0, 0, 0, 0, $imageWidth, $imageHeight); $tmpImagePath = $originalImage->getTempPath() . '/' . $dbDiskName; imagejpeg($backgroundImg, $tmpImagePath); imagedestroy($backgroundImg); imagedestroy($tmpImageData); //return str_replace(base_path(), '', $tmpImagePath); $file = File::create(['data' => $tmpImagePath, 'attachment_type' => $dbAttachmentType]); return $file->getThumb($width, $height, $opts); } return $originalImage->getThumb($width, $height, $opts); }
private function assignImages($model, $fileData) { if (array_key_exists($model->slug, $fileData)) { $images = $fileData[$model->slug]; echo $model->slug . " ["; foreach ($images as $key => $filePath) { if (!is_array($filePath)) { $pathinfo = pathinfo($filePath); $check = File::where('attachment_id', '=', $model->id)->where('attachment_type', '=', get_class($model))->where('file_name', '=', $pathinfo['basename'])->first(); if (!is_null($check)) { if (filemtime($filePath) > $check->updated_at->timestamp) { echo "^"; $check->delete(); } else { echo "~"; continue; } } else { echo "+"; } $file = new File(); $file->fromFile($filePath); switch ($key) { case 'logo_color': $model->logo_color()->save($file, null, ['title' => $model->title]); break; case 'logo_bw': $model->logo_bw()->save($file, null, ['title' => $model->title]); break; default: echo ' Image ' . $filePath . ' not saved.' . "\n"; break; } } } echo "]\n"; } }
private function assignImages($model, $fileData) { if (array_key_exists($model->slug, $fileData)) { $images = $fileData[$model->slug]; // print_r($images); echo $model->slug . " ["; // echo get_class($model) . "\n"; foreach ($images as $key => $filePath) { if (!is_array($filePath)) { $pathinfo = pathinfo($filePath); $check = File::where('attachment_id', '=', $model->id)->where('attachment_type', '=', get_class($model))->where('file_name', '=', $pathinfo['basename'])->first(); if (!is_null($check)) { // echo $filePath . " "; // echo filemtime($filePath) . " "; // echo $check->updated_at->timestamp . "\n"; if (filemtime($filePath) > $check->updated_at->timestamp) { // echo "File " . $filePath . " is Newer. Update!" . "\n"; echo "^"; $check->delete(); } else { echo "~"; continue; } } else { // echo "File " . $filePath . " is New. Create!" . "\n"; echo "+"; } $file = new File(); $file->fromFile($filePath); // $file->save(); $model->images()->save($file, null, ['title' => $model->title]); } } echo "]\n"; } }
public function putPhotoOrder($id) { // Get current user $user = Auth::getUser(); // Kiem tra ad hien tai co dung la cua user hay ko $record = Ad::whereRaw('id = ? AND user_id = ?', array($id, $user->id))->first(); if (!$record) { return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'ad_not_exist')), 500); } $data = put(); $default = array('photo_ids' => ''); $merge = array_merge($default, $data); $merge = \DLNLab\Classified\Classes\HelperClassified::trim_value($merge); extract($merge); if (!is_array(photo_ids)) { return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'require_signin')), 500); } $insert_id = array(); foreach ($photo_ids as $i => $id) { if ($id && is_numeric($id) && !in_array($id, $insert_id)) { // Get this file File::where('id', '=', $id)->update(array('sort_order' => $i + 1)); $insert_id[] = $id; } } return Response::json(array('status' => 'success', 'message' => trans(CLF_LANG_MESSAGE . 'ad_photo_saved'))); }
private function assignImages($model, $fileData) { if (array_key_exists($model->slug, $fileData)) { $images = $fileData[$model->slug]; echo $model->slug . " ["; // echo get_class($model) . "\n"; foreach ($images as $key => $filePath) { if (!is_array($filePath)) { $pathinfo = pathinfo($filePath); $check = File::where('attachment_id', '=', $model->id)->where('attachment_type', '=', get_class($model))->where('file_name', '=', $pathinfo['basename'])->first(); if (!is_null($check)) { // echo $filePath . " "; // echo filemtime($filePath) . " "; // echo $check->updated_at->timestamp . "\n"; if (filemtime($filePath) > $check->updated_at->timestamp) { // echo "File " . $filePath . " is Newer. Update!" . "\n"; echo "^"; $check->delete(); } else { echo "~"; continue; } } else { // echo "File " . $filePath . " is New. Create!" . "\n"; echo "+"; } $file = new File(); $file->fromFile($filePath); // $file->save(); // echo $filePath . "\n"; switch ($key) { case 'playbill': $model->playbill()->save($file, null, ['title' => $model->title]); break; // case 'playbill_flat': // $model->playbill_flat()->save($file); // break; // case 'playbill_mask': // $model->playbill_mask()->save($file); // break; // case 'playbill_flat': // $model->playbill_flat()->save($file); // break; // case 'playbill_mask': // $model->playbill_mask()->save($file); // break; case 'video': $model->video()->save($file, null, ['title' => $model->title]); break; case 'repertoire': $model->repertoire()->save($file, null, ['title' => $model->title]); break; case 'cover': $model->cover()->save($file, null, ['title' => $model->title]); break; case 'portrait': $model->portrait()->save($file, null, ['title' => $model->title]); break; default: echo ' Image ' . $filePath . ' not saved.' . "\n"; break; } } elseif (is_array($filePath)) { foreach ($filePath as $filename => $filePath) { $pathinfo = pathinfo($filePath); $check = File::where('attachment_id', '=', $model->id)->where('attachment_type', '=', get_class($model))->where('file_name', '=', $pathinfo['basename'])->first(); // preg_match("~^(\d+)~", $filename, $matches); // print_r($matches); if (!is_null($check)) { // echo $filePath . " "; // echo filemtime($filePath) . " "; // echo $check->updated_at->timestamp . "\n"; if (filemtime($filePath) > $check->updated_at->timestamp) { // echo "File " . $filePath . " is Newer. Update!" . "\n"; echo "^"; $check->delete(); } else { // echo "File " . $filePath . " is Older. Skip!" . "\n"; echo "~"; continue; } } else { // echo "File " . $filePath . " is New. Create!" . "\n"; echo "+"; } $file = new File(); $file->fromFile($filePath); // $file->save(); // if (count($matches) > 0) { // $file->sort_order = intval($matches[0], 10); // print_r($file); // } // if ( $key == 'bg' && preg_match('/.+?_flat/', $filename) ) { // $model->background_flat()->save($file); // } // elseif ( $key == 'bg' && preg_match('/.+?_mask/', $filename) ) { // $model->background_mask()->save($file); // } if ($key == 'bg') { $model->background()->save($file); } elseif ($key == 'gallery') { $model->featured()->save($file); } else { echo $filePath . ' not saved.' . "\n"; } } } } echo "]\n"; } }
protected function getImage($image, &$type) { if (is_a($image, 'System\\Models\\File')) { return $image; } // See if we can make a File out of an array if ($type == 'array') { $basename = basename($image['path']); $original = $image; $image = File::where("file_name", "=", $basename)->orWhere("disk_name", "=", $basename)->first(); if (!is_null($image)) { $type = 'file'; return $image; } return $original; } return (string) $image; }
public static function getFile($file) { // It's already a File if (is_a($file, 'System\\Models\\File')) { return $file; } // See if we can work with the array if (is_array($file)) { if (!isset($file['path'])) { return null; } $file = $file['path']; } // "Original" string $original = $file; // See if we can fetch a File model if (self::canBeResponsive($file)) { $basename = basename($file); $file = File::where("file_name", "=", $file)->orWhere("disk_name", "=", $file)->first(); return is_null($file) ? $original : $file; } return $original; }