function new_page() { if (isset($_POST) && !empty($_POST)) { $id = model::factory('page')->add_page($_POST['title'], $_POST['body'], model_user::instance()->getId(), $sim); header('location: ' . model::factory('renderer')->url('/admin/page/edit/' . $id)); } $renderer = model::factory('renderer', 'page'); model::factory('renderer')->add_css('/css/form.css'); return model::factory('renderer')->admin_content = $renderer->render('template/admin/page/edit.php'); }
function new_file() { // If a form was posted, add a file to the site. if (isset($_POST) && !empty($_POST)) { $id = model::factory('file')->add_file($_FILES['file']['name'], $_POST['title'], $_FILES['file']['type'], file_get_contents($_FILES['file']['tmp_name']), model_user::instance()->getId()); // and send user to file list header('location: ' . model::factory('renderer')->url('/admin/file/')); } // if not render an addition form $renderer = model::factory('renderer', 'post'); model::factory('renderer')->add_css('/css/form.css'); model::factory('renderer')->admin_content = $renderer->render('template/admin/file/edit.php', true); }
function login() { // Check to see if there are any login-attempts if (isset($_POST) && !empty($_POST)) { // If there is, initialize a user-model and check username and password against the database. $user = model_user::instance(); $user->login_by_username_and_password($_POST['username'], $_POST['password']); //Are we logged in? if ($user->logged_in()) { // Yes! Ship the user to adminpanel! header('location: ' . model::factory('renderer')->url('/admin')); } else { // Ha! You wish. Back to where you came from! header('location: ' . $_SERVER['HTTP_REFERER']); } } // If no login attempt do some cosmetic stuff. // Set page title using pagename from database. model::factory('renderer')->title = 'Logga in - ' . model::factory('conf')->get_value('site_name'); // Also provide a short text to tell whether or not the user is logged in or not. model::factory('renderer')->logged_in = model_user::instance()->logged_in() ? 'inloggad' : 'INTE inloggad'; }
$params = explode('/', $parts[3]); } else { $params = array(); } // Instantiate the class $class_name = 'controller_' . $parts[0] . '_' . $parts[1]; $class = new $class_name(); // And finish with the method $method = isset($parts[2]) && !empty($parts[2]) ? $parts[2] : 'index'; } else { // if parts is empty, use the default welcome-controller if ($parts[0] == '') { $parts[0] = 'welcome'; } // Prepare the parameters if (isset($parts[2])) { $params = explode('/', $parts[2]); } else { $params = array(); } // Instantiate the class $class_name = 'controller_' . $parts[0]; $class = new $class_name(); // And finish with the method $method = isset($parts[1]) && !empty($parts[1]) ? $parts[1] : 'index'; } // Once done. return an array with the stuff return array('class' => $class, 'params' => $params, 'method' => $method); } model_user::instance();
define('key', ''); } // Include init.php if not already included earlier. require_once 'init.php'; // Change the session-timeout to something from the database. ini_set("session.cookie_lifetime", $conf['session_timeout']); // and start it session_start(); // Initialize a new global rendering object accessible from model::factory('renderer') $renderer = new model_renderer(); // Do some magic with the url $parts = model::factory('url')->get_parts(); switch ($parts[0]) { case 'admin': // Admin? are you sure you are admin? if (model_user::instance()->isAdmin()) { // Seems like it. $parts = resolv($_GET); // Which controller do you want? Ah yes! That one. $class = new $parts['class'](); // Run the before part if there is one. if (method_exists($class, 'before')) { $class->before(); } // Alright, enough foreplay. Call the class already and its method. And don't forget the parameters! call_user_func_array(array($class, $parts['method']), $parts['params']); // Echo back the results. echo model::factory('renderer')->render('template/admin/main.html'); break; } case 'login':