Browse Source

Implement Smarty3

tags/3.2
Zach Prezkuta 7 years ago
parent
commit
96ed0a7791
100 changed files with 2499 additions and 230 deletions
  1. +38
    -6
      boot.php
  2. +51
    -16
      include/conversation.php
  3. +36
    -0
      include/friendica_smarty.php
  4. +89
    -21
      include/text.php
  5. +28
    -5
      mod/admin.php
  6. +14
    -3
      mod/contacts.php
  7. +47
    -12
      mod/content.php
  8. +11
    -4
      mod/directory.php
  9. +1
    -1
      mod/display.php
  10. +18
    -2
      mod/fbrowser.php
  11. +6
    -0
      mod/filer.php
  12. +12
    -2
      mod/group.php
  13. +12
    -4
      mod/hostxrd.php
  14. +15
    -2
      mod/install.php
  15. +91
    -41
      mod/message.php
  16. +8
    -1
      mod/nogroup.php
  17. +50
    -14
      mod/notifications.php
  18. +8
    -3
      mod/notify.php
  19. +97
    -18
      mod/photos.php
  20. +8
    -2
      mod/poco.php
  21. +1
    -0
      mod/profile.php
  22. +2
    -2
      mod/profile_photo.php
  23. +59
    -8
      mod/settings.php
  24. +10
    -4
      mod/uimport.php
  25. +7
    -1
      mod/viewcontacts.php
  26. +4
    -2
      mod/xrd.php
  27. +198
    -0
      mods/friendica-to-smarty-tpl.py
  28. +34
    -7
      object/Item.php
  29. +3
    -3
      view/admin_logs.tpl
  30. +4
    -4
      view/admin_remoteupdate.tpl
  31. +35
    -35
      view/admin_site.tpl
  32. +4
    -2
      view/api_friends_xml.tpl
  33. +1
    -1
      view/api_timeline_xml.tpl
  34. +18
    -0
      view/ca/smarty3/cmnt_received_eml.tpl
  35. +13
    -0
      view/ca/smarty3/follow_notify_eml.tpl
  36. +19
    -0
      view/ca/smarty3/friend_complete_eml.tpl
  37. +68
    -0
      view/ca/smarty3/htconfig.tpl
  38. +21
    -0
      view/ca/smarty3/intro_complete_eml.tpl
  39. +35
    -0
      view/ca/smarty3/lostpass_eml.tpl
  40. +24
    -0
      view/ca/smarty3/mail_received_html_body_eml.tpl
  41. +9
    -0
      view/ca/smarty3/mail_received_text_body_eml.tpl
  42. +19
    -0
      view/ca/smarty3/passchanged_eml.tpl
  43. +22
    -0
      view/ca/smarty3/register_open_eml.tpl
  44. +23
    -0
      view/ca/smarty3/register_verify_eml.tpl
  45. +13
    -0
      view/ca/smarty3/request_notify_eml.tpl
  46. +18
    -0
      view/ca/smarty3/wall_received_eml.tpl
  47. +1
    -1
      view/contact_edit.tpl
  48. +2
    -2
      view/contacts-template.tpl
  49. +14
    -0
      view/cs/smarty3/cmnt_received_eml.tpl
  50. +25
    -0
      view/cs/smarty3/cmnt_received_html_body_eml.tpl
  51. +14
    -0
      view/cs/smarty3/cmnt_received_text_body_eml.tpl
  52. +14
    -0
      view/cs/smarty3/follow_notify_eml.tpl
  53. +17
    -0
      view/cs/smarty3/friend_complete_eml.tpl
  54. +73
    -0
      view/cs/smarty3/htconfig.tpl
  55. +17
    -0
      view/cs/smarty3/intro_complete_eml.tpl
  56. +23
    -0
      view/cs/smarty3/lostpass_eml.tpl
  57. +25
    -0
      view/cs/smarty3/mail_received_html_body_eml.tpl
  58. +10
    -0
      view/cs/smarty3/mail_received_text_body_eml.tpl
  59. +14
    -0
      view/cs/smarty3/passchanged_eml.tpl
  60. +23
    -0
      view/cs/smarty3/register_open_eml.tpl
  61. +22
    -0
      view/cs/smarty3/register_verify_eml.tpl
  62. +15
    -0
      view/cs/smarty3/request_notify_eml.tpl
  63. +14
    -0
      view/cs/smarty3/wall_received_eml.tpl
  64. +24
    -0
      view/cs/smarty3/wall_received_html_body_eml.tpl
  65. +14
    -0
      view/cs/smarty3/wall_received_text_body_eml.tpl
  66. +17
    -0
      view/de/smarty3/cmnt_received_eml.tpl
  67. +25
    -0
      view/de/smarty3/cmnt_received_html_body_eml.tpl
  68. +16
    -0
      view/de/smarty3/cmnt_received_text_body_eml.tpl
  69. +14
    -0
      view/de/smarty3/follow_notify_eml.tpl
  70. +22
    -0
      view/de/smarty3/friend_complete_eml.tpl
  71. +68
    -0
      view/de/smarty3/htconfig.tpl
  72. +22
    -0
      view/de/smarty3/intro_complete_eml.tpl
  73. +32
    -0
      view/de/smarty3/lostpass_eml.tpl
  74. +26
    -0
      view/de/smarty3/mail_received_html_body_eml.tpl
  75. +11
    -0
      view/de/smarty3/mail_received_text_body_eml.tpl
  76. +20
    -0
      view/de/smarty3/passchanged_eml.tpl
  77. +34
    -0
      view/de/smarty3/register_open_eml.tpl
  78. +25
    -0
      view/de/smarty3/register_verify_eml.tpl
  79. +17
    -0
      view/de/smarty3/request_notify_eml.tpl
  80. +11
    -0
      view/de/smarty3/update_fail_eml.tpl
  81. +18
    -0
      view/de/smarty3/wall_received_eml.tpl
  82. +24
    -0
      view/de/smarty3/wall_received_html_body_eml.tpl
  83. +18
    -0
      view/de/smarty3/wall_received_text_body_eml.tpl
  84. +1
    -1
      view/directory_item.tpl
  85. +14
    -0
      view/en/smarty3/follow_notify_eml.tpl
  86. +22
    -0
      view/en/smarty3/friend_complete_eml.tpl
  87. +71
    -0
      view/en/smarty3/htconfig.tpl
  88. +22
    -0
      view/en/smarty3/intro_complete_eml.tpl
  89. +32
    -0
      view/en/smarty3/lostpass_eml.tpl
  90. +20
    -0
      view/en/smarty3/passchanged_eml.tpl
  91. +34
    -0
      view/en/smarty3/register_open_eml.tpl
  92. +26
    -0
      view/en/smarty3/register_verify_eml.tpl
  93. +17
    -0
      view/en/smarty3/request_notify_eml.tpl
  94. +11
    -0
      view/en/smarty3/update_fail_eml.tpl
  95. +14
    -0
      view/eo/smarty3/follow_notify_eml.tpl
  96. +22
    -0
      view/eo/smarty3/friend_complete_eml.tpl
  97. +22
    -0
      view/eo/smarty3/intro_complete_eml.tpl
  98. +32
    -0
      view/eo/smarty3/lostpass_eml.tpl
  99. +20
    -0
      view/eo/smarty3/passchanged_eml.tpl
  100. +34
    -0
      view/eo/smarty3/register_open_eml.tpl

+ 38
- 6
boot.php View File

@@ -380,9 +380,13 @@ if(! class_exists('App')) {
'videoheight' => 350,
'force_max_items' => 0,
'thread_allow' => true,
'stylesheet' => ''
'stylesheet' => '',
'template_engine' => 'internal',
);

public $smarty3_ldelim = '{{';
public $smarty3_rdelim = '}}';

private $scheme;
private $hostname;
private $baseurl;
@@ -613,6 +617,16 @@ if(! class_exists('App')) {
if(!isset($this->page['htmlhead']))
$this->page['htmlhead'] = '';
$tpl = get_markup_template('head.tpl');

// If we're using Smarty, then doing replace_macros() will replace
// any unrecognized variables with a blank string. Since we delay
// replacing $stylesheet until later, we need to replace it now
// with another variable name
if($this->theme['template_engine'] === 'smarty3')
$stylesheet = $this->smarty3_ldelim . '$stylesheet' . $this->smarty3_rdelim;
else
$stylesheet = '$stylesheet';

$this->page['htmlhead'] = replace_macros($tpl,array(
'$baseurl' => $this->get_baseurl(), // FIXME for z_path!!!!
'$local_user' => local_user(),
@@ -621,7 +635,8 @@ if(! class_exists('App')) {
'$comment' => t('Comment'),
'$showmore' => t('show more'),
'$showfewer' => t('show fewer'),
'$update_interval' => $interval
'$update_interval' => $interval,
'$stylesheet' => $stylesheet
)) . $this->page['htmlhead'];
}

@@ -955,7 +970,15 @@ if(! function_exists('login')) {
}


$o .= replace_macros($tpl,array(
$includes = array(
'$field_input' => 'field_input.tpl',
'$field_password' => 'field_password.tpl',
'$field_openid' => 'field_openid.tpl',
'$field_checkbox' => 'field_checkbox.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($tpl,$includes + array(

'$dest_url' => $dest_url,
'$logout' => t('Logout'),
@@ -1324,16 +1347,25 @@ if(! function_exists('profile_sidebar')) {

$tpl = get_markup_template('profile_vcard.tpl');

$o .= replace_macros($tpl, array(

$includes = array(
'$diaspora_vcard' => 'diaspora_vcard.tpl'
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

if($a->theme['template_engine'] === 'internal')
$location = template_escape($location);

$o .= replace_macros($tpl, $includes + array(
'$profile' => $profile,
'$connect' => $connect,
'$wallmessage' => $wallmessage,
'$location' => template_escape($location),
'$location' => $location,
'$gender' => $gender,
'$pdesc' => $pdesc,
'$marital' => $marital,
'$homepage' => $homepage,
'$diaspora' => $diaspora,
'$diaspora_info' => $diaspora,
'$contact_block' => $contact_block,
));



+ 51
- 16
include/conversation.php View File

@@ -581,33 +581,54 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {

list($categories, $folders) = get_cats_and_terms($item);

if($a->theme['template_engine'] === 'internal') {
$profile_name_e = template_escape($profile_name);
$item['title_e'] = template_escape($item['title']);
$body_e = template_escape($body);
$tags_e = template_escape($tags);
$hashtags_e = template_escape($hashtags);
$mentions_e = template_escape($mentions);
$location_e = template_escape($location);
$owner_name_e = template_escape($owner_name);
}
else {
$profile_name_e = $profile_name;
$item['title_e'] = $item['title'];
$body_e = $body;
$tags_e = $tags;
$hashtags_e = $hashtags;
$mentions_e = $mentions;
$location_e = $location;
$owner_name_e = $owner_name;
}

$tmp_item = array(
'template' => $tpl,
'id' => (($preview) ? 'P0' : $item['item_id']),
'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
'profile_url' => $profile_link,
'item_photo_menu' => item_photo_menu($item),
'name' => template_escape($profile_name),
'name' => $profile_name_e,
'sparkle' => $sparkle,
'lock' => $lock,
'thumb' => $profile_avatar,
'title' => template_escape($item['title']),
'body' => template_escape($body),
'tags' => template_escape($tags),
'hashtags' => template_escape($hashtags),
'mentions' => template_escape($mentions),
'title' => $item['title_e'],
'body' => $body_e,
'tags' => $tags_e,
'hashtags' => $hashtags_e,
'mentions' => $mentions_e,
'txt_cats' => t('Categories:'),
'txt_folders' => t('Filed under:'),
'has_cats' => ((count($categories)) ? 'true' : ''),
'has_folders' => ((count($folders)) ? 'true' : ''),
'categories' => $categories,
'folders' => $folders,
'text' => strip_tags(template_escape($body)),
'text' => strip_tags($body_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'])),
'location' => template_escape($location),
'location' => $location_e,
'indent' => '',
'owner_name' => template_escape($owner_name),
'owner_name' => $owner_name_e,
'owner_url' => $owner_url,
'owner_photo' => $owner_photo,
'plink' => get_plink($item),
@@ -682,7 +703,6 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$o = replace_macros($page_template, array(
'$baseurl' => $a->get_baseurl($ssl_state),
'$live_update' => $live_update_div,
'$remove' => t('remove'),
'$mode' => $mode,
'$user' => $a->user,
'$threads' => $threads,
@@ -856,12 +876,27 @@ function format_like($cnt,$arr,$type,$id) {
if($cnt == 1)
$o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
else {
$spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
$o .= (($type === 'like') ?
sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
:
sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
$o .= EOL ;
//$spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
switch($type) {
case 'like':
// $phrase = sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt);
$mood = t('like this');
break;
case 'dislike':
// $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt);
$mood = t('don\'t like this');
break;
}
$tpl = get_markup_template("voting_fakelink.tpl");
$phrase = replace_macros($tpl, array(
'$vote_id' => $type . 'list-' . $id,
'$count' => $cnt,
'$people' => t('people'),
'$vote_mood' => $mood
));
$o .= $phrase;
// $o .= EOL ;

$total = count($arr);
if($total >= MAX_LIKERS)
$arr = array_slice($arr, 0, MAX_LIKERS - 1);


+ 36
- 0
include/friendica_smarty.php View File

@@ -0,0 +1,36 @@
<?php

require_once("library/Smarty/libs/Smarty.class.php");

class FriendicaSmarty extends Smarty {

public $filename;
public $root;

function __construct() {
parent::__construct();

$a = get_app();

//$this->root = $_SERVER['DOCUMENT_ROOT'] . '/';
$this->root = '';

$this->setTemplateDir($this->root . 'view/smarty3/');
$this->setCompileDir($this->root . 'view/smarty3/compiled/');
$this->setConfigDir($this->root . 'view/smarty3/config/');
$this->setCacheDir($this->root . 'view/smarty3/cache/');

$this->left_delimiter = $a->smarty3_ldelim;
$this->right_delimiter = $a->smarty3_rdelim;
}

function parsed($template = '') {
if($template) {
return $this->fetch('string:' . $template);
}
return $this->fetch('file:' . $this->root . $this->filename);
}
}




+ 89
- 21
include/text.php View File

@@ -9,19 +9,38 @@
// depending on the order in which they were declared in the array.

require_once("include/template_processor.php");
require_once("include/friendica_smarty.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->theme['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 = get_app();
// $a->page['debug'] .= "$tt <br>\n";
return $output;
}}


@@ -421,29 +440,78 @@ if(! function_exists('get_intltext_template')) {
function get_intltext_template($s) {
global $lang;

$a = get_app();
$engine = '';
if($a->theme['template_engine'] === 'smarty3')
$engine = "/smarty3";

if(! isset($lang))
$lang = 'en';

if(file_exists("view/$lang/$s"))
return file_get_contents("view/$lang/$s");
elseif(file_exists("view/en/$s"))
return file_get_contents("view/en/$s");
if(file_exists("view/$lang$engine/$s"))
return file_get_contents("view/$lang$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$engine/$s");
}}

if(! function_exists('get_markup_template')) {
function get_markup_template($s) {
$a=get_app();
function get_markup_template($s, $root = '') {
// $ts = microtime();
$a = get_app();

if($a->theme['template_engine'] === 'smarty3') {
$template_file = get_template_file($a, 'smarty3/' . $s, $root);

$template = new FriendicaSmarty();
$template->filename = $template_file;

// $tt = microtime() - $ts;
// $a->page['debug'] .= "$tt <br>\n";
return $template;
}
else {
$template_file = get_template_file($a, $s, $root);
// $file_contents = file_get_contents($template_file);
// $tt = microtime() - $ts;
// $a->page['debug'] .= "$tt <br>\n";
// return $file_contents;
return file_get_contents($template_file);
}
}}

if(! function_exists("get_template_file")) {
function get_template_file($a, $filename, $root = '') {
$theme = current_theme();
if(file_exists("view/theme/$theme/$s"))
return file_get_contents("view/theme/$theme/$s");
elseif (x($a->theme_info,"extends") && file_exists("view/theme/".$a->theme_info["extends"]."/$s"))
return file_get_contents("view/theme/".$a->theme_info["extends"]."/$s");

// Make sure $root ends with a slash /
if($root !== '' && $root[strlen($root)-1] !== '/')
$root = $root . '/';

if(file_exists($root . "view/theme/$theme/$filename"))
$template_file = $root . "view/theme/$theme/$filename";
elseif (x($a->theme_info,"extends") && file_exists($root . "view/theme/".$a->theme_info["extends"]."/$filename"))
$template_file = $root . "view/theme/".$a->theme_info["extends"]."/$filename";
else
return file_get_contents("view/$s");
$template_file = $root . "view/$filename";

return $template_file;
}}

if(! function_exists("set_template_includes")) {
function set_template_includes($engine, $includes) {
if($engine === 'smarty3') {
$a = get_app();
foreach($includes as $name=>$path) {
// $sm_includes[$name] = $_SERVER['DOCUMENT_ROOT'] . '/' . get_template_file($a, 'smarty3/' . $path);
$sm_includes[$name] = get_template_file($a, 'smarty3/' . $path);
}
return $sm_includes;
}
else {
return $includes;
}
}}




+ 28
- 5
mod/admin.php View File

@@ -439,7 +439,16 @@ function admin_page_site(&$a) {
);

$t = get_markup_template("admin_site.tpl");
return replace_macros($t, array(

$includes = array(
'$field_checkbox' => 'field_checkbox.tpl',
'$field_input' => 'field_input.tpl',
'$field_select' => 'field_select.tpl',
'$field_textarea' => 'field_textarea.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

return replace_macros($t, $includes + array(
'$title' => t('Administration'),
'$page' => t('Site'),
'$submit' => t('Submit'),
@@ -488,7 +497,7 @@ function admin_page_site(&$a) {
'$poll_interval' => array('poll_interval', t("Poll interval"), (x(get_config('system','poll_interval'))?get_config('system','poll_interval'):2), t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")),
'$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")),
'$form_security_token' => get_form_security_token("admin_site"),
));

}
@@ -1109,7 +1118,14 @@ readable.");
}
}

return replace_macros($t, array(
$includes = array(
'$field_checkbox' => 'field_checkbox.tpl',
'$field_input' => 'field_input.tpl',
'$field_select' => 'field_select.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

return replace_macros($t, $includes + array(
'$title' => t('Administration'),
'$page' => t('Logs'),
'$submit' => t('Submit'),
@@ -1168,7 +1184,14 @@ function admin_page_remoteupdate(&$a) {
}
$tpl = get_markup_template("admin_remoteupdate.tpl");
return replace_macros($tpl, array(

$includes = array(
'$field_input' => 'field_input.tpl',
'$field_password' => 'field_password.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

return replace_macros($tpl, $includes + array(
'$baseurl' => $a->get_baseurl(true),
'$submit' => t("Update now"),
'$close' => t("Close"),
@@ -1181,7 +1204,7 @@ function admin_page_remoteupdate(&$a) {
'$ftppath' => array('ftppath', t("FTP Path"), '/',''),
'$ftpuser' => array('ftpuser', t("FTP User"), '',''),
'$ftppwd' => array('ftppwd', t("FTP Password"), '',''),
'$remotefile'=>array('remotefile','', $u['2'],'')
'$remotefile'=>array('remotefile','', $u['2'],''),
));
}

+ 14
- 3
mod/contacts.php View File

@@ -346,7 +346,12 @@ function contacts_content(&$a) {

$lost_contact = (($contact['archive'] && $contact['term-date'] != '0000-00-00 00:00:00' && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');

$o .= replace_macros($tpl,array(
$includes = array(
'$field_checkbox' => 'field_checkbox.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($tpl,$includes + array(
'$header' => t('Contact Editor'),
'$tab_str' => $tab_str,
'$submit' => t('Submit'),
@@ -388,7 +393,7 @@ function contacts_content(&$a) {
'$dir_icon' => $dir_icon,
'$alt_text' => $alt_text,
'$sparkle' => $sparkle,
'$url' => $url
'$url' => $url,

));

@@ -571,7 +576,13 @@ function contacts_content(&$a) {
}
$tpl = get_markup_template("contacts-template.tpl");
$o .= replace_macros($tpl,array(

$includes = array(
'$contact_template' => 'contact_template.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($tpl,$includes + array(
'$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
'$tabs' => $t,
'$total' => $total,


+ 47
- 12
mod/content.php View File

@@ -447,6 +447,23 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
$shareable = false;

$body = prepare_body($item,true);

if($a->theme['template_engine'] === 'internal') {
$name_e = template_escape($profile_name);
$title_e = template_escape($item['title']);
$body_e = template_escape($body);
$text_e = strip_tags(template_escape($body));
$location_e = template_escape($location);
$owner_name_e = template_escape($owner_name);
}
else {
$name_e = $profile_name;
$title_e = $item['title'];
$body_e = $body;
$text_e = strip_tags($body);
$location_e = $location;
$owner_name_e = $owner_name;
}
//$tmp_item = replace_macros($tpl,array(
$tmp_item = array(
@@ -455,17 +472,17 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
'profile_url' => $profile_link,
'item_photo_menu' => item_photo_menu($item),
'name' => template_escape($profile_name),
'name' => $name_e,
'sparkle' => $sparkle,
'lock' => $lock,
'thumb' => $profile_avatar,
'title' => template_escape($item['title']),
'body' => template_escape($body),
'text' => strip_tags(template_escape($body)),
'title' => $title_e,
'body' => $body_e,
'text' => $text_e,
'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
'location' => template_escape($location),
'location' => $location_e,
'indent' => '',
'owner_name' => template_escape($owner_name),
'owner_name' => $owner_name_e,
'owner_url' => $owner_url,
'owner_photo' => $owner_photo,
'plink' => get_plink($item),
@@ -802,6 +819,24 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {

$body = prepare_body($item,true);
//$tmp_item = replace_macros($template,

if($a->theme['template_engine'] === 'internal') {
$body_e = template_escape($body);
$text_e = strip_tags(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($owner_name);
}
else {
$body_e = $body;
$text_e = strip_tags($body);
$name_e = $profile_name;
$title_e = $item['title'];
$location_e = $location;
$owner_name_e = $owner_name;
}

$tmp_item = array(
// collapse comments in template. I don't like this much...
'comment_firstcollapsed' => $comment_firstcollapsed,
@@ -811,8 +846,8 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
'tags' => $tags,
'body' => template_escape($body),
'text' => strip_tags(template_escape($body)),
'body' => $body_e,
'text' => $text_e,
'id' => $item['item_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'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
@@ -821,19 +856,19 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
'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,
'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,
'shiny' => $shiny,
'owner_url' => $owner_url,
'owner_photo' => $owner_photo,
'owner_name' => template_escape($owner_name),
'owner_name' => $owner_name_e,
'plink' => get_plink($item),
'edpost' => $edpost,
'isstarred' => $isstarred,


+ 11
- 4
mod/directory.php View File

@@ -143,16 +143,23 @@ function directory_content(&$a) {
$tpl = get_markup_template('directory_item.tpl');

if($a->theme['template_engine'] === 'internal') {
$location_e = template_escape($location);
}
else {
$location_e = $location;
}

$entry = replace_macros($tpl,array(
'$id' => $rr['id'],
'$profile-link' => $profile_link,
'$profile_link' => $profile_link,
'$photo' => $a->get_cached_avatar_image($rr[$photo]),
'$alt-text' => $rr['name'],
'$alt_text' => $rr['name'],
'$name' => $rr['name'],
'$details' => $pdesc . $details,
'$page-type' => $page_type,
'$page_type' => $page_type,
'$profile' => $profile,
'$location' => template_escape($location),
'$location' => $location_e,
'$gender' => $gender,
'$pdesc' => $pdesc,
'$marital' => $marital,


+ 1
- 1
mod/display.php View File

@@ -16,7 +16,7 @@ function display_content(&$a, $update = 0) {

$o = '';

$a->page['htmlhead'] .= get_markup_template('display-head.tpl');
$a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());


if($update) {


+ 18
- 2
mod/fbrowser.php View File

@@ -55,9 +55,17 @@ function fbrowser_content($a){
global $a;
$types = Photo::supportedTypes();
$ext = $types[$rr['type']];

if($a->theme['template_engine'] === 'internal') {
$filename_e = template_escape($rr['filename']);
}
else {
$filename_e = $rr['filename'];
}

return array(
$a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['hiq'] . '.' .$ext,
template_escape($rr['filename']),
$filename_e,
$a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['loq'] . '.'. $ext
);
}
@@ -83,7 +91,15 @@ function fbrowser_content($a){
function files2($rr){ global $a;
list($m1,$m2) = explode("/",$rr['filetype']);
$filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
return array( $a->get_baseurl() . '/attach/' . $rr['id'], template_escape($rr['filename']), $a->get_baseurl() . '/images/icons/16/' . $filetype . '.png');

if($a->theme['template_engine'] === 'internal') {
$filename_e = template_escape($rr['filename']);
}
else {
$filename_e = $rr['filename'];
}

return array( $a->get_baseurl() . '/attach/' . $rr['id'], $filename_e, $a->get_baseurl() . '/images/icons/16/' . $filetype . '.png');
}
$files = array_map("files2", $files);
//echo "<pre>"; var_dump($files); killme();


+ 6
- 0
mod/filer.php View File

@@ -25,6 +25,12 @@ function filer_content(&$a) {
$filetags = file_tag_file_to_list($filetags,'file');
$filetags = explode(",", $filetags);
$tpl = get_markup_template("filer_dialog.tpl");

$includes = array(
'$field_combobox' => 'field_combobox.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o = replace_macros($tpl, array(
'$field' => array('term', t("Save to Folder:"), '', '', $filetags, t('- select -')),
'$submit' => t('Save'),


+ 12
- 2
mod/group.php View File

@@ -82,7 +82,16 @@ function group_content(&$a) {
$switchtotext = 400;

$tpl = get_markup_template('group_edit.tpl');
$context = array('$submit' => t('Submit'));

$includes = array(
'$field_input' => 'field_input.tpl',
'$groupeditortpl' => 'groupeditor.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$context = $includes + array(
'$submit' => t('Submit'),
);

if(($a->argc == 2) && ($a->argv[1] === 'new')) {
@@ -217,15 +226,16 @@ function group_content(&$a) {
}
}

$context['$groupeditor'] = $groupeditor;
$context['$desc'] = t('Click on a contact to add or remove.');

if($change) {
$context['$groupeditor'] = $groupeditor;
$tpl = get_markup_template('groupeditor.tpl');
echo replace_macros($tpl, $context);
killme();
}
$context['$groupedit_info'] = $groupeditor;
return replace_macros($tpl, $context);

}


+ 12
- 4
mod/hostxrd.php View File

@@ -14,10 +14,18 @@ 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 = 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();

}
}

+ 15
- 2
mod/install.php View File

@@ -220,7 +220,14 @@ function install_content(&$a) {

$tpl = get_markup_template('install_db.tpl');
$o .= replace_macros($tpl, array(

$includes = array(
'$field_input' => 'field_input.tpl',
'$field_password' => 'field_password.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($tpl,$includes + array(
'$title' => $install_title,
'$pass' => t('Database connection'),
'$info_01' => t('In order to install Friendica we need to know how to connect to your database.'),
@@ -260,7 +267,13 @@ function install_content(&$a) {
$timezone = ((x($_POST,'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
$tpl = get_markup_template('install_settings.tpl');
$o .= replace_macros($tpl, array(

$includes = array(
'$field_input' => 'field_input.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($tpl, $includes + array(
'$title' => $install_title,
'$pass' => t('Site settings'),



+ 91
- 41
mod/message.php View File

@@ -282,23 +282,25 @@ function message_content(&$a) {

$tpl = get_markup_template('prv_message.tpl');
$o .= replace_macros($tpl,array(
'$header' => t('Send Private Message'),
'$to' => t('To:'),
'$showinputs' => 'true',
'$prefill' => $prefill,
'$autocomp' => $autocomp,
'$preid' => $preid,
'$subject' => t('Subject:'),
'$subjtxt' => ((x($_REQUEST,'subject')) ? strip_tags($_REQUEST['subject']) : ''),
'$text' => ((x($_REQUEST,'body')) ? escape_tags(htmlspecialchars($_REQUEST['body'])) : ''),
'$readonly' => '',
'$yourmessage' => t('Your message:'),
'$select' => $select,
'$parent' => '',
'$upload' => t('Upload photo'),
'$insert' => t('Insert web link'),
'$wait' => t('Please wait'),
'$submit' => t('Submit')
'$reply' => array(
'header' => t('Send Private Message'),
'to' => t('To:'),
'showinputs' => 'true',
'prefill' => $prefill,
'autocomp' => $autocomp,
'preid' => $preid,
'subject' => t('Subject:'),
'subjtxt' => ((x($_REQUEST,'subject')) ? strip_tags($_REQUEST['subject']) : ''),
'text' => ((x($_REQUEST,'body')) ? escape_tags(htmlspecialchars($_REQUEST['body'])) : ''),
'readonly' => '',
'yourmessage' => t('Your message:'),
'select' => $select,
'parent' => '',
'upload' => t('Upload photo'),
'insert' => t('Insert web link'),
'wait' => t('Please wait'),
'submit' => t('Submit')
)
));

return $o;
@@ -346,6 +348,17 @@ function message_content(&$a) {
else {
$partecipants = sprintf( t("%s and You"), $rr['from-name']);
}

if($a->theme['template_engine'] === 'internal') {
$subject_e = template_escape((($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>'));
$body_e = template_escape($rr['body']);
$to_name_e = template_escape($rr['name']);
}
else {
$subject_e = (($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>');
$body_e = $rr['body'];
$to_name_e = $rr['name'];
}
$o .= replace_macros($tpl, array(
'$id' => $rr['id'],
@@ -353,10 +366,10 @@ function message_content(&$a) {
'$from_url' => (($rr['network'] === NETWORK_DFRN) ? $a->get_baseurl(true) . '/redir/' . $rr['contact-id'] : $rr['url']),
'$sparkle' => ' sparkle',
'$from_photo' => (($rr['thumb']) ? $rr['thumb'] : $rr['from-photo']),
'$subject' => template_escape((($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>')),
'$subject' => $subject_e,
'$delete' => t('Delete conversation'),
'$body' => template_escape($rr['body']),
'$to_name' => template_escape($rr['name']),
'$body' => $body_e,
'$to_name' => $to_name_e,
'$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['mailcreated'], t('D, d M Y - g:i A')),
'$ago' => relative_date($rr['mailcreated']),
'$seen' => $rr['mailseen'],
@@ -371,6 +384,10 @@ function message_content(&$a) {

$o .= $header;

$plaintext = true;
if( local_user() && feature_enabled(local_user(),'richtext') )
$plaintext = false;

$r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
WHERE `mail`.`uid` = %d AND `mail`.`id` = %d LIMIT 1",
@@ -408,14 +425,18 @@ function message_content(&$a) {

$tpl = get_markup_template('msg-header.tpl');
$a->page['htmlhead'] .= replace_macros($tpl, array(
'$baseurl' => $a->get_baseurl(true),
'$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
'$nickname' => $a->user['nickname'],
'$baseurl' => $a->get_baseurl(true)
'$linkurl' => t('Please enter a link URL:')
));

$tpl = get_markup_template('msg-end.tpl');
$a->page['end'] .= replace_macros($tpl, array(
'$baseurl' => $a->get_baseurl(true),
'$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
'$nickname' => $a->user['nickname'],
'$baseurl' => $a->get_baseurl(true)
'$linkurl' => t('Please enter a link URL:')
));


@@ -440,16 +461,29 @@ function message_content(&$a) {
if($extracted['images'])
$message['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $message['contact-id']);

if($a->theme['template_engine'] === 'internal') {
$from_name_e = template_escape($message['from-name']);
$subject_e = template_escape($message['title']);
$body_e = template_escape(smilies(bbcode($message['body'])));
$to_name_e = template_escape($message['name']);
}
else {
$from_name_e = $message['from-name'];
$subject_e = $message['title'];
$body_e = smilies(bbcode($message['body']));
$to_name_e = $message['name'];
}

$mails[] = array(
'id' => $message['id'],
'from_name' => template_escape($message['from-name']),
'from_name' => $from_name_e,
'from_url' => $from_url,
'sparkle' => $sparkle,
'from_photo' => $message['from-photo'],
'subject' => template_escape($message['title']),
'body' => template_escape(smilies(bbcode($message['body']))),
'subject' => $subject_e,
'body' => $body_e,
'delete' => t('Delete message'),
'to_name' => template_escape($message['name']),
'to_name' => $to_name_e,
'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'),
'ago' => relative_date($message['created']),
);
@@ -462,7 +496,21 @@ function message_content(&$a) {
$parent = '<input type="hidden" name="replyto" value="' . $message['parent-uri'] . '" />';

$tpl = get_markup_template('mail_display.tpl');
$o = replace_macros($tpl, array(

$includes = array(
'$mail_conv' => 'mail_conv.tpl',
'$prv_message' => 'prv_message.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

if($a->theme['template_engine'] === 'internal') {
$subjtxt_e = template_escape($message['title']);
}
else {
$subjtxt_e = $message['title'];
}

$o = replace_macros($tpl, $includes + array(
'$thread_id' => $a->argv[1],
'$thread_subject' => $message['title'],
'$thread_seen' => $seen,
@@ -472,20 +520,22 @@ function message_content(&$a) {
'$mails' => $mails,
// reply
'$header' => t('Send Reply'),
'$to' => t('To:'),
'$showinputs' => '',
'$subject' => t('Subject:'),
'$subjtxt' => template_escape($message['title']),
'$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ',
'$yourmessage' => t('Your message:'),
'$text' => '',
'$select' => $select,
'$parent' => $parent,
'$upload' => t('Upload photo'),
'$insert' => t('Insert web link'),
'$submit' => t('Submit'),
'$wait' => t('Please wait')
'$reply_info' => array(
'header' => t('Send Reply'),
'to' => t('To:'),
'showinputs' => '',
'subject' => t('Subject:'),
'subjtxt' => $subjtxt_e,
'readonly' => ' readonly="readonly" style="background: #BBBBBB;" ',
'yourmessage' => t('Your message:'),
'text' => '',
'select' => $select,
'parent' => $parent,
'upload' => t('Upload photo'),
'insert' => t('Insert web link'),
'submit' => t('Submit'),
'wait' => t('Please wait'),
),

));



+ 8
- 1
mod/nogroup.php View File

@@ -53,8 +53,15 @@ function nogroup_content(&$a) {
);
}
}

$tpl = get_markup_template("nogroup-template.tpl");
$o .= replace_macros($tpl,array(

$includes = array(
'$contact_template' => 'contact_template.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($tpl,$includes + array(
'$header' => t('Contacts who are not members of a group'),
'$contacts' => $contacts,
'$paginate' => paginate($a),


+ 50
- 14
mod/notifications.php View File

@@ -144,7 +144,13 @@ function notifications_content(&$a) {
if($rr['fid']) {

$return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
$notif_content .= replace_macros($sugg,array(

$includes = array(
'$field_checkbox' => 'field_checkbox.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$notif_content .= replace_macros($sugg,$includes + array(
'$str_notifytype' => t('Notification type: '),
'$notify_type' => t('Friend Suggestion'),
'$intro_id' => $rr['intro_id'],
@@ -161,7 +167,7 @@ function notifications_content(&$a) {
'$note' => $rr['note'],
'$request' => $rr['frequest'] . '?addr=' . $return_addr,
'$ignore' => t('Ignore'),
'$discard' => t('Discard')
'$discard' => t('Discard'),

));

@@ -190,7 +196,12 @@ function notifications_content(&$a) {
));
}

$notif_content .= replace_macros($tpl,array(
$includes = array(
'$field_checkbox' => 'field_checkbox.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$notif_content .= replace_macros($tpl,$includes + array(
'$str_notifytype' => t('Notification type: '),
'$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
'$dfrn_text' => $dfrn_text,
@@ -207,7 +218,7 @@ function notifications_content(&$a) {
'$approve' => t('Approve'),
'$note' => $rr['note'],
'$ignore' => t('Ignore'),
'$discard' => t('Discard')
'$discard' => t('Discard'),

));
}
@@ -215,9 +226,14 @@ function notifications_content(&$a) {
else
info( t('No introductions.') . EOL);

$o .= replace_macros($notif_tpl,array(
$includes = array(
'$common_tabs' => 'common_tabs.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($notif_tpl,$includes + array(
'$notif_header' => t('Notifications'),
'$tabs' => $tabs,
'$tabs_data' => $tabs,
'$notif_content' => $notif_content,
));
@@ -301,9 +317,14 @@ function notifications_content(&$a) {
$notif_content = t('No more network notifications.');
}
$o .= replace_macros($notif_tpl,array(
$includes = array(
'$common_tabs' => 'common_tabs.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($notif_tpl,$includes + array(
'$notif_header' => t('Network Notifications'),
'$tabs' => $tabs,
'$tabs_data' => $tabs,
'$notif_content' => $notif_content,
));
@@ -331,9 +352,14 @@ function notifications_content(&$a) {
$notif_content .= t('No more system notifications.');
}
$o .= replace_macros($notif_tpl,array(
$includes = array(
'$common_tabs' => 'common_tabs.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($notif_tpl,$includes + array(
'$notif_header' => t('System Notifications'),
'$tabs' => $tabs,
'$tabs_data' => $tabs,
'$notif_content' => $notif_content,
));

@@ -426,9 +452,14 @@ function notifications_content(&$a) {
$notif_content = t('No more personal notifications.');
}
$o .= replace_macros($notif_tpl,array(
$includes = array(
'$common_tabs' => 'common_tabs.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($notif_tpl,$includes + array(
'$notif_header' => t('Personal Notifications'),
'$tabs' => $tabs,
'$tabs_data' => $tabs,
'$notif_content' => $notif_content,
));
@@ -507,9 +538,14 @@ function notifications_content(&$a) {
$notif_content = t('No more home notifications.');
}
$o .= replace_macros($notif_tpl,array(
$includes = array(
'$common_tabs' => 'common_tabs.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($notif_tpl,$includes + array(
'$notif_header' => t('Home Notifications'),
'$tabs' => $tabs,
'$tabs_data' => $tabs,
'$notif_content' => $notif_content,
));
}


+ 8
- 3
mod/notify.php View File

@@ -61,13 +61,18 @@ function notify_content(&$a) {
$notif_content .= t('No more system notifications.');
}
$o .= replace_macros($notif_tpl,array(
$includes = array(
'$common_tabs' => 'common_tabs.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($notif_tpl,$includes + array(
'$notif_header' => t('System Notifications'),
'$tabs' => '', // $tabs,
'$tabs_data' => '', // $tabs,
'$notif_content' => $notif_content,
));

return $o;


}
}

+ 97
- 18
mod/photos.php View File

@@ -1039,6 +1039,16 @@ function photos_content(&$a) {


$tpl = get_markup_template('photos_upload.tpl');

if($a->theme['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));
}

$o .= replace_macros($tpl,array(
'$pagename' => t('Upload Photos'),
'$sessid' => session_id(),
@@ -1047,9 +1057,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']
@@ -1092,10 +1102,18 @@ function photos_content(&$a) {
if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
if($can_post) {
$edit_tpl = get_markup_template('album_edit.tpl');

if($a->theme['template_engine'] === 'internal') {
$album_e = template_escape($album);
}
else {
$album_e = $album;
}

$o .= replace_macros($edit_tpl,array(
'$nametext' => t('New album name: '),
'$nickname' => $a->data['user']['nickname'],
'$album' => template_escape($album),
'$album' => $album_e,
'$hexalbum' => bin2hex($album),
'$submit' => t('Submit'),
'$dropsubmit' => t('Delete Album')
@@ -1135,6 +1153,15 @@ function photos_content(&$a) {
$ext = $phototypes[$rr['type']];

if($a->theme['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),
@@ -1142,8 +1169,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
));

}
@@ -1344,20 +1371,32 @@ function photos_content(&$a) {
$edit = Null;
if(($cmd === 'edit') && ($can_post)) {
$edit_tpl = get_markup_template('photo_edit.tpl');

if($a->theme['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 = 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['user']['nickname'],
'$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'),
@@ -1488,14 +1527,25 @@ function photos_content(&$a) {
$drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));


if($a->theme['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,
@@ -1531,20 +1581,34 @@ function photos_content(&$a) {
}
$photo_tpl = get_markup_template('photo_view.tpl');

if($a->theme['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;
}

$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' => $dikslike_e,
'$comments' => $comments,
'$paginate' => $paginate,
));
@@ -1588,16 +1652,25 @@ function photos_content(&$a) {
$twist = 'rotright';
$ext = $phototypes[$rr['type']];
if($a->theme['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['user']['nickname'] . '/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['user']['nickname'] . '/album/' . bin2hex($rr['album']),
'name' => template_escape($rr['album']),
'name' => $name_e,
'alt' => t('View Album'),
),
@@ -1606,7 +1679,13 @@ function photos_content(&$a) {
}
$tpl = get_markup_template('photos_recent.tpl');
$o .= replace_macros($tpl,array(

$includes = array(
'$photo_top' => 'photo_top.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($tpl,$includes + array(
'$title' => t('Recent Photos'),
'$can_post' => $can_post,
'$upload' => array(t('Upload New Photos'), $a->get_baseurl().'/photos/'.$a->data['user']['nickname'].'/upload'),


+ 8
- 2
mod/poco.php View File

@@ -147,7 +147,13 @@ function poco_init(&$a) {

if($format === 'xml') {
header('Content-type: text/xml');
echo replace_macros(get_markup_template('poco_xml.tpl'),array_xmlify(array('$response' => $ret)));

$includes = array(
'$poco_entry_xml' => 'poco_entry_xml.tpl'
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

echo replace_macros(get_markup_template('poco_xml.tpl'),array_xmlify($includes + array('$response' => $ret)));
http_status_exit(500);
}
if($format === 'json') {
@@ -159,4 +165,4 @@ function poco_init(&$a) {
http_status_exit(500);


}
}

+ 1
- 0
mod/profile.php View File

@@ -33,6 +33,7 @@ function profile_init(&$a) {
auto_redir($a, $which);
}

$a->theme["template_engine"] = 'internal'; // reset the template engine to the default in case the user's theme doesn't specify one
profile_load($a,$which,$profile);

$blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false);


+ 2
- 2
mod/profile_photo.php View File

@@ -313,8 +313,8 @@ 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['end'] .= get_markup_template("cropend.tpl");
$a->page['htmlhead'] .= replace_macros(get_markup_template("crophead.tpl"), array());
$a->page['end'] .= replace_macros(get_markup_template("cropend.tpl"), array());
return;
}}


+ 59
- 8
mod/settings.php View File

@@ -554,7 +554,13 @@ function settings_content(&$a) {
if(($a->argc > 2) && ($a->argv[2] === 'add')) {
$tpl = get_markup_template("settings_oauth_edit.tpl");
$o .= replace_macros($tpl, array(

$includes = array(
'$field_input' => 'field_input.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($tpl, $includes + array(
'$form_security_token' => get_form_security_token("settings_oauth"),
'$title' => t('Add application'),
'$submit' => t('Submit'),
@@ -580,7 +586,13 @@ function settings_content(&$a) {
$app = $r[0];
$tpl = get_markup_template("settings_oauth_edit.tpl");
$o .= replace_macros($tpl, array(

$includes = array(
'$field_input' => 'field_input.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($tpl, $includes + array(
'$form_security_token' => get_form_security_token("settings_oauth"),
'$title' => t('Add application'),
'$submit' => t('Update'),
@@ -663,12 +675,17 @@ function settings_content(&$a) {


$tpl = get_markup_template("settings_features.tpl");
$o .= replace_macros($tpl, array(

$includes = array(
'$field_yesno' => 'field_yesno.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($tpl, $includes + array(
'$form_security_token' => get_form_security_token("settings_features"),
'$title' => t('Additional Features'),
'$features' => $arr,
'$submit' => t('Submit'),
'$field_yesno' => 'field_yesno.tpl',
));
return $o;
}
@@ -715,7 +732,17 @@ function settings_content(&$a) {
$mail_disabled_message = (($mail_disabled) ? t('Email access is disabled on this site.') : '');
}
$o .= replace_macros($tpl, array(

$includes = array(
'$field_checkbox' => 'field_checkbox.tpl',
'$field_input' => 'field_input.tpl',
'$field_select' => 'field_select.tpl',
'$field_custom' => 'field_custom.tpl',
'$field_password' => 'field_password.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($tpl, $includes + array(
'$form_security_token' => get_form_security_token("settings_connectors"),
'$title' => t('Connector Settings'),
@@ -805,7 +832,15 @@ function settings_content(&$a) {
}
$tpl = get_markup_template("settings_display.tpl");
$o = replace_macros($tpl, array(

$includes = array(
'$field_themeselect' => 'field_themeselect.tpl',
'$field_checkbox' => 'field_checkbox.tpl',
'$field_input' => 'field_input.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o = replace_macros($tpl, $includes + array(
'$ptitle' => t('Display Settings'),
'$form_security_token' => get_form_security_token("settings_display"),
'$submit' => t('Submit'),
@@ -891,7 +926,13 @@ function settings_content(&$a) {


$pageset_tpl = get_markup_template('pagetypes.tpl');
$pagetype = replace_macros($pageset_tpl,array(

$includes = array(
'$field_radio' => 'field_radio.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$pagetype = replace_macros($pageset_tpl,$includes + array(
'$page_normal' => array('page-flags', t('Normal Account Page'), PAGE_NORMAL,
t('This account is a normal personal profile'),
($a->user['page-flags'] == PAGE_NORMAL)),
@@ -1012,7 +1053,17 @@ function settings_content(&$a) {
require_once('include/group.php');
$group_select = mini_group_select(local_user(),$a->user['def_gid']);

$o .= replace_macros($stpl,array(
$includes = array(
'$field_password' => 'field_password.tpl',
'$field_input' => 'field_input.tpl',
'$field_custom' => 'field_custom.tpl',
'$field_checkbox' => 'field_checkbox.tpl',
'$field_yesno' => 'field_yesno.tpl',
'$field_intcheckbox' => 'field_intcheckbox.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($stpl,$includes + array(
'$ptitle' => t('Account Settings'),

'$submit' => t('Submit'),


+ 10
- 4
mod/uimport.php View File

@@ -60,13 +60,19 @@ function uimport_content(&$a) {
$tpl = get_markup_template("uimport.tpl");
return replace_macros($tpl, array(
$includes = array(
'$field_custom' => 'field_custom.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);
return replace_macros($tpl, $includes + array(
'$regbutt' => t('Import'),
'$import' => array(
'title' => t("Move account"),
'text' => t("You can import an account from another Friendica server. <br>
You need to export your account from the old server and upload it here. We will recreate your old account here with all your contacts. We will try also to inform your friends that you moved here.<br>
<b>This feature is experimental. We can't import contacts from the OStatus network (statusnet/identi.ca) or from diaspora"),
'intro' => t("You can import an account from another Friendica server."),
'instruct' => t("You need to export your account from the old server and upload it here. We will recreate your old account here with all your contacts. We will try also to inform your friends that you moved here."),
'warn' => t("This feature is experimental. We can't import contacts from the OStatus network (statusnet/identi.ca) or from Diaspora"),
'field' => array('accountfile', t('Account file'),'<input id="id_accountfile" name="accountfile" type="file">', t('To export your accont, go to "Settings->Export your porsonal data" and select "Export account"')),
),
));


+ 7
- 1
mod/viewcontacts.php View File

@@ -72,7 +72,13 @@ function viewcontacts_content(&$a) {


$tpl = get_markup_template("viewcontact_template.tpl");
$o .= replace_macros($tpl, array(

$includes = array(
'$contact_template' => 'contact_template.tpl',
);
$includes = set_template_includes($a->theme['template_engine'], $includes);

$o .= replace_macros($tpl, $includes + array(
'$title' => t('View Contacts'),
'$contacts' => $contacts,
'$paginate' => paginate($a),


+ 4
- 2
mod/xrd.php View File

@@ -28,7 +28,8 @@ function xrd_init(&$a) {
header("Content-type: text/xml");

if(get_config('system','diaspora_enabled')) {
$tpl = file_get_contents('view/xrd_diaspora.tpl');
//$tpl = file_get_contents('view/xrd_diaspora.tpl');
$tpl = get_markup_template('xrd_diaspora.tpl');
$dspr = replace_macros($tpl,array(
'$baseurl' => $a->get_baseurl(),
'$dspr_guid' => $r[0]['guid'],
@@ -38,7 +39,8 @@ function xrd_init(&$a) {
else
$dspr = '';

$tpl = file_get_contents('view/xrd_person.tpl');
//$tpl = file_get_contents('view/xrd_person.tpl');
$tpl = get_markup_template('xrd_person.tpl');

$o = replace_macros($tpl, array(
'$nick' => $r[0]['nickname'],


+ 198
- 0
mods/friendica-to-smarty-tpl.py View File

@@ -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 += 'file:' + 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)



+ 34
- 7
object/Item.php View File

@@ -216,6 +216,23 @@ class Item extends BaseObject {

list($categories, $folders) = get_cats_and_terms($item);

if($a->theme['template_engine'] === 'internal') {
$body_e = template_escape($body);
$text_e = strip_tags(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;
$text_e = strip_tags($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(),
@@ -229,8 +246,8 @@ class Item extends BaseObject {
'has_folders' => ((count($folders)) ? 'true' : ''),
'categories' => $categories,
'folders' => $folders,
'body' => template_escape($body),
'text' => strip_tags(template_escape($body)),
'body' => $body_e,
'text' => $text_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'])),
@@ -240,20 +257,20 @@ class Item extends BaseObject {
'vwall' => t('via Wall-To-Wall:'),