function delete($id) { // Let the file-model deal with the deletion model::factory('file')->delete($id); // and send the user back to the filelist header('location: ' . model::factory('renderer')->url('/admin/file/')); }
function logout() { // Unset the session! unset($_SESSION['user']); // And send the user to the frontpage header('Location: ' . model::factory('renderer')->url('/')); }
function test() { $database = model::factory('database'); $r = $database->safe_query('select * from user where user_id in :user_id', array('user_id' => array(329, 339))); var_Dump($r); var_dump($r->fetchAll()); }
function page($page) { list($id, $null) = explode(':', $page); $sql = 'select * from page where idpage="' . $id . '"'; list($page) = model::factory('database')->query($sql); $page_renderer = model::factory('renderer', 'pages'); $page_renderer->page = $page; model::factory('renderer')->content = $page_renderer->render('template/page.php'); }
function get_all() { $settings = array(); $r = model::factory('database')->query('select * from conf order by name asc'); foreach ($r as $s) { $settings[] = $s; } return $settings; }
function post($post) { list($id, $null) = explode(':', $post); $sql = 'select * from post where idpost="' . $id . '"'; $post = model::factory('database')->query($sql)->fetch_assoc(); $post_renderer = model::factory('renderer', 'post'); $post_renderer->post = $post; model::factory('renderer')->title = $post['title']; model::factory('renderer')->content = $post_renderer->render('template/post.php', true); }
function index() { if (isset($_POST) && !empty($_POST)) { foreach ($_POST as $key => $p) { model::factory('conf')->set($key, $p); } } $renderer = model::factory('renderer', 'settings'); $renderer->settings = model::factory('conf')->get_all(); return model::factory('renderer')->admin_content = $renderer->render('template/admin/settings/index.php', true); }
function roll() { $roll = model::factory('kmom2_randomize')->roll_dice(6); $rounds = $this->get_data($this->gamename); $current_round = count($rounds['players'][$rounds['current_player']]['rounds']); if ($current_round == 0 && !isset($rounds['players'][$rounds['current_player']]['rounds'][$current_round])) { $rounds['players'][$rounds['current_player']]['rounds'][] = array(); } if ($roll != 1) { $rounds['players'][$rounds['current_player']]['rounds'][count($rounds['players'][$rounds['current_player']]['rounds']) - 1][] = $roll; } else { $rounds['players'][$rounds['current_player']]['rounds'][count($rounds['players'][$rounds['current_player']]['rounds']) - 1] = array(); $rounds['players'][$rounds['current_player']]['rounds'][count($rounds['players'][$rounds['current_player']]['rounds'])] = array(); } $this->last_roll = $roll; $this->set_data($this->gamename, $rounds); }
function safe_query($sql, $parameters = array()) { if (!is_array($parameters)) { $parameters = array($parameters); } $statement = $this->database->prepare($sql); $statement->setFetchMode(PDO::FETCH_ASSOC); $statement->execute($parameters); if ($statement->errorCode() != '00000') { model::debug()->print_backtrace(); model::factory('log')->warning('PDO errorcode: ' . $statement->errorCode()); model::factory('log')->warning('PDO errorinfo: ' . json_encode($statement->errorInfo())); model::factory('log')->warning('PDO sql: ' . $sql); model::factory('log')->warning('PDO parameters: ' . json_encode($parameters)); } return $statement->fetchAll(); }
function get($file) { if (is_numeric($file)) { $sql = "select path, filename, type from file where idfile = '" . $file . "'"; } else { $sql = "select path, filename, type from file where filename = '" . $file . "'"; } list($data) = model::factory('database')->query($sql); header('Content-Description: File Transfer'); header('Content-Type: ' . $data['type']); $mime = explode('/', $data['type']); if ($mime[0] != 'image') { header('Content-Disposition: attachment; filename=' . $data['filename']); } header('Pragma: public'); header('Content-Length: ' . filesize(UPLOAD . $data['path'])); readfile(UPLOAD . $data['path']); die; }
function resolv($url) { // get_parts splits the url by '/' and returns an array with the parts or a single element array with '' $parts = model::factory('url')->get_parts(); if ($parts[0] == 'admin') { // Admin... Always requiring special attention... // Set the controller to be used if none is set if (!isset($parts[1]) || $parts[1] == '') { $parts[1] = 'welcome'; } // Prepare the parameters if (isset($parts[3])) { $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); }
function clear() { $this->gamedata->clear(); header('Location: ' . model::factory('renderer')->url('/kmom2/')); }
function delete($id) { $sql = 'delete from movie where movie_id=?'; model::factory('database')->safe_query($sql, $id); }
function index() { model::factory('renderer')->set('admin_content', 'hi'); }
static function check_password($userid, $password) { $count = model::factory('database')->safe_query('select user_id from user where user_id = :user_id and where password = :password', array('user_id' => $userid, 'password' => $password)); if (count($count) == 1) { return true; } else { return false; } }
<h1><?php echo $page['title']; ?> </h1> <div><?php echo $page['content']; ?> </div> <div id="page_info">Senast ändrad <?php echo date('Y m d H:i', $page['timestamp']); ?> av <?php echo model::factory('user')->get_username_by_id($page['author']); ?> </div>
function title($id) { $sql = "select title from page where idpage = '" . $id . "'"; list($data) = model::factory('database')->query($sql); if (!empty($data)) { return $data['title']; } else { return 'no page with that id'; } }
<?php /* * Debugger * This is still just a stub and will be extended in the future */ if (!defined('key')) { define('key', ''); } require_once 'init.php'; register_shutdown_function(array(model::factory('debug'), 'shutdown'));
function index() { model::factory('renderer', 'temp')->posts = model::factory('post')->get_all(); }
<?php $parts = model::factory('url')->get_parts(); $parts[1] = isset($parts[1]) ? $parts[1] : ''; $parts[2] = isset($parts[2]) ? $parts[2] : ''; switch ($parts[0]) { case 'admin': switch ($parts[1]) { case 'user': switch ($parts[2]) { default: break; } break; } break; } echo 'content';
// Login then // Split the url by a bit of magic $parts = resolv($_GET); // Change the requested method if needed $parts['method'] = $parts['method'] == 'index' ? 'login' : $parts['method']; // Instantiate the controller $login_class = new controller_login(); // Call the controller and method call_user_func_array(array($login_class, $parts['method']), $parts['params']); // Echo back any results echo model::factory('renderer')->render('template/login.html'); break; default: // Default? Boring! anyways... // resolve the parts $parts = resolv($_GET); // start the class $class = new $parts['class'](); // do the thing if (method_exists($class, 'before')) { $class->before(); } // twist it call_user_func_array(array($class, $parts['method']), $parts['params']); // do the other thing if (method_exists($class, 'after')) { $class->after(); } // Shoutout to my homeboys! echo model::factory('renderer')->render('template/main.html'); }
function before() { model::factory('renderer')->admin_mainhead = 'Adminpanel för ' . model::factory('conf')->get_value('site_name'); }
<?php if (model::factory('message')->get()) { $str = "<ul>\r\n"; foreach (model::factory('message')->get() as $class => $cont) { foreach ($cont as $m) { $str .= '<li class="' . $class . '">' . $m . '</li>'; } } $str .= "</ul>"; model::factory('message')->clear(); echo $str; } else { }
<h1><a href=":::url:/:::"><?php echo model::factory('conf')->get_value('site_name'); ?> </a></h1>
function delete($id) { $sql = 'delete from file where idfile = "' . $id . '"'; model::factory('database')->query($sql); }
function delete($id) { model: factory('user')->delete($id); header('location: ' . model::factory('renderer')->url('/admin/user/')); }
function index() { model::factory('renderer')->content = model::factory('renderer')->render('template/csource.php'); }