1: <?php
2: /**
3: * This file contains CONTENIDO General API functions.
4: *
5: * If you are planning to add a function, please make sure that:
6: * 1.) The function is in the correct place
7: * 2.) The function is documented
8: * 3.) The function makes sense and is generically usable
9: *
10: * @package Core
11: * @subpackage Backend
12: * @version SVN Revision $Rev:$
13: *
14: * @author Timo Hummel
15: * @copyright four for business AG <www.4fb.de>
16: * @license http://www.contenido.org/license/LIZENZ.txt
17: * @link http://www.4fb.de
18: * @link http://www.contenido.org
19: */
20:
21: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
22:
23: /**
24: * Includes a file and takes care of all path transformations.
25: *
26: * Example:
27: * cInclude('classes', 'class.backend.php');
28: *
29: * Currently defined areas:
30: *
31: * frontend Path to the *current* frontend
32: * classes Path to the CONTENIDO classes (see NOTE below)
33: * cronjobs Path to the cronjobs
34: * external Path to the external tools
35: * includes Path to the CONTENIDO includes
36: * scripts Path to the CONTENIDO scripts
37: * module Path to module
38: *
39: * NOTE: Since CONTENIDO (since v 4.9.0) provides autoloading of required
40: * class files, there is no need to load CONTENIDO class files of by using
41: * cInclude().
42: *
43: * @param string $sWhere The area which should be included
44: * @param string $sWhat The filename of the include
45: * @param bool $bForce If true, force the file to be included
46: * @param string $bReturnPath Flag to return the path instead of including the file
47: */
48: function cInclude($sWhere, $sWhat, $bForce = false, $bReturnPath = false) {
49: $backendPath = cRegistry::getBackendPath();
50: global $client, $cfg, $cfgClient, $cCurrentModule;
51:
52: // Sanity check for $sWhat
53: $sWhat = trim($sWhat);
54: $sWhere = strtolower($sWhere);
55: $bError = false;
56:
57: switch ($sWhere) {
58: case 'module':
59: $handler = new cModuleHandler($cCurrentModule);
60: $sInclude = $handler->getPhpPath() . $sWhat;
61: break;
62: case 'frontend':
63: $sInclude = cRegistry::getFrontendPath() . $sWhat;
64: break;
65: case 'wysiwyg':
66: $sInclude = $cfg['path']['wysiwyg'] . $sWhat;
67: break;
68: case 'all_wysiwyg':
69: $sInclude = $cfg['path']['all_wysiwyg'] . $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 The name of the plugin
123: * @param string $sWhat 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: ?>