Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- |--------------------------------------------------------------------------
- | Routes File
- |--------------------------------------------------------------------------
- |
- | Here is where you will register all of the routes in an application.
- | It's a breeze. Simply tell Laravel the URIs it should respond to
- | and give it the controller to call when that URI is requested.
- |
- */
- Route::get('/', function () {
- return view('welcome');
- });
- /*
- |--------------------------------------------------------------------------
- | Application Routes
- |--------------------------------------------------------------------------
- |
- | This route group applies the "web" middleware group to every route
- | it contains. The "web" middleware group is defined in your HTTP
- | kernel and includes session state, CSRF protection, and more.
- |
- */
- Route::group(['middleware' => ['web']], function () {
- //
- });
- Route::group(['middleware' => 'web'], function () {
- Route::auth();
- Route::get('/', function () {
- return view('welcome');
- });
- Route::get('/home', 'HomeController@index');
- });
- Route::group(['middleware' => ['web', 'auth']], function () {
- Route::get('user/{username}/dashboard', 'UserController@dashboard');
- });
- /*
- |--------------------------------------------------------------------------
- | Profile Controller Routes
- |--------------------------------------------------------------------------
- |
- | You can add multiple routes with controllers which can help auth your
- | users
- */
- <?php
- namespace SCMHttpControllers;
- use View;
- use DB;
- use Settings;
- use uploadSettings;
- use Input;
- use Carbon;
- use User;
- use Files;
- use File;
- use LockFile;
- use Mail;
- use EmailTemplates;
- use EmailSettings;
- use Hash;
- use Redirect;
- use Response;
- use Request;
- use Auth;
- use Validator;
- use Session;
- class UserController extends Controller {
- protected $urlUsername;
- protected $userInfo;
- protected $userFiles;
- protected $isAdmin;
- protected $totalFilesSize;
- protected $adminPreviewMode;
- protected $userFilesPaginate;
- protected $topAds;
- protected $bottomAds;
- function __construct() {
- ## Get UserName From Url
- $this->urlUsername = Request::path();
- $this->urlUsername = explode("/",$this->urlUsername);
- $this->urlUsername = $this->urlUsername[true];
- ## Get User Personal Info
- $this->userInfo = User::where('username', '=', $this->urlUsername)->first();
- if(!$this->userInfo ){
- die('User Does Not Exist');
- }
- ## Get User Files Info
- $this->userFiles = Files::where('userID', '=', $this->userInfo['id'])
- ->get();
- ## If Admin Preview Mode = true, this Variable will return true
- $this->adminPreviewMode = ( defined('ADMIN_PREVIEW_MODE') ? true : false );
- ## Get User Type ( Admin - Normal )
- $this->isAdmin = ($this->userInfo->level === 'admin') ? true : false;
- ## Get Total Files Size
- $this->totalFilesSize = 0;
- foreach($this->userFiles as $file){
- $this->totalFilesSize += $file['fileSize'];
- }
- ## ads Data
- $this->topAds = DB::table('advertising')
- ->where('adsPage','=','profile')
- ->where('adsPosition','=','top')
- ->pluck('adsContent');
- $this->bottomAds = DB::table('advertising')
- ->where('adsPage','=','profile')
- ->where('adsPosition','=','bottom')
- ->pluck('adsContent');
- ## Function To Handle Files Size
- function size ( $type, $sub = null ){
- if($sub === null){
- $si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );
- $base = 1024;
- $class = min((int)log($type , $base) , count($si_prefix) - 1);
- return @$disk_free_space = sprintf('%1.2f' ,
- $type / pow($base,$class)) . ' ' . $si_prefix[$class] ;
- }
- }
- function convertFromBytes($from,$return){
- $number=$from;
- switch($return){
- case "MB":
- return round($number/pow(1024,2),2);
- case "GB":
- return $number/pow(1024,3);
- case "TB":
- return $number/pow(1024,4);
- case "PB":
- return $number/pow(1024,5);
- default:
- return $from;
- }
- }
- }
- /**
- * Display a listing of the resource.
- *
- * @return Response
- */
- public function dashboard() {
- // Check User Avilable Space
- $userFilesSize = $this->totalFilesSize;
- $userDiskSpace = uploadSettings::find(1)->userDiskSpace;
- $userAvailableDiskSpace = $userDiskSpace - $userFilesSize;
- if($userAvailableDiskSpace < uploadSettings::find(1)->maxFileSize){
- $MaxUploadSize = $userAvailableDiskSpace;
- }else{
- $MaxUploadSize = uploadSettings::find(1)->maxFileSize;
- }
- //
- $data = array(
- 'title' => 'Dashboard',
- 'nav' => 'dashboard',
- 'settings' => Settings::find(1),
- 'adminPreviewMode' => $this->adminPreviewMode,
- 'userName' => $this->userInfo['username'],
- 'isAdmin' => $this->isAdmin,
- 'topAds' => $this->topAds,
- 'bottomAds' => $this->bottomAds,
- 'totalFiles' => count($this->userFiles),
- 'totalFreeDiskSpace' => size($userAvailableDiskSpace),
- 'totalFilesSize' => size($this->totalFilesSize),
- 'totalDownloadedFiles' => DB::table('files')
- ->where('userID', '=', $this->userInfo['id'])->sum('fileDownloadCounter')
- );
- return View::make('user.dashboard')->with('data',$data);
- }
- public function upload() {
- // Check User Avilable Space
- $userFilesSize = $this->totalFilesSize;
- $userDiskSpace = uploadSettings::find(1)->userDiskSpace;
- $userAvailableDiskSpace = $userDiskSpace - $userFilesSize;
- if($userAvailableDiskSpace < uploadSettings::find(1)->maxFileSize){
- $MaxUploadSize = $userAvailableDiskSpace;
- }else{
- $MaxUploadSize = uploadSettings::find(1)->maxFileSize;
- }
- //
- $data = array(
- 'title' => 'Upload',
- 'nav' => 'upload',
- 'settings' => Settings::find(1),
- 'adminPreviewMode' => $this->adminPreviewMode,
- 'userName' => $this->userInfo['username'],
- 'isAdmin' => $this->isAdmin,
- 'topAds' => $this->topAds,
- 'bottomAds' => $this->bottomAds,
- // User Files Loop Data
- 'userFiles' =>$this->userFiles,
- 'MaxUploadSize' => convertFromBytes($MaxUploadSize,'MB')
- );
- return View::make('user.upload')->with('data',$data);
- }
- // This Function To Return Needed data To Files Table
- public function files() {
- ini_set('zlib.output_compression', 'Off');
- //
- $this->userFilesPaginate = Files::where('userID', '=', $this->userInfo['id'])
- ->orderBy('id','desc')
- ->paginate(20);
- $data = array(
- 'title' => 'My files',
- 'nav' => 'files',
- 'settings' => Settings::find(1),
- 'adminPreviewMode' => $this->adminPreviewMode,
- 'userName' => $this->userInfo['username'],
- 'isAdmin' => $this->isAdmin,
- 'topAds' => $this->topAds,
- 'bottomAds' => $this->bottomAds,
- // User Files Loop Data
- 'totalFiles' => count($this->userFiles),
- 'userFiles' => $this->userFilesPaginate
- );
- return View::make('user.files')->with('data',$data);
- }
- // This Function Used To Delete a File
- public function deleteFile() {
- $file = Files::find(Input::get('id'));
- // check If User Owen This File
- if($this->userInfo['id'] === $file->userID || $this->adminPreviewMode ){
- $fileName = $file->filePath;
- $fileName = explode("/",$fileName);
- $fileName = end($fileName);
- $fileExt = $file->fileExt;
- $filePath = public_path('../up-files/').$fileName.'.'.$fileExt;
- $delete = File::delete($filePath);
- if($delete){
- // Delete File From files table
- Files::find(Input::get('id'))->delete();
- // Delete File From lockedfiles table If Exists
- $isLock = LockFile::where('fileId','=',Input::get('id'))->delete();
- return Response::json('deleted success');
- }else{
- return Response::json('Delete Is Faild');
- }
- }else{
- return Response::json('You Cant Delete This File !');
- }
- }
- // This Function Used To Lock ( Set Password ) a File.
- public function lockFile() {
- $file = Files::find(Input::get('eid'));
- if($this->userInfo['id'] === $file->userID || $this->adminPreviewMode ){
- if($file) {
- $lockExists = LockFile::where('fileId','=',$file->id)->first();
- if( $lockExists && trim(Input::get('password')) === '' ){
- $lockExists->delete();
- return Response::json('unLock success');
- }elseif( $lockExists && trim(Input::get('password')) !== '' ){
- $lockExists->filePassword = Hash::make(Input::get('password'));
- $lockExists->save();
- return Response::json('Change Password success');
- }else if(!$lockExists && trim(Input::get('password')) !== ''){
- $lockedFiles = new LockFile;
- $lockedFiles->fileId = Input::get('eid');
- $lockedFiles->userID = $this->userInfo['id'];
- $lockedFiles->filePassword = Hash::make(Input::get('password'));
- if($lockedFiles->save()){
- // If Lock Success
- return Response::json('Lock success');
- }else{
- // If Lock Is Fail
- return Response::json('Lock Is Fails');
- }
- }
- }
- }else{
- // If File Not Exsits
- return Response::json('You Cant Lock This File !');
- }
- }
- // This Function Used To Show Pages index.
- public function pages() {
- // Check User Avilable Space
- $userFilesSize = $this->totalFilesSize;
- $userDiskSpace = uploadSettings::find(1)->userDiskSpace;
- $userAvailableDiskSpace = $userDiskSpace - $userFilesSize;
- if($userAvailableDiskSpace < uploadSettings::find(1)->maxFileSize){
- $MaxUploadSize = $userAvailableDiskSpace;
- }else{
- $MaxUploadSize = uploadSettings::find(1)->maxFileSize;
- }
- //
- $data = array(
- 'title' => 'Pages',
- 'nav' => 'pages',
- 'settings' => Settings::find(1),
- 'adminPreviewMode' => $this->adminPreviewMode,
- 'userName' => $this->userInfo['username'],
- 'isAdmin' => $this->isAdmin,
- 'topAds' => $this->topAds,
- 'bottomAds' => $this->bottomAds,
- 'pages' => DB::table('pages')
- ->orderBy('pageOrder','ASC')
- ->paginate(20)
- );
- return View::make('user.pages')->with('data',$data);
- }
- // This Function Used To Change User Settings.
- public function settings() {
- $data = array(
- 'title' => 'Setting',
- 'nav' => 'Settings',
- 'settings' => Settings::find(1),
- 'adminPreviewMode' => $this->adminPreviewMode,
- 'userName' => $this->userInfo['username'],
- 'userInfo' => $this->userInfo,
- 'isAdmin' => $this->isAdmin,
- 'topAds' => $this->topAds,
- 'bottomAds' => $this->bottomAds,
- );
- return View::make('user.settings')->with('data',$data);
- }
- public function changeSettings(){
- // Get Form Inputs
- $inputs = Input::all();
- $rules = array ();
- if($inputs['email'] !== $this->userInfo['email']){
- $rules['email'] = 'required|email|unique:users,email';
- }
- if($inputs['username'] !== $this->userInfo['username']){
- $rules['username'] = 'min:5|regex:/^[A-Za-z0-9_.-]+$/|max:15|unique:users,username';
- }
- if($inputs['password'] !== $this->userInfo['password']){
- $rules['password'] = 'min:6|confirmed';
- $rules['password_confirmation'] = '';
- }
- $validator = Validator::make($inputs,$rules);
- if( $validator->fails() ){
- return Redirect::back()
- ->withInput($inputs)
- ->withErrors($validator);
- }else {
- $user = User::find($this->userInfo['id']);
- $user->username = strtolower($inputs['username']);
- $user->email = $inputs['email'];
- if($inputs['password'] !== ''){
- $user->password = Hash::make( $inputs['password'] );
- }
- if( $user->save() ){
- Session::flash('Message','
- <div id="message-alert" class="alert alert-success alert-dismissible" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close">
- <span aria-hidden="true">×</span></button>
- <strong>Well!</strong>
- Your Action has been Successfully Updated.
- </div>
- ');
- return Redirect::intended('user/'.strtolower($inputs['username']).'/settings');
- }else{
- return Redirect::to('user/'.strtolower($inputs['username']).'/settings')
- ->withInput()
- ->WithErrors(' Please check your entry and try again..');
- }
- }
- }
- }
- {{ ($data['adminPreviewMode']) ?
- '<div class="alert alert-danger alert-dismissible" style="margin:0px;" role="alert">
- <button type="button" class="close" data-dismiss="alert"
- aria-label="Close"><span aria-hidden="true">×</span>
- </button>
- <strong><i class="fa fa-info-circle "></i>
- Take Notice!</strong> Dir Admin, This Is (Admingit Preview Mode), Not Your Personal Account ,
- <a style="color:#2C3E50;"
- href="'.url('user/'.Auth::user()->username).'">
- <b>Back To Your Account</b>
- </a>
- </div>'
- : '' }}
- @if(Session::has('message'))
- <div class="alert alert-success alert-dismissible" style="margin:0px;" role="alert">
- <button type="button" class="close" data-dismiss="alert"
- aria-label="Close"><span aria-hidden="true">×</span>
- </button>
- <strong><i class="fa fa-ok-circle "></i>
- Welcome</strong> {{ $data['userName'] }}, Thanks For Signup, best regards, {{ Settings::find(1)->sitename }} Team.
- </div>
- @endif
- <nav style="border-radius:0;" class="navbar navbar-default navbar-xs" role="navigation">
- <!-- Brand and toggle get grouped for better mobile display -->
- <div class="navbar-header">
- <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
- <span class="sr-only">Toggle navigation</span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </button>
- <a class="navbar-brand" href="{{ url('/') }}">
- {!! Html::image('assets/img/logo/logo.png') !!}
- </a>
- </div>
- <!-- Collect the nav links, forms, and other content for toggling -->
- <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
- <ul class="nav navbar-right top-nav">
- <li class="dropdown">
- <a href="" class="dropdown-toggle" data-toggle="dropdown">
- <i class="fa fa-user"></i>
- | {{ $data['userName'] }} <b class="caret"></b>
- </a>
- <ul class="dropdown-menu">
- {{ ($data['isAdmin']) ?
- '<li>
- <a href="'.URL().'/admin">
- <i class="fa fa-fw fa-tasks"></i> Admin Panel
- </a>
- </li>'
- : '' }}
- <li>
- <a href="{{ url('/user/'.$data['userName'].'/settings') }}">
- <i class="fa fa-fw fa-gear"></i> Settings
- </a>
- </li>
- <li>
- <a href="{{ URL('') }}/logout"><i class="fa fa-fw fa-sign-out"></i> Logout</a>
- </li>
- </ul>
- </li>
- </ul>
- </div><!-- /.navbar-collapse -->
- </nav>
- @show
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <meta name="description" content="">
- <meta name="author" content="">
- {!! Html::image('assets/img/logo/logo.png') !!}
- <title>{{ $data['title'].' | '.$data['settings']->sitename }}</title>
- <!-- Bootstrap Core CSS -->
- {!! Html::style('themes/z-Responsive/assets/css/bootstrap_2.min.css') !!}
- <!-- Font Awesome Fonts -->
- {!! Html::style('themes/z-Responsive/assets/font-awesome/css/font-awesome.min.css') !!}
- <!-- Custom CSS -->
- {!! Html::style('themes/z-Responsive/assets/css/sb-admin.css') !!}
- {!! Html::style('themes/z-Responsive/assets/css/social.css') !!}
- @yield('style')
- {!! Html::style('/themes/z-Responsive/assets/css/tabs.css') !!}
- {!! Html::style('themes/z-Responsive/assets/css/navbar.css') !!}
- <link href='https://fonts.googleapis.com/css?family=Ubuntu:400,300,500,700' rel='stylesheet'
- type='text/css'>
- <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
- <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
- <!--[if lt IE 9]>
- <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
- <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
- <![endif]-->
- </head>
- @include('layouts.--header')
- <div class="container">
- <!-- PAGE WRAPPER -->
- <div id="wrapper">
- @if( $data['topAds'] )
- <!-- Top Advertising Area -->
- <div class="col-md-12 ">
- <div class="ads-top">
- $data explode(" ",'topAds')
- </div>
- </div>
- <!-- /# TopAdvertising Area -->
- @endif
- <!-- Sidebar -->
- <section >
- <div class="container">
- <div class="row">
- <!-- <h2>Welcome to IGHALO!<sup>™</sup></h2>-->
- <div class="board-inner">
- <ul class="nav nav-tabs" id="myTab">
- <li {{ ($data['nav'] === 'dashboard') ? 'class="active"' : '' }}>
- <a href="{{ url('') }}" title="Dashboard">
- <span class="round-tabs one">
- <i class="fa fa-tachometer fa-stack-1x "></i>
- </span>
- </a>
- </li>
- <li {{ ($data['nav'] === 'upload') ? 'class="active"' : '' }}>
- <a href="{{ url('/user/'.$data['userName']).'/upload' }}" title="Upload">
- <span class="round-tabs two">
- <i class="fa fa-cloud-upload fa-stack-1x "></i>
- </span>
- </a>
- </li>
- <li {{ ($data['nav'] === 'files') ? 'class="active"' : '' }}>
- <a href="{{ url('/user/'.$data['userName']).'/files' }}" title="My Files">
- <span class="round-tabs three">
- <i class="fa fa-dropbox fa-stack-1x "></i>
- </span> </a>
- </li>
- <li {{ ($data['nav'] === 'send') ? 'class="active"' : '' }}>
- <a href="{{ url('/user/'.$data['userName']).'/send' }}" title="Send Files">
- <span class="round-tabs four">
- <i class="fa fa-paper-plane fa-stack-1x "></i>
- </span>
- </a>
- </li>
- @if(DB::table('pages')->count() )
- <li {{ ($data['nav'] === 'pages') ? 'class="active"' : '' }}>
- <a href="{{ url('/user/'.$data['userName']).'/pages' }}" title="Pages">
- <span class="round-tabs five">
- <i class="fa fa-files-o fa-stack-1x "></i>
- </span> </a>
- </li>
- @endif
- </ul>
- </div>
- <div class="tab-content">
- <!-- Tab Content -->
- @if($data['nav'] === 'dashboard' )
- @yield('dashboard')
- @endif
- @if($data['nav'] === 'upload' )
- @yield('upload')
- @endif
- @if($data['nav'] === 'files' )
- @yield('files')
- @endif
- @if($data['nav'] === 'send' )
- @yield('send')
- @endif
- @if($data['nav'] === 'pages' )
- @yield('pages')
- @endif
- @if($data['nav'] === 'settings' )
- @yield('settings')
- @endif
- <!-- /#Tab Content -->
- <div class="clearfix"></div>
- </div>
- </div>
- </div>
- </section>
- @if( Social::find(1) )
- <div id='social-sidebar'><!-- SOCIAL Media SIDEBAR -->
- <ul>
- @if( Social::find(1)->twitterLink !== '' )
- <li>
- <a class='entypo-twitter' href='{{ Social::find(1)->twitterLink }}' target='_blank'>
- <i class="fa fa-twitter "></i>
- <span>Twitter</span>
- </a>
- </li>
- @endif
- @if(Social::find(1)->facebookLink !== '')
- <li>
- <a class='entypo-facebook' href='{{ Social::find(1)->facebookLink }}' target='_blank'>
- <i class="fa fa-facebook "></i>
- <span>facebook</span>
- </a>
- </li>
- @endif
- @if(Social::find(1)->googlePlusLink !== '')
- <li>
- <a class='entypo-gplus' href='{{ Social::find(1)->googlePlusLink }}' target='_blank'>
- <i class="fa fa-google-plus "></i>
- <span>google+</span>
- </a>
- </li>
- @endif
- </ul>
- </div> <!-- /#SOCIAL Media SIDEBAR -->
- @endif
- <!-- jQuery -->
- {!! Html::script('themes/z-Responsive/assets/js/jquery-1.11.3.min.js') !!}
- <!-- Bootstrap Core JavaScript -->
- {!! Html::script('themes/z-Responsive/assets/js/bootstrap.min.js') !!}
- @yield('javascript')
- @include('layouts.--footer')
- <script language="javascript">
- </script>
- @if( $data['bottomAds'] )
- <!-- bottom Advertising Area -->
- <div class="col-md-12">
- <div class="ads-bottom">
- $data explode(" ",'bottomAds')
- </div>
- </div>
- <!-- /# bottom Advertising Area -->
- @endif
- <!-- /# End page-content-wrapper -->
- </div>
- <!-- /#wrapper -->
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement