Source for file system.php

Documentation is available at system.php

  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // Copyright (C) ReloadCMS Development Team //
  4. // http://reloadcms.sf.net //
  5. // //
  6. // This program is distributed in the hope that it will be useful, //
  7. // but WITHOUT ANY WARRANTY, without even the implied warranty of //
  8. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
  9. // //
  10. // This product released under GNU General Public License v2 //
  11. ////////////////////////////////////////////////////////////////////////////////
  12.  
  13.  
  14.  
  15.  
  16.  
  17. class rcms_system extends rcms_user {
  18. var $language = '';
  19. var $skin = '';
  20. var $config = array();
  21. var $results = array();
  22. var $data = array();
  23. var $modules = array();
  24. var $feeds = array();
  25. var $cookie_lang = 'reloadcms_lang';
  26. var $cookie_skin = 'reloadcms_skin';
  27. var $output = array('modules' => array(), 'menus' => array());
  28. var $current_point = '';
  29. var $logging = LOGS_PATH;
  30. var $logging_gz = true;
  31. var $url = '';
  32.  
  33. function rcms_system($language_select_form = '', $skin_select_form = ''){
  34. global $lang;
  35. // Loading configuration
  36. $this->config = parse_ini_file(CONFIG_PATH . 'config.ini');
  37. if(empty($this->config['site_url'])){
  38. $this->url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME'] . basename($_SERVER['SCRIPT_NAME'])) . '/';
  39. } else {
  40. $this->url = $this->config['site_url'];
  41. }
  42. if($this->url{strlen($this->url) - 1} != '/'){
  43. $this->url .= '/';
  44. }
  45. $this->language = $this->config['default_lang'];
  46. $this->skin = $this->config['default_skin'];
  47. $this->initialiseLanguage(basename($language_select_form));
  48. $this->logging_gz = extension_loaded('zlib');
  49. if(!empty($this->config['allowchskin'])){
  50. if(!empty($_COOKIE[$this->cookie_skin]) && is_file(SKIN_PATH . basename($_COOKIE[$this->cookie_skin]) . '/skin.general.php')) $this->skin = basename($_COOKIE[$this->cookie_skin]);
  51. if(!empty($skin_select_form) && is_file(SKIN_PATH . basename($skin_select_form) . '/skin.general.php')) {
  52. $this->skin = $skin_select_form;
  53. setcookie($this->cookie_skin, basename($skin_select_form), FOREVER_COOKIE);
  54. }
  55. }
  56. define('CUR_SKIN_PATH', SKIN_PATH . $this->skin . '/');
  57. $this->initialiseModules();
  58. $this->initializeUser();
  59. }
  60.  
  61. function initialiseLanguage($language = '', $default = false){
  62. global $lang;
  63.  
  64. // Loading avaible languages lists
  65. $langs = rcms_scandir(LANG_PATH);
  66. foreach ($langs as $lng){
  67. if(is_dir(LANG_PATH . $lng) && is_file(LANG_PATH . $lng . '/langid.txt')){
  68. $lngdata = file(LANG_PATH . $lng . '/langid.txt');
  69. $this->data['languages'][preg_replace("/[\n\r]+/", '', $lngdata[1])] = preg_replace("/[\n\r]+/", '', $lngdata[0]);
  70. $this->data['langpath'][preg_replace("/[\n\r]+/", '', $lngdata[1])] = LANG_PATH . $lng . '/';
  71. }
  72. }
  73.  
  74. if(!empty($this->config['allowchlang']) && !$default){
  75. if(!empty($language) && !empty($this->data['languages'][$language])) {
  76. $this->language = $language;
  77. setcookie($this->cookie_lang, $language, FOREVER_COOKIE);
  78. $_COOKIE[$this->cookie_lang] = $language;
  79. } elseif(!empty($_COOKIE[$this->cookie_lang]) && !empty($this->data['languages'][basename($_COOKIE[$this->cookie_lang])])) {
  80. $this->language = basename($_COOKIE[$this->cookie_lang]);
  81. } else {
  82. if(!empty($this->config['detect_lang']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
  83. $lang_priority = explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
  84. $lang_priority = explode(',', $lang_priority[0]);
  85. } else $lang_priority = array();
  86.  
  87. foreach ($lang_priority as $lng){
  88. if($this->language == $this->config['default_lang'] && !empty($this->data['languages'][basename($lng)])){
  89. $this->language = basename($lng);
  90. }
  91. }
  92. }
  93. }
  94.  
  95. if(!is_file($this->data['langpath'][$this->language] . 'langid.txt')){
  96. die('Language "' . $this->language . '" not found');
  97. }
  98.  
  99. // Loading language files' list
  100. $lngdir = rcms_scandir($this->data['langpath'][$this->language]);
  101.  
  102. // Loading language definition
  103. $lngdata = file($this->data['langpath'][$this->language] . 'langid.txt');
  104. $this->config['language'] = preg_replace("/[\n\r]+/", '', $lngdata[1]);
  105. $this->config['encoding'] = preg_replace("/[\n\r]+/", '', $lngdata[2]);
  106.  
  107. // Loading language bindings
  108. foreach ($lngdir as $langfile){
  109. if(is_file($this->data['langpath'][$this->language] . $langfile) && $langfile !== 'langid.txt'){
  110. include_once($this->data['langpath'][$this->language] . $langfile);
  111. }
  112. }
  113. }
  114.  
  115. function initialiseModules($ignore_disable = false){
  116. // Loading modules initializations
  117. if(!$ignore_disable) {
  118. if(!$disabled = @parse_ini_file(CONFIG_PATH . 'disable.ini')){
  119. $disabled = array();
  120. }
  121. } else {
  122. $disabled = array();
  123. }
  124. $modules = rcms_scandir(MODULES_PATH);
  125. foreach ($modules as $module){
  126. if(empty($disabled[$module]) && is_readable(MODULES_PATH . $module . '/module.php')) {
  127. include_once(MODULES_PATH . $module . '/module.php');
  128. }
  129. }
  130. // Register modules rights in main database
  131. foreach ($this->modules as $type => $modules){
  132. foreach ($modules as $module => $moduledata){
  133. foreach ($moduledata['rights'] as $right => $desc){
  134. $this->rights_database[$right] = $desc;
  135. }
  136. }
  137. }
  138. }
  139.  
  140. function addInfoToHead($info){
  141. $this->config['meta'] = @$this->config['meta'] . $info;
  142. }
  143.  
  144. function setCurrentPoint($point){
  145. $this->current_point = $point;
  146. }
  147.  
  148. function defineWindow($title, $data, $align = 'left'){
  149. if ($title == __('Error')) {
  150. $title = '<font color="red">'.$title.'</font>';
  151. }
  152. if($this->current_point == '__MAIN__') {
  153. $this->output['modules'][] = array($title, $data, $align);
  154. }
  155. elseif(!empty($this->current_point)){
  156. $this->output['menus'][$this->current_point][] = array($title, $data, $align);
  157. } else return false;
  158. }
  159.  
  160. function showWindow($title, $content, $align, $template){
  161. if($title == '__NOWINDOW__') echo $content;
  162. elseif(is_readable($template)) require($template);
  163. else return false;
  164. return true;
  165. }
  166.  
  167. function registerModule($module, $type, $title, $copyright = '', $rights = array()){
  168. $this->modules[$type][$module]['title'] = $title;
  169. $this->modules[$type][$module]['copyright'] = $copyright;
  170. $this->modules[$type][$module]['rights'] = $rights;
  171. }
  172.  
  173. function registerFeed($module, $title, $desc, $real = ''){
  174. $this->feeds[$module] = array($title, $desc, $real);
  175. }
  176.  
  177. function logPut($type, $user, $message){
  178. if(!empty($this->config['logging'])){
  179. $entry = '---------------------------------' . "\n";
  180. $entry .= date('H:i:s d-m-Y', time()) . "\n";
  181. $entry .= $type . ' (' . $user . ' from ' . $_SERVER['REMOTE_ADDR'] . ')' . "\n";
  182. $entry .= $message . "\n";
  183. if($this->logging_gz){
  184. gzfile_write_contents($this->logging . date('Y-m-d', time()) . '.log.gz', $entry, 'a');
  185. } else {
  186. file_write_contents($this->logging . date('Y-m-d', time()) . '.log', $entry, 'a');
  187. }
  188. }
  189. return true;
  190. }
  191.  
  192. function logMerge($title, $t_d, $t_m, $t_y, $f_d = 1, $f_m = 1, $f_y = 1980){
  193. $logs = rcms_scandir($this->logging);
  194. $f = mktime(0, 0, 0, $f_m, $f_d, $f_y);
  195. $t = mktime(0, 0, 0, $t_m, $t_d, $t_y);
  196. $to_merge = array();
  197. foreach ($logs as $log_entry){
  198. if(preg_match("/^(.*?)-(.*?)-(.*?)\.log(|.gz)$/i", $log_entry, $matches)){
  199. $c = mktime(0, 0, 0, $matches[2], $matches[3], $matches[1]);
  200. if($c >= $f && $c <= $t){
  201. $to_merge[] = $log_entry;
  202. }
  203. }
  204. }
  205. if(!empty($to_merge)){
  206. if($this->logging_gz) $suffix = '.gz'; else $suffix = '';
  207. $merged_file = $this->logging . $title . '.tar' . $suffix;
  208. $merged = new tar();
  209. $merged->isGzipped = $this->logging_gz;
  210. $merged->filename = $merged_file;
  211. $path = getcwd();
  212. chdir($this->logging);
  213. foreach ($to_merge as $file){
  214. $merged->addFile($file, substr($file, -3) == '.gz');
  215. }
  216. chdir($path);
  217. if($merged->saveTar()){
  218. foreach ($to_merge as $file){
  219. rcms_delete_files($this->logging . $file);
  220. }
  221. }
  222. }
  223. return true;
  224. }
  225.  
  226. function logMergeByMonth(){
  227. $logs = rcms_scandir($this->logging);
  228. $d = date('d');
  229. $m = date('m');
  230. $Y = date('Y');
  231. $merged = array();
  232. foreach ($logs as $log_entry){
  233. if(preg_match("/^(.*?)-(.*?)-(.*?)\.log(|.gz)$/i", $log_entry, $matches)){
  234. $t = date('t', mktime(0, 0, 0, $matches[2], $matches[3], $matches[1]));
  235. if(!in_array($matches[1] . '-' . $matches[2], $merged) && ($matches[2] != $m || $matches[1] != $Y)){
  236. $this->logMerge($matches[1] . '-' . $matches[2], $t, $matches[2], $matches[1], 1, $matches[2], $matches[1]);
  237. $merged[] = $matches[1] . '-' . $matches[2];
  238. }
  239. }
  240. }
  241. return true;
  242. }
  243.  
  244. var $navmodifiers = array();
  245. function registerNavModifier($base, $mod_handler, $help_handler){
  246. $this->navmodifiers[$base] = array('m' => $mod_handler, 'h' => $help_handler);
  247. return true;
  248. }
  249. }
  250.  
  251. function __($string){
  252. global $lang;
  253. if(!empty($lang['def'][$string])) {
  254. return $lang['def'][$string];
  255. } else {
  256. return $string;
  257. }
  258. }
  259.  
  260. function rcms_log_put($type, $user, $message){
  261. global $system;
  262. return $system->logPut($type, $user, $message);
  263. }
  264.  
  265.  
  266. function cut_text($str,$lenght=25)
  267. {
  268. $str = substr($str, 0, $lenght) . ((strlen($str) > $lenght) ? '...' : '');
  269. return ($str);
  270. }
  271. ?>

Documentation generated on Fri, 08 Jun 2007 12:21:29 +0300 by phpDocumentor 1.3.0RC3