예제 #1
0
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 500) as $index) {
         $keywords = '';
         for ($i = 0; $i < $faker->numberBetween(4, 9); $i++) {
             $keywords .= $faker->word . ',';
         }
         $keywords = rtrim($keywords, ',');
         $name = $faker->name;
         $short_name = Str::slug($name);
         $gender = $faker->randomElement(array('male', 'female', 'both', 'any'));
         $age_from = $faker->numberBetween(0, 90);
         $age_to = $faker->numberBetween(0, 90);
         while ($age_from > $age_to) {
             $age_from = $faker->numberBetween(0, 90);
             $age_to = $faker->numberBetween(0, 90);
         }
         $ethnicity = $faker->randomElement(array('african', 'african_american', 'black', 'brazilian', 'chinese', 'caucasian', 'east_asian', 'hispanic', 'japanese', 'middle_eastern', 'native_american', 'pacific_islander', 'south_asian', 'southeast_asian', 'other', 'any'));
         $number_people = $faker->numberBetween(0, 10);
         $editorial = $faker->numberBetween(0, 1);
         $type_id = $faker->numberBetween(1, 3);
         $artist = $faker->name;
         $author_id = $faker->numberBetween(1, 15);
         VIImage::create(['name' => $name, 'short_name' => Str::slug($name), 'description' => $faker->paragraph, 'keywords' => $keywords, 'type_id' => $type_id, 'gender' => $gender, 'age_from' => $age_from, 'age_to' => $age_to, 'ethnicity' => $ethnicity, 'number_people' => $number_people, 'editorial' => $editorial, 'artist' => $artist, 'author_id' => $author_id]);
     }
 }
 public function run()
 {
     $faker = Faker::create();
     $imgDir = public_path() . DS . 'assets' . DS . 'upload' . DS . 'images';
     if (!File::exists($imgDir)) {
         File::makeDirectory($imgDir, 0755);
     }
     File::cleanDirectory($imgDir, true);
     foreach (range(1, 500) as $index) {
         $dir = $imgDir . DS . $index;
         if (!File::exists($dir)) {
             File::makeDirectory($dir, 0755);
         }
         $width = $faker->numberBetween(800, 1024);
         $height = $faker->numberBetween(800, 1024);
         $orgImg = $faker->image($dir, $width, $height);
         chmod($orgImg, 0755);
         $img = str_replace($dir . DS, '', $orgImg);
         $image = new Imagick($orgImg);
         $dpi = $image->getImageResolution();
         $dpi = $dpi['x'] > $dpi['y'] ? $dpi['x'] : $dpi['y'];
         $size = $image->getImageLength();
         $extension = strtolower($image->getImageFormat());
         //get 5 most used colors from the image
         $color_extractor = new ColorExtractor();
         $myfile = $orgImg;
         $mime_type = $image->getImageMimeType();
         switch ($mime_type) {
             case 'image/jpeg':
                 $palette_obj = $color_extractor->loadJpeg($myfile);
                 break;
             case 'image/png':
                 $palette_obj = $color_extractor->loadPng($myfile);
                 break;
             case 'image/gif':
                 $palette_obj = $color_extractor->loadGif($myfile);
                 break;
         }
         $main_color = '';
         if (is_object($palette_obj)) {
             $arr_palette = $palette_obj->extract(5);
             if (!empty($arr_palette)) {
                 $main_color = strtolower($arr_palette[0]);
                 for ($i = 1; $i < count($arr_palette); $i++) {
                     $main_color .= ',' . strtolower($arr_palette[$i]);
                 }
             }
         }
         //update field main_color from images table
         $image_obj = VIImage::findorFail((int) $index);
         $image_obj->main_color = $main_color;
         $image_obj->save();
         $id = VIImageDetail::insertGetId(['path' => 'assets/upload/images/' . $index . '/' . $img, 'height' => $height, 'width' => $width, 'ratio' => $width / $height, 'dpi' => $dpi, 'size' => $size, 'extension' => $extension, 'type' => 'main', 'image_id' => $index]);
         BackgroundProcess::makeSize($id);
     }
 }
 public function getImages()
 {
     if (!Request::ajax()) {
         return App::abort(404);
     }
     $id = Input::has('id') ? Input::get('id') : 0;
     if (!Input::has('page')) {
         $pageNum = 1;
     } else {
         $pageNum = (int) Input::get('page');
     }
     $name = '';
     $take = 25;
     $skip = floor(($pageNum - 1) * $take);
     $images = VIImage::select('id', 'name', 'short_name')->withType('main')->whereRaw('id NOT IN (SELECT image_id FROM collections_images WHERE collection_id = ?)', [$id]);
     if (Input::has('categories')) {
         $arrCategories = (array) Input::get('categories');
         $images->whereHas('categories', function ($query) use($arrCategories) {
             $query->whereIn('id', $arrCategories);
         });
     }
     if (Input::has('name')) {
         $name = Input::get('name');
         $nameStr = '*' . $name . '*';
         $images->search($nameStr);
     }
     $total = $images->count();
     $images = $images->take($take)->skip($skip)->orderBy('id', 'desc')->get();
     $arrReturn = [];
     $arrReturn['total_page'] = ceil($total / $take);
     $arrReturn['page'] = $pageNum;
     if (!$images->isEmpty()) {
         foreach ($images as $image) {
             if ($image->ratio > 1) {
                 $width = 150;
                 $height = $width / $image->ratio;
             } else {
                 $height = 150;
                 $width = $height * $image->ratio;
             }
             $arrReturn['data'][] = ['id' => $image->id, 'name' => $image->name, 'short_name' => $image->short_name, 'path' => URL . '/pic/thumb/' . $image->short_name . '-' . $image->id . '.jpg', 'width' => $width, 'height' => $height, 'ratio' => $image->ratio];
         }
     }
     return $arrReturn;
 }
예제 #4
0
 public function updateImage()
 {
     if (!Request::ajax()) {
         return App::abort(404);
     }
     $arrReturn = ['status' => 'error'];
     $id = Input::has('id') ? Input::get('id') : 0;
     if ($id) {
         $create = false;
         try {
             $image = VIImage::findorFail((int) Input::get('id'));
         } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             return App::abort(404);
         }
         $message = 'has been updated successful';
     } else {
         $create = true;
         $image = new VIImage();
         $message = 'has been created successful';
     }
     if ($create && !Input::hasFile('image')) {
         return ['status' => 'error', 'message' => 'You need to upload at least 1 image.'];
     }
     $image->name = Input::get('name');
     $image->short_name = Str::slug($image->name);
     $image->description = Input::get('description');
     $image->keywords = Input::get('keywords');
     $image->keywords = rtrim(trim($image->keywords), ',');
     $image->model = Input::get('model');
     $image->model = rtrim(trim($image->model), ',');
     $image->artist = Input::get('artist');
     $image->age_from = Input::get('age_from');
     $image->age_to = Input::get('age_to');
     $image->gender = Input::get('gender');
     $image->number_people = Input::get('number_people');
     $pass = $image->valid();
     if ($pass->passes()) {
         if (Input::hasFile('image')) {
             $color_extractor = new ColorExtractor();
             $myfile = Input::file('image');
             $mime_type = $myfile->getClientMimeType();
             switch ($mime_type) {
                 case 'image/jpeg':
                     $palette_obj = $color_extractor->loadJpeg($myfile);
                     break;
                 case 'image/png':
                     $palette_obj = $color_extractor->loadPng($myfile);
                     break;
                 case 'image/gif':
                     $palette_obj = $color_extractor->loadGif($myfile);
                     break;
             }
             $main_color = '';
             if (is_object($palette_obj)) {
                 $arr_palette = $palette_obj->extract(5);
                 if (!empty($arr_palette)) {
                     $main_color = strtolower($arr_palette[0]);
                     for ($i = 1; $i < count($arr_palette); $i++) {
                         $main_color .= ',' . strtolower($arr_palette[$i]);
                     }
                 }
             }
             $image->main_color = $main_color;
         }
         $image->save();
         //insert into statistic_images table
         if ($create) {
             StatisticImage::create(['image_id' => $image->id, 'view' => '0', 'download' => '0']);
         }
         foreach (['category_id' => 'categories', 'collection_id' => 'collections'] as $key => $value) {
             $arrOld = $remove = $add = [];
             $old = $image->{$value};
             $data = Input::has($key) ? Input::get($key) : [];
             $data = (array) json_decode($data[0]);
             if (!empty($old)) {
                 foreach ($old as $val) {
                     if (!in_array($val->id, $data)) {
                         $remove[] = $val->id;
                     } else {
                         $arrOld[] = $val->id;
                     }
                 }
             }
             foreach ($data as $id) {
                 if (!$id) {
                     continue;
                 }
                 if (!in_array($id, $arrOld)) {
                     $add[] = $id;
                 }
             }
             if (!empty($remove)) {
                 $image->{$value}()->detach($remove);
             }
             if (!empty($add)) {
                 $image->{$value}()->attach($add);
             }
             foreach ($add as $v) {
                 $arrOld[] = $v;
             }
             $image->{'arr' . ucfirst($value)} = $arrOld;
         }
         $path = public_path('assets' . DS . 'upload' . DS . 'images' . DS . $image->id);
         if ($create) {
             $main = new VIImageDetail();
             $main->image_id = $image->id;
             $main->type = 'main';
             File::makeDirectory($path, 0755, true);
         } else {
             $main = VIImageDetail::where('type', 'main')->where('image_id', $image->id)->first();
             File::delete(public_path($main->path));
         }
         if (Input::hasFile('image')) {
             $file = Input::file('image');
             $name = $image->short_name . '.' . $file->getClientOriginalExtension();
             $file->move($path, $name);
             $imageChange = true;
         } else {
             if (Input::has('choose_image') && Input::has('choose_name')) {
                 $chooseImage = Input::get('choose_image');
                 $name = Input::get('choose_name');
                 file_put_contents($path . DS . $name, file_get_contents($chooseImage));
                 $imageChange = true;
             }
         }
         if (isset($imageChange)) {
             $main->path = 'assets/upload/images/' . $image->id . '/' . $name;
             $img = Image::make($path . DS . $name);
             $main->width = $img->width();
             $main->height = $img->height();
             $main->ratio = $main->width / $main->height;
             $img = new Imagick($path . DS . $name);
             $dpi = $img->getImageResolution();
             $main->dpi = $dpi['x'] > $dpi['y'] ? $dpi['x'] : $dpi['y'];
             $main->size = $img->getImageLength();
             $main->extension = strtolower($img->getImageFormat());
             $main->save();
             BackgroundProcess::makeSize($main->detail_id);
             $image->changeImg = true;
             if ($create) {
                 $image->dimension = $main->width . 'x' . $main->height;
                 $image->newImg = true;
                 $image->path = URL . '/pic/large-thumb/' . $image->short_name . '-' . $image->id . '.jpg';
             }
         }
         $arrReturn['status'] = 'ok';
         $arrReturn['message'] = "{$image->name} {$message}.";
         $arrReturn['data'] = $image;
         return $arrReturn;
     }
     $arrReturn['message'] = '';
     $arrErr = $pass->messages()->all();
     foreach ($arrErr as $value) {
         $arrReturn['message'] .= "{$value}\n";
     }
     return $arrReturn;
 }
예제 #5
0
 public static function imageBrowser($page = 1)
 {
     if (Request::ajax()) {
         if (Input::has('page')) {
             $page = Input::get('page');
         }
         $response = Response::json(VIImage::imageBrowser('products', $page));
         $response->header('Content-Type', 'application/json');
         return $response;
     }
     return App::abort(404);
 }
예제 #6
0
 public function deleteFile()
 {
     if (Auth::user()->check()) {
         $name = Input::get('del_file');
         $image_id = Input::get('image_id');
         $page = Input::get('page') ? Input::get('page') : '1';
         $result = array();
         try {
             $image = VIImage::findorFail($image_id);
             $store = $image->store;
             $image->delete();
             if ($store == 'dropbox') {
                 try {
                     $this->filesystem->delete($name);
                 } catch (\Dropbox\Exception $e) {
                     echo $e->getMessage();
                 }
             } else {
                 if ($store == null || $store == '') {
                     $path = public_path('assets' . DS . 'upload' . DS . 'images' . DS . $image_id);
                     $path = str_replace(['\\', '/'], DS, $path);
                     try {
                         File::deleteDirectory($path);
                     } catch (Exception $e) {
                         //echo $e->getMessage();
                     }
                 }
             }
             $result = 'Your image has removed successfully!';
             //return Response::json("{}", 200);
         } catch (Exception $e) {
             //$result = $e;
         }
         Session::flash('message', $result);
         //return Redirect::route('upload-page');
         return Redirect::route('upload-page', array('page' => $page));
     }
     return Redirect::route('account-sign-in');
 }
예제 #7
0
        $app = app();
        $controller = $app->make($controller);
        return $controller->callAction($method, $params);
    })->where(['controller' => '[^/]+', 'action' => '[^/]+', 'args' => '[^?$]+']);
});
#===========================================#
#               FRONTEND                    #
#===========================================#
Route::get('/', ['as' => 'home', 'uses' => 'HomeController@index']);
/*
 * -------------------------------------------
 *  Imagelink Routes
 *  ------------------------------------------
 */
Route::get('/pic/{type}/{slug}-{id}.jpg', function ($type, $slug, $id) {
    if ($img = VIImage::getImage($id, $type)) {
        $request = Request::instance();
        $response = Response::make($img['image'], 200, ['Content-Type' => 'image/jpeg']);
        $time = date('r', $img['time']);
        $expires = date('r', strtotime('+1 year', $img['time']));
        $response->setLastModified(new DateTime($time));
        $response->setExpires(new DateTime($expires));
        $response->setPublic();
        if ($response->isNotModified($request)) {
            return $response;
        } else {
            $response->prepare($request);
            return $response;
        }
    }
    return App::abort(404);
예제 #8
0
 public function getSimilarImage($arr_image_id = array(), $viewAll = false, $skip = 0, $takes = 7)
 {
     $similar_images = array();
     $total_image = 0;
     if (count($arr_image_id)) {
         $arr_keyword = array();
         $keywords = VIImage::select(DB::raw(" GROUP_CONCAT(`keywords` SEPARATOR ',') as 'keyword' "))->whereIn('id', $arr_image_id)->get()->toArray();
         $keywords = explode(',', $keywords[0]['keyword']);
         foreach ($keywords as $key => $keyword) {
             if (!isset($arr_keyword[$keyword])) {
                 $arr_keyword[$keyword] = 1;
             } else {
                 $arr_keyword[$keyword] += 1;
             }
         }
         // pr($keywords);
         // pr(DB::getQueryLog());die;
         shuffle($arr_keyword);
         arsort($arr_keyword);
         $arr_keyword = array_keys($arr_keyword);
         $take = count($arr_keyword) < 5 ? count($arr_keyword) - 1 : 5;
         $query = VIImage::select('name', 'short_name', 'images.id')->withType('main');
         for ($i = 0; $i < $take; $i++) {
             $query->orWhereRaw("MATCH(images.name,images.description,images.keywords) AGAINST('" . $arr_keyword[$i] . "' IN BOOLEAN MODE)");
         }
         $query->whereNotIn('images.id', $arr_image_id);
         $query->groupBy('images.id');
         $total_image = $query->get()->count();
         $similar_images = $query->skip($skip)->take($takes)->get()->toArray();
     }
     $arrSimilarImages = array();
     foreach ($similar_images as $value) {
         $arrSimilarImages[$i]['image_id'] = $value['id'];
         $arrSimilarImages[$i]['name'] = $value['name'];
         $arrSimilarImages[$i]['short_name'] = $value['short_name'];
         $arrSimilarImages[$i]['width'] = $value['width'];
         $arrSimilarImages[$i]['height'] = $value['height'];
         //$arrSimilarImages[$i]['path'] = $value['path'];
         $arrSimilarImages[$i]['path'] = '/pic/small-thumb/' . $value['short_name'] . '-' . $value['id'] . '.jpg';
         $i++;
     }
     if (Request::ajax()) {
         $html = View::make('frontend.images.similar-images')->with(['arrSimilarImages' => $arrSimilarImages, 'id_image' => isset($arr_image_id[0]) ? $arr_image_id[0] : 0])->render();
         $arrReturn = ['status' => 'ok', 'message' => '', 'html' => $html];
         $response = Response::json($arrReturn);
         $response->header('Content-Type', 'application/json');
         return $response;
     }
     if (!$viewAll) {
         return View::make('frontend.images.similar-images')->with(['arrSimilarImages' => $arrSimilarImages, 'id_image' => isset($arr_image_id[0]) ? $arr_image_id[0] : 0])->render();
     }
     return ['arrSimilarImages' => $arrSimilarImages, 'total_image' => $total_image];
 }
예제 #9
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     require_once base_path('vendor/google/apiclient/src/Google/autoload.php');
     $googleDrive = Configure::getGoogleDrive();
     if (empty($googleDrive)) {
         return $this->error('Google Drive configure was empty.');
     } else {
         if (!isset($googleDrive['google_drive_email'])) {
             return $this->error('Google Drive email was not set.');
         } else {
             if (!isset($googleDrive['google_drive_key_file'])) {
                 return $this->error('Google Drive key file was not set.');
             } else {
                 if (!File::exists($googleDrive['google_drive_key_file'])) {
                     return $this->error("Google Drive key file cannot be found.\nPath: {$googleDrive['google_drive_key_file']}");
                 }
             }
         }
     }
     $auth = new Google_Auth_AssertionCredentials($googleDrive['google_drive_email'], [Google_Service_Drive::DRIVE, Google_Service_Drive::DRIVE_READONLY, Google_Service_Drive::DRIVE_FILE, Google_Service_Drive::DRIVE_METADATA_READONLY], File::get($googleDrive['google_drive_key_file']));
     $client = new Google_Client();
     $client->setAssertionCredentials($auth);
     $service = new Google_Service_Drive($client);
     $query = 'mimeType contains \'image\' and mimeType != \'image/svg+xml\'';
     $lastDate = VIImage::where('store', 'google-drive')->orderBy('id', 'desc')->pluck('created_at');
     if ($lastDate) {
         $lastDate = gmdate("Y-m-d\\TH:i:s", strtotime($lastDate));
         $query .= ' and modifiedDate > \'' . $lastDate . '\'';
     }
     $files = $service->files->listFiles(['q' => $query])->getItems();
     $arrInsert = $arrDelete = [];
     $this->getFiles($files, $arrInsert, $arrDelete);
     while (!empty($files->nextPageToken)) {
         $files = $service->files->listFiles(['q' => $query, 'pageToken' => $files->nextPageToken]);
         $this->getFiles($files, $arrInsert, $arrDelete);
     }
     if (!empty($arrDelete)) {
         $detailImages = $images = [];
         foreach ($arrDelete as $k => $file) {
             $image = VIImageDetail::select('image_id', 'detail_id')->where('path', $file)->first();
             if ($image) {
                 $detailImages[] = $image->detail_id;
                 $images[] = $image->image_id;
             }
         }
         VIImageDetail::destroy($detailImages);
         VIImage::destroy($images);
     }
     if (!empty($arrInsert)) {
         foreach ($arrInsert as $file) {
             $image = new VIImage();
             $image->name = $file['name'];
             $image->short_name = Str::slug($image->name);
             $image->store = 'google-drive';
             $image->save();
             $imageDetail = new VIImageDetail();
             $imageDetail->path = $file['link'];
             $imageDetail->width = $file['width'];
             $imageDetail->height = $file['height'];
             $imageDetail->size = $file['size'];
             $imageDetail->ratio = $file['width'] / $file['height'];
             $imageDetail->extension = $file['extension'];
             $imageDetail->type = 'main';
             $imageDetail->image_id = $image->id;
             $imageDetail->save();
         }
     }
     $this->info('Query: "' . $query . '".' . "\n" . 'Inserted ' . count($arrInsert) . ' images(s).' . "\n" . 'Deleted ' . count($arrDelete) . ' image(s).');
 }
예제 #10
0
 public function searchImage()
 {
     $keyword = Input::has('keyword') ? Input::get('keyword') : '';
     //for recently searched images
     $keyword_searched = $keyword;
     $short_name = Input::has('short_name') ? Input::get('short_name') : '';
     $sort_method = Input::has('sort_method') ? Input::get('sort_method') : 'new';
     $sort_style = Input::has('sort_style') ? Input::get('sort_style') : 'mosaic';
     if (trim($keyword) != '') {
         $keyword = '*' . trim($keyword) . '*';
     }
     $page = Input::has('page') ? Input::get('page') : 1;
     $take = Input::has('take') ? Input::get('take') : 30;
     $type = Input::has('type') ? intval(Input::get('type')) : 0;
     $orientation = Input::has('orientation') ? Input::get('orientation') : 'any';
     $skip = ($page - 1) * $take;
     $category = Input::has('category') ? intval(Input::get('category')) : 0;
     $search_type = Input::has('search_type') ? Input::get('search_type') : 'search';
     $exclude_keyword = Input::has('exclude_keyword') ? '*' . Input::get('exclude_keyword') . '*' : '';
     $exclude_people = Input::has('exclude_people');
     $include_people = Input::has('include_people');
     $gender = Input::has('gender') ? Input::get('gender') : 'any';
     $age = Input::has('age') ? Input::get('age') : 'any';
     $ethnicity = Input::has('ethnicity') ? Input::get('ethnicity') : 'any';
     $number_people = Input::has('number_people') ? Input::get('number_people') : 'any';
     $color = Input::has('color') ? Input::get('color') : '';
     $images = VIImage::select('images.short_name', 'images.id', 'images.name', 'images.main_color', DB::raw('count(lightbox_images.id) as count_favorite'))->leftJoin('lightbox_images', 'images.id', '=', 'lightbox_images.image_id')->groupBy('images.id')->with('downloads');
     switch ($sort_method) {
         case 'new':
             $images = $images->with('statistic')->orderBy('images.id', 'desc')->withType('main')->withOrientation($orientation);
             break;
         case 'relevant':
             $images = $images->with('statistic')->orderBy('images.id', 'desc')->withType('main')->withOrientation($orientation);
             break;
         case 'popular':
             $images = $images->join('statistic_image', 'statistic_image.image_id', '=', 'images.id')->with('statistic')->orderBy('view', 'desc')->orderBy('download', 'desc')->withType('main')->withOrientation($orientation);
             break;
         case 'undiscovered':
             $images = $images->join('statistic_image', 'statistic_image.image_id', '=', 'images.id')->with('statistic')->orderBy('view', 'asc')->orderBy('download', 'asc')->withType('main')->withOrientation($orientation);
             break;
         default:
             $images = $images->with('statistic')->orderBy('images.id', 'desc')->withType('main')->withOrientation($orientation);
             break;
     }
     if ($search_type == 'search' && $keyword != '') {
         $images = $images->search($keyword);
     }
     if ($exclude_keyword != '') {
         $images = $images->notSearchKeyWords($exclude_keyword);
     }
     if ($exclude_people) {
         $images = $images->where('number_people', '=', 0);
     }
     if ($include_people) {
         if ($gender != 'any') {
             $images = $images->where('gender', '=', $gender);
         }
         if ($age != 'any') {
             $age = explode('-', $age);
             $from = intval($age[0]);
             $to = intval($age[1]);
             $images = $images->where('age_from', '<=', $to)->where('age_to', '>=', $from);
         }
         if ($ethnicity != 'any') {
             $images = $images->where('ethnicity', '=', $ethnicity);
         }
         if ($number_people != 'any') {
             if ($number_people < 4) {
                 $images = $images->where('number_people', '=', $number_people);
             } else {
                 $images = $images->where('number_people', '>=', $number_people);
             }
         }
     }
     if (!(Input::has('editorial') && Input::has('non_editorial'))) {
         if (Input::has('editorial')) {
             $images = $images->where('editorial', '=', 1);
         }
         if (Input::has('non_editorial')) {
             $images = $images->where('editorial', '=', 0);
         }
     }
     if ($type != 0) {
         $images = $images->where('type_id', '=', $type);
     }
     if ($category != 0) {
         $images = $images->join('images_categories', 'images_categories.image_id', '=', 'images.id')->where('images_categories.category_id', '=', $category);
     }
     $total_image = $images->count();
     $images = $images->get()->toArray();
     $images = $this->searchColorFromArray($color, $images);
     $total_image = count($images);
     $images = array_slice($images, $skip, $take);
     //pr(DB::getQueryLog());die;
     $total_page = ceil($total_image / $take);
     //for recently searched images
     if ((trim($keyword_searched) != '' || $short_name != '') && count($images) > 0) {
         if ($keyword_searched == '') {
             $keyword_searched = str_replace('-', ' ', $short_name);
         }
         if (Auth::user()->check()) {
             BackgroundProcess::actionSearch(['type' => 'recently-search', 'keyword' => $keyword_searched, 'image_id' => $images[0]['id'], 'user_id' => Auth::user()->get()->id, 'query' => Request::server('REQUEST_URI')]);
         }
         BackgroundProcess::actionSearch(['type' => 'popular-search', 'keyword' => $keyword_searched, 'image_id' => $images[0]['id'], 'query' => Request::server('REQUEST_URI')]);
     }
     $lightboxes = array();
     if (Auth::user()->check()) {
         $lightboxes = Lightbox::where('user_id', '=', Auth::user()->get()->id)->get()->toArray();
         foreach ($lightboxes as $key => $lightbox) {
             $lightboxes[$key]['total'] = LightboxImages::where('lightbox_id', '=', $lightbox['id'])->count();
         }
     }
     $image_action_title = 'Like this item';
     if (Auth::user()->check()) {
         $image_action_title = 'Save to lightbox';
     }
     $arr_sort_method = array('new' => 'New', 'popular' => 'Popular', 'relevant' => 'Relevant', 'undiscovered' => 'Undiscovered');
     $arrReturn = array('images' => $images, 'total_page' => $total_page, "total_image" => $total_image, "sort_style" => $sort_style, "search_type" => $search_type, "categories" => $this->layout->categories, "lightboxes" => $lightboxes, "image_action_title" => $image_action_title, "arr_sort_method" => $arr_sort_method, "sort_method" => $sort_method, 'mod_download' => Configure::GetValueConfigByKey('mod_download'), 'mod_order' => Configure::GetValueConfigByKey('mod_download'));
     if (Request::ajax()) {
         return $arrReturn;
     }
     $this->layout->in_search = 1;
     $this->layout->content = View::make('frontend.search')->with($arrReturn);
 }
예제 #11
0
 public function updateAdmin()
 {
     if (Request::ajax() && Input::has('pk')) {
         $arrPost = Input::all();
         if ($arrPost['name'] == 'active') {
             $arrPost['value'] = (int) $arrPost['value'];
         }
         Admin::where('id', $arrPost['pk'])->update([$arrPost['name'] => $arrPost['value']]);
         return Response::json(['status' => 'ok']);
     }
     $prevURL = Request::header('referer');
     if (!Request::isMethod('post')) {
         return App::abort(404);
     }
     if (Input::has('id')) {
         $create = false;
         try {
             $admin = Admin::findorFail((int) Input::get('id'));
         } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             return App::abort(404);
         }
         $message = 'has been updated successful';
         unset($admin->password);
         if (Input::has('password')) {
             if (Input::has('password') && Input::has('password_confirmation')) {
                 $password = Input::get('password');
                 $admin->password = Input::get('password');
                 $admin->password_confirmation = Input::get('password_confirmation');
             }
         }
     } else {
         $create = true;
         $admin = new Admin();
         $message = 'has been created successful';
         $password = Input::get('password');
         $admin->password = $password;
         $admin->password_confirmation = Input::get('password_confirmation');
     }
     $admin->email = Input::get('email');
     $admin->first_name = Input::get('first_name');
     $admin->last_name = Input::get('last_name');
     $admin->active = Input::has('active') ? 1 : 0;
     $oldRole = 0;
     if (isset($admin->role_id) && $admin->role_id) {
         $oldRole = $admin->role_id;
     }
     $admin->role_id = Input::has('role_id') ? Input::get('role_id') : 0;
     if (Input::hasFile('image')) {
         $oldPath = $admin->image;
         $path = VIImage::upload(Input::file('image'), public_path('assets' . DS . 'images' . DS . 'admins'), 110, false);
         $path = str_replace(public_path() . DS, '', $path);
         $admin->image = str_replace(DS, '/', $path);
         if ($oldPath == $admin->image) {
             unset($oldPath);
         }
     }
     $pass = $admin->valid();
     if ($pass->passes()) {
         if (isset($admin->password_confirmation)) {
             unset($admin->password_confirmation);
         }
         if (isset($password)) {
             $admin->password = Hash::make($password);
         }
         $admin->save();
         if ($oldRole != $admin->role_id) {
             if ($oldRole) {
                 $admin->roles()->detach($oldRole);
             }
             if ($admin->role_id) {
                 $admin->roles()->attach($admin->role_id);
             }
         }
         if (isset($oldPath) && File::exists(public_path($oldPath))) {
             File::delete(public_path($oldPath));
         }
         if (Input::has('continue')) {
             if ($create) {
                 $prevURL = URL . '/admin/admins/edit-admin/' . $admin->id;
             }
             return Redirect::to($prevURL)->with('flash_success', "<b>{$admin->first_name} {$admin->last_name}</b> {$message}.");
         }
         return Redirect::to(URL . '/admin/admins')->with('flash_success', "<b>{$admin->first_name} {$admin->last_name}</b> {$message}.");
     }
     return Redirect::to($prevURL)->with('flash_error', $pass->messages()->all())->withInput();
 }
예제 #12
0
 public function updateQuickEdit()
 {
     $arrReturn = ['status' => 'error'];
     $id = (int) Input::get('pk');
     $name = Input::get('name');
     $value = Input::get('value');
     try {
         $type = Type::findorFail($id);
         if ($name == 'image') {
             if (Input::hasFile('image')) {
                 $file = Input::file('image');
                 $path = VIImage::upload(Input::file('image'), public_path('assets' . DS . 'images' . DS . 'types'), 1360, false);
                 $path = str_replace(public_path() . DS, '', $path);
                 $path = str_replace(DS, '/', $path);
                 if ($path) {
                     $oldImg = $type->image;
                     $type->image = $path;
                 }
             }
         } else {
             $value = Input::get('value');
             if ($name == 'active') {
                 $type->active = (int) $value;
             } else {
                 $type->{$name} = $value;
             }
         }
     } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
         return App::abort(404);
     }
     $pass = $type->valid();
     if ($pass->passes()) {
         $type->save();
         if (isset($oldImg) && File::exists(public_path($oldImg))) {
             File::delete(public_path($oldImg));
         }
         $arrReturn = ['status' => 'ok'];
         $arrReturn['message'] = $type->name . ' has been saved';
         $arrReturn['image'] = $type->image;
     } else {
         $arrReturn['message'] = '';
         $arrErr = $pass->messages()->all();
         foreach ($arrErr as $value) {
             $arrReturn['message'] .= "{$value}\n";
         }
     }
     return $arrReturn;
 }
예제 #13
0
 public function caculatePrice()
 {
     $sku = Input::has('sku') ? Input::get('sku') : 'ROL-663';
     $sizew = Input::has('sizew') ? Input::get('sizew') : 0;
     $sizeh = Input::has('sizeh') ? Input::get('sizeh') : 0;
     $quantity = Input::has('order_qty') ? Input::get('order_qty') : 1;
     $product = new VIImage();
     $product->sizew = $sizew;
     $product->sizeh = $sizeh;
     $groups = ProductOptionGroup::select('id', 'name', 'key')->get();
     foreach ($groups as $value) {
         $option_key = Input::has($value->key) ? Input::get($value->key) : '';
         if ($option_key != '') {
             //echo 'option_key: '.$option_key.'<br/>';
             $obj_option = ProductOption::where('key', $option_key)->first();
             $option = floatval($obj_option->name);
             if ($value->key == 'depth') {
                 $product->bleed = $option;
             } else {
                 $key = $value->key;
                 $product->{$key} = $option;
             }
         }
     }
     // echo '<pre>';
     // print_r($product);
     // echo '</pre>';
     // exit;
     $product->quantity = $quantity;
     $product->sku = $sku;
     $price = JTProduct::getPrice($product);
     if ($product->margin_up) {
         $biggerPrice = $price['sell_price'] * (1 + $product->margin_up / 100);
         $arrReturn = ['sell_price' => $price['sell_price'], 'bigger_price' => VIImage::viFormat($biggerPrice), 'amount' => $price['sub_total']];
     } else {
         $arrReturn = ['sell_price' => $price['sell_price'], 'amount' => $price['sub_total']];
     }
     if (Request::ajax()) {
         $arrReturn = ['status' => 'ok', 'message' => '', 'data' => $arrReturn];
         $response = Response::json($arrReturn);
         $response->header('Content-Type', 'application/json');
         return $response;
     }
     return false;
 }