Browse Source

Revert "Coding convention applied - part 1"

tags/3.5.2
Hypolite Petovan 3 years ago
committed by GitHub
parent
commit
7b352f3f74
100 changed files with 2192 additions and 2803 deletions
  1. +193
    -266
      boot.php
  2. +12
    -14
      include/Contact.php
  3. +1
    -1
      include/Core/PConfig.php
  4. +3
    -4
      include/DirSearch.php
  5. +8
    -12
      include/ForumManager.php
  6. +17
    -17
      include/NotificationsManager.php
  7. +16
    -21
      include/Probe.php
  8. +5
    -7
      include/Smilies.php
  9. +28
    -29
      include/acl_selectors.php
  10. +38
    -38
      include/api.php
  11. +1
    -1
      include/attach.php
  12. +4
    -4
      include/bb2diaspora.php
  13. +29
    -33
      include/bbcode.php
  14. +1
    -1
      include/cli_startup.php
  15. +2
    -2
      include/contact_selectors.php
  16. +22
    -27
      include/contact_widgets.php
  17. +129
    -138
      include/conversation.php
  18. +25
    -36
      include/cron.php
  19. +4
    -6
      include/cronhooks.php
  20. +8
    -8
      include/crypto.php
  21. +43
    -51
      include/datetime.php
  22. +37
    -37
      include/dba_pdo.php
  23. +4
    -4
      include/dbstructure.php
  24. +255
    -454
      include/dfrn.php
  25. +41
    -44
      include/diaspora.php
  26. +3
    -5
      include/discover_poco.php
  27. +15
    -15
      include/email.php
  28. +2
    -4
      include/enotify.php
  29. +16
    -16
      include/event.php
  30. +3
    -4
      include/expire.php
  31. +9
    -9
      include/features.php
  32. +3
    -4
      include/feed.php
  33. +1
    -1
      include/files.php
  34. +6
    -6
      include/friendica_smarty.php
  35. +22
    -23
      include/group.php
  36. +1
    -1
      include/html2plain.php
  37. +50
    -55
      include/identity.php
  38. +16
    -16
      include/items.php
  39. +12
    -13
      include/lock.php
  40. +7
    -7
      include/message.php
  41. +1
    -1
      include/msgclean.php
  42. +2
    -2
      include/nav.php
  43. +47
    -48
      include/network.php
  44. +1
    -1
      include/oauth.php
  45. +2
    -4
      include/oembed.php
  46. +4
    -6
      include/onepoll.php
  47. +162
    -312
      include/ostatus.php
  48. +17
    -17
      include/pgettext.php
  49. +37
    -42
      include/plugin.php
  50. +6
    -7
      include/poller.php
  51. +2
    -2
      include/post_update.php
  52. +6
    -6
      include/profile_selectors.php
  53. +4
    -8
      include/pubsubpublish.php
  54. +5
    -6
      include/queue_fn.php
  55. +3
    -3
      include/quoteconvert.php
  56. +7
    -7
      include/redir.php
  57. +11
    -13
      include/salmon.php
  58. +24
    -29
      include/security.php
  59. +38
    -40
      include/socgraph.php
  60. +8
    -9
      include/tags.php
  61. +9
    -15
      include/template_processor.php
  62. +140
    -141
      include/text.php
  63. +8
    -16
      include/threads.php
  64. +8
    -14
      include/update_gcontact.php
  65. +24
    -24
      include/user.php
  66. +2
    -2
      include/xml.php
  67. +41
    -46
      index.php
  68. +1
    -1
      mod/_well_known.php
  69. +2
    -2
      mod/acctlink.php
  70. +8
    -9
      mod/admin.php
  71. +1
    -2
      mod/allfriends.php
  72. +1
    -1
      mod/api.php
  73. +12
    -10
      mod/apps.php
  74. +2
    -2
      mod/attach.php
  75. +2
    -2
      mod/babel.php
  76. +28
    -31
      mod/cal.php
  77. +5
    -6
      mod/common.php
  78. +6
    -7
      mod/community.php
  79. +9
    -10
      mod/contactgroup.php
  80. +75
    -104
      mod/contacts.php
  81. +77
    -78
      mod/content.php
  82. +9
    -13
      mod/crepair.php
  83. +16
    -25
      mod/delegate.php
  84. +53
    -54
      mod/dfrn_confirm.php
  85. +22
    -24
      mod/dfrn_notify.php
  86. +38
    -38
      mod/dfrn_poll.php
  87. +30
    -30
      mod/dfrn_request.php
  88. +17
    -18
      mod/directory.php
  89. +1
    -2
      mod/dirfind.php
  90. +4
    -4
      mod/editpost.php
  91. +4
    -6
      mod/events.php
  92. +3
    -2
      mod/fbrowser.php
  93. +1
    -1
      mod/filer.php
  94. +12
    -14
      mod/friendica.php
  95. +2
    -3
      mod/fsuggest.php
  96. +23
    -25
      mod/group.php
  97. +7
    -14
      mod/help.php
  98. +2
    -2
      mod/home.php
  99. +1
    -1
      mod/hostxrd.php
  100. +7
    -7
      mod/hovercard.php

+ 193
- 266
boot.php
File diff suppressed because it is too large
View File


+ 12
- 14
include/Contact.php View File

@@ -5,7 +5,7 @@
// authorisation to do this.

function user_remove($uid) {
if (! $uid)
if(! $uid)
return;
logger('Removing user: ' . $uid);

@@ -49,7 +49,7 @@ function user_remove($uid) {
// Send an update to the directory
proc_run(PRIORITY_LOW, "include/directory.php", $r[0]['url']);

if ($uid == local_user()) {
if($uid == local_user()) {
unset($_SESSION['authenticated']);
unset($_SESSION['uid']);
goaway(App::get_baseurl());
@@ -122,13 +122,11 @@ function terminate_friendship($user,$self,$contact) {
// This provides for the possibility that their database is temporarily messed
// up or some other transient event and that there's a possibility we could recover from it.

function mark_for_death(array $contact) {
function mark_for_death($contact) {

if ($contact['archive']) {
if($contact['archive'])
return;
}

/// @TODO Comparison of strings this way may lead to bugs/incompatibility, better switch to DateTime
if ($contact['term-date'] <= NULL_DATE) {
q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d",
dbesc(datetime_convert()),
@@ -153,7 +151,7 @@ function mark_for_death(array $contact) {
/// Check for contact vitality via probing

$expiry = $contact['term-date'] . ' + 32 days ';
if (datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
if(datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {

// relationship is really truly dead.
// archive them rather than delete
@@ -485,7 +483,7 @@ function random_profile() {

function contacts_not_grouped($uid,$start = 0,$count = 0) {

if (! $count) {
if(! $count) {
$r = q("select count(*) as total from contact where uid = %d and self = 0 and id not in (select distinct(`contact-id`) from group_member where uid = %d) ",
intval($uid),
intval($uid)
@@ -777,18 +775,18 @@ function posts_from_contact_url(App $a, $contact_url) {
function formatted_location($profile) {
$location = '';

if ($profile['locality'])
if($profile['locality'])
$location .= $profile['locality'];

if ($profile['region'] AND ($profile['locality'] != $profile['region'])) {
if ($location)
if($profile['region'] AND ($profile['locality'] != $profile['region'])) {
if($location)
$location .= ', ';

$location .= $profile['region'];
}

if ($profile['country-name']) {
if ($location)
if($profile['country-name']) {
if($location)
$location .= ', ';

$location .= $profile['country-name'];
@@ -810,7 +808,7 @@ function account_type($contact) {
// "page-flags" is a field in the user table,
// "forum" and "prv" are used in the contact table. They stand for PAGE_COMMUNITY and PAGE_PRVGROUP.
// "community" is used in the gcontact table and is true if the contact is PAGE_COMMUNITY or PAGE_PRVGROUP.
if ((isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_COMMUNITY))
if((isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_COMMUNITY))
|| (isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_PRVGROUP))
|| (isset($contact['forum']) && intval($contact['forum']))
|| (isset($contact['prv']) && intval($contact['prv']))


+ 1
- 1
include/Core/PConfig.php View File

@@ -44,7 +44,7 @@ class PConfig {
$a->config[$uid][$family][$k] = $rr['v'];
self::$in_db[$uid][$family][$k] = true;
}
} elseif ($family != 'config') {
} else if ($family != 'config') {
// Negative caching
$a->config[$uid][$family] = "!<unset>!";
}


+ 3
- 4
include/DirSearch.php View File

@@ -20,7 +20,7 @@ class DirSearch {
*/
public static function global_search_by_name($search, $mode = '') {

if ($search) {
if($search) {
// check supported networks
if (get_config('system','diaspora_enabled'))
$diaspora = NETWORK_DIASPORA;
@@ -33,11 +33,10 @@ class DirSearch {
$ostatus = NETWORK_DFRN;

// check if we search only communities or every contact
if ($mode === "community") {
if($mode === "community")
$extra_sql = " AND `community`";
} else {
else
$extra_sql = "";
}

$search .= "%";



+ 8
- 12
include/ForumManager.php View File

@@ -50,7 +50,7 @@ class ForumManager {
if (!$contacts)
return($forumlist);

foreach ($contacts as $contact) {
foreach($contacts as $contact) {
$forumlist[] = array(
'url' => $contact['url'],
'name' => $contact['name'],
@@ -76,7 +76,7 @@ class ForumManager {
*/
public static function widget($uid,$cid = 0) {

if (! intval(feature_enabled(local_user(),'forumlist_widget')))
if(! intval(feature_enabled(local_user(),'forumlist_widget')))
return;

$o = '';
@@ -92,7 +92,7 @@ class ForumManager {

$id = 0;

foreach ($contacts as $contact) {
foreach($contacts as $contact) {

$selected = (($cid == $contact['id']) ? ' forum-selected' : '');

@@ -136,7 +136,7 @@ class ForumManager {
public static function profile_advanced($uid) {

$profile = intval(feature_enabled($uid,'forumlist_profile'));
if (! $profile)
if(! $profile)
return;

$o = '';
@@ -151,20 +151,16 @@ class ForumManager {

$total_shown = 0;

foreach ($contacts as $contact) {
foreach($contacts as $contact) {
$forumlist .= micropro($contact,false,'forumlist-profile-advanced');
$total_shown ++;

if ($total_shown == $show_total) {
if($total_shown == $show_total)
break;
}
}

if (count($contacts) > 0) {
if(count($contacts) > 0)
$o .= $forumlist;
}

return $o;
return $o;
}

/**


+ 17
- 17
include/NotificationsManager.php View File

@@ -33,7 +33,7 @@ class NotificationsManager {
*/
private function _set_extra($notes) {
$rets = array();
foreach ($notes as $n) {
foreach($notes as $n) {
$local_time = datetime_convert('UTC',date_default_timezone_get(),$n['date']);
$n['timestamp'] = strtotime($local_time);
$n['date_rel'] = relative_date($n['date']);
@@ -58,7 +58,7 @@ class NotificationsManager {
public function getAll($filter = array(), $order="-date", $limit="") {
$filter_str = array();
$filter_sql = "";
foreach ($filter as $column => $value) {
foreach($filter as $column => $value) {
$filter_str[] = sprintf("`%s` = '%s'", $column, dbesc($value));
}
if (count($filter_str)>0) {
@@ -67,7 +67,7 @@ class NotificationsManager {

$aOrder = explode(" ", $order);
$asOrder = array();
foreach ($aOrder as $o) {
foreach($aOrder as $o) {
$dir = "asc";
if ($o[0]==="-") {
$dir = "desc";
@@ -81,7 +81,7 @@ class NotificationsManager {
}
$order_sql = implode(", ", $asOrder);

if ($limit!="")
if($limit!="")
$limit = " LIMIT ".$limit;

$r = q("SELECT * FROM `notify` WHERE `uid` = %d $filter_sql ORDER BY $order_sql $limit",
@@ -369,7 +369,7 @@ class NotificationsManager {
private function networkTotal($seen = 0) {
$sql_seen = "";

if ($seen === 0)
if($seen === 0)
$sql_seen = " AND `item`.`unseen` = 1 ";

$r = q("SELECT COUNT(*) AS `total`
@@ -406,7 +406,7 @@ class NotificationsManager {
$notifs = array();
$sql_seen = "";

if ($seen === 0)
if($seen === 0)
$sql_seen = " AND `item`.`unseen` = 1 ";


@@ -445,7 +445,7 @@ class NotificationsManager {
private function systemTotal($seen = 0) {
$sql_seen = "";

if ($seen === 0)
if($seen === 0)
$sql_seen = " AND `seen` = 0 ";

$r = q("SELECT COUNT(*) AS `total` FROM `notify` WHERE `uid` = %d $sql_seen",
@@ -478,7 +478,7 @@ class NotificationsManager {
$notifs = array();
$sql_seen = "";

if ($seen === 0)
if($seen === 0)
$sql_seen = " AND `seen` = 0 ";

$r = q("SELECT `id`, `url`, `photo`, `msg`, `date`, `seen` FROM `notify`
@@ -530,7 +530,7 @@ class NotificationsManager {
$sql_seen = "";
$sql_extra = $this->_personal_sql_extra();

if ($seen === 0)
if($seen === 0)
$sql_seen = " AND `item`.`unseen` = 1 ";

$r = q("SELECT COUNT(*) AS `total`
@@ -569,7 +569,7 @@ class NotificationsManager {
$notifs = array();
$sql_seen = "";

if ($seen === 0)
if($seen === 0)
$sql_seen = " AND `item`.`unseen` = 1 ";

$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
@@ -608,7 +608,7 @@ class NotificationsManager {
private function homeTotal($seen = 0) {
$sql_seen = "";

if ($seen === 0)
if($seen === 0)
$sql_seen = " AND `item`.`unseen` = 1 ";

$r = q("SELECT COUNT(*) AS `total` FROM `item`
@@ -644,7 +644,7 @@ class NotificationsManager {
$notifs = array();
$sql_seen = "";

if ($seen === 0)
if($seen === 0)
$sql_seen = " AND `item`.`unseen` = 1 ";

$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
@@ -682,7 +682,7 @@ class NotificationsManager {
private function introTotal($all = false) {
$sql_extra = "";

if (!$all)
if(!$all)
$sql_extra = " AND `ignore` = 0 ";

$r = q("SELECT COUNT(*) AS `total` FROM `intro`
@@ -716,7 +716,7 @@ class NotificationsManager {
$notifs = array();
$sql_extra = "";

if (!$all)
if(!$all)
$sql_extra = " AND `ignore` = 0 ";

/// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact
@@ -756,12 +756,12 @@ class NotificationsManager {
private function formatIntros($intros) {
$knowyou = '';

foreach ($intros as $it) {
foreach($intros as $it) {
// There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
// We have to distinguish between these two because they use different data.

// Contact suggestions
if ($it['fid']) {
if($it['fid']) {

$return_addr = bin2hex($this->a->user['nickname'] . '@' . $this->a->get_hostname() . (($this->a->path) ? '/' . $this->a->path : ''));

@@ -793,7 +793,7 @@ class NotificationsManager {
$it['gnetwork'] = $ret["network"];

// Don't show these data until you are connected. Diaspora is doing the same.
if ($it['gnetwork'] === NETWORK_DIASPORA) {
if($it['gnetwork'] === NETWORK_DIASPORA) {
$it['glocation'] = "";
$it['gabout'] = "";
$it['ggender'] = "";


+ 16
- 21
include/Probe.php View File

@@ -564,15 +564,15 @@ class Probe {
*/
public static function valid_dfrn($data) {
$errors = 0;
if (!isset($data['key']))
if(!isset($data['key']))
$errors ++;
if (!isset($data['dfrn-request']))
if(!isset($data['dfrn-request']))
$errors ++;
if (!isset($data['dfrn-confirm']))
if(!isset($data['dfrn-confirm']))
$errors ++;
if (!isset($data['dfrn-notify']))
if(!isset($data['dfrn-notify']))
$errors ++;
if (!isset($data['dfrn-poll']))
if(!isset($data['dfrn-poll']))
$errors ++;
return $errors;
}
@@ -858,7 +858,7 @@ class Probe {

$data = array();
if (is_array($webfinger["aliases"]))
foreach ($webfinger["aliases"] AS $alias)
foreach($webfinger["aliases"] AS $alias)
if (strstr($alias, "@"))
$data["addr"] = str_replace('acct:', '', $alias);

@@ -1133,17 +1133,15 @@ class Probe {
$password = '';
openssl_private_decrypt(hex2bin($r[0]['pass']), $password,$x[0]['prvkey']);
$mbox = email_connect($mailbox,$r[0]['user'], $password);
if (!$mbox) {
if(!mbox)
return false;
}
}

$msgs = email_poll($mbox, $uri);
logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);

if (!count($msgs)) {
if (!count($msgs))
return false;
}

$data = array();

@@ -1159,26 +1157,23 @@ class Probe {
$data["poll"] = 'email '.random_string();

$x = email_msg_meta($mbox, $msgs[0]);
if (stristr($x[0]->from, $uri)) {
if(stristr($x[0]->from, $uri))
$adr = imap_rfc822_parse_adrlist($x[0]->from, '');
} elseif (stristr($x[0]->to, $uri)) {
elseif(stristr($x[0]->to, $uri))
$adr = imap_rfc822_parse_adrlist($x[0]->to, '');
}
if (isset($adr)) {
foreach ($adr as $feadr) {
if ((strcasecmp($feadr->mailbox, $data["name"]) == 0)
if(isset($adr)) {
foreach($adr as $feadr) {
if((strcasecmp($feadr->mailbox, $data["name"]) == 0)
&&(strcasecmp($feadr->host, $phost) == 0)
&& (strlen($feadr->personal))) {

$personal = imap_mime_header_decode($feadr->personal);
$data["name"] = "";
foreach ($personal as $perspart) {
if ($perspart->charset != "default") {
foreach($personal as $perspart)
if ($perspart->charset != "default")
$data["name"] .= iconv($perspart->charset, 'UTF-8//IGNORE', $perspart->text);
} else {
else
$data["name"] .= $perspart->text;
}
}

$data["name"] = notags($data["name"]);
}


+ 5
- 7
include/Smilies.php View File

@@ -125,7 +125,7 @@ class Smilies {
* @return string HML Output of the Smilie
*/
public static function replace($s, $sample = false) {
if (intval(get_config('system','no_smilies'))
if(intval(get_config('system','no_smilies'))
|| (local_user() && intval(get_pconfig(local_user(),'system','no_smilies'))))
return $s;

@@ -135,9 +135,9 @@ class Smilies {
$params = self::get_list();
$params['string'] = $s;

if ($sample) {
if($sample) {
$s = '<div class="smiley-sample">';
for ($x = 0; $x < count($params['texts']); $x ++) {
for($x = 0; $x < count($params['texts']); $x ++) {
$s .= '<dl><dt>' . $params['texts'][$x] . '</dt><dd>' . $params['icons'][$x] . '</dd></dl>';
}
}
@@ -170,13 +170,11 @@ class Smilies {
* @todo: Rework because it doesn't work correctly
*/
private function preg_heart($x) {
if (strlen($x[1]) == 1) {
if(strlen($x[1]) == 1)
return $x[0];
}
$t = '';
for ($cnt = 0; $cnt < strlen($x[1]); $cnt ++) {
for($cnt = 0; $cnt < strlen($x[1]); $cnt ++)
$t .= '<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-heart.gif" alt="&lt;3" />';
}
$r = str_replace($x[0],$t,$x[0]);
return $r;
}


+ 28
- 29
include/acl_selectors.php View File

@@ -35,7 +35,7 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {

if (dbm::is_result($r)) {
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\" ";
else
$selected = '';
@@ -88,13 +88,13 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {
$networks = array(NETWORK_DFRN);
break;
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);
else
$networks = array(NETWORK_DFRN,NETWORK_FACEBOOK,NETWORK_MAIL, NETWORK_DIASPORA);
break;
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);
else
$networks = array(NETWORK_DFRN,NETWORK_FACEBOOK,NETWORK_MAIL,NETWORK_DIASPORA,NETWORK_OSTATUS);
@@ -113,24 +113,23 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {

$sql_extra = '';

if ($x['mutual']) {
if($x['mutual']) {
$sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
}

if (intval($x['exclude']))
if(intval($x['exclude']))
$sql_extra .= sprintf(" AND `id` != %d ", intval($x['exclude']));

if (is_array($x['networks']) && count($x['networks'])) {
for ($y = 0; $y < count($x['networks']) ; $y ++) {
if(is_array($x['networks']) && count($x['networks'])) {
for($y = 0; $y < count($x['networks']) ; $y ++)
$x['networks'][$y] = "'" . dbesc($x['networks'][$y]) . "'";
}
$str_nets = implode(',',$x['networks']);
$sql_extra .= " AND `network` IN ( $str_nets ) ";
}

$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";
else
$o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"" . $x['size'] . "$\" $tabindex >\r\n";
@@ -186,14 +185,14 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p

$sql_extra = '';

if ($privmail || $celeb) {
if($privmail || $celeb) {
$sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
}

if ($privmail)
if($privmail)
$sql_extra .= sprintf(" AND `network` IN ('%s' , '%s') ",
NETWORK_DFRN, NETWORK_DIASPORA);
elseif ($privatenet)
elseif($privatenet)
$sql_extra .= sprintf(" AND `network` IN ('%s' , '%s', '%s', '%s') ",
NETWORK_DFRN, NETWORK_MAIL, NETWORK_FACEBOOK, NETWORK_DIASPORA);

@@ -205,7 +204,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
} else
$hidepreselected = "";

if ($privmail)
if($privmail)
$o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\" $tabindex $hidepreselected>\r\n";
else
$o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" $tabindex >\r\n";
@@ -288,7 +287,7 @@ function prune_deadguys($arr) {
function get_acl_permissions($user = null) {
$allow_cid = $allow_gid = $deny_cid = $deny_gid = false;

if (is_array($user)) {
if(is_array($user)) {
$allow_cid = ((strlen($user['allow_cid']))
? explode('><', $user['allow_cid']) : array() );
$allow_gid = ((strlen($user['allow_gid']))
@@ -319,25 +318,25 @@ function populate_acl($user = null, $show_jotnets = false) {
$perms = get_acl_permissions($user);

$jotnets = '';
if ($show_jotnets) {
if($show_jotnets) {
$mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);

$mail_enabled = false;
$pubmail_enabled = false;

if (! $mail_disabled) {
if(! $mail_disabled) {
$r = q("SELECT `pubmail` FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
intval(local_user())
);
if (dbm::is_result($r)) {
$mail_enabled = true;
if (intval($r[0]['pubmail']))
if(intval($r[0]['pubmail']))
$pubmail_enabled = true;
}
}

if (!$user['hidewall']) {
if ($mail_enabled) {
if($mail_enabled) {
$selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
$jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
}
@@ -380,20 +379,20 @@ function construct_acl_data(App $a, $user) {

$user_defaults = get_acl_permissions($user);

if ($acl_data['groups']) {
foreach ($acl_data['groups'] as $key=>$group) {
if($acl_data['groups']) {
foreach($acl_data['groups'] as $key=>$group) {
// 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']) )
$acl_data['groups'][$key]['selected'] = 1;
else
$acl_data['groups'][$key]['selected'] = 0;
}
}
if ($acl_data['contacts']) {
foreach ($acl_data['contacts'] as $key=>$contact) {
if($acl_data['contacts']) {
foreach($acl_data['contacts'] as $key=>$contact) {
// 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']) )
$acl_data['contacts'][$key]['selected'] = 1;
else
@@ -420,8 +419,8 @@ function acl_lookup(App $a, $out_type = 'json') {

// For use with jquery.textcomplete for private mail completion

if (x($_REQUEST,'query') && strlen($_REQUEST['query'])) {
if (! $type)
if(x($_REQUEST,'query') && strlen($_REQUEST['query'])) {
if(! $type)
$type = 'm';
$search = $_REQUEST['query'];
}
@@ -511,7 +510,7 @@ function acl_lookup(App $a, $out_type = 'json') {
intval($count)
);

foreach ($r as $g){
foreach($r as $g){
// logger('acl: group: ' . $g['name'] . ' members: ' . $g['uids']);
$groups[] = array(
"type" => "g",
@@ -547,7 +546,7 @@ function acl_lookup(App $a, $out_type = 'json') {
dbesc(NETWORK_STATUSNET)
);
}
elseif ($type == 'm') {
elseif($type == 'm') {
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive`
AND `network` IN ('%s','%s','%s')
@@ -666,7 +665,7 @@ function acl_lookup(App $a, $out_type = 'json') {

call_hooks('acl_lookup_end', $results);

if ($out_type === 'html') {
if($out_type === 'html') {
$o = array(
'tot' => $results['tot'],
'start' => $results['start'],


+ 38
- 38
include/api.php View File

@@ -154,9 +154,9 @@ use \Friendica\Core\Config;


// workaround for HTTP-auth in CGI mode
if (x($_SERVER,'REDIRECT_REMOTE_USER')) {
if(x($_SERVER,'REDIRECT_REMOTE_USER')) {
$userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"],6)) ;
if (strlen($userpass)) {
if(strlen($userpass)) {
list($name, $password) = explode(':', $userpass);
$_SERVER['PHP_AUTH_USER'] = $name;
$_SERVER['PHP_AUTH_PW'] = $password;
@@ -199,7 +199,7 @@ use \Friendica\Core\Config;

call_hooks('authenticate', $addon_auth);

if (($addon_auth['authenticated']) && (count($addon_auth['user_record']))) {
if(($addon_auth['authenticated']) && (count($addon_auth['user_record']))) {
$record = $addon_auth['user_record'];
}
else {
@@ -215,7 +215,7 @@ use \Friendica\Core\Config;
$record = $r[0];
}

if ((! $record) || (! count($record))) {
if((! $record) || (! count($record))) {
logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
header('WWW-Authenticate: Basic realm="Friendica"');
#header('HTTP/1.0 401 Unauthorized');
@@ -334,7 +334,7 @@ use \Friendica\Core\Config;
break;
case "json":
header ("Content-Type: application/json");
foreach ($r as $rr)
foreach($r as $rr)
$json = json_encode($rr);
if ($_GET['callback'])
$json = $_GET['callback']."(".$json.")";
@@ -457,7 +457,7 @@ use \Friendica\Core\Config;
logger("api_get_user: Fetching user data for user ".$contact_id, LOGGER_DEBUG);

// Searching for contact URL
if (!is_null($contact_id) AND (intval($contact_id) == 0)){
if(!is_null($contact_id) AND (intval($contact_id) == 0)){
$user = dbesc(normalise_link($contact_id));
$url = $user;
$extra_query = "AND `contact`.`nurl` = '%s' ";
@@ -465,7 +465,7 @@ use \Friendica\Core\Config;
}

// Searching for contact id with uid = 0
if (!is_null($contact_id) AND (intval($contact_id) != 0)){
if(!is_null($contact_id) AND (intval($contact_id) != 0)){
$user = dbesc(api_unique_id_to_url($contact_id));

if ($user == "")
@@ -476,7 +476,7 @@ use \Friendica\Core\Config;
if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
}

if (is_null($user) && x($_GET, 'user_id')) {
if(is_null($user) && x($_GET, 'user_id')) {
$user = dbesc(api_unique_id_to_url($_GET['user_id']));

if ($user == "")
@@ -486,7 +486,7 @@ use \Friendica\Core\Config;
$extra_query = "AND `contact`.`nurl` = '%s' ";
if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user());
}
if (is_null($user) && x($_GET, 'screen_name')) {
if(is_null($user) && x($_GET, 'screen_name')) {
$user = dbesc($_GET['screen_name']);
$nick = $user;
$extra_query = "AND `contact`.`nick` = '%s' ";
@@ -496,7 +496,7 @@ use \Friendica\Core\Config;
if (is_null($user) AND ($a->argc > (count($called_api)-1)) AND (count($called_api) > 0)){
$argid = count($called_api);
list($user, $null) = explode(".",$a->argv[$argid]);
if (is_numeric($user)){
if(is_numeric($user)){
$user = dbesc(api_unique_id_to_url($user));

if ($user == "")
@@ -593,7 +593,7 @@ use \Friendica\Core\Config;
}
}

if ($uinfo[0]['self']) {
if($uinfo[0]['self']) {

if ($uinfo[0]['network'] == "")
$uinfo[0]['network'] = NETWORK_DFRN;
@@ -648,7 +648,7 @@ use \Friendica\Core\Config;
$starred = $r[0]['count'];


if (! $uinfo[0]['self']) {
if(! $uinfo[0]['self']) {
$countfriends = 0;
$countfollowers = 0;
$starred = 0;
@@ -923,7 +923,7 @@ use \Friendica\Core\Config;
$txt = requestdata('status');
//$txt = urldecode(requestdata('status'));

if ((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {

$txt = html2bb_video($txt);
$config = HTMLPurifier_Config::createDefault();
@@ -964,9 +964,9 @@ use \Friendica\Core\Config;

// logger('api_post: ' . print_r($_POST,true));

if (requestdata('htmlstatus')) {
if(requestdata('htmlstatus')) {
$txt = requestdata('htmlstatus');
if ((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
$txt = html2bb_video($txt);

$config = HTMLPurifier_Config::createDefault();
@@ -989,16 +989,16 @@ use \Friendica\Core\Config;
if ($parent == -1)
$parent = "";

if (ctype_digit($parent))
if(ctype_digit($parent))
$_REQUEST['parent'] = $parent;
else
$_REQUEST['parent_uri'] = $parent;

if (requestdata('lat') && requestdata('long'))
if(requestdata('lat') && requestdata('long'))
$_REQUEST['coord'] = sprintf("%s %s",requestdata('lat'),requestdata('long'));
$_REQUEST['profile_uid'] = api_user();

if ($parent)
if($parent)
$_REQUEST['type'] = 'net-comment';
else {
// Check for throttling (maximum posts per day, week and month)
@@ -1066,11 +1066,11 @@ use \Friendica\Core\Config;
$_REQUEST['type'] = 'wall';
}

if (x($_FILES,'media')) {
if(x($_FILES,'media')) {
// upload the image if we have one
$_REQUEST['hush']='yeah'; //tell wall_upload function to return img info instead of echo
$media = wall_upload_post($a);
if (strlen($media)>0)
if(strlen($media)>0)
$_REQUEST['body'] .= "\n\n".$media;
}

@@ -1115,13 +1115,13 @@ use \Friendica\Core\Config;

$user_info = api_get_user($a);

if (!x($_FILES,'media')) {
if(!x($_FILES,'media')) {
// Output error
throw new BadRequestException("No media.");
}

$media = wall_upload_post($a, false);
if (!$media) {
if(!$media) {
// Output error
throw new InternalServerErrorException();
}
@@ -2469,7 +2469,7 @@ use \Friendica\Core\Config;

$ret = Array();

foreach ($r as $item) {
foreach($r as $item) {

localize_item($item);
list($status_user, $owner_user) = api_item_get_user($a,$item);
@@ -2641,9 +2641,9 @@ use \Friendica\Core\Config;
return false;
}

if ($qtype == 'friends')
if($qtype == 'friends')
$sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
if ($qtype == 'followers')
if($qtype == 'followers')
$sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND));

// friends and followers only for self
@@ -2655,7 +2655,7 @@ use \Friendica\Core\Config;
);

$ret = array();
foreach ($r as $cid){
foreach($r as $cid){
$user = api_get_user($a, $cid['nurl']);
// "uid" and "self" are only needed for some internal stuff, so remove it from here
unset($user["uid"]);
@@ -2697,7 +2697,7 @@ use \Friendica\Core\Config;
$closed = (($a->config['register_policy'] == REGISTER_CLOSED) ? 'true' : 'false');
$private = ((Config::get('system', 'block_public')) ? 'true' : 'false');
$textlimit = (string) (($a->config['max_import_size']) ? $a->config['max_import_size'] : 200000);
if ($a->config['api_import_size'])
if($a->config['api_import_size'])
$texlimit = string($a->config['api_import_size']);
$ssl = ((Config::get('system', 'have_ssl')) ? 'true' : 'false');
$sslserver = (($ssl === 'true') ? str_replace('http:','https:',App::get_baseurl()) : '');
@@ -2737,13 +2737,13 @@ use \Friendica\Core\Config;

$a = get_app();

if (! api_user()) throw new ForbiddenException();
if(! api_user()) throw new ForbiddenException();

$user_info = api_get_user($a);

if ($qtype == 'friends')
if($qtype == 'friends')
$sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
if ($qtype == 'followers')
if($qtype == 'followers')
$sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND));

if (!$user_info["self"])
@@ -2761,7 +2761,7 @@ use \Friendica\Core\Config;
return;

$ids = array();
foreach ($r as $rr)
foreach($r as $rr)
if ($stringify_ids)
$ids[] = $rr['id'];
else
@@ -2967,7 +2967,7 @@ use \Friendica\Core\Config;
if ($user_id !="") {
$sql_extra .= ' AND `mail`.`contact-id` = ' . intval($user_id);
}
elseif ($screen_name !=""){
elseif($screen_name !=""){
$sql_extra .= " AND `contact`.`nick` = '" . dbesc($screen_name). "'";
}

@@ -2978,14 +2978,14 @@ use \Friendica\Core\Config;
);
if ($verbose == "true") {
// stop execution and return error message if no mails available
if ($r == null) {
if($r == null) {
$answer = array('result' => 'error', 'message' => 'no mails available');
return api_format_data("direct_messages_all", $type, array('$result' => $answer));
}
}

$ret = Array();
foreach ($r as $item) {
foreach($r as $item) {
if ($box == "inbox" || $item['from-url'] != $profile_url){
$recipient = $user_info;
$sender = api_get_user($a,normalise_link($item['contact-url']));
@@ -3092,7 +3092,7 @@ use \Friendica\Core\Config;

function api_fr_photo_detail($type) {
if (api_user()===false) throw new ForbiddenException();
if (!x($_REQUEST,'photo_id')) throw new BadRequestException("No photo id.");
if(!x($_REQUEST,'photo_id')) throw new BadRequestException("No photo id.");

$scale = (x($_REQUEST, 'scale') ? intval($_REQUEST['scale']) : false);
$scale_sql = ($scale === false ? "" : sprintf("and scale=%d",intval($scale)));
@@ -3183,11 +3183,11 @@ use \Friendica\Core\Config;

$dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']);

if ($r[0]['duplex'] && $r[0]['issued-id']) {
if($r[0]['duplex'] && $r[0]['issued-id']) {
$orig_id = $r[0]['issued-id'];
$dfrn_id = '1:' . $orig_id;
}
if ($r[0]['duplex'] && $r[0]['dfrn-id']) {
if($r[0]['duplex'] && $r[0]['dfrn-id']) {
$orig_id = $r[0]['dfrn-id'];
$dfrn_id = '0:' . $orig_id;
}
@@ -3927,7 +3927,7 @@ use \Friendica\Core\Config;
$success = array('success' => false, 'search_results' => 'nothing found');
else {
$ret = Array();
foreach ($r as $item) {
foreach($r as $item) {
if ($box == "inbox" || $item['from-url'] != $profile_url){
$recipient = $user_info;
$sender = api_get_user($a,normalise_link($item['contact-url']));


+ 1
- 1
include/attach.php View File

@@ -1061,7 +1061,7 @@ function z_mime_content_type($filename) {
);

$dot = strpos($filename,'.');
if ($dot !== false) {
if($dot !== false) {
$ext = strtolower(substr($filename,$dot+1));
if (array_key_exists($ext, $mime_types)) {
return $mime_types[$ext];


+ 4
- 4
include/bb2diaspora.php View File

@@ -141,7 +141,7 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
// Add all tags that maybe were removed
if (preg_match_all("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",$OriginalText, $tags)) {
$tagline = "";
foreach ($tags[2] as $tag) {
foreach($tags[2] as $tag) {
$tag = html_entity_decode($tag, ENT_QUOTES, 'UTF-8');
if (!strpos(html_entity_decode($Text, ENT_QUOTES, 'UTF-8'), "#".$tag))
$tagline .= "#".$tag." ";
@@ -193,7 +193,7 @@ function unescape_underscores_in_links($m) {

function format_event_diaspora($ev) {

if (! ((is_array($ev)) && count($ev)))
if(! ((is_array($ev)) && count($ev)))
return '';

$bd_format = t('l F d, Y \@ g:i A') ; // Friday January 18, 2011 @ 8 AM
@@ -209,7 +209,7 @@ function format_event_diaspora($ev) {
$ev['start'] , $bd_format)))
. '](' . App::get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['start'])) . ")\n";

if (! $ev['nofinish'])
if(! $ev['nofinish'])
$o .= t('Finishes:') . ' ' . '['
. (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC',
$ev['finish'] , $bd_format ))
@@ -217,7 +217,7 @@ function format_event_diaspora($ev) {
$ev['finish'] , $bd_format )))
. '](' . 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'])
. "\n";



+ 29
- 33
include/bbcode.php View File

@@ -206,33 +206,30 @@ function bb_spacefy($st) {
// returning [i]italic[/i]

function bb_unspacefy_and_trim($st) {
$whole_match = $st[0];
$captured = $st[1];
$unspacefied = preg_replace("/\[ (.*?)\ ]/", "[$1]", $captured);
return $unspacefied;
$whole_match = $st[0];
$captured = $st[1];
$unspacefied = preg_replace("/\[ (.*?)\ ]/", "[$1]", $captured);
return $unspacefied;
}

function bb_find_open_close($s, $open, $close, $occurance = 1) {

if ($occurance < 1)
if($occurance < 1)
$occurance = 1;

$start_pos = -1;
for ($i = 1; $i <= $occurance; $i++) {
if ( $start_pos !== false) {
for($i = 1; $i <= $occurance; $i++) {
if( $start_pos !== false)
$start_pos = strpos($s, $open, $start_pos + 1);
}
}

if ( $start_pos === false) {
if( $start_pos === false)
return false;
}

$end_pos = strpos($s, $close, $start_pos);

if ( $end_pos === false) {
if( $end_pos === false)
return false;
}

$res = array( 'start' => $start_pos, 'end' => $end_pos );

@@ -241,35 +238,34 @@ function bb_find_open_close($s, $open, $close, $occurance = 1) {

function get_bb_tag_pos($s, $name, $occurance = 1) {

if ($occurance < 1)
if($occurance < 1)
$occurance = 1;

$start_open = -1;
for ($i = 1; $i <= $occurance; $i++) {
if ( $start_open !== false) {
for($i = 1; $i <= $occurance; $i++) {
if( $start_open !== false)
$start_open = strpos($s, '[' . $name, $start_open + 1); // allow [name= type tags
}
}

if ( $start_open === false)
if( $start_open === false)
return false;

$start_equal = strpos($s, '=', $start_open);
$start_close = strpos($s, ']', $start_open);

if ( $start_close === false)
if( $start_close === false)
return false;

$start_close++;

$end_open = strpos($s, '[/' . $name . ']', $start_close);

if ( $end_open === false)
if( $end_open === false)
return false;

$res = array( 'start' => array('open' => $start_open, 'close' => $start_close),
'end' => array('open' => $end_open, 'close' => $end_open + strlen('[/' . $name . ']')) );
if ( $start_equal !== false)
if( $start_equal !== false)
$res['start']['equal'] = $start_equal + 1;

return $res;
@@ -281,12 +277,12 @@ function bb_tag_preg_replace($pattern, $replace, $name, $s) {

$occurance = 1;
$pos = get_bb_tag_pos($string, $name, $occurance);
while ($pos !== false && $occurance < 1000) {
while($pos !== false && $occurance < 1000) {

$start = substr($string, 0, $pos['start']['open']);
$subject = substr($string, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
$end = substr($string, $pos['end']['close']);
if ($end === false)
if($end === false)
$end = '';

$subject = preg_replace($pattern, $replace, $subject);
@@ -299,7 +295,7 @@ function bb_tag_preg_replace($pattern, $replace, $name, $s) {
return $string;
}

if (! function_exists('bb_extract_images')) {
if(! function_exists('bb_extract_images')) {
function bb_extract_images($body) {

$saved_image = array();
@@ -310,12 +306,12 @@ function bb_extract_images($body) {
$img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
$img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
while (($img_st_close !== false) && ($img_end !== false)) {
while(($img_st_close !== false) && ($img_end !== false)) {

$img_st_close++; // make it point to AFTER the closing bracket
$img_end += $img_start;

if (! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
// This is an embedded image

$saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
@@ -328,7 +324,7 @@ function bb_extract_images($body) {

$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 = '';

$img_start = strpos($orig_body, '[img');
@@ -341,7 +337,7 @@ function bb_extract_images($body) {
return array('body' => $new_body, 'images' => $saved_image);
}}

if (! function_exists('bb_replace_images')) {
if(! function_exists('bb_replace_images')) {
function bb_replace_images($body, $images) {

$newbody = $body;
@@ -623,7 +619,7 @@ function bb_DiasporaLinks($match) {
function bb_RemovePictureLinks($match) {
$text = Cache::get($match[1]);

if (is_null($text)){
if(is_null($text)){
$a = get_app();

$stamp1 = microtime(true);
@@ -677,7 +673,7 @@ function bb_expand_links($match) {
function bb_CleanPictureLinksSub($match) {
$text = Cache::get($match[1]);

if (is_null($text)){
if(is_null($text)){
$a = get_app();

$stamp1 = microtime(true);
@@ -728,7 +724,7 @@ function bb_CleanPictureLinks($text) {
}

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']))
return text_highlight($match[2],strtolower($match[1]));
return $match[0];
@@ -818,7 +814,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal

$Text = str_replace(array("\r","\n"), array('<br />','<br />'), $Text);

if ($preserve_nl)
if($preserve_nl)
$Text = str_replace(array("\n","\r"), array('',''),$Text);

// Set up the parameters for a URL search string
@@ -1136,7 +1132,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
// Summary (e.g. title) is required, earlier revisions only required description (in addition to
// start which is always required). Allow desc with a missing summary for compatibility.

if ((x($ev,'desc') || x($ev,'summary')) && x($ev,'start')) {
if((x($ev,'desc') || x($ev,'summary')) && x($ev,'start')) {
$sub = format_event_html($ev, $simplehtml);

$Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$Text);
@@ -1182,7 +1178,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
$regex = '#<([^>]*?)(href)="(?!' . implode('|', $allowed_link_protocols) . ')(.*?)"(.*?)>#ism';
$Text = preg_replace($regex, '<$1$2="javascript:void(0)"$4 class="invalid-href" title="' . t('Invalid link protocol') . '">', $Text);

if ($saved_image) {
if($saved_image) {
$Text = bb_replace_images($Text, $saved_image);
}



+ 1
- 1
include/cli_startup.php View File

@@ -19,7 +19,7 @@ function cli_startup() {
require_once("dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
};
};

require_once('include/session.php');



+ 2
- 2
include/contact_selectors.php View File

@@ -37,7 +37,7 @@ function contact_reputation($current) {
5 => t('Reputable, has my trust')
);

foreach ($rep as $k => $v) {
foreach($rep as $k => $v) {
$selected = (($k == $current) ? " selected=\"selected\" " : "");
$o .= "<option value=\"$k\" $selected >$v</option>\r\n";
}
@@ -61,7 +61,7 @@ function contact_poll_interval($current, $disabled = false) {
5 => t('Monthly')
);

foreach ($rep as $k => $v) {
foreach($rep as $k => $v) {
$selected = (($k == $current) ? " selected=\"selected\" " : "");
$o .= "<option value=\"$k\" $selected >$v</option>\r\n";
}


+ 22
- 27
include/contact_widgets.php View File

@@ -17,9 +17,9 @@ function findpeople_widget() {

$a = get_app();

if (get_config('system','invitation_only')) {
if(get_config('system','invitation_only')) {
$x = get_pconfig(local_user(),'system','invites_remaining');
if ($x || is_site_admin()) {
if($x || is_site_admin()) {
$a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
. sprintf( tt('%d invitation available','%d invitations available',$x), $x)
. '</div>' . $inv;
@@ -108,7 +108,7 @@ function networks_widget($baseurl,$selected = '') {
}
}

if (count($nets) < 2)
if(count($nets) < 2)
return '';

return replace_macros(get_markup_template('nets.tpl'),array(
@@ -140,7 +140,7 @@ function fileas_widget($baseurl,$selected = '') {
$terms = array();
$cnt = preg_match_all('/\[(.*?)\]/',$saved,$matches,PREG_SET_ORDER);
if ($cnt) {
foreach ($matches as $mtch) {
foreach($matches as $mtch) {
$unescaped = xmlify(file_tag_decode($mtch[1]));
$terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : ''));
}
@@ -172,11 +172,10 @@ function categories_widget($baseurl,$selected = '') {

$matches = false;
$terms = array();
$cnt = preg_match_all('/<(.*?)>/',$saved,$matches,PREG_SET_ORDER);

if ($cnt) {
foreach ($matches as $mtch) {
$unescaped = xmlify(file_tag_decode($mtch[1]));
$cnt = preg_match_all('/<(.*?)>/',$saved,$matches,PREG_SET_ORDER);
if($cnt) {
foreach($matches as $mtch) {
$unescaped = xmlify(file_tag_decode($mtch[1]));
$terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : ''));
}
}
@@ -196,29 +195,29 @@ function common_friends_visitor_widget($profile_uid) {

$a = get_app();

if (local_user() == $profile_uid)
if(local_user() == $profile_uid)
return;

$cid = $zcid = 0;

if (is_array($_SESSION['remote'])) {
foreach ($_SESSION['remote'] as $visitor) {
if ($visitor['uid'] == $profile_uid) {
if(is_array($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $visitor) {
if($visitor['uid'] == $profile_uid) {
$cid = $visitor['cid'];
break;
}
}
}

if (! $cid) {
if (get_my_url()) {
if(! $cid) {
if(get_my_url()) {
$r = q("select id from contact where nurl = '%s' and uid = %d limit 1",
dbesc(normalise_link(get_my_url())),
intval($profile_uid)
);
if (dbm::is_result($r)) {
if (dbm::is_result($r))
$cid = $r[0]['id'];
} else {
else {
$r = q("select id from gcontact where nurl = '%s' limit 1",
dbesc(normalise_link(get_my_url()))
);
@@ -228,26 +227,22 @@ function common_friends_visitor_widget($profile_uid) {
}
}

if ($cid == 0 && $zcid == 0) {
if($cid == 0 && $zcid == 0)
return;
}

require_once('include/socgraph.php');

if ($cid) {
if($cid)
$t = count_common_friends($profile_uid,$cid);
} else {
else
$t = count_common_friends_zcid($profile_uid,$zcid);
}
if (! $t) {
if(! $t)
return;
}

if ($cid) {
if($cid)
$r = common_friends($profile_uid,$cid,0,5,true);
} else {
else
$r = common_friends_zcid($profile_uid,$zcid,0,5,true);
}

return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
'$desc' => sprintf( tt("%d contact in common", "%d contacts in common", $t), $t),


+ 129
- 138
include/conversation.php View File

@@ -7,7 +7,7 @@ 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
// 'item_redir_and_replace_images'
if (! function_exists('item_extract_images')) {
if(! function_exists('item_extract_images')) {
function item_extract_images($body) {

$saved_image = array();
@@ -18,12 +18,12 @@ function item_extract_images($body) {
$img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
$img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
while (($img_st_close !== false) && ($img_end !== false)) {
while(($img_st_close !== false) && ($img_end !== false)) {

$img_st_close++; // make it point to AFTER the closing bracket
$img_end += $img_start;

if (! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
// This is an embedded image

$saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
@@ -36,7 +36,7 @@ function item_extract_images($body) {

$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 = '';

$img_start = strpos($orig_body, '[img');
@@ -49,7 +49,7 @@ function item_extract_images($body) {
return array('body' => $new_body, 'images' => $saved_image);
}}

if (! function_exists('item_redir_and_replace_images')) {
if(! function_exists('item_redir_and_replace_images')) {
function item_redir_and_replace_images($body, $images, $cid) {

$origbody = $body;
@@ -57,7 +57,7 @@ function item_redir_and_replace_images($body, $images, $cid) {

$cnt = 1;
$pos = get_bb_tag_pos($origbody, 'url', 1);
while ($pos !== false && $cnt < 1000) {
while($pos !== false && $cnt < 1000) {

$search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
$replace = '[url=' . z_path() . '/redir/' . $cid
@@ -66,7 +66,7 @@ function item_redir_and_replace_images($body, $images, $cid) {
$newbody .= substr($origbody, 0, $pos['start']['open']);
$subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
$origbody = substr($origbody, $pos['end']['close']);
if ($origbody === false)
if($origbody === false)
$origbody = '';

$subject = preg_replace($search, $replace, $subject);
@@ -96,7 +96,7 @@ function item_redir_and_replace_images($body, $images, $cid) {
function localize_item(&$item){

$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']);

$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
@@ -126,7 +126,7 @@ function localize_item(&$item){
}
break;
default:
if ($obj['resource-id']){
if($obj['resource-id']){
$post_type = t('photo');
$m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
$rr['plink'] = $m[1];
@@ -137,19 +137,19 @@ function localize_item(&$item){

$plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';

if (activity_match($item['verb'],ACTIVITY_LIKE)) {
if(activity_match($item['verb'],ACTIVITY_LIKE)) {
$bodyverb = t('%1$s likes %2$s\'s %3$s');
}
elseif (activity_match($item['verb'],ACTIVITY_DISLIKE)) {
elseif(activity_match($item['verb'],ACTIVITY_DISLIKE)) {
$bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
}
elseif (activity_match($item['verb'],ACTIVITY_ATTEND)) {
elseif(activity_match($item['verb'],ACTIVITY_ATTEND)) {
$bodyverb = t('%1$s attends %2$s\'s %3$s');
}
elseif (activity_match($item['verb'],ACTIVITY_ATTENDNO)) {
elseif(activity_match($item['verb'],ACTIVITY_ATTENDNO)) {
$bodyverb = t('%1$s doesn\'t attend %2$s\'s %3$s');
}
elseif (activity_match($item['verb'],ACTIVITY_ATTENDMAYBE)) {
elseif(activity_match($item['verb'],ACTIVITY_ATTENDMAYBE)) {
$bodyverb = t('%1$s attends maybe %2$s\'s %3$s');
}
$item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
@@ -187,7 +187,7 @@ function localize_item(&$item){
}
if (stristr($item['verb'],ACTIVITY_POKE)) {
$verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
if (! $verb)
if(! $verb)
return;
if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;

@@ -229,7 +229,7 @@ function localize_item(&$item){
}
if (stristr($item['verb'],ACTIVITY_MOOD)) {
$verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
if (! $verb)
if(! $verb)
return;

$Aname = $item['author-name'];
@@ -262,7 +262,7 @@ function localize_item(&$item){
}
break;
default:
if ($obj['resource-id']){
if($obj['resource-id']){
$post_type = t('photo');
$m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
$rr['plink'] = $m[1];
@@ -289,7 +289,7 @@ function localize_item(&$item){
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";

$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",
dbesc($obj->id),
intval($item['uid'])
@@ -307,17 +307,16 @@ function localize_item(&$item){
}
}
$matches = null;
if (preg_match_all('/@\[url=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
foreach ($matches as $mtch) {
if (! strpos($mtch[1],'zrl=')) {
if(preg_match_all('/@\[url=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
foreach($matches as $mtch) {
if(! strpos($mtch[1],'zrl='))
$item['body'] = str_replace($mtch[0],'@[url=' . zrl($mtch[1]). ']',$item['body']);
}
}
}

// add zrl's to public images
$photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
if (preg_match($photo_pattern,$item['body'])) {
if(preg_match($photo_pattern,$item['body'])) {
$photo_replace = '[url=' . zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
$item['body'] = bb_tag_preg_replace($photo_pattern, $photo_replace, 'url', $item['body']);
}
@@ -344,9 +343,9 @@ function localize_item(&$item){
function count_descendants($item) {
$total = count($item['children']);

if ($total > 0) {
foreach ($item['children'] as $child) {
if (! visible_activity($child))
if($total > 0) {
foreach($item['children'] as $child) {
if(! visible_activity($child))
$total --;
$total += count_descendants($child);
}
@@ -361,14 +360,14 @@ function visible_activity($item) {
// in which case we handle them specially

$hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE);
foreach ($hidden_activities as $act) {
if (activity_match($item['verb'],$act)) {
foreach($hidden_activities as $act) {
if(activity_match($item['verb'],$act)) {
return false;
}
}

if (activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
if (! (($item['self']) && ($item['uid'] == local_user()))) {
if(activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
if(! (($item['self']) && ($item['uid'] == local_user()))) {
return false;
}
}
@@ -466,7 +465,7 @@ function item_condition() {
*
*/

if (!function_exists('conversation')) {
if(!function_exists('conversation')) {
function conversation(App $a, $items, $mode, $update, $preview = false) {

require_once('include/bbcode.php');
@@ -481,23 +480,22 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {

$arr_blocked = null;

if (local_user()) {
if(local_user()) {
$str_blocked = get_pconfig(local_user(),'system','blocked');
if ($str_blocked) {
if($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]);
}
}

}

$previewing = (($preview) ? ' preview ' : '');

if ($mode === 'network') {
if($mode === 'network') {
$profile_owner = local_user();
$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
// way and also you aren't writing a comment (discovered in javascript).
@@ -522,14 +520,14 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
. "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
}
}
else if ($mode === 'profile') {
else if($mode === 'profile') {
$profile_owner = $a->profile['profile_uid'];
$page_writeable = can_write_wall($a,$profile_owner);

if (!$update) {
if(!$update) {
$tab = notags(trim($_GET['tab']));
$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.

@@ -539,40 +537,40 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
}
}
}
else if ($mode === 'notes') {
else if($mode === 'notes') {
$profile_owner = local_user();
$page_writeable = true;
if (!$update) {
if(!$update) {
$live_update_div = '<div id="live-notes"></div>' . "\r\n"
. "<script> var profile_uid = " . local_user()
. "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
}
}
else if ($mode === 'display') {
else if($mode === 'display') {
$profile_owner = $a->profile['uid'];
$page_writeable = can_write_wall($a,$profile_owner);
if (!$update) {
if(!$update) {
$live_update_div = '<div id="live-display"></div>' . "\r\n"
. "<script> var profile_uid = " . $_SESSION['uid'] . ";"
. " var profile_page = 1; </script>";
}
}
else if ($mode === 'community') {
else if($mode === 'community') {
$profile_owner = 0;
$page_writeable = false;
if (!$update) {
if(!$update) {
$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";
}
}
else if ($mode === 'search') {
else if($mode === 'search') {
$live_update_div = '<div id="live-search"></div>' . "\r\n";
}

$page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);


if ($update)
if($update)
$return_url = $_SESSION['return_url'];
else
$return_url = $_SESSION['return_url'] = $a->query_string;
@@ -596,9 +594,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {

$page_template = get_markup_template("conversation.tpl");

if ($items && count($items)) {
if($items && count($items)) {

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
@@ -606,17 +604,17 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
// $tpl = get_markup_template('search_item.tpl');
$tpl = 'search_item.tpl';

foreach ($items as $item) {
foreach($items as $item) {

if ($arr_blocked) {
if($arr_blocked) {
$blocked = false;
foreach ($arr_blocked as $b) {
if ($b && link_compare($item['author-link'],$b)) {
foreach($arr_blocked as $b) {
if($b && link_compare($item['author-link'],$b)) {
$blocked = true;
break;
}
}
if ($blocked)
if($blocked)
continue;
}

@@ -628,8 +626,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$owner_name = '';
$sparkle = '';

if ($mode === 'search' || $mode === 'community') {
if (((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
if($mode === 'search' || $mode === 'community') {
if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
&& ($item['id'] != $item['parent']))
continue;
$nickname = $item['nickname'];
@@ -638,11 +636,11 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$nickname = $a->user['nickname'];

// prevent private email from leaking.
if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
continue;

$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'];


@@ -654,7 +652,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`",
intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));

foreach ($taglist as $tag) {
foreach($taglist as $tag) {

if ($tag["url"] == "")
$tag["url"] = $searchpath.strtolower($tag["term"]);
@@ -671,9 +669,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {

$sp = false;
$profile_link = best_link_url($item,$sp);
if ($profile_link === 'mailbox')
if($profile_link === 'mailbox')
$profile_link = '';
if ($sp)
if($sp)
$sparkle = ' sparkle';
else
$profile_link = zrl($profile_link);
@@ -700,7 +698,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));

localize_item($item);
if ($mode === 'network-new')
if($mode === 'network-new')
$dropping = true;
else
$dropping = false;
@@ -725,7 +723,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {

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

if ($a->theme['template_engine'] === 'internal') {
if($a->theme['template_engine'] === 'internal') {
$profile_name_e = template_escape($profile_name);
$item['title_e'] = template_escape($item['title']);
$body_e = template_escape($body);
@@ -820,18 +818,18 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
// But for now, this array respects the old style, just in case

$threads = array();
foreach ($items as $item) {
foreach($items as $item) {

if ($arr_blocked) {
if($arr_blocked) {
$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;
break;
}
}