Skip to content

Commit

Permalink
made php7+ as a requirement. php5.6 will no longer be maintained by p…
Browse files Browse the repository at this point in the history
…hp as of December this year.

added a callback method for template output

#5790
  • Loading branch information
danielkerr committed May 24, 2018
1 parent b757454 commit 6e30f9b
Show file tree
Hide file tree
Showing 18 changed files with 234 additions and 195 deletions.
67 changes: 24 additions & 43 deletions upload/catalog/controller/event/theme.php
Original file line number Diff line number Diff line change
@@ -1,60 +1,41 @@
<?php
class ControllerEventTheme extends Controller {
public function index(&$route, &$args, &$template) {

echo $template;

// If there is a template file we render
if ($template) {
// include and register Twig auto-loader
Twig_Autoloader::register();

// specify where to look for templates
$loader = new \Twig_Loader_Filesystem(DIR_TEMPLATE);

$config = array('autoescape' => false);

if ($this->config->get('template_cache')) {
$config['cache'] = DIR_CACHE;
}

// initialize Twig environment
$twig = new \Twig_Environment($loader, $config);

return $twig->createTemplate($template)->render($args);
}
}

public function override(&$route, &$args, &$template) {
if (!$this->config->get('theme_' . $this->config->get('config_theme') . '_status')) {
exit('Error: A theme has not been assigned to this store!');
}

echo 'hi';

// If the default theme is selected we need to know which directory its pointing to
// If the default theme is selected we need to know which directory its pointing to
if ($this->config->get('config_theme') == 'default') {
$theme = $this->config->get('theme_default_directory');
$directory = $this->config->get('theme_default_directory');
} else {
$theme = $this->config->get('config_theme');
$directory = $this->config->get('config_theme');
}

if (is_file(DIR_TEMPLATE . $directory . '/template/' . $route . '.twig')) {
$this->config->set('template_directory', $directory . '/template/');
} elseif (is_file(DIR_TEMPLATE . 'default/template/' . $route . '.twig')) {
$this->config->set('template_directory', 'default/template/');
}

// If there is a theme override we should get it
$this->load->model('design/theme');

$theme_info = $this->model_design_theme->getTheme($route, $theme);

if ($theme_info) {

// If you want to modify the output of the template we add a
$proxy = new Proxy();

$template = html_entity_decode($theme_info['code'], ENT_QUOTES, 'UTF-8');
// Attach to the template
$template->addFilter($proxy);

$proxy->callback = function ($code) use ($route, $args, $directory) {
// If there is a theme override we should get it
$this->load->model('design/theme');

$theme_info = $this->model_design_theme->getTheme($route, $directory);

} elseif (is_file(DIR_TEMPLATE . $theme . '/template/' . $route . '.twig')) {
$this->config->set('template_directory', $theme . '/template/');
} elseif (is_file(DIR_TEMPLATE . 'default/template/' . $route . '.twig')) {
$this->config->set('template_directory', 'default/template/');
}
if ($theme_info) {
return html_entity_decode($theme_info['code'], ENT_QUOTES, 'UTF-8');
} else {
// Because we are using a proxy the arguments will always be an array.
return $code[0];
}
};
}
}
2 changes: 1 addition & 1 deletion upload/install/controller/install/step_2.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function index() {
}

private function validate() {
if (phpversion() < '5.4') {
if (phpversion() < '7.0.0') {
$this->error['warning'] = $this->language->get('error_version');
}

Expand Down
1 change: 0 additions & 1 deletion upload/system/config/admin.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
// Site
$_['site_url'] = HTTP_SERVER;
$_['site_ssl'] = HTTPS_SERVER;

// Database
$_['db_autostart'] = true;
Expand Down
8 changes: 3 additions & 5 deletions upload/system/config/catalog.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
// Site
$_['site_url'] = HTTP_SERVER;
$_['site_ssl'] = HTTPS_SERVER;

// Url
$_['url_autostart'] = false;
Expand Down Expand Up @@ -48,12 +47,11 @@
'event/language/after'
),
'view/*' => array(
'event/theme'
//'event/theme'
),
'view/*/before' => array(
500 => 'event/theme/override',
998 => 'event/language',
1000 => 'event/theme'
500 => 'event/theme',
998 => 'event/language'
),
'language/*/after' => array(
'event/translation'
Expand Down
1 change: 0 additions & 1 deletion upload/system/config/default.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
// Site
$_['site_url'] = '';
$_['site_ssl'] = false;

// Url
$_['url_autostart'] = true;
Expand Down
29 changes: 10 additions & 19 deletions upload/system/engine/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function model($route) {
// Overriding models is a little harder so we have to use PHP's magic methods
// In future version we can use runkit
foreach (get_class_methods($class) as $method) {
$proxy->{$method} = $this->callback($this->registry, $route . '/' . $method);
$proxy->{$method} = $this->callback($route . '/' . $method);
}

$this->registry->set('model_' . str_replace('/', '_', (string)$route), $proxy);
Expand All @@ -101,7 +101,7 @@ public function model($route) {
* @param string $route
* @param array $data
*
* @return string
* @return string
*/
public function view($route, $data = array()) {
// Sanitize the call
Expand All @@ -110,29 +110,20 @@ public function view($route, $data = array()) {
// Keep the original trigger
$trigger = $route;

$output = '';

// Modify the loaded template
$file = DIR_TEMPLATE . $this->registry->get('config')->get('template_directory') . $route . $this->registry->get('config')->get('template_extension');

if (is_file($file)) {
$output = file_get_contents($file);
}
$template = new Template($this->registry->get('config')->get('template_engine'));

// Trigger the pre events
$result = $this->registry->get('event')->trigger('view/' . $trigger . '/before', array(&$route, &$data, &$output));
$result = $this->registry->get('event')->trigger('view/' . $trigger . '/before', array(&$route, &$data, &$template));

// Make sure its only the last event that returns an output if required.
if ($result && !$result instanceof Exception) {
$output = $result;
} else {
$template = new Template($this->registry->get('config')->get('template_engine'));

foreach ($data as $key => $value) {
$template->set($key, $value);
}

$output = $template->render($route, $this->registry->get('config')->get('template_cache'));
$output = $template->render($this->registry->get('config')->get('template_directory') . $route, $this->registry->get('config')->get('template_cache'));
}

// Trigger the post events
Expand Down Expand Up @@ -226,8 +217,8 @@ public function language($route, $key = '') {
return $output;
}

protected function callback($registry, $route) {
return function ($args) use ($registry, $route) {
protected function callback($route) {
return function ($args) use ($route) {
static $model;

$route = preg_replace('/[^a-zA-Z0-9_\/]/', '', (string)$route);
Expand All @@ -236,7 +227,7 @@ protected function callback($registry, $route) {
$trigger = $route;

// Trigger the pre events
$result = $registry->get('event')->trigger('model/' . $trigger . '/before', array(&$route, &$args));
$result = $this->registry->get('event')->trigger('model/' . $trigger . '/before', array(&$route, &$args));

if ($result && !$result instanceof Exception) {
$output = $result;
Expand All @@ -247,7 +238,7 @@ protected function callback($registry, $route) {
$key = substr($route, 0, strrpos($route, '/'));

if (!isset($model[$key])) {
$model[$key] = new $class($registry);
$model[$key] = new $class($this->registry);
}

$method = substr($route, strrpos($route, '/') + 1);
Expand All @@ -262,7 +253,7 @@ protected function callback($registry, $route) {
}

// Trigger the post events
$result = $registry->get('event')->trigger('model/' . $trigger . '/after', array(&$route, &$args, &$output));
$result = $this->registry->get('event')->trigger('model/' . $trigger . '/after', array(&$route, &$args, &$output));

if ($result && !$result instanceof Exception) {
$output = $result;
Expand Down
8 changes: 4 additions & 4 deletions upload/system/engine/proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ public function __set($key, $value) {

public function __call($key, $args) {
$arg_data = array();

$args = func_get_args();

foreach ($args as $arg) {
if ($arg instanceof Ref) {
$arg_data[] =& $arg->getRef();
} else {
$arg_data[] =& $arg;
}
}

if (isset($this->{$key})) {
return call_user_func_array($this->{$key}, $arg_data);
return call_user_func_array($this->{$key}, $arg_data);
} else {
$trace = debug_backtrace();

Expand Down
2 changes: 1 addition & 1 deletion upload/system/framework.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
// Registry
$registry = new Registry();

Expand Down
48 changes: 24 additions & 24 deletions upload/system/helper/bbcode.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php
/* BBCode Converter that converts BBCode writen in ckeditor */
function bbcode_decode($string) {
$pattern = array();
/* BBCode Converter that converts BBCode writen in ckeditor */
function bbcode_decode($string) {
$pattern = array();
$replace = array();

// Bold
$pattern[0] = '/\[b\](.*?)\[\/b\]/is';
$replace[0] = '<strong>$1</strong>';

// Italic
$pattern[1] = '/\[i\](.*?)\[\/i\]/is';
$replace[1] = '<em>$1</em>';
$replace[1] = '<em>$1</em>';

// Underlined
$pattern[2] = '/\[u\](.*?)\[\/u\]/is';
$replace[2] = '<u>$1</u>';
$replace[2] = '<u>$1</u>';

// Quote
$pattern[3] = '/\[quote\](.*?)\[\/quote]/is';
Expand All @@ -26,45 +26,45 @@ function bbcode_decode($string) {

// Strikethrough
$pattern[16] = '/\[s\](.*?)\[\/s\]/is';
$replace[16] = '<s>$1</s>';
$replace[16] = '<s>$1</s>';

// List Item
$pattern[7] = '/\[\*\]([\w\W]+?)\n?(?=(?:(?:\[\*\])|(?:\[\/list\])))/';
$replace[7] = '<li>$1</li>';

// List
$pattern[5] = '/\[list\](.*?)\[\/list\]/is';
$replace[5] = '<ul>$1</ul>';

// Ordered List
$pattern[6] = '/\[list\=(1|A|a|I|i)\](.*?)\[\/list\]/is';
$replace[6] = '<ol type="$1">$2</ol>';

// Image
$pattern[8] = '/\[img\](.*?)\[\/img\]/is';
$replace[8] = '<img src="$1" alt="" class="img-responsive" />';

// URL
$pattern[9] = '/\[url\](.*?)\[\/url\]/is';
$replace[9] = '<a href="$1" rel="nofollow" target="_blank">$1</a>';

// URL (named)
$pattern[10] = '/\[url\=([^\[]+?)\](.*?)\[\/url\]/is';
$replace[10] = '<a href="$1" rel="nofollow" target="_blank">$2</a>';
$replace[10] = '<a href="$1" rel="nofollow" target="_blank">$2</a>';

// Font Size
$pattern[11] = '/\[size\=([\-\+]?\d+)\](.*?)\[\/size\]/is';
$replace[11] = '<span style="font-size: $1%;">$2</span>';

// Font Color
$pattern[12] = '/\[color\=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+)\](.*?)\[\/color\]/is';
$replace[12] = '<span style="color: $1;">$2</span>';
$replace[12] = '<span style="color: $1;">$2</span>';

// YouTube
$pattern[9] = '/\[youtube\](.*?)\[\/youtube\]/is';
$replace[9] = '<iframe width="560" height="315" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>';
$string = preg_replace($pattern, $replace, $string);
return $string;

$string = preg_replace($pattern, $replace, $string);

return $string;
}
16 changes: 10 additions & 6 deletions upload/system/helper/general.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
<?php
function token($length = 32) {
if(!isset($length) || intval($length) <= 8 ){
if (!isset($length) || intval($length) <= 8) {
$length = 32;
}
}

if (function_exists('random_bytes')) {
$token = bin2hex(random_bytes($length));
}

if (function_exists('mcrypt_create_iv') && phpversion() < '7.1') {
$token = bin2hex(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM));
}

if (function_exists('openssl_random_pseudo_bytes')) {
$token = bin2hex(openssl_random_pseudo_bytes($length));
}

return substr($token, -$length, $length);
}

/**
* Backwards support for timing safe hash string comparisons
*
*
* http://php.net/manual/en/function.hash-equals.php
*/

if(!function_exists('hash_equals')) {
if (!function_exists('hash_equals')) {
function hash_equals($known_string, $user_string) {
$known_string = (string)$known_string;
$user_string = (string)$user_string;

if(strlen($known_string) != strlen($user_string)) {
if (strlen($known_string) != strlen($user_string)) {
return false;
} else {
$res = $known_string ^ $user_string;
$ret = 0;

for($i = strlen($res) - 1; $i >= 0; $i--) $ret |= ord($res[$i]);
for ($i = strlen($res) - 1; $i >= 0; $i--) $ret |= ord($res[$i]);

return !$ret;
}
Expand Down
Loading

0 comments on commit 6e30f9b

Please sign in to comment.