Example #1
0
 /**
  * Show Downloads
  */
 public function getDownloads($paginateItems = 50)
 {
     $items = $this->query()->paginate($paginateItems);
     $items['regrouped'] = $this->regroupByName($items);
     $items['index'] = array_flip(array_keys($items['regrouped']));
     app('veer')->loadedComponents['temporary'] = \Veer\Models\Download::where('original', '=', 0)->count();
     app('veer')->loadedComponents['counted'] = \Veer\Models\Download::count(\Illuminate\Support\Facades\DB::raw('DISTINCT fname'));
     return $items;
 }
Example #2
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function download($lnk = null)
 {
     $reRouting = false;
     if (\Session::has('downloadlink')) {
         if (\Session::get('downloadlink', null) == $lnk) {
             $lnk = \Session::get('downloadlinkR', null);
             $reRouting = true;
             \Session::forget('downloadlink');
         }
     }
     $denyDownload = true;
     $checkLink = \Veer\Models\Download::where('secret', '=', $lnk)->first();
     if (is_object($checkLink)) {
         if ($checkLink->expires == false) {
             $denyDownload = false;
         } else {
             $expired_times = false;
             $expired_day = false;
             if ($checkLink->expiration_times > 0 && $checkLink->downloads >= $checkLink->expiration_times) {
                 $expired_times = true;
             }
             if ($checkLink->expiration_day > \Carbon\Carbon::create(2000) && now() > $checkLink->expiration_day) {
                 $expired_day = true;
             }
             if ($expired_times == false && $expired_day == false) {
                 $denyDownload = false;
             }
         }
     }
     if ($denyDownload == true) {
         return Redirect::route('index');
     } else {
         if ($reRouting == true) {
             $checkLink->increment('downloads');
             return $this->downloadingLocalOrCloudFiles($checkLink->fname);
         }
         $newLink = "sessionLink" . str_random(64);
         \Session::put('downloadlink', $newLink);
         \Session::put('downloadlinkR', $lnk);
         return Redirect::route('download.link', $newLink);
     }
 }
Example #3
0
 /**
  * Delete file
  * 
  */
 protected function deleteFile($id)
 {
     $f = \Veer\Models\Download::find($id);
     if (!is_object($f)) {
         return false;
     }
     $allCopies = \Veer\Models\Download::where('fname', '=', $f->fname)->get();
     if (count($allCopies) <= 1) {
         // last one
         $this->deletingLocalOrCloudFiles('files', $f->fname, config("veer.downloads_path"), storage_path() . '/app/');
     }
     $f->delete();
     return true;
 }
Example #4
0
 /**
  * Detach from Entity.
  * 
  * @helper Model detach|update
  * @param string $type
  * @param mixed $id
  * @param boolean $strict
  * @return \Veer\Services\Administration\Elements\Entity
  */
 public function detach($type, $id = null, $strict = false)
 {
     $relation = $this->relationAliases($type);
     if ($this->isAllowedRelation($relation)) {
         if ($relation == 'files') {
             if (empty($id) && !$strict) {
                 \Veer\Models\Download::where('elements_id', '=', $this->id)->where('elements_type', '=', $this->className)->update(['elements_id' => 0, 'elements_type' => '']);
             } elseif (!empty($id)) {
                 \Veer\Models\Download::where('id', '=', $id)->update(['elements_id' => 0, 'elements_type' => '']);
             }
         } else {
             if (empty($id) && !$strict) {
                 $this->entity->{$relation}()->detach();
             } elseif (!empty($id)) {
                 $this->entity->{$relation}()->detach($id);
             }
         }
         event('veer.message.center', trans('veeradmin.' . $this->type . '.' . $relation . '.detach'));
     }
     return $this;
 }
Example #5
0
 public function mklink($id = null, $data = null, $returnId = false)
 {
     if (empty($id) && !isset($this->entity->id)) {
         return $this;
     } elseif (empty($id)) {
         $id = $this->entity->id;
     }
     $data = (array) $data;
     $data += ['times' => 0, 'expiration_day' => null, 'link_name' => null];
     $file = is_object($this->entity) ? $this->entity : \Veer\Models\Download::find($id);
     if (!is_object($file)) {
         return $this;
     }
     $new = $file->replicate();
     $new->secret = empty($data['link_name']) ? bcrypt(str_random(100) . date("Ymd", time())) : $data['link_name'];
     // @todo test
     if ($data['times'] > 0 || !empty($data['expiration_day'])) {
         $new->expires = 1;
         $new->expiration_times = $data['times'];
         if (!empty($data['expiration_day'])) {
             $new->expiration_day = \Carbon\Carbon::parse(strtotime($data['expiration_day']));
         }
     }
     $new->original = 0;
     $new->save();
     event('veer.message.center', trans('veeradmin.file.download'));
     return $returnId ? $new->id : $this;
 }