Esempio n. 1
0
    $id = $matches[0];
    // show single user data
    if (isMethod('GET')) {
        $UserController = new UserController();
        $UserController->getUser($id);
    } elseif (isMethod('POST')) {
        // empty for now
    }
} elseif ($matches = matchRoute('/users/:id/update')) {
    $id = $matches[0];
    // show user update form
    if (isMethod('GET')) {
        $UserController = new UserController();
        $UserController->updateFormUser($id);
    } elseif (isMethod('POST')) {
        // put POST values in array !!INSERT SECURITY CHECK HERE!!
        $update = array('name' => $_POST['name'], 'email' => $_POST['email'], 'username' => $_POST['username'], 'password' => $_POST['password']);
        $UserController = new UserController();
        $UserController->updateUser($id, $update['name'], $update['email'], $update['username'], $update['password']);
    }
} elseif ($matches = matchRoute('/users/:id/delete')) {
    $id = $matches[0];
    // show user delete form
    if (isMethod('GET')) {
        $UserController = new UserController();
        $UserController->deleteFormUser($id);
    } elseif (isMethod('POST')) {
        $UserController = new UserController();
        $UserController->deleteUser($id);
    }
}
Esempio n. 2
0
/**
 * execute
 *
 * Executes the run() method which is inside all application controllers 
 * 
 * @return void
 * @link		
 */
function execute()
{
    global $Load, $ZP;
    $applicationController = FALSE;
    $match = FALSE;
    $special = FALSE;
    $params = array();
    if (file_exists("www/config/routes.php")) {
        include "www/config/routes.php";
        if (is_array($routes)) {
            $application = segment(0, isLang());
            foreach ($routes as $route) {
                $pattern = $route["pattern"];
                $match = preg_match($pattern, $application);
                if ($match) {
                    $application = $route["application"];
                    $applicationController = $route["controller"];
                    $method = $route["method"];
                    $params = $route["params"];
                    break;
                }
            }
        }
    }
    if (!$match) {
        if (!segment(0)) {
            $application = get("defaultApplication");
        } elseif (segment(0) and !segment(1)) {
            $application = isLang() ? get("defaultApplication") : segment(0);
        } else {
            $application = segment(0, isLang());
            $applicationController = segment(1, isLang());
            if (isController($applicationController, $application)) {
                $Controller = getController($applicationController, $application);
                $controllerFile = getController($applicationController, $application, TRUE);
                $method = segment(2, isLang());
                if (!isMethod($method, $Controller)) {
                    if (isMethod("index", $Controller)) {
                        $method = "index";
                        $special = TRUE;
                    } else {
                        getException("Method \"{$method}\" doesn't exists");
                    }
                }
            } else {
                $applicationController = FALSE;
                $Controller = getController(NULL, $application);
                $controllerFile = getController(NULL, $application, TRUE);
                $method = segment(1, isLang());
                if (!isMethod($method, $Controller)) {
                    if (isMethod("index", $Controller)) {
                        $method = "index";
                        $special = TRUE;
                    } else {
                        getException("Method \"{$method}\" doesn't exists");
                    }
                }
            }
            if ($applicationController) {
                if (segments() >= 3) {
                    $j = isLang() ? 4 : 3;
                    $j = $special ? $j - 1 : $j;
                    for ($i = 0; $i < segments(); $i++) {
                        if (segment($j) or segment($j) === 0) {
                            $params[$i] = segment($j);
                            $j++;
                        }
                    }
                }
            } else {
                $count = $special ? 1 : 2;
                if (segments() > $count) {
                    $j = isLang() ? 3 : 2;
                    $j = $special ? $j - 1 : $j;
                    for ($i = 0; $i < segments(); $i++) {
                        if (segment($j) or segment($j) === 0) {
                            $params[$i] = segment($j);
                            $j++;
                        }
                    }
                }
            }
        }
    }
    if (get("webSituation") !== "Active" and !SESSION("ZanUserID") and $application !== "cpanel") {
        die(get("webMessage"));
    }
    $Load->app($application);
    $controllerFile = $applicationController ? getController($applicationController, $application, TRUE) : getController(NULL, $application, TRUE);
    if (!$controllerFile) {
        getException("The application \"{$application}\" doesn't exists");
    }
    $Controller = isset($Controller) ? $Controller : getController(NULL, $application);
    if (isset($method) and count($params) > 0) {
        if (isMethod($method, $Controller)) {
            try {
                $Reflection = new ReflectionMethod($Controller, $method);
                if (!$Reflection->isPublic()) {
                    throw new RuntimeException("The called method is not public.", 100);
                }
                call_user_func_array(array($Controller, $method), $params);
            } catch (RuntimeException $e) {
                getException($e);
            }
        } else {
            if (isController($controllerFile, TRUE)) {
                if (isset($method) and count($params) > 0) {
                    if (isMethod($method, $Controller)) {
                        try {
                            $Reflection = new ReflectionMethod($Controller, $method);
                            if (!$Reflection->isPublic()) {
                                throw new RuntimeException("The called method is not public.", 100);
                            }
                            call_user_func_array(array($Controller, $method), $params);
                        } catch (RuntimeException $e) {
                            getException($e);
                        }
                    }
                }
            } else {
                if (method_exists($Controller, "index")) {
                    try {
                        $reflection = new ReflectionMethod($Controller, "index");
                        if (!$reflection->isPublic()) {
                            throw new RuntimeException("The called method is not public.", 100);
                        } elseif ($Reflection->getNumberOfRequiredParameters() > 0 and count($params) === 0) {
                            throw new RuntimeException("The called method need required parameters (" . getParameters($Reflection->getParameters()) . ").", 200);
                        }
                        call_user_func_array(array($Controller, "index"), $params);
                    } catch (RuntimeException $e) {
                        getException($e);
                    }
                } else {
                    getException("Method index doesn't exists");
                }
            }
        }
    } elseif (isset($method)) {
        if (isMethod($method, $Controller)) {
            try {
                $Reflection = new ReflectionMethod($Controller, $method);
                if (!$Reflection->isPublic()) {
                    throw new RuntimeException("The called method is not public.", 100);
                } elseif ($Reflection->getNumberOfRequiredParameters() > 0 and count($params) === 0) {
                    throw new RuntimeException("The called method need required parameters (" . getParameters($Reflection->getParameters()) . ").", 200);
                }
                $Controller->{$method}();
            } catch (RuntimeException $e) {
                getException($e);
            }
        } else {
            if (isMethod("index", $Controller)) {
                call_user_func_array(array($Controller, "index"), $params);
            } else {
                getException("Method \"index\" doesn't exists");
            }
        }
    } else {
        if (isMethod("index", $Controller)) {
            try {
                $Reflection = new ReflectionMethod($Controller, "index");
                if (!$Reflection->isPublic()) {
                    throw new RuntimeException("The called method is not public.", 100);
                } elseif ($Reflection->getNumberOfRequiredParameters() > 0 and count($params) === 0) {
                    throw new RuntimeException("The called method need required parameters (" . getParameters($Reflection->getParameters()) . ").", 200);
                }
                call_user_func_array(array($Controller, "index"), $params);
            } catch (RuntimeException $e) {
                getException($e);
            }
        } else {
            getException("Method \"index\" doesn't exists");
        }
    }
}
Esempio n. 3
0
 *  of this software and associated documentation files (the "Software"), to deal 
 *  in the Software without restriction, including without limitation the rights 
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 *  copies of the Software, and to permit persons to whom the Software is furnished 
 *  to do so, subject to the following conditions:
 *  The above copyright notice and this permission notice shall be included in all 
 *  copies or substantial portions of the Software.
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 *  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
 *  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 *  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 *  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
require_once 'runtime.php';
foreach ($_SESSION as $k => $v) {
    sess($k, null);
}
if (isset($i_next)) {
    sess('next', $i_next);
} elseif (isMethod('GET') && isset($_SERVER['HTTP_REFERER'])) {
    sess('next', $_SERVER['HTTP_REFERER']);
}
if (isSess('next')) {
    $next = sess('next', null);
    $next = str_replace('https://', 'http://', $next);
    header('Location: ' . $next);
} else {
    header('Location: /');
}
exit;
Esempio n. 4
0
function isPost()
{
    return isMethod('POST');
}