/** * Class factory. This is used for instantiating the extended classes. * * @param string The type of the class to be called (user, forum etc.) * @param vB_Registry An instance of the vB_Registry object. * @param integer One of the ERRTYPE_x constants * @param string Option to force loading a class from a specific file; no extension * * @return vB_DataManager An instance of the desired class */ function &datamanager_init($classtype, &$registry, $errtype = ERRTYPE_STANDARD, $forcefile = '') { static $called; if (empty($called)) { // include the abstract base class require_once DIR . '/includes/class_dm.php'; $called = true; } if (preg_match('#^\\w+$#', $classtype)) { $classtype = strtolower($classtype); if ($forcefile) { $classfile = preg_replace('#[^a-z0-9_]#i', '', $forcefile); } else { $classfile = str_replace('_multiple', '', $classtype); } require_once DIR . '/includes/class_dm_' . $classfile . '.php'; switch ($classtype) { case 'attachment': $object = vB_DataManager_Attachment::fetch_library($registry, $errtype); break; case 'userpic_avatar': case 'userpic_profilepic': case 'userpic_sigpic': $object = vB_DataManager_Userpic::fetch_library($registry, $errtype, $classtype); break; default: $classname = 'vB_DataManager_' . $classtype; $object = new $classname($registry, $errtype); } return $object; } }