Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Http Foundation to Known Core #3262

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 96 additions & 86 deletions Idno/Common/Page.php

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Idno/Core/Bonita/Forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ public function draw($templateName, $returnBlank = true)
*/
public static function validateToken($action = '', $haltExecutionOnBadRequest = true)
{
if (empty($_REQUEST['__bTs']) || empty($_REQUEST['__bTk'])) {
if (!\Idno\Core\Idno::site()->request()->request->has('__bTs') || !\Idno\Core\Idno::site()->request()->request->has('__bTk')) {
if ($haltExecutionOnBadRequest) {
exit;
}

return false;
}
$time = $_REQUEST['__bTs'];
$token = $_REQUEST['__bTk'];
$time = \Idno\Core\Idno::site()->request()->request->get('__bTs');
$token = \Idno\Core\Idno::site()->request()->request->get('__bTk');
if (empty($action)) {
if (!empty($_REQUEST['__bTa'])) {
$action = $_REQUEST['__bTa'];
if (\Idno\Core\Idno::site()->request()->request->has('__bTa')) {
$action = \Idno\Core\Idno::site()->request()->request->get('__bTa');
} else {

\Idno\Core\Idno::site()->logging()->debug("No action in token");
Expand Down Expand Up @@ -93,7 +93,7 @@ public static function validateToken($action = '', $haltExecutionOnBadRequest =
public static function formSubmitted()
{

if (isset($_REQUEST['__bTk']) && isset($_REQUEST['__bTs'])) {
if (\Idno\Core\Idno::site()->request()->request->has('__bTk') && \Idno\Core\Idno::site()->request()->request->has('__bTs')) {
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions Idno/Core/Bonita/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ public static function getSiteSecret()
*/
static function detectDevice()
{
if (empty($_SERVER['HTTP_USER_AGENT'])) {
if (!\Idno\Core\Idno::site()->request()->server->has('HTTP_USER_AGENT')) {
return 'default';
}
$ua = $_SERVER['HTTP_USER_AGENT'];
$ua = \Idno\Core\Idno::site()->request()->server->get('HTTP_USER_AGENT');

// Android
if (preg_match('/android/i', $ua)) {
Expand Down
22 changes: 14 additions & 8 deletions Idno/Core/Bonita/Templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,24 @@ function process($content, $processor = 'text')
function drawPage($echo = true, $shell = 'shell')
{
if ($echo) {
// For Backward Compatibility reasons

\Idno\Core\Idno::site()->response()->setContent($this->draw($shell));
\Idno\Core\Idno::site()->sendResponse();

// $content = $this->draw($shell);
// header('Content-Length: ' . strlen($content));

$content = $this->draw($shell);
header('Content-Length: ' . strlen($content));
// // Break long output to avoid an Apache performance bug
// $split_output = str_split($content, 1024);

// Break long output to avoid an Apache performance bug
$split_output = str_split($content, 1024);
// foreach ($split_output as $chunk) {
// echo $chunk;
// }

// exit;

foreach ($split_output as $chunk) {
echo $chunk;
}

exit;
} else {
return $this->draw($shell);
}
Expand Down
23 changes: 11 additions & 12 deletions Idno/Core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function loadIniFiles()

if (($cloudcube || $aws_s3) && (!empty($bucket))) {
$this->ini_config['filesystem'] = 'local';
$this->ini_config['uploadpath'] = "s3://${bucket}${path}";
$this->ini_config['uploadpath'] = "s3://{$bucket}{$path}";
}

if (array_key_exists('KNOWN_AWS_S3_REGION', $_ENV)) {
Expand All @@ -241,10 +241,9 @@ function loadIniFiles()
}

// Check environment variables and set as appropriate
foreach ($_SERVER as $name => $val) {
foreach (\Idno\Core\Idno::site()->request()->server->all() as $name => $val) {
if (substr($name, 0, 6) == 'KNOWN_') {
$name = strtolower(str_replace('KNOWN_', '', $name));
$val = $val;
$this->ini_config[$name] = $val;
}
}
Expand Down Expand Up @@ -377,17 +376,17 @@ protected function detectBaseURL()
{

// Otherwise, use the standard server name header
if (!empty($_SERVER['SERVER_NAME'])) {
if (\Idno\Core\Idno::site()->request()->server->has('SERVER_NAME')) {

// Servername specified, so we can construct things in the normal way.
$url = (\Idno\Common\Page::isSSL() ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'];
if (!empty($_SERVER['HTTP_X_FORWARDED_PORT'])) {
if ($_SERVER['HTTP_X_FORWARDED_PORT'] != 80 && $_SERVER['HTTP_X_FORWARDED_PORT'] != 443) {
$url .= ':' . $_SERVER['HTTP_X_FORWARDED_PORT'];
$url = (\Idno\Common\Page::isSSL() ? 'https://' : 'http://') . \Idno\Core\Idno::site()->request()->server->get('SERVER_NAME');
if (\Idno\Core\Idno::site()->request()->server->has('HTTP_X_FORWARDED_PORT')) {
if (\Idno\Core\Idno::site()->request()->server->get('HTTP_X_FORWARDED_PORT') != 80 && \Idno\Core\Idno::site()->request()->server->get('HTTP_X_FORWARDED_PORT') != 443) {
$url .= ':' . \Idno\Core\Idno::site()->request()->server->get('HTTP_X_FORWARDED_PORT');
}
} else if (!empty($_SERVER['SERVER_PORT'])) {
if ($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
$url .= ':' . $_SERVER['SERVER_PORT'];
} else if (\Idno\Core\Idno::site()->request()->server->has('SERVER_PORT')) {
if (\Idno\Core\Idno::site()->request()->server->get('SERVER_PORT') != 80 && \Idno\Core\Idno::site()->request()->server->get('SERVER_PORT') != 443) {
$url .= ':' . \Idno\Core\Idno::site()->request()->server->get('SERVER_PORT');
}
}
if (defined('KNOWN_SUBDIRECTORY')) {
Expand Down Expand Up @@ -650,7 +649,7 @@ function emailIsBlocked($email)
*/
function hasSSL()
{
if (substr_count(site()->config()->getURL(), 'https://') || !empty($this->config()->force_ssl)) {
if (substr_count(site()->config()->getURL(), 'https://') || !empty($this->config->force_ssl)) {
return true;
}

Expand Down
10 changes: 5 additions & 5 deletions Idno/Core/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function setSubject($subject)
function setFrom($email, $name = '')
{
if (!empty($name)) {
return $this->message->addFrom(array($name => $email));
return $this->message->addFrom($email,$name);
}

return $this->message->addFrom($email);
Expand All @@ -53,7 +53,7 @@ function setFrom($email, $name = '')
function addTo($email, $name = '')
{
if (!empty($name)) {
return $this->message->addTo(array($name => $email));
return $this->message->addTo($email,$name);
}

return $this->message->addTo($email);
Expand All @@ -80,7 +80,7 @@ function addBcc($email)
function setReplyTo($email, $name = '')
{
if (!empty($name)) {
return $this->message->addReplyTo(array($name => $email));
return $this->message->addReplyTo($email,$name);
}

return $this->message->addReplyTo($email);
Expand Down Expand Up @@ -126,8 +126,8 @@ function setHTMLBody($body, $shell = true, array $shellVars = [])
/**
* Set the text only component of an email.
*
* @param type $template_name
* @param type $vars
* @param string $template_name
* @param string $vars
* @return mixed
*/
function setTextBodyFromTemplate($template_name, $vars = array())
Expand Down
40 changes: 40 additions & 0 deletions Idno/Core/Hook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
namespace Idno\Core {
class Hook
{
private static $instance;

private $hooks = array();

private function __construct()
{
}
private function __clone()
{
}

public static function add($hook_name, $fn)
{
$instance = self::get_instance();
$instance->hooks[$hook_name][] = $fn;
}

public static function fire($hook_name, $params = null)
{
$instance = self::get_instance();
if (isset($instance->hooks[$hook_name])) {
foreach ($instance->hooks[$hook_name] as $fn) {
call_user_func_array($fn, array(&$params));
}
}
}

public static function get_instance()
{
if (empty(self::$instance)) {
self::$instance = new Hook();
}
return self::$instance;
}
}
}
8 changes: 4 additions & 4 deletions Idno/Core/Hub.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function registerUser($user = false)
* Load the locally stored auth token & secret details, or register with the hub if no details have been
* saved
*
* @return bool
* @return mixed
*/
function loadDetails()
{
Expand Down Expand Up @@ -144,9 +144,9 @@ function connect()
$details = $this->loadDetails();
if (!empty($details['auth_token'])) {
// Apply pre-stored auth details and connect to server
} else if (!substr_count($_SERVER['REQUEST_URI'], 'callback')
&& !substr_count($_SERVER['REQUEST_URI'], '.')
&& !substr_count($_SERVER['REQUEST_URI'], '/file/')
} else if (!substr_count(\Idno\Core\Idno::site()->request()->getRequestUri(), 'callback')
&& !substr_count(\Idno\Core\Idno::site()->request()->getRequestUri(), '.')
&& !substr_count(\Idno\Core\Idno::site()->request()->getRequestUri(), '/file/')
) {
// Establish auth details, save them, and then connect
if ($details = $this->register()) {
Expand Down
Loading