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