1: <?php
2: /**
3: * File factory For XOOPS
4: *
5: * You may not change or alter any portion of this comment or credits
6: * of supporting developers from this source code or any supporting source code
7: * which is considered copyrighted (c) material of the original comment or credit authors.
8: * This program is distributed in the hope that it will be useful,
9: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
13: * @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
14: * @package class
15: * @subpackage file
16: * @since 2.3.0
17: * @author Taiwen Jiang <phppp@users.sourceforge.net>
18: */
19: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
20:
21: /**
22: * XoopsFile
23: *
24: * @package
25: * @author Taiwen Jiang <phppp@users.sourceforge.net>
26: * @access public
27: */
28: class XoopsFile
29: {
30: /**
31: * XoopsFile::__construct()
32: */
33: public function __construct()
34: {
35: }
36:
37: /**
38: * XoopsFile::getInstance()
39: *
40: * @return
41: */
42: public function getInstance()
43: {
44: static $instance;
45: if (!isset($instance)) {
46: $class = __CLASS__;
47: $instance = new $class();
48: }
49:
50: return $instance;
51: }
52:
53: /**
54: * XoopsFile::load()
55: *
56: * @param string $name
57: *
58: * @return bool
59: */
60: public static function load($name = 'file')
61: {
62: switch ($name) {
63: case 'folder':
64: if (!class_exists('XoopsFolderHandler')) {
65: if (file_exists($folder = __DIR__ . '/folder.php')) {
66: include $folder;
67: } else {
68: trigger_error('Require Item : ' . str_replace(XOOPS_ROOT_PATH, '', $folder) . ' In File ' . __FILE__ . ' at Line ' . __LINE__, E_USER_WARNING);
69:
70: return false;
71: }
72: }
73: break;
74: case 'file':
75: default:
76: if (!class_exists('XoopsFileHandler')) {
77: if (file_exists($file = __DIR__ . '/file.php')) {
78: include $file;
79: } else {
80: trigger_error('Require File : ' . str_replace(XOOPS_ROOT_PATH, '', $file) . ' In File ' . __FILE__ . ' at Line ' . __LINE__, E_USER_WARNING);
81:
82: return false;
83: }
84: }
85: break;
86: }
87:
88: return true;
89: }
90:
91: /**
92: * XoopsFile::getHandler()
93: *
94: * @param string $name
95: * @param mixed $path
96: * @param mixed $create
97: * @param mixed $mode
98: * @return
99: */
100: public static function getHandler($name = 'file', $path = false, $create = false, $mode = null)
101: {
102: $handler = null;
103: XoopsFile::load($name);
104: $class = 'Xoops' . ucfirst($name) . 'Handler';
105: if (class_exists($class)) {
106: $handler = new $class($path, $create, $mode);
107: } else {
108: trigger_error('Class ' . $class . ' not exist in File ' . __FILE__ . ' at Line ' . __LINE__, E_USER_WARNING);
109: }
110:
111: return $handler;
112: }
113: }
114: