Ejemplo n.º 1
0
 /**
  * Akismet automatic spam filter. See http://akismet.com
  *
  * @access private
  * @return void
  */
 private function runAkismet()
 {
     // Create the Akismet instance
     $akismet = new Akismet(Request::url(), $this->config->akismetKey);
     // Set the author info if the user is logged in
     if (Auth::check()) {
         $user = Auth::user();
         $akismet->setCommentAuthor($user->username);
         $akismet->setCommentAuthorEmail($user->email);
     }
     // Set the content to validate
     $akismet->setCommentContent($this->data);
     // Return the Akismet analysis
     return !$akismet->isCommentSpam();
 }
Ejemplo n.º 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;
 }