From 6b8585d48d67d109102e33a32311d76a45762667 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 9 Mar 2014 09:19:14 +0100 Subject: [PATCH 01/27] Database stuff. New table "thread". Changing "left join" to "inner join", removing "limit 1" at update and delete. --- boot.php | 10 +- database.sql | 43 ++++++ include/api.php | 7 +- include/dba.php | 32 ++++- include/delivery.php | 4 +- include/diaspora.php | 54 ++++---- include/follow.php | 2 +- include/group.php | 6 +- include/items.php | 165 +++++++++++++--------- include/notifier.php | 4 +- include/onepoll.php | 2 +- include/poller.php | 2 +- include/profile_update.php | 2 +- include/queue.php | 2 +- include/queue_fn.php | 6 +- include/security.php | 22 +-- include/socgraph.php | 16 +-- include/tags.php | 30 +--- include/user.php | 2 +- mod/community.php | 31 ++--- mod/contacts.php | 8 +- mod/content.php | 8 +- mod/display.php | 8 +- mod/item.php | 14 +- mod/network.php | 276 ++++++++++++------------------------- mod/photos.php | 17 ++- mod/profile.php | 48 +++---- mod/profiles.php | 34 ++--- mod/pubsub.php | 6 +- mod/search.php | 17 +-- mod/share.php | 2 +- mod/wall_upload.php | 4 +- update.php | 47 ++++++- 33 files changed, 487 insertions(+), 444 deletions(-) diff --git a/boot.php b/boot.php index a784b37b0..55318e1ec 100644 --- a/boot.php +++ b/boot.php @@ -14,7 +14,7 @@ require_once('include/features.php'); define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_VERSION', '3.2.1748' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1169 ); +define ( 'DB_UPDATE_VERSION', 1170 ); define ( 'EOL', "
\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); @@ -739,7 +739,7 @@ if(! class_exists('App')) { if($this->cached_profile_picdate[$common_filename]){ $this->cached_profile_image[$avatar_image] = $avatar_image . $this->cached_profile_picdate[$common_filename]; } else { - $r = q("SELECT `contact`.`avatar-date` AS picdate FROM `contact` WHERE `contact`.`thumb` like \"%%/%s\"", + $r = q("SELECT `contact`.`avatar-date` AS picdate FROM `contact` WHERE `contact`.`thumb` like '%%/%s'", $common_filename); if(! count($r)){ $this->cached_profile_image[$avatar_image] = $avatar_image; @@ -1328,7 +1328,7 @@ if(! function_exists('profile_load')) { if($profile) { $profile_int = intval($profile); $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile` - left join `contact` on `contact`.`uid` = `profile`.`uid` LEFT JOIN `user` ON `profile`.`uid` = `user`.`uid` + INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid` WHERE `user`.`nickname` = '%s' AND `profile`.`id` = %d and `contact`.`self` = 1 LIMIT 1", dbesc($nickname), intval($profile_int) @@ -1336,7 +1336,7 @@ if(! function_exists('profile_load')) { } if((! $r) && (! count($r))) { $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile` - left join `contact` on `contact`.`uid` = `profile`.`uid` LEFT JOIN `user` ON `profile`.`uid` = `user`.`uid` + INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid` WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 and `contact`.`self` = 1 LIMIT 1", dbesc($nickname) ); @@ -1591,7 +1591,7 @@ if(! function_exists('get_birthdays')) { $bd_short = t('F d'); $r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event` - LEFT JOIN `contact` ON `contact`.`id` = `event`.`cid` + INNER JOIN `contact` ON `contact`.`id` = `event`.`cid` WHERE `event`.`uid` = %d AND `type` = 'birthday' AND `start` < '%s' AND `finish` > '%s' ORDER BY `start` ASC ", intval(local_user()), diff --git a/database.sql b/database.sql index 92805ef00..848005175 100644 --- a/database.sql +++ b/database.sql @@ -1192,3 +1192,46 @@ CREATE TABLE IF NOT EXISTS `unique_contacts` ( PRIMARY KEY (`id`), KEY `url` (`url`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `thread` +-- + +CREATE TABLE IF NOT EXISTS `thread` ( + `iid` int(10) unsigned NOT NULL DEFAULT '0', + `uid` int(10) unsigned NOT NULL DEFAULT '0', + `contact-id` int(10) unsigned NOT NULL DEFAULT '0', + `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `received` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `changed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `wall` tinyint(1) NOT NULL DEFAULT '0', + `private` tinyint(1) NOT NULL DEFAULT '0', + `pubmail` tinyint(1) NOT NULL DEFAULT '0', + `moderated` tinyint(1) NOT NULL DEFAULT '0', + `visible` tinyint(1) NOT NULL DEFAULT '0', + `spam` tinyint(1) NOT NULL DEFAULT '0', + `starred` tinyint(1) NOT NULL DEFAULT '0', + `bookmark` tinyint(1) NOT NULL DEFAULT '0', + `unseen` tinyint(1) NOT NULL DEFAULT '1', + `deleted` tinyint(1) NOT NULL DEFAULT '0', + `origin` tinyint(1) NOT NULL DEFAULT '0', + `forum_mode` tinyint(1) NOT NULL DEFAULT '0', + `mention` tinyint(1) NOT NULL DEFAULT '0', + `network` char(32) NOT NULL, + PRIMARY KEY (`iid`), + KEY `uid` (`uid`), + KEY `contact-id` (`contact-id`), + KEY `created` (`created`), + KEY `edited` (`edited`), + KEY `commented` (`commented`), + KEY `received` (`received`), + KEY `changed` (`changed`), + KEY `network` (`network`), + KEY `visible_deleted_moderated_private_wall_received` (`visible`,`deleted`,`moderated`,`private`,`wall`,`received`), + KEY `uid_visible_deleted_moderated_created` (`uid`,`visible`,`deleted`,`moderated`,`created`), + KEY `uid_visible_deleted_moderated_commented` (`uid`,`visible`,`deleted`,`moderated`,`commented`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/include/api.php b/include/api.php index d98ad970d..72a64f2ac 100644 --- a/include/api.php +++ b/include/api.php @@ -842,13 +842,14 @@ $lastwall = q("SELECT `item`.* FROM `item`, `contact` - WHERE `item`.`contact-id` = %d + WHERE `item`.`uid` = %d AND `item`.`contact-id` = %d AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s'))) AND `contact`.`id`=`item`.`contact-id` AND `type`!='activity' AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`='' ORDER BY `created` DESC LIMIT 1", + intval(api_user()), intval($user_info['cid']), dbesc($user_info['url']), dbesc(normalise_link($user_info['url'])), @@ -1041,8 +1042,8 @@ `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`, `user`.`nickname`, `user`.`hidewall` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` + FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + INNER JOIN `user` ON `user`.`uid` = `item`.`uid` WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' diff --git a/include/dba.php b/include/dba.php index 293cce578..b89f28c59 100644 --- a/include/dba.php +++ b/include/dba.php @@ -18,6 +18,7 @@ class dba { private $debug = 0; private $db; + private $result; public $mysqli = true; public $connected = false; public $error = false; @@ -75,7 +76,7 @@ class dba { return $this->db; } - public function q($sql) { + public function q($sql, $onlyquery = false) { global $a; if((! $this->db) || (! $this->connected)) @@ -154,6 +155,11 @@ class dba { if(($result === true) || ($result === false)) return $result; + if ($onlyquery) { + $this->result = $result; + return true; + } + $r = array(); if($this->mysqli) { if($result->num_rows) { @@ -177,6 +183,30 @@ class dba { return($r); } + public function qfetch() { + $x = false; + + if ($this->result) + if($this->mysqli) { + if($this->result->num_rows) + $x = $this->result->fetch_array(MYSQLI_ASSOC); + } else { + if(mysql_num_rows($this->result)) + $x = mysql_fetch_array($this->result, MYSQL_ASSOC); + } + + return($x); + } + + public function qclose() { + if ($this->result) + if($this->mysqli) { + $this->result->free_result(); + } else { + mysql_free_result($this->result); + } + } + public function dbg($dbg) { $this->debug = $dbg; } diff --git a/include/delivery.php b/include/delivery.php index 1de45255e..97f393311 100644 --- a/include/delivery.php +++ b/include/delivery.php @@ -157,7 +157,7 @@ function delivery_run(&$argv, &$argc){ $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`, `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, `user`.`page-flags`, `user`.`prvnets` - FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` + FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1", intval($uid) ); @@ -319,7 +319,7 @@ function delivery_run(&$argv, &$argc){ `contact`.`name` as `senderName`, `user`.* FROM `contact` - LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid` + INNER JOIN `user` ON `contact`.`uid` = `user`.`uid` WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`network` = '%s' AND `user`.`nickname` = '%s' $sql_extra diff --git a/include/diaspora.php b/include/diaspora.php index f8d72a2f8..e949f20e9 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -578,7 +578,7 @@ function diaspora_request($importer,$xml) { // That makes us friends. if($contact['rel'] == CONTACT_IS_FOLLOWER && $importer['page-flags'] != PAGE_COMMUNITY) { - q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1", + q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d", intval(CONTACT_IS_FRIEND), intval($contact['id']), intval($importer['uid']) @@ -733,7 +733,7 @@ function diaspora_request($importer,$xml) { `avatar-date` = '%s', `blocked` = 0, `pending` = 0 - WHERE `id` = %d LIMIT 1 + WHERE `id` = %d ", dbesc($photos[0]), dbesc($photos[1]), @@ -759,7 +759,7 @@ function diaspora_post_allow($importer,$contact) { // That makes us friends. // Normally this should have handled by getting a request - but this could get lost if($contact['rel'] == CONTACT_IS_FOLLOWER && $importer['page-flags'] != PAGE_COMMUNITY) { - q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1", + q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d", intval(CONTACT_IS_FRIEND), intval($contact['id']), intval($importer['uid']) @@ -895,7 +895,7 @@ function diaspora_post($importer,$xml,$msg) { $message_id = item_store($datarray); //if($message_id) { - // q("update item set plink = '%s' where id = %d limit 1", + // q("update item set plink = '%s' where id = %d", // dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id), // intval($message_id) // ); @@ -1071,7 +1071,7 @@ function diaspora_reshare($importer,$xml,$msg) { $message_id = item_store($datarray); //if($message_id) { - // q("update item set plink = '%s' where id = %d limit 1", + // q("update item set plink = '%s' where id = %d", // dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id), // intval($message_id) // ); @@ -1170,7 +1170,7 @@ function diaspora_asphoto($importer,$xml,$msg) { $message_id = item_store($datarray); //if($message_id) { - // q("update item set plink = '%s' where id = %d limit 1", + // q("update item set plink = '%s' where id = %d", // dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id), // intval($message_id) // ); @@ -1350,7 +1350,7 @@ function diaspora_comment($importer,$xml,$msg) { $message_id = item_store($datarray); if($message_id) { - q("update item set plink = '%s' where id = %d limit 1", + q("update item set plink = '%s' where id = %d", dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id), intval($message_id) ); @@ -1559,15 +1559,15 @@ function diaspora_conversation($importer,$xml,$msg) { dbesc($message_id), dbesc($parent_uri), dbesc($msg_created_at) - ); + ); - q("update conv set updated = '%s' where id = %d limit 1", + q("update conv set updated = '%s' where id = %d", dbesc(datetime_convert()), intval($conversation['id']) - ); + ); require_once('include/enotify.php'); - notification(array( + notification(array( 'type' => NOTIFY_MAIL, 'notify_flags' => $importer['notify-flags'], 'language' => $importer['language'], @@ -1672,13 +1672,13 @@ function diaspora_message($importer,$xml,$msg) { dbesc($message_id), dbesc($parent_uri), dbesc($msg_created_at) - ); + ); - q("update conv set updated = '%s' where id = %d limit 1", + q("update conv set updated = '%s' where id = %d", dbesc(datetime_convert()), intval($conversation['id']) - ); - + ); + return; } @@ -1740,7 +1740,7 @@ function diaspora_photo($importer,$xml,$msg,$attempt=1) { array($remote_photo_name, 'scaled_full_' . $remote_photo_name)); if(strpos($parent_item['body'],$link_text) === false) { - $r = q("update item set `body` = '%s', `visible` = 1 where `id` = %d and `uid` = %d limit 1", + $r = q("update item set `body` = '%s', `visible` = 1 where `id` = %d and `uid` = %d", dbesc($link_text . $parent_item['body']), intval($parent_item['id']), intval($parent_item['uid']) @@ -1800,12 +1800,12 @@ function diaspora_like($importer,$xml,$msg) { if($positive === 'true') { logger('diaspora_like: duplicate like: ' . $guid); return; - } + } // Note: I don't think "Like" objects with positive = "false" are ever actually used // It looks like "RelayableRetractions" are used for "unlike" instead if($positive === 'false') { logger('diaspora_like: received a like with positive set to "false"...ignoring'); -/* q("UPDATE `item` SET `deleted` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1", +/* q("UPDATE `item` SET `deleted` = 1 WHERE `id` = %d AND `uid` = %d", intval($r[0]['id']), intval($importer['uid']) );*/ @@ -1942,7 +1942,7 @@ EOT; if($message_id) { - q("update item set plink = '%s' where id = %d limit 1", + q("update item set plink = '%s' where id = %d", dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id), intval($message_id) ); @@ -1989,8 +1989,8 @@ function diaspora_retraction($importer,$xml) { ); if(count($r)) { if(link_compare($r[0]['author-link'],$contact['url'])) { - q("update item set `deleted` = 1, `changed` = '%s' where `id` = %d limit 1", - dbesc(datetime_convert()), + q("update item set `deleted` = 1, `changed` = '%s' where `id` = %d", + dbesc(datetime_convert()), intval($r[0]['id']) ); } @@ -2060,12 +2060,12 @@ function diaspora_signed_retraction($importer,$xml,$msg) { ); if(count($r)) { if(link_compare($r[0]['author-link'],$contact['url'])) { - q("update item set `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '' , `title` = '' where `id` = %d limit 1", - dbesc(datetime_convert()), - dbesc(datetime_convert()), + q("update item set `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '' , `title` = '' where `id` = %d", + dbesc(datetime_convert()), + dbesc(datetime_convert()), intval($r[0]['id']) ); - + // Now check if the retraction needs to be relayed by us // // The first item in the `item` table with the parent id is the parent. However, MySQL doesn't always @@ -2161,7 +2161,7 @@ function diaspora_profile($importer,$xml,$msg) { // TODO: update name on item['author-name'] if the name changed. See consume_feed() // Not doing this currently because D* protocol is scheduled for revision soon. - $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1", + $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($name), dbesc(datetime_convert()), dbesc($images[0]), @@ -2331,7 +2331,7 @@ function diaspora_send_images($item,$owner,$contact,$images,$public_batch = fals if(! count($r)) continue; $public = (($r[0]['allow_cid'] || $r[0]['allow_gid'] || $r[0]['deny_cid'] || $r[0]['deny_gid']) ? 'false' : 'true' ); - $msg = replace_macros($tpl,array( + $msg = replace_macros($tpl,array( '$path' => xmlify($image['path']), '$filename' => xmlify($image['file']), '$msg_guid' => xmlify($image['guid']), diff --git a/include/follow.php b/include/follow.php index fc167bb82..32dd29e67 100644 --- a/include/follow.php +++ b/include/follow.php @@ -262,7 +262,7 @@ function new_contact($uid,$url,$interactive = false) { '$ostat_follow' => '' )); - $r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid` + $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid` WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1", intval($uid) ); diff --git a/include/group.php b/include/group.php index aa226688a..abfe42df7 100644 --- a/include/group.php +++ b/include/group.php @@ -157,7 +157,7 @@ function group_get_members($gid) { $ret = array(); if(intval($gid)) { $r = q("SELECT `group_member`.`contact-id`, `contact`.* FROM `group_member` - LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` + INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` WHERE `gid` = %d AND `group_member`.`uid` = %d ORDER BY `contact`.`name` ASC ", intval($gid), intval(local_user()) @@ -172,7 +172,7 @@ function group_public_members($gid) { $ret = 0; if(intval($gid)) { $r = q("SELECT `contact`.`id` AS `contact-id` FROM `group_member` - LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` + INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` WHERE `gid` = %d AND `group_member`.`uid` = %d AND `contact`.`network` = '%s' AND `contact`.`notify` != '' ", intval($gid), @@ -299,7 +299,7 @@ function expand_groups($a,$check_dead = false) { function member_of($c) { - $r = q("SELECT `group`.`name`, `group`.`id` FROM `group` LEFT JOIN `group_member` ON `group_member`.`gid` = `group`.`id` WHERE `group_member`.`contact-id` = %d AND `group`.`deleted` = 0 ORDER BY `group`.`name` ASC ", + $r = q("SELECT `group`.`name`, `group`.`id` FROM `group` INNER JOIN `group_member` ON `group_member`.`gid` = `group`.`id` WHERE `group_member`.`contact-id` = %d AND `group`.`deleted` = 0 ORDER BY `group`.`name` ASC ", intval($c) ); diff --git a/include/items.php b/include/items.php index ffd549ea1..6c438f463 100755 --- a/include/items.php +++ b/include/items.php @@ -9,6 +9,7 @@ require_once('include/tags.php'); require_once('include/text.php'); require_once('include/email.php'); require_once('include/ostatus_conversation.php'); +require_once('include/threads.php'); function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) { @@ -36,7 +37,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' "; $r = q("SELECT `contact`.*, `user`.`uid` AS `user_uid`, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags` - FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` + FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` WHERE `contact`.`self` = 1 AND `user`.`nickname` = '%s' LIMIT 1", dbesc($owner_nick) ); @@ -122,15 +123,15 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s'); - $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, - `contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`, + $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, + `contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`, `contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`, - `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, + `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`id` AS `contact-id`, `contact`.`uid` AS `contact-uid`, `sign`.`signed_text`, `sign`.`signature`, `sign`.`signer` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` - WHERE `item`.`uid` = %d AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`parent` != 0 + WHERE `item`.`uid` = %d AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`parent` != 0 AND `item`.`wall` = 1 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND ( `item`.`edited` > '%s' OR `item`.`changed` > '%s' ) $sql_extra @@ -915,7 +916,7 @@ function encode_rel_links($links) { function item_store($arr,$force_parent = false) { - // If a Diaspora signature structure was passed in, pull it out of the + // If a Diaspora signature structure was passed in, pull it out of the // item array and set it aside for later storage. $dsprsig = null; @@ -947,7 +948,7 @@ function item_store($arr,$force_parent = false) { // Shouldn't happen but we want to make absolutely sure it doesn't leak from a plugin. - if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) + if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) $arr['body'] = strip_tags($arr['body']); @@ -1058,7 +1059,7 @@ function item_store($arr,$force_parent = false) { if($r[0]['uri'] != $r[0]['parent-uri']) { $arr['parent-uri'] = $r[0]['parent-uri']; - $z = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `parent-uri` = '%s' AND `uid` = %d + $z = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `parent-uri` = '%s' AND `uid` = %d ORDER BY `id` ASC LIMIT 1", dbesc($r[0]['parent-uri']), dbesc($r[0]['parent-uri']), @@ -1077,18 +1078,32 @@ function item_store($arr,$force_parent = false) { $arr['wall'] = $r[0]['wall']; // if the parent is private, force privacy for the entire conversation - // This differs from the above settings as it subtly allows comments from - // email correspondents to be private even if the overall thread is not. + // This differs from the above settings as it subtly allows comments from + // email correspondents to be private even if the overall thread is not. if($r[0]['private']) $arr['private'] = $r[0]['private']; // Edge case. We host a public forum that was originally posted to privately. // The original author commented, but as this is a comment, the permissions - // weren't fixed up so it will still show the comment as private unless we fix it here. + // weren't fixed up so it will still show the comment as private unless we fix it here. if((intval($r[0]['forum_mode']) == 1) && (! $r[0]['private'])) $arr['private'] = 0; + + + // If its a post from myself then tag the thread as "mention" + logger("item_store: Checking if parent ".$parent_id." has to be tagged as mention for user ".$arr['uid'], LOGGER_DEBUG); + $u = q("select * from user where uid = %d limit 1", intval($arr['uid'])); + if(count($u)) { + $a = get_app(); + $self = normalise_link($a->get_baseurl() . '/profile/' . $u[0]['nickname']); + logger("item_store: 'myself' is ".$self." for parent ".$parent_id." checking against ".$arr['author-link']." and ".$arr['owner-link'], LOGGER_DEBUG); + if ((normalise_link($arr['author-link']) == $self) OR (normalise_link($arr['owner-link']) == $self)) { + q("UPDATE `thread` SET `mention` = 1 WHERE `iid` = %d", intval($parent_id)); + logger("item_store: tagged thread ".$parent_id." as mention for user ".$self, LOGGER_DEBUG); + } + } } else { @@ -1150,6 +1165,7 @@ function item_store($arr,$force_parent = false) { // Only check for notifications on start posts if ($arr['parent-uri'] === $arr['uri']) { + add_thread($r[0]['id']); logger('item_store: Check notification for contact '.$arr['contact-id'].' and post '.$current_post, LOGGER_DEBUG); // Send a notification for every new post? @@ -1246,6 +1262,7 @@ function item_store($arr,$force_parent = false) { dbesc(datetime_convert()), intval($parent_id) ); + update_thread($parent_id); if($dsprsig) { q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", @@ -1318,7 +1335,7 @@ function get_item_contact($item,$contacts) { */ function tag_deliver($uid,$item_id) { - // + // $a = get_app(); @@ -1448,6 +1465,7 @@ function tag_deliver($uid,$item_id) { dbesc($u[0]['deny_gid']), intval($item_id) ); + update_thread($item_id); proc_run('php','include/notifier.php','tgroup',$item_id); @@ -1965,7 +1983,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) $when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s'); } if($deleted && is_array($contact)) { - $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join `contact` on `item`.`contact-id` = `contact`.`id` + $r = q("SELECT `item`.*, `contact`.`self` FROM `item` INNER JOIN `contact` on `item`.`contact-id` = `contact`.`id` WHERE `uri` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d AND NOT `item`.`file` LIKE '%%[%%' LIMIT 1", dbesc($uri), intval($importer['uid']), @@ -2023,10 +2041,11 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) intval($importer['uid']) ); create_tags_from_itemuri($item['uri'], $importer['uid']); + update_thread_uri($item['uri'], $importer['uid']); } else { $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', - `body` = '', `title` = '' + `body` = '', `title` = '' WHERE `uri` = '%s' AND `uid` = %d", dbesc($when), dbesc(datetime_convert()), @@ -2122,6 +2141,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) intval($importer['uid']) ); $datarray['last-child'] = 1; + update_thread_uri($parent_uri, $importer['uid']); } @@ -2148,6 +2168,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) intval($importer['uid']) ); create_tags_from_itemuri($item_id, $importer['uid']); + update_thread_uri($item_id, $importer['uid']); } // update last-child if it changes @@ -2165,6 +2186,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) dbesc($item_id), intval($importer['uid']) ); + update_thread_uri($item_id, $importer['uid']); } continue; } @@ -2291,7 +2313,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) // Update content if 'updated' changes if(count($r)) { - if (edited_timestamp_is_newer($r[0], $datarray)) { + if (edited_timestamp_is_newer($r[0], $datarray)) { // do not accept (ignore) an earlier edit than one we currently have. if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited']) @@ -2306,6 +2328,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) intval($importer['uid']) ); create_tags_from_itemuri($item_id, $importer['uid']); + update_thread_uri($item_id, $importer['uid']); } // update last-child if it changes @@ -2318,6 +2341,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) dbesc($item_id), intval($importer['uid']) ); + update_thread_uri($item_id, $importer['uid']); } continue; } @@ -2556,65 +2580,65 @@ function local_delivery($importer,$data) { /*$newloc['pubkey'] = notags(unxmlify($base['pubkey'][0]['data'])); $newloc['prvkey'] = notags(unxmlify($base['prvkey'][0]['data']));*/ - logger("items:relocate contact ".print_r($newloc, true).print_r($importer, true), LOGGER_DEBUG); + logger("items:relocate contact ".print_r($newloc, true).print_r($importer, true), LOGGER_DEBUG); - // update contact - $r = q("SELECT photo, url FROM contact WHERE id=%d AND uid=%d;", - intval($importer['id']), - intval($importer['importer_uid'])); + // update contact + $r = q("SELECT photo, url FROM contact WHERE id=%d AND uid=%d;", + intval($importer['id']), + intval($importer['importer_uid'])); if ($r === false) return 1; - $old = $r[0]; + $old = $r[0]; - $x = q("UPDATE contact SET - name = '%s', - photo = '%s', - thumb = '%s', - micro = '%s', - url = '%s', - request = '%s', - confirm = '%s', - notify = '%s', - poll = '%s', - `site-pubkey` = '%s' - WHERE id=%d AND uid=%d;", - dbesc($newloc['name']), - dbesc($newloc['photo']), - dbesc($newloc['thumb']), - dbesc($newloc['micro']), - dbesc($newloc['url']), - dbesc($newloc['request']), - dbesc($newloc['confirm']), - dbesc($newloc['notify']), - dbesc($newloc['poll']), - dbesc($newloc['sitepubkey']), - intval($importer['id']), + $x = q("UPDATE contact SET + name = '%s', + photo = '%s', + thumb = '%s', + micro = '%s', + url = '%s', + request = '%s', + confirm = '%s', + notify = '%s', + poll = '%s', + `site-pubkey` = '%s' + WHERE id=%d AND uid=%d;", + dbesc($newloc['name']), + dbesc($newloc['photo']), + dbesc($newloc['thumb']), + dbesc($newloc['micro']), + dbesc($newloc['url']), + dbesc($newloc['request']), + dbesc($newloc['confirm']), + dbesc($newloc['notify']), + dbesc($newloc['poll']), + dbesc($newloc['sitepubkey']), + intval($importer['id']), intval($importer['importer_uid'])); - if ($x === false) + if ($x === false) return 1; - // update items - $fields = array( - 'owner-link' => array($old['url'], $newloc['url']), - 'author-link' => array($old['url'], $newloc['url']), - 'owner-avatar' => array($old['photo'], $newloc['photo']), - 'author-avatar' => array($old['photo'], $newloc['photo']), - ); - foreach ($fields as $n=>$f){ - $x = q("UPDATE item SET `%s`='%s' WHERE `%s`='%s' AND uid=%d", - $n, dbesc($f[1]), - $n, dbesc($f[0]), - intval($importer['importer_uid'])); - if ($x === false) - return 1; - } + // update items + $fields = array( + 'owner-link' => array($old['url'], $newloc['url']), + 'author-link' => array($old['url'], $newloc['url']), + 'owner-avatar' => array($old['photo'], $newloc['photo']), + 'author-avatar' => array($old['photo'], $newloc['photo']), + ); + foreach ($fields as $n=>$f){ + $x = q("UPDATE `item` SET `%s`='%s' WHERE `%s`='%s' AND uid=%d", + $n, dbesc($f[1]), + $n, dbesc($f[0]), + intval($importer['importer_uid'])); + if ($x === false) + return 1; + } // TODO // merge with current record, current contents have priority // update record, set url-updated // update profile photos // schedule a scan? - return 0; + return 0; } @@ -2832,7 +2856,7 @@ function local_delivery($importer,$data) { // POSSIBLE CLEANUP --> Why select so many fields when only forum_mode and wall are used? $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `item`.`forum_mode`,`item`.`origin`,`item`.`wall`, `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item` - LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uri` = '%s' AND (`item`.`parent-uri` = '%s' or `item`.`thr-parent` = '%s') AND `item`.`uid` = %d $sql_extra @@ -2862,7 +2886,7 @@ function local_delivery($importer,$data) { } } - $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join contact on `item`.`contact-id` = `contact`.`id` + $r = q("SELECT `item`.*, `contact`.`self` FROM `item` INNER JOIN contact on `item`.`contact-id` = `contact`.`id` WHERE `uri` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d AND NOT `item`.`file` LIKE '%%[%%' LIMIT 1", dbesc($uri), intval($importer['importer_uid']), @@ -2924,6 +2948,7 @@ function local_delivery($importer,$data) { intval($importer['importer_uid']) ); create_tags_from_itemuri($item['uri'], $importer['importer_uid']); + update_thread_uri($item['uri'], $importer['importer_uid']); } else { $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', @@ -2935,6 +2960,7 @@ function local_delivery($importer,$data) { intval($importer['importer_uid']) ); create_tags_from_itemuri($uri, $importer['importer_uid']); + update_thread_uri($uri, $importer['importer_uid']); if($item['last-child']) { // ensure that last-child is set in case the comment that had it just got wiped. q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ", @@ -3003,7 +3029,7 @@ function local_delivery($importer,$data) { // POSSIBLE CLEANUP --> Why select so many fields when only forum_mode and wall are used? $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `item`.`forum_mode`,`item`.`origin`,`item`.`wall`, `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item` - LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uri` = '%s' AND (`item`.`parent-uri` = '%s' or `item`.`thr-parent` = '%s') AND `item`.`uid` = %d $sql_extra @@ -3346,7 +3372,7 @@ function local_delivery($importer,$data) { continue; require_once('include/enotify.php'); - + $conv_parent = $conv['parent']; notification(array( @@ -3430,6 +3456,7 @@ function local_delivery($importer,$data) { intval($importer['importer_uid']) ); create_tags_from_itemuri($item_id, $importer['importer_uid']); + update_thread_uri($item_id, $importer['importer_uid']); } // update last-child if it changes @@ -4154,6 +4181,7 @@ function drop_item($id,$interactive = true) { intval($item['id']) ); create_tags_from_item($item['id']); + delete_thread($item['id']); // clean up categories and tags so they don't end up as orphans @@ -4248,6 +4276,7 @@ function drop_item($id,$interactive = true) { intval($item['uid']) ); create_tags_from_item($item['parent-uri'], $item['uid']); + delete_thread_uri($item['parent-uri'], $item['uid']); // ignore the result } else { @@ -4294,8 +4323,8 @@ function drop_item($id,$interactive = true) { function first_post_date($uid,$wall = false) { - $r = q("select id, created from item - where uid = %d and wall = %d and deleted = 0 and visible = 1 AND moderated = 0 + $r = q("select id, created from item + where uid = %d and wall = %d and deleted = 0 and visible = 1 AND moderated = 0 and id = parent order by created asc limit 1", intval($uid), diff --git a/include/notifier.php b/include/notifier.php index 8e9764315..cb080a409 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -207,7 +207,7 @@ function notifier_run(&$argv, &$argc){ $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`, `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, `user`.`page-flags`, `user`.`prvnets` - FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` + FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1", intval($uid) ); @@ -643,7 +643,7 @@ function notifier_run(&$argv, &$argc){ `contact`.`name` as `senderName`, `user`.* FROM `contact` - LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid` + INNER JOIN `user` ON `contact`.`uid` = `user`.`uid` WHERE `contact`.`blocked` = 0 AND `contact`.`archive` = 0 AND `contact`.`pending` = 0 AND `contact`.`network` = '%s' AND `user`.`nickname` = '%s' diff --git a/include/onepoll.php b/include/onepoll.php index 2a7815fa5..49047118a 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -112,7 +112,7 @@ function onepoll_run(&$argv, &$argc){ $importer_uid = $contact['uid']; - $r = q("SELECT `contact`.*, `user`.`page-flags` FROM `contact` LEFT JOIN `user` on `contact`.`uid` = `user`.`uid` WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1", + $r = q("SELECT `contact`.*, `user`.`page-flags` FROM `contact` INNER JOIN `user` on `contact`.`uid` = `user`.`uid` WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1", intval($importer_uid) ); if(! count($r)) diff --git a/include/poller.php b/include/poller.php index 9b18fe3c6..084067b19 100644 --- a/include/poller.php +++ b/include/poller.php @@ -174,7 +174,7 @@ function poller_run(&$argv, &$argc){ : '' ); - $contacts = q("SELECT `contact`.`id` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` + $contacts = q("SELECT `contact`.`id` FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != '' AND NOT `network` IN ( '%s', '%s', '%s' ) $sql_extra diff --git a/include/profile_update.php b/include/profile_update.php index 61eaee75d..611b00819 100644 --- a/include/profile_update.php +++ b/include/profile_update.php @@ -25,7 +25,7 @@ function profile_change() { return; $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile` - LEFT JOIN `user` ON `profile`.`uid` = `user`.`uid` + INNER JOIN `user` ON `profile`.`uid` = `user`.`uid` WHERE `user`.`uid` = %d AND `profile`.`is-default` = 1 LIMIT 1", intval(local_user()) ); diff --git a/include/queue.php b/include/queue.php index 2cc162823..e3ca5767a 100644 --- a/include/queue.php +++ b/include/queue.php @@ -111,7 +111,7 @@ function queue_run(&$argv, &$argc){ } $r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue` - LEFT JOIN `contact` ON `queue`.`cid` = `contact`.`id` + INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id` WHERE `queue`.`created` < UTC_TIMESTAMP() - INTERVAL 3 DAY"); if($r) { foreach($r as $rr) { diff --git a/include/queue_fn.php b/include/queue_fn.php index e43912431..5214131b2 100644 --- a/include/queue_fn.php +++ b/include/queue_fn.php @@ -2,7 +2,7 @@ function update_queue_time($id) { logger('queue: requeue item ' . $id); - q("UPDATE `queue` SET `last` = '%s' WHERE `id` = %d LIMIT 1", + q("UPDATE `queue` SET `last` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), intval($id) ); @@ -10,7 +10,7 @@ function update_queue_time($id) { function remove_queue_item($id) { logger('queue: remove queue item ' . $id); - q("DELETE FROM `queue` WHERE `id` = %d LIMIT 1", + q("DELETE FROM `queue` WHERE `id` = %d", intval($id) ); } @@ -44,7 +44,7 @@ function add_to_queue($cid,$network,$msg,$batch = false) { if($batch_queue < 1) $batch_queue = 1000; - $r = q("SELECT COUNT(*) AS `total` FROM `queue` left join `contact` ON `queue`.`cid` = `contact`.`id` + $r = q("SELECT COUNT(*) AS `total` FROM `queue` INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id` WHERE `queue`.`cid` = %d AND `contact`.`self` = 0 ", intval($cid) ); diff --git a/include/security.php b/include/security.php index 9f160e788..7c2e2d47c 100644 --- a/include/security.php +++ b/include/security.php @@ -56,7 +56,7 @@ function authenticate_success($user_record, $login_initial = false, $interactive $a->identities = array(); $r = q("select `user`.`uid`, `user`.`username`, `user`.`nickname` - from manage left join user on manage.mid = user.uid where `user`.`account_removed` = 0 + from manage INNER JOIN user on manage.mid = user.uid where `user`.`account_removed` = 0 and `manage`.`uid` = %d", intval($master_record['uid']) ); @@ -139,7 +139,7 @@ function can_write_wall(&$a,$owner) { return false; - $r = q("SELECT `contact`.*, `user`.`page-flags` FROM `contact` LEFT JOIN `user` on `user`.`uid` = `contact`.`uid` + $r = q("SELECT `contact`.*, `user`.`page-flags` FROM `contact` INNER JOIN `user` on `user`.`uid` = `contact`.`uid` WHERE `contact`.`uid` = %d AND `contact`.`id` = %d AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `user`.`blockwall` = 0 AND `readonly` = 0 AND ( `contact`.`rel` IN ( %d , %d ) OR `user`.`page-flags` = %d ) LIMIT 1", intval($owner), @@ -255,11 +255,11 @@ function item_permissions_sql($owner_id,$remote_verified = false,$groups = null) * default permissions - anonymous user */ - $sql = " AND allow_cid = '' - AND allow_gid = '' - AND deny_cid = '' - AND deny_gid = '' - AND private = 0 + $sql = " AND `item`.allow_cid = '' + AND `item`.allow_gid = '' + AND `item`.deny_cid = '' + AND `item`.deny_gid = '' + AND `item`.private = 0 "; /** @@ -291,7 +291,7 @@ function item_permissions_sql($owner_id,$remote_verified = false,$groups = null) } } if($remote_verified) { - + $gs = '<<>>'; // should be impossible to match if(is_array($groups) && count($groups)) { @@ -310,9 +310,9 @@ function item_permissions_sql($owner_id,$remote_verified = false,$groups = null) dbesc($gs), dbesc($gs) */ - " AND ( private = 0 OR ( private in (1,2) AND wall = 1 - AND ( NOT (deny_cid REGEXP '<%d>' OR deny_gid REGEXP '%s') - AND ( allow_cid REGEXP '<%d>' OR allow_gid REGEXP '%s' OR ( allow_cid = '' AND allow_gid = ''))))) + " AND ( `item`.private = 0 OR ( `item`.private in (1,2) AND wall = 1 + AND ( NOT (`item`.deny_cid REGEXP '<%d>' OR `item`.deny_gid REGEXP '%s') + AND ( `item`.allow_cid REGEXP '<%d>' OR `item`.allow_gid REGEXP '%s' OR ( allow_cid = '' AND allow_gid = ''))))) ", intval($remote_user), dbesc($gs), diff --git a/include/socgraph.php b/include/socgraph.php index 24f584db7..daec03726 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -170,7 +170,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { function count_common_friends($uid,$cid) { $r = q("SELECT count(*) as `total` - FROM `glink` left join `gcontact` on `glink`.`gcid` = `gcontact`.`id` + FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id` where `glink`.`cid` = %d and `glink`.`uid` = %d and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 and id != %d ) ", intval($cid), @@ -195,7 +195,7 @@ function common_friends($uid,$cid,$start = 0,$limit=9999,$shuffle = false) { $sql_extra = " order by `gcontact`.`name` asc "; $r = q("SELECT `gcontact`.* - FROM `glink` left join `gcontact` on `glink`.`gcid` = `gcontact`.`id` + FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id` where `glink`.`cid` = %d and `glink`.`uid` = %d and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 and id != %d ) $sql_extra limit %d, %d", @@ -215,7 +215,7 @@ function common_friends($uid,$cid,$start = 0,$limit=9999,$shuffle = false) { function count_common_friends_zcid($uid,$zcid) { $r = q("SELECT count(*) as `total` - FROM `glink` left join `gcontact` on `glink`.`gcid` = `gcontact`.`id` + FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id` where `glink`.`zcid` = %d and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 ) ", intval($zcid), @@ -236,7 +236,7 @@ function common_friends_zcid($uid,$zcid,$start = 0, $limit = 9999,$shuffle = fal $sql_extra = " order by `gcontact`.`name` asc "; $r = q("SELECT `gcontact`.* - FROM `glink` left join `gcontact` on `glink`.`gcid` = `gcontact`.`id` + FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id` where `glink`.`zcid` = %d and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 ) $sql_extra limit %d, %d", @@ -254,7 +254,7 @@ function common_friends_zcid($uid,$zcid,$start = 0, $limit = 9999,$shuffle = fal function count_all_friends($uid,$cid) { $r = q("SELECT count(*) as `total` - FROM `glink` left join `gcontact` on `glink`.`gcid` = `gcontact`.`id` + FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id` where `glink`.`cid` = %d and `glink`.`uid` = %d ", intval($cid), intval($uid) @@ -270,7 +270,7 @@ function count_all_friends($uid,$cid) { function all_friends($uid,$cid,$start = 0, $limit = 80) { $r = q("SELECT `gcontact`.* - FROM `glink` left join `gcontact` on `glink`.`gcid` = `gcontact`.`id` + FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id` where `glink`.`cid` = %d and `glink`.`uid` = %d order by `gcontact`.`name` asc LIMIT %d, %d ", intval($cid), @@ -290,7 +290,7 @@ function suggestion_query($uid, $start = 0, $limit = 80) { return array(); $r = q("SELECT count(glink.gcid) as `total`, gcontact.* from gcontact - left join glink on glink.gcid = gcontact.id + INNER JOIN glink on glink.gcid = gcontact.id where uid = %d and not gcontact.nurl in ( select nurl from contact where uid = %d ) and not gcontact.name in ( select name from contact where uid = %d ) and not gcontact.id in ( select gcid from gcign where uid = %d ) @@ -307,7 +307,7 @@ function suggestion_query($uid, $start = 0, $limit = 80) { return $r; $r2 = q("SELECT gcontact.* from gcontact - left join glink on glink.gcid = gcontact.id + INNER JOIN glink on glink.gcid = gcontact.id where glink.uid = 0 and glink.cid = 0 and glink.zcid = 0 and not gcontact.nurl in ( select nurl from contact where uid = %d ) and not gcontact.name in ( select name from contact where uid = %d ) and not gcontact.id in ( select gcid from gcign where uid = %d ) diff --git a/include/tags.php b/include/tags.php index e5bc29cd4..fbb9e6ff7 100644 --- a/include/tags.php +++ b/include/tags.php @@ -1,20 +1,4 @@ set_baseurl("https://pirati.ca"); -*/ - function create_tags_from_item($itemid) { global $a; @@ -25,7 +9,7 @@ function create_tags_from_item($itemid) { $searchpath = $a->get_baseurl()."/search?tag="; - $messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `title`, `body`, `tag` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); + $messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `title`, `body`, `tag`, `parent` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); if (!$messages) return; @@ -102,8 +86,11 @@ function create_tags_from_item($itemid) { if ((substr($tag, 0, 1) == '@') AND (strpos($link, $profile_base_friendica) OR strpos($link, $profile_base_diaspora))) { $users = q("SELECT `uid` FROM `contact` WHERE self AND (`url` = '%s' OR `nurl` = '%s')", $link, $link); foreach ($users AS $user) { - if ($user["uid"] == $message["uid"]) + if ($user["uid"] == $message["uid"]) { q("UPDATE `item` SET `mention` = 1 WHERE `id` = %d", intval($itemid)); + + q("UPDATE `thread` SET `mention` = 1 WHERE `iid` = %d", intval($message["parent"])); + } } } } @@ -125,11 +112,4 @@ function update_items() { foreach ($messages as $message) create_tags_from_item($message["id"]); } - -//print_r($tags); -//print_r($hashtags); -//print_r($mentions); -//update_items(); -//create_tags_from_item(265194); -//create_tags_from_itemuri("infoagent@diasp.org:cce94abd104c06e8", 2); ?> diff --git a/include/user.php b/include/user.php index 93b34e1f5..8528bfbfa 100644 --- a/include/user.php +++ b/include/user.php @@ -233,7 +233,7 @@ function create_user($arr) { ); if((count($r) > 1) && $newuid) { $result['message'] .= t('Nickname is already registered. Please choose another.') . EOL; - q("DELETE FROM `user` WHERE `uid` = %d LIMIT 1", + q("DELETE FROM `user` WHERE `uid` = %d", intval($newuid) ); return $result; diff --git a/mod/community.php b/mod/community.php index dbf4c82be..f3c213f0c 100644 --- a/mod/community.php +++ b/mod/community.php @@ -46,12 +46,13 @@ function community_content(&$a, $update = 0) { if( (! get_config('alt_pager', 'global')) && (! get_pconfig(local_user(),'system','alt_pager')) ) { $r = q("SELECT COUNT(distinct(`item`.`uri`)) AS `total` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` + FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 + INNER JOIN `user` ON `user`.`uid` = `item`.`uid` AND `user`.`hidewall` = 0 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 - AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' + AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' - AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `user`.`hidewall` = 0 - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0" + AND `item`.`private` = 0 AND `item`.`wall` = 1" ); if(count($r)) @@ -65,27 +66,25 @@ function community_content(&$a, $update = 0) { } //$r = q("SELECT distinct(`item`.`uri`) - $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, + $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, - `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, + `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`, `user`.`nickname`, `user`.`hidewall` - FROM `item` FORCE INDEX (`received`, `wall`) LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` - WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 + FROM `thread` FORCE INDEX (`visible_deleted_moderated_private_wall_received`) + INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND `user`.`hidewall` = 0 + INNER JOIN `item` ON `item`.`id` = `thread`.`iid` AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' - AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' - AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `item`.`id` = `item`.`parent` - AND `user`.`hidewall` = 0 + AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' + INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self` - ORDER BY `received` DESC LIMIT %d, %d ", + WHERE `thread`.`visible` = 1 AND `thread`.`deleted` = 0 and `thread`.`moderated` = 0 + AND `thread`.`private` = 0 AND `thread`.`wall` = 1 + ORDER BY `thread`.`received` DESC LIMIT %d, %d ", intval($a->pager['start']), intval($a->pager['itemspage']) ); -// group by `item`.`uri` -// AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `item`.`id` = `item`.`parent` -// AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self` if(! count($r)) { info( t('No results.') . EOL); diff --git a/mod/contacts.php b/mod/contacts.php index ad50376b7..3d79eb583 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -164,7 +164,7 @@ function contacts_post(&$a) { $info = fix_mce_lf(escape_tags(trim($_POST['info']))); $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s', - `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1", + `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d WHERE `id` = %d AND `uid` = %d", intval($profile_id), intval($priority), dbesc($info), @@ -197,7 +197,7 @@ function _contact_update($contact_id) { } function _contact_block($contact_id, $orig_record) { $blocked = (($orig_record['blocked']) ? 0 : 1); - $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1", + $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d", intval($blocked), intval($contact_id), intval(local_user()) @@ -207,7 +207,7 @@ function _contact_block($contact_id, $orig_record) { } function _contact_ignore($contact_id, $orig_record) { $readonly = (($orig_record['readonly']) ? 0 : 1); - $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1", + $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d", intval($readonly), intval($contact_id), intval(local_user()) @@ -216,7 +216,7 @@ function _contact_ignore($contact_id, $orig_record) { } function _contact_archive($contact_id, $orig_record) { $archived = (($orig_record['archive']) ? 0 : 1); - $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1", + $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d", intval($archived), intval($contact_id), intval(local_user()) diff --git a/mod/content.php b/mod/content.php index f974eecdd..a992d1c8a 100644 --- a/mod/content.php +++ b/mod/content.php @@ -176,7 +176,7 @@ function content_content(&$a, $update = 0) { if($tag) { //$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ", // dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); - //$sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; + //$sql_table = "`term` INNER JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; $sql_extra = ""; $sql_table = sprintf("`item` INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", @@ -216,7 +216,7 @@ function content_content(&$a, $update = 0) { `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 $simple_update @@ -240,7 +240,7 @@ function content_content(&$a, $update = 0) { $start = dba_timer(); $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid` - FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `item`.`parent` = `item`.`id` @@ -267,7 +267,7 @@ function content_content(&$a, $update = 0) { `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 diff --git a/mod/display.php b/mod/display.php index 116b4a17e..2de3a8a88 100644 --- a/mod/display.php +++ b/mod/display.php @@ -138,10 +138,10 @@ function display_content(&$a, $update = 0) { `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' ) AND uid = %d ) $sql_extra @@ -167,10 +167,10 @@ function display_content(&$a, $update = 0) { `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE `uri` = '%s' AND uid = %d ) ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ", intval(local_user()), diff --git a/mod/item.php b/mod/item.php index 805701dc3..451fcb48c 100644 --- a/mod/item.php +++ b/mod/item.php @@ -20,6 +20,7 @@ require_once('include/enotify.php'); require_once('include/email.php'); require_once('library/langdet/Text/LanguageDetect.php'); require_once('include/tags.php'); +require_once('include/threads.php'); function item_post(&$a) { @@ -705,6 +706,7 @@ function item_post(&$a) { intval($profile_uid) ); create_tags_from_itemuri($post_id, $profile_uid); + update_thread_uri($post_id, $profile_uid); // update filetags in pconfig file_tag_update_pconfig($uid,$categories_old,$categories_new,'category'); @@ -772,6 +774,7 @@ function item_post(&$a) { $post_id = $r[0]['id']; logger('mod_item: saved item ' . $post_id); create_tags_from_item($post_id); + add_thread($post_id); // update filetags in pconfig file_tag_update_pconfig($uid,$categories_old,$categories_new,'category'); @@ -794,8 +797,9 @@ function item_post(&$a) { dbesc(datetime_convert()), intval($parent) ); + update_thread($parent, true); - // Inherit ACL's from the parent item. + // Inherit ACLs from the parent item. $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d WHERE `id` = %d", @@ -825,15 +829,14 @@ function item_post(&$a) { 'parent' => $parent, 'parent_uri' => $parent_item['uri'] )); - + } // Store the comment signature information in case we need to relay to Diaspora store_diaspora_comment_sig($datarray, $author, ($self ? $a->user['prvkey'] : false), $parent_item, $post_id); - } - else { + } else { $parent = $post_id; if($contact_record != $author) { @@ -868,6 +871,7 @@ function item_post(&$a) { dbesc(datetime_convert()), intval($post_id) ); + update_thread($post_id); // photo comments turn the corresponding item visible to the profile wall // This way we don't see every picture in your new photo album posted to your wall at once. @@ -877,6 +881,7 @@ function item_post(&$a) { $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d", intval($parent_item['id']) ); + update_thread($parent_item['id']); } } else { @@ -893,6 +898,7 @@ function item_post(&$a) { dbesc(datetime_convert()), intval($parent) ); + update_thread($parent); $datarray['id'] = $post_id; $datarray['plink'] = $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id; diff --git a/mod/network.php b/mod/network.php index e23fd0de5..9d2f60c47 100644 --- a/mod/network.php +++ b/mod/network.php @@ -1,5 +1,8 @@ argc==2 && is_numeric($a->argv[1]) && strpos($net_baseurl, "/",1)===false){ - // $net_baseurl .= "/".$a->argv[1]; - //} + $net_args = array_merge($query_array, $net_args); + $net_queries = build_querystring($net_args); $redir_url = ($net_queries ? $net_baseurl."?".$net_queries : $net_baseurl); goaway($a->get_baseurl() . $redir_url); } } -/* $sel_tabs = network_query_get_sel_tab($a); - $last_sel_tabs = get_pconfig(local_user(), 'network.view','tab.selected'); - if (is_array($last_sel_tabs)){ - $tab_urls = array( - '/network?f=&order=comment',//all - '/network?f=&order=post', //postord - '/network?f=&conv=1', //conv - '/network/new', //new - '/network?f=&star=1', //starred - '/network?f=&bmark=1', //bookmarked - '/network?f=&spam=1', //spam - ); - - // redirect if current selected tab is 'no_active' and - // last selected tab is _not_ 'all_active'. - // and this isn't a date query - - if ($sel_tabs[0] == 'active' && $last_sel_tabs[0]!='active' && (! $is_a_date_query)) { - $k = array_search('active', $last_sel_tabs); - - // merge tab querystring with request querystring - $dest_qa = array(); - list($dest_url,$dest_qs) = explode("?", $tab_urls[$k]); - parse_str( $dest_qs, $dest_qa); - $dest_qa = array_merge($query_array, $dest_qa); - $dest_qs = build_querystring($dest_qa); - - // groups filter is in form of "network/nnn". Add it to $dest_url, if it's possible - if ($a->argc==2 && is_numeric($a->argv[1]) && strpos($dest_url, "/",1)===false){ - $dest_url .= "/".$a->argv[1]; - } - - goaway($a->get_baseurl() . $dest_url."?".$dest_qs); - } - }*/ - if(x($_GET['nets']) && $_GET['nets'] === 'all') unset($_GET['nets']); @@ -180,7 +142,7 @@ function network_init(&$a) { } $a->page['aside'] .= (feature_enabled(local_user(),'groups') ? group_side('network/0','network',true,$group_id) : ''); - $a->page['aside'] .= posted_date_widget($a->get_baseurl() . '/network',local_user(),false); + $a->page['aside'] .= posted_date_widget($a->get_baseurl() . '/network',local_user(),false); $a->page['aside'] .= networks_widget($a->get_baseurl(true) . '/network',(x($_GET, 'nets') ? $_GET['nets'] : '')); $a->page['aside'] .= saved_searches($search); $a->page['aside'] .= fileas_widget($a->get_baseurl(true) . '/network',(x($_GET, 'file') ? $_GET['file'] : '')); @@ -240,7 +202,7 @@ function saved_searches($search) { /** * Return selected tab from query - * + * * urls -> returns * '/network' => $no_active = 'active' * '/network?f=&order=comment' => $comment_active = 'active' @@ -250,7 +212,7 @@ function saved_searches($search) { * '/network?f=&star=1', => $starred_active = 'active' * '/network?f=&bmark=1', => $bookmarked_active = 'active' * '/network?f=&spam=1', => $spam_active = 'active' - * + * * @return Array ( $no_active, $comment_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active ); */ function network_query_get_sel_tab($a) { @@ -383,7 +345,6 @@ function network_content(&$a, $update = 0) { list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a); // if no tabs are selected, defaults to comments if ($no_active=='active') $all_active='active'; - //echo "
"; var_dump($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active); killme();
 
 	$cmd = (($datequery) ? '' : $a->cmd);
 	$len_naked_cmd = strlen(str_replace('/new','',$cmd));
@@ -392,48 +353,16 @@ function network_content(&$a, $update = 0) {
 	$tabs = array(
 		array(
 			'label' => t('Commented Order'),
-			'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''), 
+			'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
 			'sel'=>$all_active,
 			'title'=> t('Sort by Comment Date'),
 		),
 		array(
 			'label' => t('Posted Order'),
-			'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''), 
+			'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
 			'sel'=>$postord_active,
 			'title' => t('Sort by Post Date'),
 		),
-
-/*		array(
-			'label' => t('Personal'),
-			'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&conv=1',
-			'sel' => $conv_active,
-			'title' => t('Posts that mention or involve you'),
-		),*/
-/*		array(
-			'label' => t('New'),
-			'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ($len_naked_cmd ? '/' : '') . 'new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
-			'sel' => $new_active,
-			'title' => t('Activity Stream - by date'),
-		),*/
-/*		array(
-			'label' => t('Starred'),
-			'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&star=1',
-			'sel'=>$starred_active,
-			'title' => t('Favourite Posts'),
-		),*/
-/*		array(
-			'label' => t('Shared Links'),
-			'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&bmark=1',
-			'sel'=>$bookmarked_active,
-			'title'=> t('Interesting Links'),
-		),	*/
-//		array(
-//			'label' => t('Spam'),
-//			'url'=>$a->get_baseurl(true) . '/network?f=&spam=1'
-//			'sel'=> $spam_active,
-//			'title' => t('Posts flagged as SPAM'),
-//		),
-
 	);
 
 	if(feature_enabled(local_user(),'personal_tab')) {
@@ -472,17 +401,6 @@ function network_content(&$a, $update = 0) {
 		);
 	}
 
-	// Not yet implemented
-
-/*	if(feature_enabled(local_user(),'spam_filter'))  {
-		$tabs[] = array(
-			'label' => t('Spam'),
-			'url'=>$a->get_baseurl(true) . '/network?f=&spam=1',
-			'sel'=> $spam_active,
-			'title' => t('Posts flagged as SPAM'),
-		);
-	}*/
-
 	// save selected tab, but only if not in search or file mode
 	if(!x($_GET,'search') && !x($_GET,'file')) {
 		set_pconfig( local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) );
@@ -533,6 +451,11 @@ function network_content(&$a, $update = 0) {
 	}
 	set_pconfig(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all'));
 
+/*if ($update) {
+print_r($_GET);
+die("ss");
+}*/
+
 	if(! $update) {
 		if($group) {
 			if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
@@ -567,19 +490,23 @@ function network_content(&$a, $update = 0) {
 
 	// We don't have to deal with ACLs on this page. You're looking at everything
 	// that belongs to you, hence you can see all of it. We will filter by group if
-	// desired. 
+	// desired.
 
+	$sql_post_table = "";
 	$sql_options  = (($star) ? " and starred = 1 " : '');
 	$sql_options .= (($bmark) ? " and bookmark = 1 " : '');
+	$sql_extra = $sql_options;
+	$sql_extra2 = "";
+	$sql_extra3 = "";
+	$sql_table = "`thread`";
+	$sql_parent = "`iid`";
 
-	//$sql_nets = (($nets) ? sprintf(" and `contact`.`network` = '%s' ", dbesc($nets)) : '');
-	$sql_nets = (($nets) ? sprintf(" and `item`.`network` = '%s' ", dbesc($nets)) : '');
+	if ($nouveau OR strlen($file) OR $update) {
+		$sql_table = "`item`";
+		$sql_parent = "`parent`";
+	}
 
-	if ($star OR $bmark) {
-		$sql_table = "`item` INNER JOIN (SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options and deleted = 0 ORDER BY `commented` DESC) AS `temp1` ON item.parent = `temp1`.parent ";
-		$sql_extra = "";
-	} else
-		$sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) ";
+	$sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : '');
 
 	if($group) {
 		$r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
@@ -595,29 +522,33 @@ function network_content(&$a, $update = 0) {
 		}
 
 		$contacts = expand_groups(array($group));
+
+		$contact_str_self = "";
+
 		if((is_array($contacts)) && count($contacts)) {
 			$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 ';
 				info( t('Group is empty'));
 		}
 
-		$sql_table = "`item` INNER JOIN (SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND (`contact-id` IN ($contact_str) OR `allow_gid` like '".protect_sprintf('%<'.intval($group).'>%')."') and deleted = 0 ORDER BY `created` DESC) AS `temp1` ON item.parent = `temp1`.parent ";
-		$sql_extra = "";
-		//$sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` like '" . protect_sprintf('%<' . intval($group) . '>%') . "' ) and deleted = 0 ) ";
-		$o = '

' . t('Group: ') . $r[0]['name'] . '

' . $o; - } - elseif($cid) { + $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` "; - $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d + $sql_extra3 .= " AND `contact-id` IN ($contact_str.$contact_str_self) "; + $o = '

' . t('Group: ') . $r[0]['name'] . '

' . $o; + } elseif($cid) { + + $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d AND `blocked` = 0 AND `pending` = 0 LIMIT 1", intval($cid) ); if(count($r)) { - $sql_table = "`item` INNER JOIN (SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = ".intval($cid)." and deleted = 0 ORDER BY `item`.`received` DESC) AS `temp1` ON item.parent = `temp1`.parent "; + $sql_post_table = " INNER JOIN (SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = ".intval($cid)." and deleted = 0 ORDER BY `item`.`received` DESC) AS `temp1` ON $sql_table.$sql_parent = `temp1`.`parent` "; $sql_extra = ""; - //$sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = " . intval($cid) . " and deleted = 0 ) "; $o = '

' . t('Contact: ') . $r[0]['name'] . '

' . $o; if($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) { notice( t('Private messages to this person are at risk of public disclosure.') . EOL); @@ -636,24 +567,19 @@ function network_content(&$a, $update = 0) { $o .= get_events(); } - $sql_extra3 = ''; - if($datequery) { - $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery)))); + $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery)))); } if($datequery2) { - $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); + $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); } - $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` "); + //$sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` "); + $sql_extra2 = (($nouveau) ? '' : $sql_extra2); $sql_extra3 = (($nouveau) ? '' : $sql_extra3); - //$sql_order = "`item`.`received`"; $sql_order = ""; $order_mode = "received"; - if ($sql_table == "") - $sql_table = "`item`"; - if(x($_GET,'search')) { $search = escape_tags($_GET['search']); @@ -666,44 +592,24 @@ function network_content(&$a, $update = 0) { $tag = true; if($tag) { - //$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ", - // dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); - //$sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; - - //$sql_order = "`term`.`tid`"; - $sql_extra = ""; - $sql_table = sprintf("`item` INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", + $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user())); - - $sql_order = "`item`.`received`"; - $order_mode = "received"; } else { if (get_config('system','use_fulltext_engine')) $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search))); else $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search)))); - - $sql_order = "`item`.`received`"; - $order_mode = "received"; } + $sql_order = "`item`.`received`"; + $order_mode = "received"; } - if(strlen($file)) { + if(strlen($file)) $sql_extra .= file_tag_file_query('item',unxmlify($file)); - } - if($conv) { - $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname']; - $myurl = substr($myurl,strpos($myurl,'://')+3); - $myurl = str_replace('www.','',$myurl); - $diasp_url = str_replace('/profile/','/u/',$myurl); - - $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)", - dbesc(protect_sprintf($myurl)), - dbesc(protect_sprintf($myurl)) - ); - } + if($conv) + $sql_extra2 .= " AND `mention`"; if($update) { @@ -714,9 +620,9 @@ function network_content(&$a, $update = 0) { else { if( (! get_config('alt_pager', 'global')) && (! get_pconfig(local_user(),'system','alt_pager')) ) { $r = q("SELECT COUNT(*) AS `total` - FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 + FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = $sql_table.`contact-id` AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 + WHERE $sql_table.`uid` = %d AND $sql_table.`visible` = 1 AND $sql_table.`deleted` = 0 $sql_extra2 $sql_extra3 $sql_extra $sql_nets ", intval($_SESSION['uid']) @@ -727,16 +633,16 @@ function network_content(&$a, $update = 0) { } } - // check if we serve a mobile device and get the user settings + // check if we serve a mobile device and get the user settings // accordingly - if ($a->is_mobile) { + if ($a->is_mobile) { $itemspage_network = get_pconfig(local_user(),'system','itemspage_mobile_network'); $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 20); - } else { + } else { $itemspage_network = get_pconfig(local_user(),'system','itemspage_network'); $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40); } - // now that we have the user settings, see if the theme forces + // now that we have the user settings, see if the theme forces // a maximum item number which is lower then the user choice if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) $itemspage_network = $a->force_max_items; @@ -745,28 +651,26 @@ function network_content(&$a, $update = 0) { $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); } - $simple_update = (($update) ? " and `item`.`unseen` = 1 " : ''); - if($nouveau) { - // "New Item View" - show all items unthreaded in reverse created date order + $simple_update = (($update) ? " and `item`.`unseen` = 1 " : ''); + // "New Item View" - show all items unthreaded in reverse created date order $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `item`.`uid` = %d AND `item`.`visible` = 1 + FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 + WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 $simple_update - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 $sql_extra $sql_nets ORDER BY `item`.`received` DESC $pager_sql ", intval($_SESSION['uid']) ); $update_unseen = ' WHERE uid = ' . intval($_SESSION['uid']) . " AND unseen = 1 $sql_extra $sql_nets"; - } - else { + } else { // Normal conversation view @@ -782,31 +686,29 @@ function network_content(&$a, $update = 0) { } if ($sql_order == "") - $sql_order = "`item`.$ordering"; + $sql_order = "$sql_table.$ordering"; if (($_GET["offset"] != "")) $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"])); // Fetch a page full of parent items for this page - if($update) { $r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid` - FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND - (`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE ."' OR item.verb = '" . ACTIVITY_DISLIKE . "') - and `item`.`moderated` = 0 and `item`.`unseen` = 1 + FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - $sql_extra3 $sql_extra $sql_nets ", + WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND + (`item`.`deleted` = 0 OR `item`.`verb` = '" . ACTIVITY_LIKE ."' OR `item`.`verb` = '" . ACTIVITY_DISLIKE . "') + and `item`.`moderated` = 0 and `item`.`unseen` = 1 + $sql_extra3 $sql_extra $sql_nets ORDER BY `item_id` DESC LIMIT 100", intval(local_user()) ); - } - else { - $r = q("SELECT `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid` - FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 - AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - AND `item`.`parent` = `item`.`id` - $sql_extra3 $sql_extra $sql_nets + } else { + $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid` + FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` + AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 + WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0 + AND `thread`.`moderated` = 0 + $sql_extra2 $sql_extra3 $sql_extra $sql_nets ORDER BY $sql_order DESC $pager_sql ", intval(local_user()) ); @@ -823,7 +725,7 @@ function network_content(&$a, $update = 0) { if(! in_array($rr['item_id'],$parents_arr)) $parents_arr[] = $rr['item_id']; - //$parents_str = implode(', ', $parents_arr); + $parents_str = implode(", ", $parents_arr); // splitted into separate queries to avoid the problem with very long threads // so always the last X comments are loaded @@ -834,26 +736,25 @@ function network_content(&$a, $update = 0) { $items = array(); - foreach ($parents_arr AS $parents_str) { - + foreach ($parents_arr AS $parents) { +// $sql_extra ORDER BY `item`.`commented` DESC LIMIT %d", $thread_items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`moderated` = 0 - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - AND `item`.`parent` IN ( %s ) - $sql_extra ORDER BY `item`.`commented` DESC LIMIT %d", + AND `item`.`parent` = %d + ORDER BY `item`.`commented` DESC LIMIT %d", intval(local_user()), - dbesc($parents_str), + intval($parents), intval($max_comments + 1) ); $items = array_merge($items, $thread_items); } $items = conv_sort($items,$ordering); - } else { $items = array(); } @@ -871,17 +772,18 @@ function network_content(&$a, $update = 0) { // We aren't going to try and figure out at the item, group, and page // level which items you've seen and which you haven't. If you're looking - // at the top level network page just mark everything seen. + // at the top level network page just mark everything seen. -// The $update_unseen is a bit unreliable if you have stuff coming into your stream from a new contact - -// and other feeds that bring in stuff from the past. One can't find it all. +// The $update_unseen is a bit unreliable if you have stuff coming into your stream from a new contact - +// and other feeds that bring in stuff from the past. One can't find it all. // I'm reviving this block to mark everything seen on page 1 of the network as a temporary measure. // The correct solution is to implement a network notifications box just like the system notifications popup // with the ability in the popup to "mark all seen". // Several people are complaining because there are unseen messages they can't find and as time goes // on they just get buried deeper. It has happened to me a couple of times also. + if((! $group) && (! $cid) && (! $star)) { $r = q("UPDATE `item` SET `unseen` = 0 WHERE `unseen` = 1 AND `uid` = %d", diff --git a/mod/photos.php b/mod/photos.php index dac6dae9b..1ec16898b 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -6,6 +6,7 @@ require_once('include/bbcode.php'); require_once('include/security.php'); require_once('include/redir.php'); require_once('include/tags.php'); +require_once('include/threads.php'); function photos_init(&$a) { @@ -253,6 +254,7 @@ function photos_post(&$a) { intval($page_owner_uid) ); create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid); + delete_thread_uri($rr['parent-uri'], $page_owner_uid); $drop_id = intval($rr['id']); @@ -323,6 +325,7 @@ function photos_post(&$a) { intval($page_owner_uid) ); create_tags_from_itemuri($i[0]['uri'], $page_owner_uid); + delete_thread_uri($i[0]['uri'], $page_owner_uid); $url = $a->get_baseurl(); $drop_id = intval($i[0]['id']); @@ -371,7 +374,7 @@ function photos_post(&$a) { $width = $ph->getWidth(); $height = $ph->getHeight(); - $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0 limit 1", + $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0", dbesc($ph->imageString()), intval($height), intval($width), @@ -384,7 +387,7 @@ function photos_post(&$a) { $width = $ph->getWidth(); $height = $ph->getHeight(); - $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1 limit 1", + $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1", dbesc($ph->imageString()), intval($height), intval($width), @@ -398,7 +401,7 @@ function photos_post(&$a) { $width = $ph->getWidth(); $height = $ph->getHeight(); - $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2 limit 1", + $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2", dbesc($ph->imageString()), intval($height), intval($width), @@ -599,7 +602,7 @@ function photos_post(&$a) { $newinform .= ','; $newinform .= $inform; - $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1", + $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($newtag), dbesc($newinform), dbesc(datetime_convert()), @@ -608,6 +611,7 @@ function photos_post(&$a) { intval($page_owner_uid) ); create_tags_from_item($item_id); + update_thread($item_id); $best = 0; foreach($p as $scales) { @@ -668,7 +672,7 @@ function photos_post(&$a) { $item_id = item_store($arr); if($item_id) { - q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1", + q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d", dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id), intval($page_owner_uid), intval($item_id) @@ -877,7 +881,7 @@ function photos_post(&$a) { $item_id = item_store($arr); if($item_id) { - q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1", + q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d", dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id), intval($page_owner_uid), intval($item_id) @@ -1431,6 +1435,7 @@ function photos_content(&$a) { intval($link_item['parent']), intval(local_user()) ); + update_thread($link_item['parent']); } } diff --git a/mod/profile.php b/mod/profile.php index 28e93b294..c8f6d2a17 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -27,7 +27,7 @@ function profile_init(&$a) { $profile = 0; if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) { $which = $a->user['nickname']; - $profile = $a->argv[1]; + $profile = $a->argv[1]; } else { auto_redir($a, $which); @@ -41,7 +41,7 @@ function profile_init(&$a) { if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY)) { $a->page['htmlhead'] .= ''; } - if(x($a->profile,'openidserver')) + if(x($a->profile,'openidserver')) $a->page['htmlhead'] .= '' . "\r\n"; if(x($a->profile,'openid')) { $delegate = ((strstr($a->profile['openid'],'://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']); @@ -60,7 +60,7 @@ function profile_init(&$a) { $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : '')); $a->page['htmlhead'] .= '' . "\r\n"; header('Link: <' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); - + $dfrn_pages = array('request', 'confirm', 'notify', 'poll'); foreach($dfrn_pages as $dfrn) $a->page['htmlhead'] .= "get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n"; @@ -219,11 +219,11 @@ function profile_content(&$a, $update = 0) { $r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact-uid` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND (`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE ."' OR item.verb = '" . ACTIVITY_DISLIKE . "') and `item`.`moderated` = 0 and `item`.`unseen` = 1 - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `item`.`wall` = 1 $sql_extra ORDER BY `item`.`created` DESC", @@ -238,18 +238,20 @@ function profile_content(&$a, $update = 0) { } if($datequery) { - $sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery)))); + $sql_extra2 .= protect_sprintf(sprintf(" AND `thread`.`created` <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery)))); } if($datequery2) { - $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); + $sql_extra2 .= protect_sprintf(sprintf(" AND `thread`.`created` >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); } if( (! get_config('alt_pager', 'global')) && (! get_pconfig($a->profile['profile_uid'],'system','alt_pager')) ) { $r = q("SELECT COUNT(*) AS `total` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 - and `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1 + FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` + INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` + AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 + WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0 + and `thread`.`moderated` = 0 + AND `thread`.`wall` = 1 $sql_extra $sql_extra2 ", intval($a->profile['profile_uid']) ); @@ -277,16 +279,16 @@ function profile_content(&$a, $update = 0) { $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); - // FROM `item` FORCE INDEX (created, uid) LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - - $r = q("SELECT `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, - `contact`.`uid` AS `contact-uid` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 - and `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 1 + $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, + `thread`.`uid` AS `contact-uid` + FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` + INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` + AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 + WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0 + and `thread`.`moderated` = 0 + AND `thread`.`wall` = 1 $sql_extra $sql_extra2 - ORDER BY `item`.`created` DESC $pager_sql ", + ORDER BY `thread`.`created` DESC $pager_sql ", intval($a->profile['profile_uid']) ); @@ -303,19 +305,19 @@ function profile_content(&$a, $update = 0) { $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`network`, `contact`.`rel`, - `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, + `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` FROM `item`, `contact` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 - AND `contact`.`id` = `item`.`contact-id` + AND `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid` AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `item`.`parent` IN ( %s ) $sql_extra ", intval($a->profile['profile_uid']), dbesc($parents_str) ); - + $items = conv_sort($items,'created'); } else { $items = array(); diff --git a/mod/profiles.php b/mod/profiles.php index 148c63291..3e45f1c45 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -19,7 +19,7 @@ function profiles_init(&$a) { goaway($a->get_baseurl(true) . '/profiles'); return; // NOTREACHED } - + check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't'); // move every contact using this profile as their default to the user default @@ -29,7 +29,7 @@ function profiles_init(&$a) { intval($a->argv[2]), intval(local_user()) ); - $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", + $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d", intval($a->argv[2]), intval(local_user()) ); @@ -45,7 +45,7 @@ function profiles_init(&$a) { if(($a->argc > 1) && ($a->argv[1] === 'new')) { - + check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't'); $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", @@ -56,7 +56,7 @@ function profiles_init(&$a) { $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1", intval(local_user())); - + $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`) VALUES ( %d, '%s', '%s', '%s', '%s' )", intval(local_user()), @@ -74,12 +74,12 @@ function profiles_init(&$a) { info( t('New profile created.') . EOL); if(count($r3) == 1) goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']); - + goaway($a->get_baseurl(true) . '/profiles'); } if(($a->argc > 2) && ($a->argv[1] === 'clone')) { - + check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't'); $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", @@ -117,9 +117,9 @@ function profiles_init(&$a) { info( t('New profile created.') . EOL); if(count($r3) == 1) goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']); - + goaway($a->get_baseurl(true) . '/profiles'); - + return; // NOTREACHED } @@ -160,7 +160,7 @@ function profiles_post(&$a) { notice( t('Profile not found.') . EOL); return; } - + check_form_security_token_redirectOnErr('/profiles', 'profile_edit'); $is_default = (($orig[0]['is-default']) ? 1 : 0); @@ -259,7 +259,7 @@ function profiles_post(&$a) { intval(local_user()) ); }*/ - + $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", dbesc($newname), intval(local_user()) @@ -372,9 +372,9 @@ function profiles_post(&$a) { profile_activity($changes,$value); - } - - $r = q("UPDATE `profile` + } + + $r = q("UPDATE `profile` SET `profile-name` = '%s', `name` = '%s', `pdesc` = '%s', @@ -408,7 +408,7 @@ function profiles_post(&$a) { `work` = '%s', `education` = '%s', `hide-friends` = %d - WHERE `id` = %d AND `uid` = %d LIMIT 1", + WHERE `id` = %d AND `uid` = %d", dbesc($profile_name), dbesc($name), dbesc($pdesc), @@ -451,11 +451,11 @@ function profiles_post(&$a) { if($namechanged && $is_default) { - $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1", + $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d", dbesc(datetime_convert()), intval(local_user()) ); - $r = q("UPDATE `user` set `username` = '%s' where `uid` = %d limit 1", + $r = q("UPDATE `user` set `username` = '%s' where `uid` = %d", dbesc($name), intval(local_user()) ); @@ -554,7 +554,7 @@ function profile_activity($changed, $value) { if($i) { // give it a permanent link - q("update item set plink = '%s' where id = %d limit 1", + q("update item set plink = '%s' where id = %d", dbesc($a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $i), intval($i) ); diff --git a/mod/pubsub.php b/mod/pubsub.php index 7aa95e49c..3d8bfca48 100644 --- a/mod/pubsub.php +++ b/mod/pubsub.php @@ -79,18 +79,18 @@ function pubsub_init(&$a) { if($hub_mode === 'unsubscribe') { if(! strlen($hub_verify)) { - logger('pubsub: bogus unsubscribe'); + logger('pubsub: bogus unsubscribe'); hub_return(false, ''); } logger('pubsub: unsubscribe success'); } - $r = q("UPDATE `contact` SET `subhub` = %d WHERE `id` = %d LIMIT 1", + $r = q("UPDATE `contact` SET `subhub` = %d WHERE `id` = %d", intval($subscribe), intval($contact['id']) ); - hub_return(true, $hub_challenge); + hub_return(true, $hub_challenge); } } diff --git a/mod/search.php b/mod/search.php index cda9f68d2..75c52fc5a 100644 --- a/mod/search.php +++ b/mod/search.php @@ -131,7 +131,7 @@ function search_content(&$a) { //$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d", //$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d group by `item`.`uri` ", // dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); - //$sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; + //$sql_table = "`term` INNER JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; //$sql_order = "`term`.`tid`"; //$sql_order = "`item`.`received`"; @@ -162,11 +162,12 @@ function search_content(&$a) { if( (! get_config('alt_pager', 'global')) && (! get_pconfig(local_user(),'system','alt_pager')) ) { $r = q("SELECT distinct(`item`.`uri`) as `total` - FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` - WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 - AND (( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `user`.`hidewall` = 0) - OR ( `item`.`uid` = %d )) + FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 + INNER JOIN `user` ON `user`.`uid` = `item`.`uid` + WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 + AND (( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `user`.`hidewall` = 0) + OR ( `item`.`uid` = %d )) $sql_extra ", intval(local_user()) ); @@ -186,12 +187,12 @@ function search_content(&$a) { `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`, `user`.`nickname`, `user`.`uid`, `user`.`hidewall` - FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` + FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 + INNER JOIN `user` ON `user`.`uid` = `item`.`uid` WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 AND (( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `user`.`hidewall` = 0 ) OR ( `item`.`uid` = %d )) - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 $sql_extra ORDER BY $sql_order DESC LIMIT %d , %d ", intval(local_user()), diff --git a/mod/share.php b/mod/share.php index 66d07db3c..e9127b647 100644 --- a/mod/share.php +++ b/mod/share.php @@ -9,7 +9,7 @@ function share_init(&$a) { killme(); $r = q("SELECT item.*, contact.network FROM `item` - left join contact on `item`.`contact-id` = `contact`.`id` + inner join contact on `item`.`contact-id` = `contact`.`id` WHERE `item`.`id` = %d AND `item`.`uid` = %d LIMIT 1", intval($post_id), diff --git a/mod/wall_upload.php b/mod/wall_upload.php index 3bd3d8dc2..4cd4e5f52 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -9,7 +9,7 @@ function wall_upload_post(&$a) { if($a->argc > 1) { if(! x($_FILES,'media')) { $nick = $a->argv[1]; - $r = q("SELECT `user`.*, `contact`.`id` FROM `user` LEFT JOIN `contact` on `user`.`uid` = `contact`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1", + $r = q("SELECT `user`.*, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1", dbesc($nick) ); @@ -18,7 +18,7 @@ function wall_upload_post(&$a) { } else { $user_info = api_get_user($a); - $r = q("SELECT `user`.*, `contact`.`id` FROM `user` LEFT JOIN `contact` on `user`.`uid` = `contact`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1", + $r = q("SELECT `user`.*, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1", dbesc($user_info['screen_name']) ); } diff --git a/update.php b/update.php index ed631fee4..c84329511 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ Date: Sun, 9 Mar 2014 09:22:44 +0100 Subject: [PATCH 02/27] Vier: The shadows are reduced a little bit. --- view/theme/vier/style.css | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/view/theme/vier/style.css b/view/theme/vier/style.css index 790161206..65818c545 100644 --- a/view/theme/vier/style.css +++ b/view/theme/vier/style.css @@ -378,8 +378,6 @@ code { list-style: none; border: 3px solid #364e59; z-index: 100000; - -webkit-box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.7); - -moz-box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.7); box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.7); } /* tool */ @@ -446,11 +444,11 @@ code { a.nets-link, .side-link a, #sidebar-new-group a, a.savedsearchterm, a.fileas-link, aside h4 a { display: block; - color: black; + color: #737373; } a.sidebar-group-element { - color: black; + color: #737373; } #follow-sidebar form, #peoplefind-sidebar form, #netsearch-box form, #posted-date-selector { @@ -468,7 +466,7 @@ a.sidebar-group-element { } #forum-list a, .tool a, .admin.link a { - color: black; + color: #737373; } #forum-list { @@ -553,9 +551,6 @@ nav { background: linear-gradient(top, #516499 0%,#364a84 100%); */ color: #ffffff; z-index: 100; - /*-webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.7); - -moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.7); - border-bottom: 5px solid #F80; */ box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.7); } @@ -772,8 +767,6 @@ ul.menu-popup { list-style: none; border: 3px solid #364e59; z-index: 100000; - -webkit-box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.7); - -moz-box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.7); box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.7); } ul.menu-popup a { @@ -814,8 +807,6 @@ ul.menu-popup .empty { border: 1px solid #MenuBorder; overflow: auto; z-index: 100000; - -webkit-box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.7); - -moz-box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.7); box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.7); } .acpopupitem { @@ -878,7 +869,8 @@ aside { padding: 10px 10px 0px 20px; /* border-right: 1px solid #D2D2D2; */ /* background-color: #ECECF2; */ - background-color: #F2F2F2; + /* background-color: #F2F2F2; */ + background-color: #FFFFFF; font-size: 13px; /* background: #F1F1F1; */ /* top: 0px; */ @@ -891,7 +883,8 @@ aside { height: 100%; height: calc(100% - 42px); /* overflow: scroll; */ - box-shadow: 1px 1px 6px -3px #666; + box-shadow: 1px 2px 0px 0px #D8D8D8; + color: #737373; } aside .vcard .fn { font-size: 18px; @@ -1121,7 +1114,7 @@ section.minimal { position: relative; padding: 5px; margin-bottom: 10px; - box-shadow: 1px 1px 6px -3px rgba(0, 0, 0, 0.7); + box-shadow: 1px 2px 0px 0px #D8D8D8; background-color: #FFFFFF; /* width: 755px; */ } @@ -1454,7 +1447,7 @@ section.minimal { } #profile-jot-form { - box-shadow: 1px 1px 6px -3px #666; + box-shadow: 1px 2px 0px 0px #D8D8D8; background-color: #fafafa; padding: 10px; } @@ -1536,8 +1529,6 @@ section.minimal { position: absolute !important; top: 40px; left: 30px; - -webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.7); - -moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.7); box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.7); } .wwto .contact-photo { @@ -1923,18 +1914,18 @@ ul.tabs a { } ul.tabs a { - box-shadow: 1px 1px 6px -3px #666; + box-shadow: 1px 2px 0px 0px #D8D8D8; margin-right: 5px; } #birthday-notice, #event-notice { - box-shadow: 1px 1px 6px -3px #666; + box-shadow: 1px 2px 0px 0px #D8D8D8; margin-bottom: 5px; } #birthday-wrapper, #event-wrapper { background-color: #FAFAFA; - box-shadow: 1px 1px 6px -3px #666; + box-shadow: 1px 2px 0px 0px #D8D8D8; padding-left: 10px; padding-right: 10px; padding-top: 5px; From 9afe5c8670a071b9cd79bcc1cad0f41d386f0cde Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 9 Mar 2014 09:24:41 +0100 Subject: [PATCH 03/27] Support for xcache --- include/config.php | 60 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/include/config.php b/include/config.php index 2664b78a8..e9da8e7b3 100644 --- a/include/config.php +++ b/include/config.php @@ -66,12 +66,22 @@ function get_config($family, $key, $instore = false) { } } - // If APC is enabled then fetch the data from there + // If APC is enabled then fetch the data from there, else try XCache if (function_exists("apc_fetch") AND function_exists("apc_exists")) if (apc_exists($family."|".$key)) { $val = apc_fetch($family."|".$key); $a->config[$family][$key] = $val; + if ($val === '!!') + return false; + else + return $val; + } + elseif (function_exists("xcache_fetch") AND function_exists("xcache_isset")) + if (xcache_isset($family."|".$key)) { + $val = xcache_fetch($family."|".$key); + $a->config[$family][$key] = $val; + if ($val === '!!') return false; else @@ -87,18 +97,22 @@ function get_config($family, $key, $instore = false) { $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']); $a->config[$family][$key] = $val; - // If APC is enabled then store the data there + // If APC is enabled then store the data there, else try XCache if (function_exists("apc_store")) apc_store($family."|".$key, $val, 600); + elseif (function_exists("xcache_set")) + xcache_set($family."|".$key, $val, 600); return $val; } else { $a->config[$family][$key] = '!!'; - // If APC is enabled then store the data there + // If APC is enabled then store the data there, else try XCache if (function_exists("apc_store")) apc_store($family."|".$key, '!!', 600); + elseif (function_exists("xcache_set")) + xcache_set($family."|".$key, '!!', 600); } return false; }} @@ -134,7 +148,7 @@ function set_config($family,$key,$value) { return $ret; } - $ret = q("UPDATE `config` SET `v` = '%s' WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1", + $ret = q("UPDATE `config` SET `v` = '%s' WHERE `cat` = '%s' AND `k` = '%s'", dbesc($dbvalue), dbesc($family), dbesc($key) @@ -142,9 +156,11 @@ function set_config($family,$key,$value) { $a->config[$family][$key] = $value; - // If APC is enabled then store the data there + // If APC is enabled then store the data there, else try XCache if (function_exists("apc_store")) apc_store($family."|".$key, $value, 600); + elseif (function_exists("xcache_set")) + xcache_set($family."|".$key, $value, 600); if($ret) return $value; @@ -193,7 +209,7 @@ function get_pconfig($uid,$family, $key, $instore = false) { } } - // If APC is enabled then fetch the data from there + // If APC is enabled then fetch the data from there, else try XCache if (function_exists("apc_fetch") AND function_exists("apc_exists")) if (apc_exists($uid."|".$family."|".$key)) { $val = apc_fetch($uid."|".$family."|".$key); @@ -204,6 +220,16 @@ function get_pconfig($uid,$family, $key, $instore = false) { else return $val; } + elseif (function_exists("xcache_get") AND function_exists("xcache_isset")) + if (xcache_isset($uid."|".$family."|".$key)) { + $val = xcache_get($uid."|".$family."|".$key); + $a->config[$uid][$family][$key] = $val; + + if ($val === '!!') + return false; + else + return $val; + } $ret = q("SELECT `v` FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' LIMIT 1", @@ -216,18 +242,22 @@ function get_pconfig($uid,$family, $key, $instore = false) { $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']); $a->config[$uid][$family][$key] = $val; - // If APC is enabled then store the data there + // If APC is enabled then store the data there, else try XCache if (function_exists("apc_store")) apc_store($uid."|".$family."|".$key, $val, 600); + elseif (function_exists("xcache_set")) + xcache_set($uid."|".$family."|".$key, $val, 600); return $val; } else { $a->config[$uid][$family][$key] = '!!'; - // If APC is enabled then store the data there + // If APC is enabled then store the data there, else try XCache if (function_exists("apc_store")) apc_store($uid."|".$family."|".$key, '!!', 600); + elseif (function_exists("xcache_set")) + xcache_set($uid."|".$family."|".$key, '!!', 600); } return false; }} @@ -238,13 +268,15 @@ function del_config($family,$key) { global $a; if(x($a->config[$family],$key)) unset($a->config[$family][$key]); - $ret = q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1", + $ret = q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s'", dbesc($family), dbesc($key) ); - // If APC is enabled then store the data there + // If APC is enabled then delete the data from there, else try XCache if (function_exists("apc_delete")) apc_delete($family."|".$key); + elseif (function_exists("xcache_unset")) + xcache_unset($family."|".$key); return $ret; }} @@ -274,7 +306,7 @@ function set_pconfig($uid,$family,$key,$value) { return $value; return $ret; } - $ret = q("UPDATE `pconfig` SET `v` = '%s' WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' LIMIT 1", + $ret = q("UPDATE `pconfig` SET `v` = '%s' WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s'", dbesc($dbvalue), intval($uid), dbesc($family), @@ -283,9 +315,11 @@ function set_pconfig($uid,$family,$key,$value) { $a->config[$uid][$family][$key] = $value; - // If APC is enabled then store the data there + // If APC is enabled then store the data there, else try XCache if (function_exists("apc_store")) apc_store($uid."|".$family."|".$key, $value, 600); + elseif (function_exists("xcache_set")) + xcache_set($uid."|".$family."|".$key, $value, 600); if($ret) @@ -299,7 +333,7 @@ function del_pconfig($uid,$family,$key) { global $a; if(x($a->config[$uid][$family],$key)) unset($a->config[$uid][$family][$key]); - $ret = q("DELETE FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' LIMIT 1", + $ret = q("DELETE FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s'", intval($uid), dbesc($family), dbesc($key) From 7cec1bbfdfc1571797bc368d815e7d8f7d63ecd0 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 9 Mar 2014 09:25:57 +0100 Subject: [PATCH 04/27] Removed another "limit 1" --- include/Photo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Photo.php b/include/Photo.php index f1c9128d3..45164333d 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -595,7 +595,7 @@ class Photo { `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' - where id = %d limit 1", + where id = %d", intval($uid), intval($cid), From 9f4ef7c105371fee195b0c506772496e50ec8e7e Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 9 Mar 2014 09:26:54 +0100 Subject: [PATCH 05/27] Avoiding some PHP warnings --- include/html2plain.php | 7 ++++--- object/Item.php | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/html2plain.php b/include/html2plain.php index 445a4ab34..54cc44794 100644 --- a/include/html2plain.php +++ b/include/html2plain.php @@ -221,9 +221,10 @@ function html2plain($html, $wraplength = 75, $compact = false) if (!$compact AND ($message != "")) { $counter = 1; foreach ($urls as $id=>$url) - if (strpos($message, $url) === false) - $message .= "\n".$url." "; - //$message .= "\n[".($counter++)."] ".$url; + if ($url != "") + if (strpos($message, $url) === false) + $message .= "\n".$url." "; + //$message .= "\n[".($counter++)."] ".$url; } $message = str_replace("\n«", "«\n", $message); diff --git a/object/Item.php b/object/Item.php index 2cb131f1a..17a723acb 100644 --- a/object/Item.php +++ b/object/Item.php @@ -269,22 +269,22 @@ class Item extends BaseObject { } // Disable features that aren't available in several networks - if ($item["item_network"] != "dfrn") { + if (($item["item_network"] != "dfrn") AND isset($buttons["dislike"])) { unset($buttons["dislike"]); $tagger = ''; } - if ($item["item_network"] == "feed") + if (($item["item_network"] == "feed") AND isset($buttons["like"])) unset($buttons["like"]); - if ($item["item_network"] == "mail") + if (($item["item_network"] == "mail") AND isset($buttons["like"])) unset($buttons["like"]); - if (($item["item_network"] == "dspr") AND ($indent == 'comment')) + if (($item["item_network"] == "dspr") AND ($indent == 'comment') AND isset($buttons["like"])) unset($buttons["like"]); // Facebook can like comments - but it isn't programmed in the connector yet. - if (($item["item_network"] == "face") AND ($indent == 'comment')) + if (($item["item_network"] == "face") AND ($indent == 'comment') AND isset($buttons["like"])) unset($buttons["like"]); From 6e7bd68ebb027b90398eee4fcc3bd73912a881e3 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 11 Mar 2014 23:52:32 +0100 Subject: [PATCH 06/27] More "LIMIT 1" removed - and some other SQL improvements. --- include/Contact.php | 10 ++--- include/acl_selectors.php | 12 ++--- include/api.php | 44 ++++++++++++------- include/cache.php | 2 +- include/datetime.php | 6 +-- include/enotify.php | 16 +++---- include/event.php | 8 ++-- include/follow.php | 20 ++++----- include/group.php | 18 ++++---- include/notifier.php | 24 +++++----- include/oauth.php | 12 ++--- include/security.php | 6 +-- include/text.php | 10 ++--- mod/community.php | 3 +- mod/crepair.php | 4 +- mod/dfrn_confirm.php | 92 +++++++++++++++++++-------------------- mod/dfrn_request.php | 28 ++++++------ mod/events.php | 18 ++++---- mod/fsuggest.php | 4 +- mod/group.php | 16 +++---- mod/like.php | 10 ++--- mod/lostpass.php | 4 +- mod/mood.php | 10 ++--- mod/notifications.php | 4 +- mod/poke.php | 20 ++++----- mod/profile_photo.php | 26 +++++------ mod/profiles.php | 18 ++++---- mod/profperm.php | 8 ++-- mod/settings.php | 18 ++++---- mod/starred.php | 2 +- mod/subthread.php | 8 ++-- mod/tagger.php | 22 +++++----- mod/tagrm.php | 2 +- update.php | 24 +++++----- 34 files changed, 271 insertions(+), 258 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index af7786998..a6429bbf4 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -64,13 +64,13 @@ function contact_remove($id) { $archive = get_pconfig($r[0]['uid'], 'system','archive_removed_contacts'); if($archive) { - q("update contact set `archive` = 1, `network` = 'none', `writable` = 0 where id = %d limit 1", + q("update contact set `archive` = 1, `network` = 'none', `writable` = 0 where id = %d", intval($id) ); return; } - q("DELETE FROM `contact` WHERE `id` = %d LIMIT 1", + q("DELETE FROM `contact` WHERE `id` = %d", intval($id) ); q("DELETE FROM `item` WHERE `contact-id` = %d ", @@ -148,7 +148,7 @@ function mark_for_death($contact) { return; if($contact['term-date'] == '0000-00-00 00:00:00') { - q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d LIMIT 1", + q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), intval($contact['id']) ); @@ -166,7 +166,7 @@ function mark_for_death($contact) { // archive them rather than delete // though if the owner tries to unarchive them we'll start the whole process over again - q("update contact set `archive` = 1 where id = %d limit 1", + q("update contact set `archive` = 1 where id = %d", intval($contact['id']) ); q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact['id']), intval($contact['uid'])); @@ -181,7 +181,7 @@ function mark_for_death($contact) { if(! function_exists('unmark_for_death')) { function unmark_for_death($contact) { // It's a miracle. Our dead contact has inexplicably come back to life. - q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d LIMIT 1", + q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d", dbesc('0000-00-00 00:00:00'), intval($contact['id']) ); diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 72c434692..ee74ccc16 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -399,19 +399,19 @@ function acl_lookup(&$a, $out_type = 'json') { } else { $sql_extra = $sql_extra2 = ""; } - + // count groups and contacts if ($type=='' || $type=='g'){ - $r = q("SELECT COUNT(`id`) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra", + $r = q("SELECT COUNT(*) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra", intval(local_user()) ); $group_count = (int)$r[0]['g']; } else { $group_count = 0; } - + if ($type=='' || $type=='c'){ - $r = q("SELECT COUNT(`id`) AS c FROM `contact` + $r = q("SELECT COUNT(*) AS c FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != '' $sql_extra2" , @@ -423,7 +423,7 @@ function acl_lookup(&$a, $out_type = 'json') { // autocomplete for Private Messages - $r = q("SELECT COUNT(`id`) AS c FROM `contact` + $r = q("SELECT COUNT(*) AS c FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `network` IN ('%s','%s','%s') $sql_extra2" , @@ -439,7 +439,7 @@ function acl_lookup(&$a, $out_type = 'json') { // autocomplete for Contacts - $r = q("SELECT COUNT(`id`) AS c FROM `contact` + $r = q("SELECT COUNT(*) AS c FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra2" , intval(local_user()) diff --git a/include/api.php b/include/api.php index 72a64f2ac..0a63a2c04 100644 --- a/include/api.php +++ b/include/api.php @@ -384,26 +384,26 @@ intval(api_user()) ); + //AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''", // count public wall messages - $r = q("SELECT COUNT(`id`) as `count` FROM `item` + $r = q("SELECT count(*) as `count` FROM `item` force index (uid_type) WHERE `uid` = %d - AND `type`='wall' - AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''", + AND `type`='wall'", intval($uinfo[0]['uid']) ); $countitms = $r[0]['count']; } else { - $r = q("SELECT COUNT(`id`) as `count` FROM `item` - WHERE `contact-id` = %d - AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''", + //AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''", + $r = q("SELECT count(*) as `count` FROM `item` + WHERE `contact-id` = %d", intval($uinfo[0]['id']) ); $countitms = $r[0]['count']; } // count friends - $r = q("SELECT COUNT(`id`) as `count` FROM `contact` + $r = q("SELECT count(*) as `count` FROM `contact` WHERE `uid` = %d AND `rel` IN ( %d, %d ) AND `self`=0 AND `blocked`=0 AND `pending`=0 AND `hidden`=0", intval($uinfo[0]['uid']), @@ -412,7 +412,7 @@ ); $countfriends = $r[0]['count']; - $r = q("SELECT COUNT(`id`) as `count` FROM `contact` + $r = q("SELECT count(*) as `count` FROM `contact` WHERE `uid` = %d AND `rel` IN ( %d, %d ) AND `self`=0 AND `blocked`=0 AND `pending`=0 AND `hidden`=0", intval($uinfo[0]['uid']), @@ -421,7 +421,7 @@ ); $countfollowers = $r[0]['count']; - $r = q("SELECT count(`id`) as `count` FROM item where starred = 1 and uid = %d and deleted = 0", + $r = q("SELECT count(*) as `count` FROM item where starred = 1 and uid = %d and deleted = 0", intval($uinfo[0]['uid']) ); $starred = $r[0]['count']; @@ -528,7 +528,8 @@ $status_user["protected"] = (($item["allow_cid"] != "") OR ($item["allow_gid"] != "") OR ($item["deny_cid"] != "") OR - ($item["deny_gid"] != "")); + ($item["deny_gid"] != "") OR + $item["private"]); return ($status_user); } @@ -745,12 +746,27 @@ logger('api_status_show: user_info: '.print_r($user_info, true), LOGGER_DEBUG); // get last public wall message - $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `c`.`nick` as `reply_author`, `i`.`author-link` AS `item-author` - FROM `item`, `contact`, `item` as `i`, `contact` as `c` + //$lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `c`.`nick` as `reply_author`, `i`.`author-link` AS `item-author` + // FROM `item`, `contact`, `item` as `i`, `contact` as `c` + // WHERE `item`.`contact-id` = %d + // AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s'))) + // AND `i`.`id` = `item`.`parent` + // AND `contact`.`id`=`item`.`contact-id` AND `c`.`id`=`i`.`contact-id` AND `contact`.`self`=1 + // AND `item`.`type`!='activity' + // AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`='' + // ORDER BY `item`.`created` DESC + // LIMIT 1", + // intval($user_info['cid']), + // dbesc($user_info['url']), + // dbesc(normalise_link($user_info['url'])), + // dbesc($user_info['url']), + // dbesc(normalise_link($user_info['url'])) + //); + $lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`author-link` AS `item-author` + FROM `item`, `item` as `i` WHERE `item`.`contact-id` = %d AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s'))) AND `i`.`id` = `item`.`parent` - AND `contact`.`id`=`item`.`contact-id` AND `c`.`id`=`i`.`contact-id` AND `contact`.`self`=1 AND `item`.`type`!='activity' AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`='' ORDER BY `item`.`created` DESC @@ -773,8 +789,6 @@ if ($lastwall['parent']!=$lastwall['id']) { $in_reply_to_status_id= intval($lastwall['parent']); $in_reply_to_status_id_str = (string) intval($lastwall['parent']); - //$in_reply_to_user_id = $lastwall['reply_uid']; - //$in_reply_to_screen_name = $lastwall['reply_author']; $r = q("SELECT * FROM unique_contacts WHERE `url` = '%s'", dbesc(normalise_link($lastwall['item-author']))); if ($r) { diff --git a/include/cache.php b/include/cache.php index e6ea8f045..86539310a 100644 --- a/include/cache.php +++ b/include/cache.php @@ -47,7 +47,7 @@ * dbesc($key) * ); * if(count($r)) { - * q("UPDATE `cache` SET `v` = '%s', `updated = '%s' WHERE `k` = '%s' limit 1", + * q("UPDATE `cache` SET `v` = '%s', `updated = '%s' WHERE `k` = '%s'", * dbesc($value), * dbesc(datetime_convert()), * dbesc($key)); diff --git a/include/datetime.php b/include/datetime.php index efcfa0a17..3ad9ea3a1 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -19,7 +19,7 @@ if(! function_exists('select_timezone')) { function select_timezone($current = 'America/Los_Angeles') { $timezone_identifiers = DateTimeZone::listIdentifiers(); - + $o ='