diff --git a/boot.php b/boot.php
index c122ba075..074fcde73 100644
--- a/boot.php
+++ b/boot.php
@@ -488,17 +488,36 @@ if(! class_exists('App')) {
// Allow themes to control internal parameters
// by changing App values in theme.php
- //
- // Possibly should make these part of the plugin
- // system, but it seems like overkill to invoke
- // all the plugin machinery just to change a couple
- // of values
+
public $sourcename = '';
public $videowidth = 425;
public $videoheight = 350;
public $force_max_items = 0;
public $theme_thread_allow = true;
+ // An array for all theme-controllable parameters
+ // Mostly unimplemented yet. Only options 'template_engine' and
+ // beyond are used.
+
+ private $theme = array(
+ 'sourcename' => '',
+ 'videowidth' => 425,
+ 'videoheight' => 350,
+ 'force_max_items' => 0,
+ 'thread_allow' => true,
+ 'stylesheet' => '',
+ 'template_engine' => 'internal',
+ );
+
+ private $ldelim = array(
+ 'internal' => '',
+ 'smarty3' => '{{'
+ );
+ private $rdelim = array(
+ 'internal' => '',
+ 'smarty3' => '}}'
+ );
+
private $scheme;
private $hostname;
private $baseurl;
@@ -753,9 +772,29 @@ if(! class_exists('App')) {
}
- function init_pagehead() {
- $this->page['title'] = $this->config['sitename'];
- $this->page['htmlhead'] = get_markup_template('head.tpl');
+ function build_pagehead() {
+
+ $interval = ((local_user()) ? get_pconfig(local_user(),'system','update_interval') : 40000);
+ if($interval < 10000)
+ $interval = 40000;
+
+ $this->page['title'] = $this->config['system']['sitename'];
+
+
+ /* put the head template at the beginning of page['htmlhead']
+ * since the code added by the modules frequently depends on it
+ * being first
+ */
+ $tpl = get_markup_template('head.tpl');
+ $this->page['htmlhead'] = replace_macros($tpl, array(
+ '$baseurl' => $this->get_baseurl(),
+ '$local_user' => local_user(),
+ '$generator' => FRIENDICA_PLATFORM . ' ' . FRIENDICA_VERSION,
+ '$update_interval' => $interval,
+ '$head_css' => head_get_css(),
+ '$head_js' => head_get_js(),
+ '$js_strings' => js_strings()
+ )) . $this->page['htmlhead'];
}
function set_curl_code($code) {
@@ -797,6 +836,32 @@ if(! class_exists('App')) {
return $this->cached_profile_image[$avatar_image];
}
+ function get_template_engine() {
+ return $this->theme['template_engine'];
+ }
+
+ function set_template_engine($engine = 'internal') {
+
+ $this->theme['template_engine'] = 'internal';
+
+ switch($engine) {
+ case 'smarty3':
+ if(is_writable('view/tpl/smarty3/'))
+ $this->theme['template_engine'] = 'smarty3';
+ break;
+ default:
+ break;
+ }
+ }
+
+ function get_template_ldelim($engine = 'internal') {
+ return $this->ldelim[$engine];
+ }
+
+ function get_template_rdelim($engine = 'internal') {
+ return $this->rdelim[$engine];
+ }
+
}
}
@@ -1264,20 +1329,26 @@ function profile_load(&$a, $nickname, $profile = 0) {
$_SESSION['theme'] = $a->profile['channel_theme'];
- /**
- * load/reload current theme info
- */
+ /**
+ * load/reload current theme info
+ */
- $theme_info_file = "view/theme/".current_theme()."/php/theme.php";
- if (file_exists($theme_info_file)){
- require_once($theme_info_file);
- }
+ $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
- $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
-
- $a->set_widget('profile',profile_sidebar($a->profile, $block));
- return;
+ $theme_info_file = "view/theme/".current_theme()."/php/theme.php";
+ if (file_exists($theme_info_file)){
+ require_once($theme_info_file);
}
+
+ return;
+}}
+
+function profile_aside(&$a) {
+
+ $block = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);
+
+ $a->set_widget('profile',profile_sidebar($a->profile, $block));
+ return;
}
@@ -1969,23 +2040,7 @@ function construct_page(&$a) {
head_add_js('mod_' . $a->module . '.js');
-
- $interval = ((local_user()) ? get_pconfig(local_user(),'system','update_interval') : 40000);
- if($interval < 10000)
- $interval = 40000;
-
- $a->page['title'] = $a->config['system']['sitename'];
-
-
- $a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array(
- '$baseurl' => $a->get_baseurl(),
- '$local_user' => local_user(),
- '$generator' => FRIENDICA_PLATFORM . ' ' . FRIENDICA_VERSION,
- '$update_interval' => $interval,
- '$head_css' => head_get_css(),
- '$head_js' => head_get_js(),
- '$js_strings' => js_strings()
- ));
+ $a->build_pagehead();
$arr = $a->get_widgets();
if(count($arr)) {
@@ -2022,4 +2077,4 @@ function construct_page(&$a) {
);
return;
-}
\ No newline at end of file
+}
diff --git a/include/ItemObject.php b/include/ItemObject.php
index 8091f003b..6f9eaa18e 100644
--- a/include/ItemObject.php
+++ b/include/ItemObject.php
@@ -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,
diff --git a/include/conversation.php b/include/conversation.php
index ba92c1a57..56bcef559 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..2f4694c58
--- /dev/null
+++ b/include/friendica_smarty.php
@@ -0,0 +1,43 @@
+ "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);
+ }
+}
+
+
+
diff --git a/include/plugin.php b/include/plugin.php
index 6a35a6187..0395c1a8e 100644
--- a/include/plugin.php
+++ b/include/plugin.php
@@ -1,5 +1,6 @@
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;
+ }
+ }
}}
diff --git a/include/text.php b/include/text.php
index 5438aae73..9db22d9ed 100644
--- a/include/text.php
+++ b/include/text.php
@@ -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
\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
\n";
+ return $output;
}}
diff --git a/index.php b/index.php
index d5739f39e..cc6249256 100644
--- a/index.php
+++ b/index.php
@@ -96,13 +96,6 @@ if((x($_GET,'zid')) && (! $install)) {
if((x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login'))
require("auth.php");
-/*
- * Create the page head after setting the language
- * and getting any auth credentials
- */
-
-$a->init_pagehead();
-
if(! x($_SESSION,'sysmsg'))
$_SESSION['sysmsg'] = array();
@@ -280,18 +273,28 @@ if($a->module_loaded) {
if(! $a->error) {
+ // If a theme has defined an _aside() function, run that first
+ //
+ // If the theme function doesn't exist, see if this theme extends another,
+ // and see if that other theme has an _aside() function--if it does, run it
+ //
+ // If $aside_default is not False after the theme _aside() function, run the
+ // module's _aside() function too
+ //
+ // This gives themes more control over how the left sidebar looks
+
$aside_default = true;
call_hooks($a->module . '_mod_aside',$placeholder);
if(function_exists(str_replace('-','_',current_theme()) . '_' . $a->module . '_aside')) {
$func = str_replace('-','_',current_theme()) . '_' . $a->module . '_aside';
$aside_default = $func($a);
}
- elseif(x($a->theme_info,"extends") && $aside_default
+ elseif($aside_default && x($a->theme_info,"extends")
&& (function_exists(str_replace('-','_',$a->theme_info["extends"]) . '_' . $a->module . '_aside'))) {
$func = str_replace('-','_',$a->theme_info["extends"]) . '_' . $a->module . '_aside';
$aside_default = $func($a);
}
- elseif(function_exists($a->module . '_aside') && $aside_default) {
+ if($aside_default && function_exists($a->module . '_aside')) {
$func = $a->module . '_aside';
$func($a);
}
@@ -329,7 +332,6 @@ if(stristr( implode("",$_SESSION['sysmsg']), t('Permission denied'))) {
call_hooks('page_end', $a->page['content']);
-
construct_page($a);
session_write_close();
diff --git a/mod/admin.php b/mod/admin.php
index d0c904b02..13ecf7eef 100644
--- a/mod/admin.php
+++ b/mod/admin.php
@@ -610,7 +610,7 @@ function admin_page_users(&$a){
t('Community/Celebrity Account'),
t('Automatic Friend Account')
);
- $e['page-flags'] = $accounts[$e['page-flags']];
+ $e['page_flags'] = $accounts[$e['page-flags']];
$e['register_date'] = relative_date($e['register_date']);
$e['login_date'] = relative_date($e['login_date']);
$e['lastitem_date'] = relative_date($e['lastitem_date']);
diff --git a/mod/channel.php b/mod/channel.php
index 8729fee2d..096c76ae2 100644
--- a/mod/channel.php
+++ b/mod/channel.php
@@ -2,16 +2,6 @@
function channel_init(&$a) {
- $a->page['htmlhead'] .= '' . "\r\n" ;
-
-}
-
-
-function channel_aside(&$a) {
-
- require_once('include/contact_widgets.php');
- require_once('include/items.php');
-
if(argc() > 1)
$which = argv(1);
else {
@@ -28,10 +18,24 @@ function channel_aside(&$a) {
$profile = argv(1);
}
- $cat = ((x($_REQUEST,'cat')) ? htmlspecialchars($_REQUEST['cat']) : '');
+ $a->page['htmlhead'] .= '' . "\r\n" ;
+ // Run profile_load() here to make sure the theme is set before
+ // we start loading content
profile_load($a,$which,$profile);
+}
+
+
+function channel_aside(&$a) {
+
+ require_once('include/contact_widgets.php');
+ require_once('include/items.php');
+
+ profile_aside($a);
+
+ $cat = ((x($_REQUEST,'cat')) ? htmlspecialchars($_REQUEST['cat']) : '');
+
$a->set_widget('archive',posted_date_widget($a->get_baseurl(true) . '/channel/' . $a->profile['nickname'],$a->profile['profile_uid'],true));
$a->set_widget('categories',categories_widget($a->get_baseurl(true) . '/channel/' . $a->profile['nickname'],$cat));
diff --git a/mod/display.php b/mod/display.php
index c6af8fdd2..d109d9a9b 100644
--- a/mod/display.php
+++ b/mod/display.php
@@ -16,7 +16,7 @@ function display_content(&$a) {
$o = '
"; var_dump($files); killme(); @@ -96,6 +113,7 @@ function fbrowser_content($a){ '$path' => array( array($a->get_baseurl()."/fbrowser/image/", t("Files")) ), '$folders' => false, '$files' =>$files, + '$cancel' => t('Cancel'), )); } diff --git a/mod/hcard.php b/mod/hcard.php index cc6d326b5..83ae7c7af 100644 --- a/mod/hcard.php +++ b/mod/hcard.php @@ -48,3 +48,6 @@ function hcard_init(&$a) { } +function hcard_aside(&$a) { + profile_aside($a); +} diff --git a/mod/hostxrd.php b/mod/hostxrd.php index 9b2411f26..0a66dcc84 100644 --- a/mod/hostxrd.php +++ b/mod/hostxrd.php @@ -14,10 +14,15 @@ function hostxrd_init(&$a) { set_config('system','site_pubkey', $res['pubkey']); } - $tpl = file_get_contents('view/xrd_host.tpl'); - echo str_replace(array( - '$zhost','$zroot','$domain','$zot_post','$bigkey'),array($a->get_hostname(),z_root(),z_path(),z_root() . '/post', salmon_key(get_config('system','site_pubkey'))),$tpl); + $tpl = get_markup_template('xrd_host.tpl'); + echo replace_macros($tpl, array( + '$zhost' => $a->get_hostname(), + '$zroot' => z_root(), + '$domain' => z_path(), + '$zot_post' => z_root() . '/post', + '$bigkey' => salmon_key(get_config('system','site_pubkey')), + )); session_write_close(); exit(); -} \ No newline at end of file +} diff --git a/mod/message.php b/mod/message.php index 3e88362a0..9e5e09e99 100644 --- a/mod/message.php +++ b/mod/message.php @@ -362,6 +362,19 @@ function message_content(&$a) { $rr['to'] = find_xchan_in_array($rr['to_xchan'],$c); $rr['seen'] = (($rr['mail_flags'] & MAIL_SEEN) ? 1 : ""); + if($a->get_template_engine() === 'internal') { + $from_name_e = template_escape($rr['from']['xchan_name']); + $subject_e = template_escape((($rr['seen']) ? $rr['title'] : '' . $rr['title'] . '')); + $body_e = template_escape($rr['body']); + $to_name_e = template_escape($rr['to']['xchan_name']); + } + else { + $from_name_e = $rr['from']['xchan_name']; + $subject_e = (($rr['seen']) ? $rr['title'] : '' . $rr['title'] . ''); + $body_e = $rr['body']; + $to_name_e = $rr['to']['xchan_name']; + } + $o .= replace_macros($tpl, array( '$id' => $rr['id'], '$from_name' => template_escape($rr['from']['xchan_name']), @@ -385,6 +398,10 @@ function message_content(&$a) { $o .= $header; + $plaintext = true; + if( local_user() && feature_enabled(local_user(),'richtext') ) + $plaintext = false; + $r = q("SELECT parent_uri from mail WHERE channel_id = %d and id = %d limit 1", intval(local_user()), intval(argv(1)) @@ -432,7 +449,9 @@ function message_content(&$a) { $a->page['htmlhead'] .= replace_macros($tpl, array( '$nickname' => $channel['channel_addr'], - '$baseurl' => $a->get_baseurl(true) + '$baseurl' => $a->get_baseurl(true), + '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), + '$linkurl' => t('Please enter a link URL:') )); @@ -451,16 +470,29 @@ logger('message: ' . print_r($message,true)); // if($extracted['images']) // $message['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $message['contact-id']); + if($a->get_template_engine() === 'internal') { + $from_name_e = template_escape($message['from']['xchan_name']); + $subject_e = template_escape($message['title']); + $body_e = template_escape(smilies(bbcode($message['body']))); + $to_name_e = template_escape($message['to']['xchan_name']); + } + else { + $from_name_e = $message['from']['xchan_name']; + $subject_e = $message['title']; + $body_e = smilies(bbcode($message['body'])); + $to_name_e = $message['to']['xchan_name']; + } + $mails[] = array( 'id' => $message['id'], - 'from_name' => template_escape($message['from']['xchan_name']), + 'from_name' => $from_name_e, 'from_url' => z_root() . '/chanview/?f=&hash=' . $message['from_xchan'], 'from_photo' => $message['from']['xchan_photo_m'], - 'to_name' => template_escape($message['to']['xchan_name']), + 'to_name' => $to_name_e, 'to_url' => z_root() . '/chanview/?f=&hash=' . $message['to_xchan'], 'to_photo' => $message['to']['xchan_photo_m'], - 'subject' => template_escape($message['title']), - 'body' => template_escape(smilies(bbcode($message['body']))), + 'subject' => $subject_e, + 'body' => $body_e, 'delete' => t('Delete message'), 'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'), ); @@ -476,6 +508,13 @@ logger('message: ' . print_r($message,true)); $select = $message[$recp]['xchan_name'] . ''; $parent = ''; + if($a->get_template_engine() === 'internal') { + $subjtxt_e = template_escape($message['title']); + } + else { + $subjtxt_e = $message['title']; + } + $tpl = get_markup_template('mail_display.tpl'); $o = replace_macros($tpl, array( '$thread_id' => $a->argv[1], @@ -491,7 +530,7 @@ logger('message: ' . print_r($message,true)); '$to' => t('To:'), '$showinputs' => '', '$subject' => t('Subject:'), - '$subjtxt' => template_escape($message['title']), + '$subjtxt' => $subjtxt_e, '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ', '$yourmessage' => t('Your message:'), '$text' => '', diff --git a/mod/photos.php b/mod/photos.php index ee0a930fd..90f436699 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1063,6 +1063,15 @@ function photos_content(&$a) { } + if($a->get_template_engine() === 'internal') { + $albumselect_e = template_escape($albumselect); + $aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user, $celeb))); + } + else { + $albumselect_e = $albumselect; + $aclselect_e = (($visitor) ? '' : populate_acl($a->user, $celeb)); + } + $tpl = get_markup_template('photos_upload.tpl'); $o .= replace_macros($tpl,array( '$pagename' => t('Upload Photos'), @@ -1072,9 +1081,9 @@ function photos_content(&$a) { '$newalbum' => t('New album name: '), '$existalbumtext' => t('or existing album name: '), '$nosharetext' => t('Do not show a status post for this upload'), - '$albumselect' => template_escape($albumselect), + '$albumselect' => $albumselect_e, '$permissions' => t('Permissions'), - '$aclselect' => (($visitor) ? '' : template_escape(populate_acl($a->user, $celeb))), + '$aclselect' => $aclselect_e, '$uploader' => $ret['addon_text'], '$default' => (($ret['default_upload']) ? $default_upload : ''), '$uploadurl' => $ret['post_url'] @@ -1116,11 +1125,18 @@ function photos_content(&$a) { if($cmd === 'edit') { if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) { if($can_post) { + if($a->get_template_engine() === 'internal') { + $album_e = template_escape($album); + } + else { + $album_e = $album; + } + $edit_tpl = get_markup_template('album_edit.tpl'); $o .= replace_macros($edit_tpl,array( '$nametext' => t('New album name: '), '$nickname' => $a->data['channel']['channel_address'], - '$album' => template_escape($album), + '$album' => $album_e, '$hexalbum' => bin2hex($album), '$submit' => t('Submit'), '$dropsubmit' => t('Delete Album') @@ -1160,6 +1176,15 @@ function photos_content(&$a) { $ext = $phototypes[$rr['type']]; + if($a->get_template_engine() === 'internal') { + $imgalt_e = template_escape($rr['filename']); + $desc_e = template_escape($rr['desc']); + } + else { + $imgalt_e = $rr['filename']; + $desc_e = $rr['desc']; + } + $o .= replace_macros($tpl,array( '$id' => $rr['id'], '$twist' => ' ' . $twist . rand(2,4), @@ -1167,8 +1192,8 @@ function photos_content(&$a) { . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''), '$phototitle' => t('View Photo'), '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . $rr['scale'] . '.' .$ext, - '$imgalt' => template_escape($rr['filename']), - '$desc'=> template_escape($rr['desc']) + '$imgalt' => $imgalt_e, + '$desc'=> $desc_e )); } @@ -1365,21 +1390,32 @@ function photos_content(&$a) { $edit = Null; if(($cmd === 'edit') && ($can_post)) { + if($a->get_template_engine() === 'internal') { + $album_e = template_escape($ph[0]['album']); + $caption_e = template_escape($ph[0]['desc']); + $aclselect_e = template_escape(populate_acl($ph[0])); + } + else { + $album_e = $ph[0]['album']; + $caption_e = $ph[0]['desc']; + $aclselect_e = populate_acl($ph[0]); + } + $edit_tpl = get_markup_template('photo_edit.tpl'); $edit = replace_macros($edit_tpl, array( '$id' => $ph[0]['id'], '$rotatecw' => t('Rotate CW (right)'), '$rotateccw' => t('Rotate CCW (left)'), - '$album' => template_escape($ph[0]['album']), + '$album' => $album_e, '$newalbum' => t('New album name'), '$nickname' => $a->data['channel']['channel_address'], '$resource_id' => $ph[0]['resource_id'], '$capt_label' => t('Caption'), - '$caption' => template_escape($ph[0]['desc']), + '$caption' => $caption_e, '$tag_label' => t('Add a Tag'), '$tags' => $link_item['tag'], '$permissions' => t('Permissions'), - '$aclselect' => template_escape(populate_acl($ph[0])), + '$aclselect' => $aclselect_e, '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'), '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0), '$submit' => t('Submit'), @@ -1516,14 +1552,25 @@ function photos_content(&$a) { $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete'))); + if($a->get_template_engine() === 'internal') { + $name_e = template_escape($profile_name); + $title_e = template_escape($item['title']); + $body_e = template_escape(bbcode($item['body'])); + } + else { + $name_e = $profile_name; + $title_e = $item['title']; + $body_e = bbcode($item['body']); + } + $comments .= replace_macros($template,array( '$id' => $item['item_id'], '$profile_url' => $profile_link, - '$name' => template_escape($profile_name), + '$name' => $name_e, '$thumb' => $profile_avatar, '$sparkle' => $sparkle, - '$title' => template_escape($item['title']), - '$body' => template_escape(bbcode($item['body'])), + '$title' => $title_e, + '$body' => $body_e, '$ago' => relative_date($item['created']), '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''), '$drop' => $drop, @@ -1535,21 +1582,34 @@ function photos_content(&$a) { $paginate = paginate($a); } + if($a->get_template_engine() === 'internal') { + $album_e = array($album_link,template_escape($ph[0]['album'])); + $tags_e = template_escape($tags); + $like_e = template_escape($like); + $dislike_e = template_escape($dislike); + } + else { + $album_e = array($album_link,$ph[0]['album']); + $tags_e = $tags; + $like_e = $like; + $dislike_e = $dislike; + } + $photo_tpl = get_markup_template('photo_view.tpl'); $o .= replace_macros($photo_tpl, array( '$id' => $ph[0]['id'], - '$album' => array($album_link,template_escape($ph[0]['album'])), + '$album' => $album_e, '$tools' => $tools, '$lock' => $lock, '$photo' => $photo, '$prevlink' => $prevlink, '$nextlink' => $nextlink, '$desc' => $ph[0]['desc'], - '$tags' => template_escape($tags), + '$tags' => $tags_e, '$edit' => $edit, '$likebuttons' => $likebuttons, - '$like' => template_escape($like), - '$dislike' => template_escape($dislike), + '$like' => $like_e, + '$dislike' => $dislike_e, '$comments' => $comments, '$paginate' => $paginate, )); @@ -1593,16 +1653,25 @@ function photos_content(&$a) { $twist = 'rotright'; $ext = $phototypes[$rr['type']]; + if($a->get_template_engine() === 'internal') { + $alt_e = template_escape($rr['filename']); + $name_e = template_escape($rr['album']); + } + else { + $alt_e = $rr['filename']; + $name_e = $rr['album']; + } + $photos[] = array( 'id' => $rr['id'], 'twist' => ' ' . $twist . rand(2,4), 'link' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $rr['resource_id'], 'title' => t('View Photo'), 'src' => $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext, - 'alt' => template_escape($rr['filename']), + 'alt' => $alt_e, 'album' => array( 'link' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($rr['album']), - 'name' => template_escape($rr['album']), + 'name' => $name_e, 'alt' => t('View Album'), ), @@ -1611,7 +1680,7 @@ function photos_content(&$a) { } $tpl = get_markup_template('photos_recent.tpl'); - $o .= replace_macros($tpl,array( + $o .= replace_macros($tpl, array( '$title' => t('Recent Photos'), '$can_post' => $can_post, '$upload' => array(t('Upload New Photos'), $a->get_baseurl().'/photos/'.$a->data['channel']['channel_address'].'/upload'), diff --git a/mod/profile.php b/mod/profile.php index ce2d92f9b..8f15766b6 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -2,16 +2,6 @@ function profile_init(&$a) { - $a->page['htmlhead'] .= '' . "\r\n" ; - -} - - -function profile_aside(&$a) { - - require_once('include/contact_widgets.php'); - require_once('include/items.php'); - if(argc() > 1) $which = argv(1); else { @@ -28,6 +18,7 @@ function profile_aside(&$a) { $profile = argv(1); } + $a->page['htmlhead'] .= '' . "\r\n" ; $x = q("select channel_id as profile_uid from channel where channel_address = '%s' limit 1", dbesc(argv(1)) @@ -37,13 +28,33 @@ function profile_aside(&$a) { $channel_display = get_pconfig($a->profile['profile_uid'],'system','channel_format'); if(! $channel_display) profile_load($a,$which,$profile); + } + +} + + +function profile_aside(&$a) { + + require_once('include/contact_widgets.php'); + require_once('include/items.php'); + + $x = q("select channel_id as profile_uid from channel where channel_address = '%s' limit 1", + dbesc(argv(1)) + ); + if($x) { + $channel_display = get_pconfig($a->profile['profile_uid'],'system','channel_format'); + if(! $channel_display) + profile_aside($a); + if($channel_display === 'full') $a->page['template'] = 'full'; else { + $cat = ((x($_REQUEST,'cat')) ? htmlspecialchars($_REQUEST['cat']) : ''); $a->set_widget('archive',posted_date_widget($a->get_baseurl(true) . '/channel/' . $a->profile['nickname'],$a->profile['profile_uid'],true)); $a->set_widget('categories',categories_widget($a->get_baseurl(true) . '/channel/' . $a->profile['nickname'],$cat)); } } + } diff --git a/mod/profile_photo.php b/mod/profile_photo.php index e78d2ca6f..e7be543c6 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -14,6 +14,16 @@ function profile_photo_init(&$a) { } +function profile_photo_init(&$a) { + + if(! local_user()) { + return; + } + + profile_aside($a); +} + + function profile_photo_post(&$a) { if(! local_user()) { @@ -318,7 +328,7 @@ function profile_photo_crop_ui_head(&$a, $ph){ $a->config['imagecrop'] = $hash; $a->config['imagecrop_resolution'] = $smallest; $a->config['imagecrop_ext'] = $ph->getExt(); - $a->page['htmlhead'] .= get_markup_template("crophead.tpl"); + $a->page['htmlhead'] .= replace_macros(get_markup_template("crophead.tpl"), array()); return; }} diff --git a/mod/profiles.php b/mod/profiles.php index 37be9bd08..5b2102852 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -1,6 +1,162 @@ 2) && (argv(1) === "drop") && intval(argv(2))) { + $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is_default` = 0 LIMIT 1", + intval($a->argv[2]), + intval(local_user()) + ); + if(! count($r)) { + notice( t('Profile not found.') . EOL); + goaway($a->get_baseurl(true) . '/profiles'); + return; // NOTREACHED + } + $profile_guid = $r['profile_guid']; + + check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't'); + + // move every contact using this profile as their default to the user default + + $r = q("UPDATE abook SET abook_profile = (SELECT profile_guid AS FROM profile WHERE is_default = 1 AND uid = %d LIMIT 1) WHERE abook_profile = '%s' AND abook_channel = %d ", + intval(local_user()), + dbesc($profile_guid), + intval(local_user()) + ); + $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", + intval(argv(2)), + intval(local_user()) + ); + if($r) + info( t('Profile deleted.') . EOL); + + goaway($a->get_baseurl(true) . '/profiles'); + return; // NOTREACHED + } + + + + + + if((argc() > 1) && (argv(1) === 'new')) { + + check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't'); + + $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", + intval(local_user())); + $num_profiles = count($r0); + + $name = t('Profile-') . ($num_profiles + 1); + + $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is_default` = 1 LIMIT 1", + intval(local_user())); + + $r2 = q("INSERT INTO `profile` (`aid`, `uid` , `profile_guid`, `profile_name` , `name`, `photo`, `thumb`) + VALUES ( %d, '%s', '%s', '%s', '%s' )", + intval(get_account_id()), + intval(local_user()), + dbesc(random_string()), + dbesc($name), + dbesc($r1[0]['name']), + dbesc($r1[0]['photo']), + dbesc($r1[0]['thumb']) + ); + + $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile_name` = '%s' LIMIT 1", + intval(local_user()), + dbesc($name) + ); + + info( t('New profile created.') . EOL); + if(count($r3) == 1) + goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']); + + goaway($a->get_baseurl(true) . '/profiles'); + } + + if((argc() > 2) && (argv(1) === 'clone')) { + + check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't'); + + $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", + intval(local_user())); + $num_profiles = count($r0); + + $name = t('Profile-') . ($num_profiles + 1); + $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1", + intval(local_user()), + intval($a->argv[2]) + ); + if(! count($r1)) { + notice( t('Profile unavailable to clone.') . EOL); + $a->error = 404; + return; + } + unset($r1[0]['id']); + $r1[0]['is_default'] = 0; + $r1[0]['publish'] = 0; + $r1[0]['profile_name'] = dbesc($name); + $r1[0]['profile_guid'] = dbesc(random_string()); + + dbesc_array($r1[0]); + + $r2 = dbq("INSERT INTO `profile` (`" + . implode("`, `", array_keys($r1[0])) + . "`) VALUES ('" + . implode("', '", array_values($r1[0])) + . "')" ); + + $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile_name` = '%s' LIMIT 1", + intval(local_user()), + dbesc($name) + ); + info( t('New profile created.') . EOL); + if(count($r3) == 1) + goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']); + + goaway($a->get_baseurl(true) . '/profiles'); + + return; // NOTREACHED + } + + + // Run profile_load() here to make sure the theme is set before + // we start loading content + if((argc() > 1) && (intval(argv(1)))) { + $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", + intval($a->argv[1]), + intval(local_user()) + ); + if(! count($r)) { + notice( t('Profile not found.') . EOL); + $a->error = 404; + return; + } + + $chan = $a->get_channel(); + + profile_load($a,$chan['channel_address'],$r[0]['id']); + } +} + +function profiles_aside(&$a) { + + if(! local_user()) { + return; + } + + if((argc() > 1) && (intval(argv(1)))) { + profile_aside($a); + } +} + function profiles_post(&$a) { if(! local_user()) { @@ -307,130 +463,12 @@ function profiles_post(&$a) { function profiles_content(&$a) { $o = ''; - nav_set_selected('profiles'); if(! local_user()) { notice( t('Permission denied.') . EOL); return; } - if((argc() > 2) && (argv(1) === "drop") && intval(argv(2))) { - $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is_default` = 0 LIMIT 1", - intval($a->argv[2]), - intval(local_user()) - ); - if(! count($r)) { - notice( t('Profile not found.') . EOL); - goaway($a->get_baseurl(true) . '/profiles'); - return; // NOTREACHED - } - $profile_guid = $r['profile_guid']; - - check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't'); - - // move every contact using this profile as their default to the user default - - $r = q("UPDATE abook SET abook_profile = (SELECT profile_guid AS FROM profile WHERE is_default = 1 AND uid = %d LIMIT 1) WHERE abook_profile = '%s' AND abook_channel = %d ", - intval(local_user()), - dbesc($profile_guid), - intval(local_user()) - ); - $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval(argv(2)), - intval(local_user()) - ); - if($r) - info( t('Profile deleted.') . EOL); - - goaway($a->get_baseurl(true) . '/profiles'); - return; // NOTREACHED - } - - - - - - if((argc() > 1) && (argv(1) === 'new')) { - - check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't'); - - $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", - intval(local_user())); - $num_profiles = count($r0); - - $name = t('Profile-') . ($num_profiles + 1); - - $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is_default` = 1 LIMIT 1", - intval(local_user())); - - $r2 = q("INSERT INTO `profile` (`aid`, `uid` , `profile_guid`, `profile_name` , `name`, `photo`, `thumb`) - VALUES ( %d, '%s', '%s', '%s', '%s' )", - intval(get_account_id()), - intval(local_user()), - dbesc(random_string()), - dbesc($name), - dbesc($r1[0]['name']), - dbesc($r1[0]['photo']), - dbesc($r1[0]['thumb']) - ); - - $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile_name` = '%s' LIMIT 1", - intval(local_user()), - dbesc($name) - ); - - info( t('New profile created.') . EOL); - if(count($r3) == 1) - goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']); - - goaway($a->get_baseurl(true) . '/profiles'); - } - - if((argc() > 2) && (argv(1) === 'clone')) { - - check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't'); - - $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", - intval(local_user())); - $num_profiles = count($r0); - - $name = t('Profile-') . ($num_profiles + 1); - $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1", - intval(local_user()), - intval($a->argv[2]) - ); - if(! count($r1)) { - notice( t('Profile unavailable to clone.') . EOL); - return; - } - unset($r1[0]['id']); - $r1[0]['is_default'] = 0; - $r1[0]['publish'] = 0; - $r1[0]['profile_name'] = dbesc($name); - $r1[0]['profile_guid'] = dbesc(random_string()); - - dbesc_array($r1[0]); - - $r2 = dbq("INSERT INTO `profile` (`" - . implode("`, `", array_keys($r1[0])) - . "`) VALUES ('" - . implode("', '", array_values($r1[0])) - . "')" ); - - $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile_name` = '%s' LIMIT 1", - intval(local_user()), - dbesc($name) - ); - info( t('New profile created.') . EOL); - if(count($r3) == 1) - goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']); - - goaway($a->get_baseurl(true) . '/profiles'); - - return; // NOTREACHED - } - - if((argc() > 1) && (intval(argv(1)))) { $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[1]), @@ -441,10 +479,6 @@ function profiles_content(&$a) { return; } - $chan = $a->get_channel(); - - profile_load($a,$chan['channel_address'],$r[0]['id']); - require_once('include/profile_selectors.php'); diff --git a/mod/profperm.php b/mod/profperm.php index b31dfc128..7c7fe7b11 100644 --- a/mod/profperm.php +++ b/mod/profperm.php @@ -13,6 +13,15 @@ function profperm_init(&$a) { } +function profperm_aside(&$a) { + + if(! local_user()) + return; + + profile_aside($a); +} + + function profperm_content(&$a) { if(! local_user()) { diff --git a/mod/setup.php b/mod/setup.php index b3649ca40..4fa5152ea 100755 --- a/mod/setup.php +++ b/mod/setup.php @@ -183,6 +183,8 @@ function setup_content(&$a) { check_htconfig($checks); + check_smarty3($checks); + check_keys($checks); if(x($_POST,'phpath')) @@ -439,6 +441,22 @@ function check_htconfig(&$checks) { } +function check_smarty3(&$checks) { + $status = true; + $help = ""; + if( !is_writable('view/tpl/smarty3') ) { + + $status=false; + $help = t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL; + $help .= t('In order to store these compiled templates, the web server needs to have write access to the directory view/tpl/smarty3/ under the Friendica top level folder.').EOL; + $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL; + $help .= t('Note: as a security measure, you should give the web server write access to view/tpl/smarty3/ only--not the template files (.tpl) that it contains.').EOL; + } + + check_add($checks, t('view/tpl/smarty3 is writable'), $status, true, $help); + +} + function check_htaccess(&$checks) { $a = get_app(); $status = true; diff --git a/mod/viewcontacts.php b/mod/viewcontacts.php index 8133fb4a0..7f5050d5d 100644 --- a/mod/viewcontacts.php +++ b/mod/viewcontacts.php @@ -11,6 +11,16 @@ function viewcontacts_init(&$a) { } +function viewcontacts_aside(&$a) { + + if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + return; + } + + profile_aside($a); +} + + function viewcontacts_content(&$a) { if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { diff --git a/mod/xrd.php b/mod/xrd.php index d22ff4699..a576f76c4 100644 --- a/mod/xrd.php +++ b/mod/xrd.php @@ -29,7 +29,7 @@ function xrd_init(&$a) { $dspr = ''; - $tpl = file_get_contents('view/xrd_person.tpl'); + $tpl = get_markup_template('view/xrd_person.tpl'); $o = replace_macros($tpl, array( '$nick' => $r[0]['nickname'], diff --git a/mods/friendica-to-smarty-tpl.py b/mods/friendica-to-smarty-tpl.py new file mode 100755 index 000000000..b82aa912a --- /dev/null +++ b/mods/friendica-to-smarty-tpl.py @@ -0,0 +1,198 @@ +#!/usr/bin/python +# +# Script to convert Friendica internal template files into Smarty template files +# Copyright 2012 Zach Prezkuta +# Licensed under GPL v3 + +import os, re, string + +ldelim = '{{' +rdelim = '}}' + +def fToSmarty(matches): + match = matches.group(0) + if match == '$j': + return match + match = string.replace(match, '[', '') + match = string.replace(match, ']', '') + + ldel = ldelim + rdel = rdelim + if match.find("'") > -1: + match = string.replace(match, "'", '') + ldel = "'" + ldel + rdel = rdel + "'" + elif match.find('"') > -1: + match = string.replace(match, '"', '') + ldel = '"' + ldel + rdel = rdel + '"' + + return ldel + match + rdel + + +def fix_element(element): + # Much of the positioning here is important, e.g. if you do element.find('if ') before you do + # element.find('endif'), then you may get some multiply-replaced delimiters + + if element.find('endif') > -1: + element = ldelim + '/if' + rdelim + return element + + if element.find('if ') > -1: + element = string.replace(element, '{{ if', ldelim + 'if') + element = string.replace(element, '{{if', ldelim + 'if') + element = string.replace(element, ' }}', rdelim) + element = string.replace(element, '}}', rdelim) + return element + + if element.find('else') > -1: + element = ldelim + 'else' + rdelim + return element + + if element.find('endfor') > -1: + element = ldelim + '/foreach' + rdelim + return element + + if element.find('for ') > -1: + element = string.replace(element, '{{ for ', ldelim + 'foreach ') + element = string.replace(element, '{{for ', ldelim + 'foreach ') + element = string.replace(element, ' }}', rdelim) + element = string.replace(element, '}}', rdelim) + return element + + if element.find('endinc') > -1: + element = '' + return element + + if element.find('inc ') > -1: + parts = element.split(' ') + element = ldelim + 'include file="' + + # We need to find the file name. It'll either be in parts[1] if the element was written as {{ inc file.tpl }} + # or it'll be in parts[2] if the element was written as {{inc file.tpl}} + if parts[0].find('inc') > -1: + first = 0 + else: + first = 1 + + if parts[first+1][0] == '$': + # This takes care of elements where the filename is a variable, e.g. {{ inc $file }} + element += ldelim + parts[first+1].rstrip('}') + rdelim + else: + # This takes care of elements where the filename is a path, e.g. {{ inc file.tpl }} + element += parts[first+1].rstrip('}') + + element += '"' + + if len(parts) > first + 1 and parts[first+2] == 'with': + # Take care of variable substitutions, e.g. {{ inc file.tpl with $var=this_var }} + element += ' ' + parts[first+3].rstrip('}')[1:] + + element += rdelim + return element + + +def convert(filename, tofilename, php_tpl): + for line in filename: + newline = '' + st_pos = 0 + brack_pos = line.find('{{') + + if php_tpl: + # If php_tpl is True, this script will only convert variables in quotes, like '$variable' + # or "$variable". This is for .tpl files that produce PHP scripts, where you don't want + # all the PHP variables converted into Smarty variables + pattern1 = re.compile(r""" +([\'\"]\$\[[a-zA-Z]\w* +(\. +(\d+|[a-zA-Z][\w-]*) +)* +(\|[\w\$:\.]*)* +\][\'\"]) +""", re.VERBOSE) + pattern2 = re.compile(r""" +([\'\"]\$[a-zA-Z]\w* +(\. +(\d+|[a-zA-Z][\w-]*) +)* +(\|[\w\$:\.]*)* +[\'\"]) +""", re.VERBOSE) + else: + # Compile the pattern for bracket-style variables, e.g. $[variable.key|filter:arg1:arg2|filter2:arg1:arg2] + # Note that dashes are only allowed in array keys if the key doesn't start + # with a number, e.g. $[variable.key-id] is ok but $[variable.12-id] isn't + # + # Doesn't currently process the argument position key 'x', i.e. filter:arg1:x:arg2 doesn't get + # changed to arg1|filter:variable:arg2 like Smarty requires + # + # Filter arguments can be variables, e.g. $variable, but currently can't have array keys with dashes + # like filter:$variable.key-name + pattern1 = re.compile(r""" +(\$\[[a-zA-Z]\w* +(\. +(\d+|[a-zA-Z][\w-]*) +)* +(\|[\w\$:\.]*)* +\]) +""", re.VERBOSE) + + # Compile the pattern for normal style variables, e.g. $variable.key + pattern2 = re.compile(r""" +(\$[a-zA-Z]\w* +(\. +(\d+|[a-zA-Z][\w-]*) +)* +(\|[\w\$:\.]*)* +) +""", re.VERBOSE) + + while brack_pos > -1: + if brack_pos > st_pos: + line_segment = line[st_pos:brack_pos] + line_segment = pattern2.sub(fToSmarty, line_segment) + newline += pattern1.sub(fToSmarty, line_segment) + + end_brack_pos = line.find('}}', brack_pos) + if end_brack_pos < 0: + print "Error: no matching bracket found" + + newline += fix_element(line[brack_pos:end_brack_pos + 2]) + st_pos = end_brack_pos + 2 + + brack_pos = line.find('{{', st_pos) + + line_segment = line[st_pos:] + line_segment = pattern2.sub(fToSmarty, line_segment) + newline += pattern1.sub(fToSmarty, line_segment) + newline = newline.replace("{#", ldelim + "*") + newline = newline.replace("#}", "*" + rdelim) + tofilename.write(newline) + + +path = raw_input('Path to template folder to convert: ') +if path[-1:] != '/': + path = path + '/' + +outpath = path + 'smarty3/' + +if not os.path.exists(outpath): + os.makedirs(outpath) + +files = os.listdir(path) +for a_file in files: + if a_file == 'htconfig.tpl': + php_tpl = True + else: + php_tpl = False + + filename = os.path.join(path,a_file) + ext = a_file.split('.')[-1] + if os.path.isfile(filename) and ext == 'tpl': + with open(filename, 'r') as f: + newfilename = os.path.join(outpath,a_file) + with open(newfilename, 'w') as outf: + print "Converting " + filename + " to " + newfilename + convert(f, outf, php_tpl) + + diff --git a/view/theme/fancyred/php/config.php b/view/theme/fancyred/php/config.php index 48035f507..833d09050 100644 --- a/view/theme/fancyred/php/config.php +++ b/view/theme/fancyred/php/config.php @@ -65,7 +65,7 @@ function fancyred_form(&$a, $font_size, $line_height, $colour) { 'dark' => 'dark', ); - $t = file_get_contents( dirname(__file__). "/../tpl/theme_settings.tpl" ); + $t = get_markup_template('theme_settings.tpl'); $o .= replace_macros($t, array( '$submit' => t('Submit'), '$baseurl' => $a->get_baseurl(), diff --git a/view/theme/fancyred/php/theme.php b/view/theme/fancyred/php/theme.php index b77664567..1ac6d4d21 100644 --- a/view/theme/fancyred/php/theme.php +++ b/view/theme/fancyred/php/theme.php @@ -1,5 +1,6 @@ set_template_engine('smarty3'); // head_add_js('redbasic.js'); } diff --git a/view/theme/fancyred/tpl/smarty3/conv_item.tpl b/view/theme/fancyred/tpl/smarty3/conv_item.tpl new file mode 100644 index 000000000..cf0f02f03 --- /dev/null +++ b/view/theme/fancyred/tpl/smarty3/conv_item.tpl @@ -0,0 +1,117 @@ +{{if $item.comment_firstcollapsed}} ++ {{/if}} diff --git a/view/theme/fancyred/tpl/smarty3/theme_settings.tpl b/view/theme/fancyred/tpl/smarty3/theme_settings.tpl new file mode 100644 index 000000000..72749d9ce --- /dev/null +++ b/view/theme/fancyred/tpl/smarty3/theme_settings.tpl @@ -0,0 +1,7 @@ +{{include file="field_select.tpl" field=$font_size}} + +{{include file="field_select.tpl" field=$line_height}} + ++ +diff --git a/view/theme/redbasic/php/config.php b/view/theme/redbasic/php/config.php index 1ca9cc5ed..ad5df57ce 100644 --- a/view/theme/redbasic/php/config.php +++ b/view/theme/redbasic/php/config.php @@ -65,7 +65,7 @@ function redbasic_form(&$a, $font_size, $line_height, $colour) { 'dark' => 'dark', ); - $t = file_get_contents( dirname(__file__). "/../tpl/theme_settings.tpl" ); + $t = get_markup_template('theme_settings.tpl'); $o .= replace_macros($t, array( '$submit' => t('Submit'), '$baseurl' => $a->get_baseurl(), diff --git a/view/theme/redbasic/php/theme.php b/view/theme/redbasic/php/theme.php index 47e1df5d1..52e571f0a 100644 --- a/view/theme/redbasic/php/theme.php +++ b/view/theme/redbasic/php/theme.php @@ -1,5 +1,6 @@ set_template_engine('smarty3'); // head_add_js('redbasic.js'); } diff --git a/view/theme/redbasic/tpl/smarty3/theme_settings.tpl b/view/theme/redbasic/tpl/smarty3/theme_settings.tpl new file mode 100644 index 000000000..27f356b92 --- /dev/null +++ b/view/theme/redbasic/tpl/smarty3/theme_settings.tpl @@ -0,0 +1,7 @@ +{{include file="field_select.tpl" field=$font_size}} + +{{include file="field_select.tpl" field=$line_height}} + ++ +diff --git a/view/tpl/admin_users.tpl b/view/tpl/admin_users.tpl index f67e4a0f7..727030f5d 100644 --- a/view/tpl/admin_users.tpl +++ b/view/tpl/admin_users.tpl @@ -70,7 +70,7 @@$u.register_date $u.login_date $u.lastitem_date -$u.page-flags +$u.page_flags diff --git a/view/tpl/conv_item.tpl b/view/tpl/conv_item.tpl index 66fb499a6..0c0553639 100644 --- a/view/tpl/conv_item.tpl +++ b/view/tpl/conv_item.tpl @@ -101,8 +101,8 @@ {{ if $item.toplevel }} -{{ for $item.children as $item }} - {{ inc $item.template }}{{ endinc }} +{{ for $item.children as $child }} + {{ inc $child.template with $item=$child }}{{ endinc }} {{ endfor }} {{ endif }} diff --git a/view/tpl/directory_item.tpl b/view/tpl/directory_item.tpl index b45da4465..d496cb2ad 100644 --- a/view/tpl/directory_item.tpl +++ b/view/tpl/directory_item.tpl @@ -2,7 +2,7 @@ diff --git a/view/tpl/filebrowser.tpl b/view/tpl/filebrowser.tpl index 1e97237f4..7db31d716 100644 --- a/view/tpl/filebrowser.tpl +++ b/view/tpl/filebrowser.tpl @@ -77,7 +77,7 @@- +