Beispiel #1
0
 /**
  * Run cron tasks. This is a simple implementation without
  * any bells and whistles.
  *
  * @static
  * @return void
  */
 public static function run()
 {
     // We run the cron tasks once every 5 minutes
     Cache::remember('site.cron', 5, function () {
         $expired = array();
         $storage = storage_path();
         // Retrieve expired pastes
         $pastes = Paste::where('expire', '>', 0)->where('expire', '<', time())->get();
         if ($pastes->count() > 0) {
             // Check if the comments table exists
             $hasComments = Schema::hasTable('comments');
             // Build the expired pastes array
             // Also delete associated comments and attachments
             foreach ($pastes as $paste) {
                 $expired[] = $paste->urlkey;
                 $paste->comments()->delete();
                 $attachment = "{$storage}/uploads/{$paste->urlkey}";
                 if ($paste->attachment and File::exists($attachment)) {
                     File::delete($attachment);
                 }
             }
             // Remove expired pastes
             Paste::whereIn('urlkey', $expired)->delete();
             // Remove expired revisions
             Revision::whereIn('urlkey', $expired)->delete();
         }
         // Delete paste statistics older than configured age
         $ttl = Site::config('general')->statsTTL;
         $date = date('Y-m-d', strtotime($ttl));
         Statistics::where('date', '<', $date)->delete();
         // Crun run successfully
         return TRUE;
     });
 }
Beispiel #2
0
 /**
  * Generates a navigation menu
  *
  * @access public
  * @param  string  $menu
  * @return string
  */
 public static function menu($menu)
 {
     // Current path - will be used to highlight menu item
     $path = Request::path();
     // Current user ID for role based menus
     $user = Auth::check() ? Auth::user()->id : 0;
     // Get current project name
     $project = System::project();
     // Grab and parse all the menus
     $group = Config::get("menus.{$menu}");
     // The cache key is not only menu and path specific but also
     // unique for a user and a project
     $cacheKey = "site.menu.{$menu}.{$path}.{$user}.{$project}";
     // Build the menu items. Items are cached for 60 minutes
     $output = Cache::remember($cacheKey, 60, function () use($path, $user, $group) {
         $output = NULL;
         foreach ($group as $key => $item) {
             if (!str_contains($key, '_')) {
                 $label = Lang::get($item['label']);
                 $current = FALSE;
                 // Check if visibility of the item is bound
                 if (isset($item['visible'])) {
                     $visible = FALSE;
                     $bindings = preg_split('/\\||,/', $item['visible']);
                     // Iterate through each binding
                     foreach ($bindings as $binding) {
                         $components = explode('.', $binding);
                         // Check for the invert flag
                         if (starts_with($components[0], '!')) {
                             $components[0] = substr($components[0], 1);
                             $invert = TRUE;
                         } else {
                             $invert = FALSE;
                         }
                         // Check for a value
                         if (str_contains($components[1], '=')) {
                             $expression = explode('=', $components[1]);
                             $components[1] = $expression[0];
                             $value = $expression[1];
                         } else {
                             $value = TRUE;
                         }
                         // Get the binding flags
                         switch ($components[0]) {
                             case 'role':
                                 $flags = Auth::roles();
                                 break;
                             case 'config':
                                 $flags = Site::config('general');
                                 break;
                             default:
                                 $flags = NULL;
                                 break;
                         }
                         // Do not parse the menu item if the flag does not
                         // evaluate to true
                         if (!is_null($flags)) {
                             $visible = ($visible or $flags->{$components}[1] == $value xor $invert);
                         }
                     }
                     // Set the visibility of the item
                     if (!$visible) {
                         continue;
                     }
                 }
                 // Determine whether this is the active link
                 if ($group['_exact'] and $key === $path) {
                     $current = TRUE;
                 } else {
                     if (!$group['_exact'] and starts_with($path, $key)) {
                         $current = TRUE;
                     }
                 }
                 // Highlight the active item
                 if ($current) {
                     $active = 'class="active"';
                     $href = '';
                 } else {
                     $active = '';
                     $href = 'href="' . url($key) . '"';
                 }
                 // Set the entry icon
                 if (isset($item['icon'])) {
                     $icon = View::make('common/icon', array('icon' => $item['icon']), FALSE);
                 } else {
                     $icon = NULL;
                 }
                 // Generate the item markup
                 $output .= "<li {$active}><a {$href}>{$icon} {$label}</a></li>";
             }
         }
         // Add login/logout link if menu is set for that
         if ($group['_showLogin']) {
             if ($user) {
                 $label = Lang::get('global.logout');
                 $href = 'href="' . url('user/logout') . '"';
             } else {
                 $label = Lang::get('global.login');
                 $href = 'href="' . url('user/login') . '"';
             }
             // Are we on the login screen?
             $active = $path == 'user/login' ? 'class="active"' : '';
             $icon = View::make('common/icon', array('icon' => 'user'), FALSE);
             // Generate the markup
             $output .= "<li {$active}><a {$href}>{$icon} {$label}</a></li>";
         }
         return $output;
     });
     return $output;
 }
 /**
  * Parses and outputs highlighted code
  *
  * @param  string  $key
  * @param  string  $code
  * @param  string  $language
  * @return string
  */
 public function parse($key, $code, $language)
 {
     $geshi = $this->geshi;
     $parsed = Cache::remember("site.code.{$key}", 45000, function () use($geshi, $code, $language) {
         $geshi->set_source($code);
         $geshi->set_language($language);
         return @$geshi->parse_code($code);
     });
     return $parsed ?: $code;
 }