forked from ushahidi/SwiftRiver
/
swiftriver.php
99 lines (84 loc) · 2.56 KB
/
swiftriver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php defined('SYSPATH') or die('No direct script access');
/**
* Initializes the SwiftRiver environment
*
* PHP version 5
* LICENSE: This source file is subject to GPLv3 license
* that is available through the world-wide-web at the following URI:
* http://www.gnu.org/copyleft/gpl.html
* @author Ushahidi Team <team@ushahidi.com>
* @package SwiftRiver - http://github.com/ushahidi/Swiftriver_v2
* @subpackage Cookie config
* @copyright Ushahidi - http://www.ushahidi.com
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License v3 (GPLv3)
*/
class Swiftriver {
/**
* Default salt value to add to the cookies
*/
const DEFAULT_COOKIE_SALT = 'cZjO0Lgfv7QrRGiG3XZJZ7fXuPz0vfcL';
// Cookie name constants
const COOKIE_SEARCH_SCOPE = "search_scope";
const COOKIE_PREVIOUS_SEARCH_SCOPE = "previous_search_scope";
const COOKIE_SEARCH_ITEM_ID = "search_item_id";
/**
* Application initialization
* - Loads the plugins
* - Sets the cookie configuration
*/
public static function init()
{
// Set defaule cache configuration
Cache::$default = Kohana::$config->load('site')->get('default_cache');
try
{
$cache = Cache::instance()->get('dummy'.rand(0,99));
}
catch (Exception $e)
{
// Use the dummy driver
Cache::$default = 'dummy';
}
// Load the plugins
Swiftriver_Plugins::load();
// Add the current default theme to the list of modules
$theme = Model_Setting::get_setting('site_theme');
if ($theme != "default")
{
Kohana::modules(array_merge(
array('themes/'.$theme->value => THEMEPATH.$theme->value),
Kohana::modules()
));
}
// Clean up
unset ($active_plugins, $theme);
// Load the cookie configuration
$cookie_config = Kohana::$config->load('cookie');
Cookie::$httponly = TRUE;
Cookie::$salt = $cookie_config->get('salt', Swiftriver::DEFAULT_COOKIE_SALT);
Cookie::$domain = $cookie_config->get('domain') OR '';
Cookie::$secure = $cookie_config->get('secure') OR FALSE;
Cookie::$expiration = $cookie_config->get('expiration') OR 0;
// Set the default site locale
I18n::$lang = Model_Setting::get_setting('site_locale');
}
/**
* Returns the CDN url for $file
*
* @param string file name
* @return string
*/
public static function get_cdn_url($file)
{
$cdn_url = Kohana::$config->load('site')->get('cdn_url');
if (isset($cdn_url))
{
$cdn_dirs = Kohana::$config->load('site')->get('cdn_directories');
foreach ($cdn_dirs as $dir)
{
$file = preg_replace('|^('.$dir.')|', $cdn_url.'/$1', $file);
}
}
return $file;
}
}