From 76aa9b3037a69d7d3be7e2f7c1416438a30dd577 Mon Sep 17 00:00:00 2001 From: Michael Johnston Date: Sun, 22 Apr 2012 13:37:25 -0400 Subject: api: add support for StatusNet-style media param to API --- include/api.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/api.php b/include/api.php index 0885a1434..f9be68c3d 100644 --- a/include/api.php +++ b/include/api.php @@ -567,8 +567,17 @@ $_REQUEST['profile_uid'] = local_user(); if(requestdata('parent')) $_REQUEST['type'] = 'net-comment'; - else + else { $_REQUEST['type'] = 'wall'; + if(x($_FILES,'media')) { + // upload the image if we have one + $_REQUEST['hush']='yeah'; //tell wall_upload function to return img info instead of echo + require_once('mod/wall_upload.php'); + $media = wall_upload_post($a); + if(strlen($media)>0) + $_REQUEST['body'] .= "\n\n".$media; + } + } // set this so that the item_post() function is quiet and doesn't redirect or emit json -- cgit v1.2.3 From 2170df897b9dc72b87cc104520f6a67ddfbb994f Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 22 Apr 2012 19:19:02 -0700 Subject: bug #388 - notify_comment received after post deleted --- include/diaspora.php | 2 +- include/items.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 06df9c24a..afd86957b 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1172,7 +1172,7 @@ function diaspora_comment($importer,$xml,$msg) { proc_run('php','include/notifier.php','comment',$message_id); } - $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 ", + $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0 ", dbesc($parent_item['uri']), intval($importer['uid']) ); diff --git a/include/items.php b/include/items.php index 0a8bc12c0..07f62ece5 100644 --- a/include/items.php +++ b/include/items.php @@ -2479,7 +2479,7 @@ function local_delivery($importer,$data) { if(!x($datarray['type']) || $datarray['type'] != 'activity') { - $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 ", + $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0", dbesc($parent_uri), intval($importer['importer_uid']) ); -- cgit v1.2.3 From e9e4fb664aab0f6cc4e8696eafc9ddba0797c11d Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 23 Apr 2012 05:42:46 -0700 Subject: allow bbcode representation of html symbols such as © by wrapping in bb brackets --- include/bbcode.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 3697f1fc5..85d310b75 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -298,6 +298,9 @@ function bbcode($Text,$preserve_nl = false) { $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_unspacefy_and_trim',$Text); $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_unspacefy_and_trim',$Text); + + $Text = preg_replace('/\[\&\;([#a-z0-9]+)\;\]/','&$1;',$Text); + // fix any escaped ampersands that may have been converted into links $Text = preg_replace("/\<(.*?)(src|href)=(.*?)\&\;(.*?)\>/ism",'<$1$2=$3&$4>',$Text); if(strlen($saved_image)) -- cgit v1.2.3 From 363753411914ab9d2678c5b47f432e5357ad7a04 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 23 Apr 2012 19:42:57 -0700 Subject: move unfriend to standalone function for use in account removal --- include/Contact.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'include') diff --git a/include/Contact.php b/include/Contact.php index 9ba1e8ae5..537850e00 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -73,6 +73,49 @@ function contact_remove($id) { } +// sends an unfriend message. Does not remove the contact + +function terminate_friendship($user,$self,$contact) { + + + $a = get_app(); + + require_once('include/datetime.php'); + + if($contact['network'] === NETWORK_OSTATUS) { + + $slap = replace_macros(get_markup_template('follow_slap.tpl'), array( + '$name' => $user['username'], + '$profile_page' => $a->get_baseurl() . '/profile/' . $user['nickname'], + '$photo' => $self['photo'], + '$thumb' => $self['thumb'], + '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME), + '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(), + '$title' => '', + '$type' => 'text', + '$content' => t('stopped following'), + '$nick' => $user['nickname'], + '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW, + '$ostat_follow' => '' // 'http://ostatus.org/schema/1.0/unfollow' . "\r\n" + )); + + if((x($contact,'notify')) && (strlen($contact['notify']))) { + require_once('include/salmon.php'); + slapper($user,$contact['notify'],$slap); + } + } + elseif($contact['network'] === NETWORK_DIASPORA) { + require_once('include/diaspora.php'); + diaspora_unshare($user,$contact); + } + elseif($contact['network'] === NETWORK_DFRN) { + require_once('include/items.php'); + dfrn_deliver($user,$contact,'placeholder', 1); + } + +} + + // Contact has refused to recognise us as a friend. We will start a countdown. // If they still don't recognise us in 32 days, the relationship is over, // and we won't waste any more time trying to communicate with them. -- cgit v1.2.3 From 2064d86cb39c20b738ba5f8ca35d4102216a5c30 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 23 Apr 2012 22:41:32 -0700 Subject: separate tag search from body search --- include/diaspora.php | 12 ++++++------ include/html2plain.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index afd86957b..5069c1127 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -706,10 +706,10 @@ function diaspora_post($importer,$xml) { continue; $basetag = str_replace('_',' ',substr($tag,1)); - $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body); + $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body); if(strlen($str_tags)) $str_tags .= ','; - $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]'; + $str_tags .= '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]'; continue; } } @@ -872,10 +872,10 @@ function diaspora_reshare($importer,$xml) { $basetag = str_replace('_',' ',substr($tag,1)); - $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body); + $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body); if(strlen($str_tags)) $str_tags .= ','; - $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]'; + $str_tags .= '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]'; continue; } } @@ -1113,10 +1113,10 @@ function diaspora_comment($importer,$xml,$msg) { $basetag = str_replace('_',' ',substr($tag,1)); - $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body); + $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body); if(strlen($str_tags)) $str_tags .= ','; - $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]'; + $str_tags .= '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]'; continue; } } diff --git a/include/html2plain.php b/include/html2plain.php index 21261327d..839dd70a7 100644 --- a/include/html2plain.php +++ b/include/html2plain.php @@ -83,7 +83,7 @@ function collecturls($message) { $urls = array(); foreach ($result as $treffer) { // A list of some links that should be ignored - $list = array("/user/", "/tag/", "/group/", "/profile/", "/search?search=", "mailto:", "/u/", "/node/", + $list = array("/user/", "/tag/", "/group/", "/profile/", "/search?search=", "/search?tag=", "mailto:", "/u/", "/node/", "//facebook.com/profile.php?id=", "//plus.google.com/"); foreach ($list as $listitem) if (strpos($treffer[1], $listitem) !== false) -- cgit v1.2.3 From 3c6cf1f19ce783fe1b3b735cc405bf052d25aad7 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 26 Apr 2012 19:55:20 -0700 Subject: make comment edit icons look more like base theme --- include/conversation.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 1b869b91e..521b4623b 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -553,6 +553,14 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { '$myphoto' => $a->contact['thumb'], '$comment' => t('Comment'), '$submit' => t('Submit'), + '$edbold' => t('Bold'), + '$editalic' => t('Italic'), + '$eduline' => t('Underline'), + '$edquote' => t('Quote'), + '$edcode' => t('Code'), + '$edimg' => t('Image'), + '$edurl' => t('Link'), + '$edvideo' => t('Video'), '$preview' => t('Preview'), '$ww' => (($mode === 'network') ? $commentww : '') )); -- cgit v1.2.3 From 26c53580d128d3ebbbc3d6172525b80690a63255 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 27 Apr 2012 17:17:58 -0700 Subject: implement contact archival --- include/acl_selectors.php | 4 ++-- include/notifier.php | 7 ++++--- include/text.php | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/acl_selectors.php b/include/acl_selectors.php index a5f5aff53..461ad0c36 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -122,7 +122,7 @@ function contact_selector($selname, $selclass, $preselected = false, $options) { $o .= "\r\n"; $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact` - WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != '' + WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != '' $sql_extra ORDER BY `name` ASC ", intval(local_user()) diff --git a/include/notifier.php b/include/notifier.php index ca7c7b92e..922e869f6 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -304,7 +304,7 @@ function notifier_run($argv, $argc){ $conversant_str = dbesc(implode(', ',$conversants)); } - $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0"); + $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0"); if(count($r)) $contacts = $r; @@ -520,7 +520,8 @@ function notifier_run($argv, $argc){ `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid` - WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0 + WHERE `contact`.`blocked` = 0 AND `contact`.`archive` = 0 + AND `contact`.`pending` = 0 AND `contact`.`network` = '%s' AND `user`.`nickname` = '%s' $sql_extra AND `user`.`account_expired` = 0 LIMIT 1", @@ -769,7 +770,7 @@ function notifier_run($argv, $argc){ ); $r2 = q("SELECT `id`, `name`,`network` FROM `contact` - WHERE `network` in ( '%s', '%s') AND `uid` = %d AND `blocked` = 0 AND `pending` = 0 + WHERE `network` in ( '%s', '%s') AND `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `rel` != %d order by rand() ", dbesc(NETWORK_DFRN), dbesc(NETWORK_MAIL2), diff --git a/include/text.php b/include/text.php index 8c8db66a9..af32b2476 100644 --- a/include/text.php +++ b/include/text.php @@ -558,7 +558,7 @@ function contact_block() { if((! is_array($a->profile)) || ($a->profile['hide-friends'])) return $o; - $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0", + $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 AND `archive` = 0", intval($a->profile['uid']) ); if(count($r)) { @@ -569,7 +569,7 @@ function contact_block() { $micropro = Null; } else { - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 ORDER BY RAND() LIMIT %d", + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 AND `archive` = 0 ORDER BY RAND() LIMIT %d", intval($a->profile['uid']), intval($shown) ); -- cgit v1.2.3 From f163aed66d2aec038131131c68110043de36137a Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 27 Apr 2012 23:17:40 -0700 Subject: break up poller into separate processes --- include/onepoll.php | 519 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/poller.php | 437 +------------------------------------------ 2 files changed, 525 insertions(+), 431 deletions(-) create mode 100644 include/onepoll.php (limited to 'include') diff --git a/include/onepoll.php b/include/onepoll.php new file mode 100644 index 000000000..4ae34664f --- /dev/null +++ b/include/onepoll.php @@ -0,0 +1,519 @@ +set_baseurl(get_config('system','url')); + + load_hooks(); + + logger('onepoll: start'); + + $abandon_days = intval(get_config('system','account_abandon_days')); + if($abandon_days < 1) + $abandon_days = 0; + + + $manual_id = 0; + $generation = 0; + $hub_update = false; + $force = false; + $restart = false; + + if(($argc > 1) && (intval($argv[1]))) + $contact_id = intval($argv[1]); + + if(! $contact_id) { + logger('onepoll: no contact'); + return; + } + + $d = datetime_convert(); + + // Only poll from those with suitable relationships, + // and which have a polling address and ignore Diaspora since + // we are unable to match those posts with a Diaspora GUID and prevent duplicates. + + $abandon_sql = (($abandon_days) + ? sprintf(" AND `user`.`login_date` > UTC_TIMESTAMP() - INTERVAL %d DAY ", intval($abandon_days)) + : '' + ); + + $contacts = q("SELECT `contact`.* FROM `contact` + WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != '' + AND NOT `network` IN ( '%s', '%s' ) + AND `contact`.`id` = %d + AND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0 + AND `contact`.`archive` = 0 LIMIT 1", + intval(CONTACT_IS_SHARING), + intval(CONTACT_IS_FRIEND), + dbesc(NETWORK_DIASPORA), + dbesc(NETWORK_FACEBOOK), + intval($contact_id) + ); + + if(! count($contacts)) { + return; + } + + $contact = $contacts[0]; + + + $xml = false; + + $t = $contact['last-update']; + + if($contact['subhub']) { + $interval = get_config('system','pushpoll_frequency'); + $contact['priority'] = (($interval !== false) ? intval($interval) : 3); + $hub_update = false; + + if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) + $hub_update = true; + } + else + $hub_update = false; + + + $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", + intval($importer_uid) + ); + if(! count($r)) + continue; + + $importer = $r[0]; + + logger("onepoll: poll: ({$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}"); + + $last_update = (($contact['last-update'] === '0000-00-00 00:00:00') + ? datetime_convert('UTC','UTC','now - 7 days', ATOM_TIME) + : datetime_convert('UTC','UTC',$contact['last-update'], ATOM_TIME) + ); + + if($contact['network'] === NETWORK_DFRN) { + + $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']); + if(intval($contact['duplex']) && $contact['dfrn-id']) + $idtosend = '0:' . $orig_id; + if(intval($contact['duplex']) && $contact['issued-id']) + $idtosend = '1:' . $orig_id; + + // they have permission to write to us. We already filtered this in the contact query. + $perm = 'rw'; + + $url = $contact['poll'] . '?dfrn_id=' . $idtosend + . '&dfrn_version=' . DFRN_PROTOCOL_VERSION + . '&type=data&last_update=' . $last_update + . '&perm=' . $perm ; + + $handshake_xml = fetch_url($url); + + logger('onepoll: handshake with url ' . $url . ' returns xml: ' . $handshake_xml, LOGGER_DATA); + + + if(! $handshake_xml) { + logger("poller: $url appears to be dead - marking for death "); + // dead connection - might be a transient event, or this might + // mean the software was uninstalled or the domain expired. + // Will keep trying for one month. + mark_for_death($contact); + + // set the last-update so we don't keep polling + $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1", + dbesc(datetime_convert()), + intval($contact['id']) + ); + + continue; + } + + if(! strstr($handshake_xml,'status) == 1) { + logger("poller: $url replied status 1 - marking for death "); + + // we may not be friends anymore. Will keep trying for one month. + // set the last-update so we don't keep polling + + + $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1", + dbesc(datetime_convert()), + intval($contact['id']) + ); + mark_for_death($contact); + } + else { + if($contact['term-date'] != '0000-00-00 00:00:00') { + logger("poller: $url back from the dead - removing mark for death"); + unmark_for_death($contact); + } + } + + if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) + continue; + + if(((float) $res->dfrn_version > 2.21) && ($contact['poco'] == '')) { + q("update contact set poco = '%s' where id = %d limit 1", + dbesc(str_replace('/profile/','/poco/', $contact['url'])), + intval($contact['id']) + ); + } + + $postvars = array(); + + $sent_dfrn_id = hex2bin((string) $res->dfrn_id); + $challenge = hex2bin((string) $res->challenge); + + $final_dfrn_id = ''; + + if(($contact['duplex']) && strlen($contact['prvkey'])) { + openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']); + openssl_private_decrypt($challenge,$postvars['challenge'],$contact['prvkey']); + } + else { + openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']); + openssl_public_decrypt($challenge,$postvars['challenge'],$contact['pubkey']); + } + + $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.')); + + if(strpos($final_dfrn_id,':') == 1) + $final_dfrn_id = substr($final_dfrn_id,2); + + if($final_dfrn_id != $orig_id) { + logger('poller: ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id); + // did not decode properly - cannot trust this site + continue; + } + + $postvars['dfrn_id'] = $idtosend; + $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; + $postvars['perm'] = 'rw'; + + $xml = post_url($contact['poll'],$postvars); + + } + elseif(($contact['network'] === NETWORK_OSTATUS) + || ($contact['network'] === NETWORK_DIASPORA) + || ($contact['network'] === NETWORK_FEED) ) { + + // Upgrading DB fields from an older Friendica version + // Will only do this once per notify-enabled OStatus contact + // or if relationship changes + + $stat_writeable = ((($contact['notify']) && ($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['rel'] == CONTACT_IS_FRIEND)) ? 1 : 0); + + if($stat_writeable != $contact['writable']) { + q("UPDATE `contact` SET `writable` = %d WHERE `id` = %d LIMIT 1", + intval($stat_writeable), + intval($contact['id']) + ); + } + + // Are we allowed to import from this person? + + if($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['blocked'] || $contact['readonly']) + continue; + + $xml = fetch_url($contact['poll']); + } + elseif($contact['network'] === NETWORK_MAIL || $contact['network'] === NETWORK_MAIL2) { + + logger("onepoll: mail: Fetching", LOGGER_DEBUG); + + $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); + if($mail_disabled) + continue; + + logger("onepoll: Mail: Enabled", LOGGER_DEBUG); + + $mbox = null; + $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", + intval($importer_uid) + ); + $mailconf = q("SELECT * FROM `mailacct` WHERE `server` != '' AND `uid` = %d LIMIT 1", + intval($importer_uid) + ); + if(count($x) && count($mailconf)) { + $mailbox = construct_mailbox_name($mailconf[0]); + $password = ''; + openssl_private_decrypt(hex2bin($mailconf[0]['pass']),$password,$x[0]['prvkey']); + $mbox = email_connect($mailbox,$mailconf[0]['user'],$password); + unset($password); + logger("Mail: Connect"); + if($mbox) { + q("UPDATE `mailacct` SET `last_check` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1", + dbesc(datetime_convert()), + intval($mailconf[0]['id']), + intval($importer_uid) + ); + } + } + if($mbox) { + + $msgs = email_poll($mbox,$contact['addr']); + + if(count($msgs)) { + logger("Mail: Parsing ".count($msgs)." mails.", LOGGER_DEBUG); + + foreach($msgs as $msg_uid) { + logger("Mail: Parsing mail ".$msg_uid, LOGGER_DATA); + + $datarray = array(); + $meta = email_msg_meta($mbox,$msg_uid); + $headers = email_msg_headers($mbox,$msg_uid); + + // look for a 'references' header and try and match with a parent item we have locally. + + $raw_refs = ((x($headers,'references')) ? str_replace("\t",'',$headers['references']) : ''); + $datarray['uri'] = msgid2iri(trim($meta->message_id,'<>')); + + if($raw_refs) { + $refs_arr = explode(' ', $raw_refs); + if(count($refs_arr)) { + for($x = 0; $x < count($refs_arr); $x ++) + $refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'"; + } + $qstr = implode(',',$refs_arr); + $r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `uri` IN ( $qstr ) AND `uid` = %d LIMIT 1", + intval($importer_uid) + ); + if(count($r)) + $datarray['parent-uri'] = $r[0]['uri']; + } + + + if(! x($datarray,'parent-uri')) + $datarray['parent-uri'] = $datarray['uri']; + + // Have we seen it before? + $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", + intval($importer_uid), + dbesc($datarray['uri']) + ); + + if(count($r)) { +// logger("Mail: Seen before ".$msg_uid); + if($meta->deleted && ! $r[0]['deleted']) { + q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1", + dbesc(datetime_convert()), + intval($r[0]['id']) + ); + } + switch ($mailconf[0]['action']) { + case 0: + break; + case 1: + logger("Mail: Deleting ".$msg_uid); + imap_delete($mbox, $msg_uid, FT_UID); + break; + case 2: + logger("Mail: Mark as seen ".$msg_uid); + imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); + break; + case 3: + logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']); + imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); + if ($mailconf[0]['movetofolder'] != "") + imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID); + break; + } + continue; + } + + // Decoding the header + $subject = imap_mime_header_decode($meta->subject); + $datarray['title'] = ""; + foreach($subject as $subpart) + if ($subpart->charset != "default") + $datarray['title'] .= iconv($subpart->charset, 'UTF-8//IGNORE', $subpart->text); + else + $datarray['title'] .= $subpart->text; + + $datarray['title'] = notags(trim($datarray['title'])); + + //$datarray['title'] = notags(trim($meta->subject)); + $datarray['created'] = datetime_convert('UTC','UTC',$meta->date); + + // Is it reply? + $reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") or + (substr(strtolower($datarray['title']), 0, 3) == "re-") or + (raw_refs != "")); + + $r = email_get_msg($mbox,$msg_uid, $reply); + if(! $r) { + logger("Mail: can't fetch msg ".$msg_uid); + continue; + } + $datarray['body'] = escape_tags($r['body']); + + logger("Mail: Importing ".$msg_uid); + + // some mailing lists have the original author as 'from' - add this sender info to msg body. + // todo: adding a gravatar for the original author would be cool + + if(! stristr($meta->from,$contact['addr'])) { + $from = imap_mime_header_decode($meta->from); + $fromdecoded = ""; + foreach($from as $frompart) + if ($frompart->charset != "default") + $fromdecoded .= iconv($frompart->charset, 'UTF-8//IGNORE', $frompart->text); + else + $fromdecoded .= $frompart->text; + + $datarray['body'] = "[b]".t('From: ') . escape_tags($fromdecoded) . "[/b]\n\n" . $datarray['body']; + } + + $datarray['uid'] = $importer_uid; + $datarray['contact-id'] = $contact['id']; + if($datarray['parent-uri'] === $datarray['uri']) + $datarray['private'] = 1; + if(($contact['network'] === NETWORK_MAIL) && (! get_pconfig($importer_uid,'system','allow_public_email_replies'))) { + $datarray['private'] = 1; + $datarray['allow_cid'] = '<' . $contact['id'] . '>'; + } + $datarray['author-name'] = $contact['name']; + $datarray['author-link'] = 'mailbox'; + $datarray['author-avatar'] = $contact['photo']; + + $stored_item = item_store($datarray); + q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d", + dbesc($datarray['parent-uri']), + intval($importer_uid) + ); + q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1", + intval($stored_item) + ); + switch ($mailconf[0]['action']) { + case 0: + break; + case 1: + logger("Mail: Deleting ".$msg_uid); + imap_delete($mbox, $msg_uid, FT_UID); + break; + case 2: + logger("Mail: Mark as seen ".$msg_uid); + imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); + break; + case 3: + logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']); + imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); + if ($mailconf[0]['movetofolder'] != "") + imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID); + break; + } + } + } + imap_close($mbox); + } + } + elseif($contact['network'] === NETWORK_FACEBOOK) { + // This is picked up by the Facebook plugin on a cron hook. + // Ignored here. + } + + if($xml) { + logger('poller: received xml : ' . $xml, LOGGER_DATA); + if(! strstr($xml,' UTC_TIMESTAMP() - INTERVAL 1 DAY", + intval($contact['id']) + ); + } + if(count($r)) { + if(! $r[0]['total']) { + poco_load($contact['id'],$importer_uid,$contact['poco']); + } + } + + return; +} + +if (array_search(__file__,get_included_files())===0){ + onepoll_run($argv,$argc); + killme(); +} diff --git a/include/poller.php b/include/poller.php index 499483d00..0a0e66b86 100644 --- a/include/poller.php +++ b/include/poller.php @@ -113,6 +113,8 @@ function poller_run($argv, $argc){ $force = true; } + $interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval'))); + $sql_extra = (($manual_id) ? " AND `id` = $manual_id " : ""); reload_plugins(); @@ -136,6 +138,7 @@ function poller_run($argv, $argc){ AND NOT `network` IN ( '%s', '%s' ) $sql_extra AND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0 + AND `contact`.`archive` = 0 AND `user`.`account_expired` = 0 $abandon_sql ORDER BY RAND()", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND), @@ -224,440 +227,12 @@ function poller_run($argv, $argc){ continue; } - // Check to see if we are running out of memory - if so spawn a new process and kill this one - - $avail_memory = return_bytes(ini_get('memory_limit')); - $memused = memory_get_peak_usage(true); - if(intval($avail_memory)) { - if(($memused / $avail_memory) > 0.95) { - if($generation + 1 > 10) { - logger('poller: maximum number of spawns exceeded. Terminating.'); - killme(); - } - logger('poller: memory exceeded. ' . $memused . ' bytes used. Spawning new poll.'); - proc_run('php', 'include/poller.php', 'restart', (string) $generation + 1); - killme(); - } - } - - $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", - intval($importer_uid) - ); - if(! count($r)) - continue; - - $importer = $r[0]; - - logger("poller: poll: ({$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}"); - - $last_update = (($contact['last-update'] === '0000-00-00 00:00:00') - ? datetime_convert('UTC','UTC','now - 30 days', ATOM_TIME) - : datetime_convert('UTC','UTC',$contact['last-update'], ATOM_TIME) - ); - - if($contact['network'] === NETWORK_DFRN) { - - $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']); - - if(intval($contact['duplex']) && $contact['dfrn-id']) - $idtosend = '0:' . $orig_id; - if(intval($contact['duplex']) && $contact['issued-id']) - $idtosend = '1:' . $orig_id; - - // they have permission to write to us. We already filtered this in the contact query. - $perm = 'rw'; - - $url = $contact['poll'] . '?dfrn_id=' . $idtosend - . '&dfrn_version=' . DFRN_PROTOCOL_VERSION - . '&type=data&last_update=' . $last_update - . '&perm=' . $perm ; - - $handshake_xml = fetch_url($url); - - logger('poller: handshake with url ' . $url . ' returns xml: ' . $handshake_xml, LOGGER_DATA); - - - if(! $handshake_xml) { - logger("poller: $url appears to be dead - marking for death "); - // dead connection - might be a transient event, or this might - // mean the software was uninstalled or the domain expired. - // Will keep trying for one month. - mark_for_death($contact); - - // set the last-update so we don't keep polling - - $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1", - dbesc(datetime_convert()), - intval($contact['id']) - ); - - continue; - } - - if(! strstr($handshake_xml,'status) == 1) { - logger("poller: $url replied status 1 - marking for death "); - - // we may not be friends anymore. Will keep trying for one month. - // set the last-update so we don't keep polling - - $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1", - dbesc(datetime_convert()), - intval($contact['id']) - ); - - mark_for_death($contact); - } - else { - if($contact['term-date'] != '0000-00-00 00:00:00') { - logger("poller: $url back from the dead - removing mark for death"); - unmark_for_death($contact); - } - } - - if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) - continue; - - if(((float) $res->dfrn_version > 2.21) && ($contact['poco'] == '')) { - q("update contact set poco = '%s' where id = %d limit 1", - dbesc(str_replace('/profile/','/poco/', $contact['url'])), - intval($contact['id']) - ); - } - - $postvars = array(); - - $sent_dfrn_id = hex2bin((string) $res->dfrn_id); - $challenge = hex2bin((string) $res->challenge); - - $final_dfrn_id = ''; - - if(($contact['duplex']) && strlen($contact['prvkey'])) { - openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']); - openssl_private_decrypt($challenge,$postvars['challenge'],$contact['prvkey']); - } - else { - openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']); - openssl_public_decrypt($challenge,$postvars['challenge'],$contact['pubkey']); - } - - $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.')); - - if(strpos($final_dfrn_id,':') == 1) - $final_dfrn_id = substr($final_dfrn_id,2); - - if($final_dfrn_id != $orig_id) { - logger('poller: ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id); - // did not decode properly - cannot trust this site - continue; - } - - $postvars['dfrn_id'] = $idtosend; - $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; - $postvars['perm'] = 'rw'; - - $xml = post_url($contact['poll'],$postvars); - } - elseif(($contact['network'] === NETWORK_OSTATUS) - || ($contact['network'] === NETWORK_DIASPORA) - || ($contact['network'] === NETWORK_FEED) ) { - - // Upgrading DB fields from an older Friendica version - // Will only do this once per notify-enabled OStatus contact - // or if relationship changes - - $stat_writeable = ((($contact['notify']) && ($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['rel'] == CONTACT_IS_FRIEND)) ? 1 : 0); - - if($stat_writeable != $contact['writable']) { - q("UPDATE `contact` SET `writable` = %d WHERE `id` = %d LIMIT 1", - intval($stat_writeable), - intval($contact['id']) - ); - } - - // Are we allowed to import from this person? - - if($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['blocked'] || $contact['readonly']) - continue; - - $xml = fetch_url($contact['poll']); - } - elseif($contact['network'] === NETWORK_MAIL || $contact['network'] === NETWORK_MAIL2) { - - logger("Mail: Fetching"); - - $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); - if($mail_disabled) - continue; - - logger("Mail: Enabled"); - - $mbox = null; - $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", - intval($importer_uid) - ); - $mailconf = q("SELECT * FROM `mailacct` WHERE `server` != '' AND `uid` = %d LIMIT 1", - intval($importer_uid) - ); - if(count($x) && count($mailconf)) { - $mailbox = construct_mailbox_name($mailconf[0]); - $password = ''; - openssl_private_decrypt(hex2bin($mailconf[0]['pass']),$password,$x[0]['prvkey']); - $mbox = email_connect($mailbox,$mailconf[0]['user'],$password); - unset($password); - logger("Mail: Connect"); - if($mbox) { - q("UPDATE `mailacct` SET `last_check` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1", - dbesc(datetime_convert()), - intval($mailconf[0]['id']), - intval($importer_uid) - ); - } - } - if($mbox) { - logger("Mail: mbox"); - - $msgs = email_poll($mbox,$contact['addr']); - - if(count($msgs)) { - logger("Mail: Parsing ".count($msgs)." mails."); - - foreach($msgs as $msg_uid) { - logger("Mail: Parsing mail ".$msg_uid); - - $datarray = array(); - $meta = email_msg_meta($mbox,$msg_uid); - $headers = email_msg_headers($mbox,$msg_uid); - - // look for a 'references' header and try and match with a parent item we have locally. - - $raw_refs = ((x($headers,'references')) ? str_replace("\t",'',$headers['references']) : ''); - $datarray['uri'] = msgid2iri(trim($meta->message_id,'<>')); - - if($raw_refs) { - $refs_arr = explode(' ', $raw_refs); - if(count($refs_arr)) { - for($x = 0; $x < count($refs_arr); $x ++) - $refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'"; - } - $qstr = implode(',',$refs_arr); - $r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `uri` IN ( $qstr ) AND `uid` = %d LIMIT 1", - intval($importer_uid) - ); - if(count($r)) - $datarray['parent-uri'] = $r[0]['uri']; - } - - - if(! x($datarray,'parent-uri')) - $datarray['parent-uri'] = $datarray['uri']; - - // Have we seen it before? - $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", - intval($importer_uid), - dbesc($datarray['uri']) - ); - - if(count($r)) { - logger("Mail: Seen before ".$msg_uid); - if($meta->deleted && ! $r[0]['deleted']) { - q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1", - dbesc(datetime_convert()), - intval($r[0]['id']) - ); - } - switch ($mailconf[0]['action']) { - case 0: - break; - case 1: - logger("Mail: Deleting ".$msg_uid); - imap_delete($mbox, $msg_uid, FT_UID); - break; - case 2: - logger("Mail: Mark as seen ".$msg_uid); - imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); - break; - case 3: - logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']); - imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); - if ($mailconf[0]['movetofolder'] != "") - imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID); - break; - } - continue; - } - - // Decoding the header - $subject = imap_mime_header_decode($meta->subject); - $datarray['title'] = ""; - foreach($subject as $subpart) - if ($subpart->charset != "default") - $datarray['title'] .= iconv($subpart->charset, 'UTF-8//IGNORE', $subpart->text); - else - $datarray['title'] .= $subpart->text; - - $datarray['title'] = notags(trim($datarray['title'])); - - //$datarray['title'] = notags(trim($meta->subject)); - $datarray['created'] = datetime_convert('UTC','UTC',$meta->date); - - // Is it reply? - $reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") or - (substr(strtolower($datarray['title']), 0, 3) == "re-") or - (raw_refs != "")); - - $r = email_get_msg($mbox,$msg_uid, $reply); - if(! $r) { - logger("Mail: can't fetch msg ".$msg_uid); - continue; - } - $datarray['body'] = escape_tags($r['body']); - - logger("Mail: Importing ".$msg_uid); - - // some mailing lists have the original author as 'from' - add this sender info to msg body. - // todo: adding a gravatar for the original author would be cool - - if(! stristr($meta->from,$contact['addr'])) { - $from = imap_mime_header_decode($meta->from); - $fromdecoded = ""; - foreach($from as $frompart) - if ($frompart->charset != "default") - $fromdecoded .= iconv($frompart->charset, 'UTF-8//IGNORE', $frompart->text); - else - $fromdecoded .= $frompart->text; - - $datarray['body'] = "[b]".t('From: ') . escape_tags($fromdecoded) . "[/b]\n\n" . $datarray['body']; - } - - $datarray['uid'] = $importer_uid; - $datarray['contact-id'] = $contact['id']; - if($datarray['parent-uri'] === $datarray['uri']) - $datarray['private'] = 1; - if(($contact['network'] === NETWORK_MAIL) && (! get_pconfig($importer_uid,'system','allow_public_email_replies'))) { - $datarray['private'] = 1; - $datarray['allow_cid'] = '<' . $contact['id'] . '>'; - } - $datarray['author-name'] = $contact['name']; - $datarray['author-link'] = 'mailbox'; - $datarray['author-avatar'] = $contact['photo']; - - $stored_item = item_store($datarray); - q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d", - dbesc($datarray['parent-uri']), - intval($importer_uid) - ); - q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1", - intval($stored_item) - ); - switch ($mailconf[0]['action']) { - case 0: - break; - case 1: - logger("Mail: Deleting ".$msg_uid); - imap_delete($mbox, $msg_uid, FT_UID); - break; - case 2: - logger("Mail: Mark as seen ".$msg_uid); - imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); - break; - case 3: - logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']); - imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); - if ($mailconf[0]['movetofolder'] != "") - imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID); - break; - } - } - } - - imap_close($mbox); - } - } - elseif($contact['network'] === NETWORK_FACEBOOK) { - // This is picked up by the Facebook plugin on a cron hook. - // Ignored here. - } - - if($xml) { - logger('poller: received xml : ' . $xml, LOGGER_DATA); - - if(! strstr($xml,' UTC_TIMESTAMP() - INTERVAL 1 DAY", - intval($contact['id']) - ); - } - if(count($r)) { - if(! $r[0]['total']) { - poco_load($contact['id'],$importer_uid,$contact['poco']); - } - } - - // loop - next contact + proc_run('php','include/onepoll.php',$contact['id']); + if($interval) + @time_sleep_until(microtime(true) + (float) $interval); } } - return; } -- cgit v1.2.3 From 44700b914da591ff3535358db34d035014611264 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 28 Apr 2012 04:20:38 -0700 Subject: poller refactor: continue not valid in this context --- include/onepoll.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/onepoll.php b/include/onepoll.php index 4ae34664f..722ebe846 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -107,7 +107,7 @@ function onepoll_run($argv, $argc){ intval($importer_uid) ); if(! count($r)) - continue; + return; $importer = $r[0]; -- cgit v1.2.3 From 4ff2e9a10358e68f7af90ebf6d50d75d3a6ed284 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 28 Apr 2012 16:54:33 -0700 Subject: a few more continues that should be returns --- include/onepoll.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/onepoll.php b/include/onepoll.php index 722ebe846..51516d059 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -152,7 +152,7 @@ function onepoll_run($argv, $argc){ intval($contact['id']) ); - continue; + return; } if(! strstr($handshake_xml,'status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) - continue; + return; if(((float) $res->dfrn_version > 2.21) && ($contact['poco'] == '')) { q("update contact set poco = '%s' where id = %d limit 1", @@ -221,7 +221,7 @@ function onepoll_run($argv, $argc){ if($final_dfrn_id != $orig_id) { logger('poller: ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id); // did not decode properly - cannot trust this site - continue; + return; } $postvars['dfrn_id'] = $idtosend; @@ -251,7 +251,7 @@ function onepoll_run($argv, $argc){ // Are we allowed to import from this person? if($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['blocked'] || $contact['readonly']) - continue; + return; $xml = fetch_url($contact['poll']); } @@ -261,7 +261,7 @@ function onepoll_run($argv, $argc){ $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); if($mail_disabled) - continue; + return; logger("onepoll: Mail: Enabled", LOGGER_DEBUG); @@ -458,7 +458,7 @@ function onepoll_run($argv, $argc){ dbesc(datetime_convert()), intval($contact['id']) ); - continue; + return; } -- cgit v1.2.3 From 64060f82dc68d490f3d729f3fbe139527c831fd0 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 28 Apr 2012 21:56:17 -0700 Subject: toggle to archive unfriends, though render them useless --- include/Contact.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include') diff --git a/include/Contact.php b/include/Contact.php index 537850e00..2523fc023 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -51,6 +51,21 @@ function user_remove($uid) { function contact_remove($id) { + + $r = q("select uid from contact where id = %d limit 1", + intval($id) + ); + if((! count($r)) || (! intval($r[0]['uid']))) + return; + + $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", + intval($id) + ); + return; + } + q("DELETE FROM `contact` WHERE `id` = %d LIMIT 1", intval($id) ); -- cgit v1.2.3 From e3fecb2557ad0ac2f156f9583683f7c9d998e212 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 29 Apr 2012 17:34:54 -0700 Subject: improved db error logging --- include/dba.php | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/dba.php b/include/dba.php index 44a663eac..414f4ae7a 100644 --- a/include/dba.php +++ b/include/dba.php @@ -74,23 +74,29 @@ class dba { if((! $this->db) || (! $this->connected)) return false; + + $this->error = ''; if($this->mysqli) $result = @$this->db->query($sql); else $result = @mysql_query($sql,$this->db); + if($this->mysqli) { + if($this->db->errno) + $this->error = $this->db->error; + } + elseif(mysql_errno($this->db)) + $this->error = mysql_error($this->db); + + if(strlen($this->error)) { + logger('dba: ' . $this->error); + } + if($this->debug) { $mesg = ''; - if($this->mysqli) { - if($this->db->errno) - logger('dba: ' . $this->db->error); - } - elseif(mysql_errno($this->db)) - logger('dba: ' . mysql_error($this->db)); - if($result === false) $mesg = 'false'; elseif($result === true) @@ -102,7 +108,9 @@ class dba { $mesg = mysql_num_rows($result) . ' results' . EOL; } - $str = 'SQL = ' . printable($sql) . EOL . 'SQL returned ' . $mesg . EOL; + $str = 'SQL = ' . printable($sql) . EOL . 'SQL returned ' . $mesg + . (($this->error) ? ' error: ' . $this->error : '') + . EOL; logger('dba: ' . $str ); } @@ -116,7 +124,7 @@ class dba { if($result === false) { logger('dba: ' . printable($sql) . ' returned false.'); if(file_exists('dbfail.out')) - file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n", FILE_APPEND); + file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND); } if(($result === true) || ($result === false)) -- cgit v1.2.3 From 1ebde084154f6272664e0b8c7309aab5b9c91cf2 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 29 Apr 2012 19:41:17 -0700 Subject: log db error strings in all cases --- include/dba.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/dba.php b/include/dba.php index 414f4ae7a..c9f880241 100644 --- a/include/dba.php +++ b/include/dba.php @@ -74,9 +74,9 @@ class dba { if((! $this->db) || (! $this->connected)) return false; - - $this->error = ''; + $this->error = ''; + if($this->mysqli) $result = @$this->db->query($sql); else @@ -122,7 +122,7 @@ class dba { */ if($result === false) { - logger('dba: ' . printable($sql) . ' returned false.'); + logger('dba: ' . printable($sql) . ' returned false.' . "\n" . $this->error); if(file_exists('dbfail.out')) file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND); } -- cgit v1.2.3 From ae2aa744449f0e7161c5fae81773ae5defd3ad76 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 29 Apr 2012 20:05:29 -0700 Subject: not all profile selector choices have unique or direct translations --- include/profile_selectors.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/profile_selectors.php b/include/profile_selectors.php index a2cef959d..d2f677e32 100644 --- a/include/profile_selectors.php +++ b/include/profile_selectors.php @@ -7,8 +7,10 @@ function gender_selector($current="",$suffix="") { $o .= "'; return $o; @@ -20,8 +22,10 @@ function sexpref_selector($current="",$suffix="") { $o .= "'; return $o; @@ -34,8 +38,10 @@ function marital_selector($current="",$suffix="") { $o .= "'; return $o; -- cgit v1.2.3 From 928faf3b9712e88e030b2ccbbc630e3991e03d03 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 29 Apr 2012 22:34:05 -0700 Subject: typo in profile_selectors, fix remote tagging --- include/items.php | 44 +++++++++++++++++++++++++++++-------------- include/profile_selectors.php | 6 +++--- 2 files changed, 33 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 07f62ece5..7d61c9f1d 100644 --- a/include/items.php +++ b/include/items.php @@ -2227,10 +2227,10 @@ function local_delivery($importer,$data) { logger('local_delivery: received remote comment'); $is_like = false; // remote reply to our post. Import and then notify everybody else. - $datarray = get_atom_elements($feed,$item); + $datarray = get_atom_elements($feed,$item); - $r = q("SELECT `id`, `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", + $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($item_id), intval($importer['importer_uid']) ); @@ -2266,14 +2266,22 @@ function local_delivery($importer,$data) { // return 0; // } + // our user with $importer['importer_uid'] is the owner + + $own = q("select name,url,thumb from contact where uid = %d and self = 1 limit 1", + intval($importer['importer_uid']) + ); + + $datarray['type'] = 'remote-comment'; $datarray['wall'] = 1; $datarray['parent-uri'] = $parent_uri; $datarray['uid'] = $importer['importer_uid']; - $datarray['owner-name'] = $r[0]['name']; - $datarray['owner-link'] = $r[0]['url']; - $datarray['owner-avatar'] = $r[0]['thumb']; + $datarray['owner-name'] = $own[0]['name']; + $datarray['owner-link'] = $own[0]['url']; + $datarray['owner-avatar'] = $own[0]['thumb']; $datarray['contact-id'] = $importer['id']; + if(($datarray['verb'] === ACTIVITY_LIKE) || ($datarray['verb'] === ACTIVITY_DISLIKE)) { $is_like = true; $datarray['type'] = 'activity'; @@ -2290,26 +2298,34 @@ function local_delivery($importer,$data) { } if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['object-type'] === ACTIVITY_OBJ_TAGTERM)) { - - + $xo = parse_xml_string($datarray['object'],false); $xt = parse_xml_string($datarray['target'],false); - if(($xt->type == ACTIVITY_OBJ_NOTE) && ($xt->id == $r[0]['uri'])) { + if(($xt->type == ACTIVITY_OBJ_NOTE) && ($xt->id)) { + + // fetch the parent item + + $tagp = q("select * from item where uri = '%s' and uid = %d limit 1", + dbesc($xt->id), + intval($importer['importer_uid']) + ); + if(! count($tagp)) + continue; // extract tag, if not duplicate, and this user allows tags, add to parent item if($xo->id && $xo->content) { $newtag = '#[url=' . $xo->id . ']'. $xo->content . '[/url]'; - - if(! (stristr($r[0]['tag'],$newtag))) { + if(! (stristr($tagp[0]['tag'],$newtag))) { $i = q("SELECT `blocktags` FROM `user` where `uid` = %d LIMIT 1", intval($importer['importer_uid']) ); - if(count($i) && ! ($i[0]['blocktags'])) { - q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1", - dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . $newtag), - intval($r[0]['id']) + if(count($i) && ! intval($i[0]['blocktags'])) { + q("UPDATE item SET tag = '%s', `edited` = '%s' WHERE id = %d LIMIT 1", + dbesc($tagp[0]['tag'] . (strlen($tagp[0]['tag']) ? ',' : '') . $newtag), + intval($tagp[0]['id']), + dbesc(datetime_convert()) ); } } diff --git a/include/profile_selectors.php b/include/profile_selectors.php index d2f677e32..4700bb96f 100644 --- a/include/profile_selectors.php +++ b/include/profile_selectors.php @@ -7,7 +7,7 @@ function gender_selector($current="",$suffix="") { $o .= ""; foreach($select as $selection) { - if($selection !== 'NOTRANSLATION')) { + if($selection !== 'NOTRANSLATION') { $selected = (($selection == $current) ? ' selected="selected" ' : ''); $o .= ""; } @@ -38,7 +38,7 @@ function marital_selector($current="",$suffix="") { $o .= "