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 bool $bReturnPath
49: * Flag to return the path instead of including the file
50: *
51: * @return bool|string|NULL
52: *
53: * @throws cInvalidArgumentException
54: */
55: function cInclude($sWhere, $sWhat, $bForce = false, $bReturnPath = false) {
56: $backendPath = cRegistry::getBackendPath();
57: global $client, $cfg, $cfgClient, $cCurrentModule;
58:
59: // Sanity check for $sWhat
60: $sWhat = trim($sWhat);
61: $sWhere = cString::toLowerCase($sWhere);
62: $bError = false;
63:
64: switch ($sWhere) {
65: case 'module':
66: $handler = new cModuleHandler($cCurrentModule);
67: $sInclude = $handler->getPhpPath() . $sWhat;
68: break;
69: case 'frontend':
70: $sInclude = cRegistry::getFrontendPath() . $sWhat;
71: break;
72: case 'classes':
73: if (cAutoload::isAutoloadable($cfg['path'][$sWhere] . $sWhat)) {
74: // The class file will be loaded automatically by the autoloader - get out here
75: return NULL;
76: }
77: $sInclude = $backendPath . $cfg['path'][$sWhere] . $sWhat;
78: break;
79: default:
80: $sInclude = $backendPath . $cfg['path'][$sWhere] . $sWhat;
81: break;
82: }
83:
84: $sFoundPath = '';
85:
86: if (!cFileHandler::exists($sInclude) || preg_match('#^\.\./#', $sWhat)) {
87: $bError = true;
88: }
89:
90: // should the path be returned?
91: if ($bReturnPath) {
92: if ($sFoundPath !== '') {
93: $sInclude = $sFoundPath . DIRECTORY_SEPARATOR . $sInclude;
94: }
95:
96: if (!$bError) {
97: return $sInclude;
98: } else {
99: return false;
100: }
101: }
102:
103: if ($bError) {
104: cError("Error: Can't include $sInclude", E_USER_ERROR);
105: return false;
106: }
107:
108: // now include the file
109: if ($bForce == true) {
110: return include($sInclude);
111: } else {
112: return include_once($sInclude);
113: }
114:
115: }
116:
117: /**
118: * Includes a file from a plugin and takes care of all path transformations.
119: *
120: * Example:
121: * plugin_include('formedit', 'classes/class.formedit.php');
122: *
123: * @param string $sWhere
124: * The name of the plugin
125: * @param string $sWhat
126: * The filename of the include
127: */
128: function plugin_include($sWhere, $sWhat) {
129: global $cfg;
130:
131: $sInclude = cRegistry::getBackendPath() . $cfg['path']['plugins'] . $sWhere. '/' . $sWhat;
132:
133: include_once($sInclude);
134: }
135:
136: ?>