4
* The controller class!
6
* @subpackage dryden -> runtime
8
* @author Bobby Allen (ballen@zpanelcp.com)
9
* @copyright ZPanel Project (http://www.zpanelcp.com/)
10
* @link http://www.zpanelcp.com/
11
* @license GPL (http://www.gnu.org/licenses/gpl.html)
13
class runtime_controller {
16
* @var array All current request 'get' variables.
21
* @var array All current request 'post' variables.
26
* @var array All current request 'session' variables.
28
private $vars_session;
31
* @var array All current request 'cookie' variables.
36
* Get the latest requests and updates the values avaliable to the model/view.
37
* @author Bobby Allen (ballen@zpanelcp.com)
39
public function Init() {
40
$this->vars_get = array($_GET);
41
$this->vars_post = array($_POST);
42
$this->vars_session = array($_SESSION);
43
$this->vars_cookie = array($_COOKIE);
45
if (!isset($this->vars_session[0]['zpuid'])) {
46
ui_module::GetLoginTemplate();
49
if (isset($this->vars_get[0]['module'])) {
50
ui_module::getModule($this->GetCurrentModule());
52
if (isset($this->vars_get[0]['action'])) {
53
if ((class_exists('module_controller', FALSE)) && (method_exists('module_controller', 'do' . $this->vars_get[0]['action']))) {
54
call_user_func(array('module_controller', 'do' . $this->vars_get[0]['action']));
56
echo ui_sysmessage::shout("No 'do" . $this->vars_get[0]['action'] . "' class exists - Please create it to enable controller actions and runtime placeholders within your module.");
63
* Returns a vlaue from one of the requested type.
64
* @author Bobby Allen (ballen@zpanelcp.com)
65
* @param string $type The type of request data to return.
66
* @param string $name The named key of the array.
67
* @retrun mixed Returns that array data if avaliable (is set) otherwise will return 'false'.
69
public function GetControllerRequest($type = "URL", $name) {
70
if ($type == 'FORM') {
71
if (isset($this->vars_post[0][$name])) {
72
return $this->vars_post[0][$name];
76
} elseif ($type == 'URL') {
77
if (isset($this->vars_get[0][$name])) {
78
return $this->vars_get[0][$name];
82
} elseif ($type == 'USER') {
83
if (isset($this->vars_session[0][$name])) {
84
return $this->vars_session[0][$name];
89
if (isset($this->vars_cookie[0][$name])) {
90
return $this->vars_cookie[0][$name];
99
* Grabs the list of all controller requests for a given type.
100
* @author Bobby Allen (ballen@zpanelcp.com)
101
* @param string $type What type of requests would you like to see? (URL, USER, FORM or COOKIE)
102
* @return array List of all set variables for the requested type.
104
public function GetAllControllerRequests($type = "URL") {
105
if ($type == 'FORM') {
106
return $this->vars_post[0];
107
} elseif ($type == 'URL') {
108
return $this->vars_get[0];
109
} elseif ($type == 'USER') {
110
return $this->vars_session[0];
112
return $this->vars_cookie[0];
118
* Gets the current framework requested action.
121
public function GetAction() {
122
if (isset($this->vars_get[0]['action']))
123
return $this->vars_get[0]['action'];
128
* Gets the current framework requested module 'options'.
131
public function GetOptions() {
132
if (isset($this->vars_get[0]['options']))
133
return $this->vars_get[0]['options'];
138
* Gets and returns the name of the current module.
141
public function GetCurrentModule() {
142
if (isset($this->vars_get[0]['module']))
143
return $this->vars_get[0]['module'];
148
* Displays Controller debug infomation (mainly for module development and debugging)
149
* @author Bobby Allen (ballen@zpanelcp.com)
150
* @global string $script_memory The current amount of memory that the script it using.
151
* @global int $starttime The microtime of when the script started executing.
152
* @return string HTML output of the debug infomation.
154
public function OutputControllerDebug() {
155
global $script_memory;
157
if (isset($this->vars_get[0]['debug'])) {
159
var_dump($this->GetAllControllerRequests('URL'));
160
$set_urls = ob_get_contents();
163
var_dump($this->GetAllControllerRequests('FORM'));
164
$set_forms = ob_get_contents();
167
var_dump($this->GetAllControllerRequests('USER'));
168
$set_sessions = ob_get_contents();
171
var_dump($this->GetAllControllerRequests('COOKIE'));
172
$set_cookies = ob_get_contents();
175
debug_execution::GetLoadedClasses();
176
$classes_loaded = ob_get_contents();
178
$mtime = microtime();
179
$mtime = explode(" ", $mtime);
180
$mtime = $mtime[1] + $mtime[0];
182
$totaltime = ($endtime - $starttime);
183
runtime_hook::Execute('OnDisplayRuntimeDebug');
184
return "<h1>Controller Debug Mode</h1><strong>PHP Script Memory Usage:</strong> " . debug_execution::ScriptMemoryUsage($script_memory) . "<br><strong>Script Execution Time: </strong> " . $totaltime . "<br><br><strong>URL Variables set:</strong><br><pre>" . $set_urls . "</pre><strong>POST Variables set:</strong><br><pre>" . $set_forms . "</pre><strong>SESSION Variables set:</strong><br><pre>" . $set_sessions . "</pre><strong>COOKIE Variables set:</strong><br><pre>" . $set_cookies . "</pre><br><br><strong>Loaded classes:</strong><pre>" . $classes_loaded . "</pre>";
191
* Checks if the current script is running in CLI mode (eg. as a cron job)
192
* @author Bobby Allen (ballen@zpanelcp.com)
195
static function IsCLI() {
196
if (!@$_SERVER['HTTP_USER_AGENT'])
202
* Used in hooks to communicate with the modules controller.ext.php
203
* @author Bobby Allen (ballen@zpanelcp.com)
204
* @param string $module_path The full path to the module.
206
static function ModuleControllerCode($module_path) {
207
$raw_path = str_replace("\\", "/", $module_path);
208
$module_path = str_replace("/hooks", "/code/", $raw_path);
209
$rawroot_path = str_replace("\\", "/", dirname(__FILE__));
210
$root_path = str_replace("/dryden/runtime", "/", $rawroot_path);
211
require_once $root_path . 'dryden/loader.inc.php';
212
require_once $root_path . 'cnf/db.php';
213
require_once $root_path . 'inc/dbc.inc.php';
214
if (file_exists($module_path . 'controller.ext.php')) {
215
require_once $module_path . 'controller.ext.php';
217
$hook_log = new debug_logger();
218
$hook_log->method = ctrl_options::GetOption('logmode');
219
$hook_log->logcode = "611";
220
$hook_log->detail = "No hook controller.ext.php avaliable to import in (" . $root_path . 'controller.ext.php' . ")";
221
$hook_log->writeLog();