1: <?php
2:
3: /**
4: * This file contains CONTENIDO General API functions.
5: *
6: * If you are planning to add a function, please make sure that:
7: * 1.) The function is in the correct place
8: * 2.) The function is documented
9: * 3.) The function makes sense and is generically usable
10: *
11: * @package Core
12: * @subpackage Backend
13: * @version SVN Revision $Rev:$
14: *
15: * @author Timo Hummel
16: * @copyright four for business AG <www.4fb.de>
17: * @license http://www.contenido.org/license/LIZENZ.txt
18: * @link http://www.4fb.de
19: * @link http://www.contenido.org
20: */
21:
22: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
23:
24: /**
25: * Includes a file and takes care of all path transformations.
26: *
27: * Example:
28: * cInclude('classes', 'class.backend.php');
29: *
30: * Currently defined areas:
31: *
32: * frontend Path to the *current* frontend
33: * classes Path to the CONTENIDO classes (see NOTE below)
34: * cronjobs Path to the cronjobs
35: * external Path to the external tools
36: * includes Path to the CONTENIDO includes
37: * scripts Path to the CONTENIDO scripts
38: * module Path to module
39: *
40: * NOTE: Since CONTENIDO (since v 4.9.0) provides autoloading of required
41: * class files, there is no need to load CONTENIDO class files of by using
42: * cInclude().
43: *
44: * @param string $sWhere
45: * The area which should be included
46: * @param string $sWhat
47: * The filename of the include
48: * @param bool $bForce
49: * If true, force the file to be included
50: * @param string $bReturnPath
51: * Flag to return the path instead of including the file
52: * @return bool|string|NULL
53: */
54: function cInclude($sWhere, $sWhat, $bForce = false, $bReturnPath = false) {
55: $backendPath = cRegistry::getBackendPath();
56: global $client, $cfg, $cfgClient, $cCurrentModule;
57:
58: // Sanity check for $sWhat
59: $sWhat = trim($sWhat);
60: $sWhere = strtolower($sWhere);
61: $bError = false;
62:
63: switch ($sWhere) {
64: case 'module':
65: $handler = new cModuleHandler($cCurrentModule);
66: $sInclude = $handler->getPhpPath() . $sWhat;
67: break;
68: case 'frontend':
69: $sInclude = cRegistry::getFrontendPath() . $sWhat;
70: break;
71: case 'classes':
72: if (cAutoload::isAutoloadable($cfg['path'][$sWhere] . $sWhat)) {
73: // The class file will be loaded automatically by the autoloader - get out here
74: return NULL;
75: }
76: $sInclude = $backendPath . $cfg['path'][$sWhere] . $sWhat;
77: break;
78: default:
79: $sInclude = $backendPath . $cfg['path'][$sWhere] . $sWhat;
80: break;
81: }
82:
83: $sFoundPath = '';
84:
85: if (!cFileHandler::exists($sInclude) || preg_match('#^\.\./#', $sWhat)) {
86: $bError = true;
87: }
88:
89: // should the path be returned?
90: if ($bReturnPath) {
91: if ($sFoundPath !== '') {
92: $sInclude = $sFoundPath . DIRECTORY_SEPARATOR . $sInclude;
93: }
94:
95: if (!$bError) {
96: return $sInclude;
97: } else {
98: return false;
99: }
100: }
101:
102: if ($bError) {
103: cError("Error: Can't include $sInclude", E_USER_ERROR);
104: return false;
105: }
106:
107: // now include the file
108: if ($bForce == true) {
109: return include($sInclude);
110: } else {
111: return include_once($sInclude);
112: }
113:
114: }
115:
116: /**
117: * Includes a file from a plugin and takes care of all path transformations.
118: *
119: * Example:
120: * plugin_include('formedit', 'classes/class.formedit.php');
121: *
122: * @param string $sWhere
123: * The name of the plugin
124: * @param string $sWhat
125: * The filename of the include
126: */
127: function plugin_include($sWhere, $sWhat) {
128: global $cfg;
129:
130: $sInclude = cRegistry::getBackendPath() . $cfg['path']['plugins'] . $sWhere. '/' . $sWhat;
131:
132: include_once($sInclude);
133: }
134:
135: ?>