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: if (false === ($editor = getEffectiveSetting('wysiwyg', 'editor', false))) {
67: $sInclude = $cfg['path']['wysiwyg'] . $sWhat;
68: } else {
69: $sInclude = $cfg['path']['all_wysiwyg'] . $editor;
70: }
71: break;
72: case 'all_wysiwyg':
73: $sInclude = $cfg['path']['all_wysiwyg'] . $sWhat;
74: break;
75: case 'classes':
76: if (cAutoload::isAutoloadable($cfg['path'][$sWhere] . $sWhat)) {
77: // The class file will be loaded automatically by the autoloader - get out here
78: return NULL;
79: }
80: $sInclude = $backendPath . $cfg['path'][$sWhere] . $sWhat;
81: break;
82: default:
83: $sInclude = $backendPath . $cfg['path'][$sWhere] . $sWhat;
84: break;
85: }
86:
87: $sFoundPath = '';
88:
89: if (!cFileHandler::exists($sInclude) || preg_match('#^\.\./#', $sWhat)) {
90: $bError = true;
91: }
92:
93: // should the path be returned?
94: if ($bReturnPath) {
95: if ($sFoundPath !== '') {
96: $sInclude = $sFoundPath . DIRECTORY_SEPARATOR . $sInclude;
97: }
98:
99: if (!$bError) {
100: return $sInclude;
101: } else {
102: return false;
103: }
104: }
105:
106: if ($bError) {
107: cError("Error: Can't include $sInclude", E_USER_ERROR);
108: return false;
109: }
110:
111: // now include the file
112: if ($bForce == true) {
113: return include($sInclude);
114: } else {
115: return include_once($sInclude);
116: }
117:
118: }
119:
120: /**
121: * Includes a file from a plugin and takes care of all path transformations.
122: *
123: * Example:
124: * plugin_include('formedit', 'classes/class.formedit.php');
125: *
126: * @param string $sWhere The name of the plugin
127: * @param string $sWhat The filename of the include
128: */
129: function plugin_include($sWhere, $sWhat) {
130: global $cfg;
131:
132: $sInclude = cRegistry::getBackendPath() . $cfg['path']['plugins'] . $sWhere. '/' . $sWhat;
133:
134: include_once($sInclude);
135: }
136: ?>