本文整理汇总了PHP中Rewrite类的典型用法代码示例。如果您正苦于以下问题:PHP Rewrite类的具体用法?PHP Rewrite怎么用?PHP Rewrite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Rewrite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: osc_get_osclass_section
/**
* Get section
*
* @return string
*/
function osc_get_osclass_section()
{
return Rewrite::newInstance()->get_section();
}
示例2: doModel
function doModel()
{
switch ($this->action) {
case 'login_post':
//post execution for the login
if (!osc_users_enabled()) {
osc_add_flash_error_message(_m('Users are not enabled'));
$this->redirectTo(osc_base_url());
}
osc_csrf_check();
osc_run_hook('before_validating_login');
// e-mail or/and password is/are empty or incorrect
$wrongCredentials = false;
$email = Params::getParam('email');
$password = Params::getParam('password', false, false);
if ($email == '') {
osc_add_flash_error_message(_m('Please provide an email address'));
$wrongCredentials = true;
}
if ($password == '') {
osc_add_flash_error_message(_m('Empty passwords are not allowed. Please provide a password'));
$wrongCredentials = true;
}
if ($wrongCredentials) {
$this->redirectTo(osc_user_login_url());
}
if (osc_validate_email($email)) {
$user = User::newInstance()->findByEmail($email);
}
if (empty($user)) {
$user = User::newInstance()->findByUsername($email);
}
if (empty($user)) {
osc_add_flash_error_message(_m("The user doesn't exist"));
$this->redirectTo(osc_user_login_url());
}
if (!osc_verify_password($password, isset($user['s_password']) ? $user['s_password'] : '')) {
osc_add_flash_error_message(_m('The password is incorrect'));
$this->redirectTo(osc_user_login_url());
// @TODO if valid user, send email parameter back to the login form
} else {
if (@$user['s_password'] != '') {
if (preg_match('|\\$2y\\$([0-9]{2})\\$|', $user['s_password'], $cost)) {
if ($cost[1] != BCRYPT_COST) {
User::newInstance()->update(array('s_password' => osc_hash_password($password)), array('pk_i_id' => $user['pk_i_id']));
}
} else {
User::newInstance()->update(array('s_password' => osc_hash_password($password)), array('pk_i_id' => $user['pk_i_id']));
}
}
}
// e-mail or/and IP is/are banned
$banned = osc_is_banned($email);
// int 0: not banned or unknown, 1: email is banned, 2: IP is banned, 3: both email & IP are banned
if ($banned & 1) {
osc_add_flash_error_message(_m('Your current email is not allowed'));
}
if ($banned & 2) {
osc_add_flash_error_message(_m('Your current IP is not allowed'));
}
if ($banned !== 0) {
$this->redirectTo(osc_user_login_url());
}
osc_run_hook('before_login');
$url_redirect = osc_get_http_referer();
$page_redirect = '';
if (osc_rewrite_enabled()) {
if ($url_redirect != '') {
$request_uri = urldecode(preg_replace('@^' . osc_base_url() . '@', "", $url_redirect));
$tmp_ar = explode("?", $request_uri);
$request_uri = $tmp_ar[0];
$rules = Rewrite::newInstance()->listRules();
foreach ($rules as $match => $uri) {
if (preg_match('#' . $match . '#', $request_uri, $m)) {
$request_uri = preg_replace('#' . $match . '#', $uri, $request_uri);
if (preg_match('|([&?]{1})page=([^&]*)|', '&' . $request_uri . '&', $match)) {
$page_redirect = $match[2];
if ($page_redirect == '' || $page_redirect == 'login') {
$url_redirect = osc_user_dashboard_url();
}
}
break;
}
}
}
}
require_once LIB_PATH . 'osclass/UserActions.php';
$uActions = new UserActions(false);
$logged = $uActions->bootstrap_login($user['pk_i_id']);
if ($logged == 0) {
osc_add_flash_error_message(_m("The user doesn't exist"));
} else {
if ($logged == 1) {
if (time() - strtotime($user['dt_access_date']) > 1200) {
// EACH 20 MINUTES
osc_add_flash_error_message(sprintf(_m('The user has not been validated yet. Would you like to re-send your <a href="%s">activation?</a>'), osc_user_resend_activation_link($user['pk_i_id'], $user['s_email'])));
} else {
osc_add_flash_error_message(_m('The user has not been validated yet'));
}
} else {
//.........这里部分代码省略.........
示例3: analyzeUrl
public function analyzeUrl()
{
// Check if URL is set in general
if (is_null($this->url)) {
throw new Exception("No request URL set!");
return;
}
// Check for rewrtite rules
$rewrite = new Rewrite($this->url);
$rewrite->applyRules();
if ($rewrite->getTargetUrl() != $this->url) {
if (!$rewrite->transportQueryParameter()) {
$_GET = array();
$_POST = array();
}
if ($rewrite->isRedirect()) {
$this->redirectToUrl($rewrite->getTargetUrl(), $_POST);
}
$this->setUrl($rewrite->getTargetUrl());
$this->analyzeRequest(!$rewrite->isLastForward());
}
// Check access rights to requested content
$access = new AccessOfficer("content", $this->content_id, $this->session->getUser(), $this->content_parents);
if (!$access->check()) {
// Access denied
if (!$access->getDeniedContentID()) {
// No content to be shown as 403 page set
// TODO set up default 403 (and 404) templates
throw new Exception("Access denied and no denied content defined!");
return;
}
// Should parameters be transported through the redirects / rewrites
if (!$access->transportQueryParameter()) {
$_GET = array();
$_POST = array();
}
// Show 403 error page or redirect if neccessary
$newcontent = new Content($access->getDeniedContentID());
if ($access->isRedirect() && $newcontent->getID() != $this->content_id) {
// Redirect, but keep requested URL as origin parameter
// TODO: keep origin request parameters as well!
$this->redirectToUrl("/" . $newcontent->getUrl() . "?origin=" . $this->url, $_POST);
}
$this->setUrl($newcontent->getUrl());
$this->analyzeRequest(!$access->isLastForward());
}
// TODO: HookPoints to manipulate this behaviour
}
示例4: addTableHeader
private function addTableHeader()
{
$arg_date = '&sort=date';
if (Params::getParam('sort') == 'date') {
if (Params::getParam('direction') == 'desc') {
$arg_date .= '&direction=asc';
}
}
$arg_item = '&sort=attached_to';
if (Params::getParam('sort') == 'attached_to') {
if (Params::getParam('direction') == 'desc') {
$arg_item .= '&direction=asc';
}
}
Rewrite::newInstance()->init();
$page = (int) Params::getParam('iPage');
if ($page == 0) {
$page = 1;
}
Params::setParam('iPage', $page);
$url_base = preg_replace('|&direction=([^&]*)|', '', preg_replace('|&sort=([^&]*)|', '', osc_base_url() . Rewrite::newInstance()->get_raw_request_uri()));
$this->addColumn('bulkactions', '<input id="check_all" type="checkbox" />');
$this->addColumn('file', __('File'));
$this->addColumn('action', __('Action'));
$this->addColumn('attached_to', '<a href="' . osc_esc_html($url_base . $arg_item) . '">' . __('Attached to') . '</a>');
$this->addColumn('date', '<a href="' . osc_esc_html($url_base . $arg_date) . '">' . __('Date') . '</a>');
$dummy =& $this;
osc_run_hook("admin_media_table", $dummy);
}
示例5: do410
function do410()
{
Rewrite::newInstance()->set_location('error');
header('HTTP/1.1 410 Gone');
osc_current_web_theme_path('404.php');
exit;
}
示例6: _init
public static function _init()
{
date_default_timezone_set(Conf::param('timezone'));
//设置默认时区
//地址重写
Rewrite::init();
}
示例7: item_success_item_validate
function item_success_item_validate()
{
if (Params::getParam('page') == 'item' && Params::getParam('action') == 'activate') {
$secret = Params::getParam('secret');
$id = Params::getParam('id');
$item = Item::newInstance()->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s') OR (i.fk_i_user_id = '%d'))", addslashes($id), addslashes($secret), addslashes(osc_logged_user_id()));
// item doesn't exist
if (count($item) == 0) {
Rewrite::newInstance()->set_location('error');
header('HTTP/1.1 404 Not Found');
osc_current_web_theme_path('404.php');
exit;
}
View::newInstance()->_exportVariableToView('item', $item[0]);
if ($item[0]['b_active'] == 0) {
// ACTIVETE ITEM
$mItems = new ItemActions(false);
$success = $mItems->activate($item[0]['pk_i_id'], $item[0]['s_secret']);
if ($success) {
osc_add_flash_ok_message(_m('The listing has been validated'));
item_success_redirect(Item::newInstance()->findByPrimaryKey($item[0]['pk_i_id']));
exit;
} else {
osc_add_flash_error_message(_m("The listing can't be validated"));
}
} else {
osc_add_flash_warning_message(_m('The listing has already been validated'));
}
osc_redirect_to(osc_item_url());
}
}
示例8: __construct
public function __construct($lang = array())
{
$this->location = Rewrite::newInstance()->get_location();
$this->section = Rewrite::newInstance()->get_section();
$this->aLevel = array();
$this->setTitles($lang);
}
示例9: social_bookmarks_header
function social_bookmarks_header()
{
$location = Rewrite::newInstance()->get_location();
$section = Rewrite::newInstance()->get_section();
if ($location == 'item' && $section == '') {
echo '
<style type="text/css">
.social-bookmarks ul { margin: 10px 0; list-style: none; }
.social-bookmarks ul li { float: left; }
.social-bookmarks .clear { clear:both; }
</style>';
}
}
示例10: doModel
function doModel()
{
$user_menu = false;
if(Params::existParam('route')) {
$routes = Rewrite::newInstance()->getRoutes();
$rid = Params::getParam('route');
$file = '../';
if(isset($routes[$rid]) && isset($routes[$rid]['file'])) {
$file = $routes[$rid]['file'];
$user_menu = $routes[$rid]['user_menu'];
}
} else {
// DEPRECATED: Disclosed path in URL is deprecated, use routes instead
// This will be REMOVED in 3.4
$file = Params::getParam('file');
}
// valid file?
if( strpos($file, '../') !== false || strpos($file, '..\\') !==false || stripos($file, '/admin/') !== false ) { //If the file is inside an "admin" folder, it should NOT be opened in frontend
$this->do404();
return;
}
// check if the file exists
if( !file_exists(osc_plugins_path() . $file) ) {
$this->do404();
return;
}
osc_run_hook('custom_controller');
$this->_exportVariableToView('file', $file);
if($user_menu) {
if(osc_is_web_user_logged_in()) {
Params::setParam('in_user_menu', true);
$this->doView('user-custom.php');
} else {
$this->redirectTo(osc_user_login_url());
}
} else {
$this->doView('custom.php');
}
}
示例11: pop_redirect_404
function pop_redirect_404($header_text = '')
{
if ($header_text != '') {
View::newInstance()->_exportVariableToView('pop_404_header_text', $header_text);
}
Rewrite::newInstance()->set_location('error');
header('HTTP/1.1 404 Not Found');
osc_current_web_theme_path('404.php');
exit;
}
示例12: define
<?php
define('WWW_ROOT', __DIR__);
require __DIR__ . '/../log/Log.class.php';
require __DIR__ . '/Rewrite.class.php';
Log::getLogger(array('level' => Log::ALL));
class Render implements RewriteHandle
{
public function process($file)
{
echo file_get_contents($file);
}
}
$rewrite = new Rewrite(__DIR__ . '/test');
$rewrite->addConfigFile('home.conf');
$rewrite->addConfigFile('common.conf');
$rewrite->addRewriteHandle('tpl', new Render());
$rewrite->dispatch('/home/test');
示例13:
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'oc-load.php';
//create object
$rewrite = Rewrite::newInstance();
$rewrite->clearRules();
/*****************************
********* Add rules *********
*****************************/
// Contact rules
$rewrite->addRule('^contact/?$', 'index.php?page=contact');
// Feed rules
$rewrite->addRule('^feed$', 'index.php?page=search&sFeed=rss');
$rewrite->addRule('^feed/(.+)$', 'index.php?page=search&sFeed=$1');
// Language rules
$rewrite->addRule('^language/(.*?)/?$', 'index.php?page=language&locale=$1');
// Search rules
$rewrite->addRule('^search/(.*)$', 'index.php?page=search&sPattern=$1');
$rewrite->addRule('^s/(.*)$', 'index.php?page=search&sPattern=$1');
// Item rules
示例14: do404
function do404()
{
Rewrite::newInstance()->set_location('error');
header('HTTP/1.1 404 Not Found');
osc_current_web_theme_path('404.php');
}
示例15: allSeo_title_filter
function allSeo_title_filter($text)
{
$location = Rewrite::newInstance()->get_location();
$section = Rewrite::newInstance()->get_section();
switch ($location) {
// Listing page and page related to listings
case 'item':
switch ($section) {
case 'item_add':
$text = __('Publish a listing', 'all_in_one');
break;
case 'item_edit':
$text = __('Edit your listing', 'all_in_one');
break;
case 'send_friend':
$text = __('Send to a friend', 'all_in_one') . Delimiter() . osc_item_title();
break;
case 'contact':
$text = __('Contact seller', 'all_in_one') . Delimiter() . osc_item_title();
break;
default:
$text = SeoGenerateTitleListing();
break;
}
break;
// Static page
// Static page
case 'page':
if (GetPageTitle() == '') {
$text = osc_static_page_title();
} else {
$text = GetPageTitle();
}
break;
// Error page
// Error page
case 'error':
$text = __('Page not found', 'all_in_one');
break;
// Search & Category page
// Search & Category page
case 'search':
$region = osc_search_region();
$city = osc_search_city();
$pattern = osc_search_pattern();
$category = osc_search_category_id();
$s_page = '';
$i_page = Params::getParam('iPage');
if ($i_page != '' && $i_page > 1) {
$s_page = Delimiter() . __('page', 'all_in_one') . ' ' . $i_page;
}
$result = SeoGenerateTitleCategory();
if ($result == '') {
$result = __('Search result', 'all_in_one');
}
$text = $result . $s_page;
break;
// Login page
// Login page
case 'login':
switch ($section) {
case 'recover':
$text = __('Recover your password', 'all_in_one');
default:
$text = __('Login into your account', 'all_in_one');
}
break;
// Registration page
// Registration page
case 'register':
$text = __('Create a new account', 'all_in_one');
break;
// User page and pages related to user
// User page and pages related to user
case 'user':
switch ($section) {
case 'dashboard':
$text = __('Dashboard', 'all_in_one');
break;
case 'items':
$text = __('Manage my listings', 'all_in_one');
break;
case 'alerts':
$text = __('Manage my alerts', 'all_in_one');
break;
case 'profile':
$text = __('Update my profile', 'all_in_one');
break;
case 'pub_profile':
$text = __('Public profile of', 'all_in_one') . ' ' . ucfirst(osc_user_name());
break;
case 'change_email':
$text = __('Change my email', 'all_in_one');
break;
case 'change_password':
$text = __('Change my password', 'all_in_one');
break;
case 'forgot':
$text = __('Recover my password', 'all_in_one');
break;
//.........这里部分代码省略.........