Example #1
0
/**
 * Builds a URL relative to the GlotPress' domain root.
 *
 * @param mixed $path string path or array of path components
 * @param array $query associative array of query arguments (optional)
 */
function gp_url($path = '/', $query = null)
{
    $base = gp_url_path(gp_url_public_root());
    $base = '/' . ltrim($base, '/');
    // Make sure `$base` has always a leading slash.
    return apply_filters('gp_url', gp_url_add_path_and_query($base, $path, $query), $path, $query);
}
Example #2
0
 /**
  * Returns the current request URI path, relative to
  * the application URI and without the query string
  */
 function request_uri()
 {
     $subdir = rtrim(gp_url_path(), '/');
     if (preg_match("@^{$subdir}(.*?)(\\?.*)?\$@", $_SERVER['REQUEST_URI'], $match)) {
         return urldecode($match[1]);
     }
     return false;
 }
Example #3
0
 public function route()
 {
     global $wp_query;
     $real_request_uri = $this->request_uri();
     $api_request_uri = $real_request_uri;
     $request_method = strtolower($this->request_method());
     $api = gp_startswith($real_request_uri, '/' . $this->api_prefix . '/');
     if ($api) {
         $real_request_uri = substr($real_request_uri, strlen($this->api_prefix) + 1);
     }
     $url_path = gp_url_path(gp_url_public_root());
     // If the request URL doesn't match our base URL, don't bother trying to match
     if ($url_path && !gp_startswith($_SERVER['REQUEST_URI'], $url_path)) {
         return;
     }
     foreach (array($api_request_uri, $real_request_uri) as $request_uri) {
         foreach ($this->urls as $re => $func) {
             foreach (array('get', 'post', 'head', 'put', 'delete') as $http_method) {
                 if (gp_startswith($re, $http_method . ':')) {
                     if ($http_method != $request_method) {
                         continue;
                     }
                     $re = substr($re, strlen($http_method . ':'));
                     break;
                 }
             }
             if (preg_match("@^{$re}\$@", $request_uri, $matches)) {
                 /*
                  * WordPress will be returning a 404 status header by default for GlotPress pages
                  * as nothing is found by WP_Query.
                  * This overrides the status header and the `$is_404` property of WP_Query if we've matched
                  * something here. Route controllers still can return a 404 status header.
                  */
                 status_header('200');
                 $wp_query->is_404 = false;
                 if (is_array($func)) {
                     list($class, $method) = $func;
                     $route = new $class();
                     $route->api = $api;
                     $route->last_method_called = $method;
                     $route->class_name = $class;
                     GP::$current_route =& $route;
                     $route->before_request();
                     $route->request_running = true;
                     // make sure after_request() is called even if we $this->exit_() in the request
                     register_shutdown_function(array(&$route, 'after_request'));
                     call_user_func_array(array($route, $method), array_slice($matches, 1));
                     $route->after_request();
                     $route->request_running = false;
                 } else {
                     call_user_func_array($func, array_slice($matches, 1));
                 }
                 exit;
             }
         }
     }
     gp_tmpl_404();
 }
Example #4
0
/**
 * Builds a URL relative to the GlotPress base
 * 
 * @param mixed $path string path or array of path components
 * @param array $query associative array of query arguments (optional)
 */
function gp_url($path, $query = null)
{
    $url = gp_url_join(gp_url_path(gp_get_option('url')), $path);
    if ($query && is_array($query)) {
        $url = add_query_arg(urlencode_deep($query), $url);
    } elseif ($query) {
        $url .= '?' . ltrim($query, '?');
    }
    return apply_filters('gp_url', $url, $path, $query);
}
Example #5
0
function gp_populate_notices()
{
    GP::$redirect_notices = array();
    $prefix = '_gp_notice_';
    foreach ($_COOKIE as $key => $value) {
        if (gp_startswith($key, $prefix) && ($suffix = substr($key, strlen($prefix)))) {
            GP::$redirect_notices[$suffix] = $value;
        }
        setcookie($key, '', 0, gp_url_path());
    }
}
/**
 * Return the rewrite rules
 *
 * @return string Rewrite rules
 */
function gp_mod_rewrite_rules()
{
    $path = gp_add_slash(gp_url_path(guess_uri()));
    return '
# BEGIN GlotPress
	<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteBase ' . $path . '
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule . ' . $path . 'index.php [L]
	</IfModule>
# END GlotPress';
}
Example #7
0
/**
 * Builds a URL relative to the GlotPress' domain root.
 *
 * @param mixed $path string path or array of path components
 * @param array $query associative array of query arguments (optional)
 */
function gp_url($path = '/', $query = null)
{
    $base = gp_url_path(gp_url_public_root());
    $base = '/' . ltrim($base, '/');
    // Make sure `$base` has always a leading slash.
    /**
     * Filter a URL relative to GlotPress' domain root.
     *
     * @since 1.0.0
     *
     * @param string        $base The base path.
     * @param string|array  $path The GlotPress path or the components as an array.
     * @param string $query The query part of the URL.
     */
    return apply_filters('gp_url', gp_url_add_path_and_query($base, $path, $query), $path, $query);
}
Example #8
0
/**
 * It is possible to define this in wp-config.php and it will be used as the domain for all cookies.
 * Set it carefully for sharing cookies amonst subdomains
 *
 * @link http://curl.haxx.se/rfc/cookie_spec.html
 */
if (!defined('GP_COOKIE_DOMAIN')) {
    define('GP_COOKIE_DOMAIN', false);
}
$_auth_class_name = gp_const_get('AUTH_CLASS', 'WP_Auth');
if (!class_exists($_auth_class_name)) {
    require_once gp_const_get('AUTH_CLASS_FILE', BACKPRESS_PATH . 'class.wp-auth.php');
    $cookies = array();
    $cookies['auth'][] = array('domain' => GP_COOKIE_DOMAIN, 'path' => gp_url_path(), 'name' => gp_const_get('GP_AUTH_COOKIE', 'glotpress_auth'));
    $cookies['secure_auth'][] = array('domain' => GP_COOKIE_DOMAIN, 'path' => gp_url_path(), 'name' => gp_const_get('GP_SECURE_AUTH_COOKIE', 'glotpress_sec_auth'), 'secure' => 'true');
    $cookies['logged_in'][] = array('domain' => GP_COOKIE_DOMAIN, 'path' => gp_url_path(), 'name' => gp_const_get('GP_LOGGED_IN_COOKIE', 'glotpress_logged_in'));
    $wp_auth_object = new $_auth_class_name($gpdb, $wp_users_object, $cookies);
    unset($cookies);
}
unset($_auth_class_name);
require_once GP_PATH . GP_INC . 'warnings.php';
require_once GP_PATH . GP_INC . 'validation.php';
require_once GP_PATH . GP_INC . 'advanced-permissions.php';
require_once GP_PATH . GP_INC . 'thing.php';
require_once GP_PATH . GP_INC . 'things/original.php';
require_once GP_PATH . GP_INC . 'things/permission.php';
require_once GP_PATH . GP_INC . 'things/project.php';
require_once GP_PATH . GP_INC . 'things/translation-set.php';
require_once GP_PATH . GP_INC . 'things/translation.php';
require_once GP_PATH . GP_INC . 'things/user.php';
require_once GP_PATH . GP_INC . 'things/validator-permission.php';
 /**
  * @ticket gh-203
  */
 function test_gp_url_path_returns_empty_string_if_url_has_no_path()
 {
     $this->assertSame('', gp_url_path('http://glotpress.org'));
 }
Example #10
0
function gp_populate_notices()
{
    GP::$redirect_notices = array();
    $prefix = '_gp_notice_';
    $cookie_path = '/' . ltrim(gp_url_path(), '/');
    // Make sure that the cookie path is never empty.
    foreach ($_COOKIE as $key => $value) {
        if (gp_startswith($key, $prefix) && ($suffix = substr($key, strlen($prefix)))) {
            GP::$redirect_notices[$suffix] = wp_unslash($value);
            gp_set_cookie($key, '', 0, $cookie_path);
        }
    }
}
Example #11
0
/**
 * Return the IIS rewrite rules
 *
 * @return string Rewrite rules
 */
function gp_iis_rewrite_rules()
{
    $path = gp_add_slash(gp_url_path(guess_uri()));
    return '
<configuration>
    <system.webServer>
		<rewrite>
		  <rules>
			<rule name="GlotPress Rewrite Rule" stopProcessing="true">
			  <match url="." ignoreCase="false" />
			  <conditions>
				<!--# BEGIN GlotPress-->
				<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
				<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
			  </conditions>
			  <action type="Rewrite" url="' . $path . 'index.php" />
			</rule>
		  </rules>
		</rewrite>
    </system.webServer>
</configuration>';
}
Example #12
0
<?php

/**
 * Landing point for GlotPress installation
 */
define('GP_INSTALLING', true);
require_once 'gp-load.php';
require_once BACKPRESS_PATH . 'class.bp-sql-schema-parser.php';
require_once GP_PATH . GP_INC . 'install-upgrade.php';
require_once GP_PATH . GP_INC . 'schema.php';
$show_htaccess_instructions = true;
if (gp_get_option('gp_db_version') <= gp_get_option_from_db('gp_db_version') && !isset($_GET['force'])) {
    $success_message = __('You already have the latest version, no need to upgrade!');
    $errors = array();
    $show_htaccess_instructions = false;
} else {
    if (gp_get('action', 'install') == 'upgrade') {
        $success_message = __('GlotPress was successully upgraded!');
        $errors = gp_upgrade();
    } else {
        $success_message = __('GlotPress was successully installed!');
        $errors = gp_install();
    }
}
// TODO: check if the .htaccess is in place or try to write it
$show_htaccess_instructions = $show_htaccess_instructions && empty($errors);
$path = gp_add_slash(gp_url_path());
$action = gp_get('action', 'install');
gp_tmpl_load('install', get_defined_vars());
Example #13
0
    define('WP_AUTH_COOKIE_VERSION', 2);
}
// WP_Pass
if (!class_exists('WP_Pass')) {
    require_once BACKPRESS_PATH . 'class.wp-pass.php';
}
// We assume all variables set in this file will be global.
// If the file is inovked inside a function, we will lose them all.
// So, make all local variables, global
gp_set_globals(get_defined_vars());
if (!class_exists('WP_Auth')) {
    require_once BACKPRESS_PATH . 'class.wp-auth.php';
    $cookies = array();
    $cookies['auth'][] = array('domain' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '', 'path' => gp_url_path(), 'name' => gp_const_get('GP_AUTH_COOKIE', 'glotpress_auth'));
    $cookies['secure_auth'][] = array('domain' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '', 'path' => gp_url_path(), 'name' => gp_const_get('GP_SECURE_AUTH_COOKIE', 'glotpress_sec_auth'), 'secure' => 'true');
    $cookies['logged_in'][] = array('domain' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '', 'path' => gp_url_path(), 'name' => gp_const_get('GP_LOGGED_IN_COOKIE', 'glotpress_logged_in'));
    $wp_auth_object = new WP_Auth($gpdb, $wp_users_object, $cookies);
    unset($cookies);
}
require_once GP_PATH . GP_INC . 'warnings.php';
require_once GP_PATH . GP_INC . 'validation.php';
require_once GP_PATH . GP_INC . 'thing.php';
foreach (glob(GP_PATH . GP_INC . 'things/*.php') as $thing) {
    require_once $thing;
}
require_once GP_PATH . GP_INC . 'routes.php';
foreach (glob(GP_PATH . GP_INC . 'routes/*.php') as $route) {
    require_once $route;
}
GP::$translation_warnings = new GP_Translation_Warnings();
GP::$builtin_translation_warnings = new GP_Builtin_Translation_Warnings();
Example #14
0
function gp_url_base($path = '/', $query = null)
{
    return apply_filters('gp_url_base', gp_url_add_path_and_query(gp_url_path(gp_url_base_root()), $path, $query), $path, $query);
}