public function getArtist($name)
 {
     $artist = Artist::where('permalink', '=', $name);
     $artist = $artist->first();
     $inside_image = Media::find($artist->inside_image);
     return View::make('artists.single')->with('artist', $artist)->with('inside_image', $inside_image);
 }
示例#2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     $validation = Validator::make($input, Comment::$rules);
     if ($validation->passes()) {
         $last_comment = Comment::where('user_id', '=', Auth::user()->id)->orderBy('created_at', 'desc')->first();
         $current_date = new DateTime(date("Y-m-d H:i:s"));
         if (empty($last_comment)) {
             $interval = 5;
         } else {
             $interval = $current_date->diff($last_comment->created_at);
             $interval = intval($interval->format('%i'));
         }
         /*if($interval >= 3){*/
         $this->add_daily_comment_points();
         $comment = new Comment();
         $comment->media_id = $input['media_id'];
         $comment->comment = htmlspecialchars($input['comment']);
         $comment->user_id = Auth::user()->id;
         //echo $comment;
         if ($comment->save()) {
             $notification = new Notification();
             $media = Media::find($comment->media_id);
             $notification->user_id = $media->user_id;
             $user_comment = $comment->user()->username;
             $notification->url_comment = URL::to('media') . '/' . $media->slug;
             if ($media->user_id == Auth::user()->id) {
                 $notification->is_read = 1;
             } else {
                 $notification->is_read = 0;
                 $notification->content = $user_comment . " comments in " . '" ' . $comment->media()->title . ' " your';
             }
             $notification->save();
         }
         echo $comment;
         /*} else {
         			echo 0;
         		}*/
     } else {
         echo 0;
     }
 }
 public function postRemoveMedia($id)
 {
     $media = Media::find($id);
     $owner = $media->mediable_id;
     $ownerType = $media->mediable_type;
     $owner = $ownerType::find($owner);
     $isAjax = Request::ajax();
     // Disasociate this from its parent exhibit
     foreach ($owner->media as $key => $image) {
         if ($image->id == $id) {
             $owner->media[$key]->update(['mediable_id' => 0, 'mediable_type' => null]);
             $mediasave = $owner->media[$key]->save();
         }
     }
     $mediasave = $mediasave ? true : false;
     if ($isAjax) {
         return json_encode($mediasave);
     } else {
         return Redirect::back()->with('status', 'alert-danger')->with('global', 'Something went wrong!');
     }
 }
示例#4
0
 public function postRemoveMedia($id)
 {
     $media = Media::find($id);
     $media = new Media();
     $media->delete();
     $media = Media::find($id);
     $owner = $media->mediable_id;
     $ownerType = $media->mediable_type;
     $owner = $ownerType::find($owner);
     $isAjax = Request::ajax();
     // Disasociate this from its parent exhibit
     foreach ($owner->media as $key => $image) {
         if ($image->id == $id) {
             $owner->media[$key]->update(['mediable_id' => 0, 'mediable_type' => null]);
             $mediasave = $owner->media[$key]->save();
         }
     }
     if ($mediasave == true) {
         $outcome = $owner->update(array('cover_image' => ''));
     }
     return json_encode($outcome);
 }
示例#5
0
    return $view;
}), 'GET /admin/resetpw/(:num?)' => array('before' => 'auth', function ($userid = NULL) {
    $user = User::find($userid);
    $newpw = Str::random(8);
    $to = $user->email;
    $subject = 'Password Reset';
    $message = $newpw;
    $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
    mail($to, $subject, $message, $headers);
    $user->password = Hash::make($newpw);
    $user->save();
    return Redirect::to('admin/users');
}), 'POST /admin/editmedia' => array('before' => 'auth', function () {
    $media_id = Input::get('mediaid');
    $page_id = Input::get('page');
    $media = Media::find($media_id);
    $media->caption = Input::get('caption');
    $media->meta = Input::get('meta');
    $media->size = Input::get('size');
    $media->save();
    DB::table('pages_media')->where('media_id', '=', $media_id)->delete();
    DB::table('pages_media')->insert(array('media_id' => $media_id, 'page_id' => $page_id));
    return Redirect::to('admin/media');
}), 'POST /admin/edituser' => array('before' => 'auth', function () {
    $user_id = Input::get('userid');
    $rules = array('firstname' => 'required|max:140', 'lastname' => 'required|max:140', 'email' => 'required|max:50', 'role' => 'required');
    $validator = Validator::make(Input::get(), $rules);
    if (!$validator->valid()) {
        return Redirect::to('admin/edituser/' . $user_id)->with('errors', $validator->errors)->with_input();
    }
    $user = User::find($user_id);
示例#6
0
function check($id, $file, $user_ip, $auth_ano = false)
{
    $status = false;
    $id_user = $id;
    $id_file = $file;
    try {
        if ($auth_ano) {
            date_default_timezone_set('Pacific/Auckland');
            $ip_date = date("Y-m-d");
            $media = Media::find($id_file);
            $size_f = $media->size;
            $ip_bytes = DataIp::where('ip', '=', $user_ip)->where('date', '=', $ip_date)->sum('bytes');
            if ($size_f < 4294967296 - $ip_bytes) {
                $status = true;
            } else {
                $status = false;
            }
        } else {
            $user = User::where('id', '=', $id_user)->first();
            if (count($user) != 0) {
                $useage = $user->used_bytes;
                $media = Media::find($id_file);
                if (count($media) != 0) {
                    date_default_timezone_set('Pacific/Auckland');
                    $todays_date = date("Y-m-d H:i:s");
                    $today = strtotime($todays_date);
                    $exp_date = $user->prem_valid;
                    $expiration_date = strtotime($exp_date);
                    if ($expiration_date > $today) {
                        $active = true;
                    } else {
                        $active = false;
                    }
                    if ($active) {
                        if ($useage < $user->avl_bytes) {
                            $size_f = $media->size;
                            if ($size_f < $user->avl_bytes - $useage) {
                                $status = true;
                            }
                        }
                    } else {
                        $date = DateTime::createFromFormat('Y-m-d H:i:s', date('Y-m-d H:i:s'));
                        $date->modify('+1 day');
                        $date = $date->format('Y-m-d H:i:s');
                        if ($user->category_id != 1) {
                            $user->last_prem = date("Y-m-d H:i:s");
                        }
                        $user->category_id = 1;
                        $user->prem_valid = $date;
                        $user->used_bytes = 0;
                        $user->avl_bytes = 1073741824;
                        $user->save();
                        $useage = $user->used_bytes;
                        if ($useage < $user->avl_bytes) {
                            $size_f = $media->size;
                            if ($size_f < $user->avl_bytes - $useage) {
                                $status = true;
                            }
                        }
                    }
                    if ($user->category_id == 1) {
                        date_default_timezone_set('Pacific/Auckland');
                        $ip_date = date("Y-m-d");
                        $size_f = $media->size;
                        $ip_bytes = DataIp::where('ip', '=', $user_ip)->where('date', '=', $ip_date)->sum('bytes');
                        if ($size_f < 1073741824 - $ip_bytes) {
                            $status = true;
                        } else {
                            $status = false;
                        }
                    }
                }
            }
        }
    } catch (Exception $e) {
        echo 'Message: ' . $e->getMessage();
        $report = new UserFlag();
        $report->type = "data useage check auth";
        $report->res = $e->getMessage();
        $report->save();
    }
    return $status;
}
示例#7
0
 public function toggle_active($id)
 {
     $media = Media::find($id);
     if ($media->active == 1) {
         $media->active = 0;
     } else {
         $media->active = 1;
     }
     $media->save();
 }
示例#8
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function delete($id)
 {
     $media = Media::find($id);
     if ($media->user_id == Auth::user()->id || Auth::user()->admin == 1) {
         $media_flags = MediaFlag::where('media_id', '=', $id)->get();
         foreach ($media_flags as $media_flag) {
             $media_flag->delete();
         }
         $media_likes = MediaLike::where('media_id', '=', $id)->get();
         foreach ($media_likes as $media_like) {
             $media_like->delete();
         }
         $comments = Comment::where('media_id', '=', $id)->get();
         foreach ($comments as $comment) {
             $comment_votes = CommentVote::where('comment_id', '=', $comment->id)->get();
             foreach ($comment_votes as $comment_vote) {
                 $comment_vote->delete();
             }
             $comment_flags = CommentFlag::where('comment_id', '=', $comment->id)->get();
             foreach ($comment_flags as $comment_flag) {
                 $comment_flag->delete();
             }
             $comment->delete();
         }
         // if the media type is a gif we need to remove the animation file too.
         if (strpos($media->pic_url, '.gif') > 0) {
             if (file_exists(Config::get('site.uploads_dir') . 'images/' . str_replace(".gif", "-animation.gif", $media->pic_url))) {
                 unlink(Config::get('site.uploads_dir') . 'images/' . str_replace(".gif", "-animation.gif", $media->pic_url));
             }
         }
         // remove the image
         if (file_exists(Config::get('site.uploads_dir') . 'images/' . $media->pic_url)) {
             unlink(Config::get('site.uploads_dir') . 'images/' . $media->pic_url);
         }
         $media->delete();
     }
     return Redirect::to('admin?section=media')->with(array('note' => Lang::get('lang.delete_success'), 'note_type' => 'success'));
 }
示例#9
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function delete($id)
 {
     $media = Media::find($id);
     if ($media->user_id == Auth::user()->id || Auth::user()->admin == 1) {
         $media_flags = MediaFlag::where('media_id', '=', $id)->get();
         foreach ($media_flags as $media_flag) {
             $media_flag->delete();
         }
         $media_likes = MediaLike::where('media_id', '=', $id)->get();
         foreach ($media_likes as $media_like) {
             $media_like->delete();
         }
         $comments = Comment::where('media_id', '=', $id)->get();
         foreach ($comments as $comment) {
             $comment_votes = CommentVote::where('comment_id', '=', $comment->id)->get();
             foreach ($comment_votes as $comment_vote) {
                 $comment_vote->delete();
             }
             $comment_flags = CommentFlag::where('comment_id', '=', $comment->id)->get();
             foreach ($comment_flags as $comment_flag) {
                 $comment_flag->delete();
             }
             $comment->delete();
         }
         $arrayPicUrl = explode("/", $media->pic_url);
         // if the media type is a gif we need to remove the animation file too.
         if (strpos($media->pic_url, '.gif') > 0) {
             \Cloudinary\Uploader::destroy(Constant::FOLDER_CLOUDINARY . '/' . $arrayPicUrl[0] . '/' . pathinfo(str_replace(".gif", "-animation.gif", $media->pic_url), PATHINFO_FILENAME));
         }
         // remove the image
         \Cloudinary\Uploader::destroy(Constant::FOLDER_CLOUDINARY . '/' . $arrayPicUrl[0] . '/' . pathinfo($media->pic_url, PATHINFO_FILENAME));
         $media->delete();
     }
     return Redirect::to('admin?section=media')->with(array('note' => Lang::get('lang.delete_success'), 'note_type' => 'success'));
 }
 public function postUpload($id)
 {
     $media = Media::find($id);
     if ($media == null) {
         die('{"OK": 0, "info": "Unable to find this media record in the database. It could have been deleted."}');
     }
     $media_tmp_folder = public_path() . '/assets/medias/tmp/' . $media->category_id . '/' . $id;
     $media_folder = public_path() . '/assets/medias/' . $media->category_id . '/' . $id;
     if (empty($_FILES) || $_FILES['file']['error']) {
         die('{"OK": 0, "info": "Failed to move uploaded file."}');
     }
     $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
     $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
     $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : $_FILES["file"]["name"];
     //$filePath = public_path() . '/assets/medias' . "/$fileName";
     $filePath = $media_tmp_folder . "/{$fileName}";
     // Create the directory
     if (!file_exists($media_tmp_folder)) {
         mkdir($media_tmp_folder, 0777, true);
     }
     // For Unit testing
     if ($fileName == 'foo113a.pdf') {
         die('{"OK": 1, "info": "Upload successful."}');
     }
     // Open temp file
     $out = @fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
     if ($out) {
         // Read binary input stream and append it to temp file
         $in = @fopen($_FILES['file']['tmp_name'], "rb");
         if ($in) {
             while ($buff = fread($in, 4096)) {
                 fwrite($out, $buff);
             }
         } else {
             die('{"OK": 0, "info": "Failed to open input stream."}');
         }
         @fclose($in);
         @fclose($out);
         @unlink($_FILES['file']['tmp_name']);
     } else {
         die('{"OK": 0, "info": "Failed to open output stream."}');
     }
     // Check if file has been uploaded
     if (!$chunks || $chunk == $chunks - 1) {
         // Strip the temp .part suffix off
         rename("{$filePath}.part", $filePath);
         // Get mime type of the file
         $file = new \Symfony\Component\HttpFoundation\File\File($filePath);
         $mime = $file->getMimeType();
         // Save the media link
         $media->path = $fileName;
         $media->mimetype = $mime;
         $media->save();
         // Delete old media
         $media->deleteMediaFolder($media_folder);
         // Create the directory
         if (!file_exists($media_folder)) {
             mkdir($media_folder, 0777, true);
         }
         \File::move($filePath, $media_folder . "/{$fileName}");
         // Delete tmp media
         $media->deleteMediaFolder($media_tmp_folder);
     }
     die('{"OK": 1, "info": "Upload successful."}');
 }
 /**
  * Display a single exhibit.
  */
 public function single($name)
 {
     $exhibit = Exhibit::where('permalink', '=', $name);
     $exhibit = $exhibit->first();
     $mediaIDs = json_decode($exhibit->media_ids);
     $assignedGroup = array();
     $imageGroup = array();
     if ($exhibit->count()) {
         // Get the order of media_ids and pass it in to assigned image group
         if (!is_null($mediaIDs)) {
             foreach ($mediaIDs as $mediaID) {
                 $media = Media::find($mediaID);
                 $imageGroup[] = $media;
             }
         }
         $assignedImageGroup = DB::table('media')->where('mediable_id', '=', $exhibit->id)->where('mediable_type', '=', 'Exhibit')->orderBy('updated_at', 'desc')->get();
         if (isset($assignedImageGroup) && !is_null($mediaIDs)) {
             foreach ($assignedImageGroup as $media) {
                 if (!in_array($media->id, $mediaIDs)) {
                     $assignedGroup[] = $media;
                 }
             }
         }
         if (isset($exhibit->video)) {
             $videoEmbed = array();
             $re = "/(?:http:\\/\\/|https:\\/\\/)(?:www.)?(vimeo|youtube).com\\/(?:watch\\?v=)?(.*?)(?:\\z|&)/";
             preg_match($re, $exhibit->video, $out);
             if (isset($out[1])) {
                 $videoEmbed['source'] = $out[1];
                 $videoEmbed['id'] = $out[2];
             }
         }
         return View::make('exhibits.show-single')->with('videoEmbed', $videoEmbed)->with('exhibit', $exhibit)->with('imageGroup', $imageGroup)->with('assignedGroup', $assignedGroup)->with('page_title', 'Add Exhibits');
     }
     return App::abort(404);
 }