protected function parseHost($host) { if (!$this->domain && !$this->subdomain) { // Load the default domain $domain = Kohana::$config->load('multisite.domain'); // If no host passed in, check the for HOST in environment if (!$host) { $host = getenv('HOST'); } // If we still don't have a host if (!$host) { // .. parse the current URL $url = Url::createFromServer($_SERVER); // .. and grab the host $host = $url->getHost()->toUnicode(); } // If $domain is set and we're at a subdomain of $domain.. if ($domain and substr($host, strlen($domain) * -1) == $domain) { // .. grab just the subdomain $subdomain = substr($host, 0, strlen($domain) * -1 - 1); } else { // .. otherwise grab the whole domain $domain = $host; $subdomain = ''; } $this->domain = $domain; $this->subdomain = $subdomain; } }
public function testCreateFromServerWithoutRequestUri() { $server = array('PHP_SELF' => '/toto?foo=bar', 'SERVER_ADDR' => '127.0.0.1', 'HTTPS' => 'on', 'SERVER_PROTOCOL' => 'HTTP', 'SERVER_PORT' => 23); $url = Url::createFromServer($server); $this->assertSame('https://127.0.0.1:23/toto?foo=bar', (string) $url); $server = array('SERVER_ADDR' => '127.0.0.1', 'HTTPS' => 'on', 'SERVER_PROTOCOL' => 'HTTP', 'SERVER_PORT' => 23); $url = Url::createFromServer($server); $this->assertSame('https://127.0.0.1:23/', (string) $url); }
/** * @param StorageInterface $tokenStorage * @param StorageRegistryInterface $storageRegistry * @param string $baseUrl */ public function __construct(StorageInterface $tokenStorage, StorageRegistryInterface $storageRegistry, $baseUrl = null) { parent::__construct($tokenStorage, $storageRegistry); if ($baseUrl) { $this->baseUrl = $baseUrl; } else { $this->baseUrl = Url::createFromServer($_SERVER)->getBaseUrl(); } }
/** * Génère l'URL correspondant à une route nommée * @param string $routeName Le nom de route * @param mixed $params Tableau de paramètres optionnel de cette route * @param boolean $absolute Retourne une url absolue si true (relative si false) * @return L'URL correspondant à la route */ public static function generateUrl($routeName, $params = array(), $absolute = false) { $params = empty($params) ? array() : $params; $app = getApp(); $router = $app->getRouter(); $routeUrl = $router->generate($routeName, $params); $url = $routeUrl; if ($absolute) { $u = \League\Url\Url::createFromServer($_SERVER); $url = $u->getBaseUrl() . $routeUrl; } return $url; }
protected function send_resetpassword($to, $params) { $site_name = Kohana::$config->load('site.name'); $site_email = Kohana::$config->load('site.email'); $multisite_email = Kohana::$config->load('multisite.email'); $client_url = Kohana::$config->load('site.client_url'); // @todo make this more robust if ($multisite_email) { $from_email = $multisite_email; } elseif ($site_email) { $from_email = $site_email; } else { $url = Url::createFromServer($_SERVER); $host = $url->getHost()->toUnicode(); $from_email = 'noreply@' . $host; } $view = View::factory('email/forgot-password'); $view->site_name = $site_name; $view->token = $params['token']; $view->client_url = $client_url; $message = $view->render(); $subject = $site_name . ': Password reset'; $email = Email::factory($subject, $message, 'text/html')->to($to)->from($from_email, $site_name)->send(); }
public function getDbConfig($host = NULL) { // Load the default domain $domain = Kohana::$config->load('multisite.domain'); // If no host passed in, check the for HOST in environment if (!$host) { $host = getenv('HOST'); } // If we still don't have a host if (!$host) { // .. parse the current URL $url = Url::createFromServer($_SERVER); // .. and grab the host $host = $url->getHost()->toUnicode(); } // If $domain is set and we're at a subdomain of $domain.. if ($domain and substr_compare($host, $domain, strlen($domain) * -1) !== FALSE) { // .. grab just the subdomain $subdomain = substr($host, 0, strlen($domain) * -1 - 1); } else { // .. otherwise grab the whole domain $domain = $host; $subdomain = ''; } // .. and find the current deployment credentials $result = DB::select()->from('deployments')->where('subdomain', '=', $subdomain)->where('domain', '=', $domain)->limit(1)->offset(0)->execute($this->db); $deployment = $result->current(); // No deployment? throw a 404 if (!count($deployment)) { throw new HTTP_Exception_404("Deployment not found"); } // Set new database config $config = Kohana::$config->load('database')->default; $config['connection'] = ['hostname' => $deployment['dbhost'], 'database' => $deployment['dbname'], 'username' => $deployment['dbuser'], 'password' => $deployment['dbpassword'], 'persistent' => $config['connection']['persistent']]; return $config; }
/** * Set Default Uri * * @return void */ protected function setDefaultUri() { $this->uri = Url::createFromServer($_SERVER); }
/** * @todo redo * @param Directory $basePath */ public function init(\Directory $basePath) { /** * @todo create a default bag and only override if something * special needed */ $bag = Container::getInstance(); $bag->add('basePath', function () use($basePath) { return $basePath; }); /** * @todo move to config class and create a set up */ $bag->add('config', function () use($basePath) { $configPath = $basePath->path . '/config/config.json'; if (is_readable($configPath)) { $config = ArrayHelper::configArrayToObject(json_decode(file_get_contents($configPath), true)); if (!isset($config->baseDir)) { $config->baseDir = ''; } } else { $config = new \StdClass(); $config->url = isset($_SERVER['SERVER_NAME']) ? 'http://' . $_SERVER['SERVER_NAME'] . '/' : 'http://mizzencms.net/'; $config->siteName = 'MizzenLite'; $config->baseDir = ''; } return $config; }); $bag->add('url', function () use($bag) { $url = Url::createFromServer($_SERVER); /** * Remove index.php if exists */ $url->getPath()->remove('index.php'); /** * remove base dir (for when we are installed in a dir) */ if (!empty($bag->get('config')->baseDir)) { $url->getPath()->remove($bag->get('config')->baseDir); } /** * home needs to be converted to index */ if ((string) $url->getPath() === '') { $url->setPath('index'); } return $url; }); $bag->add('metaParser', function () { return new MetaParser(); }); $bag->add('pageRepository', function () { $prp = new PageRepositoryGenerator(new PageRepository(), new Finder()); $prp->populateRepository(); return $prp->getPageRepository(); }); $bag->add('navigation', function () { return (new Navigation())->createPageMenu(); }); $bag->add('eventManager', function () { return new EventManager(); }); $bag->add('view', function () { return new View(); }); }
// Add config Config\Yaml::getInstance()->addFile($appRoot . '/src/xAPI/Config/Config.production.yml'); // Set up logging $logger = new Logger\MonologWriter(['handlers' => [new StreamHandler($appRoot . '/storage/logs/production.' . date('Y-m-d') . '.log')]]); $app->config('log.writer', $logger); }); // Only invoked if mode is "development" $app->configureMode('development', function () use($app, $appRoot) { // Add config Config\Yaml::getInstance()->addFile($appRoot . '/src/xAPI/Config/Config.development.yml'); // Set up logging $logger = new Logger\MonologWriter(['handlers' => [new StreamHandler($appRoot . '/storage/logs/development.' . date('Y-m-d') . '.log')]]); $app->config('log.writer', $logger); }); if (PHP_SAPI !== 'cli') { $app->url = Url::createFromServer($_SERVER); } // Error handling $app->error(function (\Exception $e) { $code = $e->getCode(); if ($code < 100) { $code = 500; } Resource::error($code, $e->getMessage()); }); // Database layer setup $app->hook('slim.before', function () use($app) { $app->container->singleton('mongo', function () use($app) { $client = new Client($app->config('database')['host_uri']); $client->map([$app->config('database')['db_name'] => '\\API\\Collection']); $client->useDatabase($app->config('database')['db_name']);
<?php /** * Bootstrap the library */ require_once __DIR__ . '/../vendor/autoload.php'; /** * Setup error reporting */ error_reporting(E_ALL); ini_set('display_errors', 1); /** * Setup the timezone */ ini_set('date.timezone', 'Europe/Amsterdam'); /** * Create a new instance of the URL class with the current URI, stripping the query string */ $currentUri = \League\Url\Url::createFromServer($_SERVER); $currentUri->setQuery(''); function inline_image($rawData) { return '<img src="' . 'data:image/' . Gregwar\Image\Image::fromData($rawData)->guessType() . ';' . 'base64,' . base64_encode($rawData) . '">'; } /** * Load the credential for the different services */ require_once __DIR__ . '/init.php';
defined('SYSPATH') or die('No direct access allowed.'); /** * Kohana Site Config * * @author Ushahidi Team <*****@*****.**> * @package Ushahidi\Application\Config * @copyright 2013 Ushahidi * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3) */ /** * Site settings * * The following options are available: * * - string name Display name of the site. * - string description A brief description of the site. * - string email Site contact email. * - string timezone Default timezone for the site. See http://php.net/manual/en/timezones.php * - string language Native language for the site in ISO 639-1 format. See http://en.wikipedia.org/wiki/ISO_639-1 * - string date_format Set format in which to return dates. See http://php.net/manual/en/datetime.createfromformat.php */ $clientUrl = getenv('CLIENT_URL'); if (!empty(getenv("MULTISITE_DOMAIN"))) { try { $host = \League\Url\Url::createFromServer($_SERVER)->getHost()->toUnicode(); $clientUrl = str_replace(getenv("MULTISITE_DOMAIN"), getenv("MULTISITE_CLIENT_DOMAIN"), $host); } catch (Exception $e) { } } return array('name' => '', 'description' => '', 'email' => '', 'timezone' => 'UTC', 'language' => 'en-US', 'date_format' => 'n/j/Y', 'client_url' => $clientUrl ?: false, 'first_login' => true, 'tier' => 'free', 'private' => false);