XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
xoopsload.php
Go to the documentation of this file.
1 <?php
20 defined('XOOPS_ROOT_PATH') or die('Restricted access');
21 
22 class XoopsLoad
23 {
24  //static $loaded;
25  //static $configs;
26 
27  static function load($name, $type = "core")
28  {
29  static $loaded;
30  static $deprecated;
31 
32  if (!isset($deprecated)) {
33  $deprecated = array(
34  'uploader' => 'xoopsmediauploader',
35  'utility' => 'xoopsutility',
36  'captcha' => 'xoopscaptcha',
37  'cache' => 'xoopscache',
38  'file' => 'xoopsfile',
39  'model' => 'xoopsmodelfactory',
40  'calendar' => 'xoopscalendar',
41  'userutility' => 'xoopsuserutility',
42  );
43  }
44  $name = strtolower($name);
45  if (in_array($type,array('core','class')) && array_key_exists($name, $deprecated)) {
46  if (isset($GLOBALS['xoopsLogger'])) {
47  $GLOBALS['xoopsLogger']->addDeprecated("xoops_load('{$name}') is deprecated, use xoops_load('{$deprecated[$name]}')");
48  } else {
49  trigger_error("xoops_load('{$name}') is deprecated, use xoops_load('{$deprecated[$name]}')", E_USER_WARNING);
50  }
51  $name = $deprecated[$name];
52  }
53 
54  $type = empty($type) ? 'core' : $type;
55  if (isset($loaded[$type][$name])) {
56  return $loaded[$type][$name];
57  }
58 
59  if (class_exists($name, false)) {
60  $loaded[$type][$name] = true;
61  return true;
62  }
63  $isloaded = false;
64  switch ($type) {
65  case 'framework':
66  $isloaded = XoopsLoad::loadFramework($name);
67  break;
68  case 'class':
69  case 'core':
70  $type = 'core';
71  $isloaded = XoopsLoad::loadCore($name);
72  break;
73  default:
74  $isloaded = XoopsLoad::loadModule($name, $type);
75  break;
76  }
77  $loaded[$type][$name] = $isloaded;
78  return $loaded[$type][$name];
79  }
80 
86  static function loadCore($name)
87  {
88  static $configs;
89 
90  if (!isset($configs)) {
92  }
93  if (isset($configs[$name])) {
94  require $configs[$name];
95  if (class_exists($name) && method_exists($name, '__autoload')) {
96  call_user_func(array($name , '__autoload'));
97  }
98  return true;
99  } elseif (file_exists($file = XOOPS_ROOT_PATH . '/class/' . $name . '.php')) {
100  include_once $file;
101  $class = 'Xoops' . ucfirst($name);
102  if (class_exists($class)) {
103  return $class;
104  } else {
105  trigger_error('Class ' . $name . ' not found in file ' . __FILE__ . 'at line ' . __LINE__, E_USER_WARNING);
106  }
107  }
108  return false;
109  }
110 
116  function loadFramework($name)
117  {
118  if (!file_exists($file = XOOPS_ROOT_PATH . '/Frameworks/' . $name . '/xoops' . $name . '.php')) {
119  trigger_error('File ' . str_replace(XOOPS_ROOT_PATH, '', $file) . ' not found in file ' . __FILE__ . ' at line ' . __LINE__, E_USER_WARNING);
120  return false;
121  }
122  include $file;
123  $class = 'Xoops' . ucfirst($name);
124  if (class_exists($class)) {
125  return $class;
126  }
127  }
133  function loadModule($name, $dirname = null)
134  {
135  if (empty($dirname)) {
136  return false;
137  }
138  if (file_exists($file = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/class/' . $name . '.php')) {
139  include $file;
140  if (class_exists(ucfirst($dirname) . ucfirst($name))) {
141  return true;
142  }
143  }
144  return false;
145  }
146 
152  static function loadCoreConfig()
153  {
154  return $configs = array(
155  'xoopsuserutility' => XOOPS_ROOT_PATH . '/class/userutility.php',
156  'xoopsmediauploader' => XOOPS_ROOT_PATH . '/class/uploader.php',
157  'xoopsutility' => XOOPS_ROOT_PATH . '/class/utility/xoopsutility.php',
158  'xoopscaptcha' => XOOPS_ROOT_PATH . '/class/captcha/xoopscaptcha.php',
159  'xoopscache' => XOOPS_ROOT_PATH . '/class/cache/xoopscache.php',
160  'xoopsfile' => XOOPS_ROOT_PATH . '/class/file/xoopsfile.php',
161  'xoopsmodelfactory' => XOOPS_ROOT_PATH . '/class/model/xoopsmodel.php',
162  'xoopscalendar' => XOOPS_ROOT_PATH . '/class/calendar/xoopscalendar.php',
163  'xoopskernel' => XOOPS_ROOT_PATH . '/class/xoopskernel.php',
164  'xoopssecurity' => XOOPS_ROOT_PATH . '/class/xoopssecurity.php',
165  'xoopslogger' => XOOPS_ROOT_PATH . '/class/logger/xoopslogger.php',
166  'xoopspagenav' => XOOPS_ROOT_PATH . '/class/pagenav.php',
167  'xoopslists' => XOOPS_ROOT_PATH . '/class/xoopslists.php',
168  'xoopslocal' => XOOPS_ROOT_PATH . '/include/xoopslocal.php',
169  'xoopslocalabstract' => XOOPS_ROOT_PATH . '/class/xoopslocal.php',
170  'xoopseditor' => XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php',
171  'xoopseditorhandler' => XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php',
172  'xoopsformloader' => XOOPS_ROOT_PATH . '/class/xoopsformloader.php',
173  'xoopsformelement' => XOOPS_ROOT_PATH . '/class/xoopsform/formelement.php',
174  'xoopsform' => XOOPS_ROOT_PATH . '/class/xoopsform/form.php',
175  'xoopsformlabel' => XOOPS_ROOT_PATH . '/class/xoopsform/formlabel.php',
176  'xoopsformselect' => XOOPS_ROOT_PATH . '/class/xoopsform/formselect.php',
177  'xoopsformpassword' => XOOPS_ROOT_PATH . '/class/xoopsform/formpassword.php',
178  'xoopsformbutton' => XOOPS_ROOT_PATH . '/class/xoopsform/formbutton.php',
179  'xoopsformbuttontray' => XOOPS_ROOT_PATH . '/class/xoopsform/formbuttontray.php',
180  'xoopsformcheckbox' => XOOPS_ROOT_PATH . '/class/xoopsform/formcheckbox.php',
181  'xoopsformselectcheckgroup' => XOOPS_ROOT_PATH . '/class/xoopsform/formselectcheckgroup.php',
182  'xoopsformhidden' => XOOPS_ROOT_PATH . '/class/xoopsform/formhidden.php',
183  'xoopsformfile' => XOOPS_ROOT_PATH . '/class/xoopsform/formfile.php',
184  'xoopsformradio' => XOOPS_ROOT_PATH . '/class/xoopsform/formradio.php',
185  'xoopsformradioyn' => XOOPS_ROOT_PATH . '/class/xoopsform/formradioyn.php',
186  'xoopsformselectcountry' => XOOPS_ROOT_PATH . '/class/xoopsform/formselectcountry.php',
187  'xoopsformselecttimezone' => XOOPS_ROOT_PATH . '/class/xoopsform/formselecttimezone.php',
188  'xoopsformselectlang' => XOOPS_ROOT_PATH . '/class/xoopsform/formselectlang.php',
189  'xoopsformselectgroup' => XOOPS_ROOT_PATH . '/class/xoopsform/formselectgroup.php',
190  'xoopsformselectuser' => XOOPS_ROOT_PATH . '/class/xoopsform/formselectuser.php',
191  'xoopsformselecttheme' => XOOPS_ROOT_PATH . '/class/xoopsform/formselecttheme.php',
192  'xoopsformselectmatchoption' => XOOPS_ROOT_PATH . '/class/xoopsform/formselectmatchoption.php',
193  'xoopsformtext' => XOOPS_ROOT_PATH . '/class/xoopsform/formtext.php',
194  'xoopsformtextarea' => XOOPS_ROOT_PATH . '/class/xoopsform/formtextarea.php',
195  'xoopsformdhtmltextarea' => XOOPS_ROOT_PATH . '/class/xoopsform/formdhtmltextarea.php',
196  'xoopsformelementtray' => XOOPS_ROOT_PATH . '/class/xoopsform/formelementtray.php',
197  'xoopsthemeform' => XOOPS_ROOT_PATH . '/class/xoopsform/themeform.php',
198  'xoopssimpleform' => XOOPS_ROOT_PATH . '/class/xoopsform/simpleform.php',
199  'xoopsformtextdateselect' => XOOPS_ROOT_PATH . '/class/xoopsform/formtextdateselect.php',
200  'xoopsformdatetime' => XOOPS_ROOT_PATH . '/class/xoopsform/formdatetime.php',
201  'xoopsformhiddentoken' => XOOPS_ROOT_PATH . '/class/xoopsform/formhiddentoken.php',
202  'xoopsformcolorpicker' => XOOPS_ROOT_PATH . '/class/xoopsform/formcolorpicker.php',
203  'xoopsformcaptcha' => XOOPS_ROOT_PATH . '/class/xoopsform/formcaptcha.php',
204  'xoopsformeditor' => XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php',
205  'xoopsformselecteditor' => XOOPS_ROOT_PATH . '/class/xoopsform/formselecteditor.php',
206  'xoopsformcalendar' => XOOPS_ROOT_PATH . '/class/xoopsform/formcalendar.php',
207  );
208  }
209 
216  function loadConfig($data = null)
217  {
218  if (is_array($data)) {
219  $configs = $data;
220  } else {
221  if (! empty($data)) {
222  $dirname = $data;
223  } elseif (is_object($GLOBALS['xoopsModule'])) {
224  $dirname = $GLOBALS['xoopsModule']->getVar('dirname', 'n');
225  } else {
226  return false;
227  }
228  if (file_exists($file = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/include/autoload.php')) {
229  if (! $configs = include $file) {
230  return false;
231  }
232  }
233  }
234  return $configs = array_merge(XoopsLoad::loadCoreConfig(), $configs);
235  }
236 }
237 // To be enabled in XOOPS 3.0
238 // spl_autoload_register(array('XoopsLoad', 'load'));
239 
240 
241 ?>