Пример #1
0
 /**
  * Boots system.
  */
 public static function initialize()
 {
     self::$cli = PHP_SAPI === 'cli';
     # Set Rails path
     self::$path = str_replace(DIRECTORY_SEPARATOR, '/', __DIR__);
     // self::$path = str_replace(DIRECTORY_SEPARATOR, '/', RAILS_PATH);
     # Set root path
     self::$root = str_replace(DIRECTORY_SEPARATOR, '/', RAILS_ROOT);
     # Set public path
     self::$publicPath = defined('RAILS_PUBLIC_PATH') ? RAILS_PUBLIC_PATH : self::$root . '/public';
     self::$publicPath = str_replace(DIRECTORY_SEPARATOR, '/', self::$publicPath);
     /**
      * Set environment.
      */
     self::$env = RAILS_ENV;
     self::$config = self::defaultConfig();
     # Debugging functions...
     include self::$path . '/Toolbox/functions.php';
     self::setRailsConfig();
 }
Пример #2
0
 private function useCache()
 {
     return \Rails::env() == 'production';
 }
Пример #3
0
 public static function setEnv($env)
 {
     self::$env = $env;
 }
Пример #4
0
 public function voted_tags(array $options = array())
 {
     $type = !empty($options['type']) ? $options['type'] : null;
     $favorite_tags = Rails::cache()->read("favorite_tags/" . $this->id . "/" . $type);
     if ($favorite_tags) {
         return $favorite_tags;
     }
     if (Rails::env() == "test") {
         # disable filtering in test mode to simplify tests
         $popular_tags = "";
     } else {
         $popular_tags = implode(', ', self::connection()->selectValues("SELECT id FROM tags WHERE tag_type = " . CONFIG()->tag_types['General'] . " ORDER BY post_count DESC LIMIT 8"));
         if ($popular_tags) {
             $popular_tags = "AND pt.tag_id NOT IN ({$popular_tags})";
         }
     }
     if ($type) {
         $type = (int) $type;
         $sql = "SELECT\n                (SELECT name FROM tags WHERE id = pt.tag_id) AS tag, SUM(v.score) AS sum\n                FROM posts_tags pt, tags t, post_votes v\n                WHERE v.user_id = {$this->id}\n                AND v.post_id = pt.post_id\n                AND pt.tag_id = t.id\n                {$popular_tags}\n                AND t.tag_type = {$type}\n                GROUP BY pt.tag_id\n                ORDER BY sum DESC\n                LIMIT 6\n            ";
     } else {
         $sql = "SELECT\n                (SELECT name FROM tags WHERE id = pt.tag_id) AS tag, SUM(v.score) AS sum\n                FROM posts_tags pt, post_votes v\n                WHERE v.user_id = {$this->id}\n                AND v.post_id = pt.post_id\n                {$popular_tags}\n                GROUP BY pt.tag_id\n                ORDER BY sum DESC\n                LIMIT 6\n            ";
     }
     $favorite_tags = self::connection()->select($sql);
     Rails::cache()->write("favorite_tags/" . $this->id . "/" . $type, $favorite_tags, ['expires_in' => '1 day']);
     return $favorite_tags;
 }
Пример #5
0
$config->eager_load_paths = [];
/**
 * Set's the cache storing class.
 *
 * For FileStore
 * cache_store ( string 'file_store', string $cache_path )
 *
 * For Memcached
 * cache_store ( string 'mem_cached_store' [, mixed $server1 [, mixed $server2 ... ] ] )
 * Defaults to host "localhost" and port 11211.
 * Examples:
 * Add 1 server with default options.
 * $config->cache_store = 'mem_cached_store';
 * Add 1 server with foobarhost as host and default port.
 * $config->cache_store = [ 'mem_cached_store', 'foobarhost' ];
 * Add 2 servers: one with localhost as host with default port, and the other one
 *  with other.server as host and 4456 as port.
 * $config->cache_store = [ 'mem_cached_store', 'localhost', ['other.server', 4456] ];
 */
$config->cache_store = ['file_store', Rails::root() . '/tmp/cache'];
/**
 * This is supposed to be used to set a custom logger.
 * But rather, customize the default logger in Application\Base::init().
 */
$config->logger = null;
$config->log_file = Rails::root() . '/log/' . Rails::env() . '.log';
/**
 * Accepts int from 0 to 8.
 */
$config->log_level = false;
return $config;