From 885dc1df81c9ab752f9f5d66894786944184a9c9 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 10 Jan 2016 09:19:00 +0100 Subject: [PATCH] gcontact update script, rebuilt follow page, query speedup for community and network groups --- include/Contact.php | 162 ++++++++++++++++++++++++++++++++++++++ include/acl_selectors.php | 15 +++- include/cron.php | 5 +- include/dbstructure.php | 4 +- include/group.php | 17 +++- include/identity.php | 3 + include/threads.php | 2 +- mod/community.php | 9 +-- mod/contacts.php | 43 ++-------- mod/display.php | 59 +++++++------- mod/follow.php | 28 +++++-- mod/network.php | 38 +++++---- view/global.css | 4 + 13 files changed, 287 insertions(+), 102 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 3185e87348..5aaaa11bff 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -500,3 +500,165 @@ function get_contact($url, $uid = 0) { return $contactid; } + +/** + * @brief Returns posts from a given gcontact + * + * @param App $a argv application class + * @param int $gcontact_id Global contact + * + * @return string posts in HTML + */ +function posts_from_gcontact($a, $gcontact_id) { + + require_once('include/conversation.php'); + + // There are no posts with "uid = 0" with connector networks + // This speeds up the query a lot + $r = q("SELECT `network` FROM `gcontact` WHERE `id` = %d", dbesc($gcontact_id)); + if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""))) + $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND `item`.`private`))"; + else + $sql = "`item`.`uid` = %d"; + + if(get_config('system', 'old_pager')) { + $r = q("SELECT COUNT(*) AS `total` FROM `item` + WHERE `gcontact-id` = %d and $sql", + intval($gcontact_id), + intval(local_user())); + + $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` + WHERE `gcontact-id` = %d AND $sql AND + NOT `deleted` AND NOT `moderated` AND `visible` + ORDER BY `item`.`created` DESC LIMIT %d, %d", + intval($gcontact_id), + intval(local_user()), + intval($a->pager['start']), + intval($a->pager['itemspage']) + ); + + $o = conversation($a,$r,'community',false); + + if(!get_config('system', 'old_pager')) { + $o .= alt_pager($a,count($r)); + } else { + $o .= paginate($a); + } + + return $o; +} + +/** + * @brief set the gcontact-id in all item entries + * + * This job has to be started multiple times until all entries are set. + * It isn't started in the update function since it would consume too much time and can be done in the background. + */ +function item_set_gcontact() { + define ('POST_UPDATE_VERSION', 1192); + + // Was the script completed? + if (get_config("system", "post_update_version") >= POST_UPDATE_VERSION) + return; + + // Check if the first step is done (Setting "gcontact-id" in the item table) + $r = q("SELECT `author-link`, `author-name`, `author-avatar`, `uid`, `network` FROM `item` WHERE `gcontact-id` = 0 LIMIT 1000"); + if (!$r) { + // Are there unfinished entries in the thread table? + $r = q("SELECT COUNT(*) AS `total` FROM `thread` + INNER JOIN `item` ON `item`.`id` =`thread`.`iid` + WHERE `thread`.`gcontact-id` = 0 AND + (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)"); + + if ($r AND ($r[0]["total"] == 0)) { + set_config("system", "post_update_version", POST_UPDATE_VERSION); + return false; + } + + // Update the thread table from the item table + q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid` + SET `thread`.`gcontact-id` = `item`.`gcontact-id` + WHERE `thread`.`gcontact-id` = 0 AND + (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)"); + + return false; + } + + $item_arr = array(); + foreach ($r AS $item) { + $index = $item["author-link"]."-".$item["uid"]; + $item_arr[$index] = array("author-link" => $item["author-link"], + "uid" => $item["uid"], + "network" => $item["network"]); + } + + // Set the "gcontact-id" in the item table and add a new gcontact entry if needed + foreach($item_arr AS $item) { + $gcontact_id = get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'], + "photo" => $item['author-avatar'], "name" => $item['author-name'])); + q("UPDATE `item` SET `gcontact-id` = %d WHERE `uid` = %d AND `author-link` = '%s' AND `gcontact-id` = 0", + intval($gcontact_id), intval($item["uid"]), dbesc($item["author-link"])); + } + return true; +} + +/** + * @brief Returns posts from a given contact + * + * @param App $a argv application class + * @param int $contact_id contact + * + * @return string posts in HTML + */ +function posts_from_contact($a, $contact_id) { + + require_once('include/conversation.php'); + + $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id)); + if (!$r) + return false; + + $contact = $r[0]; + + 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') + AND NOT `deleted` AND NOT `moderated` AND `visible` + 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']) + ); + + $o .= conversation($a,$r,'community',false); + + if(!get_config('system', 'old_pager')) + $o .= alt_pager($a,count($r)); + else + $o .= paginate($a); + + return $o; +} +?> diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 4ef3d05ea3..d5730a93a9 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -407,7 +407,7 @@ function acl_lookup(&$a, $out_type = 'json') { $search = $_REQUEST['query']; } -// logger("Searching for ".$search." - type ".$type, LOGGER_DEBUG); + logger("Searching for ".$search." - type ".$type, LOGGER_DEBUG); if ($search!=""){ $sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'"; @@ -503,7 +503,7 @@ function acl_lookup(&$a, $out_type = 'json') { } } - if ($type=='' || $type=='c'){ + if ($type==''){ $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, forum FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != '' @@ -514,6 +514,17 @@ function acl_lookup(&$a, $out_type = 'json') { dbesc(NETWORK_OSTATUS), dbesc(NETWORK_STATUSNET) ); } + elseif ($type=='c'){ + + $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, forum FROM `contact` + WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != '' + AND NOT (`network` IN ('%s')) + $sql_extra2 + ORDER BY `name` ASC ", + intval(local_user()), + dbesc(NETWORK_STATUSNET) + ); + } elseif($type == 'm') { $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 diff --git a/include/cron.php b/include/cron.php index a6e81f6bfd..b1db9278af 100644 --- a/include/cron.php +++ b/include/cron.php @@ -133,9 +133,8 @@ function cron_run(&$argv, &$argc){ // Check every conversation check_conversations(false); - // Follow your friends from your legacy OStatus account - // Doesn't work - // ostatus_check_follow_friends(); + // Set the gcontact-id in the item table if missing + item_set_gcontact(); // update nodeinfo data nodeinfo_cron(); diff --git a/include/dbstructure.php b/include/dbstructure.php index 4b2cdb251c..7fed50e741 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -877,7 +877,7 @@ function db_definition() { "uid_thrparent" => array("uid","thr-parent"), "uid_parenturi" => array("uid","parent-uri"), "uid_contactid_created" => array("uid","contact-id","created"), - "uid_gcontactid_created" => array("uid","gcontact-id","created"), + "gcontactid_uid_created" => array("gcontact-id","uid","created"), "wall_body" => array("wall","body(6)"), "uid_visible_moderated_created" => array("uid","visible","moderated","created"), "uid_uri" => array("uid","uri"), @@ -1324,6 +1324,8 @@ function db_definition() { "uid_network_created" => array("uid","network","created"), "uid_contactid_commented" => array("uid","contact-id","commented"), "uid_contactid_created" => array("uid","contact-id","created"), + "uid_gcontactid_commented" => array("uid","gcontact-id","commented"), + "uid_gcontactid_created" => array("uid","gcontact-id","created"), "wall_private_received" => array("wall","private","received"), "uid_created" => array("uid","created"), "uid_commented" => array("uid","commented"), diff --git a/include/group.php b/include/group.php index fd1c97dfde..a1375e00df 100644 --- a/include/group.php +++ b/include/group.php @@ -297,17 +297,26 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro return $o; } -function expand_groups($a,$check_dead = false) { +function expand_groups($a,$check_dead = false, $use_gcontact = false) { if(! (is_array($a) && count($a))) return array(); $groups = implode(',', $a); $groups = dbesc($groups); - $r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )"); + + if ($use_gcontact) + $r = q("SELECT `gcontact`.`id` AS `contact-id` FROM `group_member` + INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` + INNER JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl` + WHERE `gid` IN ($groups)"); + else + $r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )"); + + $ret = array(); if(count($r)) foreach($r as $rr) $ret[] = $rr['contact-id']; - if($check_dead) { + if($check_dead AND !$use_gcontact) { require_once('include/acl_selectors.php'); $ret = prune_deadguys($ret); } @@ -366,4 +375,4 @@ function groups_count_unseen() { ); return $r; -} \ No newline at end of file +} diff --git a/include/identity.php b/include/identity.php index fb405b90f1..fdd28f81ce 100644 --- a/include/identity.php +++ b/include/identity.php @@ -300,6 +300,7 @@ function profile_sidebar($profile, $block = 0) { $account_type = ""; if((x($profile,'address') == 1) + || (x($profile,'location') == 1) || (x($profile,'locality') == 1) || (x($profile,'region') == 1) || (x($profile,'postal-code') == 1) @@ -368,6 +369,8 @@ function profile_sidebar($profile, $block = 0) { if (isset($p["address"])) $p["address"] = bbcode($p["address"]); + else + $p["address"] = bbcode($p["location"]); if (isset($p["photo"])) $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL); diff --git a/include/threads.php b/include/threads.php index a671846594..44a7e65384 100644 --- a/include/threads.php +++ b/include/threads.php @@ -111,7 +111,7 @@ function update_thread_uri($itemuri, $uid) { } function update_thread($itemid, $setmention = false) { - $items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, + $items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, 'gcontact-id`, `deleted`, `origin`, `forum_mode`, `network` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid)); if (!$items) diff --git a/mod/community.php b/mod/community.php index d6f87762bd..86bd18c869 100644 --- a/mod/community.php +++ b/mod/community.php @@ -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); - } diff --git a/mod/contacts.php b/mod/contacts.php index 0a8aad9d72..ac7c7d85a1 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -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; diff --git a/mod/display.php b/mod/display.php index 3a4674c323..41cad5c6a9 100644 --- a/mod/display.php +++ b/mod/display.php @@ -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"]; + } } } diff --git a/mod/follow.php b/mod/follow.php index cc08831285..b92a0d980f 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -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; } diff --git a/mod/network.php b/mod/network.php index 4b9493bc61..a12fa4ec36 100644 --- a/mod/network.php +++ b/mod/network.php @@ -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; diff --git a/view/global.css b/view/global.css index 05940508ca..900df53146 100644 --- a/view/global.css +++ b/view/global.css @@ -321,3 +321,7 @@ ul.credits li { .p-addr { clear: both; } + +#live-community { + clear: both; +}