added spaces + some curly braces + some usage of dbm::is_result()

Signed-off-by: Roland Haeder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2017-04-04 19:46:56 +02:00
parent bebff8ebbb
commit 03571f6e74
No known key found for this signature in database
GPG Key ID: B72F8185C6C7BD78
11 changed files with 309 additions and 268 deletions

View File

@ -35,7 +35,7 @@ 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 = '';
@ -88,13 +88,13 @@ 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);
@ -113,23 +113,24 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {
$sql_extra = ''; $sql_extra = '';
if($x['mutual']) { if ($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 (intval($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 ++) 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";
@ -185,14 +186,14 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
$sql_extra = ''; $sql_extra = '';
if($privmail || $celeb) { if ($privmail || $celeb) {
$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);
@ -204,7 +205,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
} 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";
@ -287,7 +288,7 @@ function prune_deadguys($arr) {
function get_acl_permissions($user = null) { function get_acl_permissions($user = null) {
$allow_cid = $allow_gid = $deny_cid = $deny_gid = false; $allow_cid = $allow_gid = $deny_cid = $deny_gid = false;
if(is_array($user)) { if (is_array($user)) {
$allow_cid = ((strlen($user['allow_cid'])) $allow_cid = ((strlen($user['allow_cid']))
? explode('><', $user['allow_cid']) : array() ); ? explode('><', $user['allow_cid']) : array() );
$allow_gid = ((strlen($user['allow_gid'])) $allow_gid = ((strlen($user['allow_gid']))
@ -318,25 +319,25 @@ function populate_acl($user = null, $show_jotnets = false) {
$perms = get_acl_permissions($user); $perms = get_acl_permissions($user);
$jotnets = ''; $jotnets = '';
if($show_jotnets) { if ($show_jotnets) {
$mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
$mail_enabled = false; $mail_enabled = false;
$pubmail_enabled = false; $pubmail_enabled = false;
if(! $mail_disabled) { if (! $mail_disabled) {
$r = q("SELECT `pubmail` FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", $r = q("SELECT `pubmail` FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
intval(local_user()) intval(local_user())
); );
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) {
$selected = (($pubmail_enabled) ? ' checked="checked" ' : ''); $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>'; $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
} }
@ -379,20 +380,20 @@ function construct_acl_data(App $a, $user) {
$user_defaults = get_acl_permissions($user); $user_defaults = get_acl_permissions($user);
if($acl_data['groups']) { if ($acl_data['groups']) {
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
@ -419,8 +420,8 @@ 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'];
} }
@ -510,7 +511,7 @@ function acl_lookup(App $a, $out_type = 'json') {
intval($count) intval($count)
); );
foreach($r as $g){ foreach ($r as $g){
// logger('acl: group: ' . $g['name'] . ' members: ' . $g['uids']); // logger('acl: group: ' . $g['name'] . ' members: ' . $g['uids']);
$groups[] = array( $groups[] = array(
"type" => "g", "type" => "g",
@ -546,7 +547,7 @@ function acl_lookup(App $a, $out_type = 'json') {
dbesc(NETWORK_STATUSNET) dbesc(NETWORK_STATUSNET)
); );
} }
elseif($type == 'm') { elseif ($type == 'm') {
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact` $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` WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive`
AND `network` IN ('%s','%s','%s') AND `network` IN ('%s','%s','%s')
@ -665,7 +666,7 @@ function acl_lookup(App $a, $out_type = 'json') {
call_hooks('acl_lookup_end', $results); call_hooks('acl_lookup_end', $results);
if($out_type === 'html') { if ($out_type === 'html') {
$o = array( $o = array(
'tot' => $results['tot'], 'tot' => $results['tot'],
'start' => $results['start'], 'start' => $results['start'],

View File

@ -154,9 +154,9 @@ use \Friendica\Core\Config;
// workaround for HTTP-auth in CGI mode // 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)) ; $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"],6)) ;
if(strlen($userpass)) { if (strlen($userpass)) {
list($name, $password) = explode(':', $userpass); list($name, $password) = explode(':', $userpass);
$_SERVER['PHP_AUTH_USER'] = $name; $_SERVER['PHP_AUTH_USER'] = $name;
$_SERVER['PHP_AUTH_PW'] = $password; $_SERVER['PHP_AUTH_PW'] = $password;
@ -199,7 +199,7 @@ use \Friendica\Core\Config;
call_hooks('authenticate', $addon_auth); 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']; $record = $addon_auth['user_record'];
} }
else { else {
@ -215,7 +215,7 @@ use \Friendica\Core\Config;
$record = $r[0]; $record = $r[0];
} }
if((! $record) || (! count($record))) { if ((! $record) || (! count($record))) {
logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG); logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
header('WWW-Authenticate: Basic realm="Friendica"'); header('WWW-Authenticate: Basic realm="Friendica"');
#header('HTTP/1.0 401 Unauthorized'); #header('HTTP/1.0 401 Unauthorized');
@ -334,7 +334,7 @@ use \Friendica\Core\Config;
break; break;
case "json": case "json":
header ("Content-Type: application/json"); header ("Content-Type: application/json");
foreach($r as $rr) foreach ($r as $rr)
$json = json_encode($rr); $json = json_encode($rr);
if ($_GET['callback']) if ($_GET['callback'])
$json = $_GET['callback']."(".$json.")"; $json = $_GET['callback']."(".$json.")";
@ -458,7 +458,7 @@ use \Friendica\Core\Config;
logger("api_get_user: Fetching user data for user ".$contact_id, LOGGER_DEBUG); logger("api_get_user: Fetching user data for user ".$contact_id, LOGGER_DEBUG);
// Searching for contact URL // 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)); $user = dbesc(normalise_link($contact_id));
$url = $user; $url = $user;
$extra_query = "AND `contact`.`nurl` = '%s' "; $extra_query = "AND `contact`.`nurl` = '%s' ";
@ -466,7 +466,7 @@ use \Friendica\Core\Config;
} }
// Searching for contact id with uid = 0 // 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)); $user = dbesc(api_unique_id_to_url($contact_id));
if ($user == "") if ($user == "")
@ -477,7 +477,7 @@ use \Friendica\Core\Config;
if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user()); 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'])); $user = dbesc(api_unique_id_to_url($_GET['user_id']));
if ($user == "") if ($user == "")
@ -487,7 +487,7 @@ use \Friendica\Core\Config;
$extra_query = "AND `contact`.`nurl` = '%s' "; $extra_query = "AND `contact`.`nurl` = '%s' ";
if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user()); 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']); $user = dbesc($_GET['screen_name']);
$nick = $user; $nick = $user;
$extra_query = "AND `contact`.`nick` = '%s' "; $extra_query = "AND `contact`.`nick` = '%s' ";
@ -497,7 +497,7 @@ use \Friendica\Core\Config;
if (is_null($user) AND ($a->argc > (count($called_api)-1)) AND (count($called_api) > 0)){ if (is_null($user) AND ($a->argc > (count($called_api)-1)) AND (count($called_api) > 0)){
$argid = count($called_api); $argid = count($called_api);
list($user, $null) = explode(".",$a->argv[$argid]); list($user, $null) = explode(".",$a->argv[$argid]);
if(is_numeric($user)){ if (is_numeric($user)){
$user = dbesc(api_unique_id_to_url($user)); $user = dbesc(api_unique_id_to_url($user));
if ($user == "") if ($user == "")
@ -594,7 +594,7 @@ use \Friendica\Core\Config;
} }
} }
if($uinfo[0]['self']) { if ($uinfo[0]['self']) {
if ($uinfo[0]['network'] == "") if ($uinfo[0]['network'] == "")
$uinfo[0]['network'] = NETWORK_DFRN; $uinfo[0]['network'] = NETWORK_DFRN;
@ -649,7 +649,7 @@ use \Friendica\Core\Config;
$starred = $r[0]['count']; $starred = $r[0]['count'];
if(! $uinfo[0]['self']) { if (! $uinfo[0]['self']) {
$countfriends = 0; $countfriends = 0;
$countfollowers = 0; $countfollowers = 0;
$starred = 0; $starred = 0;
@ -924,7 +924,7 @@ use \Friendica\Core\Config;
$txt = requestdata('status'); $txt = requestdata('status');
//$txt = urldecode(requestdata('status')); //$txt = urldecode(requestdata('status'));
if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) { if ((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
$txt = html2bb_video($txt); $txt = html2bb_video($txt);
$config = HTMLPurifier_Config::createDefault(); $config = HTMLPurifier_Config::createDefault();
@ -965,9 +965,9 @@ use \Friendica\Core\Config;
// logger('api_post: ' . print_r($_POST,true)); // logger('api_post: ' . print_r($_POST,true));
if(requestdata('htmlstatus')) { if (requestdata('htmlstatus')) {
$txt = requestdata('htmlstatus'); $txt = requestdata('htmlstatus');
if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) { if ((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
$txt = html2bb_video($txt); $txt = html2bb_video($txt);
$config = HTMLPurifier_Config::createDefault(); $config = HTMLPurifier_Config::createDefault();
@ -990,16 +990,16 @@ use \Friendica\Core\Config;
if ($parent == -1) if ($parent == -1)
$parent = ""; $parent = "";
if(ctype_digit($parent)) if (ctype_digit($parent))
$_REQUEST['parent'] = $parent; $_REQUEST['parent'] = $parent;
else else
$_REQUEST['parent_uri'] = $parent; $_REQUEST['parent_uri'] = $parent;
if(requestdata('lat') && requestdata('long')) if (requestdata('lat') && requestdata('long'))
$_REQUEST['coord'] = sprintf("%s %s",requestdata('lat'),requestdata('long')); $_REQUEST['coord'] = sprintf("%s %s",requestdata('lat'),requestdata('long'));
$_REQUEST['profile_uid'] = api_user(); $_REQUEST['profile_uid'] = api_user();
if($parent) if ($parent)
$_REQUEST['type'] = 'net-comment'; $_REQUEST['type'] = 'net-comment';
else { else {
// Check for throttling (maximum posts per day, week and month) // Check for throttling (maximum posts per day, week and month)
@ -1067,11 +1067,11 @@ use \Friendica\Core\Config;
$_REQUEST['type'] = 'wall'; $_REQUEST['type'] = 'wall';
} }
if(x($_FILES,'media')) { if (x($_FILES,'media')) {
// upload the image if we have one // upload the image if we have one
$_REQUEST['hush']='yeah'; //tell wall_upload function to return img info instead of echo $_REQUEST['hush']='yeah'; //tell wall_upload function to return img info instead of echo
$media = wall_upload_post($a); $media = wall_upload_post($a);
if(strlen($media)>0) if (strlen($media)>0)
$_REQUEST['body'] .= "\n\n".$media; $_REQUEST['body'] .= "\n\n".$media;
} }
@ -1116,13 +1116,13 @@ use \Friendica\Core\Config;
$user_info = api_get_user($a); $user_info = api_get_user($a);
if(!x($_FILES,'media')) { if (!x($_FILES,'media')) {
// Output error // Output error
throw new BadRequestException("No media."); throw new BadRequestException("No media.");
} }
$media = wall_upload_post($a, false); $media = wall_upload_post($a, false);
if(!$media) { if (!$media) {
// Output error // Output error
throw new InternalServerErrorException(); throw new InternalServerErrorException();
} }
@ -2470,7 +2470,7 @@ use \Friendica\Core\Config;
$ret = Array(); $ret = Array();
foreach($r as $item) { foreach ($r as $item) {
localize_item($item); localize_item($item);
list($status_user, $owner_user) = api_item_get_user($a,$item); list($status_user, $owner_user) = api_item_get_user($a,$item);
@ -2642,9 +2642,9 @@ use \Friendica\Core\Config;
return false; 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)); $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)); $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND));
// friends and followers only for self // friends and followers only for self
@ -2656,7 +2656,7 @@ use \Friendica\Core\Config;
); );
$ret = array(); $ret = array();
foreach($r as $cid){ foreach ($r as $cid){
$user = api_get_user($a, $cid['nurl']); $user = api_get_user($a, $cid['nurl']);
// "uid" and "self" are only needed for some internal stuff, so remove it from here // "uid" and "self" are only needed for some internal stuff, so remove it from here
unset($user["uid"]); unset($user["uid"]);
@ -2698,7 +2698,7 @@ use \Friendica\Core\Config;
$closed = (($a->config['register_policy'] == REGISTER_CLOSED) ? 'true' : 'false'); $closed = (($a->config['register_policy'] == REGISTER_CLOSED) ? 'true' : 'false');
$private = ((Config::get('system', 'block_public')) ? 'true' : 'false'); $private = ((Config::get('system', 'block_public')) ? 'true' : 'false');
$textlimit = (string) (($a->config['max_import_size']) ? $a->config['max_import_size'] : 200000); $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']); $texlimit = string($a->config['api_import_size']);
$ssl = ((Config::get('system', 'have_ssl')) ? 'true' : 'false'); $ssl = ((Config::get('system', 'have_ssl')) ? 'true' : 'false');
$sslserver = (($ssl === 'true') ? str_replace('http:','https:',App::get_baseurl()) : ''); $sslserver = (($ssl === 'true') ? str_replace('http:','https:',App::get_baseurl()) : '');
@ -2740,13 +2740,13 @@ use \Friendica\Core\Config;
$a = get_app(); $a = get_app();
if(! api_user()) throw new ForbiddenException(); if (! api_user()) throw new ForbiddenException();
$user_info = api_get_user($a); $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)); $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)); $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND));
if (!$user_info["self"]) if (!$user_info["self"])
@ -2764,7 +2764,7 @@ use \Friendica\Core\Config;
return; return;
$ids = array(); $ids = array();
foreach($r as $rr) foreach ($r as $rr)
if ($stringify_ids) if ($stringify_ids)
$ids[] = $rr['id']; $ids[] = $rr['id'];
else else
@ -2970,7 +2970,7 @@ use \Friendica\Core\Config;
if ($user_id !="") { if ($user_id !="") {
$sql_extra .= ' AND `mail`.`contact-id` = ' . intval($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). "'"; $sql_extra .= " AND `contact`.`nick` = '" . dbesc($screen_name). "'";
} }
@ -2981,14 +2981,14 @@ use \Friendica\Core\Config;
); );
if ($verbose == "true") { if ($verbose == "true") {
// stop execution and return error message if no mails available // stop execution and return error message if no mails available
if($r == null) { if ($r == null) {
$answer = array('result' => 'error', 'message' => 'no mails available'); $answer = array('result' => 'error', 'message' => 'no mails available');
return api_format_data("direct_messages_all", $type, array('$result' => $answer)); return api_format_data("direct_messages_all", $type, array('$result' => $answer));
} }
} }
$ret = Array(); $ret = Array();
foreach($r as $item) { foreach ($r as $item) {
if ($box == "inbox" || $item['from-url'] != $profile_url){ if ($box == "inbox" || $item['from-url'] != $profile_url){
$recipient = $user_info; $recipient = $user_info;
$sender = api_get_user($a,normalise_link($item['contact-url'])); $sender = api_get_user($a,normalise_link($item['contact-url']));
@ -3095,7 +3095,7 @@ use \Friendica\Core\Config;
function api_fr_photo_detail($type) { function api_fr_photo_detail($type) {
if (api_user()===false) throw new ForbiddenException(); 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 = (x($_REQUEST, 'scale') ? intval($_REQUEST['scale']) : false);
$scale_sql = ($scale === false ? "" : sprintf("and scale=%d",intval($scale))); $scale_sql = ($scale === false ? "" : sprintf("and scale=%d",intval($scale)));
@ -3186,11 +3186,11 @@ use \Friendica\Core\Config;
$dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']); $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']; $orig_id = $r[0]['issued-id'];
$dfrn_id = '1:' . $orig_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']; $orig_id = $r[0]['dfrn-id'];
$dfrn_id = '0:' . $orig_id; $dfrn_id = '0:' . $orig_id;
} }
@ -3930,7 +3930,7 @@ use \Friendica\Core\Config;
$success = array('success' => false, 'search_results' => 'nothing found'); $success = array('success' => false, 'search_results' => 'nothing found');
else { else {
$ret = Array(); $ret = Array();
foreach($r as $item) { foreach ($r as $item) {
if ($box == "inbox" || $item['from-url'] != $profile_url){ if ($box == "inbox" || $item['from-url'] != $profile_url){
$recipient = $user_info; $recipient = $user_info;
$sender = api_get_user($a,normalise_link($item['contact-url'])); $sender = api_get_user($a,normalise_link($item['contact-url']));

View File

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

View File

@ -132,7 +132,7 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
// Add all tags that maybe were removed // Add all tags that maybe were removed
if (preg_match_all("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",$OriginalText, $tags)) { if (preg_match_all("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",$OriginalText, $tags)) {
$tagline = ""; $tagline = "";
foreach($tags[2] as $tag) { foreach ($tags[2] as $tag) {
$tag = html_entity_decode($tag, ENT_QUOTES, 'UTF-8'); $tag = html_entity_decode($tag, ENT_QUOTES, 'UTF-8');
if (!strpos(html_entity_decode($Text, ENT_QUOTES, 'UTF-8'), "#".$tag)) if (!strpos(html_entity_decode($Text, ENT_QUOTES, 'UTF-8'), "#".$tag))
$tagline .= "#".$tag." "; $tagline .= "#".$tag." ";
@ -184,7 +184,7 @@ 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
@ -200,7 +200,7 @@ 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 ))
@ -208,7 +208,7 @@ function format_event_diaspora($ev) {
$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";

View File

@ -206,30 +206,33 @@ function bb_spacefy($st) {
// returning [i]italic[/i] // 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];
$unspacefied = preg_replace("/\[ (.*?)\ ]/", "[$1]", $captured); $unspacefied = preg_replace("/\[ (.*?)\ ]/", "[$1]", $captured);
return $unspacefied; return $unspacefied;
} }
function bb_find_open_close($s, $open, $close, $occurance = 1) { function bb_find_open_close($s, $open, $close, $occurance = 1) {
if($occurance < 1) if ($occurance < 1)
$occurance = 1; $occurance = 1;
$start_pos = -1; $start_pos = -1;
for($i = 1; $i <= $occurance; $i++) { for ($i = 1; $i <= $occurance; $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 );
@ -238,35 +241,48 @@ function bb_find_open_close($s, $open, $close, $occurance = 1) {
function get_bb_tag_pos($s, $name, $occurance = 1) { function get_bb_tag_pos($s, $name, $occurance = 1) {
if($occurance < 1) if ($occurance < 1)
$occurance = 1; $occurance = 1;
$start_open = -1; $start_open = -1;
for($i = 1; $i <= $occurance; $i++) { for ($i = 1; $i <= $occurance; $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;
} }
@ -277,12 +293,12 @@ function bb_tag_preg_replace($pattern, $replace, $name, $s) {
$occurance = 1; $occurance = 1;
$pos = get_bb_tag_pos($string, $name, $occurance); $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']); $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);
@ -295,7 +311,7 @@ function bb_tag_preg_replace($pattern, $replace, $name, $s) {
return $string; return $string;
} }
if(! function_exists('bb_extract_images')) { if (! function_exists('bb_extract_images')) {
function bb_extract_images($body) { function bb_extract_images($body) {
$saved_image = array(); $saved_image = array();
@ -306,12 +322,12 @@ function bb_extract_images($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);
$img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : 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_st_close++; // make it point to AFTER the closing bracket
$img_end += $img_start; $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 // This is an embedded image
$saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close)); $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
@ -324,7 +340,7 @@ function bb_extract_images($body) {
$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');
@ -337,7 +353,7 @@ function bb_extract_images($body) {
return array('body' => $new_body, 'images' => $saved_image); 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) { function bb_replace_images($body, $images) {
$newbody = $body; $newbody = $body;
@ -619,7 +635,7 @@ function bb_DiasporaLinks($match) {
function bb_RemovePictureLinks($match) { function bb_RemovePictureLinks($match) {
$text = Cache::get($match[1]); $text = Cache::get($match[1]);
if(is_null($text)){ if (is_null($text)){
$a = get_app(); $a = get_app();
$stamp1 = microtime(true); $stamp1 = microtime(true);
@ -673,7 +689,7 @@ function bb_expand_links($match) {
function bb_CleanPictureLinksSub($match) { function bb_CleanPictureLinksSub($match) {
$text = Cache::get($match[1]); $text = Cache::get($match[1]);
if(is_null($text)){ if (is_null($text)){
$a = get_app(); $a = get_app();
$stamp1 = microtime(true); $stamp1 = microtime(true);
@ -724,7 +740,7 @@ function bb_CleanPictureLinks($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];
@ -814,7 +830,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
$Text = str_replace(array("\r","\n"), array('<br />','<br />'), $Text); $Text = str_replace(array("\r","\n"), array('<br />','<br />'), $Text);
if($preserve_nl) if ($preserve_nl)
$Text = str_replace(array("\n","\r"), array('',''),$Text); $Text = str_replace(array("\n","\r"), array('',''),$Text);
// Set up the parameters for a URL search string // Set up the parameters for a URL search string
@ -1132,7 +1148,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 // 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. // 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); $sub = format_event_html($ev, $simplehtml);
$Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$Text); $Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$Text);
@ -1178,7 +1194,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
$regex = '#<([^>]*?)(href)="(?!' . implode('|', $allowed_link_protocols) . ')(.*?)"(.*?)>#ism'; $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); $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); $Text = bb_replace_images($Text, $saved_image);
} }

View File

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

View File

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

View File

@ -17,9 +17,9 @@ function findpeople_widget() {
$a = get_app(); $a = get_app();
if(get_config('system','invitation_only')) { if (get_config('system','invitation_only')) {
$x = get_pconfig(local_user(),'system','invites_remaining'); $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">' $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
. sprintf( tt('%d invitation available','%d invitations available',$x), $x) . sprintf( tt('%d invitation available','%d invitations available',$x), $x)
. '</div>' . $inv; . '</div>' . $inv;
@ -108,7 +108,7 @@ 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(
@ -140,7 +140,7 @@ function fileas_widget($baseurl,$selected = '') {
$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]));
$terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : '')); $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : ''));
} }
@ -173,8 +173,8 @@ 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]));
$terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : '')); $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : ''));
} }
@ -195,29 +195,29 @@ 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;
if(is_array($_SESSION['remote'])) { if (is_array($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $visitor) { foreach ($_SESSION['remote'] as $visitor) {
if($visitor['uid'] == $profile_uid) { if ($visitor['uid'] == $profile_uid) {
$cid = $visitor['cid']; $cid = $visitor['cid'];
break; break;
} }
} }
} }
if(! $cid) { if (! $cid) {
if(get_my_url()) { if (get_my_url()) {
$r = q("select id from contact where nurl = '%s' and uid = %d limit 1", $r = q("select id from contact where nurl = '%s' and uid = %d limit 1",
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 +227,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

@ -7,7 +7,7 @@ require_once("include/acl_selectors.php");
// Note: the code in 'item_extract_images' and 'item_redir_and_replace_images' // 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 // is identical to the code in mod/message.php for 'item_extract_images' and
// 'item_redir_and_replace_images' // '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) {
$saved_image = array(); $saved_image = array();
@ -18,12 +18,12 @@ function item_extract_images($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);
$img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : 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_st_close++; // make it point to AFTER the closing bracket
$img_end += $img_start; $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 // This is an embedded image
$saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close)); $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]')); $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');
@ -49,7 +49,7 @@ function item_extract_images($body) {
return array('body' => $new_body, 'images' => $saved_image); 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) { function item_redir_and_replace_images($body, $images, $cid) {
$origbody = $body; $origbody = $body;
@ -57,7 +57,7 @@ function item_redir_and_replace_images($body, $images, $cid) {
$cnt = 1; $cnt = 1;
$pos = get_bb_tag_pos($origbody, 'url', 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'; $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
$replace = '[url=' . z_path() . '/redir/' . $cid $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']); $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);
@ -96,7 +96,7 @@ function item_redir_and_replace_images($body, $images, $cid) {
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']);
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
@ -126,7 +126,7 @@ function localize_item(&$item){
} }
break; break;
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];
@ -137,19 +137,19 @@ function localize_item(&$item){
$plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]'; $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'); $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'); $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'); $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'); $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'); $bodyverb = t('%1$s attends maybe %2$s\'s %3$s');
} }
$item['body'] = sprintf($bodyverb, $author, $objauthor, $plink); $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
@ -187,7 +187,7 @@ function localize_item(&$item){
} }
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;
@ -229,7 +229,7 @@ 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'];
@ -262,7 +262,7 @@ function localize_item(&$item){
} }
break; break;
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];
@ -289,7 +289,7 @@ function localize_item(&$item){
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
$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'])
@ -307,16 +307,16 @@ function localize_item(&$item){
} }
} }
$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";
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]'; $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']); $item['body'] = bb_tag_preg_replace($photo_pattern, $photo_replace, 'url', $item['body']);
} }
@ -343,9 +343,9 @@ function localize_item(&$item){
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);
} }
@ -360,14 +360,14 @@ function visible_activity($item) {
// in which case we handle them specially // 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)) {
return false; return false;
} }
} }
if(activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) { if (activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
if(! (($item['self']) && ($item['uid'] == local_user()))) { if (! (($item['self']) && ($item['uid'] == local_user()))) {
return false; return false;
} }
} }
@ -465,7 +465,7 @@ function item_condition() {
* *
*/ */
if(!function_exists('conversation')) { 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');
@ -480,22 +480,23 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$arr_blocked = null; $arr_blocked = null;
if(local_user()) { if (local_user()) {
$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]);
}
} }
} }
$previewing = (($preview) ? ' preview ' : ''); $previewing = (($preview) ? ' preview ' : '');
if($mode === 'network') { if ($mode === 'network') {
$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. // 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 // We only launch liveUpdate if you aren't filtering in some incompatible
// way and also you aren't writing a comment (discovered in javascript). // way and also you aren't writing a comment (discovered in javascript).
@ -520,14 +521,14 @@ 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";
} }
} }
else if($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);
if(!$update) { if (!$update) {
$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, // 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. // because browser prefetching might change it on us. We have to deliver it with the page.
@ -537,40 +538,40 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
} }
} }
} }
else if($mode === 'notes') { else if ($mode === 'notes') {
$profile_owner = local_user(); $profile_owner = local_user();
$page_writeable = true; $page_writeable = true;
if(!$update) { if (!$update) {
$live_update_div = '<div id="live-notes"></div>' . "\r\n" $live_update_div = '<div id="live-notes"></div>' . "\r\n"
. "<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";
} }
} }
else if($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) {
$live_update_div = '<div id="live-display"></div>' . "\r\n" $live_update_div = '<div id="live-display"></div>' . "\r\n"
. "<script> var profile_uid = " . $_SESSION['uid'] . ";" . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
. " var profile_page = 1; </script>"; . " var profile_page = 1; </script>";
} }
} }
else if($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";
} }
} }
else if($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;
@ -594,9 +595,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$page_template = get_markup_template("conversation.tpl"); $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 // "New Item View" on network page or search page results
// - just loop through the items and format them minimally for display // - just loop through the items and format them minimally for display
@ -604,17 +605,17 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
// $tpl = get_markup_template('search_item.tpl'); // $tpl = get_markup_template('search_item.tpl');
$tpl = 'search_item.tpl'; $tpl = 'search_item.tpl';
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;
} }
@ -626,8 +627,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$owner_name = ''; $owner_name = '';
$sparkle = ''; $sparkle = '';
if($mode === 'search' || $mode === 'community') { if ($mode === 'search' || $mode === 'community') {
if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) if (((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
&& ($item['id'] != $item['parent'])) && ($item['id'] != $item['parent']))
continue; continue;
$nickname = $item['nickname']; $nickname = $item['nickname'];
@ -636,11 +637,11 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$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'];
@ -652,7 +653,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`", $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)); intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));
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"]);
@ -669,9 +670,9 @@ 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) if ($sp)
$sparkle = ' sparkle'; $sparkle = ' sparkle';
else else
$profile_link = zrl($profile_link); $profile_link = zrl($profile_link);
@ -698,7 +699,7 @@ 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;
@ -723,7 +724,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
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') {
$profile_name_e = template_escape($profile_name); $profile_name_e = template_escape($profile_name);
$item['title_e'] = template_escape($item['title']); $item['title_e'] = template_escape($item['title']);
$body_e = template_escape($body); $body_e = template_escape($body);
@ -818,18 +819,18 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
// But for now, this array respects the old style, just in case // 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;
} }
@ -839,10 +840,10 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
builtin_activity_puller($item, $conv_responses); builtin_activity_puller($item, $conv_responses);
// Only add what is visible // Only add what is visible
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;
} }
@ -850,7 +851,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$item['pagedrop'] = $page_dropping; $item['pagedrop'] = $page_dropping;
if($item['id'] == $item['parent']) { if ($item['id'] == $item['parent']) {
$item_object = new Item($item); $item_object = new Item($item);
$conv->add_thread($item_object); $conv->add_thread($item_object);
} }
@ -858,7 +859,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$threads = $conv->get_template_data($conv_responses); $threads = $conv->get_template_data($conv_responses);
if(!$threads) { if (!$threads) {
logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG); logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
$threads = array(); $threads = array();
} }
@ -894,8 +895,8 @@ function best_link_url($item,&$sparkle,$ssl_state = false) {
$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'];
@ -910,7 +911,7 @@ function item_photo_menu($item)
{ {
$ssl_state = false; $ssl_state = false;
if(local_user()) { if (local_user()) {
$ssl_state = true; $ssl_state = true;
} }
@ -944,7 +945,7 @@ function item_photo_menu($item)
$rel = $r[0]['rel']; $rel = $r[0]['rel'];
} }
if($sparkle) { if ($sparkle) {
$status_link = $profile_link . '?url=status'; $status_link = $profile_link . '?url=status';
$photos_link = $profile_link . '?url=photos'; $photos_link = $profile_link . '?url=photos';
$profile_link = $profile_link . '?url=profile'; $profile_link = $profile_link . '?url=profile';
@ -1012,9 +1013,9 @@ 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')) { 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 = '';
$sparkle = ''; $sparkle = '';
@ -1039,9 +1040,9 @@ function builtin_activity_puller($item, &$conv_responses) {
break; break;
} }
if((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) { if ((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) {
$url = $item['author-link']; $url = $item['author-link'];
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" ';
} }
@ -1050,18 +1051,18 @@ function builtin_activity_puller($item, &$conv_responses) {
$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']] ++;
@ -1085,12 +1086,12 @@ function builtin_activity_puller($item, &$conv_responses) {
// $id = item id // $id = item id
// returns formatted text // returns formatted text
if(! function_exists('format_like')) { if (! function_exists('format_like')) {
function format_like($cnt,$arr,$type,$id) { function format_like($cnt,$arr,$type,$id) {
$o = ''; $o = '';
$expanded = ''; $expanded = '';
if($cnt == 1) { if ($cnt == 1) {
$likers = $arr[0]; $likers = $arr[0];
// Phrase if there is only one liker. In other cases it will be uses for the expanded // Phrase if there is only one liker. In other cases it will be uses for the expanded
@ -1114,16 +1115,16 @@ 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);
$str = implode(', ', $arr2) . ' ' . $last; $str = implode(', ', $arr2) . ' ' . $last;
} }
if($total >= MAX_LIKERS) { if ($total >= MAX_LIKERS) {
$str = implode(', ', $arr); $str = implode(', ', $arr);
$str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS ); $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
} }
@ -1211,17 +1212,17 @@ 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 ($_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 // 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 // It looks like it's from the index.php?q=[etc] rewrite that the web
// server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
if(strpos($query_str, '?') === false) 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';
@ -1302,20 +1303,20 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
function get_item_children($arr, $parent) { function get_item_children($arr, $parent) {
$children = array(); $children = array();
$a = get_app(); $a = get_app();
foreach($arr as $item) { foreach ($arr as $item) {
if($item['id'] != $item['parent']) { if ($item['id'] != $item['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;
} }
} }
else if($item['parent'] == $parent['id']) { else if ($item['parent'] == $parent['id']) {
$children[] = $item; $children[] = $item;
} }
} }
@ -1326,8 +1327,8 @@ function get_item_children($arr, $parent) {
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');
foreach($result as $k => $i) { foreach ($result as $k => $i) {
if(count($result[$k]['children'])) { if (count($result[$k]['children'])) {
$result[$k]['children'] = sort_item_children($result[$k]['children']); $result[$k]['children'] = sort_item_children($result[$k]['children']);
} }
} }
@ -1335,17 +1336,19 @@ function sort_item_children($items) {
} }
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);
}
} }
} }
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();
@ -1353,35 +1356,42 @@ function conv_sort($arr,$order) {
// This is a preparation for having two different items with the same uri in one thread // 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 will otherwise lead to an endless loop.
foreach($arr as $x) foreach ($arr as $x) {
if (!isset($newarr[$x['uri']])) 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);
}
}
/*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);
if($p !== false) if ($p !== false)
$parents[$p]['children'][] = $x; $parents[$p]['children'][] = $x;
} }
}*/ }*/
if(count($parents)) { if (count($parents)) {
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']);
/*$y = $parents[$k]['children']; /*$y = $parents[$k]['children'];
usort($y,'sort_thr_created_rev'); usort($y,'sort_thr_created_rev');
@ -1391,13 +1401,14 @@ function conv_sort($arr,$order) {
} }
$ret = array(); $ret = array();
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);
/*foreach($x['children'] as $y) /*foreach ($x['children'] as $y)
$ret[] = $y;*/ $ret[] = $y;*/
}
} }
} }
@ -1418,9 +1429,11 @@ function sort_thr_commented($a,$b) {
} }
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;
} }
@ -1434,17 +1447,16 @@ function render_location_dummy($item) {
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) {
$ret[$v] = array(); $ret[$v] = array();
$ret[$v]['count'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri']] : ''); $ret[$v]['count'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri']] : '');
$ret[$v]['list'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri'] . '-l'] : ''); $ret[$v]['list'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri'] . '-l'] : '');
$ret[$v]['self'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri'] . '-self'] : '0'); $ret[$v]['self'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri'] . '-self'] : '0');
if(count($ret[$v]['list']) > MAX_LIKERS) { if (count($ret[$v]['list']) > MAX_LIKERS) {
$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']);
@ -1452,9 +1464,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;

View File

@ -18,9 +18,10 @@ 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()) {
logger('cron intervall not reached'); logger('cron intervall not reached');
return; return;
} }
@ -65,7 +66,7 @@ function cron_run(&$argv, &$argc){
$d1 = get_config('system','last_expire_day'); $d1 = get_config('system','last_expire_day');
$d2 = intval(datetime_convert('UTC','UTC','now','d')); $d2 = intval(datetime_convert('UTC','UTC','now','d'));
if($d2 != intval($d1)) { if ($d2 != intval($d1)) {
proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_contact_birthdays"); proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_contact_birthdays");
@ -170,7 +171,7 @@ function cron_poll_contacts($argc, $argv) {
continue; continue;
} }
foreach($res as $contact) { foreach ($res as $contact) {
$xml = false; $xml = false;
@ -192,7 +193,7 @@ function cron_poll_contacts($argc, $argv) {
$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;
@ -204,28 +205,28 @@ function cron_poll_contacts($argc, $argv) {
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")) {
$update = true; $update = true;
} }
break; break;
case 4: case 4:
if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 week")) { if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 week")) {
$update = true; $update = true;
} }
break; break;
case 3: case 3:
if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) { if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) {
$update = true; $update = true;
} }
break; break;
case 2: case 2:
if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 12 hour")) { if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 12 hour")) {
$update = true; $update = true;
} }
break; break;
case 1: case 1:
default: default:
if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 hour")) { if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 hour")) {
$update = true; $update = true;
} }
break; break;
@ -242,6 +243,10 @@ function cron_poll_contacts($argc, $argv) {
} else { } else {
proc_run(PRIORITY_LOW, 'include/onepoll.php', intval($contact['id'])); proc_run(PRIORITY_LOW, 'include/onepoll.php', intval($contact['id']));
} }
if ($interval) {
time_sleep_until(microtime(true) + (float) $interval);
}
} }
} }
} }

View File

@ -8,23 +8,25 @@ function cronhooks_run(&$argv, &$argc){
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);
if($next > time()) { if ($next > time()) {
logger('cronhook intervall not reached'); logger('cronhook intervall not reached');
return; return;
} }