'
- . $cnt . ' ' . t('people') . ' ' . (($type === 'like') ? t('like this.') : t('don\'t like this.')) . EOL ;
- $total = count($arr);
- if($total >= MAX_LIKERS)
- $arr = array_slice($arr, 0, MAX_LIKERS - 1);
- if($total < MAX_LIKERS)
- $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
- $str = implode(', ', $arr);
- if($total >= MAX_LIKERS)
- $str .= t(', and ') . $total - MAX_LIKERS . t(' other people');
- $str .= (($type === 'like') ? t(' like this.') : t(' don\'t like this.'));
- $o .= "\t" . '' . $str . '
';
- }
- return $o;
-}}
// wrapper to load a view template, checking for alternate
// languages before falling back to the default
+// obsolete, deprecated.
+
if(! function_exists('load_view_file')) {
function load_view_file($s) {
+ global $lang, $a;
+ if(! isset($lang))
+ $lang = 'en';
$b = basename($s);
$d = dirname($s);
- $lang = get_config('system','language');
- if($lang === false)
- $lang = 'en';
if(file_exists("$d/$lang/$b"))
return file_get_contents("$d/$lang/$b");
+
+ $theme = current_theme();
+
+ if(file_exists("$d/theme/$theme/$b"))
+ return file_get_contents("$d/theme/$theme/$b");
+
return file_get_contents($s);
}}
+if(! function_exists('get_intltext_template')) {
+function get_intltext_template($s) {
+ global $lang;
+
+ 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");
+ else
+ return file_get_contents("view/$s");
+}}
+
+if(! function_exists('get_markup_template')) {
+function get_markup_template($s) {
+
+ $theme = current_theme();
+
+ if(file_exists("view/theme/$theme/$s"))
+ return file_get_contents("view/theme/$theme/$s");
+ else
+ return file_get_contents("view/$s");
+
+}}
+
+
+
+
+
// for html,xml parsing - let's say you've got
// an attribute foobar="class1 class2 class3"
// and you want to find out if it contains 'class3'.
@@ -1772,15 +1983,15 @@ function get_tags($s) {
$s = preg_replace('/\[code\](.*?)\[\/code\]/sm','',$s);
if(preg_match_all('/([@#][^ \x0D\x0A,:?]+)([ \x0D\x0A,:?]|$)/',$s,$match)) {
- foreach($match[1] as $match) {
- if(strstr($match,"]")) {
+ foreach($match[1] as $mtch) {
+ if(strstr($mtch,"]")) {
// we might be inside a bbcode color tag - leave it alone
continue;
}
- if(substr($match,-1,1) === '.')
- $ret[] = substr($match,0,-1);
+ if(substr($mtch,-1,1) === '.')
+ $ret[] = substr($mtch,0,-1);
else
- $ret[] = $match;
+ $ret[] = $mtch;
}
}
@@ -1796,29 +2007,6 @@ return str_replace ("%","=",rawurlencode($s));
}}
-if(! function_exists('like_puller')) {
-function like_puller($a,$item,&$arr,$mode) {
-
- $url = '';
- $sparkle = '';
- $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
-
- if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
- $url = $item['author-link'];
- if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
- $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
- $sparkle = ' class="sparkle" ';
- }
- if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
- $arr[$item['parent'] . '-l'] = array();
- if(! isset($arr[$item['parent']]))
- $arr[$item['parent']] = 1;
- else
- $arr[$item['parent']] ++;
- $arr[$item['parent'] . '-l'][] = '' . $item['author-name'] . '';
- }
- return;
-}}
if(! function_exists('get_mentions')) {
function get_mentions($item) {
@@ -1829,8 +2017,10 @@ function get_mentions($item) {
$arr = explode(',',$item['tag']);
foreach($arr as $x) {
$matches = null;
- if(preg_match('/@\[url=([^\]]*)\]/',$x,$matches))
+ if(preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) {
$o .= "\t\t" . '' . "\r\n";
+ $o .= "\t\t" . '' . "\r\n";
+ }
}
return $o;
}}
@@ -1861,20 +2051,9 @@ function contact_block() {
intval($shown)
);
if(count($r)) {
- $o .= '';
+ $o .= '
';
$o .= '
';
@@ -1888,6 +2067,44 @@ function contact_block() {
}}
+if(! function_exists('micropro')) {
+function micropro($contact, $redirect = false, $class = '', $textmode = false) {
+
+ if($class)
+ $class = ' ' . $class;
+
+ $url = $contact['url'];
+ $sparkle = '';
+
+ if($redirect) {
+ $a = get_app();
+ $redirect_url = $a->get_baseurl() . '/redir/' . $contact['id'];
+ if(local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === 'dfrn')) {
+ $url = $redirect_url;
+ $sparkle = ' sparkle';
+ }
+ }
+ $click = ((x($contact,'click')) ? ' onclick="' . $contact['click'] . '" ' : '');
+ if($click)
+ $url = '';
+ if($textmode) {
+ return '
' . "\r\n";
+ }
+ else {
+ return '
' . "\r\n";
+ }
+}}
+
+
+
if(! function_exists('search')) {
function search($s) {
$a = get_app();
@@ -1957,7 +2174,7 @@ function aes_encrypt($val,$ky)
if(! function_exists('linkify')) {
function linkify($s) {
- $s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%]*)/", '
$1', $s);
+ $s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%\$\!\+]*)/", '
$1', $s);
return($s);
}}
@@ -1979,7 +2196,7 @@ function smilies($s) {
$a = get_app();
return str_replace(
- array( '<3', '</3', '<\\3', ':-)', ';-)', ':-(', ':(', ':-P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O'),
+ array( '<3', '</3', '<\\3', ':-)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O'),
array(
'
',
'
',
@@ -1989,6 +2206,7 @@ function smilies($s) {
'
',
'
',
'
',
+ '
',
'
',
'
',
'
',
@@ -2106,8 +2324,15 @@ function profile_sidebar($profile) {
$photo = '
';
+ // don't show connect link to yourself
+
$connect = (($profile['uid'] != local_user()) ? '
' . t('Connect') . '' : '');
-
+
+ // don't show connect link to authenticated visitors either
+
+ if((remote_user()) && ($_SESSION['visitor_visiting'] == $profile['uid']))
+ $connect = '';
+
if((x($profile,'address') == 1)
|| (x($profile,'locality') == 1)
|| (x($profile,'region') == 1)
@@ -2132,11 +2357,15 @@ function profile_sidebar($profile) {
$pubkey = ((x($profile,'pubkey') == 1) ? '
' . $profile['pubkey'] . '
' : '');
- $marital = ((x($profile,'marital') == 1) ? '
♥ ' . t('Status:') . ' ' . $profile['marital'] . '
' : '');
+ $marital = ((x($profile,'marital') == 1) ? '♥ ' . t('Status:') . ' ' . $profile['marital'] . '
' : '');
- $homepage = ((x($profile,'homepage') == 1) ? '' . t('Homepage:') . ' ' . linkify($profile['homepage']) . '
' : '');
+ $homepage = ((x($profile,'homepage') == 1) ? '' . t('Homepage:') . ' ' . linkify($profile['homepage']) . '
' : '');
- $tpl = load_view_file('view/profile_vcard.tpl');
+ if($profile['hidewall'] && (! local_user()) && (! remote_user())) {
+ $location = $gender = $marital = $homepage = '';
+ }
+
+ $tpl = get_markup_template('profile_vcard.tpl');
$o .= replace_macros($tpl, array(
'$fullname' => $fullname,
@@ -2244,9 +2473,7 @@ function get_birthdays() {
if(! local_user())
return $o;
- $bd_format = get_config('system','birthday_format');
- if(! $bd_format)
- $bd_format = 'g A l F d' ; // 8 AM Friday January 18
+ $bd_format = t('g A l F d') ; // 8 AM Friday January 18
$r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
LEFT JOIN `contact` ON `contact`.`id` = `event`.`cid`
@@ -2258,25 +2485,39 @@ function get_birthdays() {
);
if($r && count($r)) {
- $o .= '' . t('Birthdays this week:') . '
';
- $o .= '
' . t("\x28Adjusted for local time\x29") . '
';
- $o .= '
';
-
- foreach($r as $rr) {
- $now = strtotime('now');
- $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
-
- $o .= '
' . $rr['name'] . ' '
- . day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '')
- . '
' ;
+ $total = 0;
+ foreach($r as $rr)
+ if(strlen($rr['name']))
+ $total ++;
+
+ if($total) {
+ $o .= '
' . t('Birthday Reminders') . ' ' . '(' . $total . ')' . '
';
+ $o .= '
' . t('Birthdays this week:') . '
';
+ $o .= '
' . t("\x28Adjusted for local time\x29") . '
';
+ $o .= '
';
+
+ foreach($r as $rr) {
+ if(! strlen($rr['name']))
+ continue;
+ $now = strtotime('now');
+ $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
+
+ $o .= '
' . $rr['name'] . ' '
+ . day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '')
+ . '
' ;
+ }
+ $o .= '
';
}
-
- $o .= '';
}
+ return $o;
+}}
- return $o;
+if(! function_exists('normalise_link')) {
+function normalise_link($url) {
+ $ret = str_replace(array('https:','//www.'), array('http:','//'), $url);
+ return(rtrim($ret,'/'));
}}
/**
@@ -2292,20 +2533,56 @@ function get_birthdays() {
if(! function_exists('link_compare')) {
function link_compare($a,$b) {
- $a1 = str_replace(array('https:','//www.'), array('http:','//'), $a);
- $b1 = str_replace(array('https:','//www.'), array('http:','//'), $b);
- if(strcasecmp($a1,$b1) === 0)
+ if(strcasecmp(normalise_link($a),normalise_link($b)) === 0)
return true;
return false;
}}
if(! function_exists('prepare_body')) {
-function prepare_body($item) {
+function prepare_body($item,$attach = false) {
+
+ $s = prepare_text($item['body']);
+ if(! $attach)
+ return $s;
+
+ $arr = explode(',',$item['attach']);
+ $s .= '';
+ if(count($arr)) {
+ foreach($arr as $r) {
+ $matches = false;
+ $icon = '';
+ $cnt = preg_match('|\[attach\]href=\"(.+?)\" size=\"(.+?)\" type=\"(.+?)\" title=\"(.+?)\"\[\/attach\]|',$r,$matches);
+ if($cnt) {
+ $icontype = strtolower(substr($matches[3],0,strpos($matches[3],'/')));
+ switch($icontype) {
+ case 'video':
+ case 'audio':
+ case 'image':
+ case 'text':
+ $icon = '
';
+ break;
+ default:
+ $icon = '
';
+ break;
+ }
+ $title = ((strlen(trim($matches[4]))) ? escape_tags(trim($matches[4])) : escape_tags($matches[1]));
+ $title .= ' ' . $matches[2] . ' ' . t('bytes');
+
+ $s .= '
' . $icon . '';
+ }
+ }
+ }
+ $s .= '
';
+ return $s;
+}}
+
+if(! function_exists('prepare_text')) {
+function prepare_text($text) {
require_once('include/bbcode.php');
- $s = smilies(bbcode($item['body']));
+ $s = smilies(bbcode($text));
return $s;
}}
@@ -2324,46 +2601,56 @@ function prepare_body($item) {
* $cmd and string args are surrounded with ""
*/
-if(! function_exists('run_proc')) {
+if(! function_exists('proc_run')) {
function proc_run($cmd){
+
+ $a = get_app();
+
$args = func_get_args();
call_hooks("proc_run", $args);
+
+ if(count($args) && $args[0] === 'php')
+ $args[0] = ((x($a->config,'php_path')) && (strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
- foreach ($args as &$arg){
- if(is_string($arg)) $arg='"'.$arg.'"';
+ foreach ($args as $arg){
+ $arg = escapeshellarg($arg);
}
$cmdline = implode($args," ");
proc_close(proc_open($cmdline." &",array(),$foo));
}}
-/*
- * Return full URL to theme which is currently in effect.
- * Provide a sane default if nothing is chosen or the specified theme does not exist.
- */
-
-if(! function_exists('current_theme_url')) {
-function current_theme_url() {
-
+if(! function_exists('current_theme')) {
+function current_theme(){
$app_base_themes = array('duepuntozero', 'loozah');
-
+
$a = get_app();
-
+
$system_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : '');
- $theme_name = ((x($_SESSION,'theme')) ? $_SESSION['theme'] : $system_theme);
-
+ $theme_name = ((is_array($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $system_theme);
+
if($theme_name && file_exists('view/theme/' . $theme_name . '/style.css'))
- return($a->get_baseurl() . '/view/theme/' . $theme_name . '/style.css');
-
+ return($theme_name);
+
foreach($app_base_themes as $t) {
if(file_exists('view/theme/' . $t . '/style.css'))
- return($a->get_baseurl() . '/view/theme/' . $t . '/style.css');
- }
-
+ return($t);
+ }
+
$fallback = glob('view/theme/*/style.css');
if(count($fallback))
- return($a->get_baseurl() . $fallback[0]);
+ return (str_replace('view/theme/','', str_replace("/style.css","",$fallback[0])));
-
+}}
+
+/*
+* Return full URL to theme which is currently in effect.
+* Provide a sane default if nothing is chosen or the specified theme does not exist.
+*/
+if(! function_exists('current_theme_url')) {
+function current_theme_url() {
+ global $a;
+ $t = current_theme();
+ return($a->get_baseurl() . '/view/theme/' . $t . '/style.css');
}}
if(! function_exists('feed_birthday')) {
@@ -2454,7 +2741,7 @@ if(! function_exists('get_plink')) {
function get_plink($item) {
$a = get_app();
$plink = (((x($item,'plink')) && (! $item['private'])) ? '' : '');
+ . $item['plink'] . '" title="' . t('link to source') . '" target="external-link" class="icon remote-link">' : '');
return $plink;
}}
@@ -2463,3 +2750,49 @@ function unamp($s) {
return str_replace('&', '&', $s);
}}
+
+
+
+if(! function_exists('lang_selector')) {
+function lang_selector() {
+ global $lang;
+ $o .= '';
+ $o .= '
';
+ return $o;
+}}
+
+
+if(! function_exists('parse_xml_string')) {
+function parse_xml_string($s) {
+ if(! strstr($s,'code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA);
+ libxml_clear_errors();
+ return $x;
+}}
+
+if(! function_exists('is_site_admin')) {
+function is_site_admin() {
+ $a = get_app();
+ if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email']))
+ return true;
+ return false;
+}}
+