XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
loader.php
Go to the documentation of this file.
1 <?php
2 // $Id: loader.php 1041 2012-09-09 06:23:26Z i.bitcero $
3 // --------------------------------------------------------------
4 // Red México Common Utilities
5 // A framework for Red México Modules
6 // Author: Eduardo Cortés <i.bitcero@gmail.com>
7 // Email: i.bitcero@gmail.com
8 // License: GPL 2.0
9 // --------------------------------------------------------------
10 
11 define("RMCPATH",XOOPS_ROOT_PATH.'/modules/rmcommon');
12 define("RMCURL",XOOPS_URL.'/modules/rmcommon');
13 define('ABSURL', XOOPS_URL);
14 define('ABSPATH', XOOPS_ROOT_PATH);
15 define('RMCVERSION','2.1.8.8 RC');
16 
17 // Message Levels
18 define('RMMSG_INFO', 0);
19 define('RMMSG_WARN', 1);
20 define('RMMSG_SUCCESS', 2);
21 define('RMMSG_SAVED', 3);
22 define('RMMSG_ERROR', 4);
23 define('RMMSG_OTHER', 5);
24 
25 ob_start('cu_render_output');
26 
31  global $xoopsModule;
32 
33  if(class_exists($class)) return;
34 
35  $class = strtolower($class);
36 
37  if($class=='xoopskernel') return;
38 
39  if (substr($class, 0, 2)=='rm') $class = substr($class, 2);
40 
41  if (substr($class, strlen($class) - strlen('handler'))=='handler'){
42  $class = substr($class, 0, strlen($class) - 7);
43  }
44 
45  $paths = array(
46  '/api',
47  '/class',
48  '/kernel',
49  '/fields'
50  );
51 
52  if (is_a($xoopsModule, 'XoopsModule') && $xoopsModule->dirname()!='system'){
53  $paths[] = '/modules/'.$xoopsModule->dirname().'/class';
54  }
55 
56  foreach ($paths as $path){
57  if (file_exists(RMCPATH.$path.'/'.$class.'.php')){
58  include_once RMCPATH.$path.'/'.$class.'.php';
59  break;
60  } elseif(file_exists(RMCPATH.$path.'/'.$class.'.class.php')){
61  include_once RMCPATH.$path.'/'.$class.'.class.php';
62  break;
63  } elseif (file_exists(XOOPS_ROOT_PATH.$path.'/'.$class.'.php')){
64  include_once XOOPS_ROOT_PATH.$path.'/'.$class.'.php';
65  break;
66  } elseif(file_exists(XOOPS_ROOT_PATH.$path.'/'.$class.'.class.php')){
67  include_once XOOPS_ROOT_PATH.$path.'/'.$class.'.class.php';
68  break;
69  }
70  }
71 
72 }
73 
74 spl_autoload_register('rmc_autoloader');
75 
82 function cu_render_output($output){
83  global $xoTheme, $xoopsTpl;
84 
86 
87  if (function_exists('xoops_cp_header')) return $output;
88 
89  $page = $output;
90  if($xoopsTpl){
91  if(defined('COMMENTS_INCLUDED') && COMMENTS_INCLUDED){
92  RMTemplate::get()->add_xoops_style('comments.css', 'rmcommon');
93  }
94  }
95 
96  include_once RMTemplate::get()->tpl_path('rmc_header.php', 'rmcommon');
97  $rtn .= $scripts;
98  $rtn .= $styles;
99  $rtn .= $heads;
100 
101  $find = array();
102  $repl = array();
103  foreach($metas as $name => $content){
104 
105  $str = "<meta\s+name=['\"]??".$name."['\"]??\s+content=['\"]??(.+)['\"]??\s*\/?>";
106  if(preg_match($str, $page)){
107  $find[] = $str;
108  $str = "meta name=\"$name\" content=\"$content\" />\n";
109  $repl[] = $str;
110  } else {
111 
112  $rtn .= "\n<meta name=\"$name\" content=\"$content\" />";
113 
114  }
115 
116  }
117 
118  if(!empty($find))
119  $page = preg_replace($find, $repl, $page);
120 
121  $pos = strpos($page, "</body>");
122  if($pos===FALSE) return $output;
123 
124  $ret = substr($page, 0, $pos)."\n";
125  $ret .= $fscripts."\n".$fstyles;
126  $ret .= substr($page, $pos);
127 
128  $page = $ret;
129 
130  $pos = strpos($page, "<!-- RMTemplateHeader -->");
131  if($pos!==FALSE){
132  $page = str_replace('<!-- RMTemplateHeader -->', $rtn, $page);
133  $page = $rmEvents->run_event('rmcommon.end.flush',$page);
134  return $page;
135  }
136 
137  $pos = strpos($page, "</head>");
138  if($pos===FALSE) return $output;
139 
140  $ret = substr($page, 0, $pos)."\n";
141  $ret .= $rtn;
142  $ret .= substr($page, $pos);
143 
144  $ret = $rmEvents->run_event('rmcommon.end.flush',$ret);
145 
146  return $ret;
147 }
148 
149 include_once XOOPS_ROOT_PATH.'/class/logger/xoopslogger.php';
150 include_once XOOPS_ROOT_PATH.'/class/database/databasefactory.php';
151 
152 $dbF = new XoopsDatabaseFactory();
153 $db =& $dbF->getDatabaseConnection();
154 
155 $GLOBALS['rmc_config'] = RMFunctions::get()->configs();
156 global $rmc_config;
157 // Base classes
158 $GLOBALS['rmEvents'] = RMEvents::get();
161 
163 
164 define('RMCLANG', $rmEvents->run_event('rmcommon.set.language', $rmc_config['lang']));
165 
166 // Load plugins
167 $file = XOOPS_CACHE_PATH.'/plgs.cnf';
168 $plugins = array();
169 $GLOBALS['installed_plugins'] = array();
170 
171 if (file_exists($file)){
172  $plugins = json_decode(file_get_contents($file), true);
173 }
174 
175 if (empty($plugins) || !is_array($plugins)){
176 
177  $result = $db->query("SELECT dir FROM ".$db->prefix("rmc_plugins").' WHERE status=1');
178  while($row = $db->fetchArray($result)){
179  $GLOBALS['installed_plugins'][$row['dir']] = true;
180  $plugins[] = $row['dir'];
181  $rmEvents->load_extra_preloads(RMCPATH.'/plugins/'.$row['dir'], ucfirst($row['dir']).'Plugin');
182  }
183  file_put_contents($file, json_encode($plugins));
184 
185 } else {
186 
187  foreach($plugins as $p){
188  $GLOBALS['installed_plugins'][$p] = true;
189  $rmEvents->load_extra_preloads(RMCPATH.'/plugins/'.$p, ucfirst($p).'Plugin');
190  }
191 
192 }
193 
194 // Load GUI theme events
195 $rmEvents->load_extra_preloads(RMCPATH.'/themes/'.$rmc_config['theme'], ucfirst($rmc_config['theme']));
196 
197 unset($plugins);
198 unset($file);
199 
200 $GLOBALS['installed_plugins'] = $rmEvents->run_event("rmcommon.plugins.loaded", $GLOBALS['installed_plugins']);
201 
202 require_once 'api/l10n.php';
203 
204 // Load rmcommon language
205 load_mod_locale('rmcommon');
206 
207 if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->dirname()!='rmcommon')
208  load_mod_locale($xoopsModule->dirname());
209 
210 if (!$rmc_config){
211  _e('Sorry, Red Mexico Common Utilities has not been installed yet!');
212  die();
213 }
214 
215 $rmEvents->run_event('rmcommon.base.loaded');
216 $rmTpl->add_head_script('var xoUrl = "'.XOOPS_URL.'";');
217 
218 if($rmc_config['updates'] && $xoopsOption['pagetype']=='admin'){
219 
220  $interval = $rmc_config['updatesinterval']<=0 ? 7 : $rmc_config['updatesinterval'];
221  if(file_exists(XOOPS_CACHE_PATH.'/updates.chk'))
222  $updates = unserialize(base64_decode(file_get_contents(XOOPS_CACHE_PATH.'/updates.chk')));
223  else
224  $updates = array('date'=>0,'total'=>0,'updates'=>array());
225 
226  $rmTpl->add_local_script('updates.js','rmcommon','include', 'text/javascript', '', true);
227 
228  if($updates['date']<(time()-($rmc_config['updatesinterval']*86400))){
229  $rmTpl->add_head_script('(function(){rmCheckUpdates();})();');
230  define('RMC_CHECK_UPDATES', 1);
231  }else{
232  $rmTpl->add_head_script('$(document).ready(function(){rmCallNotifier('.$updates['total'].');});');
233  }
234 
235 }
236 
237 include_once RMCPATH.'/include/tpl_functions.php';