/** * Processes antispam filters * * @access public * @return bool */ public function passes() { if (!empty($this->data)) { // Load the antispam configuration // This is not same as the site configuration $antispam = Config::get('antispam'); // We get the enabled services // Then we iterate through each of them to see if there is a // handler available for the service. If found, we run the handler $services = preg_split('/\\||,/', $this->config->services); // Immutable services are always executed even if they are not // set explicitly from the admin panel. These services ideally // require no configuration and therefore, do not appear in the // antispam section of the admin panel $services = array_merge($services, $antispam['immutable']); // Remove leading/trailing spaces from service names $services = array_map('trim', $services); // Run the spam filters foreach ($services as $service) { // Check if this service is available for the current scope // This helps us decide whether or not to run this service if (in_array($service, $antispam['scopes'][$this->scope])) { $handler = array($this, 'run' . studly_case($service)); if (is_callable($handler)) { if (!call_user_func($handler)) { if (isset($this->customMessages[$service])) { $this->message = $this->customMessages[$service]; } else { $this->message = Lang::get('antispam.' . $service); } return FALSE; } } } } } return TRUE; }
/** * Fetches available Sticky Notes versions for update * * @static * @param bool $csv * @return array|string */ public static function updateVersions($csv = FALSE) { $versions = array(); foreach (Config::get('schema.update') as $version => $schema) { $versions[$version] = $version; } if ($csv) { $versions = implode(',', $versions); } return $versions; }
/** * 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; }
/** * Submits statistics to Sticky Notes server * * @return void */ public static function submitStats() { try { // Send / mask the site's URL $url = Config::get('app.fullStats') ? URL::current() : Lang::get('global.anonymous'); // Populate the data to be send $data = array('url' => $url, 'action' => Request::segment(2), 'version' => Config::get('app.version')); // Send the stats to the REST stats service Requests::post(Site::config('services')->statsUrl, array(), $data); } catch (Requests_Exception $e) { // HTTP POST failed. Suppress this exception } }