diff options
author | Zach Prezkuta <fermion@gmx.com> | 2013-01-06 14:42:51 -0700 |
---|---|---|
committer | Zach Prezkuta <fermion@gmx.com> | 2013-01-06 15:57:11 -0700 |
commit | a0d19ffb7241a1c7a4b85e6d0fd58fbb2f718468 (patch) | |
tree | 280d792355cb2e60cf62e8451b6d8afbbfcc7c0d /include | |
parent | 61b8ea9e1af74e2056e18b02c170a899de9abd1b (diff) | |
download | volse-hubzilla-a0d19ffb7241a1c7a4b85e6d0fd58fbb2f718468.tar.gz volse-hubzilla-a0d19ffb7241a1c7a4b85e6d0fd58fbb2f718468.tar.bz2 volse-hubzilla-a0d19ffb7241a1c7a4b85e6d0fd58fbb2f718468.zip |
implement Smarty3
Diffstat (limited to 'include')
-rw-r--r-- | include/ItemObject.php | 27 | ||||
-rw-r--r-- | include/conversation.php | 3 | ||||
-rw-r--r-- | include/features.php | 2 | ||||
-rw-r--r-- | include/friendica_smarty.php | 43 | ||||
-rw-r--r-- | include/plugin.php | 80 | ||||
-rw-r--r-- | include/text.php | 33 |
6 files changed, 142 insertions, 46 deletions
diff --git a/include/ItemObject.php b/include/ItemObject.php index 45ea6860a..8ae13e0d8 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -204,13 +204,28 @@ class Item extends BaseObject { $body = prepare_body($item,true); + if($a->theme['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, diff --git a/include/conversation.php b/include/conversation.php index 7ad231b58..ecd6d358e 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -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')) diff --git a/include/features.php b/include/features.php index 738de429f..e4781518b 100644 --- a/include/features.php +++ b/include/features.php @@ -58,4 +58,4 @@ function get_features() { call_hooks('get_features',$arr); return $arr; -}
\ No newline at end of file +} diff --git a/include/friendica_smarty.php b/include/friendica_smarty.php new file mode 100644 index 000000000..b3f0d18a0 --- /dev/null +++ b/include/friendica_smarty.php @@ -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/smarty3/"); + if( x($a->theme_info,"extends") ) + $template_dirs = $template_dirs + array('extends' => "view/theme/".$a->theme_info["extends"]."/smarty3/"); + $template_dirs = $template_dirs + array('base' => 'view/smarty3/'); + $this->setTemplateDir($template_dirs); + + $this->setCompileDir('view/smarty3/compiled/'); + $this->setConfigDir('view/smarty3/config/'); + $this->setCacheDir('view/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); + } +} + + + diff --git a/include/plugin.php b/include/plugin.php index 6a35a6187..be238b78c 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -465,37 +465,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 +512,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 = '') { + + $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); - $x = theme_include($s); - if($x) - return file_get_contents($x); + if($template_file) { + $template = new FriendicaSmarty(); + $template->filename = $template_file; + + return $template; + } + } }} diff --git a/include/text.php b/include/text.php index 5438aae73..83d989947 100644 --- a/include/text.php +++ b/include/text.php @@ -13,15 +13,32 @@ 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') { + $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; }} |