From 2d2167c1468dacf5ada314a5cb68b737c19faaab Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 20 Jul 2018 22:16:16 -0400 Subject: [PATCH 01/10] [advancedcontentfilter] Rename DBA::inArray to DBA::toArray --- advancedcontentfilter/advancedcontentfilter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advancedcontentfilter/advancedcontentfilter.php b/advancedcontentfilter/advancedcontentfilter.php index 42a5ba30..37463d5d 100644 --- a/advancedcontentfilter/advancedcontentfilter.php +++ b/advancedcontentfilter/advancedcontentfilter.php @@ -119,7 +119,7 @@ function advancedcontentfilter_prepare_body_content_filter(App $a, &$hook_data) $rules = Cache::get('rules_' . local_user()); if (!isset($rules)) { - $rules = DBA::inArray(DBA::select( + $rules = DBA::toArray(DBA::select( 'advancedcontentfilter_rules', ['name', 'expression', 'serialized'], ['uid' => local_user(), 'active' => true] @@ -300,7 +300,7 @@ function advancedcontentfilter_get_rules() throw new HTTPException\UnauthorizedException(L10n::t('You must be logged in to use this method')); } - $rules = DBA::inArray(DBA::select('advancedcontentfilter_rules', [], ['uid' => local_user()])); + $rules = DBA::toArray(DBA::select('advancedcontentfilter_rules', [], ['uid' => local_user()])); return json_encode($rules); } From a9da9db7eb939f248ae7cb451c482534d9dd7943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Sun, 22 Jul 2018 18:01:05 +0200 Subject: [PATCH 02/10] [pumpio] Fixes/imports: (#661) * [pumpio] Fixes/imports: - added curly braces and spaces for better readability - merged 2 `if()` blocks into one for lesser nested code blocks - added type-hint `App` and `array` where applyable - better "import" (`use` under PHP) classes and not reference them directly, reducing and improving readability * [pumpio] Fixes: - x() is deprecated, let's use !empty() instead - added spaces for better readability * [pumpio] Fixes: - added missing App "imports" (thanks to MrPetovan) - added type-hint array for $b - added some spaces --- pumpio/pumpio.php | 138 +++++++++++++++++++++++----------------------- 1 file changed, 70 insertions(+), 68 deletions(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 191f8505..b3442ed7 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -6,6 +6,7 @@ * Author: Michael Vogel */ +use Friendica\App; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; use Friendica\Core\Addon; @@ -59,7 +60,7 @@ function pumpio_uninstall() function pumpio_module() {} -function pumpio_content(&$a) +function pumpio_content(App $a) { if (!local_user()) { notice(L10n::t('Permission denied.') . EOL); @@ -92,7 +93,7 @@ function pumpio_check_item_notification($a, &$notification_data) $notification_data["profiles"][] = "https://".$hostname."/".$username; } -function pumpio_registerclient(&$a, $host) +function pumpio_registerclient(App $a, $host) { $url = "https://".$host."/api/client/register"; @@ -135,7 +136,7 @@ function pumpio_registerclient(&$a, $host) } -function pumpio_connect(&$a) +function pumpio_connect(App $a) { // Start a session. This is necessary to hold on to a few keys the callback script will also need session_start(); @@ -211,13 +212,14 @@ function pumpio_connect(&$a) return $o; } -function pumpio_jot_nets(&$a, &$b) +function pumpio_jot_nets(App $a, &$b) { - if (!local_user()) { + if (! local_user()) { return; } $pumpio_post = PConfig::get(local_user(), 'pumpio', 'post'); + if (intval($pumpio_post) == 1) { $pumpio_defpost = PConfig::get(local_user(), 'pumpio', 'post_by_default'); $selected = ((intval($pumpio_defpost) == 1) ? ' checked="checked" ' : ''); @@ -226,7 +228,7 @@ function pumpio_jot_nets(&$a, &$b) } } -function pumpio_settings(&$a, &$s) +function pumpio_settings(App $a, &$s) { if (!local_user()) { return; @@ -326,28 +328,29 @@ function pumpio_settings(&$a, &$s) $s .= '
'; } -function pumpio_settings_post(&$a, &$b) +function pumpio_settings_post(App $a, array &$b) { - if (x($_POST, 'pumpio-submit')) { - if (x($_POST, 'pumpio_delete')) { - PConfig::set(local_user(), 'pumpio', 'consumer_key', ''); - PConfig::set(local_user(), 'pumpio', 'consumer_secret', ''); - PConfig::set(local_user(), 'pumpio', 'oauth_token', ''); + if (!empty($_POST['pumpio-submit'])) { + if (!empty($_POST['pumpio_delete'])) { + PConfig::set(local_user(), 'pumpio', 'consumer_key' , ''); + PConfig::set(local_user(), 'pumpio', 'consumer_secret' , ''); + PConfig::set(local_user(), 'pumpio', 'oauth_token' , ''); PConfig::set(local_user(), 'pumpio', 'oauth_token_secret', ''); - PConfig::set(local_user(), 'pumpio', 'post', false); - PConfig::set(local_user(), 'pumpio', 'import', false); - PConfig::set(local_user(), 'pumpio', 'host', ''); - PConfig::set(local_user(), 'pumpio', 'user', ''); - PConfig::set(local_user(), 'pumpio', 'public', false); - PConfig::set(local_user(), 'pumpio', 'mirror', false); - PConfig::set(local_user(), 'pumpio', 'post_by_default', false); - PConfig::set(local_user(), 'pumpio', 'lastdate', 0); - PConfig::set(local_user(), 'pumpio', 'last_id', ''); + PConfig::set(local_user(), 'pumpio', 'post' , false); + PConfig::set(local_user(), 'pumpio', 'import' , false); + PConfig::set(local_user(), 'pumpio', 'host' , ''); + PConfig::set(local_user(), 'pumpio', 'user' , ''); + PConfig::set(local_user(), 'pumpio', 'public' , false); + PConfig::set(local_user(), 'pumpio', 'mirror' , false); + PConfig::set(local_user(), 'pumpio', 'post_by_default' , false); + PConfig::set(local_user(), 'pumpio', 'lastdate' , 0); + PConfig::set(local_user(), 'pumpio', 'last_id' , ''); } else { // filtering the username if it is filled wrong $user = $_POST['pumpio_user']; if (strstr($user, "@")) { $pos = strpos($user, "@"); + if ($pos > 0) { $user = substr($user, 0, $pos); } @@ -358,13 +361,13 @@ function pumpio_settings_post(&$a, &$b) $host = trim($host); $host = str_replace(["https://", "http://"], ["", ""], $host); - PConfig::set(local_user(), 'pumpio', 'post',intval($_POST['pumpio'])); - PConfig::set(local_user(), 'pumpio', 'import', $_POST['pumpio_import']); - PConfig::set(local_user(), 'pumpio', 'host', $host); - PConfig::set(local_user(), 'pumpio', 'user', $user); - PConfig::set(local_user(), 'pumpio', 'public', $_POST['pumpio_public']); - PConfig::set(local_user(), 'pumpio', 'mirror', $_POST['pumpio_mirror']); - PConfig::set(local_user(), 'pumpio', 'post_by_default',intval($_POST['pumpio_bydefault'])); + PConfig::set(local_user(), 'pumpio', 'post' , intval($_POST['pumpio'])); + PConfig::set(local_user(), 'pumpio', 'import' , $_POST['pumpio_import']); + PConfig::set(local_user(), 'pumpio', 'host' , $host); + PConfig::set(local_user(), 'pumpio', 'user' , $user); + PConfig::set(local_user(), 'pumpio', 'public' , $_POST['pumpio_public']); + PConfig::set(local_user(), 'pumpio', 'mirror' , $_POST['pumpio_mirror']); + PConfig::set(local_user(), 'pumpio', 'post_by_default', intval($_POST['pumpio_bydefault'])); if (!$_POST['pumpio_mirror']) { PConfig::delete(local_user(), 'pumpio', 'lastdate'); @@ -375,12 +378,12 @@ function pumpio_settings_post(&$a, &$b) } } -function pumpio_load_config(\Friendica\App $a) +function pumpio_load_config(App $a) { $a->loadConfigFile(__DIR__. '/config/pumpio.ini.php'); } -function pumpio_post_local(&$a, &$b) +function pumpio_post_local(App $a, array &$b) { if (!local_user() || (local_user() != $b['uid'])) { return; @@ -388,7 +391,7 @@ function pumpio_post_local(&$a, &$b) $pumpio_post = intval(PConfig::get(local_user(), 'pumpio', 'post')); - $pumpio_enable = (($pumpio_post && x($_REQUEST, 'pumpio_enable')) ? intval($_REQUEST['pumpio_enable']) : 0); + $pumpio_enable = (($pumpio_post && !empty($_REQUEST['pumpio_enable'])) ? intval($_REQUEST['pumpio_enable']) : 0); if ($b['api_source'] && intval(PConfig::get(local_user(), 'pumpio', 'post_by_default'))) { $pumpio_enable = 1; @@ -405,12 +408,10 @@ function pumpio_post_local(&$a, &$b) $b['postopts'] .= 'pumpio'; } -function pumpio_send(&$a, &$b) +function pumpio_send(App $a, array &$b) { - if (!PConfig::get($b["uid"], 'pumpio', 'import')) { - if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) { - return; - } + if (!PConfig::get($b["uid"], 'pumpio', 'import') && ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))) { + return; } logger("pumpio_send: parameter ".print_r($b, true), LOGGER_DATA); @@ -584,7 +585,7 @@ function pumpio_send(&$a, &$b) } } -function pumpio_action(&$a, $uid, $uri, $action, $content = "") +function pumpio_action(App $a, $uid, $uri, $action, $content = "") { // Don't do likes and other stuff if you don't import the timeline if (!PConfig::get($uid, 'pumpio', 'import')) { @@ -660,7 +661,7 @@ function pumpio_action(&$a, $uid, $uri, $action, $content = "") } } -function pumpio_sync(&$a) +function pumpio_sync(App $a) { $r = q("SELECT * FROM `addon` WHERE `installed` = 1 AND `name` = 'pumpio'"); @@ -730,12 +731,12 @@ function pumpio_sync(&$a) Config::set('pumpio', 'last_poll', time()); } -function pumpio_cron(&$a, $b) +function pumpio_cron(App $a, $b) { Worker::add(PRIORITY_MEDIUM,"addon/pumpio/pumpio_sync.php"); } -function pumpio_fetchtimeline(&$a, $uid) +function pumpio_fetchtimeline(App $a, $uid) { $ckey = PConfig::get($uid, 'pumpio', 'consumer_key'); $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret'); @@ -865,7 +866,7 @@ function pumpio_fetchtimeline(&$a, $uid) } } -function pumpio_dounlike(&$a, $uid, $self, $post, $own_id) +function pumpio_dounlike(App $a, $uid, $self, $post, $own_id) { // Searching for the unliked post // Two queries for speed issues @@ -905,7 +906,7 @@ function pumpio_dounlike(&$a, $uid, $self, $post, $own_id) } } -function pumpio_dolike(&$a, $uid, $self, $post, $own_id, $threadcompletion = true) +function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = true) { require_once('include/items.php'); @@ -1075,7 +1076,7 @@ function pumpio_get_contact($uid, $contact, $no_insert = false) return $contact_id; } -function pumpio_dodelete(&$a, $uid, $self, $post, $own_id) +function pumpio_dodelete(App $a, $uid, $self, $post, $own_id) { // Two queries for speed issues $condition = ['uri' => $post->object->id, 'uid' => $uid]; @@ -1092,7 +1093,7 @@ function pumpio_dodelete(&$a, $uid, $self, $post, $own_id) return false; } -function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcompletion = true) +function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcompletion = true) { require_once('include/items.php'); @@ -1285,12 +1286,12 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet return $top_item; } -function pumpio_fetchinbox(&$a, $uid) +function pumpio_fetchinbox(App $a, $uid) { - $ckey = PConfig::get($uid, 'pumpio', 'consumer_key'); - $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret'); - $otoken = PConfig::get($uid, 'pumpio', 'oauth_token'); - $osecret = PConfig::get($uid, 'pumpio', 'oauth_token_secret'); + $ckey = PConfig::get($uid, 'pumpio', 'consumer_key'); + $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret'); + $otoken = PConfig::get($uid, 'pumpio', 'oauth_token'); + $osecret = PConfig::get($uid, 'pumpio', 'oauth_token_secret'); $lastdate = PConfig::get($uid, 'pumpio', 'lastdate'); $hostname = PConfig::get($uid, 'pumpio', 'host'); $username = PConfig::get($uid, "pumpio", "user"); @@ -1347,19 +1348,19 @@ function pumpio_fetchinbox(&$a, $uid) } } - foreach ($lastitems AS $item) { + foreach ($lastitems as $item) { pumpio_fetchallcomments($a, $uid, $item["uri"]); } PConfig::set($uid, 'pumpio', 'last_id', $last_id); } -function pumpio_getallusers(&$a, $uid) +function pumpio_getallusers(App &$a, $uid) { - $ckey = PConfig::get($uid, 'pumpio', 'consumer_key'); - $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret'); - $otoken = PConfig::get($uid, 'pumpio', 'oauth_token'); - $osecret = PConfig::get($uid, 'pumpio', 'oauth_token_secret'); + $ckey = PConfig::get($uid, 'pumpio', 'consumer_key'); + $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret'); + $otoken = PConfig::get($uid, 'pumpio', 'oauth_token'); + $osecret = PConfig::get($uid, 'pumpio', 'oauth_token_secret'); $hostname = PConfig::get($uid, 'pumpio', 'host'); $username = PConfig::get($uid, "pumpio", "user"); @@ -1376,7 +1377,7 @@ function pumpio_getallusers(&$a, $uid) $url = 'https://'.$hostname.'/api/user/'.$username.'/following'; if (pumpio_reachable($url)) { - $success = $client->CallAPI($url, 'GET', [], ['FailOnAccessError'=>true], $users); + $success = $client->CallAPI($url, 'GET', [], ['FailOnAccessError' => true], $users); } else { $success = false; } @@ -1385,24 +1386,25 @@ function pumpio_getallusers(&$a, $uid) $url = 'https://'.$hostname.'/api/user/'.$username.'/following?count='.$users->totalItems; if (pumpio_reachable($url)) { - $success = $client->CallAPI($url, 'GET', [], ['FailOnAccessError'=>true], $users); + $success = $client->CallAPI($url, 'GET', [], ['FailOnAccessError' => true], $users); } else { $success = false; } } if (is_array($users->items)) { - foreach ($users->items AS $user) { + foreach ($users->items as $user) { pumpio_get_contact($uid, $user); } } } -function pumpio_queue_hook(&$a, &$b) +function pumpio_queue_hook(App $a, array &$b) { $qi = q("SELECT * FROM `queue` WHERE `network` = '%s'", dbesc(NETWORK_PUMPIO) ); + if (!DBM::is_result($qi)) { return; } @@ -1426,10 +1428,10 @@ function pumpio_queue_hook(&$a, &$b) //logger('pumpio_queue: fetching userdata '.print_r($userdata, true)); - $oauth_token = PConfig::get($userdata['uid'], "pumpio", "oauth_token"); + $oauth_token = PConfig::get($userdata['uid'], "pumpio", "oauth_token"); $oauth_token_secret = PConfig::get($userdata['uid'], "pumpio", "oauth_token_secret"); - $consumer_key = PConfig::get($userdata['uid'], "pumpio","consumer_key"); - $consumer_secret = PConfig::get($userdata['uid'], "pumpio","consumer_secret"); + $consumer_key = PConfig::get($userdata['uid'], "pumpio", "consumer_key"); + $consumer_secret = PConfig::get($userdata['uid'], "pumpio", "consumer_secret"); $host = PConfig::get($userdata['uid'], "pumpio", "host"); $user = PConfig::get($userdata['uid'], "pumpio", "user"); @@ -1481,7 +1483,7 @@ function pumpio_queue_hook(&$a, &$b) } } -function pumpio_getreceiver(&$a, $b) +function pumpio_getreceiver(App $a, array $b) { $receiver = []; @@ -1566,12 +1568,12 @@ function pumpio_getreceiver(&$a, $b) return $receiver; } -function pumpio_fetchallcomments(&$a, $uid, $id) +function pumpio_fetchallcomments(App $a, $uid, $id) { - $ckey = PConfig::get($uid, 'pumpio', 'consumer_key'); - $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret'); - $otoken = PConfig::get($uid, 'pumpio', 'oauth_token'); - $osecret = PConfig::get($uid, 'pumpio', 'oauth_token_secret'); + $ckey = PConfig::get($uid, 'pumpio', 'consumer_key'); + $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret'); + $otoken = PConfig::get($uid, 'pumpio', 'oauth_token'); + $osecret = PConfig::get($uid, 'pumpio', 'oauth_token_secret'); $hostname = PConfig::get($uid, 'pumpio', 'host'); $username = PConfig::get($uid, "pumpio", "user"); From 332ea212b56f0e5b4dc99a79e5dfd90278e6bbfa Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 21 Jul 2018 08:42:08 -0400 Subject: [PATCH 03/10] Rename DBM method calls to DBA method calls --- .../advancedcontentfilter.php | 3 +- catavatar/catavatar.php | 5 +- diaspora/diaspora.php | 3 +- forumdirectory/forumdirectory.php | 6 +-- ifttt/ifttt.php | 3 +- mailstream/mailstream.php | 6 +-- public_server/public_server.php | 9 ++-- pumpio/pumpio.php | 49 +++++++++---------- statusnet/statusnet.php | 35 +++++++------ twitter/twitter.php | 43 ++++++++-------- viewsrc/viewsrc.php | 4 +- 11 files changed, 79 insertions(+), 87 deletions(-) diff --git a/advancedcontentfilter/advancedcontentfilter.php b/advancedcontentfilter/advancedcontentfilter.php index 37463d5d..e1a162e0 100644 --- a/advancedcontentfilter/advancedcontentfilter.php +++ b/advancedcontentfilter/advancedcontentfilter.php @@ -40,7 +40,6 @@ use Friendica\Core\Cache; use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Database\DBA; -use Friendica\Database\DBM; use Friendica\Database\DBStructure; use Friendica\Model\Item; use Friendica\Model\Term; @@ -414,7 +413,7 @@ function advancedcontentfilter_get_variables_guid(ServerRequestInterface $reques $params = ['order' => ['uid' => true]]; $item = Item::selectFirstForUser(local_user(), [], $condition, $params); - if (!DBM::is_result($item)) { + if (!DBA::is_result($item)) { throw new HTTPException\NotFoundException(L10n::t('Unknown post with guid: %s', $args['guid'])); } diff --git a/catavatar/catavatar.php b/catavatar/catavatar.php index 074cc00c..46f33ac4 100644 --- a/catavatar/catavatar.php +++ b/catavatar/catavatar.php @@ -13,7 +13,6 @@ use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\Worker; use Friendica\Database\DBA; -use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\Photo; use Friendica\Network\HTTPException\NotFoundException; @@ -86,7 +85,7 @@ function catavatar_addon_settings_post(App $a, &$s) $url = $a->get_baseurl() . '/catavatar/' . local_user() . '?ts=' . time(); $self = DBA::selectFirst('contact', ['id'], ['uid' => local_user(), 'self' => true]); - if (!DBM::is_result($self)) { + if (!DBA::is_result($self)) { notice(L10n::t("The cat hadn't found itself.")); return; } @@ -95,7 +94,7 @@ function catavatar_addon_settings_post(App $a, &$s) $condition = ['uid' => local_user(), 'contact-id' => $self['id']]; $photo = DBA::selectFirst('photo', ['resource-id'], $condition); - if (!DBM::is_result($photo)) { + if (!DBA::is_result($photo)) { notice(L10n::t('There was an error, the cat ran away.')); return; } diff --git a/diaspora/diaspora.php b/diaspora/diaspora.php index 2f8c13fe..11535751 100644 --- a/diaspora/diaspora.php +++ b/diaspora/diaspora.php @@ -14,7 +14,6 @@ use Friendica\Core\Addon; use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Database\DBA; -use Friendica\Database\DBM; use Friendica\Model\Queue; function diaspora_install() { @@ -141,7 +140,7 @@ function diaspora_settings(&$a,&$s) { $status = ""; $r = q("SELECT `addr` FROM `contact` WHERE `self` AND `uid` = %d", intval(local_user())); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $status = L10n::t("Please remember: You can always be reached from Diaspora with your Friendica handle %s. ", $r[0]['addr']); $status .= L10n::t('This connector is only meant if you still want to use your old Diaspora account for some time. '); $status .= L10n::t('However, it is preferred that you tell your Diaspora contacts the new handle %s instead.', $r[0]['addr']); diff --git a/forumdirectory/forumdirectory.php b/forumdirectory/forumdirectory.php index a72c45ba..97e5ea65 100644 --- a/forumdirectory/forumdirectory.php +++ b/forumdirectory/forumdirectory.php @@ -11,7 +11,7 @@ use Friendica\Content\Widget; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; -use Friendica\Database\DBM; +use Friendica\Database\DBA; use Friendica\Model\Profile; use Friendica\Util\Temporal; @@ -107,7 +107,7 @@ function forumdirectory_content(&$a) $r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`" . " WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 AND `page-flags` = 2 $sql_extra "); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $a->set_pager_total($r[0]['total']); } @@ -120,7 +120,7 @@ function forumdirectory_content(&$a) intval($a->pager['itemspage']) ); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { if (in_array('small', $a->argv)) { $photo = 'thumb'; } else { diff --git a/ifttt/ifttt.php b/ifttt/ifttt.php index 832f3df2..d24df5fd 100644 --- a/ifttt/ifttt.php +++ b/ifttt/ifttt.php @@ -15,7 +15,6 @@ use Friendica\Core\Addon; use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Database\DBA; -use Friendica\Database\DBM; use Friendica\Model\Item; function ifttt_install() @@ -102,7 +101,7 @@ function ifttt_post(App $a) $nickname = $a->argv[1]; $user = DBA::selectFirst('user', ['uid'], ['nickname' => $nickname]); - if (!DBM::is_result($user)) { + if (!DBA::is_result($user)) { logger('User ' . $nickname . ' not found.', LOGGER_DEBUG); return; } diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index 66b43303..5a72c7ea 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -11,7 +11,7 @@ use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\PConfig; -use Friendica\Database\DBM; +use Friendica\Database\DBA; use Friendica\Util\Network; use Friendica\Model\Item; @@ -173,7 +173,7 @@ function mailstream_do_images($a, &$item, &$attachments) { function mailstream_sender($item) { $r = q('SELECT * FROM `contact` WHERE `id` = %d', $item['contact-id']); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $contact = $r[0]; if ($contact['name'] != $item['author-name']) { return $contact['name'] . ' - ' . $item['author-name']; @@ -214,7 +214,7 @@ function mailstream_subject($item) { // Don't look more than 100 levels deep for a subject, in case of loops for ($i = 0; ($i < 100) && $parent; $i++) { $parent_item = Item::selectFirst(['thr-parent', 'title'], ['uri' => $parent]); - if (!DBM::is_result($parent_item)) { + if (!DBA::is_result($parent_item)) { break; } if ($parent_item['thr-parent'] === $parent) { diff --git a/public_server/public_server.php b/public_server/public_server.php index a30d3303..e2c54a1a 100644 --- a/public_server/public_server.php +++ b/public_server/public_server.php @@ -10,7 +10,6 @@ use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Database\DBA; -use Friendica\Database\DBM; use Friendica\Util\DateTimeFormat; function public_server_install() @@ -60,7 +59,7 @@ function public_server_cron($a, $b) `expire_notification_sent` <= '%s'", dbesc(NULL_DATE), dbesc(NULL_DATE)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { foreach ($r as $rr) { notification([ 'uid' => $rr['uid'], @@ -83,7 +82,7 @@ function public_server_cron($a, $b) if ($nologin) { $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` <= '%s' AND `register_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s'", dbesc(NULL_DATE), intval($nologin), dbesc(NULL_DATE)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { foreach ($r as $rr) { $fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')]; DBA::update('user', $fields, ['uid' => $rr['uid']]); @@ -95,7 +94,7 @@ function public_server_cron($a, $b) if ($flagusers) { $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s' AND `page-flags` = 0", intval($flagusers), dbesc(NULL_DATE)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { foreach ($r as $rr) { $fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')]; DBA::update('user', $fields, ['uid' => $rr['uid']]); @@ -108,7 +107,7 @@ function public_server_cron($a, $b) if ($flagposts && $flagpostsexpire) { $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s' and `expire` = 0 AND `page-flags` = 0", intval($flagposts), dbesc(NULL_DATE)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { foreach ($r as $rr) { DBA::update('user', ['expire' => $flagpostsexpire], ['uid' => $rr['uid']]); } diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index b3442ed7..3377bfc5 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -15,7 +15,6 @@ use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\Worker; use Friendica\Database\DBA; -use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\GContact; use Friendica\Model\Group; @@ -421,7 +420,7 @@ function pumpio_send(App $a, array &$b) $condition = ['id' => $b['parent'], 'network' => NETWORK_PUMPIO]; $orig_post = Item::selectFirst([], $condition); - if (!DBM::is_result($orig_post)) { + if (!DBA::is_result($orig_post)) { logger("pumpio_send: no pumpio post ".$b["parent"]); return; } else { @@ -573,7 +572,7 @@ function pumpio_send(App $a, array &$b) logger('pumpio_send '.$username.': '.$url.' general error: ' . print_r($user, true)); $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", $b['uid']); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $a->contact = $r[0]["id"]; } @@ -601,7 +600,7 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "") $orig_post = Item::selectFirst([], ['uri' => $uri, 'uid' => $uid]); - if (!DBM::is_result($orig_post)) { + if (!DBA::is_result($orig_post)) { return; } @@ -650,7 +649,7 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "") logger('pumpio_action '.$username.' '.$action.': general error: '.$uri.' '.print_r($user, true)); $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", $b['uid']); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $a->contact = $r[0]["id"]; } @@ -665,7 +664,7 @@ function pumpio_sync(App $a) { $r = q("SELECT * FROM `addon` WHERE `installed` = 1 AND `name` = 'pumpio'"); - if (!DBM::is_result($r)) { + if (!DBA::is_result($r)) { return; } @@ -683,7 +682,7 @@ function pumpio_sync(App $a) logger('pumpio: cron_start'); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'pumpio' AND `k` = 'mirror' AND `v` = '1' ORDER BY RAND() "); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { foreach ($r as $rr) { logger('pumpio: mirroring user '.$rr['uid']); pumpio_fetchtimeline($a, $rr['uid']); @@ -698,11 +697,11 @@ function pumpio_sync(App $a) $abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'pumpio' AND `k` = 'import' AND `v` = '1' ORDER BY RAND() "); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { foreach ($r as $rr) { if ($abandon_days != 0) { $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); - if (!DBM::is_result($user)) { + if (!DBA::is_result($user)) { logger('abandoned account: timeline from user '.$rr['uid'].' will not be imported'); continue; } @@ -871,9 +870,9 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id) // Searching for the unliked post // Two queries for speed issues $orig_post = Item::selectFirst([], ['uri' => $post->object->id, 'uid' => $uid]); - if (!DBM::is_result($orig_post)) { + if (!DBA::is_result($orig_post)) { $orig_post = Item::selectFirst([], ['extid' => $post->object->id, 'uid' => $uid]); - if (!DBM::is_result($orig_post)) { + if (!DBA::is_result($orig_post)) { return; } } @@ -888,7 +887,7 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id) intval($uid) ); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $contactid = $r[0]['id']; } @@ -899,7 +898,7 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id) Item::delete(['verb' => ACTIVITY_LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { logger("pumpio_dounlike: unliked existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); } else { logger("pumpio_dounlike: not found. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); @@ -918,9 +917,9 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = // Searching for the liked post // Two queries for speed issues $orig_post = Item::selectFirst([], ['uri' => $post->object->id, 'uid' => $uid]); - if (!DBM::is_result($orig_post)) { + if (!DBA::is_result($orig_post)) { $orig_post = Item::selectFirst([], ['extid' => $post->object->id, 'uid' => $uid]); - if (!DBM::is_result($orig_post)) { + if (!DBA::is_result($orig_post)) { return; } } @@ -943,7 +942,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = intval($uid) ); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $contactid = $r[0]['id']; } @@ -1018,7 +1017,7 @@ function pumpio_get_contact($uid, $contact, $no_insert = false) $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1", intval($uid), dbesc(normalise_link($contact->url))); - if (!DBM::is_result($r)) { + if (!DBA::is_result($r)) { // create contact record q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`, @@ -1048,7 +1047,7 @@ function pumpio_get_contact($uid, $contact, $no_insert = false) intval($uid) ); - if (!DBM::is_result($r)) { + if (!DBA::is_result($r)) { return false; } @@ -1176,7 +1175,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp intval($uid) ); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $contact_id = $r[0]['id']; } else { $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", @@ -1184,7 +1183,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp intval($uid) ); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $contact_id = $r[0]['id']; } else { $contact_id = $self[0]['id']; @@ -1405,7 +1404,7 @@ function pumpio_queue_hook(App $a, array &$b) dbesc(NETWORK_PUMPIO) ); - if (!DBM::is_result($qi)) { + if (!DBA::is_result($qi)) { return; } @@ -1420,7 +1419,7 @@ function pumpio_queue_hook(App $a, array &$b) WHERE `contact`.`self` = 1 AND `contact`.`id` = %d LIMIT 1", intval($x['cid']) ); - if (!DBM::is_result($r)) { + if (!DBA::is_result($r)) { continue; } @@ -1512,7 +1511,7 @@ function pumpio_getreceiver(App $a, array $b) dbesc(NETWORK_PUMPIO) ); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $receiver["bcc"][] = [ "displayName" => $r[0]["name"], "objectType" => "person", @@ -1555,7 +1554,7 @@ function pumpio_getreceiver(App $a, array $b) dbesc(NETWORK_PUMPIO) ); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $receiver["to"][] = [ "displayName" => $r[0]["name"], "objectType" => "person", @@ -1587,7 +1586,7 @@ function pumpio_fetchallcomments(App $a, $uid, $id) // Fetching the original post $condition = ["`uri` = ? AND `uid` = ? AND `extid` != ''", $id, $uid]; $item = Item::selectFirst(['extid'], $condition); - if (!DBM::is_result($item)) { + if (!DBA::is_result($item)) { return false; } diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 9af2c6d1..5a611fdf 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -48,7 +48,6 @@ use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Database\DBA; -use Friendica\Database\DBM; use Friendica\Model\GContact; use Friendica\Model\Group; use Friendica\Model\Item; @@ -465,7 +464,7 @@ function statusnet_post_hook(App $a, &$b) $condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]]; $orig_post = Item::selectFirst(['author-link', 'uri'], $condition); - if (!DBM::is_result($orig_post)) { + if (!DBA::is_result($orig_post)) { logger("statusnet_post_hook: no parent found " . $b["thr-parent"]); return; } else { @@ -686,7 +685,7 @@ function statusnet_prepare_body(App $a, &$b) $condition = ['uri' => $item["thr-parent"], 'uid' => local_user()]; $orig_post = Item::selectFirst(['author-link', 'uri'], $condition); - if (DBM::is_result($orig_post)) { + if (DBA::is_result($orig_post)) { $nick = preg_replace("=https?://(.*)/(.*)=ism", "$2", $orig_post["author-link"]); $nickname = "@[url=" . $orig_post["author-link"] . "]" . $nick . "[/url]"; @@ -731,7 +730,7 @@ function statusnet_cron(App $a, $b) logger('statusnet: cron_start'); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'mirror_posts' AND `v` = '1' ORDER BY RAND() "); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { foreach ($r as $rr) { logger('statusnet: fetching for user ' . $rr['uid']); statusnet_fetchtimeline($a, $rr['uid']); @@ -746,11 +745,11 @@ function statusnet_cron(App $a, $b) $abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'import' AND `v` ORDER BY RAND()"); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { foreach ($r as $rr) { if ($abandon_days != 0) { $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); - if (!DBM::is_result($user)) { + if (!DBA::is_result($user)) { logger('abandoned account: timeline from user ' . $rr['uid'] . ' will not be imported'); continue; } @@ -902,16 +901,16 @@ function statusnet_fetch_contact($uid, $contact, $create_user) $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' AND `network` = '%s'LIMIT 1", intval($uid), dbesc(normalise_link($contact->statusnet_profile_url)), dbesc(NETWORK_STATUSNET)); - if (!DBM::is_result($r) && !$create_user) { + if (!DBA::is_result($r) && !$create_user) { return 0; } - if (DBM::is_result($r) && ($r[0]["readonly"] || $r[0]["blocked"])) { + if (DBA::is_result($r) && ($r[0]["readonly"] || $r[0]["blocked"])) { logger("statusnet_fetch_contact: Contact '" . $r[0]["nick"] . "' is blocked or readonly.", LOGGER_DEBUG); return -1; } - if (!DBM::is_result($r)) { + if (!DBA::is_result($r)) { // create contact record q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`, @@ -941,7 +940,7 @@ function statusnet_fetch_contact($uid, $contact, $create_user) intval($uid), dbesc(NETWORK_STATUSNET)); - if (!DBM::is_result($r)) { + if (!DBA::is_result($r)) { return false; } @@ -1025,7 +1024,7 @@ function statusnet_fetchuser(App $a, $uid, $screen_name = "", $user_id = "") $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $self = $r[0]; } else { return; @@ -1087,11 +1086,11 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $fields = ['uri', 'parent-uri', 'parent']; $item = Item::selectFirst($fields, ['uri' => $parent, 'uid' => $uid]); - if (!DBM::is_result($item)) { + if (!DBA::is_result($item)) { $item = Item::selectFirst($fields, ['extid' => $parent, 'uid' => $uid]); } - if (DBM::is_result($item)) { + if (DBA::is_result($item)) { $postarray['thr-parent'] = $item['uri']; $postarray['parent-uri'] = $item['parent-uri']; $postarray['parent'] = $item['parent']; @@ -1109,7 +1108,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $contactid = $r[0]["id"]; $postarray['owner-name'] = $r[0]["name"]; @@ -1213,7 +1212,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) intval($own_contact), intval($uid)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $nick = $r[0]["nick"]; } else { logger("statusnet_fetchhometimeline: Own GNU Social contact not found for user " . $uid, LOGGER_DEBUG); @@ -1223,7 +1222,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $self = $r[0]; } else { logger("statusnet_fetchhometimeline: Own contact not found for user " . $uid, LOGGER_DEBUG); @@ -1232,7 +1231,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) $u = q("SELECT * FROM user WHERE uid = %d LIMIT 1", intval($uid)); - if (!DBM::is_result($u)) { + if (!DBA::is_result($u)) { logger("statusnet_fetchhometimeline: Own user not found for user " . $uid, LOGGER_DEBUG); return; } @@ -1522,7 +1521,7 @@ function statusnet_fetch_own_contact(App $a, $uid) } else { $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", intval($uid), dbesc($own_url)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $contact_id = $r[0]["id"]; } else { PConfig::delete($uid, 'statusnet', 'own_url'); diff --git a/twitter/twitter.php b/twitter/twitter.php index aa0adfb8..9d501767 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -72,7 +72,6 @@ use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\Worker; use Friendica\Database\DBA; -use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\GContact; use Friendica\Model\Group; @@ -185,7 +184,7 @@ function twitter_follow(App $a, &$contact) FROM `contact` WHERE `uid` = %d AND `nick` = '%s'", intval($uid), dbesc($nickname)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $contact["contact"] = $r[0]; } } @@ -468,7 +467,7 @@ function twitter_post_hook(App $a, &$b) $condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]]; $orig_post = Item::selectFirst([], $condition); - if (!DBM::is_result($orig_post)) { + if (!DBA::is_result($orig_post)) { logger("twitter_post_hook: no parent found " . $b["thr-parent"]); return; } else { @@ -622,7 +621,7 @@ function twitter_post_hook(App $a, &$b) logger('Send to Twitter failed: "' . print_r($result->errors, true) . '"'); $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($b['uid'])); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $a->contact = $r[0]["id"]; } @@ -677,7 +676,7 @@ function twitter_cron(App $a, $b) logger('twitter: cron_start'); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'mirror_posts' AND `v` = '1'"); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { foreach ($r as $rr) { logger('twitter: fetching for user ' . $rr['uid']); Worker::add(PRIORITY_MEDIUM, "addon/twitter/twitter_sync.php", 1, (int) $rr['uid']); @@ -692,11 +691,11 @@ function twitter_cron(App $a, $b) $abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1'"); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { foreach ($r as $rr) { if ($abandon_days != 0) { $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); - if (!DBM::is_result($user)) { + if (!DBA::is_result($user)) { logger('abandoned account: timeline from user ' . $rr['uid'] . ' will not be imported'); continue; } @@ -751,7 +750,7 @@ function twitter_expire(App $a, $b) logger('twitter_expire: expire_start'); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1' ORDER BY RAND()"); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { foreach ($r as $rr) { logger('twitter_expire: user ' . $rr['uid']); Item::expire($rr['uid'], $days, NETWORK_TWITTER, true); @@ -774,7 +773,7 @@ function twitter_prepare_body(App $a, &$b) $condition = ['uri' => $item["thr-parent"], 'uid' => local_user()]; $orig_post = Item::selectFirst(['author-link'], $condition); - if (DBM::is_result($orig_post)) { + if (DBA::is_result($orig_post)) { $nicknameplain = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $orig_post["author-link"]); $nickname = "@[url=" . $orig_post["author-link"] . "]" . $nicknameplain . "[/url]"; $nicknameplain = "@" . $nicknameplain; @@ -925,7 +924,7 @@ function twitter_queue_hook(App $a, &$b) $qi = q("SELECT * FROM `queue` WHERE `network` = '%s'", dbesc(NETWORK_TWITTER) ); - if (!DBM::is_result($qi)) { + if (!DBA::is_result($qi)) { return; } @@ -940,7 +939,7 @@ function twitter_queue_hook(App $a, &$b) WHERE `contact`.`self` = 1 AND `contact`.`id` = %d LIMIT 1", intval($x['cid']) ); - if (!DBM::is_result($r)) { + if (!DBA::is_result($r)) { continue; } @@ -1019,11 +1018,11 @@ function twitter_fetch_contact($uid, $data, $create_user) } $contact = DBA::selectFirst('contact', [], ['uid' => $uid, 'alias' => "twitter::" . $data->id_str]); - if (!DBM::is_result($contact) && !$create_user) { + if (!DBA::is_result($contact) && !$create_user) { return 0; } - if (!DBM::is_result($contact)) { + if (!DBA::is_result($contact)) { // create contact record $fields['uid'] = $uid; $fields['created'] = DateTimeFormat::utcNow(); @@ -1083,7 +1082,7 @@ function twitter_fetchuser(App $a, $uid, $screen_name = "", $user_id = "") $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $self = $r[0]; } else { return; @@ -1354,11 +1353,11 @@ function twitter_createpost(App $a, $uid, $post, $self, $create_user, $only_exis $fields = ['uri', 'parent-uri', 'parent']; $parent_item = Item::selectFirst($fields, ['uri' => $parent, 'uid' => $uid]); - if (!DBM::is_result($parent_item)) { + if (!DBA::is_result($parent_item)) { $parent_item = Item::selectFirst($fields, ['extid' => $parent, 'uid' => $uid]); } - if (DBM::is_result($parent_item)) { + if (DBA::is_result($parent_item)) { $postarray['thr-parent'] = $parent_item['uri']; $postarray['parent-uri'] = $parent_item['parent-uri']; $postarray['parent'] = $parent_item['parent']; @@ -1376,7 +1375,7 @@ function twitter_createpost(App $a, $uid, $post, $self, $create_user, $only_exis $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $contactid = $r[0]["id"]; $postarray['owner-name'] = $r[0]["name"]; @@ -1575,7 +1574,7 @@ function twitter_fetchhometimeline(App $a, $uid) intval($own_contact), intval($uid)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $own_id = $r[0]["nick"]; } else { logger("twitter_fetchhometimeline: Own twitter contact not found for user " . $uid, LOGGER_DEBUG); @@ -1585,7 +1584,7 @@ function twitter_fetchhometimeline(App $a, $uid) $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $self = $r[0]; } else { logger("twitter_fetchhometimeline: Own contact not found for user " . $uid, LOGGER_DEBUG); @@ -1594,7 +1593,7 @@ function twitter_fetchhometimeline(App $a, $uid) $u = q("SELECT * FROM user WHERE uid = %d LIMIT 1", intval($uid)); - if (!DBM::is_result($u)) { + if (!DBA::is_result($u)) { logger("twitter_fetchhometimeline: Own user not found for user " . $uid, LOGGER_DEBUG); return; } @@ -1661,7 +1660,7 @@ function twitter_fetchhometimeline(App $a, $uid) if ($postarray['uri'] == $postarray['parent-uri']) { $contact = DBA::selectFirst('contact', [], ['id' => $postarray['contact-id'], 'self' => false]); - if (DBM::is_result($contact)) { + if (DBA::is_result($contact)) { $notify = Item::isRemoteSelf($contact, $postarray); } } @@ -1753,7 +1752,7 @@ function twitter_fetch_own_contact(App $a, $uid) $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", intval($uid), dbesc("twitter::" . $own_id)); - if (DBM::is_result($r)) { + if (DBA::is_result($r)) { $contact_id = $r[0]["id"]; } else { PConfig::delete($uid, 'twitter', 'own_id'); diff --git a/viewsrc/viewsrc.php b/viewsrc/viewsrc.php index 9ffa0b8c..b0e7666c 100644 --- a/viewsrc/viewsrc.php +++ b/viewsrc/viewsrc.php @@ -9,7 +9,7 @@ use Friendica\Core\Addon; use Friendica\Core\L10n; use Friendica\Model\Item; -use Friendica\Database\DBM; +use Friendica\Database\DBA; function viewsrc_install() { Addon::registerHook('item_photo_menu', 'addon/viewsrc/viewsrc.php', 'viewsrc_item_photo_menu'); @@ -43,7 +43,7 @@ function viewsrc_item_photo_menu(&$a, &$b) if (local_user() != $b['item']['uid']) { $item = Item::selectFirstForUser(local_user(), ['id'], ['uid' => local_user(), 'guid' => $b['item']['guid']]); - if (!DBM::is_result($item)) { + if (!DBA::is_result($item)) { return; } From f4ad0d372125f51a11a27ee036217d93a48deafb Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 21 Jul 2018 08:46:13 -0400 Subject: [PATCH 04/10] Rename DBA::is_result to DBA::isResult --- .../advancedcontentfilter.php | 2 +- catavatar/catavatar.php | 4 +- diaspora/diaspora.php | 2 +- forumdirectory/forumdirectory.php | 4 +- ifttt/ifttt.php | 2 +- mailstream/mailstream.php | 4 +- public_server/public_server.php | 8 ++-- pumpio/pumpio.php | 48 +++++++++---------- statusnet/statusnet.php | 34 ++++++------- twitter/twitter.php | 42 ++++++++-------- viewsrc/viewsrc.php | 2 +- 11 files changed, 76 insertions(+), 76 deletions(-) diff --git a/advancedcontentfilter/advancedcontentfilter.php b/advancedcontentfilter/advancedcontentfilter.php index e1a162e0..34d47425 100644 --- a/advancedcontentfilter/advancedcontentfilter.php +++ b/advancedcontentfilter/advancedcontentfilter.php @@ -413,7 +413,7 @@ function advancedcontentfilter_get_variables_guid(ServerRequestInterface $reques $params = ['order' => ['uid' => true]]; $item = Item::selectFirstForUser(local_user(), [], $condition, $params); - if (!DBA::is_result($item)) { + if (!DBA::isResult($item)) { throw new HTTPException\NotFoundException(L10n::t('Unknown post with guid: %s', $args['guid'])); } diff --git a/catavatar/catavatar.php b/catavatar/catavatar.php index 46f33ac4..f84ae117 100644 --- a/catavatar/catavatar.php +++ b/catavatar/catavatar.php @@ -85,7 +85,7 @@ function catavatar_addon_settings_post(App $a, &$s) $url = $a->get_baseurl() . '/catavatar/' . local_user() . '?ts=' . time(); $self = DBA::selectFirst('contact', ['id'], ['uid' => local_user(), 'self' => true]); - if (!DBA::is_result($self)) { + if (!DBA::isResult($self)) { notice(L10n::t("The cat hadn't found itself.")); return; } @@ -94,7 +94,7 @@ function catavatar_addon_settings_post(App $a, &$s) $condition = ['uid' => local_user(), 'contact-id' => $self['id']]; $photo = DBA::selectFirst('photo', ['resource-id'], $condition); - if (!DBA::is_result($photo)) { + if (!DBA::isResult($photo)) { notice(L10n::t('There was an error, the cat ran away.')); return; } diff --git a/diaspora/diaspora.php b/diaspora/diaspora.php index 11535751..79cd236d 100644 --- a/diaspora/diaspora.php +++ b/diaspora/diaspora.php @@ -140,7 +140,7 @@ function diaspora_settings(&$a,&$s) { $status = ""; $r = q("SELECT `addr` FROM `contact` WHERE `self` AND `uid` = %d", intval(local_user())); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $status = L10n::t("Please remember: You can always be reached from Diaspora with your Friendica handle %s. ", $r[0]['addr']); $status .= L10n::t('This connector is only meant if you still want to use your old Diaspora account for some time. '); $status .= L10n::t('However, it is preferred that you tell your Diaspora contacts the new handle %s instead.', $r[0]['addr']); diff --git a/forumdirectory/forumdirectory.php b/forumdirectory/forumdirectory.php index 97e5ea65..c71c4a38 100644 --- a/forumdirectory/forumdirectory.php +++ b/forumdirectory/forumdirectory.php @@ -107,7 +107,7 @@ function forumdirectory_content(&$a) $r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`" . " WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 AND `page-flags` = 2 $sql_extra "); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $a->set_pager_total($r[0]['total']); } @@ -120,7 +120,7 @@ function forumdirectory_content(&$a) intval($a->pager['itemspage']) ); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { if (in_array('small', $a->argv)) { $photo = 'thumb'; } else { diff --git a/ifttt/ifttt.php b/ifttt/ifttt.php index d24df5fd..14add12a 100644 --- a/ifttt/ifttt.php +++ b/ifttt/ifttt.php @@ -101,7 +101,7 @@ function ifttt_post(App $a) $nickname = $a->argv[1]; $user = DBA::selectFirst('user', ['uid'], ['nickname' => $nickname]); - if (!DBA::is_result($user)) { + if (!DBA::isResult($user)) { logger('User ' . $nickname . ' not found.', LOGGER_DEBUG); return; } diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index 5a72c7ea..012416b8 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -173,7 +173,7 @@ function mailstream_do_images($a, &$item, &$attachments) { function mailstream_sender($item) { $r = q('SELECT * FROM `contact` WHERE `id` = %d', $item['contact-id']); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $contact = $r[0]; if ($contact['name'] != $item['author-name']) { return $contact['name'] . ' - ' . $item['author-name']; @@ -214,7 +214,7 @@ function mailstream_subject($item) { // Don't look more than 100 levels deep for a subject, in case of loops for ($i = 0; ($i < 100) && $parent; $i++) { $parent_item = Item::selectFirst(['thr-parent', 'title'], ['uri' => $parent]); - if (!DBA::is_result($parent_item)) { + if (!DBA::isResult($parent_item)) { break; } if ($parent_item['thr-parent'] === $parent) { diff --git a/public_server/public_server.php b/public_server/public_server.php index e2c54a1a..1fbd41b8 100644 --- a/public_server/public_server.php +++ b/public_server/public_server.php @@ -59,7 +59,7 @@ function public_server_cron($a, $b) `expire_notification_sent` <= '%s'", dbesc(NULL_DATE), dbesc(NULL_DATE)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { foreach ($r as $rr) { notification([ 'uid' => $rr['uid'], @@ -82,7 +82,7 @@ function public_server_cron($a, $b) if ($nologin) { $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` <= '%s' AND `register_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s'", dbesc(NULL_DATE), intval($nologin), dbesc(NULL_DATE)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { foreach ($r as $rr) { $fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')]; DBA::update('user', $fields, ['uid' => $rr['uid']]); @@ -94,7 +94,7 @@ function public_server_cron($a, $b) if ($flagusers) { $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s' AND `page-flags` = 0", intval($flagusers), dbesc(NULL_DATE)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { foreach ($r as $rr) { $fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')]; DBA::update('user', $fields, ['uid' => $rr['uid']]); @@ -107,7 +107,7 @@ function public_server_cron($a, $b) if ($flagposts && $flagpostsexpire) { $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s' and `expire` = 0 AND `page-flags` = 0", intval($flagposts), dbesc(NULL_DATE)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { foreach ($r as $rr) { DBA::update('user', ['expire' => $flagpostsexpire], ['uid' => $rr['uid']]); } diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 3377bfc5..6a6cc606 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -420,7 +420,7 @@ function pumpio_send(App $a, array &$b) $condition = ['id' => $b['parent'], 'network' => NETWORK_PUMPIO]; $orig_post = Item::selectFirst([], $condition); - if (!DBA::is_result($orig_post)) { + if (!DBA::isResult($orig_post)) { logger("pumpio_send: no pumpio post ".$b["parent"]); return; } else { @@ -572,7 +572,7 @@ function pumpio_send(App $a, array &$b) logger('pumpio_send '.$username.': '.$url.' general error: ' . print_r($user, true)); $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", $b['uid']); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $a->contact = $r[0]["id"]; } @@ -600,7 +600,7 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "") $orig_post = Item::selectFirst([], ['uri' => $uri, 'uid' => $uid]); - if (!DBA::is_result($orig_post)) { + if (!DBA::isResult($orig_post)) { return; } @@ -649,7 +649,7 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "") logger('pumpio_action '.$username.' '.$action.': general error: '.$uri.' '.print_r($user, true)); $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", $b['uid']); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $a->contact = $r[0]["id"]; } @@ -664,7 +664,7 @@ function pumpio_sync(App $a) { $r = q("SELECT * FROM `addon` WHERE `installed` = 1 AND `name` = 'pumpio'"); - if (!DBA::is_result($r)) { + if (!DBA::isResult($r)) { return; } @@ -682,7 +682,7 @@ function pumpio_sync(App $a) logger('pumpio: cron_start'); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'pumpio' AND `k` = 'mirror' AND `v` = '1' ORDER BY RAND() "); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { foreach ($r as $rr) { logger('pumpio: mirroring user '.$rr['uid']); pumpio_fetchtimeline($a, $rr['uid']); @@ -697,11 +697,11 @@ function pumpio_sync(App $a) $abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'pumpio' AND `k` = 'import' AND `v` = '1' ORDER BY RAND() "); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { foreach ($r as $rr) { if ($abandon_days != 0) { $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); - if (!DBA::is_result($user)) { + if (!DBA::isResult($user)) { logger('abandoned account: timeline from user '.$rr['uid'].' will not be imported'); continue; } @@ -870,9 +870,9 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id) // Searching for the unliked post // Two queries for speed issues $orig_post = Item::selectFirst([], ['uri' => $post->object->id, 'uid' => $uid]); - if (!DBA::is_result($orig_post)) { + if (!DBA::isResult($orig_post)) { $orig_post = Item::selectFirst([], ['extid' => $post->object->id, 'uid' => $uid]); - if (!DBA::is_result($orig_post)) { + if (!DBA::isResult($orig_post)) { return; } } @@ -887,7 +887,7 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id) intval($uid) ); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $contactid = $r[0]['id']; } @@ -898,7 +898,7 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id) Item::delete(['verb' => ACTIVITY_LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { logger("pumpio_dounlike: unliked existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); } else { logger("pumpio_dounlike: not found. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); @@ -917,9 +917,9 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = // Searching for the liked post // Two queries for speed issues $orig_post = Item::selectFirst([], ['uri' => $post->object->id, 'uid' => $uid]); - if (!DBA::is_result($orig_post)) { + if (!DBA::isResult($orig_post)) { $orig_post = Item::selectFirst([], ['extid' => $post->object->id, 'uid' => $uid]); - if (!DBA::is_result($orig_post)) { + if (!DBA::isResult($orig_post)) { return; } } @@ -942,7 +942,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = intval($uid) ); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $contactid = $r[0]['id']; } @@ -1017,7 +1017,7 @@ function pumpio_get_contact($uid, $contact, $no_insert = false) $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1", intval($uid), dbesc(normalise_link($contact->url))); - if (!DBA::is_result($r)) { + if (!DBA::isResult($r)) { // create contact record q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`, @@ -1047,7 +1047,7 @@ function pumpio_get_contact($uid, $contact, $no_insert = false) intval($uid) ); - if (!DBA::is_result($r)) { + if (!DBA::isResult($r)) { return false; } @@ -1175,7 +1175,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp intval($uid) ); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $contact_id = $r[0]['id']; } else { $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", @@ -1183,7 +1183,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp intval($uid) ); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $contact_id = $r[0]['id']; } else { $contact_id = $self[0]['id']; @@ -1404,7 +1404,7 @@ function pumpio_queue_hook(App $a, array &$b) dbesc(NETWORK_PUMPIO) ); - if (!DBA::is_result($qi)) { + if (!DBA::isResult($qi)) { return; } @@ -1419,7 +1419,7 @@ function pumpio_queue_hook(App $a, array &$b) WHERE `contact`.`self` = 1 AND `contact`.`id` = %d LIMIT 1", intval($x['cid']) ); - if (!DBA::is_result($r)) { + if (!DBA::isResult($r)) { continue; } @@ -1511,7 +1511,7 @@ function pumpio_getreceiver(App $a, array $b) dbesc(NETWORK_PUMPIO) ); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $receiver["bcc"][] = [ "displayName" => $r[0]["name"], "objectType" => "person", @@ -1554,7 +1554,7 @@ function pumpio_getreceiver(App $a, array $b) dbesc(NETWORK_PUMPIO) ); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $receiver["to"][] = [ "displayName" => $r[0]["name"], "objectType" => "person", @@ -1586,7 +1586,7 @@ function pumpio_fetchallcomments(App $a, $uid, $id) // Fetching the original post $condition = ["`uri` = ? AND `uid` = ? AND `extid` != ''", $id, $uid]; $item = Item::selectFirst(['extid'], $condition); - if (!DBA::is_result($item)) { + if (!DBA::isResult($item)) { return false; } diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 5a611fdf..c1701e08 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -464,7 +464,7 @@ function statusnet_post_hook(App $a, &$b) $condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]]; $orig_post = Item::selectFirst(['author-link', 'uri'], $condition); - if (!DBA::is_result($orig_post)) { + if (!DBA::isResult($orig_post)) { logger("statusnet_post_hook: no parent found " . $b["thr-parent"]); return; } else { @@ -685,7 +685,7 @@ function statusnet_prepare_body(App $a, &$b) $condition = ['uri' => $item["thr-parent"], 'uid' => local_user()]; $orig_post = Item::selectFirst(['author-link', 'uri'], $condition); - if (DBA::is_result($orig_post)) { + if (DBA::isResult($orig_post)) { $nick = preg_replace("=https?://(.*)/(.*)=ism", "$2", $orig_post["author-link"]); $nickname = "@[url=" . $orig_post["author-link"] . "]" . $nick . "[/url]"; @@ -730,7 +730,7 @@ function statusnet_cron(App $a, $b) logger('statusnet: cron_start'); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'mirror_posts' AND `v` = '1' ORDER BY RAND() "); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { foreach ($r as $rr) { logger('statusnet: fetching for user ' . $rr['uid']); statusnet_fetchtimeline($a, $rr['uid']); @@ -745,11 +745,11 @@ function statusnet_cron(App $a, $b) $abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'import' AND `v` ORDER BY RAND()"); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { foreach ($r as $rr) { if ($abandon_days != 0) { $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); - if (!DBA::is_result($user)) { + if (!DBA::isResult($user)) { logger('abandoned account: timeline from user ' . $rr['uid'] . ' will not be imported'); continue; } @@ -901,16 +901,16 @@ function statusnet_fetch_contact($uid, $contact, $create_user) $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' AND `network` = '%s'LIMIT 1", intval($uid), dbesc(normalise_link($contact->statusnet_profile_url)), dbesc(NETWORK_STATUSNET)); - if (!DBA::is_result($r) && !$create_user) { + if (!DBA::isResult($r) && !$create_user) { return 0; } - if (DBA::is_result($r) && ($r[0]["readonly"] || $r[0]["blocked"])) { + if (DBA::isResult($r) && ($r[0]["readonly"] || $r[0]["blocked"])) { logger("statusnet_fetch_contact: Contact '" . $r[0]["nick"] . "' is blocked or readonly.", LOGGER_DEBUG); return -1; } - if (!DBA::is_result($r)) { + if (!DBA::isResult($r)) { // create contact record q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`, @@ -940,7 +940,7 @@ function statusnet_fetch_contact($uid, $contact, $create_user) intval($uid), dbesc(NETWORK_STATUSNET)); - if (!DBA::is_result($r)) { + if (!DBA::isResult($r)) { return false; } @@ -1024,7 +1024,7 @@ function statusnet_fetchuser(App $a, $uid, $screen_name = "", $user_id = "") $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $self = $r[0]; } else { return; @@ -1086,11 +1086,11 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $fields = ['uri', 'parent-uri', 'parent']; $item = Item::selectFirst($fields, ['uri' => $parent, 'uid' => $uid]); - if (!DBA::is_result($item)) { + if (!DBA::isResult($item)) { $item = Item::selectFirst($fields, ['extid' => $parent, 'uid' => $uid]); } - if (DBA::is_result($item)) { + if (DBA::isResult($item)) { $postarray['thr-parent'] = $item['uri']; $postarray['parent-uri'] = $item['parent-uri']; $postarray['parent'] = $item['parent']; @@ -1108,7 +1108,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $contactid = $r[0]["id"]; $postarray['owner-name'] = $r[0]["name"]; @@ -1212,7 +1212,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) intval($own_contact), intval($uid)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $nick = $r[0]["nick"]; } else { logger("statusnet_fetchhometimeline: Own GNU Social contact not found for user " . $uid, LOGGER_DEBUG); @@ -1222,7 +1222,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $self = $r[0]; } else { logger("statusnet_fetchhometimeline: Own contact not found for user " . $uid, LOGGER_DEBUG); @@ -1231,7 +1231,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) $u = q("SELECT * FROM user WHERE uid = %d LIMIT 1", intval($uid)); - if (!DBA::is_result($u)) { + if (!DBA::isResult($u)) { logger("statusnet_fetchhometimeline: Own user not found for user " . $uid, LOGGER_DEBUG); return; } @@ -1521,7 +1521,7 @@ function statusnet_fetch_own_contact(App $a, $uid) } else { $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", intval($uid), dbesc($own_url)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $contact_id = $r[0]["id"]; } else { PConfig::delete($uid, 'statusnet', 'own_url'); diff --git a/twitter/twitter.php b/twitter/twitter.php index 9d501767..786b3474 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -184,7 +184,7 @@ function twitter_follow(App $a, &$contact) FROM `contact` WHERE `uid` = %d AND `nick` = '%s'", intval($uid), dbesc($nickname)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $contact["contact"] = $r[0]; } } @@ -467,7 +467,7 @@ function twitter_post_hook(App $a, &$b) $condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]]; $orig_post = Item::selectFirst([], $condition); - if (!DBA::is_result($orig_post)) { + if (!DBA::isResult($orig_post)) { logger("twitter_post_hook: no parent found " . $b["thr-parent"]); return; } else { @@ -621,7 +621,7 @@ function twitter_post_hook(App $a, &$b) logger('Send to Twitter failed: "' . print_r($result->errors, true) . '"'); $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($b['uid'])); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $a->contact = $r[0]["id"]; } @@ -676,7 +676,7 @@ function twitter_cron(App $a, $b) logger('twitter: cron_start'); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'mirror_posts' AND `v` = '1'"); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { foreach ($r as $rr) { logger('twitter: fetching for user ' . $rr['uid']); Worker::add(PRIORITY_MEDIUM, "addon/twitter/twitter_sync.php", 1, (int) $rr['uid']); @@ -691,11 +691,11 @@ function twitter_cron(App $a, $b) $abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1'"); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { foreach ($r as $rr) { if ($abandon_days != 0) { $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); - if (!DBA::is_result($user)) { + if (!DBA::isResult($user)) { logger('abandoned account: timeline from user ' . $rr['uid'] . ' will not be imported'); continue; } @@ -750,7 +750,7 @@ function twitter_expire(App $a, $b) logger('twitter_expire: expire_start'); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1' ORDER BY RAND()"); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { foreach ($r as $rr) { logger('twitter_expire: user ' . $rr['uid']); Item::expire($rr['uid'], $days, NETWORK_TWITTER, true); @@ -773,7 +773,7 @@ function twitter_prepare_body(App $a, &$b) $condition = ['uri' => $item["thr-parent"], 'uid' => local_user()]; $orig_post = Item::selectFirst(['author-link'], $condition); - if (DBA::is_result($orig_post)) { + if (DBA::isResult($orig_post)) { $nicknameplain = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $orig_post["author-link"]); $nickname = "@[url=" . $orig_post["author-link"] . "]" . $nicknameplain . "[/url]"; $nicknameplain = "@" . $nicknameplain; @@ -924,7 +924,7 @@ function twitter_queue_hook(App $a, &$b) $qi = q("SELECT * FROM `queue` WHERE `network` = '%s'", dbesc(NETWORK_TWITTER) ); - if (!DBA::is_result($qi)) { + if (!DBA::isResult($qi)) { return; } @@ -939,7 +939,7 @@ function twitter_queue_hook(App $a, &$b) WHERE `contact`.`self` = 1 AND `contact`.`id` = %d LIMIT 1", intval($x['cid']) ); - if (!DBA::is_result($r)) { + if (!DBA::isResult($r)) { continue; } @@ -1018,11 +1018,11 @@ function twitter_fetch_contact($uid, $data, $create_user) } $contact = DBA::selectFirst('contact', [], ['uid' => $uid, 'alias' => "twitter::" . $data->id_str]); - if (!DBA::is_result($contact) && !$create_user) { + if (!DBA::isResult($contact) && !$create_user) { return 0; } - if (!DBA::is_result($contact)) { + if (!DBA::isResult($contact)) { // create contact record $fields['uid'] = $uid; $fields['created'] = DateTimeFormat::utcNow(); @@ -1082,7 +1082,7 @@ function twitter_fetchuser(App $a, $uid, $screen_name = "", $user_id = "") $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $self = $r[0]; } else { return; @@ -1353,11 +1353,11 @@ function twitter_createpost(App $a, $uid, $post, $self, $create_user, $only_exis $fields = ['uri', 'parent-uri', 'parent']; $parent_item = Item::selectFirst($fields, ['uri' => $parent, 'uid' => $uid]); - if (!DBA::is_result($parent_item)) { + if (!DBA::isResult($parent_item)) { $parent_item = Item::selectFirst($fields, ['extid' => $parent, 'uid' => $uid]); } - if (DBA::is_result($parent_item)) { + if (DBA::isResult($parent_item)) { $postarray['thr-parent'] = $parent_item['uri']; $postarray['parent-uri'] = $parent_item['parent-uri']; $postarray['parent'] = $parent_item['parent']; @@ -1375,7 +1375,7 @@ function twitter_createpost(App $a, $uid, $post, $self, $create_user, $only_exis $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $contactid = $r[0]["id"]; $postarray['owner-name'] = $r[0]["name"]; @@ -1574,7 +1574,7 @@ function twitter_fetchhometimeline(App $a, $uid) intval($own_contact), intval($uid)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $own_id = $r[0]["nick"]; } else { logger("twitter_fetchhometimeline: Own twitter contact not found for user " . $uid, LOGGER_DEBUG); @@ -1584,7 +1584,7 @@ function twitter_fetchhometimeline(App $a, $uid) $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $self = $r[0]; } else { logger("twitter_fetchhometimeline: Own contact not found for user " . $uid, LOGGER_DEBUG); @@ -1593,7 +1593,7 @@ function twitter_fetchhometimeline(App $a, $uid) $u = q("SELECT * FROM user WHERE uid = %d LIMIT 1", intval($uid)); - if (!DBA::is_result($u)) { + if (!DBA::isResult($u)) { logger("twitter_fetchhometimeline: Own user not found for user " . $uid, LOGGER_DEBUG); return; } @@ -1660,7 +1660,7 @@ function twitter_fetchhometimeline(App $a, $uid) if ($postarray['uri'] == $postarray['parent-uri']) { $contact = DBA::selectFirst('contact', [], ['id' => $postarray['contact-id'], 'self' => false]); - if (DBA::is_result($contact)) { + if (DBA::isResult($contact)) { $notify = Item::isRemoteSelf($contact, $postarray); } } @@ -1752,7 +1752,7 @@ function twitter_fetch_own_contact(App $a, $uid) $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", intval($uid), dbesc("twitter::" . $own_id)); - if (DBA::is_result($r)) { + if (DBA::isResult($r)) { $contact_id = $r[0]["id"]; } else { PConfig::delete($uid, 'twitter', 'own_id'); diff --git a/viewsrc/viewsrc.php b/viewsrc/viewsrc.php index b0e7666c..ab5d3afa 100644 --- a/viewsrc/viewsrc.php +++ b/viewsrc/viewsrc.php @@ -43,7 +43,7 @@ function viewsrc_item_photo_menu(&$a, &$b) if (local_user() != $b['item']['uid']) { $item = Item::selectFirstForUser(local_user(), ['id'], ['uid' => local_user(), 'guid' => $b['item']['guid']]); - if (!DBA::is_result($item)) { + if (!DBA::isResult($item)) { return; } From 522e8e58c284b98b95a6bf147fa8448b84793c7b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 21 Jul 2018 09:13:02 -0400 Subject: [PATCH 05/10] [multiple] Rename dbesc to DBA::escape --- diaspora/diaspora.php | 2 +- forumdirectory/forumdirectory.php | 2 +- gravatar/gravatar.php | 7 ++- jappixmini/jappixmini.php | 9 +-- libravatar/libravatar.php | 7 ++- mailstream/mailstream.php | 6 +- public_server/public_server.php | 8 +-- pumpio/pumpio.php | 48 ++++++++-------- remote_permissions/remote_permissions.php | 22 ++++---- statusnet/statusnet.php | 68 +++++++++++------------ testdrive/testdrive.php | 8 ++- twitter/twitter.php | 8 +-- widgets/widget_like.php | 4 +- widgets/widgets.php | 6 +- 14 files changed, 109 insertions(+), 96 deletions(-) diff --git a/diaspora/diaspora.php b/diaspora/diaspora.php index 79cd236d..490cd4d8 100644 --- a/diaspora/diaspora.php +++ b/diaspora/diaspora.php @@ -51,7 +51,7 @@ function diaspora_queue_hook(&$a,&$b) { $hostname = $a->get_hostname(); $qi = q("SELECT * FROM `queue` WHERE `network` = '%s'", - dbesc(NETWORK_DIASPORA2) + DBA::escape(NETWORK_DIASPORA2) ); if(! count($qi)) return; diff --git a/forumdirectory/forumdirectory.php b/forumdirectory/forumdirectory.php index c71c4a38..d3e724c1 100644 --- a/forumdirectory/forumdirectory.php +++ b/forumdirectory/forumdirectory.php @@ -100,7 +100,7 @@ function forumdirectory_content(&$a) if (strlen($search)) { $sql_extra = " AND MATCH (`profile`.`name`, `user`.`nickname`, `pdesc`, `locality`,`region`,`country-name`," . "`gender`,`marital`,`sexual`,`about`,`romance`,`work`,`education`,`pub_keywords`,`prv_keywords` )" - . " AGAINST ('" . dbesc($search) . "' IN BOOLEAN MODE) "; + . " AGAINST ('" . DBA::escape($search) . "' IN BOOLEAN MODE) "; } $publish = Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 "; diff --git a/gravatar/gravatar.php b/gravatar/gravatar.php index 7e5a918b..00d8e5b3 100644 --- a/gravatar/gravatar.php +++ b/gravatar/gravatar.php @@ -5,9 +5,12 @@ * Version: 1.1 * Author: Klaus Weidenbach */ + +use Friendica\App; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; +use Friendica\Database\DBA; /** * Installs the addon hook @@ -29,7 +32,7 @@ function gravatar_uninstall() { logger("unregistered gravatar in avatar_lookup hook"); } -function gravatar_load_config(\Friendica\App $a) +function gravatar_load_config(App $a) { $a->loadConfigFile(__DIR__. '/config/gravatar.ini.php'); } @@ -93,7 +96,7 @@ function gravatar_addon_admin (&$a, &$o) { // Check if Libravatar is enabled and show warning $r = q("SELECT * FROM `addon` WHERE `name` = '%s' and `installed` = 1", - dbesc('libravatar') + DBA::escape('libravatar') ); if (count($r)) { $o = '
' .L10n::t('Information') .'

' .L10n::t('Libravatar addon is installed, too. Please disable Libravatar addon or this Gravatar addon.
The Libravatar addon will fall back to Gravatar if nothing was found at Libravatar.') .'



'; diff --git a/jappixmini/jappixmini.php b/jappixmini/jappixmini.php index 372193fb..7b4a9cb6 100644 --- a/jappixmini/jappixmini.php +++ b/jappixmini/jappixmini.php @@ -67,6 +67,7 @@ use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\PConfig; +use Friendica\Database\DBA; use Friendica\Model\User; use Friendica\Util\Network; @@ -195,7 +196,7 @@ function jappixmini_init() $role = $_REQUEST["role"]; if ($role == "pub") { - $r = q("SELECT * FROM `contact` WHERE LENGTH(`pubkey`) AND `dfrn-id`='%s' LIMIT 1", dbesc($dfrn_id)); + $r = q("SELECT * FROM `contact` WHERE LENGTH(`pubkey`) AND `dfrn-id`='%s' LIMIT 1", DBA::escape($dfrn_id)); if (!count($r)) { killme(); } @@ -204,7 +205,7 @@ function jappixmini_init() $decrypt_func = openssl_public_decrypt; $key = $r[0]["pubkey"]; } else if ($role == "prv") { - $r = q("SELECT * FROM `contact` WHERE LENGTH(`prvkey`) AND `issued-id`='%s' LIMIT 1", dbesc($dfrn_id)); + $r = q("SELECT * FROM `contact` WHERE LENGTH(`prvkey`) AND `issued-id`='%s' LIMIT 1", DBA::escape($dfrn_id)); if (!count($r)) { killme(); } @@ -524,7 +525,7 @@ function jappixmini_script(App $a) $key = $row['k']; $pos = strpos($key, ":"); $dfrn_id = substr($key, $pos + 1); - $r = q("SELECT `name` FROM `contact` WHERE `uid`=$uid AND (`dfrn-id`='%s' OR `issued-id`='%s')", dbesc($dfrn_id), dbesc($dfrn_id)); + $r = q("SELECT `name` FROM `contact` WHERE `uid`=$uid AND (`dfrn-id`='%s' OR `issued-id`='%s')", DBA::escape($dfrn_id), DBA::escape($dfrn_id)); if (count($r)) $name = $r[0]["name"]; @@ -593,7 +594,7 @@ function jappixmini_cron(App $a, $d) // for each user, go through list of contacts $contacts = q("SELECT * FROM `contact` WHERE `uid`=%d AND ((LENGTH(`dfrn-id`) AND LENGTH(`pubkey`)) OR (LENGTH(`issued-id`) AND LENGTH(`prvkey`))) AND `network` = '%s'", - intval($uid), dbesc(NETWORK_DFRN)); + intval($uid), DBA::escape(NETWORK_DFRN)); foreach ($contacts as $contact_row) { $request = $contact_row["request"]; if (!$request) { diff --git a/libravatar/libravatar.php b/libravatar/libravatar.php index 14bc0358..ee283f0c 100644 --- a/libravatar/libravatar.php +++ b/libravatar/libravatar.php @@ -5,9 +5,12 @@ * Version: 1.1 * Author: Klaus Weidenbach */ + +use Friendica\App; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; +use Friendica\Database\DBA; /** * Installs the addon hook @@ -29,7 +32,7 @@ function libravatar_uninstall() logger("unregistered libravatar in avatar_lookup hook"); } -function libravatar_load_config(\Friendica\App $a) +function libravatar_load_config(App $a) { $a->loadConfigFile(__DIR__. '/config/libravatar.ini.php'); } @@ -96,7 +99,7 @@ function libravatar_addon_admin(&$a, &$o) // Libravatar falls back to gravatar, so show warning about gravatar addon if enabled $r = q("SELECT * FROM `addon` WHERE `name` = '%s' and `installed` = 1", - dbesc('gravatar') + DBA::escape('gravatar') ); if (count($r)) { $o = '
' .L10n::t('Information') .'

' .L10n::t('Gravatar addon is installed. Please disable the Gravatar addon.
The Libravatar addon will fall back to Gravatar if nothing was found at Libravatar.') .'



'; diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index 012416b8..8b3c6ede 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -120,8 +120,8 @@ function mailstream_post_hook(&$a, &$item) { $message_id = mailstream_generate_id($a, $item['uri']); q("INSERT INTO `mailstream_item` (`uid`, `contact-id`, `uri`, `message-id`) " . "VALUES (%d, '%s', '%s', '%s')", intval($item['uid']), - intval($item['contact-id']), dbesc($item['uri']), dbesc($message_id)); - $r = q('SELECT * FROM `mailstream_item` WHERE `uid` = %d AND `contact-id` = %d AND `uri` = "%s"', intval($item['uid']), intval($item['contact-id']), dbesc($item['uri'])); + intval($item['contact-id']), DBA::escape($item['uri']), DBA::escape($message_id)); + $r = q('SELECT * FROM `mailstream_item` WHERE `uid` = %d AND `contact-id` = %d AND `uri` = "%s"', intval($item['uid']), intval($item['contact-id']), DBA::escape($item['uri'])); if (count($r) != 1) { logger('mailstream_post_remote_hook: Unexpected number of items returned from mailstream_item', LOGGER_NORMAL); return; @@ -307,7 +307,7 @@ function mailstream_send($a, $message_id, $item, $user) { // In case of failure, still set the item to completed. Otherwise // we'll just try to send it over and over again and it'll fail // every time. - q('UPDATE `mailstream_item` SET `completed` = now() WHERE `message-id` = "%s"', dbesc($message_id)); + q('UPDATE `mailstream_item` SET `completed` = now() WHERE `message-id` = "%s"', DBA::escape($message_id)); } /** diff --git a/public_server/public_server.php b/public_server/public_server.php index 1fbd41b8..19aca3a8 100644 --- a/public_server/public_server.php +++ b/public_server/public_server.php @@ -57,7 +57,7 @@ function public_server_cron($a, $b) $r = q("SELECT * FROM `user` WHERE `account_expires_on` < UTC_TIMESTAMP() + INTERVAL 5 DAY AND `account_expires_on` > '%s' AND `expire_notification_sent` <= '%s'", - dbesc(NULL_DATE), dbesc(NULL_DATE)); + DBA::escape(NULL_DATE), DBA::escape(NULL_DATE)); if (DBA::isResult($r)) { foreach ($r as $rr) { @@ -81,7 +81,7 @@ function public_server_cron($a, $b) $nologin = Config::get('public_server', 'nologin', false); if ($nologin) { $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` <= '%s' AND `register_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s'", - dbesc(NULL_DATE), intval($nologin), dbesc(NULL_DATE)); + DBA::escape(NULL_DATE), intval($nologin), DBA::escape(NULL_DATE)); if (DBA::isResult($r)) { foreach ($r as $rr) { $fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')]; @@ -93,7 +93,7 @@ function public_server_cron($a, $b) $flagusers = Config::get('public_server', 'flagusers', false); if ($flagusers) { $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s' AND `page-flags` = 0", - intval($flagusers), dbesc(NULL_DATE)); + intval($flagusers), DBA::escape(NULL_DATE)); if (DBA::isResult($r)) { foreach ($r as $rr) { $fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')]; @@ -106,7 +106,7 @@ function public_server_cron($a, $b) $flagpostsexpire = Config::get('public_server', 'flagpostsexpire'); if ($flagposts && $flagpostsexpire) { $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s' and `expire` = 0 AND `page-flags` = 0", - intval($flagposts), dbesc(NULL_DATE)); + intval($flagposts), DBA::escape(NULL_DATE)); if (DBA::isResult($r)) { foreach ($r as $rr) { DBA::update('user', ['expire' => $flagpostsexpire], ['uid' => $rr['uid']]); diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 6a6cc606..fb96d5b6 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -883,7 +883,7 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id) $contactid = $self[0]['id']; } else { $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", - dbesc(normalise_link($post->actor->url)), + DBA::escape(normalise_link($post->actor->url)), intval($uid) ); @@ -938,7 +938,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = $post->actor->image->url = $self[0]['photo']; } else { $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", - dbesc(normalise_link($post->actor->url)), + DBA::escape(normalise_link($post->actor->url)), intval($uid) ); @@ -1015,7 +1015,7 @@ function pumpio_get_contact($uid, $contact, $no_insert = false) } $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1", - intval($uid), dbesc(normalise_link($contact->url))); + intval($uid), DBA::escape(normalise_link($contact->url))); if (!DBA::isResult($r)) { // create contact record @@ -1024,26 +1024,26 @@ function pumpio_get_contact($uid, $contact, $no_insert = false) `location`, `about`, `writable`, `blocked`, `readonly`, `pending` ) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', %d, 0, 0, 0)", intval($uid), - dbesc(DateTimeFormat::utcNow()), - dbesc($contact->url), - dbesc(normalise_link($contact->url)), - dbesc(str_replace("acct:", "", $contact->id)), - dbesc(''), - dbesc($contact->id), // What is it for? - dbesc('pump.io ' . $contact->id), // What is it for? - dbesc($contact->displayName), - dbesc($contact->preferredUsername), - dbesc($contact->image->url), - dbesc(NETWORK_PUMPIO), + DBA::escape(DateTimeFormat::utcNow()), + DBA::escape($contact->url), + DBA::escape(normalise_link($contact->url)), + DBA::escape(str_replace("acct:", "", $contact->id)), + DBA::escape(''), + DBA::escape($contact->id), // What is it for? + DBA::escape('pump.io ' . $contact->id), // What is it for? + DBA::escape($contact->displayName), + DBA::escape($contact->preferredUsername), + DBA::escape($contact->image->url), + DBA::escape(NETWORK_PUMPIO), intval(CONTACT_IS_FRIEND), intval(1), - dbesc($contact->location->displayName), - dbesc($contact->summary), + DBA::escape($contact->location->displayName), + DBA::escape($contact->summary), intval(1) ); $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1", - dbesc(normalise_link($contact->url)), + DBA::escape(normalise_link($contact->url)), intval($uid) ); @@ -1171,7 +1171,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp } elseif ($contact_id == 0) { // Take an existing contact, the contact of the note or - as a fallback - the id of the user $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", - dbesc(normalise_link($post->actor->url)), + DBA::escape(normalise_link($post->actor->url)), intval($uid) ); @@ -1179,7 +1179,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp $contact_id = $r[0]['id']; } else { $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", - dbesc(normalise_link($post->actor->url)), + DBA::escape(normalise_link($post->actor->url)), intval($uid) ); @@ -1304,7 +1304,7 @@ function pumpio_fetchinbox(App $a, $uid) INNER JOIN `item` ON `item`.`id` = `thread`.`iid` WHERE `thread`.`network` = '%s' AND `thread`.`uid` = %d AND `item`.`extid` != '' ORDER BY `thread`.`commented` DESC LIMIT 10", - dbesc(NETWORK_PUMPIO), + DBA::escape(NETWORK_PUMPIO), intval($uid) ); @@ -1401,7 +1401,7 @@ function pumpio_getallusers(App &$a, $uid) function pumpio_queue_hook(App $a, array &$b) { $qi = q("SELECT * FROM `queue` WHERE `network` = '%s'", - dbesc(NETWORK_PUMPIO) + DBA::escape(NETWORK_PUMPIO) ); if (!DBA::isResult($qi)) { @@ -1508,7 +1508,7 @@ function pumpio_getreceiver(App $a, array $b) $r = q("SELECT `name`, `nick`, `url` FROM `contact` WHERE `id` = %d AND `uid` = %d AND `network` = '%s' AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", intval($cid), intval($b["uid"]), - dbesc(NETWORK_PUMPIO) + DBA::escape(NETWORK_PUMPIO) ); if (DBA::isResult($r)) { @@ -1526,7 +1526,7 @@ function pumpio_getreceiver(App $a, array $b) "FROM `group_member`, `contact` WHERE `group_member`.`gid` = %d ". "AND `contact`.`id` = `group_member`.`contact-id` AND `contact`.`network` = '%s'", intval($gid), - dbesc(NETWORK_PUMPIO) + DBA::escape(NETWORK_PUMPIO) ); foreach ($r AS $row) @@ -1551,7 +1551,7 @@ function pumpio_getreceiver(App $a, array $b) $r = q("SELECT `name`, `nick`, `url` FROM `contact` WHERE `id` = %d AND `uid` = %d AND `network` = '%s' AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", intval($cid), intval($b["uid"]), - dbesc(NETWORK_PUMPIO) + DBA::escape(NETWORK_PUMPIO) ); if (DBA::isResult($r)) { diff --git a/remote_permissions/remote_permissions.php b/remote_permissions/remote_permissions.php index 94bdf5c1..a9f5b51e 100644 --- a/remote_permissions/remote_permissions.php +++ b/remote_permissions/remote_permissions.php @@ -6,10 +6,12 @@ * Author: Zach * */ + use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\PConfig; +use Friendica\Database\DBA; function remote_permissions_install() { Addon::registerHook('lockview_content', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_content'); @@ -84,7 +86,7 @@ function remote_permissions_content($a, $item_copy) { // The contact lives here. Get his/her user info $nick = $r[0]['nick']; $r = q("SELECT uid FROM user WHERE nickname = '%s' LIMIT 1", - dbesc($nick) + DBA::escape($nick) ); if(! $r) return; @@ -104,15 +106,15 @@ function remote_permissions_content($a, $item_copy) { if($item_copy['uri'] === $item_copy['parent-uri']) { // Lockview for a top-level post $r = q("SELECT allow_cid, allow_gid, deny_cid, deny_gid FROM item WHERE uri = '%s' AND type = 'wall' LIMIT 1", - dbesc($item_copy['uri']) + DBA::escape($item_copy['uri']) ); } else { // Lockview for a comment $r = q("SELECT allow_cid, allow_gid, deny_cid, deny_gid FROM item WHERE uri = '%s' AND parent = ( SELECT id FROM item WHERE uri = '%s' AND type = 'wall' ) LIMIT 1", - dbesc($item_copy['uri']), - dbesc($item_copy['parent-uri']) + DBA::escape($item_copy['uri']), + DBA::escape($item_copy['parent-uri']) ); } if($r) { @@ -130,7 +132,7 @@ function remote_permissions_content($a, $item_copy) { if(count($allowed_groups)) { $r = q("SELECT DISTINCT `contact-id` FROM group_member WHERE gid IN ( %s )", - dbesc(implode(', ', $allowed_groups)) + DBA::escape(implode(', ', $allowed_groups)) ); foreach($r as $rr) $allow[] = $rr['contact-id']; @@ -139,7 +141,7 @@ function remote_permissions_content($a, $item_copy) { if(count($deny_groups)) { $r = q("SELECT DISTINCT `contact-id` FROM group_member WHERE gid IN ( %s )", - dbesc(implode(', ', $deny_groups)) + DBA::escape(implode(', ', $deny_groups)) ); foreach($r as $rr) $deny[] = $rr['contact-id']; @@ -149,7 +151,7 @@ function remote_permissions_content($a, $item_copy) { if($allow) { $r = q("SELECT name FROM contact WHERE id IN ( %s )", - dbesc(implode(', ', array_diff($allow, $deny))) + DBA::escape(implode(', ', array_diff($allow, $deny))) ); foreach($r as $rr) $allow_names[] = $rr['name']; @@ -162,8 +164,8 @@ function remote_permissions_content($a, $item_copy) { // will have different URIs than the original. We can match the GUID for // those $r = q("SELECT `uid` FROM item WHERE uri = '%s' OR guid = '%s'", - dbesc($item_copy['uri']), - dbesc($item_copy['guid']) + DBA::escape($item_copy['uri']), + DBA::escape($item_copy['guid']) ); if(! $r) return; @@ -173,7 +175,7 @@ function remote_permissions_content($a, $item_copy) { $allow[] = $rr['uid']; $r = q("SELECT username FROM user WHERE uid IN ( %s )", - dbesc(implode(', ', $allow)) + DBA::escape(implode(', ', $allow)) ); if(! $r) return; diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index c1701e08..58f4485e 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -899,7 +899,7 @@ function statusnet_fetch_contact($uid, $contact, $create_user) "location" => $contact->location, "about" => $contact->description, "addr" => statusnet_address($contact), "generation" => 3]); - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' AND `network` = '%s'LIMIT 1", intval($uid), dbesc(normalise_link($contact->statusnet_profile_url)), dbesc(NETWORK_STATUSNET)); + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' AND `network` = '%s'LIMIT 1", intval($uid), DBA::escape(normalise_link($contact->statusnet_profile_url)), DBA::escape(NETWORK_STATUSNET)); if (!DBA::isResult($r) && !$create_user) { return 0; @@ -917,28 +917,28 @@ function statusnet_fetch_contact($uid, $contact, $create_user) `location`, `about`, `writable`, `blocked`, `readonly`, `pending` ) VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', %d, 0, 0, 0 ) ", intval($uid), - dbesc(DateTimeFormat::utcNow()), - dbesc($contact->statusnet_profile_url), - dbesc(normalise_link($contact->statusnet_profile_url)), - dbesc(statusnet_address($contact)), - dbesc(normalise_link($contact->statusnet_profile_url)), - dbesc(''), - dbesc(''), - dbesc($contact->name), - dbesc($contact->screen_name), - dbesc($contact->profile_image_url), - dbesc(NETWORK_STATUSNET), + DBA::escape(DateTimeFormat::utcNow()), + DBA::escape($contact->statusnet_profile_url), + DBA::escape(normalise_link($contact->statusnet_profile_url)), + DBA::escape(statusnet_address($contact)), + DBA::escape(normalise_link($contact->statusnet_profile_url)), + DBA::escape(''), + DBA::escape(''), + DBA::escape($contact->name), + DBA::escape($contact->screen_name), + DBA::escape($contact->profile_image_url), + DBA::escape(NETWORK_STATUSNET), intval(CONTACT_IS_FRIEND), intval(1), - dbesc($contact->location), - dbesc($contact->description), + DBA::escape($contact->location), + DBA::escape($contact->description), intval(1) ); $r = q("SELECT * FROM `contact` WHERE `alias` = '%s' AND `uid` = %d AND `network` = '%s' LIMIT 1", - dbesc($contact->statusnet_profile_url), + DBA::escape($contact->statusnet_profile_url), intval($uid), - dbesc(NETWORK_STATUSNET)); + DBA::escape(NETWORK_STATUSNET)); if (!DBA::isResult($r)) { return false; @@ -955,10 +955,10 @@ function statusnet_fetch_contact($uid, $contact, $create_user) `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d", - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), - dbesc(DateTimeFormat::utcNow()), + DBA::escape($photos[0]), + DBA::escape($photos[1]), + DBA::escape($photos[2]), + DBA::escape(DateTimeFormat::utcNow()), intval($contact_id) ); } else { @@ -986,19 +986,19 @@ function statusnet_fetch_contact($uid, $contact, $create_user) `location` = '%s', `about` = '%s' WHERE `id` = %d", - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), - dbesc(DateTimeFormat::utcNow()), - dbesc(DateTimeFormat::utcNow()), - dbesc(DateTimeFormat::utcNow()), - dbesc($contact->statusnet_profile_url), - dbesc(normalise_link($contact->statusnet_profile_url)), - dbesc(statusnet_address($contact)), - dbesc($contact->name), - dbesc($contact->screen_name), - dbesc($contact->location), - dbesc($contact->description), + DBA::escape($photos[0]), + DBA::escape($photos[1]), + DBA::escape($photos[2]), + DBA::escape(DateTimeFormat::utcNow()), + DBA::escape(DateTimeFormat::utcNow()), + DBA::escape(DateTimeFormat::utcNow()), + DBA::escape($contact->statusnet_profile_url), + DBA::escape(normalise_link($contact->statusnet_profile_url)), + DBA::escape(statusnet_address($contact)), + DBA::escape($contact->name), + DBA::escape($contact->screen_name), + DBA::escape($contact->location), + DBA::escape($contact->description), intval($r[0]['id']) ); } @@ -1520,7 +1520,7 @@ function statusnet_fetch_own_contact(App $a, $uid) $contact_id = statusnet_fetch_contact($uid, $user, true); } else { $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", - intval($uid), dbesc($own_url)); + intval($uid), DBA::escape($own_url)); if (DBA::isResult($r)) { $contact_id = $r[0]["id"]; } else { diff --git a/testdrive/testdrive.php b/testdrive/testdrive.php index 8e71103f..e67479df 100644 --- a/testdrive/testdrive.php +++ b/testdrive/testdrive.php @@ -6,9 +6,11 @@ * Author: Mike Macgirvin */ +use Friendica\App; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; +use Friendica\Database\DBA; use Friendica\Model\User; use Friendica\Util\DateTimeFormat; @@ -33,7 +35,7 @@ function testdrive_uninstall() { } -function testdrive_load_config(\Friendica\App $a) +function testdrive_load_config(App $a) { $a->loadConfigFile(__DIR__. '/config/testdrive.ini.php'); } @@ -51,7 +53,7 @@ function testdrive_register_account($a,$b) { return; $r = q("UPDATE user set account_expires_on = '%s' where uid = %d", - dbesc(DateTimeFormat::convert('now +' . $days . ' days')), + DBA::escape(DateTimeFormat::convert('now +' . $days . ' days')), intval($uid) ); @@ -79,7 +81,7 @@ function testdrive_cron($a,$b) { ]); q("update user set expire_notification_sent = '%s' where uid = %d", - dbesc(DateTimeFormat::utcNow()), + DBA::escape(DateTimeFormat::utcNow()), intval($rr['uid']) ); diff --git a/twitter/twitter.php b/twitter/twitter.php index 786b3474..59188705 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -142,7 +142,7 @@ function twitter_check_item_notification(App $a, &$notification_data) $own_user = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", intval($notification_data["uid"]), - dbesc("twitter::".$own_id) + DBA::escape("twitter::".$own_id) ); if ($own_user) { @@ -183,7 +183,7 @@ function twitter_follow(App $a, &$contact) $r = q("SELECT name,nick,url,addr,batch,notify,poll,request,confirm,poco,photo,priority,network,alias,pubkey FROM `contact` WHERE `uid` = %d AND `nick` = '%s'", intval($uid), - dbesc($nickname)); + DBA::escape($nickname)); if (DBA::isResult($r)) { $contact["contact"] = $r[0]; } @@ -922,7 +922,7 @@ function twitter_fetchtimeline(App $a, $uid) function twitter_queue_hook(App $a, &$b) { $qi = q("SELECT * FROM `queue` WHERE `network` = '%s'", - dbesc(NETWORK_TWITTER) + DBA::escape(NETWORK_TWITTER) ); if (!DBA::isResult($qi)) { return; @@ -1751,7 +1751,7 @@ function twitter_fetch_own_contact(App $a, $uid) } else { $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", intval($uid), - dbesc("twitter::" . $own_id)); + DBA::escape("twitter::" . $own_id)); if (DBA::isResult($r)) { $contact_id = $r[0]["id"]; } else { diff --git a/widgets/widget_like.php b/widgets/widget_like.php index 5f03c12e..2e387954 100644 --- a/widgets/widget_like.php +++ b/widgets/widget_like.php @@ -37,7 +37,7 @@ function like_widget_content(&$a, $conf){ // count likes $r = q( $baseq . "AND `item`.`verb` = 'http://activitystrea.ms/schema/1.0/like'", intval($conf['uid']), - dbesc($args[0]) + DBA::escape($args[0]) ); $likes = $r[0]['c']; $iid = $r[0]['id']; @@ -45,7 +45,7 @@ function like_widget_content(&$a, $conf){ // count dislikes $r = q( $baseq . "AND `item`.`verb` = 'http://purl.org/macgirvin/dfrn/1.0/dislike'", intval($conf['uid']), - dbesc($args[0]) + DBA::escape($args[0]) ); $dislikes = $r[0]['c']; diff --git a/widgets/widgets.php b/widgets/widgets.php index 1c7489f1..deea77ac 100644 --- a/widgets/widgets.php +++ b/widgets/widgets.php @@ -5,21 +5,23 @@ * Version: 1.0 * Author: Fabio Comuni */ + use Friendica\Core\Addon; use Friendica\Core\L10n; use Friendica\Core\PConfig; +use Friendica\Database\DBA; function widgets_install() { Addon::registerHook('addon_settings', 'addon/widgets/widgets.php', 'widgets_settings'); Addon::registerHook('addon_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post'); logger("installed widgets"); } + function widgets_uninstall() { Addon::unregisterHook('addon_settings', 'addon/widgets/widgets.php', 'widgets_settings'); Addon::unregisterHook('addon_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post'); } - function widgets_settings_post(){ if(! local_user()) return; @@ -89,7 +91,7 @@ function widgets_content(&$a) { } $r = q("SELECT * FROM pconfig WHERE uid IN (SELECT uid FROM pconfig WHERE v='%s')AND cat='widgets'", - dbesc($_GET['k']) + DBA::escape($_GET['k']) ); if (!count($r)){ if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); killme();} From b058ac39df607eff447989e9d853b98c844f1d74 Mon Sep 17 00:00:00 2001 From: Andreas Neustifter Date: Mon, 23 Jul 2018 23:06:09 +0200 Subject: [PATCH 06/10] [curweather] Fix widget layout. [friendica#5473] (#662) See issue [friendica#5473](https://github.com/friendica/friendica/issues/5473) and PR#653. --- curweather/curweather.css | 4 +- curweather/curweather.php | 334 ++++++++++++++++---------------- curweather/templates/widget.tpl | 27 ++- 3 files changed, 186 insertions(+), 179 deletions(-) diff --git a/curweather/curweather.css b/curweather/curweather.css index 69574ff0..a16cbc06 100644 --- a/curweather/curweather.css +++ b/curweather/curweather.css @@ -1,11 +1,11 @@ #curweather-network img { float: left; - margin: 30px 10px; } ul.curweather-details li { list-type: none; } -p.curweather-footer { +div.curweather-footer { + margin-top: 10px; font-size: 0.8em; } diff --git a/curweather/curweather.php b/curweather/curweather.php index fe506ca3..71dada34 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -21,203 +21,203 @@ use Friendica\Util\Network; // get the weather data from OpenWeatherMap function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0) { - $url = "http://api.openweathermap.org/data/2.5/weather?q=".$loc."&appid=".$appid."&lang=".$lang."&units=".$units."&mode=xml"; - $cached = Cache::get('curweather'.md5($url)); - $now = new DateTime(); - if (!is_null($cached)) { - $cdate = PConfig::get(local_user(), 'curweather', 'last'); - $cached = unserialize($cached); - if ($cdate + $cachetime > $now->getTimestamp()) { - return $cached; - } - } - try { - $res = new SimpleXMLElement(Network::fetchUrl($url)); - } catch (Exception $e) { - if (!$_SESSION['curweather_notice_shown']) { - info(L10n::t('Error fetching weather data. Error was: '.$e->getMessage())); - $_SESSION['curweather_notice_shown'] = true; - } - return false; - } - unset($_SESSION['curweather_notice_shown']); - if ((string)$res->temperature['unit']==='metric') { - $tunit = '°C'; - $wunit = 'm/s'; - } else { - $tunit = '°F'; - $wunit = 'mph'; - } - if ( trim((string)$res->weather['value']) == trim((string)$res->clouds['name']) ) { - $desc = (string)$res->clouds['name']; - } else { - $desc = (string)$res->weather['value'].', '.(string)$res->clouds['name']; - } - $r = [ - 'city'=> (string) $res->city['name'][0], - 'country' => (string) $res->city->country[0], - 'lat' => (string) $res->city->coord['lat'], - 'lon' => (string) $res->city->coord['lon'], - 'temperature' => (string) $res->temperature['value'][0].$tunit, - 'pressure' => (string) $res->pressure['value'].(string)$res->pressure['unit'], - 'humidity' => (string) $res->humidity['value'].(string)$res->humidity['unit'], - 'descripion' => $desc, - 'wind' => (string)$res->wind->speed['name'].' ('.(string)$res->wind->speed['value'].$wunit.')', - 'update' => (string)$res->lastupdate['value'], - 'icon' => (string)$res->weather['icon'] - ]; - PConfig::set(local_user(), 'curweather', 'last', $now->getTimestamp()); - Cache::set('curweather'.md5($url), serialize($r), CACHE_HOUR); - return $r; + $url = "http://api.openweathermap.org/data/2.5/weather?q=".$loc."&appid=".$appid."&lang=".$lang."&units=".$units."&mode=xml"; + $cached = Cache::get('curweather'.md5($url)); + $now = new DateTime(); + if (!is_null($cached)) { + $cdate = PConfig::get(local_user(), 'curweather', 'last'); + $cached = unserialize($cached); + if ($cdate + $cachetime > $now->getTimestamp()) { + return $cached; + } + } + try { + $res = new SimpleXMLElement(Network::fetchUrl($url)); + } catch (Exception $e) { + if (!$_SESSION['curweather_notice_shown']) { + info(L10n::t('Error fetching weather data. Error was: '.$e->getMessage())); + $_SESSION['curweather_notice_shown'] = true; + } + return false; + } + unset($_SESSION['curweather_notice_shown']); + if ((string)$res->temperature['unit']==='metric') { + $tunit = '°C'; + $wunit = 'm/s'; + } else { + $tunit = '°F'; + $wunit = 'mph'; + } + if ( trim((string)$res->weather['value']) == trim((string)$res->clouds['name']) ) { + $desc = (string)$res->clouds['name']; + } else { + $desc = (string)$res->weather['value'].', '.(string)$res->clouds['name']; + } + $r = [ + 'city'=> (string) $res->city['name'][0], + 'country' => (string) $res->city->country[0], + 'lat' => (string) $res->city->coord['lat'], + 'lon' => (string) $res->city->coord['lon'], + 'temperature' => (string) $res->temperature['value'][0].$tunit, + 'pressure' => (string) $res->pressure['value'].(string)$res->pressure['unit'], + 'humidity' => (string) $res->humidity['value'].(string)$res->humidity['unit'], + 'descripion' => $desc, + 'wind' => (string)$res->wind->speed['name'].' ('.(string)$res->wind->speed['value'].$wunit.')', + 'update' => (string)$res->lastupdate['value'], + 'icon' => (string)$res->weather['icon'] + ]; + PConfig::set(local_user(), 'curweather', 'last', $now->getTimestamp()); + Cache::set('curweather'.md5($url), serialize($r), CACHE_HOUR); + return $r; } function curweather_install() { - Addon::registerHook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init'); - Addon::registerHook('addon_settings', 'addon/curweather/curweather.php', 'curweather_addon_settings'); - Addon::registerHook('addon_settings_post', 'addon/curweather/curweather.php', 'curweather_addon_settings_post'); + Addon::registerHook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init'); + Addon::registerHook('addon_settings', 'addon/curweather/curweather.php', 'curweather_addon_settings'); + Addon::registerHook('addon_settings_post', 'addon/curweather/curweather.php', 'curweather_addon_settings_post'); } function curweather_uninstall() { - Addon::unregisterHook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init'); - Addon::unregisterHook('addon_settings', 'addon/curweather/curweather.php', 'curweather_addon_settings'); - Addon::unregisterHook('addon_settings_post', 'addon/curweather/curweather.php', 'curweather_addon_settings_post'); + Addon::unregisterHook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init'); + Addon::unregisterHook('addon_settings', 'addon/curweather/curweather.php', 'curweather_addon_settings'); + Addon::unregisterHook('addon_settings_post', 'addon/curweather/curweather.php', 'curweather_addon_settings_post'); } function curweather_network_mod_init(&$fk_app,&$b) { - if(! intval(PConfig::get(local_user(),'curweather','curweather_enable'))) - return; + if(! intval(PConfig::get(local_user(),'curweather','curweather_enable'))) + return; - $fk_app->page['htmlhead'] .= '' . "\r\n"; + $fk_app->page['htmlhead'] .= '' . "\r\n"; - // $rpt value is needed for location - // $lang will be taken from the browser session to honour user settings - // TODO $lang does not work if the default settings are used - // and not all response strings are translated - // $units can be set in the settings by the user - // $appid is configured by the admin in the admin panel - // those parameters will be used to get: cloud status, temperature, preassure - // and relative humidity for display, also the relevent area of the map is - // linked from lat/log of the reply of OWMp - $rpt = PConfig::get(local_user(), 'curweather', 'curweather_loc'); + // $rpt value is needed for location + // $lang will be taken from the browser session to honour user settings + // TODO $lang does not work if the default settings are used + // and not all response strings are translated + // $units can be set in the settings by the user + // $appid is configured by the admin in the admin panel + // those parameters will be used to get: cloud status, temperature, preassure + // and relative humidity for display, also the relevent area of the map is + // linked from lat/log of the reply of OWMp + $rpt = PConfig::get(local_user(), 'curweather', 'curweather_loc'); - // set the language to the browsers language and use metric units - $lang = $_SESSION['language']; - $units = PConfig::get( local_user(), 'curweather', 'curweather_units'); - $appid = Config::get('curweather','appid'); - $cachetime = intval(Config::get('curweather','cachetime')); - if ($units==="") - $units = 'metric'; - $ok = true; + // set the language to the browsers language and use metric units + $lang = $_SESSION['language']; + $units = PConfig::get( local_user(), 'curweather', 'curweather_units'); + $appid = Config::get('curweather','appid'); + $cachetime = intval(Config::get('curweather','cachetime')); + if ($units==="") + $units = 'metric'; + $ok = true; - $res = getWeather($rpt, $units, $lang, $appid, $cachetime); - if ($res===false) - $ok = false; + $res = getWeather($rpt, $units, $lang, $appid, $cachetime); + if ($res===false) + $ok = false; - if ($ok) { - $t = get_markup_template("widget.tpl", "addon/curweather/" ); - $curweather = replace_macros ($t, [ - '$title' => L10n::t("Current Weather"), - '$icon' => proxy_url('http://openweathermap.org/img/w/'.$res['icon'].'.png'), - '$city' => $res['city'], - '$lon' => $res['lon'], - '$lat' => $res['lat'], - '$description' => $res['descripion'], - '$temp' => $res['temperature'], - '$relhumidity' => ['caption'=>L10n::t('Relative Humidity'), 'val'=>$res['humidity']], - '$pressure' => ['caption'=>L10n::t('Pressure'), 'val'=>$res['pressure']], - '$wind' => ['caption'=>L10n::t('Wind'), 'val'=> $res['wind']], - '$lastupdate' => L10n::t('Last Updated').': '.$res['update'].'UTC', - '$databy' => L10n::t('Data by'), - '$showonmap' => L10n::t('Show on map') - ]); - } else { - $t = get_markup_template('widget-error.tpl', 'addon/curweather/'); - $curweather = replace_macros( $t, [ - '$problem' => L10n::t('There was a problem accessing the weather data. But have a look'), - '$rpt' => $rpt, - '$atOWM' => L10n::t('at OpenWeatherMap') - ]); - } + if ($ok) { + $t = get_markup_template("widget.tpl", "addon/curweather/" ); + $curweather = replace_macros ($t, [ + '$title' => L10n::t("Current Weather"), + '$icon' => proxy_url('http://openweathermap.org/img/w/'.$res['icon'].'.png'), + '$city' => $res['city'], + '$lon' => $res['lon'], + '$lat' => $res['lat'], + '$description' => $res['descripion'], + '$temp' => $res['temperature'], + '$relhumidity' => ['caption'=>L10n::t('Relative Humidity'), 'val'=>$res['humidity']], + '$pressure' => ['caption'=>L10n::t('Pressure'), 'val'=>$res['pressure']], + '$wind' => ['caption'=>L10n::t('Wind'), 'val'=> $res['wind']], + '$lastupdate' => L10n::t('Last Updated').': '.$res['update'].'UTC', + '$databy' => L10n::t('Data by'), + '$showonmap' => L10n::t('Show on map') + ]); + } else { + $t = get_markup_template('widget-error.tpl', 'addon/curweather/'); + $curweather = replace_macros( $t, [ + '$problem' => L10n::t('There was a problem accessing the weather data. But have a look'), + '$rpt' => $rpt, + '$atOWM' => L10n::t('at OpenWeatherMap') + ]); + } - $fk_app->page['aside'] = $curweather.$fk_app->page['aside']; + $fk_app->page['aside'] = $curweather.$fk_app->page['aside']; } function curweather_addon_settings_post($a,$post) { - if(! local_user() || (! x($_POST,'curweather-settings-submit'))) - return; - PConfig::set(local_user(),'curweather','curweather_loc',trim($_POST['curweather_loc'])); - PConfig::set(local_user(),'curweather','curweather_enable',intval($_POST['curweather_enable'])); - PConfig::set(local_user(),'curweather','curweather_units',trim($_POST['curweather_units'])); - - info(L10n::t('Current Weather settings updated.') . EOL); + if(! local_user() || (! x($_POST,'curweather-settings-submit'))) + return; + PConfig::set(local_user(),'curweather','curweather_loc',trim($_POST['curweather_loc'])); + PConfig::set(local_user(),'curweather','curweather_enable',intval($_POST['curweather_enable'])); + PConfig::set(local_user(),'curweather','curweather_units',trim($_POST['curweather_units'])); + + info(L10n::t('Current Weather settings updated.') . EOL); } function curweather_addon_settings(&$a,&$s) { - if(! local_user()) - return; - - /* Get the current state of our config variable */ - - $curweather_loc = PConfig::get(local_user(), 'curweather', 'curweather_loc'); - $curweather_units = PConfig::get(local_user(), 'curweather', 'curweather_units'); - $appid = Config::get('curweather','appid'); - if ($appid=="") { - $noappidtext = L10n::t('No APPID found, please contact your admin to obtain one.'); - } else { - $noappidtext = ''; - } - $enable = intval(PConfig::get(local_user(),'curweather','curweather_enable')); - $enable_checked = (($enable) ? ' checked="checked" ' : ''); - - // load template and replace the macros - $t = get_markup_template("settings.tpl", "addon/curweather/" ); - $s = replace_macros ($t, [ - '$submit' => L10n::t('Save Settings'), - '$header' => L10n::t('Current Weather').' '.L10n::t('Settings'), - '$noappidtext' => $noappidtext, - '$info' => L10n::t('Enter either the name of your location or the zip code.'), - '$curweather_loc' => [ 'curweather_loc', L10n::t('Your Location'), $curweather_loc, L10n::t('Identifier of your location (name or zip code), e.g. Berlin,DE or 14476,DE.') ], - '$curweather_units' => [ 'curweather_units', L10n::t('Units'), $curweather_units, L10n::t('select if the temperature should be displayed in °C or °F'), ['metric'=>'°C', 'imperial'=>'°F']], - '$enabled' => [ 'curweather_enable', L10n::t('Show weather data'), $enable, ''] - ]); - return; + if(! local_user()) + return; + + /* Get the current state of our config variable */ + + $curweather_loc = PConfig::get(local_user(), 'curweather', 'curweather_loc'); + $curweather_units = PConfig::get(local_user(), 'curweather', 'curweather_units'); + $appid = Config::get('curweather','appid'); + if ($appid=="") { + $noappidtext = L10n::t('No APPID found, please contact your admin to obtain one.'); + } else { + $noappidtext = ''; + } + $enable = intval(PConfig::get(local_user(),'curweather','curweather_enable')); + $enable_checked = (($enable) ? ' checked="checked" ' : ''); + + // load template and replace the macros + $t = get_markup_template("settings.tpl", "addon/curweather/" ); + $s = replace_macros ($t, [ + '$submit' => L10n::t('Save Settings'), + '$header' => L10n::t('Current Weather').' '.L10n::t('Settings'), + '$noappidtext' => $noappidtext, + '$info' => L10n::t('Enter either the name of your location or the zip code.'), + '$curweather_loc' => [ 'curweather_loc', L10n::t('Your Location'), $curweather_loc, L10n::t('Identifier of your location (name or zip code), e.g. Berlin,DE or 14476,DE.') ], + '$curweather_units' => [ 'curweather_units', L10n::t('Units'), $curweather_units, L10n::t('select if the temperature should be displayed in °C or °F'), ['metric'=>'°C', 'imperial'=>'°F']], + '$enabled' => [ 'curweather_enable', L10n::t('Show weather data'), $enable, ''] + ]); + return; } // Config stuff for the admin panel to let the admin of the node set a APPID // for accessing the API of openweathermap function curweather_addon_admin_post (&$a) { - if(! is_site_admin()) - return; - if ($_POST['curweather-submit']) { - Config::set('curweather','appid',trim($_POST['appid'])); - Config::set('curweather','cachetime',trim($_POST['cachetime'])); - info(L10n::t('Curweather settings saved.'.EOL)); - } + if(! is_site_admin()) + return; + if ($_POST['curweather-submit']) { + Config::set('curweather','appid',trim($_POST['appid'])); + Config::set('curweather','cachetime',trim($_POST['cachetime'])); + info(L10n::t('Curweather settings saved.'.EOL)); + } } function curweather_addon_admin (&$a, &$o) { - if(! is_site_admin()) - return; - $appid = Config::get('curweather','appid'); - $cachetime = Config::get('curweather','cachetime'); - $t = get_markup_template("admin.tpl", "addon/curweather/" ); - $o = replace_macros ($t, [ - '$submit' => L10n::t('Save Settings'), - '$cachetime' => [ - 'cachetime', - L10n::t('Caching Interval'), - $cachetime, - L10n::t('For how long should the weather data be cached? Choose according your OpenWeatherMap account type.'), [ - '0'=>L10n::t('no cache'), - '300'=>'5 '.L10n::t('minutes'), - '900'=>'15 '.L10n::t('minutes'), - '1800'=>'30 '.L10n::t('minutes'), - '3600'=>'60 '.L10n::t('minutes') - ] - ], - '$appid' => ['appid', L10n::t('Your APPID'), $appid, L10n::t('Your API key provided by OpenWeatherMap')] - ]); + if(! is_site_admin()) + return; + $appid = Config::get('curweather','appid'); + $cachetime = Config::get('curweather','cachetime'); + $t = get_markup_template("admin.tpl", "addon/curweather/" ); + $o = replace_macros ($t, [ + '$submit' => L10n::t('Save Settings'), + '$cachetime' => [ + 'cachetime', + L10n::t('Caching Interval'), + $cachetime, + L10n::t('For how long should the weather data be cached? Choose according your OpenWeatherMap account type.'), [ + '0'=>L10n::t('no cache'), + '300'=>'5 '.L10n::t('minutes'), + '900'=>'15 '.L10n::t('minutes'), + '1800'=>'30 '.L10n::t('minutes'), + '3600'=>'60 '.L10n::t('minutes') + ] + ], + '$appid' => ['appid', L10n::t('Your APPID'), $appid, L10n::t('Your API key provided by OpenWeatherMap')] + ]); } diff --git a/curweather/templates/widget.tpl b/curweather/templates/widget.tpl index 0847ec08..925ebaa7 100644 --- a/curweather/templates/widget.tpl +++ b/curweather/templates/widget.tpl @@ -1,17 +1,24 @@
-
+

{{$title}}: {{$city}}

-

+

+
+
    -
  • {{$temp}}
  • -
  • {{$relhumidity['caption']}}: {{$relhumidity['val']}}
  • -
  • {{$pressure['caption']}}: {{$pressure['val']}}
  • -
  • {{$wind['caption']}}: {{$wind['val']}}
  • -

- +
  • {{$temp}}
  • +
  • {{$relhumidity['caption']}}: {{$relhumidity['val']}}
  • +
  • {{$pressure['caption']}}: {{$pressure['val']}}
  • +
  • {{$wind['caption']}}: {{$wind['val']}}
  • + +
    +
    + +
    From c4c2514f3b9f511aaf0e90632a26c4f30bf820cc Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 23 Jul 2018 18:46:16 -0400 Subject: [PATCH 07/10] [widgets] Add missing use statement after dbesc conversion --- widgets/widget_like.php | 1 + 1 file changed, 1 insertion(+) diff --git a/widgets/widget_like.php b/widgets/widget_like.php index 2e387954..deb4d261 100644 --- a/widgets/widget_like.php +++ b/widgets/widget_like.php @@ -1,6 +1,7 @@ Date: Tue, 24 Jul 2018 00:54:14 +0200 Subject: [PATCH 08/10] [mailstream]: Fixed logger level NORMAL -> INFO (#664) --- mailstream/mailstream.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index 8b3c6ede..7aad5861 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -123,7 +123,7 @@ function mailstream_post_hook(&$a, &$item) { intval($item['contact-id']), DBA::escape($item['uri']), DBA::escape($message_id)); $r = q('SELECT * FROM `mailstream_item` WHERE `uid` = %d AND `contact-id` = %d AND `uri` = "%s"', intval($item['uid']), intval($item['contact-id']), DBA::escape($item['uri'])); if (count($r) != 1) { - logger('mailstream_post_remote_hook: Unexpected number of items returned from mailstream_item', LOGGER_NORMAL); + logger('mailstream_post_remote_hook: Unexpected number of items returned from mailstream_item', LOGGER_INFO); return; } $ms_item = $r[0]; @@ -132,7 +132,7 @@ function mailstream_post_hook(&$a, &$item) { . $item['uid'] . ' ' . $item['contact-id'], LOGGER_DATA); $user = mailstream_get_user($item['uid']); if (!$user) { - logger('mailstream_post_remote_hook: no user ' . $item['uid'], LOGGER_NORMAL); + logger('mailstream_post_remote_hook: no user ' . $item['uid'], LOGGER_INFO); return; } mailstream_send($a, $ms_item['message-id'], $item, $user); @@ -141,7 +141,7 @@ function mailstream_post_hook(&$a, &$item) { function mailstream_get_user($uid) { $r = q('SELECT * FROM `user` WHERE `uid` = %d', intval($uid)); if (count($r) != 1) { - logger('mailstream_post_remote_hook: Unexpected number of users returned', LOGGER_NORMAL); + logger('mailstream_post_remote_hook: Unexpected number of users returned', LOGGER_INFO); return; } return $r[0]; @@ -300,9 +300,9 @@ function mailstream_send($a, $message_id, $item, $user) { } logger('mailstream_send sent message ' . $mail->MessageID . ' ' . $mail->Subject, LOGGER_DEBUG); } catch (phpmailerException $e) { - logger('mailstream_send PHPMailer exception sending message ' . $message_id . ': ' . $e->errorMessage(), LOGGER_NORMAL); + logger('mailstream_send PHPMailer exception sending message ' . $message_id . ': ' . $e->errorMessage(), LOGGER_INFO); } catch (Exception $e) { - logger('mailstream_send exception sending message ' . $message_id . ': ' . $e->getMessage(), LOGGER_NORMAL); + logger('mailstream_send exception sending message ' . $message_id . ': ' . $e->getMessage(), LOGGER_INFO); } // In case of failure, still set the item to completed. Otherwise // we'll just try to send it over and over again and it'll fail @@ -334,7 +334,7 @@ function mailstream_cron($a, $b) { logger('mailstream_cron processing ' . count($ms_item_ids) . ' items', LOGGER_DEBUG); foreach ($ms_item_ids as $ms_item_id) { if (!$ms_item_id['message-id'] || !strlen($ms_item_id['message-id'])) { - logger('mailstream_cron: Item ' . $ms_item_id['id'] . ' URI ' . $ms_item_id['uri'] . ' has no message-id', LOGGER_NORMAL); + logger('mailstream_cron: Item ' . $ms_item_id['id'] . ' URI ' . $ms_item_id['uri'] . ' has no message-id', LOGGER_INFO); } $item = Item::selectFirst([], ['id' => $ms_item_id['id']]); $users = q("SELECT * FROM `user` WHERE `uid` = %d", intval($item['uid'])); @@ -343,7 +343,7 @@ function mailstream_cron($a, $b) { mailstream_send($a, $ms_item_id['message-id'], $item, $user); } else { - logger('mailstream_cron: Unable to find item ' . $ms_item_id['id'], LOGGER_NORMAL); + logger('mailstream_cron: Unable to find item ' . $ms_item_id['id'], LOGGER_INFO); q("UPDATE `mailstream_item` SET `completed` = now() WHERE `message-id` = %d", intval($ms_item['message-id'])); } } From 280e835481506a47bf50f3c153ca70e8d2f3ad24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 24 Jul 2018 01:04:06 +0200 Subject: [PATCH 09/10] [diaspora] Cleanups and type-hinting (#665) * [diaspora] Fixes/cleanups: - added curly braces/spaces for better readability - don't use count() when you can use DBM::is_result() - used proper type-hints `App` and `array` - "imported" Friendica\App * [diaspora]: Fixed parser error, ops * [diaspora]: - DBA::isResult() is now the new name (MrPetovan) - added spaces for nice indending and better readability - changed 4-spaces to tab --- diaspora/diaspora.php | 134 +++++++++++++++++++++++------------------- 1 file changed, 75 insertions(+), 59 deletions(-) diff --git a/diaspora/diaspora.php b/diaspora/diaspora.php index 490cd4d8..18df37bb 100644 --- a/diaspora/diaspora.php +++ b/diaspora/diaspora.php @@ -9,6 +9,7 @@ require_once 'addon/diaspora/Diaspora_Connection.php'; +use Friendica\App; use Friendica\Content\Text\BBCode; use Friendica\Core\Addon; use Friendica\Core\L10n; @@ -16,49 +17,59 @@ use Friendica\Core\PConfig; use Friendica\Database\DBA; use Friendica\Model\Queue; -function diaspora_install() { - Addon::registerHook('post_local', 'addon/diaspora/diaspora.php', 'diaspora_post_local'); - Addon::registerHook('notifier_normal', 'addon/diaspora/diaspora.php', 'diaspora_send'); - Addon::registerHook('jot_networks', 'addon/diaspora/diaspora.php', 'diaspora_jot_nets'); +function diaspora_install() +{ + Addon::registerHook('post_local', 'addon/diaspora/diaspora.php', 'diaspora_post_local'); + Addon::registerHook('notifier_normal', 'addon/diaspora/diaspora.php', 'diaspora_send'); + Addon::registerHook('jot_networks', 'addon/diaspora/diaspora.php', 'diaspora_jot_nets'); Addon::registerHook('connector_settings', 'addon/diaspora/diaspora.php', 'diaspora_settings'); Addon::registerHook('connector_settings_post', 'addon/diaspora/diaspora.php', 'diaspora_settings_post'); - Addon::registerHook('queue_predeliver', 'addon/diaspora/diaspora.php', 'diaspora_queue_hook'); + Addon::registerHook('queue_predeliver', 'addon/diaspora/diaspora.php', 'diaspora_queue_hook'); } -function diaspora_uninstall() { - Addon::unregisterHook('post_local', 'addon/diaspora/diaspora.php', 'diaspora_post_local'); - Addon::unregisterHook('notifier_normal', 'addon/diaspora/diaspora.php', 'diaspora_send'); - Addon::unregisterHook('jot_networks', 'addon/diaspora/diaspora.php', 'diaspora_jot_nets'); + +function diaspora_uninstall() +{ + Addon::unregisterHook('post_local', 'addon/diaspora/diaspora.php', 'diaspora_post_local'); + Addon::unregisterHook('notifier_normal', 'addon/diaspora/diaspora.php', 'diaspora_send'); + Addon::unregisterHook('jot_networks', 'addon/diaspora/diaspora.php', 'diaspora_jot_nets'); Addon::unregisterHook('connector_settings', 'addon/diaspora/diaspora.php', 'diaspora_settings'); Addon::unregisterHook('connector_settings_post', 'addon/diaspora/diaspora.php', 'diaspora_settings_post'); - Addon::unregisterHook('queue_predeliver', 'addon/diaspora/diaspora.php', 'diaspora_queue_hook'); + Addon::unregisterHook('queue_predeliver', 'addon/diaspora/diaspora.php', 'diaspora_queue_hook'); } +function diaspora_jot_nets(App $a, &$b) +{ + if (!local_user()) { + return; + } -function diaspora_jot_nets(&$a,&$b) { - if(! local_user()) - return; + $diaspora_post = PConfig::get(local_user(), 'diaspora', 'post'); - $diaspora_post = PConfig::get(local_user(),'diaspora','post'); - if(intval($diaspora_post) == 1) { - $diaspora_defpost = PConfig::get(local_user(),'diaspora','post_by_default'); - $selected = ((intval($diaspora_defpost) == 1) ? ' checked="checked" ' : ''); - $b .= '
    ' - . L10n::t('Post to Diaspora') . '
    '; - } + if (intval($diaspora_post) == 1) { + $diaspora_defpost = PConfig::get(local_user(), 'diaspora', 'post_by_default'); + + $selected = ((intval($diaspora_defpost) == 1) ? ' checked="checked" ' : ''); + + $b .= '
    ' + . L10n::t('Post to Diaspora') . '
    '; + } } -function diaspora_queue_hook(&$a,&$b) { +function diaspora_queue_hook(App $a, &$b) { $hostname = $a->get_hostname(); $qi = q("SELECT * FROM `queue` WHERE `network` = '%s'", DBA::escape(NETWORK_DIASPORA2) ); - if(! count($qi)) - return; - foreach($qi as $x) { - if($x['network'] !== NETWORK_DIASPORA2) + if (!DBA:isResult($qi)) { + return; + } + + foreach ($qi as $x) { + if ($x['network'] !== NETWORK_DIASPORA2) { continue; + } logger('diaspora_queue: run'); @@ -66,19 +77,21 @@ function diaspora_queue_hook(&$a,&$b) { WHERE `contact`.`self` = 1 AND `contact`.`id` = %d LIMIT 1", intval($x['cid']) ); - if(! count($r)) + + if (!DBA:isResult($r)) { continue; + } $userdata = $r[0]; - $handle = PConfig::get($userdata['uid'],'diaspora','handle'); - $password = PConfig::get($userdata['uid'],'diaspora','password'); - $aspect = PConfig::get($userdata['uid'],'diaspora','aspect'); + $handle = PConfig::get($userdata['uid'], 'diaspora', 'handle'); + $password = PConfig::get($userdata['uid'], 'diaspora', 'password'); + $aspect = PConfig::get($userdata['uid'], 'diaspora', 'aspect'); $success = false; if ($handle && $password) { - logger('diaspora_queue: able to post for user '.$handle); + logger('diaspora_queue: able to post for user '.$handle); $z = unserialize($x['content']); @@ -114,10 +127,11 @@ function diaspora_queue_hook(&$a,&$b) { } } -function diaspora_settings(&$a,&$s) { - - if(! local_user()) +function diaspora_settings(App $a, &$s) +{ + if (! local_user()) { return; + } /* Add our stylesheet to the page so we can make our settings look nice */ @@ -140,6 +154,7 @@ function diaspora_settings(&$a,&$s) { $status = ""; $r = q("SELECT `addr` FROM `contact` WHERE `self` AND `uid` = %d", intval(local_user())); + if (DBA::isResult($r)) { $status = L10n::t("Please remember: You can always be reached from Diaspora with your Friendica handle %s. ", $r[0]['addr']); $status .= L10n::t('This connector is only meant if you still want to use your old Diaspora account for some time. '); @@ -152,6 +167,7 @@ function diaspora_settings(&$a,&$s) { $conn = new Diaspora_Connection($handle, $password); $conn->logIn(); $aspects = $conn->getAspects(); + if (!$aspects) { $status = L10n::t("Can't login to your Diaspora account. Please check handle (in the format user@domain.tld) and password."); } @@ -224,21 +240,19 @@ function diaspora_settings(&$a,&$s) { } -function diaspora_settings_post(&$a,&$b) { - - if(x($_POST,'diaspora-submit')) { - - PConfig::set(local_user(),'diaspora','post',intval($_POST['diaspora'])); - PConfig::set(local_user(),'diaspora','post_by_default',intval($_POST['diaspora_bydefault'])); - PConfig::set(local_user(),'diaspora','handle',trim($_POST['handle'])); - PConfig::set(local_user(),'diaspora','password',trim($_POST['password'])); - PConfig::set(local_user(),'diaspora','aspect',trim($_POST['aspect'])); +function diaspora_settings_post(App $a, &$b) +{ + if (!empty($_POST['diaspora-submit'])) { + PConfig::set(local_user(),'diaspora', 'post' , intval($_POST['diaspora'])); + PConfig::set(local_user(),'diaspora', 'post_by_default', intval($_POST['diaspora_bydefault'])); + PConfig::set(local_user(),'diaspora', 'handle' , trim($_POST['handle'])); + PConfig::set(local_user(),'diaspora', 'password' , trim($_POST['password'])); + PConfig::set(local_user(),'diaspora', 'aspect' , trim($_POST['aspect'])); } - } -function diaspora_post_local(&$a,&$b) { - +function diaspora_post_local(App $a, array &$b) +{ if ($b['edit']) { return; } @@ -270,29 +284,28 @@ function diaspora_post_local(&$a,&$b) { $b['postopts'] .= 'diaspora'; } - - - -function diaspora_send(&$a,&$b) { +function diaspora_send(App $a, array &$b) +{ $hostname = $a->get_hostname(); logger('diaspora_send: invoked'); - if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) { + if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) { return; } - if(! strstr($b['postopts'],'diaspora')) { + if (!strstr($b['postopts'],'diaspora')) { return; } - if($b['parent'] != $b['id']) { + if ($b['parent'] != $b['id']) { return; } // Dont't post if the post doesn't belong to us. // This is a check for forum postings $self = DBA::selectFirst('contact', ['id'], ['uid' => $b['uid'], 'self' => true]); + if ($b['contact-id'] != $self['id']) { return; } @@ -310,13 +323,15 @@ function diaspora_send(&$a,&$b) { $tags = ''; $x = preg_match_all('/\#\[(.*?)\](.*?)\[/',$b['tag'],$matches,PREG_SET_ORDER); - if($x) { - foreach($matches as $mtch) { + if ($x) { + foreach ($matches as $mtch) { $tag_arr[] = $mtch[2]; } } - if(count($tag_arr)) + + if (count($tag_arr)) { $tags = implode(',',$tag_arr); + } $title = $b['title']; $body = $b['body']; @@ -333,17 +348,18 @@ function diaspora_send(&$a,&$b) { // remove multiple newlines do { $oldbody = $body; - $body = str_replace("\n\n\n", "\n\n", $body); - } while ($oldbody != $body); + $body = str_replace("\n\n\n", "\n\n", $body); + } while ($oldbody != $body); // convert to markdown $body = BBCode::toMarkdown($body); // Adding the title - if(strlen($title)) + if (strlen($title)) { $body = "## ".html_entity_decode($title)."\n\n".$body; + } - require_once("addon/diaspora/diasphp.php"); + require_once "addon/diaspora/diasphp.php"; try { logger('diaspora_send: prepare', LOGGER_DEBUG); From 95a98faeecb51df8805bf90d5c3fc032c6ac527f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 24 Jul 2018 01:31:44 +0200 Subject: [PATCH 10/10] [diaspora]: Ops, fixed parser error. Followup to #665 (#666) --- diaspora/diaspora.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diaspora/diaspora.php b/diaspora/diaspora.php index 18df37bb..338e0fa5 100644 --- a/diaspora/diaspora.php +++ b/diaspora/diaspora.php @@ -62,7 +62,7 @@ function diaspora_queue_hook(App $a, &$b) { DBA::escape(NETWORK_DIASPORA2) ); - if (!DBA:isResult($qi)) { + if (!DBA::isResult($qi)) { return; } @@ -78,7 +78,7 @@ function diaspora_queue_hook(App $a, &$b) { intval($x['cid']) ); - if (!DBA:isResult($r)) { + if (!DBA::isResult($r)) { continue; }