From 8b049a96bd3733126f77ac83507306243bc7663d Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 6 Feb 2018 14:24:24 +0000 Subject: [PATCH 1/5] Direct calls to the database are replace by class calls to the item class --- pumpio/pumpio.php | 32 ++++++++------------------------ statusnet/statusnet.php | 6 +----- twitter/twitter.php | 11 ++--------- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 1e416f47..82d54a94 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -543,10 +543,7 @@ function pumpio_send(&$a,&$b) { logger('pumpio_send '.$username.': success '.$post_id); if($post_id && $iscomment) { logger('pumpio_send '.$username.': Update extid '.$post_id." for post id ".$b['id']); - q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d", - dbesc($post_id), - intval($b['id']) - ); + Item::update(['extid' => $post_id], ['id' => $b['id']]); } } else { logger('pumpio_send '.$username.': '.$url.' general error: ' . print_r($user,true)); @@ -870,13 +867,7 @@ function pumpio_dounlike(&$a, $uid, $self, $post, $own_id) { $contactid = $orig_post['contact-id']; } - $r = q("UPDATE `item` SET `deleted` = 1, `unseen` = 1, `changed` = '%s' WHERE `verb` = '%s' AND `uid` = %d AND `contact-id` = %d AND `thr-parent` = '%s'", - dbesc(DateTimeFormat::utcNow()), - dbesc(ACTIVITY_LIKE), - intval($uid), - intval($contactid), - dbesc($orig_post['uri']) - ); + Item::delete(["`verb` = ? AND `uid` = ? AND `contact-id` = ? AND `thr-parent` = ?", ACTIVITY_LIKE, $uid, $contactid, $orig_post['uri']]); if(count($r)) logger("pumpio_dounlike: unliked existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); @@ -1060,7 +1051,7 @@ function pumpio_dodelete(&$a, $uid, $self, $post, $own_id) { ); if (count($r)) - return Item::delete($r[0]["id"]); + return Item::deleteById($r[0]["id"]); $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1", dbesc($post->object->id), @@ -1068,7 +1059,7 @@ function pumpio_dodelete(&$a, $uid, $self, $post, $own_id) { ); if (count($r)) - return Item::delete($r[0]["id"]); + return Item::deleteById($r[0]["id"]); } function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcompletion = true) { @@ -1256,13 +1247,9 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet $postarray["id"] = $top_item; if (($top_item == 0) && ($post->verb == "update")) { - $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s' , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d", - dbesc($postarray["title"]), - dbesc($postarray["body"]), - dbesc($postarray["edited"]), - dbesc($postarray["uri"]), - intval($uid) - ); + $fields = ['title' => $postarray["title"], 'body' => $postarray["body"], 'changed' => $postarray["edited"]]; + $condition = ['uri' => $postarray["uri"], 'uid' => $uid]; + Item::update($fields, $condition); } if ($post->object->objectType == "comment") { @@ -1491,10 +1478,7 @@ function pumpio_queue_hook(&$a,&$b) { logger('pumpio_queue: send '.$username.': success '.$post_id); if($post_id && $iscomment) { logger('pumpio_send '.$username.': Update extid '.$post_id." for post id ".$z['item']); - q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d", - dbesc($post_id), - intval($z['item']) - ); + Item::update(['extid' => $post_id], ['id' => $z['item']]); } Queue::removeItem($x['id']); } else diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 22e8f5f9..f1c080f4 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -600,11 +600,7 @@ function statusnet_post_hook(App $a, &$b) logger('Send to GNU Social failed: "' . $result->error . '"'); } elseif ($iscomment) { logger('statusnet_post: Update extid ' . $result->id . " for post id " . $b['id']); - q("UPDATE `item` SET `extid` = '%s', `body` = '%s' WHERE `id` = %d", - dbesc($hostname . "::" . $result->id), - dbesc($result->text), - intval($b['id']) - ); + Item::update(['extid' => $hostname . "::" . $result->id, 'body' => $result->text], ['id' => $b['id']]); } } if ($tempfile != "") { diff --git a/twitter/twitter.php b/twitter/twitter.php index bf85f081..47b4fa07 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -571,11 +571,7 @@ function twitter_post_hook(App $a, &$b) $image = ""; } elseif ($iscomment) { logger('twitter_post: Update extid ' . $result->id_str . " for post id " . $b['id']); - q("UPDATE `item` SET `extid` = '%s', `body` = '%s' WHERE `id` = %d", - dbesc("twitter::" . $result->id_str), - dbesc($result->text), - intval($b['id']) - ); + Item::update(['extid' => "twitter::" . $result->id_str, 'body' => $result->text], ['id' => $b['id']]); } } @@ -621,10 +617,7 @@ function twitter_post_hook(App $a, &$b) notice(L10n::t('Twitter post failed. Queued for retry.') . EOL); } elseif ($iscomment) { logger('twitter_post: Update extid ' . $result->id_str . " for post id " . $b['id']); - q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d", - dbesc("twitter::" . $result->id_str), - intval($b['id']) - ); + Item::update(['extid' => "twitter::" . $result->id_str], ['id' => $b['id']]); } } } -- 2.45.3 From d29890613ebafb39dfd175c041f48da8416adc4f Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 6 Feb 2018 16:24:35 +0000 Subject: [PATCH 2/5] Simpler form --- pumpio/pumpio.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 82d54a94..8e194f85 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -867,7 +867,7 @@ function pumpio_dounlike(&$a, $uid, $self, $post, $own_id) { $contactid = $orig_post['contact-id']; } - Item::delete(["`verb` = ? AND `uid` = ? AND `contact-id` = ? AND `thr-parent` = ?", ACTIVITY_LIKE, $uid, $contactid, $orig_post['uri']]); + Item::delete(['verb' => ACTIVITY_LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]); if(count($r)) logger("pumpio_dounlike: unliked existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); -- 2.45.3 From 22ac032cc3ca8580dd974ac0c55ea2378b0680c1 Mon Sep 17 00:00:00 2001 From: rabuzarus Date: Tue, 6 Feb 2018 18:24:03 +0100 Subject: [PATCH 3/5] membersince addon works now with frio --- membersince/membersince.php | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/membersince/membersince.php b/membersince/membersince.php index 63482579..de7519c9 100644 --- a/membersince/membersince.php +++ b/membersince/membersince.php @@ -23,9 +23,37 @@ function membersince_uninstall() function membersince_display(&$a, &$b) { - // Works in Vier - $b = preg_replace('/<\/dl>/', "\n\n\n
\n
" . L10n::t('Member since:') . "
\n
" . DateTimeFormat::local($a->profile['register_date']) . "
\n
", $b, 1); + if (current_theme() == 'frio') { + // Works in Frio. + $doc = new DOMDocument(); + $doc->loadHTML($b); - // Trying for Frio - //$b = preg_replace('/<\/div>/', "

" . L10n::t('Member since:') . "
" . DateTimeFormat::local($a->profile['register_date']) . "
", $b, 1); + $elm = $doc->getElementById('aprofile-fullname'); + + $div = $doc->createElement('div'); + $div->setAttribute('id','aprofile-membersince'); + $div->setAttribute('class','col-lg-12 col-md-12 col-sm-12 col-xs-12 aprofile'); + + // The seperator line. + $hr = $doc->createElement('hr',''); + $hr->setAttribute('class','profile-separator'); + + // The label div. + $label = $doc->createElement('div', L10n::t('Member since:')); + $label->setAttribute('class', 'col-lg-4 col-md-4 col-sm-4 col-xs-12 profile-label-name text-muted'); + + // The div for the register date of the profile owner. + $entry = $doc->createElement('div', DateTimeFormat::local($a->profile['register_date'])); + $entry->setAttribute('class', 'col-lg-8 col-md-8 col-sm-8 col-xs-12 profile-entry'); + + $div->appendChild($hr); + $div->appendChild($label); + $div->appendChild($entry); + $elm->parentNode->appendChild($div); + + $b = $doc->saveHTML(); + } else { + // Works in Vier. + $b = preg_replace('/<\/dl>/', "\n\n\n
\n
" . L10n::t('Member since:') . "
\n
" . DateTimeFormat::local($a->profile['register_date']) . "
\n
", $b, 1); + } } -- 2.45.3 From 40f99e48287c6cb44e3f1d3df3e8dabfb9d9c259 Mon Sep 17 00:00:00 2001 From: rabuzarus Date: Tue, 6 Feb 2018 18:26:34 +0100 Subject: [PATCH 4/5] update membersince addon to version 1.1 since it does now support frio --- membersince/membersince.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/membersince/membersince.php b/membersince/membersince.php index de7519c9..67d29e1d 100644 --- a/membersince/membersince.php +++ b/membersince/membersince.php @@ -2,7 +2,7 @@ /** * Name: MemberSince * Description: Display membership date in profile - * Version: 1.0 + * Version: 1.1 * Author: Mike Macgirvin * */ -- 2.45.3 From 9faa56702aeaa5cba1ec512a9868d75545e8a34f Mon Sep 17 00:00:00 2001 From: rabuzarus Date: Wed, 7 Feb 2018 14:34:30 +0100 Subject: [PATCH 5/5] membersince is now added in frio after the fullname entry --- membersince/membersince.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/membersince/membersince.php b/membersince/membersince.php index 67d29e1d..8c42c135 100644 --- a/membersince/membersince.php +++ b/membersince/membersince.php @@ -49,7 +49,7 @@ function membersince_display(&$a, &$b) $div->appendChild($hr); $div->appendChild($label); $div->appendChild($entry); - $elm->parentNode->appendChild($div); + $elm->parentNode->insertBefore($div, $elm->nextSibling); $b = $doc->saveHTML(); } else { -- 2.45.3