1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
3 * Help class for handling config items transparently,
4 * i.e independent of storage location (file or database)
9 * Dummy value to compare to when ... no config was found!
11 const CONFIG_NOT_FOUND
= null;
14 * Fetch config item from db or config file
15 * If $page is set it will fetch for a page-specific
16 * setting for current user
18 public static function get($config_str=false, $page='', $save=false)
20 $config_str = trim($config_str);
21 if (empty($config_str) ||
!is_string($config_str)) {
25 $setting = self
::CONFIG_NOT_FOUND
;
27 # check for database value
28 $cfg = Ninja_setting_Model
::fetch_page_setting($config_str, $page);
30 $setting = $cfg->setting
;
33 if ($setting === self
::CONFIG_NOT_FOUND
) {
34 # if nothing was found - try the config file
35 $setting = Kohana
::config($config_str, false, false);
36 if (is_array($setting) && empty($setting)) {
39 # save to database and session as user setting
40 Ninja_setting_Model
::save_page_setting($config_str, $page, $setting);
48 * Fetch specific key from config file
51 public static function get_cgi_cfg_key($key=false, $file='cgi.cfg')
54 if (empty($key) ||
empty($file) ||
!Auth
::instance()->logged_in())
57 $session = Session
::instance();
58 $val = $session->get($key, null);
60 $val = arr
::search(System_Model
::parse_config_file($file), $key, null);
62 # store value in session
63 $session->set($key, $val);
70 * On a OP5 Monitor system, return the system version
74 public static function get_version_info()
76 static $version = NULL;
77 if ($version === NULL) {
78 $file = Kohana
::config('config.version_info');
79 if (@is_readable
($file)) {
80 $handle = fopen($file, 'r');
81 $contents = fread($handle, filesize($file));
83 $version = trim(str_replace('VERSION=','',$contents));