Example #1
0
<?php

return array('1800' => array('expire_30mins', TRUE), '21600' => array('expire_6hrs', TRUE), '86400' => array('expire_1day', TRUE), '604800' => array('expire_1week', TRUE), '2592000' => array('expire_1month', TRUE), '31536000' => array('expire_1year', TRUE), '0' => array('expire_forever', Site::config('general')->noExpire or Auth::roles()->admin));
 /**
  * Displays the default view page
  *
  * @access public
  * @param  string  $urlkey
  * @param  string  $hash
  * @param  string  $action
  * @param  string  $extra
  * @return \Illuminate\Support\Facades\View|\Illuminate\Support\Facades\Redirect|null
  */
 public function getPaste($urlkey, $hash = '', $action = '', $extra = '')
 {
     $site = Site::config('general');
     $paste = Paste::where('urlkey', $urlkey)->first();
     // Paste was not found
     if (is_null($paste)) {
         App::abort(404);
         // Not found
     }
     // Check if the logged in user is the owner of the paste
     $owner = Auth::access($paste->author_id);
     // We do not make password prompt mandatory for owners
     if (!$owner) {
         // Require hash to be passed for private pastes
         if ($paste->private and $paste->hash != $hash) {
             App::abort(401);
             // Unauthorized
         }
         // Check if paste is password protected and user hasn't entered
         // the password yet
         if ($paste->password and !Session::has('paste.password' . $paste->id)) {
             return View::make('site/password', array());
         }
     }
     // Increment the hit counter
     if (!Session::has('paste.viewed' . $paste->id)) {
         $paste->hits++;
         $paste->save();
         Session::put('paste.viewed' . $paste->id, TRUE);
     }
     // Let's do some action!
     switch ($action) {
         case 'delete':
             if (empty($extra)) {
                 // Delete the paste if the user has access
                 if ($site->allowPasteDel and $owner) {
                     Revision::where('urlkey', $paste->urlkey)->delete();
                     $paste->comments()->delete();
                     $attachment = storage_path() . "/uploads/{$paste->urlkey}";
                     if ($paste->attachment and File::exists($attachment)) {
                         File::delete($attachment);
                     }
                     $paste->delete();
                     Session::flash('messages.success', Lang::get('global.paste_deleted'));
                     return Redirect::to('/');
                 } else {
                     App::abort(401);
                     // Unauthorized
                 }
             } else {
                 if (is_numeric($extra)) {
                     $comment = Comment::findOrFail($extra);
                     // Delete the comment if the user has access
                     if ($owner or Auth::user()->username == $comment->author) {
                         $comment->delete();
                     } else {
                         App::abort(401);
                         // Unauthorized
                     }
                 }
             }
             return Redirect::to(URL::previous());
         case 'raw':
             $response = Response::make($paste->data);
             $response->header('Content-Type', 'text/plain');
             return $response;
         case 'toggle':
             if ($owner) {
                 Revision::where('urlkey', $paste->urlkey)->delete();
                 $paste->private = $paste->private ? 0 : 1;
                 $paste->password = '';
                 $paste->save();
             }
             return Redirect::to(URL::previous());
         case 'flag':
             if ($site->flagPaste == 'all' or $site->flagPaste == 'user' and Auth::roles()->user) {
                 $paste->flagged = 1;
                 $paste->save();
                 Cache::forget('global.flags');
                 Session::flash('messages.success', Lang::get('global.paste_flagged'));
             } else {
                 App::abort(401);
                 // Unauthorized
             }
             return Redirect::to(URL::previous());
         case 'unflag':
             if (Auth::roles()->admin) {
                 $paste->flagged = 0;
                 $paste->save();
                 Cache::forget('global.flags');
                 Session::flash('messages.success', Lang::get('global.paste_unflagged'));
             } else {
                 App::abort(401);
                 // Unauthorized
             }
             return Redirect::to(URL::previous());
     }
     // Build the sharing subject for the paste
     $subject = sprintf(Lang::get('mail.share_subject'), $site->title, URL::current());
     // Build data for show paste page
     $data = array('paste' => $paste, 'revisions' => $paste->revisions, 'comments' => $paste->comments()->paginate($site->perPage), 'share' => 'mailto:?subject=' . urlencode($subject), 'attachment' => sprintf(Lang::get('show.download_attachment'), Lang::get('show.unknown')));
     // If paste has an attachment, get the file type
     if ($paste->attachment) {
         $pathToFile = storage_path() . "/uploads/{$paste->urlkey}";
         if (File::exists($pathToFile)) {
             $file = new Symfony\Component\HttpFoundation\File\File($pathToFile);
             $data['attachment'] = sprintf(Lang::get('show.download_attachment'), $file->getMimeType());
         }
     }
     // Display the show paste view
     return View::make('site/show', $data);
 }
Example #3
0
    if (Request::segment(1) != 'setup') {
        // Redirect to the installer
        if (!$installed) {
            Setup::start();
            return Redirect::to('setup/install');
        } else {
            if (Request::segment(2) != 'login') {
                if ($appVersion > $dbVersion) {
                    Setup::start();
                    return Redirect::to('setup/update');
                } else {
                    // Run Google Analytics visitor tracking
                    Service::analytics();
                    // Set global admin messages
                    View::globals();
                    // Run cron tasks
                    Cron::run();
                }
            }
        }
    } else {
        if (Request::segment(2) == 'update' and $dbVersion > 0 and Auth::roles()->guest) {
            App::abort(503);
            // Service unavailable
        } else {
            if ($installed and $appVersion == $dbVersion and !Session::has('setup.stage')) {
                return Redirect::to('/');
            }
        }
    }
});
 /**
  * Searches for a paste by its content
  *
  * @access public
  * @param  string  $term
  * @return \Illuminate\Support\Facades\View
  */
 public function getSearch()
 {
     $term = Input::get('q');
     $config = Site::config('general');
     // Initialize the antispam filters
     $antispam = Antispam::make('search', 'q');
     if ($config->pasteSearch and strlen($term) >= 5) {
         if ($antispam->passes() or Session::has('search.exempt')) {
             // Show all pastes to admins
             if (Auth::roles()->admin) {
                 $query = Paste::query();
             } else {
                 $query = Paste::where('private', '<>', 1);
             }
             // Append the search term
             $query = $query->where('data', 'like', "%{$term}%");
             // Filter by project
             if (!empty($this->project)) {
                 $query = $query->where('project', $this->project);
             }
             // Get number of results to show per page
             $perPage = $config->perPage;
             // Query the search results
             $pastes = $query->orderBy('id', 'desc')->paginate($perPage);
             // Append the search term to pagination URLs
             $pastes->appends('q', $term);
             // We will not run antispam if it passed once and there are
             // multiple pages. But we exempt it only for the next request.
             Session::flash('search.exempt', $perPage > $pastes->count());
             return $this->getList($pastes, TRUE);
         } else {
             Session::flash('messages.error', $antispam->message());
         }
     }
     return Redirect::to('all')->withInput();
 }
Example #5
0
 /**
  * Check if the paste cannot expire
  *
  * @static
  * @return bool
  */
 public static function noExpire()
 {
     $noExpire = FALSE;
     // Admins can always create permanent pastes
     if (Auth::roles()->admin) {
         $noExpire = TRUE;
     }
     // Check if only registered users can create permanent pastes
     if (Site::config('general')->noExpire == 'user' and Auth::roles()->user) {
         $noExpire = TRUE;
     }
     // Check if everyone can create permanent pastes
     if (Site::config('general')->noExpire == 'all') {
         $noExpire = TRUE;
     }
     return $noExpire;
 }
Example #6
0
|
*/
Blade::extend(function ($value) {
    return preg_replace('/\\{\\?(.+)\\?\\}/', '<?php ${1} ?>', $value);
});
/*
|--------------------------------------------------------------------------
| Authenticated validator
|--------------------------------------------------------------------------
|
| This rule checks whether the site allows guest posts. If it does not,
| it throws an error asking the user to log in before posting.
|
*/
Validator::extend('auth', function ($attribute, $value, $parameters) {
    return !(Auth::roles()->guest and !Site::config('general')->guestPosts);
});
/*
|--------------------------------------------------------------------------
| Multibyte string length validator
|--------------------------------------------------------------------------
|
| This rule checks whether a specific string is longer than the maximum
| allowed multibyte length.
|
*/
Validator::extend('mbmax', function ($attribute, $value, $parameters) {
    if ($parameters[0] > 0) {
        return mb_strlen($value, '8bit') <= $parameters[0];
    }
    return TRUE;