Merge pull request #13 from fermionic/20130105-smarty3

implement smarty3
This commit is contained in:
friendica
2013-01-06 19:25:01 -08:00
245 changed files with 6821 additions and 287 deletions

View File

@@ -204,13 +204,28 @@ class Item extends BaseObject {
$body = prepare_body($item,true);
if($a->get_template_engine() === 'internal') {
$body_e = template_escape($body);
$name_e = template_escape($profile_name);
$title_e = template_escape($item['title']);
$location_e = template_escape($location);
$owner_name_e = template_escape($this->get_owner_name());
}
else {
$body_e = $body;
$name_e = $profile_name;
$title_e = $item['title'];
$location_e = $location;
$owner_name_e = $this->get_owner_name();
}
$tmp_item = array(
'template' => $this->get_template(),
'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
'tags' => $tags,
'body' => $body,
'text' => strip_tags(template_escape($body)),
'body' => $body_e,
'text' => strip_tags($body_e),
'id' => $this->get_id(),
'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $this->get_owner_name(), ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
@@ -219,19 +234,19 @@ class Item extends BaseObject {
'vwall' => t('via Wall-To-Wall:'),
'profile_url' => $profile_link,
'item_photo_menu' => item_photo_menu($item),
'name' => template_escape($profile_name),
'name' => $name_e,
'thumb' => $profile_avatar,
'osparkle' => $osparkle,
'sparkle' => $sparkle,
'title' => template_escape($item['title']),
'title' => $title_e,
'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
'lock' => $lock,
'location' => template_escape($location),
'location' => $location_e,
'indent' => $indent,
'owner_url' => $this->get_owner_url(),
'owner_photo' => $this->get_owner_photo(),
'owner_name' => template_escape($this->get_owner_name()),
'owner_name' => $owner_name_e,
// Item toolbar buttons
'like' => $like,

View File

@@ -344,7 +344,6 @@ function visible_activity($item) {
return true;
}
/**
* "Render" a conversation or list of items for HTML display.
* There are two major forms of display:
@@ -886,7 +885,7 @@ function status_editor($a,$x,$popup=false) {
$o = '';
$geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
$geotag = (($x['allow_location']) ? replace_macros(get_markup_template('jot_geotag.tpl'), array()) : '');
$plaintext = true;
if(feature_enabled(local_user(),'richtext'))

View File

@@ -58,4 +58,4 @@ function get_features() {
call_hooks('get_features',$arr);
return $arr;
}
}

View File

@@ -0,0 +1,43 @@
<?php
require_once("library/Smarty/libs/Smarty.class.php");
class FriendicaSmarty extends Smarty {
public $filename;
function __construct() {
parent::__construct();
$a = get_app();
$theme = current_theme();
// setTemplateDir can be set to an array, which Smarty will parse in order.
// The order is thus very important here
$template_dirs = array('theme' => "view/theme/$theme/tpl/smarty3/");
if( x($a->theme_info,"extends") )
$template_dirs = $template_dirs + array('extends' => "view/theme/".$a->theme_info["extends"]."/tpl/smarty3/");
$template_dirs = $template_dirs + array('base' => 'view/tpl/smarty3/');
$this->setTemplateDir($template_dirs);
$this->setCompileDir('view/tpl/smarty3/compiled/');
$this->setConfigDir('view/tpl/smarty3/config/');
$this->setCacheDir('view/tpl/smarty3/cache/');
$this->left_delimiter = $a->get_template_ldelim('smarty3');
$this->right_delimiter = $a->get_template_rdelim('smarty3');
// Don't report errors so verbosely
$this->error_reporting = E_ALL & ~E_NOTICE;
}
function parsed($template = '') {
if($template) {
return $this->fetch('string:' . $template);
}
return $this->fetch('file:' . $this->filename);
}
}

View File

@@ -1,5 +1,6 @@
<?php
require_once("include/friendica_smarty.php");
// install and uninstall plugin
if (! function_exists('uninstall_plugin')){
@@ -465,37 +466,40 @@ function format_js_if_exists($source) {
}
function theme_include($file) {
function theme_include($file, $root = '') {
global $t; // use builtin template processor
$a = get_app();
$paths = array(
'view/theme/$theme/$ext/$file',
'view/theme/$theme/$file',
'view/theme/$parent/$ext/$file',
'view/theme/$parent/$file',
'view/$ext/$file',
'view/$file'
);
// Make sure $root ends with a slash / if it's not blank
if($root !== '' && $root[strlen($root)-1] !== '/')
$root = $root . '/';
$theme_info = get_app()->theme_info;
$theme_info = $a->theme_info;
if(array_key_exists('extends',$theme_info))
$parent = $theme_info['extends'];
else
$parent = 'NOPATH';
$theme = current_theme();
$ext = substr($file,strrpos($file,'.')+1);
$paths = array(
"{$root}view/theme/$theme/$ext/$file",
"{$root}view/theme/$theme/$file",
"{$root}view/theme/$parent/$ext/$file",
"{$root}view/theme/$parent/$file",
"{$root}view/$ext/$file",
"{$root}view/$file"
);
foreach($paths as $p) {
$f = $t->replace($p,array(
'$theme' => current_theme(),
'$ext' => substr($file,strrpos($file,'.')+1),
'$parent' => $parent,
'$file' => $file
));
if(strstr($f,'NOPATH'))
// strpos() is faster than strstr when checking if one string is in another (http://php.net/manual/en/function.strstr.php)
if(strpos($p,'NOPATH') !== false)
continue;
if(file_exists($f))
return $f;
if(file_exists($p))
return $p;
}
return '';
}
@@ -509,19 +513,38 @@ function get_intltext_template($s) {
if(! isset($a->language))
$a->language = 'en';
if(file_exists("view/{$a->language}/$s"))
return file_get_contents("view/{$a->language}/$s");
elseif(file_exists("view/en/$s"))
return file_get_contents("view/en/$s");
$engine = '';
if($a->get_template_engine() === 'smarty3')
$engine = "/smarty3";
if(file_exists("view/{$a->language}$engine/$s"))
return file_get_contents("view/{$a->language}$engine/$s");
elseif(file_exists("view/en$engine/$s"))
return file_get_contents("view/en$engine/$s");
else
return file_get_contents("view/$s");
return file_get_contents("view/tpl/$engine/$s");
}}
if(! function_exists('get_markup_template')) {
function get_markup_template($s) {
function get_markup_template($s, $root = '') {
$x = theme_include($s);
if($x)
return file_get_contents($x);
$a = get_app();
$template_eng = $a->get_template_engine();
if($template_eng === 'internal') {
$template_file = theme_include($s, $root);
if($template_file)
return file_get_contents($template_file);
}
else {
$template_file = theme_include("$template_eng/$s", $root);
if($template_file) {
$template = new FriendicaSmarty();
$template->filename = $template_file;
return $template;
}
}
}}

View File

@@ -13,15 +13,35 @@ require_once("include/template_processor.php");
if(! function_exists('replace_macros')) {
function replace_macros($s,$r) {
global $t;
//$ts = microtime();
$r = $t->replace($s,$r);
//$tt = microtime() - $ts;
//$a = get_app();
//$a->page['debug'] .= "$tt <br>\n";
return template_unescape($r);
// $ts = microtime();
$a = get_app();
if($a->get_template_engine() === 'smarty3') {
$output = '';
if(gettype($s) !== 'NULL') {
$template = '';
if(gettype($s) === 'string') {
$template = $s;
$s = new FriendicaSmarty();
}
foreach($r as $key=>$value) {
if($key[0] === '$') {
$key = substr($key, 1);
}
$s->assign($key, $value);
}
$output = $s->parsed($template);
}
}
else {
$r = $t->replace($s,$r);
$output = template_unescape($r);
}
// $tt = microtime() - $ts;
// $a->page['debug'] .= "$tt <br>\n";
return $output;
}}