gcontact update script, rebuilt follow page, query speedup for community and network groups
This commit is contained in:
parent
6703ba468a
commit
885dc1df81
13 changed files with 287 additions and 102 deletions
|
@ -143,14 +143,13 @@ function community_getpublicitems($start, $itemspage) {
|
|||
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
|
||||
`author-name` AS `name`, `owner-avatar` AS `photo`,
|
||||
`owner-link` AS `url`, `owner-avatar` AS `thumb`
|
||||
FROM `item` WHERE `item`.`uid` = 0 AND `item`.`id` = `item`.`parent`
|
||||
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
|
||||
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
|
||||
ORDER BY `item`.`received` DESC LIMIT %d, %d",
|
||||
FROM `thread`
|
||||
INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
|
||||
WHERE `thread`.`uid` = 0
|
||||
ORDER BY `thread`.`created` DESC LIMIT %d, %d",
|
||||
intval($start),
|
||||
intval($itemspage)
|
||||
);
|
||||
|
||||
return($r);
|
||||
|
||||
}
|
||||
|
|
|
@ -345,7 +345,6 @@ function _contact_archive($contact_id, $orig_record) {
|
|||
return $r;
|
||||
}
|
||||
function _contact_drop($contact_id, $orig_record) {
|
||||
require_once('include/Contact.php');
|
||||
$a = get_app();
|
||||
|
||||
terminate_friendship($a->user,$a->contact,$orig_record);
|
||||
|
@ -890,50 +889,24 @@ function contacts_tab($a, $contact_id, $active_tab) {
|
|||
|
||||
function contact_posts($a, $contact_id) {
|
||||
|
||||
require_once('include/conversation.php');
|
||||
|
||||
$r = q("SELECT * FROM `contact` WHERE `id` = %d", intval($contact_id));
|
||||
$r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
|
||||
if ($r) {
|
||||
$contact = $r[0];
|
||||
$a->page['aside'] = "";
|
||||
profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
|
||||
}
|
||||
|
||||
if(get_config('system', 'old_pager')) {
|
||||
$r = q("SELECT COUNT(*) AS `total` FROM `item`
|
||||
WHERE `item`.`uid` = %d AND `author-link` IN ('%s', '%s')",
|
||||
intval(local_user()),
|
||||
dbesc(str_replace("https://", "http://", $contact["url"])),
|
||||
dbesc(str_replace("http://", "https://", $contact["url"])));
|
||||
|
||||
$a->set_pager_total($r[0]['total']);
|
||||
}
|
||||
|
||||
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
|
||||
`author-name` AS `name`, `owner-avatar` AS `photo`,
|
||||
`owner-link` AS `url`, `owner-avatar` AS `thumb`
|
||||
FROM `item` FORCE INDEX (uid_contactid_created)
|
||||
WHERE `item`.`uid` = %d AND `contact-id` = %d
|
||||
AND `author-link` IN ('%s', '%s')
|
||||
ORDER BY `item`.`created` DESC LIMIT %d, %d",
|
||||
intval(local_user()),
|
||||
intval($contact_id),
|
||||
dbesc(str_replace("https://", "http://", $contact["url"])),
|
||||
dbesc(str_replace("http://", "https://", $contact["url"])),
|
||||
intval($a->pager['start']),
|
||||
intval($a->pager['itemspage'])
|
||||
);
|
||||
} else
|
||||
$profile = "";
|
||||
|
||||
$tab_str = contacts_tab($a, $contact_id, 1);
|
||||
|
||||
$o .= $tab_str;
|
||||
|
||||
$o .= conversation($a,$r,'community',false);
|
||||
if ($contact["url"]) {
|
||||
$r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
|
||||
dbesc(normalise_link($contact["url"])));
|
||||
|
||||
if(!get_config('system', 'old_pager')) {
|
||||
$o .= alt_pager($a,count($r));
|
||||
} else {
|
||||
$o .= paginate($a);
|
||||
if ($r[0]["id"] <> 0)
|
||||
$o .= posts_from_gcontact($a, $r[0]["id"]);
|
||||
}
|
||||
|
||||
return $o;
|
||||
|
|
|
@ -154,49 +154,48 @@ function display_fetchauthor($a, $item) {
|
|||
$profiledata["about"] = "";
|
||||
}
|
||||
|
||||
// Don't show details from Diaspora contacts if you don't follow the contact
|
||||
$showdetails = ($profiledata["network"] != NETWORK_DIASPORA);
|
||||
|
||||
// Fetching further contact data from the contact table
|
||||
$r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` = '%s'",
|
||||
dbesc(normalise_link($profiledata["url"])), intval($item["uid"]), dbesc($item["network"]));
|
||||
|
||||
$r = q("SELECT `uid`, `network`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords`
|
||||
FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)",
|
||||
dbesc(normalise_link($profiledata["url"])), intval($item["uid"]), dbesc($item["network"]),
|
||||
intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
|
||||
if (!count($r))
|
||||
$r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
|
||||
dbesc(normalise_link($profiledata["url"])), intval($item["uid"]));
|
||||
|
||||
if (!count($r))
|
||||
$r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
|
||||
dbesc(normalise_link($profiledata["url"])));
|
||||
$r = q("SELECT `uid`, `network`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords`
|
||||
FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `rel` IN (%d, %d)",
|
||||
dbesc(normalise_link($profiledata["url"])), intval($item["uid"]),
|
||||
intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
|
||||
|
||||
if (count($r)) {
|
||||
if ((($r[0]["uid"] != local_user()) OR !local_user()) AND ($profiledata["network"] == NETWORK_DIASPORA)) {
|
||||
$r[0]["location"] = "";
|
||||
$r[0]["about"] = "";
|
||||
}
|
||||
|
||||
$profiledata["photo"] = $r[0]["photo"];
|
||||
$profiledata["address"] = $r[0]["location"];
|
||||
$profiledata["about"] = $r[0]["about"];
|
||||
if ($r[0]["nick"] != "")
|
||||
$profiledata["nickname"] = $r[0]["nick"];
|
||||
$profiledata["nickname"] = $r[0]["nick"];
|
||||
$profiledata["addr"] = $r[0]["addr"];
|
||||
$profiledata["keywords"] = $r[0]["keywords"];
|
||||
|
||||
if (($r[0]["uid"] != 0) OR $showdetails) {
|
||||
$showdetails = true;
|
||||
$profiledata["address"] = $r[0]["location"];
|
||||
$profiledata["about"] = $r[0]["about"];
|
||||
$profiledata["gender"] = $r[0]["gender"];
|
||||
}
|
||||
}
|
||||
|
||||
// Fetching profile data from global contacts
|
||||
if ($profiledata["network"] != NETWORK_FEED) {
|
||||
$r = q("SELECT `photo`, `nick`, `addr`, `location`, `about`, `gender` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"])));
|
||||
$r = q("SELECT `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"])));
|
||||
if (count($r)) {
|
||||
if ($r[0]["avatar"] != "")
|
||||
$profiledata["photo"] = $r[0]["avatar"];
|
||||
if (($r[0]["location"] != "") AND ($profiledata["network"] != NETWORK_DIASPORA))
|
||||
$profiledata["photo"] = $r[0]["photo"];
|
||||
$profiledata["nickname"] = $r[0]["nick"];
|
||||
$profiledata["addr"] = $r[0]["addr"];
|
||||
$profiledata["keywords"] = $r[0]["keywords"];
|
||||
|
||||
if ($showdetails) {
|
||||
$profiledata["address"] = $r[0]["location"];
|
||||
if (($r[0]["about"] != "") AND ($profiledata["network"] != NETWORK_DIASPORA))
|
||||
$profiledata["about"] = $r[0]["about"];
|
||||
if (($r[0]["nick"] != "") AND ($r[0]["nick"] != ""))
|
||||
$profiledata["nickname"] = $r[0]["nick"];
|
||||
if ($r[0]["gender"] != "")
|
||||
$profiledata["gender"] = $r[0]["gender"];
|
||||
if ($r[0]["addr"] != "")
|
||||
$profiledata["addr"] = $r[0]["addr"];
|
||||
if ($r[0]["keywords"] != "")
|
||||
$profiledata["keywords"] = $r[0]["keywords"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
require_once('include/Scrape.php');
|
||||
require_once('include/follow.php');
|
||||
require_once('include/Contact.php');
|
||||
require_once('include/contact_selectors.php');
|
||||
|
||||
function follow_content(&$a) {
|
||||
|
@ -75,15 +76,18 @@ function follow_content(&$a) {
|
|||
}
|
||||
|
||||
$myaddr = $r[0]["url"];
|
||||
$gcontact_id = 0;
|
||||
|
||||
// Makes the connection request for friendica contacts easier
|
||||
$_SESSION["fastlane"] = $ret["url"];
|
||||
|
||||
$r = q("SELECT `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
|
||||
$r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
|
||||
normalise_link($ret["url"]));
|
||||
|
||||
if (!$r)
|
||||
$r = array(array("location" => "", "about" => "", "keywords" => ""));
|
||||
else
|
||||
$gcontact_id = $r[0]["id"];
|
||||
|
||||
if($ret['network'] === NETWORK_DIASPORA) {
|
||||
$r[0]["location"] = "";
|
||||
|
@ -95,11 +99,12 @@ function follow_content(&$a) {
|
|||
if ($ret["addr"] != "")
|
||||
$header .= " <".$ret["addr"].">";
|
||||
|
||||
$header .= " (".network_to_name($ret['network'], $ret['url']).")";
|
||||
//$header .= " (".network_to_name($ret['network'], $ret['url']).")";
|
||||
$header = t("Connect/Follow");
|
||||
|
||||
$o = replace_macros($tpl,array(
|
||||
'$header' => htmlentities($header),
|
||||
'$photo' => proxy_url($ret["photo"], false, PROXY_SIZE_SMALL),
|
||||
//'$photo' => proxy_url($ret["photo"], false, PROXY_SIZE_SMALL),
|
||||
'$desc' => "",
|
||||
'$pls_answer' => t('Please answer the following:'),
|
||||
'$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'),$ret["name"]), false, '', array(t('No'),t('Yes'))),
|
||||
|
@ -121,13 +126,26 @@ function follow_content(&$a) {
|
|||
'$url_label' => t("Profile URL"),
|
||||
'$myaddr' => $myaddr,
|
||||
'$request' => $request,
|
||||
'$location' => bbcode($r[0]["location"]),
|
||||
/*'$location' => bbcode($r[0]["location"]),
|
||||
'$location_label' => t("Location:"),
|
||||
'$about' => bbcode($r[0]["about"], false, false),
|
||||
'$about_label' => t("About:"),
|
||||
'$about_label' => t("About:"), */
|
||||
'$keywords' => $r[0]["keywords"],
|
||||
'$keywords_label' => t("Tags:")
|
||||
));
|
||||
|
||||
$a->page['aside'] = "";
|
||||
profile_load($a, "", 0, get_contact_details_by_url($ret["url"]));
|
||||
|
||||
// Show last public posts
|
||||
if ($gcontact_id <> 0) {
|
||||
$o .= replace_macros(get_markup_template('section_title.tpl'),
|
||||
array('$title' => t('Status Messages and Posts')
|
||||
));
|
||||
|
||||
$o .= posts_from_gcontact($a, $gcontact_id);
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
|
|
@ -312,6 +312,9 @@ function network_content(&$a, $update = 0) {
|
|||
return login(false);
|
||||
}
|
||||
|
||||
// Rawmode is used for fetching new content at the end of the page
|
||||
$rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
|
||||
|
||||
/// @TODO Is this really necessary? $a is already available to hooks
|
||||
$arr = array('query' => $a->query_string);
|
||||
call_hooks('network_content_init', $arr);
|
||||
|
@ -470,7 +473,7 @@ function network_content(&$a, $update = 0) {
|
|||
}
|
||||
set_pconfig(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all'));
|
||||
|
||||
if(! $update) {
|
||||
if(!$update AND !$rawmode) {
|
||||
if($group) {
|
||||
if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
|
||||
notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
|
||||
|
@ -549,27 +552,30 @@ function network_content(&$a, $update = 0) {
|
|||
}
|
||||
|
||||
$contacts = expand_groups(array($group));
|
||||
|
||||
$contact_str_self = "";
|
||||
$gcontacts = expand_groups(array($group), false, true);
|
||||
|
||||
if((is_array($contacts)) && count($contacts)) {
|
||||
$contact_str_self = "";
|
||||
$gcontact_str_self = "";
|
||||
|
||||
$contact_str = implode(',',$contacts);
|
||||
$self = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($_SESSION['uid']));
|
||||
if (count($self))
|
||||
$contact_str_self = ",".$self[0]["id"];
|
||||
}
|
||||
else {
|
||||
$contact_str = ' 0 ';
|
||||
$gcontact_str = implode(',',$gcontacts);
|
||||
$self = q("SELECT `contact`.`id`, `gcontact`.`id` AS `gid` FROM `contact`
|
||||
INNER JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
|
||||
WHERE `uid` = %d AND `self`", intval($_SESSION['uid']));
|
||||
if (count($self)) {
|
||||
$contact_str_self = $self[0]["id"];
|
||||
$gcontact_str_self = $self[0]["gid"];
|
||||
}
|
||||
|
||||
$sql_post_table = " INNER JOIN `item` AS `temp1` ON `temp1`.`id` = ".$sql_table.".".$sql_parent;
|
||||
$sql_extra3 .= " AND ($sql_table.`contact-id` IN ($contact_str) ";
|
||||
$sql_extra3 .= " OR ($sql_table.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '".protect_sprintf('%<'.intval($group).'>%')."' AND `temp1`.`private`))";
|
||||
} else {
|
||||
$sql_extra3 .= " AND false ";
|
||||
info( t('Group is empty'));
|
||||
}
|
||||
|
||||
//$sql_post_table = " INNER JOIN (SELECT DISTINCT(`parent`) FROM `item` WHERE (`contact-id` IN ($contact_str) OR `allow_gid` like '".protect_sprintf('%<'.intval($group).'>%')."') and deleted = 0 ORDER BY `created` DESC) AS `temp1` ON $sql_table.$sql_parent = `temp1`.`parent` ";
|
||||
|
||||
$sql_extra3 .= " AND $sql_table.`contact-id` IN ($contact_str$contact_str_self) ";
|
||||
$sql_extra3 .= " AND EXISTS (SELECT `id` FROM `item` WHERE (`contact-id` IN ($contact_str)
|
||||
OR `allow_gid` LIKE '".protect_sprintf('%<'.intval($group).'>%')."') AND `deleted` = 0
|
||||
AND `id` = $sql_table.$sql_parent) ";
|
||||
|
||||
$o = replace_macros(get_markup_template("section_title.tpl"),array(
|
||||
'$title' => sprintf( t('Group: %s'), $r[0]['name'])
|
||||
)) . $o;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue