Merge pull request #3287 from Quix0r/rewrites/coding-convention-split2-1-2

Coding convention applied split 2-1-2 (of 2-14-2)
This commit is contained in:
Hypolite Petovan 2017-04-19 20:39:07 -04:00 committed by GitHub
commit 0811f9257e
13 changed files with 2342 additions and 1804 deletions

View file

@ -4,11 +4,11 @@
* @file include/acl_selectors.php * @file include/acl_selectors.php
*/ */
require_once("include/contact_selectors.php"); require_once "include/contact_selectors.php";
require_once("include/contact_widgets.php"); require_once "include/contact_widgets.php";
require_once("include/DirSearch.php"); require_once "include/DirSearch.php";
require_once("include/features.php"); require_once "include/features.php";
require_once("mod/proxy.php"); require_once "mod/proxy.php";
/** /**
@ -35,10 +35,11 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
if (dbm::is_result($r)) { if (dbm::is_result($r)) {
foreach ($r as $rr) { foreach ($r as $rr) {
if((is_array($preselected)) && in_array($rr['id'], $preselected)) if ((is_array($preselected)) && in_array($rr['id'], $preselected)) {
$selected = " selected=\"selected\" "; $selected = " selected=\"selected\" ";
else } else {
$selected = ''; $selected = '';
}
$trimmed = mb_substr($rr['name'],0,12); $trimmed = mb_substr($rr['name'],0,12);
@ -54,7 +55,8 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
return $o; return $o;
} }
/// @TODO after an optional parameter, no mandadory parameter can follow
/// @TODO find proper type-hints
function contact_selector($selname, $selclass, $preselected = false, $options) { function contact_selector($selname, $selclass, $preselected = false, $options) {
$a = get_app(); $a = get_app();
@ -88,18 +90,20 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {
$networks = array(NETWORK_DFRN); $networks = array(NETWORK_DFRN);
break; break;
case 'PRIVATE': case 'PRIVATE':
if(is_array($a->user) && $a->user['prvnets']) if (is_array($a->user) && $a->user['prvnets']) {
$networks = array(NETWORK_DFRN, NETWORK_MAIL, NETWORK_DIASPORA); $networks = array(NETWORK_DFRN, NETWORK_MAIL, NETWORK_DIASPORA);
else } else {
$networks = array(NETWORK_DFRN, NETWORK_FACEBOOK, NETWORK_MAIL, NETWORK_DIASPORA); $networks = array(NETWORK_DFRN, NETWORK_FACEBOOK, NETWORK_MAIL, NETWORK_DIASPORA);
}
break; break;
case 'TWO_WAY': case 'TWO_WAY':
if(is_array($a->user) && $a->user['prvnets']) if (is_array($a->user) && $a->user['prvnets']) {
$networks = array(NETWORK_DFRN, NETWORK_MAIL, NETWORK_DIASPORA); $networks = array(NETWORK_DFRN, NETWORK_MAIL, NETWORK_DIASPORA);
else } else {
$networks = array(NETWORK_DFRN, NETWORK_FACEBOOK, NETWORK_MAIL, NETWORK_DIASPORA, NETWORK_OSTATUS); $networks = array(NETWORK_DFRN, NETWORK_FACEBOOK, NETWORK_MAIL, NETWORK_DIASPORA, NETWORK_OSTATUS);
}
break; break;
default: default: /// @TODO Maybe log this call?
break; break;
} }
} }
@ -113,26 +117,30 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {
$sql_extra = ''; $sql_extra = '';
if($x['mutual']) { if (x($x, 'mutual')) {
$sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND)); $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
} }
if(intval($x['exclude'])) if (x($x, 'exclude')) {
$sql_extra .= sprintf(" AND `id` != %d ", intval($x['exclude'])); $sql_extra .= sprintf(" AND `id` != %d ", intval($x['exclude']));
}
if (is_array($x['networks']) && count($x['networks'])) { if (is_array($x['networks']) && count($x['networks'])) {
for($y = 0; $y < count($x['networks']) ; $y ++) /// @TODO rewrite to foreach()
for ($y = 0; $y < count($x['networks']) ; $y ++) {
$x['networks'][$y] = "'" . dbesc($x['networks'][$y]) . "'"; $x['networks'][$y] = "'" . dbesc($x['networks'][$y]) . "'";
}
$str_nets = implode(',', $x['networks']); $str_nets = implode(',', $x['networks']);
$sql_extra .= " AND `network` IN ( $str_nets ) "; $sql_extra .= " AND `network` IN ( $str_nets ) ";
} }
$tabindex = (x($options, 'tabindex') ? "tabindex=\"" . $options["tabindex"] . "\"" : ""); $tabindex = (x($options, 'tabindex') ? "tabindex=\"" . $options["tabindex"] . "\"" : "");
if($x['single']) if ($x['single']) {
$o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"" . $x['size'] . "\" $tabindex >\r\n"; $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"" . $x['size'] . "\" $tabindex >\r\n";
else } else {
$o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"" . $x['size'] . "$\" $tabindex >\r\n"; $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"" . $x['size'] . "$\" $tabindex >\r\n";
}
$r = q("SELECT `id`, `name`, `url`, `network` FROM `contact` $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != '' WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != ''
@ -174,7 +182,7 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {
function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false, $privatenet = false, $tabindex = null) { function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false, $privatenet = false, $tabindex = null) {
require_once("include/bbcode.php"); require_once "include/bbcode.php";
$a = get_app(); $a = get_app();
@ -189,25 +197,28 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
$sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND)); $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
} }
if($privmail) if ($privmail) {
$sql_extra .= sprintf(" AND `network` IN ('%s' , '%s') ", $sql_extra .= sprintf(" AND `network` IN ('%s' , '%s') ",
NETWORK_DFRN, NETWORK_DIASPORA); NETWORK_DFRN, NETWORK_DIASPORA);
elseif($privatenet) } elseif ($privatenet) {
$sql_extra .= sprintf(" AND `network` IN ('%s' , '%s', '%s', '%s') ", $sql_extra .= sprintf(" AND `network` IN ('%s' , '%s', '%s', '%s') ",
NETWORK_DFRN, NETWORK_MAIL, NETWORK_FACEBOOK, NETWORK_DIASPORA); NETWORK_DFRN, NETWORK_MAIL, NETWORK_FACEBOOK, NETWORK_DIASPORA);
}
$tabindex = ($tabindex > 0 ? "tabindex=\"$tabindex\"" : ""); $tabindex = ($tabindex > 0 ? "tabindex=\"$tabindex\"" : "");
if ($privmail AND $preselected) { if ($privmail AND $preselected) {
$sql_extra .= " AND `id` IN (".implode(",", $preselected).")"; $sql_extra .= " AND `id` IN (".implode(",", $preselected).")";
$hidepreselected = ' style="display: none;"'; $hidepreselected = ' style="display: none;"';
} else } else {
$hidepreselected = ""; $hidepreselected = "";
}
if($privmail) if ($privmail) {
$o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\" $tabindex $hidepreselected>\r\n"; $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\" $tabindex $hidepreselected>\r\n";
else } else {
$o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" $tabindex >\r\n"; $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" $tabindex >\r\n";
}
$r = q("SELECT `id`, `name`, `url`, `network` FROM `contact` $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != '' WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != ''
@ -229,8 +240,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
foreach ($r as $rr) { foreach ($r as $rr) {
if ((is_array($preselected)) && in_array($rr['id'], $preselected)) { if ((is_array($preselected)) && in_array($rr['id'], $preselected)) {
$selected = " selected=\"selected\" "; $selected = " selected=\"selected\" ";
} } else {
else {
$selected = ''; $selected = '';
} }
@ -249,8 +259,9 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
$o .= "</select>\r\n"; $o .= "</select>\r\n";
if ($privmail AND $preselected) if ($privmail AND $preselected) {
$o .= implode(", ", $receiverlist); $o .= implode(", ", $receiverlist);
}
call_hooks($a->module . '_post_' . $selname, $o); call_hooks($a->module . '_post_' . $selname, $o);
@ -330,10 +341,11 @@ function populate_acl($user = null, $show_jotnets = false) {
); );
if (dbm::is_result($r)) { if (dbm::is_result($r)) {
$mail_enabled = true; $mail_enabled = true;
if(intval($r[0]['pubmail'])) if (intval($r[0]['pubmail'])) {
$pubmail_enabled = true; $pubmail_enabled = true;
} }
} }
}
if (!$user['hidewall']) { if (!$user['hidewall']) {
if ($mail_enabled) { if ($mail_enabled) {
@ -342,10 +354,11 @@ function populate_acl($user = null, $show_jotnets = false) {
} }
call_hooks('jot_networks', $jotnets); call_hooks('jot_networks', $jotnets);
} else } else {
$jotnets .= sprintf(t('Connectors disabled, since "%s" is enabled.'), $jotnets .= sprintf(t('Connectors disabled, since "%s" is enabled.'),
t('Hide your profile details from unknown viewers?')); t('Hide your profile details from unknown viewers?'));
} }
}
$tpl = get_markup_template("acl_selector.tpl"); $tpl = get_markup_template("acl_selector.tpl");
$o = replace_macros($tpl, array( $o = replace_macros($tpl, array(
@ -363,7 +376,7 @@ function populate_acl($user = null, $show_jotnets = false) {
'$aclModalTitle' => t('Permissions'), '$aclModalTitle' => t('Permissions'),
'$aclModalDismiss' => t('Close'), '$aclModalDismiss' => t('Close'),
'$features' => array( '$features' => array(
"aclautomention"=>(feature_enabled($user['uid'],"aclautomention")?"true":"false") 'aclautomention' => (feature_enabled($user['uid'], "aclautomention") ? "true" : "false")
), ),
)); ));
@ -383,22 +396,24 @@ function construct_acl_data(App $a, $user) {
foreach ($acl_data['groups'] as $key => $group) { foreach ($acl_data['groups'] as $key => $group) {
// Add a "selected" flag to groups that are posted to by default // Add a "selected" flag to groups that are posted to by default
if ($user_defaults['allow_gid'] && if ($user_defaults['allow_gid'] &&
in_array($group['id'], $user_defaults['allow_gid']) && !in_array($group['id'], $user_defaults['deny_gid']) ) in_array($group['id'], $user_defaults['allow_gid']) && !in_array($group['id'], $user_defaults['deny_gid']) ) {
$acl_data['groups'][$key]['selected'] = 1; $acl_data['groups'][$key]['selected'] = 1;
else } else {
$acl_data['groups'][$key]['selected'] = 0; $acl_data['groups'][$key]['selected'] = 0;
} }
} }
}
if ($acl_data['contacts']) { if ($acl_data['contacts']) {
foreach ($acl_data['contacts'] as $key => $contact) { foreach ($acl_data['contacts'] as $key => $contact) {
// Add a "selected" flag to groups that are posted to by default // Add a "selected" flag to groups that are posted to by default
if ($user_defaults['allow_cid'] && if ($user_defaults['allow_cid'] &&
in_array($contact['id'], $user_defaults['allow_cid']) && !in_array($contact['id'], $user_defaults['deny_cid']) ) in_array($contact['id'], $user_defaults['allow_cid']) && !in_array($contact['id'], $user_defaults['deny_cid']) ) {
$acl_data['contacts'][$key]['selected'] = 1; $acl_data['contacts'][$key]['selected'] = 1;
else } else {
$acl_data['contacts'][$key]['selected'] = 0; $acl_data['contacts'][$key]['selected'] = 0;
} }
} }
}
return $acl_data; return $acl_data;
@ -420,8 +435,9 @@ function acl_lookup(App $a, $out_type = 'json') {
// For use with jquery.textcomplete for private mail completion // For use with jquery.textcomplete for private mail completion
if (x($_REQUEST, 'query') && strlen($_REQUEST['query'])) { if (x($_REQUEST, 'query') && strlen($_REQUEST['query'])) {
if(! $type) if (! $type) {
$type = 'm'; $type = 'm';
}
$search = $_REQUEST['query']; $search = $_REQUEST['query'];
} }
@ -431,6 +447,7 @@ function acl_lookup(App $a, $out_type = 'json') {
$sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'"; $sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
$sql_extra2 = "AND (`attag` LIKE '%%".dbesc($search)."%%' OR `name` LIKE '%%".dbesc($search)."%%' OR `nick` LIKE '%%".dbesc($search)."%%')"; $sql_extra2 = "AND (`attag` LIKE '%%".dbesc($search)."%%' OR `name` LIKE '%%".dbesc($search)."%%' OR `nick` LIKE '%%".dbesc($search)."%%')";
} else { } else {
/// @TODO Avoid these needless else blocks by putting variable-initialization atop of if()
$sql_extra = $sql_extra2 = ""; $sql_extra = $sql_extra2 = "";
} }
@ -446,8 +463,8 @@ function acl_lookup(App $a, $out_type = 'json') {
$sql_extra2 .= " ".unavailable_networks(); $sql_extra2 .= " ".unavailable_networks();
// autocomplete for editor mentions
if ($type == '' || $type == 'c') { if ($type == '' || $type == 'c') {
// autocomplete for editor mentions
$r = q("SELECT COUNT(*) AS c FROM `contact` $r = q("SELECT COUNT(*) AS c FROM `contact`
WHERE `uid` = %d AND NOT `self` WHERE `uid` = %d AND NOT `self`
AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND NOT `blocked` AND NOT `pending` AND NOT `archive`
@ -534,9 +551,7 @@ function acl_lookup(App $a, $out_type = 'json') {
intval(local_user()), intval(local_user()),
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_STATUSNET) dbesc(NETWORK_OSTATUS), dbesc(NETWORK_STATUSNET)
); );
} } elseif ($type == 'c') {
elseif ($type=='c'){
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact` $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact`
WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != '' WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != ''
AND NOT (`network` IN ('%s')) AND NOT (`network` IN ('%s'))
@ -602,7 +617,7 @@ function acl_lookup(App $a, $out_type = 'json') {
'network' => $g['network'], 'network' => $g['network'],
'link' => $g['url'], 'link' => $g['url'],
'nick' => htmlentities(($g['attag']) ? $g['attag'] : $g['nick']), 'nick' => htmlentities(($g['attag']) ? $g['attag'] : $g['nick']),
'forum' => ((x($g['forum']) || x($g['prv'])) ? 1 : 0), 'forum' => ((x($g, 'forum') || x($g, 'prv')) ? 1 : 0),
); );
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -1067,6 +1067,7 @@ function z_mime_content_type($filename) {
return $mime_types[$ext]; return $mime_types[$ext];
} }
} }
/// @TODO Then let's get rid of it?
// can't use this because we're just passing a name, e.g. not a file that can be opened // can't use this because we're just passing a name, e.g. not a file that can be opened
// elseif (function_exists('finfo_open')) { // elseif (function_exists('finfo_open')) {
// $finfo = @finfo_open(FILEINFO_MIME); // $finfo = @finfo_open(FILEINFO_MIME);

View file

@ -30,11 +30,12 @@ function diaspora_mention2bb($match) {
return '@[url=' . $data['url'] . ']' . $name . '[/url]'; return '@[url=' . $data['url'] . ']' . $name . '[/url]';
} }
// we don't want to support a bbcode specific markdown interpreter /*
// and the markdown library we have is pretty good, but provides HTML output. * we don't want to support a bbcode specific markdown interpreter
// So we'll use that to convert to HTML, then convert the HTML back to bbcode, * and the markdown library we have is pretty good, but provides HTML output.
// and then clean up a few Diaspora specific constructs. * So we'll use that to convert to HTML, then convert the HTML back to bbcode,
* and then clean up a few Diaspora specific constructs.
*/
function diaspora2bb($s) { function diaspora2bb($s) {
$s = html_entity_decode($s, ENT_COMPAT, 'UTF-8'); $s = html_entity_decode($s, ENT_COMPAT, 'UTF-8');
@ -93,11 +94,11 @@ function diaspora_mentions($match) {
$contact = get_contact_details_by_url($match[3]); $contact = get_contact_details_by_url($match[3]);
if (!isset($contact['addr'])) { if (!x($contact, 'addr')) {
$contact = Probe::uri($match[3]); $contact = Probe::uri($match[3]);
} }
if (!isset($contact['addr'])) { if (!x($contact, 'addr')) {
return $match[0]; return $match[0];
} }
@ -222,9 +223,9 @@ function unescape_underscores_in_links($m) {
} }
function format_event_diaspora($ev) { function format_event_diaspora($ev) {
if (! ((is_array($ev)) && count($ev))) {
if(! ((is_array($ev)) && count($ev)))
return ''; return '';
}
$bd_format = t('l F d, Y \@ g:i A') ; // Friday January 18, 2011 @ 8 AM $bd_format = t('l F d, Y \@ g:i A') ; // Friday January 18, 2011 @ 8 AM
@ -239,17 +240,19 @@ function format_event_diaspora($ev) {
$ev['start'] , $bd_format))) $ev['start'] , $bd_format)))
. '](' . App::get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['start'])) . ")\n"; . '](' . App::get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['start'])) . ")\n";
if(! $ev['nofinish']) if (! $ev['nofinish']) {
$o .= t('Finishes:') . ' ' . '[' $o .= t('Finishes:') . ' ' . '['
. (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC',
$ev['finish'] , $bd_format )) $ev['finish'] , $bd_format ))
: day_translate(datetime_convert('UTC', 'UTC', : day_translate(datetime_convert('UTC', 'UTC',
$ev['finish'] , $bd_format ))) $ev['finish'] , $bd_format )))
. '](' . App::get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['finish'])) . ")\n"; . '](' . App::get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['finish'])) . ")\n";
}
if(strlen($ev['location'])) if (strlen($ev['location'])) {
$o .= t('Location:') . bb2diaspora($ev['location']) $o .= t('Location:') . bb2diaspora($ev['location'])
. "\n"; . "\n";
}
$o .= "\n"; $o .= "\n";
return $o; return $o;

View file

@ -9,16 +9,18 @@ require_once 'include/Contact.php';
require_once 'include/plaintext.php'; require_once 'include/plaintext.php';
function bb_PictureCacheExt($matches) { function bb_PictureCacheExt($matches) {
if (strpos($matches[3], "data:image/") === 0) if (strpos($matches[3], "data:image/") === 0) {
return ($matches[0]); return $matches[0];
}
$matches[3] = proxy_url($matches[3]); $matches[3] = proxy_url($matches[3]);
return "[img=" . $matches[1] . "x" . $matches[2] . "]" . $matches[3] . "[/img]"; return "[img=" . $matches[1] . "x" . $matches[2] . "]" . $matches[3] . "[/img]";
} }
function bb_PictureCache($matches) { function bb_PictureCache($matches) {
if (strpos($matches[1], "data:image/") === 0) if (strpos($matches[1], "data:image/") === 0) {
return ($matches[0]); return $matches[0];
}
$matches[1] = proxy_url($matches[1]); $matches[1] = proxy_url($matches[1]);
return "[img]" . $matches[1] . "[/img]"; return "[img]" . $matches[1] . "[/img]";
@ -36,8 +38,9 @@ function bb_map_location($match) {
function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { function bb_attachment($Text, $simplehtml = false, $tryoembed = true) {
$data = get_attachment_data($Text); $data = get_attachment_data($Text);
if (!$data) if (!$data) {
return $Text; return $Text;
}
if (isset($data["title"])) { if (isset($data["title"])) {
$data["title"] = strip_tags($data["title"]); $data["title"] = strip_tags($data["title"]);
@ -57,38 +60,43 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) {
// If the link description is similar to the text above then don't add the link description // If the link description is similar to the text above then don't add the link description
if (($data["title"] != "") AND ((strpos($test1,$test2) !== false) OR if (($data["title"] != "") AND ((strpos($test1,$test2) !== false) OR
(similar_text($test1,$test2) / strlen($data["title"])) > 0.9)) (similar_text($test1,$test2) / strlen($data["title"])) > 0.9)) {
$title2 = $data["url"]; $title2 = $data["url"];
}
$text = sprintf('<a href="%s" title="%s" class="attachment thumbnail" rel="nofollow external">%s</a><br />', $text = sprintf('<a href="%s" title="%s" class="attachment thumbnail" rel="nofollow external">%s</a><br />',
$data["url"], $data["title"], $title2); $data["url"], $data["title"], $title2);
} elseif (($simplehtml != 4) AND ($simplehtml != 0)) } elseif (($simplehtml != 4) AND ($simplehtml != 0)) {
$text = sprintf('<a href="%s" target="_blank">%s</a><br>', $data["url"], $data["title"]); $text = sprintf('<a href="%s" target="_blank">%s</a><br>', $data["url"], $data["title"]);
else { } else {
$text = sprintf('<span class="type-%s">', $data["type"]); $text = sprintf('<span class="type-%s">', $data["type"]);
$bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $data["url"], $data["title"]), $data["url"], $data["title"]); $bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $data["url"], $data["title"]), $data["url"], $data["title"]);
if ($tryoembed) if ($tryoembed) {
$oembed = tryoembed($bookmark); $oembed = tryoembed($bookmark);
else } else {
$oembed = $bookmark[0]; $oembed = $bookmark[0];
}
if (strstr(strtolower($oembed), "<iframe ")) if (strstr(strtolower($oembed), "<iframe ")) {
$text = $oembed; $text = $oembed;
else { } else {
if (($data["image"] != "") AND !strstr(strtolower($oembed), "<img ")) if (($data["image"] != "") AND !strstr(strtolower($oembed), "<img ")) {
$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data["url"], proxy_url($data["image"]), $data["title"]); $text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data["url"], proxy_url($data["image"]), $data["title"]);
elseif (($data["preview"] != "") AND !strstr(strtolower($oembed), "<img ")) } elseif (($data["preview"] != "") AND !strstr(strtolower($oembed), "<img ")) {
$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data["url"], proxy_url($data["preview"]), $data["title"]); $text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data["url"], proxy_url($data["preview"]), $data["title"]);
}
if (($data["type"] == "photo") AND ($data["url"] != "") AND ($data["image"] != "")) if (($data["type"] == "photo") AND ($data["url"] != "") AND ($data["image"] != "")) {
$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a>', $data["url"], proxy_url($data["image"]), $data["title"]); $text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a>', $data["url"], proxy_url($data["image"]), $data["title"]);
else } else {
$text .= $oembed; $text .= $oembed;
}
if (trim($data["description"]) != "") if (trim($data["description"]) != "") {
$text .= sprintf('<blockquote>%s</blockquote></span>', trim(bbcode($data["description"]))); $text .= sprintf('<blockquote>%s</blockquote></span>', trim(bbcode($data["description"])));
} }
} }
}
return $data["text"] . $text . $data["after"]; return $data["text"] . $text . $data["after"];
} }
@ -96,34 +104,37 @@ function bb_remove_share_information($Text, $plaintext = false, $nolink = false)
$data = get_attachment_data($Text); $data = get_attachment_data($Text);
if (!$data) if (!$data) {
return $Text; return $Text;
} elseif ($nolink) {
if ($nolink)
return $data["text"] . $data["after"]; return $data["text"] . $data["after"];
}
$title = htmlentities($data["title"], ENT_QUOTES, 'UTF-8', false); $title = htmlentities($data["title"], ENT_QUOTES, 'UTF-8', false);
$text = htmlentities($data["text"], ENT_QUOTES, 'UTF-8', false); $text = htmlentities($data["text"], ENT_QUOTES, 'UTF-8', false);
if ($plaintext OR (($title != "") AND strstr($text, $title))) if ($plaintext OR (($title != "") AND strstr($text, $title))) {
$data["title"] = $data["url"]; $data["title"] = $data["url"];
elseif (($text != "") AND strstr($title, $text)) { } elseif (($text != "") AND strstr($title, $text)) {
$data["text"] = $data["title"]; $data["text"] = $data["title"];
$data["title"] = $data["url"]; $data["title"] = $data["url"];
} }
if (($data["text"] == "") AND ($data["title"] != "") AND ($data["url"] == "")) if (($data["text"] == "") AND ($data["title"] != "") AND ($data["url"] == "")) {
return $data["title"] . $data["after"]; return $data["title"] . $data["after"];
}
// If the link already is included in the post, don't add it again // If the link already is included in the post, don't add it again
if (($data["url"] != "") AND strpos($data["text"], $data["url"])) if (($data["url"] != "") AND strpos($data["text"], $data["url"])) {
return $data["text"] . $data["after"]; return $data["text"] . $data["after"];
}
$text = $data["text"]; $text = $data["text"];
if (($data["url"] != "") AND ($data["title"] != "")) if (($data["url"] != "") AND ($data["title"] != "")) {
$text .= "\n[url=" . $data["url"] . "]" . $data["title"] . "[/url]"; $text .= "\n[url=" . $data["url"] . "]" . $data["title"] . "[/url]";
elseif (($data["url"] != "")) } elseif (($data["url"] != "")) {
$text .= "\n" . $data["url"]; $text .= "\n" . $data["url"];
}
return $text . "\n" . $data["after"]; return $text . "\n" . $data["after"];
} }
@ -145,14 +156,16 @@ function cleancss($input) {
for ($i = 0; $i < strlen($input); $i++) { for ($i = 0; $i < strlen($input); $i++) {
$char = substr($input, $i, 1); $char = substr($input, $i, 1);
if (($char >= "a") and ($char <= "z")) if (($char >= "a") and ($char <= "z")) {
$cleaned .= $char;
if (!(strpos(" #;:0123456789-_.%", $char) === false))
$cleaned .= $char; $cleaned .= $char;
} }
return($cleaned); if (!(strpos(" #;:0123456789-_.%", $char) === false)) {
$cleaned .= $char;
}
}
return $cleaned;
} }
function stripcode_br_cb($s) { function stripcode_br_cb($s) {
@ -166,25 +179,30 @@ function tryoembed($match) {
$url = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"), $url = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"),
array("https://www.youtube.com/", "https://player.vimeo.com/"), $url); array("https://www.youtube.com/", "https://player.vimeo.com/"), $url);
$o = oembed_fetch_url($url); $o = oembed_fetch_url($url);
if (!is_object($o)) if (!is_object($o)) {
return $match[0]; return $match[0];
}
if (isset($match[2])) if (isset($match[2])) {
$o->title = $match[2]; $o->title = $match[2];
}
if ($o->type=="error") return $match[0]; if ($o->type == "error") {
return $match[0];
}
$html = oembed_format_object($o); $html = oembed_format_object($o);
return $html; return $html;
} }
// [noparse][i]italic[/i][/noparse] turns into /*
// [noparse][ i ]italic[ /i ][/noparse], * [noparse][i]italic[/i][/noparse] turns into
// to hide them from parser. * [noparse][ i ]italic[ /i ][/noparse],
* to hide them from parser.
*/
function bb_spacefy($st) { function bb_spacefy($st) {
$whole_match = $st[0]; $whole_match = $st[0];
$captured = $st[1]; $captured = $st[1];
@ -193,10 +211,11 @@ function bb_spacefy($st) {
return $new_str; return $new_str;
} }
// The previously spacefied [noparse][ i ]italic[ /i ][/noparse], /*
// now turns back and the [noparse] tags are trimed * The previously spacefied [noparse][ i ]italic[ /i ][/noparse],
// returning [i]italic[/i] * now turns back and the [noparse] tags are trimed
* returning [i]italic[/i]
*/
function bb_unspacefy_and_trim($st) { function bb_unspacefy_and_trim($st) {
$whole_match = $st[0]; $whole_match = $st[0];
$captured = $st[1]; $captured = $st[1];
@ -205,23 +224,26 @@ function bb_unspacefy_and_trim($st) {
} }
function bb_find_open_close($s, $open, $close, $occurence = 1) { function bb_find_open_close($s, $open, $close, $occurence = 1) {
if ($occurence < 1) {
if($occurence < 1)
$occurence = 1; $occurence = 1;
}
$start_pos = -1; $start_pos = -1;
for ($i = 1; $i <= $occurence; $i++) { for ($i = 1; $i <= $occurence; $i++) {
if( $start_pos !== false) if ($start_pos !== false) {
$start_pos = strpos($s, $open, $start_pos + 1); $start_pos = strpos($s, $open, $start_pos + 1);
} }
}
if( $start_pos === false) if ($start_pos === false) {
return false; return false;
}
$end_pos = strpos($s, $close, $start_pos); $end_pos = strpos($s, $close, $start_pos);
if( $end_pos === false) if ($end_pos === false) {
return false; return false;
}
$res = array( 'start' => $start_pos, 'end' => $end_pos ); $res = array( 'start' => $start_pos, 'end' => $end_pos );
@ -229,36 +251,50 @@ function bb_find_open_close($s, $open, $close, $occurence = 1) {
} }
function get_bb_tag_pos($s, $name, $occurence = 1) { function get_bb_tag_pos($s, $name, $occurence = 1) {
if ($occurence < 1) {
if($occurence < 1)
$occurence = 1; $occurence = 1;
}
$start_open = -1; $start_open = -1;
for ($i = 1; $i <= $occurence; $i++) { for ($i = 1; $i <= $occurence; $i++) {
if( $start_open !== false) if ($start_open !== false) {
$start_open = strpos($s, '[' . $name, $start_open + 1); // allow [name= type tags $start_open = strpos($s, '[' . $name, $start_open + 1); // allow [name= type tags
} }
}
if( $start_open === false) if ($start_open === false) {
return false; return false;
}
$start_equal = strpos($s, '=', $start_open); $start_equal = strpos($s, '=', $start_open);
$start_close = strpos($s, ']', $start_open); $start_close = strpos($s, ']', $start_open);
if( $start_close === false) if ($start_close === false) {
return false; return false;
}
$start_close++; $start_close++;
$end_open = strpos($s, '[/' . $name . ']', $start_close); $end_open = strpos($s, '[/' . $name . ']', $start_close);
if( $end_open === false) if ($end_open === false) {
return false; return false;
}
$res = array( 'start' => array('open' => $start_open, 'close' => $start_close), $res = array(
'end' => array('open' => $end_open, 'close' => $end_open + strlen('[/' . $name . ']')) ); 'start' => array(
if( $start_equal !== false) 'open' => $start_open,
'close' => $start_close
),
'end' => array(
'open' => $end_open,
'close' => $end_open + strlen('[/' . $name . ']')
),
);
if ($start_equal !== false) {
$res['start']['equal'] = $start_equal + 1; $res['start']['equal'] = $start_equal + 1;
}
return $res; return $res;
} }
@ -270,12 +306,12 @@ function bb_tag_preg_replace($pattern, $replace, $name, $s) {
$occurence = 1; $occurence = 1;
$pos = get_bb_tag_pos($string, $name, $occurence); $pos = get_bb_tag_pos($string, $name, $occurence);
while ($pos !== false && $occurence < 1000) { while ($pos !== false && $occurence < 1000) {
$start = substr($string, 0, $pos['start']['open']); $start = substr($string, 0, $pos['start']['open']);
$subject = substr($string, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']); $subject = substr($string, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
$end = substr($string, $pos['end']['close']); $end = substr($string, $pos['end']['close']);
if($end === false) if ($end === false) {
$end = ''; $end = '';
}
$subject = preg_replace($pattern, $replace, $subject); $subject = preg_replace($pattern, $replace, $subject);
$string = $start . $subject . $end; $string = $start . $subject . $end;
@ -310,14 +346,16 @@ function bb_extract_images($body) {
$new_body = $new_body . substr($orig_body, 0, $img_start) . '[$#saved_image' . $cnt . '#$]'; $new_body = $new_body . substr($orig_body, 0, $img_start) . '[$#saved_image' . $cnt . '#$]';
$cnt++; $cnt++;
} } else {
else
$new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]')); $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
}
$orig_body = substr($orig_body, $img_end + strlen('[/img]')); $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
if($orig_body === false) // in case the body ends on a closing image tag if ($orig_body === false) {
// in case the body ends on a closing image tag
$orig_body = ''; $orig_body = '';
}
$img_start = strpos($orig_body, '[img'); $img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
@ -504,104 +542,114 @@ function bb_ShareAttributes($share, $simplehtml) {
); );
break; break;
} }
return($text);
return $text;
} }
function GetProfileUsername($profile, $username, $compact = false, $getnetwork = false) { function GetProfileUsername($profile, $username, $compact = false, $getnetwork = false) {
$twitter = preg_replace("=https?://twitter.com/(.*)=ism", "$1@twitter.com", $profile); $twitter = preg_replace("=https?://twitter.com/(.*)=ism", "$1@twitter.com", $profile);
if ($twitter != $profile) { if ($twitter != $profile) {
if ($getnetwork) if ($getnetwork) {
return(NETWORK_TWITTER); return NETWORK_TWITTER;
elseif ($compact) } elseif ($compact) {
return($twitter); return $twitter;
else } else {
return ($username . " (" . $twitter . ")"); return ($username . " (" . $twitter . ")");
} }
}
$appnet = preg_replace("=https?://alpha.app.net/(.*)=ism", "$1@alpha.app.net", $profile); $appnet = preg_replace("=https?://alpha.app.net/(.*)=ism", "$1@alpha.app.net", $profile);
if ($appnet != $profile) { if ($appnet != $profile) {
if ($getnetwork) if ($getnetwork) {
return(NETWORK_APPNET); return NETWORK_APPNET;
elseif ($compact) } elseif ($compact) {
return($appnet); return $appnet;
else } else {
return ($username . " (" . $appnet . ")"); return ($username . " (" . $appnet . ")");
} }
}
$gplus = preg_replace("=https?://plus.google.com/(.*)=ism", "$1@plus.google.com", $profile); $gplus = preg_replace("=https?://plus.google.com/(.*)=ism", "$1@plus.google.com", $profile);
if ($gplus != $profile) { if ($gplus != $profile) {
if ($getnetwork) if ($getnetwork) {
return(NETWORK_GPLUS); return NETWORK_GPLUS;
elseif ($compact) } elseif ($compact) {
return ($gplususername . " (" . $username . ")"); return ($gplususername . " (" . $username . ")");
else } else {
return ($username . " (" . $gplus . ")"); return ($username . " (" . $gplus . ")");
} }
}
$friendica = preg_replace("=https?://(.*)/profile/(.*)=ism", "$2@$1", $profile); $friendica = preg_replace("=https?://(.*)/profile/(.*)=ism", "$2@$1", $profile);
if ($friendica != $profile) { if ($friendica != $profile) {
if ($getnetwork) if ($getnetwork) {
return(NETWORK_DFRN); return NETWORK_DFRN;
elseif ($compact) } elseif ($compact) {
return($friendica); return $friendica;
else } else {
return ($username . " (" . $friendica . ")"); return ($username . " (" . $friendica . ")");
} }
}
$diaspora = preg_replace("=https?://(.*)/u/(.*)=ism", "$2@$1", $profile); $diaspora = preg_replace("=https?://(.*)/u/(.*)=ism", "$2@$1", $profile);
if ($diaspora != $profile) { if ($diaspora != $profile) {
if ($getnetwork) if ($getnetwork) {
return(NETWORK_DIASPORA); return NETWORK_DIASPORA;
elseif ($compact) } elseif ($compact) {
return($diaspora); return $diaspora;
else } else {
return ($username . " (" . $diaspora . ")"); return ($username . " (" . $diaspora . ")");
} }
}
$red = preg_replace("=https?://(.*)/channel/(.*)=ism", "$2@$1", $profile); $red = preg_replace("=https?://(.*)/channel/(.*)=ism", "$2@$1", $profile);
if ($red != $profile) { if ($red != $profile) {
if ($getnetwork) if ($getnetwork) {
// red is identified as Diaspora - friendica can't connect directly to it // red is identified as Diaspora - friendica can't connect directly to it
return(NETWORK_DIASPORA); return NETWORK_DIASPORA;
elseif ($compact) } elseif ($compact) {
return($red); return $red;
else } else {
return ($username . " (" . $red . ")"); return ($username . " (" . $red . ")");
} }
}
$StatusnetHost = preg_replace("=https?://(.*)/user/(.*)=ism", "$1", $profile); $StatusnetHost = preg_replace("=https?://(.*)/user/(.*)=ism", "$1", $profile);
if ($StatusnetHost != $profile) { if ($StatusnetHost != $profile) {
$StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile); $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile);
if ($StatusnetUser != $profile) { if ($StatusnetUser != $profile) {
/// @TODO Some hosts run on https, not just http and sometimes http is disabled, let's support both here
$UserData = fetch_url("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); $UserData = fetch_url("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser);
$user = json_decode($UserData); $user = json_decode($UserData);
if ($user) { if ($user) {
if ($getnetwork) if ($getnetwork) {
return(NETWORK_STATUSNET); return NETWORK_STATUSNET;
elseif ($compact) } elseif ($compact) {
return ($user->screen_name . "@" . $StatusnetHost); return ($user->screen_name . "@" . $StatusnetHost);
else } else {
return ($username . " (" . $user->screen_name . "@" . $StatusnetHost . ")"); return ($username . " (" . $user->screen_name . "@" . $StatusnetHost . ")");
} }
} }
} }
}
// pumpio (http://host.name/user) // pumpio (http://host.name/user)
$rest = preg_replace("=https?://([\.\w]+)/([\.\w]+)(.*)=ism", "$3", $profile); $rest = preg_replace("=https?://([\.\w]+)/([\.\w]+)(.*)=ism", "$3", $profile);
if ($rest == "") { if ($rest == "") {
$pumpio = preg_replace("=https?://([\.\w]+)/([\.\w]+)(.*)=ism", "$2@$1", $profile); $pumpio = preg_replace("=https?://([\.\w]+)/([\.\w]+)(.*)=ism", "$2@$1", $profile);
if ($pumpio != $profile) { if ($pumpio != $profile) {
if ($getnetwork) if ($getnetwork) {
return(NETWORK_PUMPIO); return NETWORK_PUMPIO;
elseif ($compact) } elseif ($compact) {
return($pumpio); return $pumpio;
else } else {
return ($username . " (" . $pumpio . ")"); return ($username . " (" . $pumpio . ")");
} }
} }
}
return($username); return $username;
} }
function bb_DiasporaLinks($match) { function bb_DiasporaLinks($match) {
@ -652,15 +700,17 @@ function bb_RemovePictureLinks($match) {
} }
Cache::set($match[1],$text); Cache::set($match[1],$text);
} }
return($text);
return $text;
} }
function bb_expand_links($match) { function bb_expand_links($match) {
if (($match[3] == "") OR ($match[2] == $match[3]) OR stristr($match[2], $match[3])) if (($match[3] == "") OR ($match[2] == $match[3]) OR stristr($match[2], $match[3])) {
return ($match[1] . "[url]" . $match[2] . "[/url]"); return ($match[1] . "[url]" . $match[2] . "[/url]");
else } else {
return ($match[1] . $match[3] . " [url]" . $match[2] . "[/url]"); return ($match[1] . $match[3] . " [url]" . $match[2] . "[/url]");
} }
}
function bb_CleanPictureLinksSub($match) { function bb_CleanPictureLinksSub($match) {
$text = Cache::get($match[1]); $text = Cache::get($match[1]);
@ -707,18 +757,20 @@ function bb_CleanPictureLinksSub($match) {
} }
Cache::set($match[1],$text); Cache::set($match[1],$text);
} }
return($text);
return $text;
} }
function bb_CleanPictureLinks($text) { function bb_CleanPictureLinks($text) {
$text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'bb_CleanPictureLinksSub', $text); $text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'bb_CleanPictureLinksSub', $text);
return ($text); return $text;
} }
function bb_highlight($match) { function bb_highlight($match) {
if (in_array(strtolower($match[1]), ['php', 'css', 'mysql', 'sql', 'abap', 'diff', 'html', 'perl', 'ruby', if (in_array(strtolower($match[1]), ['php', 'css', 'mysql', 'sql', 'abap', 'diff', 'html', 'perl', 'ruby',
'vbscript','avrc','dtd','java','xml','cpp','python','javascript','js','sh'])) 'vbscript', 'avrc', 'dtd', 'java', 'xml', 'cpp', 'python', 'javascript', 'js', 'sh'])) {
return text_highlight($match[2], strtolower($match[1])); return text_highlight($match[2], strtolower($match[1]));
}
return $match[0]; return $match[0];
} }
@ -1083,14 +1135,13 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
// Shared content // Shared content
$Text = preg_replace_callback("/(.*?)\[share(.*?)\](.*?)\[\/share\]/ism", $Text = preg_replace_callback("/(.*?)\[share(.*?)\](.*?)\[\/share\]/ism",
function ($match) use ($simplehtml) { function ($match) use ($simplehtml) {
return(bb_ShareAttributes($match, $simplehtml)); return bb_ShareAttributes($match, $simplehtml);
}, $Text); }, $Text);
$Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '<br/><img src="' .App::get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /><br />', $Text); $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '<br/><img src="' .App::get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /><br />', $Text);
$Text = preg_replace("/\[crypt(.*?)\](.*?)\[\/crypt\]/ism", '<br/><img src="' .App::get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . '$1' . ' ' . t('Encrypted content') . '" /><br />', $Text); $Text = preg_replace("/\[crypt(.*?)\](.*?)\[\/crypt\]/ism", '<br/><img src="' .App::get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . '$1' . ' ' . t('Encrypted content') . '" /><br />', $Text);
//$Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism", '<br/><img src="' .App::get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . '$1' . ' ' . t('Encrypted content') . '" /><br />', $Text); //$Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism", '<br/><img src="' .App::get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . '$1' . ' ' . t('Encrypted content') . '" /><br />', $Text);
// Try to Oembed // Try to Oembed
if ($tryoembed) { if ($tryoembed) {
$Text = preg_replace("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", '<video src="$1" controls="controls" width="' . $a->videowidth . '" height="' . $a->videoheight . '"><a href="$1">$1</a></video>', $Text); $Text = preg_replace("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", '<video src="$1" controls="controls" width="' . $a->videowidth . '" height="' . $a->videoheight . '"><a href="$1">$1</a></video>', $Text);

View file

@ -13,7 +13,7 @@ function follow_widget($value = "") {
} }
function findpeople_widget() { function findpeople_widget() {
require_once('include/Contact.php'); require_once 'include/Contact.php';
$a = get_app(); $a = get_app();
@ -45,32 +45,41 @@ function unavailable_networks() {
$networks = array(); $networks = array();
if (!plugin_enabled("appnet")) if (!plugin_enabled("appnet")) {
$networks[] = NETWORK_APPNET; $networks[] = NETWORK_APPNET;
}
if (!plugin_enabled("fbpost") AND !plugin_enabled("facebook")) if (!plugin_enabled("fbpost") AND !plugin_enabled("facebook")) {
$networks[] = NETWORK_FACEBOOK; $networks[] = NETWORK_FACEBOOK;
}
if (!plugin_enabled("statusnet")) if (!plugin_enabled("statusnet")) {
$networks[] = NETWORK_STATUSNET; $networks[] = NETWORK_STATUSNET;
}
if (!plugin_enabled("pumpio")) if (!plugin_enabled("pumpio")) {
$networks[] = NETWORK_PUMPIO; $networks[] = NETWORK_PUMPIO;
}
if (!plugin_enabled("twitter")) if (!plugin_enabled("twitter")) {
$networks[] = NETWORK_TWITTER; $networks[] = NETWORK_TWITTER;
}
if (get_config("system","ostatus_disabled")) if (get_config("system", "ostatus_disabled")) {
$networks[] = NETWORK_OSTATUS; $networks[] = NETWORK_OSTATUS;
}
if (!get_config("system","diaspora_enabled")) if (!get_config("system", "diaspora_enabled")) {
$networks[] = NETWORK_DIASPORA; $networks[] = NETWORK_DIASPORA;
}
if (!plugin_enabled("pnut")) if (!plugin_enabled("pnut")) {
$networks[] = NETWORK_PNUT; $networks[] = NETWORK_PNUT;
}
if (!sizeof($networks)) if (!sizeof($networks)) {
return ""; return "";
}
$network_filter = implode("','", $networks); $network_filter = implode("','", $networks);
@ -99,7 +108,7 @@ function networks_widget($baseurl,$selected = '') {
$nets = array(); $nets = array();
if (dbm::is_result($r)) { if (dbm::is_result($r)) {
require_once('include/contact_selectors.php'); require_once 'include/contact_selectors.php';
foreach ($r as $rr) { foreach ($r as $rr) {
/// @TODO If 'network' is not there, this triggers an E_NOTICE /// @TODO If 'network' is not there, this triggers an E_NOTICE
if ($rr['network']) { if ($rr['network']) {
@ -108,8 +117,9 @@ function networks_widget($baseurl,$selected = '') {
} }
} }
if(count($nets) < 2) if (count($nets) < 2) {
return ''; return '';
}
return replace_macros(get_markup_template('nets.tpl'), array( return replace_macros(get_markup_template('nets.tpl'), array(
'$title' => t('Networks'), '$title' => t('Networks'),
@ -173,6 +183,7 @@ function categories_widget($baseurl,$selected = '') {
$matches = false; $matches = false;
$terms = array(); $terms = array();
$cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER); $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
if ($cnt) { if ($cnt) {
foreach ($matches as $mtch) { foreach ($matches as $mtch) {
$unescaped = xmlify(file_tag_decode($mtch[1])); $unescaped = xmlify(file_tag_decode($mtch[1]));
@ -195,8 +206,9 @@ function common_friends_visitor_widget($profile_uid) {
$a = get_app(); $a = get_app();
if(local_user() == $profile_uid) if (local_user() == $profile_uid) {
return; return;
}
$cid = $zcid = 0; $cid = $zcid = 0;
@ -215,9 +227,9 @@ function common_friends_visitor_widget($profile_uid) {
dbesc(normalise_link(get_my_url())), dbesc(normalise_link(get_my_url())),
intval($profile_uid) intval($profile_uid)
); );
if (dbm::is_result($r)) if (dbm::is_result($r)) {
$cid = $r[0]['id']; $cid = $r[0]['id'];
else { } else {
$r = q("select id from gcontact where nurl = '%s' limit 1", $r = q("select id from gcontact where nurl = '%s' limit 1",
dbesc(normalise_link(get_my_url())) dbesc(normalise_link(get_my_url()))
); );
@ -227,22 +239,26 @@ function common_friends_visitor_widget($profile_uid) {
} }
} }
if($cid == 0 && $zcid == 0) if ($cid == 0 && $zcid == 0) {
return; return;
}
require_once('include/socgraph.php'); require_once 'include/socgraph.php';
if($cid) if ($cid) {
$t = count_common_friends($profile_uid, $cid); $t = count_common_friends($profile_uid, $cid);
else } else {
$t = count_common_friends_zcid($profile_uid, $zcid); $t = count_common_friends_zcid($profile_uid, $zcid);
if(! $t) }
if (! $t) {
return; return;
}
if($cid) if ($cid) {
$r = common_friends($profile_uid, $cid, 0, 5, true); $r = common_friends($profile_uid, $cid, 0, 5, true);
else } else {
$r = common_friends_zcid($profile_uid, $zcid, 0, 5, true); $r = common_friends_zcid($profile_uid, $zcid, 0, 5, true);
}
return replace_macros(get_markup_template('remote_friends_common.tpl'), array( return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
'$desc' => sprintf( tt("%d contact in common", "%d contacts in common", $t), $t), '$desc' => sprintf( tt("%d contact in common", "%d contacts in common", $t), $t),

View file

@ -1,12 +1,14 @@
<?php <?php
require_once("include/bbcode.php"); require_once "include/bbcode.php";
require_once("include/acl_selectors.php"); require_once "include/acl_selectors.php";
// Note: the code in 'item_extract_images' and 'item_redir_and_replace_images' /*
// is identical to the code in mod/message.php for 'item_extract_images' and * Note: the code in 'item_extract_images' and 'item_redir_and_replace_images'
// 'item_redir_and_replace_images' * is identical to the code in mod/message.php for 'item_extract_images' and
* 'item_redir_and_replace_images'
*/
if (! function_exists('item_extract_images')) { if (! function_exists('item_extract_images')) {
function item_extract_images($body) { function item_extract_images($body) {
@ -30,14 +32,16 @@ function item_extract_images($body) {
$new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]'; $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
$cnt++; $cnt++;
} } else {
else
$new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]')); $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
}
$orig_body = substr($orig_body, $img_end + strlen('[/img]')); $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
if($orig_body === false) // in case the body ends on a closing image tag if ($orig_body === false) {
// in case the body ends on a closing image tag
$orig_body = ''; $orig_body = '';
}
$img_start = strpos($orig_body, '[img'); $img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
@ -66,8 +70,9 @@ function item_redir_and_replace_images($body, $images, $cid) {
$newbody .= substr($origbody, 0, $pos['start']['open']); $newbody .= substr($origbody, 0, $pos['start']['open']);
$subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']); $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
$origbody = substr($origbody, $pos['end']['close']); $origbody = substr($origbody, $pos['end']['close']);
if($origbody === false) if ($origbody === false) {
$origbody = ''; $origbody = '';
}
$subject = preg_replace($search, $replace, $subject); $subject = preg_replace($search, $replace, $subject);
$newbody .= $subject; $newbody .= $subject;
@ -79,26 +84,28 @@ function item_redir_and_replace_images($body, $images, $cid) {
$cnt = 0; $cnt = 0;
foreach ($images as $image) { foreach ($images as $image) {
// We're depending on the property of 'foreach' (specified on the PHP website) that /*
// it loops over the array starting from the first element and going sequentially * We're depending on the property of 'foreach' (specified on the PHP website) that
// to the last element * it loops over the array starting from the first element and going sequentially
* to the last element.
*/
$newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody); $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
$cnt++; $cnt++;
} }
return $newbody; return $newbody;
}} }}
/** /**
* Render actions localized * Render actions localized
*/ */
function localize_item(&$item) { function localize_item(&$item) {
$extracted = item_extract_images($item['body']); $extracted = item_extract_images($item['body']);
if($extracted['images']) if ($extracted['images']) {
$item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']); $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
}
/// @Separted ???
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
if (activity_match($item['verb'], ACTIVITY_LIKE) if (activity_match($item['verb'], ACTIVITY_LIKE)
|| activity_match($item['verb'], ACTIVITY_DISLIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)
@ -106,10 +113,14 @@ function localize_item(&$item){
|| activity_match($item['verb'], ACTIVITY_ATTENDNO) || activity_match($item['verb'], ACTIVITY_ATTENDNO)
|| activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) { || activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
$r = q("SELECT * from `item`,`contact` WHERE /// @TODO may hurt performance
`item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';", $r = q("SELECT * FROM `item`, `contact`
WHERE `item`.`contact-id`=`contact`.`id`
AND `item`.`uri`='%s'",
dbesc($item['parent-uri'])); dbesc($item['parent-uri']));
if (!dbm::is_result($r)) return; if (!dbm::is_result($r)) {
return;
}
$obj = $r[0]; $obj = $r[0];
$author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]'; $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
@ -128,7 +139,8 @@ function localize_item(&$item){
default: default:
if ($obj['resource-id']) { if ($obj['resource-id']) {
$post_type = t('photo'); $post_type = t('photo');
$m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m); $m = array();
preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
$rr['plink'] = $m[1]; $rr['plink'] = $m[1];
} else { } else {
$post_type = t('status'); $post_type = t('status');
@ -175,21 +187,25 @@ function localize_item(&$item){
case "alternate": $Blink = $atts['href']; case "alternate": $Blink = $atts['href'];
case "photo": $Bphoto = $atts['href']; case "photo": $Bphoto = $atts['href'];
} }
} }
$A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]'; $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]'; $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]'; if ($Bphoto != "") {
$Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
}
$item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto; $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
} }
if (stristr($item['verb'], ACTIVITY_POKE)) { if (stristr($item['verb'], ACTIVITY_POKE)) {
$verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1)); $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
if(! $verb) if (! $verb) {
return; return;
if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return; }
if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) {
return;
}
$Aname = $item['author-name']; $Aname = $item['author-name'];
$Alink = $item['author-link']; $Alink = $item['author-link'];
@ -200,22 +216,26 @@ function localize_item(&$item){
$links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>"); $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
$Bname = $obj->title; $Bname = $obj->title;
$Blink = ""; $Bphoto = ""; $Blink = "";
$Bphoto = "";
foreach ($links->link as $l) { foreach ($links->link as $l) {
$atts = $l->attributes(); $atts = $l->attributes();
switch ($atts['rel']) { switch ($atts['rel']) {
case "alternate": $Blink = $atts['href']; case "alternate": $Blink = $atts['href'];
case "photo": $Bphoto = $atts['href']; case "photo": $Bphoto = $atts['href'];
} }
} }
$A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]'; $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]'; $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]'; if ($Bphoto != "") {
$Bphoto = '[url=' . zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
}
// we can't have a translation string with three positions but no distinguishable text /*
// So here is the translate string. * we can't have a translation string with three positions but no distinguishable text
* So here is the translate string.
*/
$txt = t('%1$s poked %2$s'); $txt = t('%1$s poked %2$s');
// now translate the verb // now translate the verb
@ -229,8 +249,9 @@ function localize_item(&$item){
} }
if (stristr($item['verb'], ACTIVITY_MOOD)) { if (stristr($item['verb'], ACTIVITY_MOOD)) {
$verb = urldecode(substr($item['verb'], strpos($item['verb'], '#') + 1)); $verb = urldecode(substr($item['verb'], strpos($item['verb'], '#') + 1));
if(! $verb) if (! $verb) {
return; return;
}
$Aname = $item['author-name']; $Aname = $item['author-name'];
$Alink = $item['author-link']; $Alink = $item['author-link'];
@ -242,10 +263,16 @@ function localize_item(&$item){
} }
if (activity_match($item['verb'], ACTIVITY_TAG)) { if (activity_match($item['verb'], ACTIVITY_TAG)) {
$r = q("SELECT * from `item`,`contact` WHERE /// @TODO may hurt performance "joining" two tables + asterisk
`item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';", $r = q("SELECT * FROM `item`, `contact`
WHERE `item`.`contact-id`=`contact`.`id`
AND `item`.`uri`='%s'",
dbesc($item['parent-uri'])); dbesc($item['parent-uri']));
if (!dbm::is_result($r)) return;
if (!dbm::is_result($r)) {
return;
}
$obj = $r[0]; $obj = $r[0];
$author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]'; $author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
@ -269,6 +296,8 @@ function localize_item(&$item){
} else { } else {
$post_type = t('status'); $post_type = t('status');
} }
// Let's break everthing ... ;-)
break;
} }
$plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]'; $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
@ -280,8 +309,9 @@ function localize_item(&$item){
} }
if (activity_match($item['verb'], ACTIVITY_FAVORITE)) { if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
if ($item['object-type']== "") if ($item['object-type'] == "") {
return; return;
}
$Aname = $item['author-name']; $Aname = $item['author-name'];
$Alink = $item['author-link']; $Alink = $item['author-link'];
@ -290,10 +320,11 @@ function localize_item(&$item){
$obj = parse_xml_string($xmlhead.$item['object']); $obj = parse_xml_string($xmlhead.$item['object']);
if (strlen($obj->id)) { if (strlen($obj->id)) {
$r = q("select * from item where uri = '%s' and uid = %d limit 1", $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($obj->id), dbesc($obj->id),
intval($item['uid']) intval($item['uid'])
); );
if (dbm::is_result($r) && $r[0]['plink']) { if (dbm::is_result($r) && $r[0]['plink']) {
$target = $r[0]; $target = $r[0];
$Bname = $target['author-name']; $Bname = $target['author-name'];
@ -302,17 +333,17 @@ function localize_item(&$item){
$B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]'; $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
$P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]'; $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
$item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n"; $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
} }
} }
} }
$matches = null; $matches = null;
if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) { if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) {
foreach ($matches as $mtch) { foreach ($matches as $mtch) {
if(! strpos($mtch[1],'zrl=')) if (! strpos($mtch[1], 'zrl=')) {
$item['body'] = str_replace($mtch[0], '@[url=' . zrl($mtch[1]) . ']', $item['body']); $item['body'] = str_replace($mtch[0], '@[url=' . zrl($mtch[1]) . ']', $item['body']);
} }
} }
}
// add zrl's to public images // add zrl's to public images
$photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is"; $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
@ -332,21 +363,20 @@ function localize_item(&$item){
$item['plink'] = $y . '?f=&url=' . $item['plink']; $item['plink'] = $y . '?f=&url=' . $item['plink'];
} }
} }
} }
/** /**
* Count the total of comments on this item and its desendants * Count the total of comments on this item and its desendants
* @TODO proper type-hint + doc-tag
*/ */
function count_descendants($item) { function count_descendants($item) {
$total = count($item['children']); $total = count($item['children']);
if ($total > 0) { if ($total > 0) {
foreach ($item['children'] as $child) { foreach ($item['children'] as $child) {
if(! visible_activity($child)) if (! visible_activity($child)) {
$total --; $total --;
}
$total += count_descendants($child); $total += count_descendants($child);
} }
} }
@ -356,9 +386,10 @@ function count_descendants($item) {
function visible_activity($item) { function visible_activity($item) {
// likes (etc.) can apply to other things besides posts. Check if they are post children, /*
// in which case we handle them specially * likes (etc.) can apply to other things besides posts. Check if they are post children,
* in which case we handle them specially
*/
$hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE); $hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE);
foreach ($hidden_activities as $act) { foreach ($hidden_activities as $act) {
if (activity_match($item['verb'], $act)) { if (activity_match($item['verb'], $act)) {
@ -379,7 +410,6 @@ function visible_activity($item) {
* @brief SQL query for items * @brief SQL query for items
*/ */
function item_query() { function item_query() {
return "SELECT " . item_fieldlists() . " FROM `item` " . return "SELECT " . item_fieldlists() . " FROM `item` " .
item_joins() . " WHERE " . item_condition(); item_joins() . " WHERE " . item_condition();
} }
@ -439,7 +469,6 @@ These Fields are not added below (yet). They are here to for bug search.
* @brief SQL join for contacts that are needed for displaying items * @brief SQL join for contacts that are needed for displaying items
*/ */
function item_joins() { function item_joins() {
return "STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND return "STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND
(NOT `contact`.`blocked` OR `contact`.`pending`) (NOT `contact`.`blocked` OR `contact`.`pending`)
LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
@ -450,10 +479,10 @@ function item_joins() {
* @brief SQL condition for items that are needed for displaying items * @brief SQL condition for items that are needed for displaying items
*/ */
function item_condition() { function item_condition() {
return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`"; return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`";
} }
if (!function_exists('conversation')) {
/** /**
* "Render" a conversation or list of items for HTML display. * "Render" a conversation or list of items for HTML display.
* There are two major forms of display: * There are two major forms of display:
@ -464,13 +493,11 @@ function item_condition() {
* that are based on unique features of the calling module. * that are based on unique features of the calling module.
* *
*/ */
if(!function_exists('conversation')) {
function conversation(App $a, $items, $mode, $update, $preview = false) { function conversation(App $a, $items, $mode, $update, $preview = false) {
require_once('include/bbcode.php'); require_once 'include/bbcode.php';
require_once('include/Contact.php'); require_once 'include/Contact.php';
require_once('mod/proxy.php'); require_once 'mod/proxy.php';
$ssl_state = ((local_user()) ? true : false); $ssl_state = ((local_user()) ? true : false);
@ -484,9 +511,10 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$str_blocked = get_pconfig(local_user(), 'system', 'blocked'); $str_blocked = get_pconfig(local_user(), 'system', 'blocked');
if ($str_blocked) { if ($str_blocked) {
$arr_blocked = explode(',', $str_blocked); $arr_blocked = explode(',', $str_blocked);
for($x = 0; $x < count($arr_blocked); $x ++) for ($x = 0; $x < count($arr_blocked); $x ++) {
$arr_blocked[$x] = trim($arr_blocked[$x]); $arr_blocked[$x] = trim($arr_blocked[$x]);
} }
}
} }
@ -496,10 +524,11 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$profile_owner = local_user(); $profile_owner = local_user();
$page_writeable = true; $page_writeable = true;
if (!$update) { if (!$update) {
// The special div is needed for liveUpdate to kick in for this page. /*
// We only launch liveUpdate if you aren't filtering in some incompatible * The special div is needed for liveUpdate to kick in for this page.
// way and also you aren't writing a comment (discovered in javascript). * We only launch liveUpdate if you aren't filtering in some incompatible
* way and also you aren't writing a comment (discovered in javascript).
*/
$live_update_div = '<div id="live-network"></div>' . "\r\n" $live_update_div = '<div id="live-network"></div>' . "\r\n"
. "<script> var profile_uid = " . $_SESSION['uid'] . "<script> var profile_uid = " . $_SESSION['uid']
. "; var netargs = '" . substr($a->cmd, 8) . "; var netargs = '" . substr($a->cmd, 8)
@ -519,8 +548,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
. "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
} }
} } elseif ($mode === 'profile') {
else if($mode === 'profile') {
$profile_owner = $a->profile['profile_uid']; $profile_owner = $a->profile['profile_uid'];
$page_writeable = can_write_wall($a,$profile_owner); $page_writeable = can_write_wall($a,$profile_owner);
@ -528,16 +556,17 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$tab = notags(trim($_GET['tab'])); $tab = notags(trim($_GET['tab']));
$tab = ( $tab ? $tab : 'posts' ); $tab = ( $tab ? $tab : 'posts' );
if ($tab === 'posts') { if ($tab === 'posts') {
// This is ugly, but we can't pass the profile_uid through the session to the ajax updater, /*
// because browser prefetching might change it on us. We have to deliver it with the page. * This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
* because browser prefetching might change it on us. We have to deliver it with the page.
*/
$live_update_div = '<div id="live-profile"></div>' . "\r\n" $live_update_div = '<div id="live-profile"></div>' . "\r\n"
. "<script> var profile_uid = " . $a->profile['profile_uid'] . "<script> var profile_uid = " . $a->profile['profile_uid']
. "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
} }
} }
} } elseif ($mode === 'notes') {
else if($mode === 'notes') {
$profile_owner = local_user(); $profile_owner = local_user();
$page_writeable = true; $page_writeable = true;
if (!$update) { if (!$update) {
@ -545,8 +574,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
. "<script> var profile_uid = " . local_user() . "<script> var profile_uid = " . local_user()
. "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
} }
} } elseif ($mode === 'display') {
else if($mode === 'display') {
$profile_owner = $a->profile['uid']; $profile_owner = $a->profile['uid'];
$page_writeable = can_write_wall($a,$profile_owner); $page_writeable = can_write_wall($a,$profile_owner);
if (!$update) { if (!$update) {
@ -554,26 +582,25 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
. "<script> var profile_uid = " . $_SESSION['uid'] . ";" . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
. " var profile_page = 1; </script>"; . " var profile_page = 1; </script>";
} }
} } elseif ($mode === 'community') {
else if($mode === 'community') {
$profile_owner = 0; $profile_owner = 0;
$page_writeable = false; $page_writeable = false;
if (!$update) { if (!$update) {
$live_update_div = '<div id="live-community"></div>' . "\r\n" $live_update_div = '<div id="live-community"></div>' . "\r\n"
. "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; . "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
} }
} } elseif ($mode === 'search') {
else if($mode === 'search') {
$live_update_div = '<div id="live-search"></div>' . "\r\n"; $live_update_div = '<div id="live-search"></div>' . "\r\n";
} }
$page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false); $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
if($update) if ($update) {
$return_url = $_SESSION['return_url']; $return_url = $_SESSION['return_url'];
else } else {
$return_url = $_SESSION['return_url'] = $a->query_string; $return_url = $_SESSION['return_url'] = $a->query_string;
}
$cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview); $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
call_hooks('conversation_start',$cb); call_hooks('conversation_start',$cb);
@ -598,9 +625,12 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') { if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
// "New Item View" on network page or search page results /*
// - just loop through the items and format them minimally for display * "New Item View" on network page or search page results
* - just loop through the items and format them minimally for display
*/
/// @TODO old lost code?
// $tpl = get_markup_template('search_item.tpl'); // $tpl = get_markup_template('search_item.tpl');
$tpl = 'search_item.tpl'; $tpl = 'search_item.tpl';
@ -614,9 +644,10 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
break; break;
} }
} }
if($blocked) if ($blocked) {
continue; continue;
} }
}
$threadsid++; $threadsid++;
@ -631,19 +662,19 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
&& ($item['id'] != $item['parent'])) && ($item['id'] != $item['parent']))
continue; continue;
$nickname = $item['nickname']; $nickname = $item['nickname'];
} } else {
else
$nickname = $a->user['nickname']; $nickname = $a->user['nickname'];
}
// prevent private email from leaking. // prevent private email from leaking.
if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
continue; continue;
}
$profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']); $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
if($item['author-link'] && (! $item['author-name'])) if ($item['author-link'] && (! $item['author-name'])) {
$profile_name = $item['author-link']; $profile_name = $item['author-link'];
}
$tags = array(); $tags = array();
$hashtags = array(); $hashtags = array();
@ -654,8 +685,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
foreach ($taglist as $tag) { foreach ($taglist as $tag) {
if ($tag["url"] == "") if ($tag["url"] == "") {
$tag["url"] = $searchpath . strtolower($tag["term"]); $tag["url"] = $searchpath . strtolower($tag["term"]);
}
if ($tag["type"] == TERM_HASHTAG) { if ($tag["type"] == TERM_HASHTAG) {
$hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>"; $hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
@ -669,28 +701,33 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$sp = false; $sp = false;
$profile_link = best_link_url($item,$sp); $profile_link = best_link_url($item,$sp);
if($profile_link === 'mailbox') if ($profile_link === 'mailbox') {
$profile_link = ''; $profile_link = '';
if($sp) }
$sparkle = ' sparkle';
else
$profile_link = zrl($profile_link);
if (!isset($item['author-thumb']) OR ($item['author-thumb'] == "")) { if ($sp) {
$sparkle = ' sparkle';
} else {
$profile_link = zrl($profile_link);
}
if (!x($item, 'author-thumb') OR ($item['author-thumb'] == "")) {
$author_contact = get_contact_details_by_url($item['author-link'], $profile_owner); $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
if ($author_contact["thumb"]) if ($author_contact["thumb"]) {
$item['author-thumb'] = $author_contact["thumb"]; $item['author-thumb'] = $author_contact["thumb"];
else } else {
$item['author-thumb'] = $item['author-avatar']; $item['author-thumb'] = $item['author-avatar'];
} }
}
if (!isset($item['owner-thumb']) OR ($item['owner-thumb'] == "")) { if (!isset($item['owner-thumb']) OR ($item['owner-thumb'] == "")) {
$owner_contact = get_contact_details_by_url($item['owner-link'], $profile_owner); $owner_contact = get_contact_details_by_url($item['owner-link'], $profile_owner);
if ($owner_contact["thumb"]) if ($owner_contact["thumb"]) {
$item['owner-thumb'] = $owner_contact["thumb"]; $item['owner-thumb'] = $owner_contact["thumb"];
else } else {
$item['owner-thumb'] = $item['owner-avatar']; $item['owner-thumb'] = $item['owner-avatar'];
} }
}
$locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => ''); $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
call_hooks('render_location',$locate); call_hooks('render_location',$locate);
@ -698,11 +735,11 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate)); $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
localize_item($item); localize_item($item);
if($mode === 'network-new') if ($mode === 'network-new') {
$dropping = true; $dropping = true;
else } else {
$dropping = false; $dropping = false;
}
$drop = array( $drop = array(
'dropping' => $dropping, 'dropping' => $dropping,
@ -720,7 +757,6 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$body = prepare_body($item, true, $preview); $body = prepare_body($item, true, $preview);
list($categories, $folders) = get_cats_and_terms($item); list($categories, $folders) = get_cats_and_terms($item);
if ($a->theme['template_engine'] === 'internal') { if ($a->theme['template_engine'] === 'internal') {
@ -732,8 +768,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$mentions_e = template_escape($mentions); $mentions_e = template_escape($mentions);
$location_e = template_escape($location); $location_e = template_escape($location);
$owner_name_e = template_escape($owner_name); $owner_name_e = template_escape($owner_name);
} } else {
else {
$profile_name_e = $profile_name; $profile_name_e = $profile_name;
$item['title_e'] = $item['title']; $item['title_e'] = $item['title'];
$body_e = $body; $body_e = $body;
@ -744,8 +779,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$owner_name_e = $owner_name; $owner_name_e = $owner_name;
} }
if ($item['item_network'] == "") if ($item['item_network'] == "") {
$item['item_network'] = $item['network']; $item['item_network'] = $item['network'];
}
$tmp_item = array( $tmp_item = array(
'template' => $tpl, 'template' => $tpl,
@ -802,38 +838,35 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$threads[$threadsid]['items'] = array($arr['output']); $threads[$threadsid]['items'] = array($arr['output']);
} }
} } else {
else
{
// Normal View // Normal View
$page_template = get_markup_template("threaded_conversation.tpl"); $page_template = get_markup_template("threaded_conversation.tpl");
require_once('object/Conversation.php'); require_once 'object/Conversation.php';
require_once('object/Item.php'); require_once 'object/Item.php';
$conv = new Conversation($mode, $preview); $conv = new Conversation($mode, $preview);
// get all the topmost parents /*
// this shouldn't be needed, as we should have only them in our array * get all the topmost parents
// But for now, this array respects the old style, just in case * this shouldn't be needed, as we should have only them in our array
* But for now, this array respects the old style, just in case
*/
$threads = array(); $threads = array();
foreach ($items as $item) { foreach ($items as $item) {
if ($arr_blocked) { if ($arr_blocked) {
$blocked = false; $blocked = false;
foreach ($arr_blocked as $b) { foreach ($arr_blocked as $b) {
if ($b && link_compare($item['author-link'], $b)) { if ($b && link_compare($item['author-link'], $b)) {
$blocked = true; $blocked = true;
break; break;
} }
} }
if($blocked) if ($blocked) {
continue; continue;
} }
}
// Can we put this after the visibility check? // Can we put this after the visibility check?
builtin_activity_puller($item, $conv_responses); builtin_activity_puller($item, $conv_responses);
@ -842,6 +875,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
continue; continue;
} }
if (! visible_activity($item)) { if (! visible_activity($item)) {
continue; continue;
} }
@ -889,25 +923,25 @@ function best_link_url($item,&$sparkle,$ssl_state = false) {
if (local_user()) { if (local_user()) {
$r = q("SELECT `id` FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `nurl` = '%s' AND NOT `pending` LIMIT 1", $r = q("SELECT `id` FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `nurl` = '%s' AND NOT `pending` LIMIT 1",
dbesc(NETWORK_DFRN), intval(local_user()), dbesc(normalise_link($clean_url))); dbesc(NETWORK_DFRN), intval(local_user()), dbesc(normalise_link($clean_url)));
if ($r) { if (dbm::is_result($r)) {
$best_url = 'redir/' . $r[0]['id']; $best_url = 'redir/' . $r[0]['id'];
$sparkle = true; $sparkle = true;
} }
} }
if (! $best_url) { if (! $best_url) {
if(strlen($item['author-link'])) if (strlen($item['author-link'])) {
$best_url = $item['author-link']; $best_url = $item['author-link'];
else } else {
$best_url = $item['url']; $best_url = $item['url'];
} }
}
return $best_url; return $best_url;
} }
if (! function_exists('item_photo_menu')) { if (! function_exists('item_photo_menu')) {
function item_photo_menu($item) function item_photo_menu($item) {
{
$ssl_state = false; $ssl_state = false;
if (local_user()) { if (local_user()) {
@ -938,7 +972,7 @@ function item_photo_menu($item)
$rel = 0; $rel = 0;
$r = q("SELECT `id`, `network`, `rel` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1", $r = q("SELECT `id`, `network`, `rel` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1",
intval(local_user()), dbesc(normalise_link($item['author-link']))); intval(local_user()), dbesc(normalise_link($item['author-link'])));
if ($r) { if (dbm::is_result($r)) {
$cid = $r[0]['id']; $cid = $r[0]['id'];
$network = $r[0]['network']; $network = $r[0]['network'];
$rel = $r[0]['rel']; $rel = $r[0]['rel'];
@ -964,7 +998,7 @@ function item_photo_menu($item)
} }
if (local_user()) { if (local_user()) {
$menu = Array( $menu = array(
t('Follow Thread') => $sub_link, t('Follow Thread') => $sub_link,
t('View Status') => $status_link, t('View Status') => $status_link,
t('View Profile') => $profile_link, t('View Profile') => $profile_link,
@ -1004,6 +1038,7 @@ function item_photo_menu($item)
return $o; return $o;
}} }}
if (! function_exists('builtin_activity_puller')) {
/** /**
* @brief Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.) * @brief Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.)
* Increments the count of each matching activity and adds a link to the author as needed. * Increments the count of each matching activity and adds a link to the author as needed.
@ -1012,7 +1047,6 @@ function item_photo_menu($item)
* @param array &$conv_responses (already created with builtin activity structure) * @param array &$conv_responses (already created with builtin activity structure)
* @return void * @return void
*/ */
if(! function_exists('builtin_activity_puller')) {
function builtin_activity_puller($item, &$conv_responses) { function builtin_activity_puller($item, &$conv_responses) {
foreach ($conv_responses as $mode => $v) { foreach ($conv_responses as $mode => $v) {
$url = ''; $url = '';
@ -1044,27 +1078,31 @@ function builtin_activity_puller($item, &$conv_responses) {
if ((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'], $item['url']))) { if ((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'], $item['url']))) {
$url = 'redir/' . $item['contact-id']; $url = 'redir/' . $item['contact-id'];
$sparkle = ' class="sparkle" '; $sparkle = ' class="sparkle" ';
} } else {
else
$url = zrl($url); $url = zrl($url);
}
$url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>'; $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
if(! $item['thr-parent']) if (! $item['thr-parent']) {
$item['thr-parent'] = $item['parent-uri']; $item['thr-parent'] = $item['parent-uri'];
}
if (! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l'])) if (! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l']))
&& (is_array($conv_responses[$mode][$item['thr-parent'] . '-l'])))) && (is_array($conv_responses[$mode][$item['thr-parent'] . '-l'])))) {
$conv_responses[$mode][$item['thr-parent'] . '-l'] = array(); $conv_responses[$mode][$item['thr-parent'] . '-l'] = array();
}
// only list each unique author once // only list each unique author once
if(in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) if (in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) {
continue; continue;
}
if(! isset($conv_responses[$mode][$item['thr-parent']])) if (! isset($conv_responses[$mode][$item['thr-parent']])) {
$conv_responses[$mode][$item['thr-parent']] = 1; $conv_responses[$mode][$item['thr-parent']] = 1;
else } else {
$conv_responses[$mode][$item['thr-parent']] ++; $conv_responses[$mode][$item['thr-parent']] ++;
}
if (public_contact() == $item['author-id']) { if (public_contact() == $item['author-id']) {
$conv_responses[$mode][$item['thr-parent'] . '-self'] = 1; $conv_responses[$mode][$item['thr-parent'] . '-self'] = 1;
@ -1078,15 +1116,16 @@ function builtin_activity_puller($item, &$conv_responses) {
} }
}} }}
// Format the vote text for a profile item
// $cnt = number of people who vote the item
// $arr = array of pre-linked names of likers/dislikers
// $type = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
// $id = item id
// returns formatted text
if (! function_exists('format_like')) { if (! function_exists('format_like')) {
function format_like($cnt,$arr,$type,$id) { /**
* Format the vote text for a profile item
* @param int $cnt = number of people who vote the item
* @param array $arr = array of pre-linked names of likers/dislikers
* @param string $type = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
* @param int $id = item id
* @return formatted text
*/
function format_like($cnt, array $arr, $type, $id) {
$o = ''; $o = '';
$expanded = ''; $expanded = '';
@ -1116,8 +1155,9 @@ function format_like($cnt,$arr,$type,$id) {
if ($cnt > 1) { if ($cnt > 1) {
$total = count($arr); $total = count($arr);
if($total >= MAX_LIKERS) if ($total >= MAX_LIKERS) {
$arr = array_slice($arr, 0, MAX_LIKERS - 1); $arr = array_slice($arr, 0, MAX_LIKERS - 1);
}
if ($total < MAX_LIKERS) { if ($total < MAX_LIKERS) {
$last = t('and') . ' ' . $arr[count($arr)-1]; $last = t('and') . ' ' . $arr[count($arr)-1];
$arr2 = array_slice($arr, 0, -1); $arr2 = array_slice($arr, 0, -1);
@ -1169,11 +1209,10 @@ function format_like($cnt,$arr,$type,$id) {
return $o; return $o;
}} }}
function status_editor(App $a, $x, $notes_cid = 0, $popup = false) {
function status_editor($a,$x, $notes_cid = 0, $popup=false) {
$o = ''; $o = '';
$geotag = (($x['allow_location']) ? replace_macros(get_markup_template('jot_geotag.tpl'), array()) : ''); $geotag = (x($x, 'allow_location') ? replace_macros(get_markup_template('jot_geotag.tpl'), array()) : '');
$tpl = get_markup_template('jot-header.tpl'); $tpl = get_markup_template('jot-header.tpl');
$a->page['htmlhead'] .= replace_macros($tpl, array( $a->page['htmlhead'] .= replace_macros($tpl, array(
@ -1211,22 +1250,25 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
// Private/public post links for the non-JS ACL form // Private/public post links for the non-JS ACL form
$private_post = 1; $private_post = 1;
if($_REQUEST['public']) if (x($_REQUEST, 'public')) {
$private_post = 0; $private_post = 0;
}
$query_str = $a->query_string; $query_str = $a->query_string;
if(strpos($query_str, 'public=1') !== false) if (strpos($query_str, 'public=1') !== false) {
$query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str); $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
}
// I think $a->query_string may never have ? in it, but I could be wrong /*
// It looks like it's from the index.php?q=[etc] rewrite that the web * I think $a->query_string may never have ? in it, but I could be wrong
// server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61 * It looks like it's from the index.php?q=[etc] rewrite that the web
if(strpos($query_str, '?') === false) * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
*/
if (strpos($query_str, '?') === false) {
$public_post_link = '?public=1'; $public_post_link = '?public=1';
else } else {
$public_post_link = '&public=1'; $public_post_link = '&public=1';
}
// $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins)); // $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
$tpl = get_markup_template("jot.tpl"); $tpl = get_markup_template("jot.tpl");
@ -1292,7 +1334,6 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
if ($popup == true) { if ($popup == true) {
$o = '<div id="jot-popup" style="display: none;">'.$o.'</div>'; $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
} }
return $o; return $o;
@ -1307,15 +1348,15 @@ function get_item_children($arr, $parent) {
if (get_config('system', 'thread_allow') && $a->theme_thread_allow) { if (get_config('system', 'thread_allow') && $a->theme_thread_allow) {
// Fallback to parent-uri if thr-parent is not set // Fallback to parent-uri if thr-parent is not set
$thr_parent = $item['thr-parent']; $thr_parent = $item['thr-parent'];
if($thr_parent == '') if ($thr_parent == '') {
$thr_parent = $item['parent-uri']; $thr_parent = $item['parent-uri'];
}
if ($thr_parent == $parent['uri']) { if ($thr_parent == $parent['uri']) {
$item['children'] = get_item_children($arr, $item); $item['children'] = get_item_children($arr, $item);
$children[] = $item; $children[] = $item;
} }
} } elseif ($item['parent'] == $parent['id']) {
else if($item['parent'] == $parent['id']) {
$children[] = $item; $children[] = $item;
} }
} }
@ -1323,6 +1364,7 @@ function get_item_children($arr, $parent) {
return $children; return $children;
} }
/// @TODO Add type-hint
function sort_item_children($items) { function sort_item_children($items) {
$result = $items; $result = $items;
usort($result, 'sort_thr_created_rev'); usort($result, 'sort_thr_created_rev');
@ -1334,44 +1376,58 @@ function sort_item_children($items) {
return $result; return $result;
} }
/// @TODO Add type-hint
function add_children_to_list($children, &$arr) { function add_children_to_list($children, &$arr) {
foreach ($children as $y) { foreach ($children as $y) {
$arr[] = $y; $arr[] = $y;
if(count($y['children'])) if (count($y['children'])) {
add_children_to_list($y['children'], $arr); add_children_to_list($y['children'], $arr);
} }
} }
}
/// @TODO Add type-hint
function conv_sort($arr, $order) { function conv_sort($arr, $order) {
if((!(is_array($arr) && count($arr)))) if ((!(is_array($arr) && count($arr)))) {
return array(); return array();
}
$parents = array(); $parents = array();
$children = array(); $children = array();
$newarr = array(); $newarr = array();
// This is a preparation for having two different items with the same uri in one thread /*
// This will otherwise lead to an endless loop. * This is a preparation for having two different items with the same uri in one thread
foreach($arr as $x) * This will otherwise lead to an endless loop.
if (!isset($newarr[$x['uri']])) */
foreach ($arr as $x) {
if (!isset($newarr[$x['uri']])) {
$newarr[$x['uri']] = $x; $newarr[$x['uri']] = $x;
}
}
$arr = $newarr; $arr = $newarr;
foreach($arr as $x) foreach ($arr as $x) {
if($x['id'] == $x['parent']) if ($x['id'] == $x['parent']) {
$parents[] = $x; $parents[] = $x;
}
}
if(stristr($order,'created')) if (stristr($order, 'created')) {
usort($parents, 'sort_thr_created'); usort($parents, 'sort_thr_created');
elseif(stristr($order,'commented')) } elseif (stristr($order, 'commented')) {
usort($parents, 'sort_thr_commented'); usort($parents, 'sort_thr_commented');
}
if(count($parents)) if (count($parents)) {
foreach($parents as $i=>$_x) foreach ($parents as $i => $_x) {
$parents[$i]['children'] = get_item_children($arr, $_x); $parents[$i]['children'] = get_item_children($arr, $_x);
}
}
/// @TODO Old-lost code?
/*foreach ($arr as $x) { /*foreach ($arr as $x) {
if ($x['id'] != $x['parent']) { if ($x['id'] != $x['parent']) {
$p = find_thread_parent_index($parents,$x); $p = find_thread_parent_index($parents,$x);
@ -1383,6 +1439,7 @@ function conv_sort($arr,$order) {
foreach ($parents as $k => $v) { foreach ($parents as $k => $v) {
if (count($parents[$k]['children'])) { if (count($parents[$k]['children'])) {
$parents[$k]['children'] = sort_item_children($parents[$k]['children']); $parents[$k]['children'] = sort_item_children($parents[$k]['children']);
/// @TODO Old-lost code?
/*$y = $parents[$k]['children']; /*$y = $parents[$k]['children'];
usort($y,'sort_thr_created_rev'); usort($y,'sort_thr_created_rev');
$parents[$k]['children'] = $y;*/ $parents[$k]['children'] = $y;*/
@ -1394,44 +1451,55 @@ function conv_sort($arr,$order) {
if (count($parents)) { if (count($parents)) {
foreach ($parents as $x) { foreach ($parents as $x) {
$ret[] = $x; $ret[] = $x;
if(count($x['children'])) if (count($x['children'])) {
add_children_to_list($x['children'], $ret); add_children_to_list($x['children'], $ret);
/// @TODO Old-lost code?
/*foreach ($x['children'] as $y) /*foreach ($x['children'] as $y)
$ret[] = $y;*/ $ret[] = $y;*/
} }
} }
}
return $ret; return $ret;
} }
/// @TODO Add type-hint
function sort_thr_created($a, $b) { function sort_thr_created($a, $b) {
return strcmp($b['created'], $a['created']); return strcmp($b['created'], $a['created']);
} }
/// @TODO Add type-hint
function sort_thr_created_rev($a, $b) { function sort_thr_created_rev($a, $b) {
return strcmp($a['created'], $b['created']); return strcmp($a['created'], $b['created']);
} }
/// @TODO Add type-hint
function sort_thr_commented($a, $b) { function sort_thr_commented($a, $b) {
return strcmp($b['commented'], $a['commented']); return strcmp($b['commented'], $a['commented']);
} }
/// @TODO Add type-hint
function find_thread_parent_index($arr, $x) { function find_thread_parent_index($arr, $x) {
foreach($arr as $k => $v) foreach ($arr as $k => $v) {
if($v['id'] == $x['parent']) if ($v['id'] == $x['parent']) {
return $k; return $k;
}
}
return false; return false;
} }
/// @TODO Add type-hint
function render_location_dummy($item) { function render_location_dummy($item) {
if ($item['location'] != "") if ($item['location'] != "") {
return $item['location']; return $item['location'];
if ($item['coord'] != "")
return $item['coord'];
} }
if ($item['coord'] != "") {
return $item['coord'];
}
}
/// @TODO Add type-hint
function get_responses($conv_responses, $response_verbs, $ob, $item) { function get_responses($conv_responses, $response_verbs, $ob, $item) {
$ret = array(); $ret = array();
foreach ($response_verbs as $v) { foreach ($response_verbs as $v) {
@ -1443,8 +1511,7 @@ function get_responses($conv_responses,$response_verbs,$ob,$item) {
$ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS); $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);
array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-' array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-'
. (($ob) ? $ob->get_id() : $item['id']) . '"><b>' . t('View all') . '</b></a>'); . (($ob) ? $ob->get_id() : $item['id']) . '"><b>' . t('View all') . '</b></a>');
} } else {
else {
$ret[$v]['list_part'] = ''; $ret[$v]['list_part'] = '';
} }
$ret[$v]['button'] = get_response_button_text($v, $ret[$v]['count']); $ret[$v]['button'] = get_response_button_text($v, $ret[$v]['count']);
@ -1453,9 +1520,10 @@ function get_responses($conv_responses,$response_verbs,$ob,$item) {
$count = 0; $count = 0;
foreach ($ret as $key) { foreach ($ret as $key) {
if ($key['count'] == true) if ($key['count'] == true) {
$count++; $count++;
} }
}
$ret['count'] = $count; $ret['count'] = $count;
return $ret; return $ret;

View file

@ -4,7 +4,7 @@ use \Friendica\Core\Config;
function cron_run(&$argv, &$argc){ function cron_run(&$argv, &$argc){
global $a; global $a;
require_once('include/datetime.php'); require_once 'include/datetime.php';
// Poll contacts with specific parameters // Poll contacts with specific parameters
if ($argc > 1) { if ($argc > 1) {
@ -18,6 +18,7 @@ function cron_run(&$argv, &$argc){
if (! $poll_interval) { if (! $poll_interval) {
$poll_interval = 10; $poll_interval = 10;
} }
if ($last) { if ($last) {
$next = $last + ($poll_interval * 60); $next = $last + ($poll_interval * 60);
if ($next > time()) { if ($next > time()) {
@ -156,7 +157,7 @@ function cron_poll_contacts($argc, $argv) {
dbesc(NETWORK_MAIL2) dbesc(NETWORK_MAIL2)
); );
if (!count($contacts)) { if (!dbm::is_result($contacts)) {
return; return;
} }
@ -183,25 +184,24 @@ function cron_poll_contacts($argc, $argv) {
} }
if ($contact['subhub'] AND in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) { if ($contact['subhub'] AND in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) {
// We should be getting everything via a hub. But just to be sure, let's check once a day. /*
// (You can make this more or less frequent if desired by setting 'pushpoll_frequency' appropriately) * We should be getting everything via a hub. But just to be sure, let's check once a day.
// This also lets us update our subscription to the hub, and add or replace hubs in case it * (You can make this more or less frequent if desired by setting 'pushpoll_frequency' appropriately)
// changed. We will only update hubs once a day, regardless of 'pushpoll_frequency'. * This also lets us update our subscription to the hub, and add or replace hubs in case it
* changed. We will only update hubs once a day, regardless of 'pushpoll_frequency'.
*/
$poll_interval = get_config('system', 'pushpoll_frequency'); $poll_interval = get_config('system', 'pushpoll_frequency');
$contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3); $contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3);
} }
if ($contact['priority'] AND !$force) { if ($contact['priority'] AND !$force) {
$update = false; $update = false;
$t = $contact['last-update']; $t = $contact['last-update'];
/** /*
* Based on $contact['priority'], should we poll this site now? Or later? * Based on $contact['priority'], should we poll this site now? Or later?
*/ */
switch ($contact['priority']) { switch ($contact['priority']) {
case 5: case 5:
if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 month")) { if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 month")) {

View file

@ -5,22 +5,24 @@ use \Friendica\Core\Config;
function cronhooks_run(&$argv, &$argc) { function cronhooks_run(&$argv, &$argc) {
global $a; global $a;
require_once('include/datetime.php'); require_once 'include/datetime.php';
if (($argc == 2) AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) { if (($argc == 2) AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
foreach ($a->hooks["cron"] as $hook) foreach ($a->hooks["cron"] as $hook) {
if ($hook[1] == $argv[1]) { if ($hook[1] == $argv[1]) {
logger("Calling cron hook '" . $hook[1] . "'", LOGGER_DEBUG); logger("Calling cron hook '" . $hook[1] . "'", LOGGER_DEBUG);
call_single_hook($a, $name, $hook, $data); call_single_hook($a, $name, $hook, $data);
} }
}
return; return;
} }
$last = get_config('system', 'last_cronhook'); $last = get_config('system', 'last_cronhook');
$poll_interval = intval(get_config('system', 'cronhook_interval')); $poll_interval = intval(get_config('system', 'cronhook_interval'));
if(! $poll_interval) if (! $poll_interval) {
$poll_interval = 9; $poll_interval = 9;
}
if ($last) { if ($last) {
$next = $last + ($poll_interval * 60); $next = $last + ($poll_interval * 60);

View file

@ -554,8 +554,9 @@ class dfrn {
xml::add_element($doc, $author, "poco:displayName", $profile["name"]); xml::add_element($doc, $author, "poco:displayName", $profile["name"]);
xml::add_element($doc, $author, "poco:updated", $namdate); xml::add_element($doc, $author, "poco:updated", $namdate);
if (trim($profile["dob"]) > '0001-01-01') if (trim($profile["dob"]) > '0001-01-01') {
xml::add_element($doc, $author, "poco:birthday", "0000-".date("m-d", strtotime($profile["dob"]))); xml::add_element($doc, $author, "poco:birthday", "0000-".date("m-d", strtotime($profile["dob"])));
}
xml::add_element($doc, $author, "poco:note", $profile["about"]); xml::add_element($doc, $author, "poco:note", $profile["about"]);
xml::add_element($doc, $author, "poco:preferredUsername", $profile["nickname"]); xml::add_element($doc, $author, "poco:preferredUsername", $profile["nickname"]);

File diff suppressed because it is too large Load diff