protected function authenticate($username, $password) { if (!($config = $this->needsAuthentification(Router::uri()))) { return true; } if (empty($username) || empty($password)) { return false; } // from file .htpasswd if (is_string($config['logins'])) { $filename = $config['logins']; if (!file_exists($filename)) { die($filename . ' not found'); } foreach (file($filename) as $line) { list($user, $pass) = explode(':', $line); if ($user == $username && $pass == crypt($password, substr($password, 0, 2))) { return true; } } // from plain config } else { foreach ($config['logins'] as $u => $p) { if ($username == $u && $p == $password) { return true; } } } return false; }
public static function parseUri() { self::$default_uri = self::$uri = self::_getUri(); $router = Config::get('*', 'router'); if (is_array($router) && !empty($router)) { if (isset($router['default']['controller']) && ($controller = $router['default']['controller'])) { self::setController($controller); } if (isset($router['default']['action']) && ($action = $router['default']['action'])) { self::setAction($action); } unset($router['default']); foreach ($router as $method => $arr) { if ($method == strtolower($_SERVER['REQUEST_METHOD']) || $method === 'any') { foreach ($arr as $key => $val) { $key = str_replace(array('.', '/'), array('\\.', '\\/'), $key); if (preg_match('#^' . $key . '$#', self::$uri)) { if (strpos($val, '$') !== FALSE and strpos($key, '(') !== FALSE) { self::$uri = preg_replace('#^' . $key . '$#', $val, self::$uri); self::$uri = preg_replace('#//+#', '/', self::$uri); self::$uri = preg_replace('#\\.[\\s./]*/#', '', self::$uri); self::$uri = trim(self::$uri, '/'); } else { self::$uri = trim($val, '/'); } break; } } } continue; } } self::_setRouter(self::$uri); }
public function beforeRender() { $this->attributes->action = Router::uri('blogSearch', array('q' => '')); if (!empty($this->controller->params['q'])) { $this->q->value($this->controller->params['q']); } return parent::beforeRender(); }
private function load_controller() { // Uri format: app/controller/method thus making uri[1] the controller // If no controller is set through the uri array then set it to default if (Router::uri(1) === null) { Router::uri(1, Config::$config[$this->data['app']['name']]['default_controller']); } require DOC_ROOT . 'apps/' . $this->app_name . '/controllers/controller.' . Router::uri(1) . '.php'; $controller_name = String::uc_slug(Router::uri(1), '_') . '_Controller'; $controller_obj = new $controller_name($this->data); }
public function __construct($data) { $this->data = $data; $method = Router::uri(2); $dm = $this->default_method; // If no method is set go to default if (is_null($method)) { $this->{$dm}(); } else { $this->{$method}(); } }
private static function url_to_array($uri) { self::$uri = urldecode(trim($uri, '/')); $uri_parts = explode('?', self::$uri); $first_part = $uri_parts[0]; $uri_array = explode('/', $first_part); $uri_elements = array(); // Удаляет все специальные символы и кирилицу из элементов массива (заменяет на "_"), чтоб срабатывало исключение foreach ($uri_array as $val) { $uri_element = preg_replace("/[^a-zA-Z0-9]/", "_", $val); $uri_elements[] = $uri_element; } self::$url_array = $uri_elements; //Debugger::PrintR($uri_elements); return $uri_elements; }
public function check($testRoute) { foreach ($this->Permissions as $Permission) { $regexp = '@' . $Permission->rule . '@i'; Log::write(Log::VERBOSE, sprintf('%s: checking "%s" against "%s"', get_class($this), $testRoute, $regexp)); if (preg_match($regexp, $testRoute)) { return true; } } if ($this->controller instanceof AdminController) { $this->controller->redirect(Router::uri('admin')); } else { $this->controller->redirect(Router::uri('root')); } return false; }
public static function uri_to_array($uri = NULL) { // Not defaulting to server request uri allows some testing to be done if (is_null($uri)) { $uri = $_SERVER['REQUEST_URI']; } // Lowercase the entire string then strip http, https and ftp (just for fun) our of uri and then explode by "/" self::$uri = explode('/', trim(preg_replace('/([.*^?])\\??(.*)/', '$1', trim(str_replace(array('http://', 'https://', 'ftp://'), '', strtolower($uri), $count), '/')), '?/')); // We want to rebuild the array without the actual domain if ($count > 0) { array_shift(self::$uri); } $new_uri = array(); foreach (self::$uri as $key => $singleton) { // Strip the string of all special characters $new_uri[] = String::clean($singleton, '_'); } // Replace uri with the new modified version self::$uri = $new_uri; return self::$uri; }
<div class="toolbar"> <?php echo $HTML->link(Router::uri('root'), __('Frontend'), array('class' => 'back flip')); echo $HTML->tag('h1', $pageTitle); echo $HTML->link(Router::uri('adminLogout'), __('Logout'), array('class' => 'button flip')); ?> </div> <ul class="rounded"> <li class="arrow"><?php echo $HTML->link(Router::uri('adminWall'), __('Aktuelles/Wall')); ?> </li> </ul> <ul class="rounded"> <li class="arrow"> <?php echo $HTML->link(Router::url('adminNode'), __('Seiten')); ?> <?php if (!empty($NodeTotalCount)) { echo $HTML->tag('small', $NodeTotalCount, array('class' => 'counter')); } ?> </li> <li class="arrow"> <?php echo $HTML->link(Router::url('adminBlogPost'), __('Blogeinträge')); ?> <?php if (!empty($BlogPostTotalCount)) { echo $HTML->tag('small', $BlogPostTotalCount, array('class' => 'counter'));
<h1><?php echo __('Fehler 404 - Seite nicht gefunden'); ?> </h1> <p> Die aufgerufene Seite ist leider nicht mehr auffindbar. Bitte überprüfe die URL und probier es noch mal wenn du willst. </p> <p> Die beste Möglichkeit schnell weiter zu lesen ist allerdings auf die <?php echo $HTML->link(Router::uri('root'), 'Startseite'); ?> zurück zu gehen. </p> <p> Viel Spass weiterhin! </p>
public function edit($id = null) { $this->MediaFile = parent::edit($id); $this->data->set('pageTitle', $this->MediaFile->getText('title', $this->MediaFile->filename)); // language and texts foreach ($this->Languages as $Language) { $TextModel = $this->MediaFile->{'Text' . String::ucFirst($Language->id)}; $TextModel->MediaFile = $this->MediaFile; $TextModel->User = $this->UserLogin->User; $Form = new AdminMediaTextForm(); $Form->attributes->set('name', 'AdminMediaTextForm' . ucfirst($Language->id)); $Form->attributes->set('id', 'AdminMediaTextForm' . ucfirst($Language->id)); $Form->init($this); $Form->startup(); $Form->configure(); $Form->fromModel($TextModel); $Form->attributes->set('action', Router::uri()); $Form->language_id->value($Language->id); $this->data->set('AdminMediaTextForm' . String::ucFirst($Language->id), $Form); if ($Form->ok() && $this->request->data['language_id'] == $Language->id) { $Form->toModel($TextModel); if (!$TextModel->save()) { $Form->errors = $TextModel->validationErrors; } else { $Form->success = __('Erfolgreich :1 gespeichert', $Language->get('name'), FlashMessageType::SUCCESS); $this->redirect(Router::url()); } } } // newly uploaded files $this->AdminMediaFileForm->file->mandatory(false); if ($this->AdminMediaFileForm->ok()) { $this->AdminMediaFileForm->toModel($this->MediaFile); if ($newFile = $this->AdminMediaFileForm->file->value()) { $this->MediaFile->replace($newFile, $this->AdminMediaFileForm->file->originalFilename()); } if (!$this->MediaFile->save()) { $this->AdminMediaFileForm->errors = $this->MediaFile->validationErrors; } else { $this->FlashMessage->set(__('Erfolgreich gespeichert'), FlashMessageType::SUCCESS); } } }
<h1><?php echo __('Gruppen'); ?> </h1> <ul class="breadcrumb"> <li><?php echo $HTML->link(Router::getRoute('admin'), __('Home')); ?> </li> <li><?php echo $HTML->link(Router::uri('adminScaffold', array('controller' => $controller)), __('Gruppen & Rechte')); ?> </li> <li><?php echo __('Gruppe erstellen'); ?> </li> </ul> <?php echo $AdminUserGroupForm;
public function search($q = null, $fields = array()) { if (isset($this->request->data['q'])) { $this->redirect(Router::uri('blogSearch', array('q' => $this->request->data['q']))); } parent::search($q, array('text', 'headline', 'tags')); $this->action = 'index'; $this->data->set('q', $q); return true; }
static function init() { $uri = str_replace(Conf::$BASE_URL, '', 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); self::$params = $_GET || []; self::$uri = strtok($uri, '?'); }
<?php require 'core/master.inc.php'; // Remap URI with routes if needed Router::new_uri(Config::$config['core']['routes']); // If no app is set through the uri array then set it to default if (is_null(Router::uri(0))) { Router::uri(0, Config::$config['core']['default_app']); } // If app doesn't exist then show error if (!in_array(Router::uri(0), Config::$config['core']['installed_apps'])) { die('<h1>Opps</h1> <p>The app <strong>"' . Router::uri(0) . '"</strong> does not exist.</p>'); } $init = new App_Init(Router::uri(0)); // initiate init class
public function edit() { $this->data['table'] = String::clean(Router::uri(3), '_'); $scaffolder = new Scaffolder($this->data['table'], intval(Router::uri(4))); $scaffolder->iterate(); $this->data['form'] = $scaffolder->display(); if (isset($_POST['submit'])) { if ($scaffolder->save_object()) { if (empty($_POST['redirect'])) { Flash::set('<div class="sub_menu_extension"><strong>Your entry was added succefully! You can edit it below.</strong></div>'); Core_Helpers::redirect('/admin/edit/' . Router::uri(3) . '/' . $scaffolder->current_id . '/'); } else { Flash::set('<div class="sub_menu_extension"><strong>Your entry was added succefully!</strong></div>'); Core_Helpers::redirect($_POST['redirect']); } } } $this->load_template('edit'); }
<?php echo __('Sie können Benutzer in verschiedene Gruppen stecken um deren Zugriffsrechte zu verändern. Jede Gruppe hat andere Zugriffsrechte zu bestimmten Bereichen.'); ?> </p> <?php if (empty($UserGroups)) { ?> <p class="hint"> <?php echo __('Es wurden noch keine Gruppen angelegt.'); ?> </p> <?php } else { ?> <ul id="UserGroups"> <?php foreach ($UserGroups as $UserGroup) { ?> <li> <?php echo $HTML->link(Router::uri('adminScaffoldId', array('controller' => $controller, 'id' => $UserGroup->id, 'action' => 'edit')), $UserGroup->get('name')); ?> </li> <?php } ?> </ul> <?php }
public function build($slug, $search_value) { // This is to check if the slug being given matches one in the index_information table, if not then we'll check later if it's even a table $index_info = new Index_Information(); if ($index_info->select(array('slug' => strtolower($slug)))) { $this->data['page_title'] = $index_info->title; $this->data['table'] = $index_info->table; // If no custom sql is in the table then just use the default select * statement if (is_null($index_info->sql) || empty($index_info->sql)) { $index_info->sql = '%select%'; } // Check if we should do a search... if (isset($search_value)) { // If there's already a where statement we need an AND if (preg_match('/where/i', $index_info->sql)) { $index_info->sql .= 'AND '; } $index_info->sql .= ''; } // Next, get the total number of items in the database // I know this isn't the most efficient count rows but because this can be a custom query, i don't know how else... $num_entries = Database::get_instance()->num_rows(str_replace('%select%', 'SELECT * FROM ' . $index_info->table, $index_info->sql)); if ($num_entries == false) { $num_entries = 0; } // Initialize the Pager object $pager = new Pagination($current_page, $per_page, $num_entries); // Converting string in url to what should match a db object $db_object_name = String::uc_slug($index_info->table, '_', '_'); // If $db_object doesn't match a current class then something's wrong... if (!class_exists($db_object_name)) { die('<h2>Sorry, ' . $db_object_name . ' does not exist.</h2>'); } $db_object = new $db_object_name(); $this->data['fields'] = $db_object->get_fields(); // TODO: Parameter for added columns should be included, must add field to table and model $this->data['objects'] = $db_object->select_many($index_info->sql . ' LIMIT ' . $pager->first_record . ', ' . $pager->per_page); /* TEMPLATE FIELD FORMAT: <table>header html... %startloop% <tr>loop info</tr> %fieldname% %fieldname% %endloop% </table>footer html */ $this->data['template']['header'] = preg_match('/(.*?)%startloop%/im', $index_info->template, $matches); $this->data['template']['header'] = $matches[1]; $this->data['template']['loop'] = preg_match('/%startloop%(.*?)%endloop%/im', $index_info->template, $matches); $this->data['template']['loop'] = $matches[1]; $this->data['template']['footer'] = preg_match('/%endloop%(.*?)/im', $index_info->template, $matches); $this->data['template']['footer'] = $matches[1]; } else { $this->data['table'] = String::clean($slug, '_'); // Converting string in url to what should match a db object $db_object_name = String::uc_slug($slug, '_', '-'); $db_object = new $db_object_name(); $this->data['fields'] = $db_object->get_fields(); // If $db_object doesn't match a current class then something's wrong... if (!class_exists($db_object_name)) { die('<h2>Sorry, ' . $db_object_name . ' does not exist.</h2>'); } // This is where we'll store the WHERE info the sql statement $where = ''; // Check if we should do a search... if (isset($search_value)) { $where .= ' WHERE '; foreach ($this->data['fields'] as $field) { $where .= '(`' . $field . '` LIKE \'%' . Database::get_instance()->escape($search_value) . '%\') OR '; } $where = ' ' . trim($where, 'OR '); } // Next, get the total number of items in the database $this->data['num_entries'] = $num_entries = Database::get_instance()->get_value('SELECT COUNT(*) FROM `' . $this->data['table'] . '`' . $where); // Initialize the Pager object $pager = new Pagination($current_page, $per_page, $num_entries); $this->data['objects'] = $db_object->select_many('%select%' . $where . ' ORDER BY ' . $db_object->id_column_name . ' DESC LIMIT ' . $pager->first_record . ', ' . $pager->per_page); $this->data['page_title'] = String::uc_slug($slug, ' ', '_'); $this->data['template']['header'] = '<table class="default_table"><tr><th class="entry_actions_wrapper"></th>'; $this->data['template']['footer'] = '</table>'; $this->data['template']['loop'] = '<tr class="entry_row" id="entry_%id%"><td class="entry_actions_wrapper"><div class="entry_actions"><a href="' . WEB_ROOT . Router::uri(0) . '/delete/' . $slug . '/%id%/" class="delete" rel="facebox.default_modal">Delete</a><a href="' . WEB_ROOT . Router::uri(0) . '/edit/' . $slug . '/%id%/" class="edit">Edit</a></div></td>'; // We only want to return the first 4 fields, more than that and it might be too long if (count($this->data['fields']) > 4) { $this->data['fields'] = array_slice($this->data['fields'], 0, 4); } foreach ($this->data['fields'] as $field) { $this->data['template']['header'] .= '<th>' . String::uc_slug($field, ' ', '_') . '</th>'; $this->data['template']['loop'] .= '<td>%' . $field . '%</td>'; } $object_filter = new Object_Filter(); $this->data['objects'] = $object_filter->for_display($this->data['table'], $this->data['fields'], $this->data['objects']); // Final column for edit and delete buttons $this->data['template']['header'] .= '</tr>'; $this->data['template']['loop'] .= '</tr>'; $this->data['template']['header'] .= '</tr>'; } }
<?php // Determine our absolute document root, includes trailing slash define('DOC_ROOT', realpath(dirname(__FILE__) . '/../') . '/'); include DOC_ROOT . 'tests/autoload.php'; // START TEST /////// include DOC_ROOT . 'core/class.router.php'; Router::new_uri(array('login' => 'auth/index/login/', 'recover' => 'auth/index/recover/', 'logout' => 'auth/index/logout/'), 'http://konnectapp.com/login/'); var_dump(Router::uri(2));
<div class="toolbar"> <?php echo $HTML->link(Router::uri('root'), __('Frontend'), array('class' => 'back flip')); echo $HTML->tag('h1', $pageTitle); ?> </div> <div class="info"> <?php echo $this->element('jqtouch/form', array('Form' => $LoginForm)); ?> </div>