~josephjamesmills/zpanelcp/zpanelcp

« back to all changes in this revision

Viewing changes to debian/zpanelx/etc/zpanel/dryden/runtime/controller.class.php

  • Committer: Joseph Mills
  • Date: 2012-05-09 02:52:32 UTC
  • Revision ID: josephjamesmills@gmail.com-20120509025232-ob5xni0ggrse28c0
setup framwork for www

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
/**
4
 
 * The controller class!
5
 
 * @package zpanelx
6
 
 * @subpackage dryden -> runtime
7
 
 * @version 1.0.0
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)
12
 
 */
13
 
class runtime_controller {
14
 
 
15
 
    /**
16
 
     * @var array All current request 'get' variables. 
17
 
     */
18
 
    private $vars_get;
19
 
 
20
 
    /**
21
 
     * @var array All current request 'post' variables. 
22
 
     */
23
 
    private $vars_post;
24
 
 
25
 
    /**
26
 
     * @var array All current request 'session' variables. 
27
 
     */
28
 
    private $vars_session;
29
 
 
30
 
    /**
31
 
     * @var array All current request 'cookie' variables. 
32
 
     */
33
 
    private $vars_cookie;
34
 
 
35
 
    /**
36
 
     * Get the latest requests and updates the values avaliable to the model/view.
37
 
     * @author Bobby Allen (ballen@zpanelcp.com)
38
 
     */
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);
44
 
 
45
 
        if (!isset($this->vars_session[0]['zpuid'])) {
46
 
            ui_module::GetLoginTemplate();
47
 
        }
48
 
 
49
 
        if (isset($this->vars_get[0]['module'])) {
50
 
            ui_module::getModule($this->GetCurrentModule());
51
 
        }
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']));
55
 
            } else {
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.");
57
 
            }
58
 
        }
59
 
        return;
60
 
    }
61
 
 
62
 
    /**
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'.
68
 
     */
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];
73
 
            } else {
74
 
                return false;
75
 
            }
76
 
        } elseif ($type == 'URL') {
77
 
            if (isset($this->vars_get[0][$name])) {
78
 
                return $this->vars_get[0][$name];
79
 
            } else {
80
 
                return false;
81
 
            }
82
 
        } elseif ($type == 'USER') {
83
 
            if (isset($this->vars_session[0][$name])) {
84
 
                return $this->vars_session[0][$name];
85
 
            } else {
86
 
                return false;
87
 
            }
88
 
        } else {
89
 
            if (isset($this->vars_cookie[0][$name])) {
90
 
                return $this->vars_cookie[0][$name];
91
 
            } else {
92
 
                return false;
93
 
            }
94
 
        }
95
 
        return false;
96
 
    }
97
 
 
98
 
    /**
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. 
103
 
     */
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];
111
 
        } else {
112
 
            return $this->vars_cookie[0];
113
 
        }
114
 
        return false;
115
 
    }
116
 
 
117
 
    /**
118
 
     * Gets the current framework requested action.
119
 
     * @return boolean 
120
 
     */
121
 
    public function GetAction() {
122
 
        if (isset($this->vars_get[0]['action']))
123
 
            return $this->vars_get[0]['action'];
124
 
        return false;
125
 
    }
126
 
 
127
 
    /**
128
 
     * Gets the current framework requested module 'options'.
129
 
     * @return boolean 
130
 
     */
131
 
    public function GetOptions() {
132
 
        if (isset($this->vars_get[0]['options']))
133
 
            return $this->vars_get[0]['options'];
134
 
        return false;
135
 
    }
136
 
 
137
 
    /**
138
 
     * Gets and returns the name of the current module.
139
 
     * @return boolean 
140
 
     */
141
 
    public function GetCurrentModule() {
142
 
        if (isset($this->vars_get[0]['module']))
143
 
            return $this->vars_get[0]['module'];
144
 
        return false;
145
 
    }
146
 
 
147
 
    /**
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. 
153
 
     */
154
 
    public function OutputControllerDebug() {
155
 
        global $script_memory;
156
 
        global $starttime;
157
 
        if (isset($this->vars_get[0]['debug'])) {
158
 
            ob_start();
159
 
            var_dump($this->GetAllControllerRequests('URL'));
160
 
            $set_urls = ob_get_contents();
161
 
            ob_end_clean();
162
 
            ob_start();
163
 
            var_dump($this->GetAllControllerRequests('FORM'));
164
 
            $set_forms = ob_get_contents();
165
 
            ob_end_clean();
166
 
            ob_start();
167
 
            var_dump($this->GetAllControllerRequests('USER'));
168
 
            $set_sessions = ob_get_contents();
169
 
            ob_end_clean();
170
 
            ob_start();
171
 
            var_dump($this->GetAllControllerRequests('COOKIE'));
172
 
            $set_cookies = ob_get_contents();
173
 
            ob_end_clean();
174
 
            ob_start();
175
 
            debug_execution::GetLoadedClasses();
176
 
            $classes_loaded = ob_get_contents();
177
 
            ob_end_clean();
178
 
            $mtime = microtime();
179
 
            $mtime = explode(" ", $mtime);
180
 
            $mtime = $mtime[1] + $mtime[0];
181
 
            $endtime = $mtime;
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>";
185
 
        } else {
186
 
            return false;
187
 
        }
188
 
    }
189
 
 
190
 
    /**
191
 
     * Checks if the current script is running in CLI mode (eg. as a cron job)
192
 
     * @author Bobby Allen (ballen@zpanelcp.com)
193
 
     * @return boolean
194
 
     */
195
 
    static function IsCLI() {
196
 
        if (!@$_SERVER['HTTP_USER_AGENT'])
197
 
            return true;
198
 
        return false;
199
 
    }
200
 
 
201
 
    /**
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.
205
 
     */
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';
216
 
        } else {
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();
222
 
        }
223
 
    }
224
 
 
225
 
}
226
 
 
227
 
?>