Replacing "q" calls with "DBA" calls

This commit is contained in:
Michael 2021-10-03 17:35:20 +00:00
parent 9682cc7dda
commit 428c6876f0
9 changed files with 259 additions and 353 deletions

View file

@ -72,7 +72,7 @@ function statusnet_install()
Hook::register('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron');
Hook::register('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body');
Hook::register('check_item_notification', 'addon/statusnet/statusnet.php', 'statusnet_check_item_notification');
Logger::log("installed GNU Social");
Logger::notice("installed GNU Social");
}
function statusnet_check_item_notification(App $a, &$notification_data)
@ -407,7 +407,7 @@ function statusnet_hook_fork(App $a, array &$b)
if (DI::pConfig()->get($post['uid'], 'statusnet', 'import')) {
// Don't fork if it isn't a reply to a GNU Social post
if (($post['parent'] != $post['id']) && !Post::exists(['id' => $post['parent'], 'network' => Protocol::STATUSNET])) {
Logger::log('No GNU Social parent found for item ' . $post['id']);
Logger::notice('No GNU Social parent found for item ' . $post['id']);
$b['execute'] = false;
return;
}
@ -459,7 +459,7 @@ function statusnet_action(App $a, $uid, $pid, $action)
$connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret);
Logger::log("statusnet_action '" . $action . "' ID: " . $pid, Logger::DATA);
Logger::debug("statusnet_action '" . $action . "' ID: " . $pid);
switch ($action) {
case "delete":
@ -472,7 +472,7 @@ function statusnet_action(App $a, $uid, $pid, $action)
$result = $connection->post("favorites/destroy/" . $pid);
break;
}
Logger::log("statusnet_action '" . $action . "' send, result: " . print_r($result, true), Logger::DEBUG);
Logger::info("statusnet_action '" . $action . "' send, result: " . print_r($result, true));
}
function statusnet_post_hook(App $a, &$b)
@ -491,19 +491,19 @@ function statusnet_post_hook(App $a, &$b)
$hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $api);
if ($b['parent'] != $b['id']) {
Logger::log("statusnet_post_hook: parameter " . print_r($b, true), Logger::DATA);
Logger::debug("statusnet_post_hook: parameter " . print_r($b, true));
// Looking if its a reply to a GNU Social post
$hostlength = strlen($hostname) + 2;
if ((substr($b["parent-uri"], 0, $hostlength) != $hostname . "::") && (substr($b["extid"], 0, $hostlength) != $hostname . "::") && (substr($b["thr-parent"], 0, $hostlength) != $hostname . "::")) {
Logger::log("statusnet_post_hook: no GNU Social post " . $b["parent"]);
Logger::notice("statusnet_post_hook: no GNU Social post " . $b["parent"]);
return;
}
$condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]];
$orig_post = Post::selectFirst(['author-link', 'uri'], $condition);
if (!DBA::isResult($orig_post)) {
Logger::log("statusnet_post_hook: no parent found " . $b["thr-parent"]);
Logger::notice("statusnet_post_hook: no parent found " . $b["thr-parent"]);
return;
} else {
$iscomment = true;
@ -514,12 +514,12 @@ function statusnet_post_hook(App $a, &$b)
$nickname = "@[url=" . $orig_post["author-link"] . "]" . $nick . "[/url]";
$nicknameplain = "@" . $nick;
Logger::log("statusnet_post_hook: comparing " . $nickname . " and " . $nicknameplain . " with " . $b["body"], Logger::DEBUG);
Logger::info("statusnet_post_hook: comparing " . $nickname . " and " . $nicknameplain . " with " . $b["body"]);
if ((strpos($b["body"], $nickname) === false) && (strpos($b["body"], $nicknameplain) === false)) {
$b["body"] = $nickname . " " . $b["body"];
}
Logger::log("statusnet_post_hook: parent found " . print_r($orig_post, true), Logger::DEBUG);
Logger::info("statusnet_post_hook: parent found " . print_r($orig_post, true));
} else {
$iscomment = false;
@ -540,7 +540,7 @@ function statusnet_post_hook(App $a, &$b)
}
if ($b['verb'] == Activity::LIKE) {
Logger::log("statusnet_post_hook: parameter 2 " . substr($b["thr-parent"], $hostlength), Logger::DEBUG);
Logger::info("statusnet_post_hook: parameter 2 " . substr($b["thr-parent"], $hostlength));
if ($b['deleted'])
statusnet_action($a, $b["uid"], substr($b["thr-parent"], $hostlength), "unlike");
else
@ -561,7 +561,7 @@ function statusnet_post_hook(App $a, &$b)
return;
}
Logger::log('GNU Socialpost invoked');
Logger::notice('GNU Socialpost invoked');
DI::pConfig()->load($b['uid'], 'statusnet');
@ -610,7 +610,7 @@ function statusnet_post_hook(App $a, &$b)
if (strlen($msg)) {
if ($iscomment) {
$postdata["in_reply_to_status_id"] = substr($orig_post["uri"], $hostlength);
Logger::log('statusnet_post send reply ' . print_r($postdata, true), Logger::DEBUG);
Logger::info('statusnet_post send reply ' . print_r($postdata, true));
}
// New code that is able to post pictures
@ -621,17 +621,17 @@ function statusnet_post_hook(App $a, &$b)
$cb->setToken($otoken, $osecret);
$result = $cb->statuses_update($postdata);
//$result = $dent->post('statuses/update', $postdata);
Logger::log('statusnet_post send, result: ' . print_r($result, true) .
"\nmessage: " . $msg . "\nOriginal post: " . print_r($b, true) . "\nPost Data: " . print_r($postdata, true), Logger::DEBUG);
Logger::info('statusnet_post send, result: ' . print_r($result, true) .
"\nmessage: " . $msg . "\nOriginal post: " . print_r($b, true) . "\nPost Data: " . print_r($postdata, true));
if (!empty($result->source)) {
DI::pConfig()->set($b["uid"], "statusnet", "application_name", strip_tags($result->source));
}
if (!empty($result->error)) {
Logger::log('Send to GNU Social failed: "' . $result->error . '"');
Logger::notice('Send to GNU Social failed: "' . $result->error . '"');
} elseif ($iscomment) {
Logger::log('statusnet_post: Update extid ' . $result->id . " for post id " . $b['id']);
Logger::notice('statusnet_post: Update extid ' . $result->id . " for post id " . $b['id']);
Item::update(['extid' => $hostname . "::" . $result->id, 'body' => $result->text], ['id' => $b['id']]);
}
}
@ -761,16 +761,16 @@ function statusnet_cron(App $a, $b)
if ($last) {
$next = $last + ($poll_interval * 60);
if ($next > time()) {
Logger::log('statusnet: poll intervall not reached');
Logger::notice('statusnet: poll intervall not reached');
return;
}
}
Logger::log('statusnet: cron_start');
Logger::notice('statusnet: cron_start');
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'mirror_posts' AND `v` = '1' ORDER BY RAND() ");
if (DBA::isResult($r)) {
foreach ($r as $rr) {
Logger::log('statusnet: fetching for user ' . $rr['uid']);
Logger::notice('statusnet: fetching for user ' . $rr['uid']);
statusnet_fetchtimeline($a, $rr['uid']);
}
}
@ -788,17 +788,17 @@ function statusnet_cron(App $a, $b)
if ($abandon_days != 0) {
$user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit);
if (!DBA::isResult($user)) {
Logger::log('abandoned account: timeline from user ' . $rr['uid'] . ' will not be imported');
Logger::notice('abandoned account: timeline from user ' . $rr['uid'] . ' will not be imported');
continue;
}
}
Logger::log('statusnet: importing timeline from user ' . $rr['uid']);
Logger::notice('statusnet: importing timeline from user ' . $rr['uid']);
statusnet_fetchhometimeline($a, $rr["uid"], $rr["v"]);
}
}
Logger::log('statusnet: cron_end');
Logger::notice('statusnet: cron_end');
DI::config()->set('statusnet', 'last_poll', time());
}
@ -901,7 +901,7 @@ function statusnet_fetchtimeline(App $a, $uid)
//print_r($_REQUEST);
if ($_REQUEST["body"] != "") {
Logger::log('statusnet: posting for user ' . $uid);
Logger::notice('statusnet: posting for user ' . $uid);
item_post($a);
}
@ -936,7 +936,7 @@ function statusnet_fetch_contact($uid, $contact, $create_user)
}
if (DBA::isResult($r) && ($r[0]["readonly"] || $r[0]["blocked"])) {
Logger::log("statusnet_fetch_contact: Contact '" . $r[0]["nick"] . "' is blocked or readonly.", Logger::DEBUG);
Logger::info("statusnet_fetch_contact: Contact '" . $r[0]["nick"] . "' is blocked or readonly.");
return -1;
}
@ -998,7 +998,7 @@ function statusnet_fetch_contact($uid, $contact, $create_user)
// check that we have all the photos, this has been known to fail on occasion
if ((!$r[0]['photo']) || (!$r[0]['thumb']) || (!$r[0]['micro']) || ($update_photo)) {
Logger::log("statusnet_fetch_contact: Updating contact " . $contact->screen_name, Logger::DEBUG);
Logger::info("statusnet_fetch_contact: Updating contact " . $contact->screen_name);
$photos = Photo::importProfilePhoto($contact->profile_image_url, $uid, $r[0]['id']);
@ -1084,7 +1084,7 @@ function statusnet_fetchuser(App $a, $uid, $screen_name = "", $user_id = "")
function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_existing_contact)
{
Logger::log("statusnet_createpost: start", Logger::DEBUG);
Logger::info("statusnet_createpost: start");
$api = DI::pConfig()->get($uid, 'statusnet', 'baseapi');
$hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $api);
@ -1201,7 +1201,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex
$postarray["coord"] = $content->coordinates->coordinates[1] . " " . $content->coordinates->coordinates[0];
}
Logger::log("statusnet_createpost: end", Logger::DEBUG);
Logger::info("statusnet_createpost: end");
return $postarray;
}
@ -1220,7 +1220,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1)
// "create_user" is deactivated, since currently you cannot add users manually by now
$create_user = true;
Logger::log("statusnet_fetchhometimeline: Fetching for user " . $uid, Logger::DEBUG);
Logger::info("statusnet_fetchhometimeline: Fetching for user " . $uid);
$connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret);
@ -1237,7 +1237,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1)
if (DBA::isResult($r)) {
$nick = $r[0]["nick"];
} else {
Logger::log("statusnet_fetchhometimeline: Own GNU Social contact not found for user " . $uid, Logger::DEBUG);
Logger::info("statusnet_fetchhometimeline: Own GNU Social contact not found for user " . $uid);
return;
}
@ -1247,14 +1247,14 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1)
if (DBA::isResult($r)) {
$self = $r[0];
} else {
Logger::log("statusnet_fetchhometimeline: Own contact not found for user " . $uid, Logger::DEBUG);
Logger::info("statusnet_fetchhometimeline: Own contact not found for user " . $uid);
return;
}
$u = q("SELECT * FROM user WHERE uid = %d LIMIT 1",
intval($uid));
if (!DBA::isResult($u)) {
Logger::log("statusnet_fetchhometimeline: Own user not found for user " . $uid, Logger::DEBUG);
Logger::info("statusnet_fetchhometimeline: Own user not found for user " . $uid);
return;
}
@ -1285,13 +1285,13 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1)
$errormsg = "Unknown error";
}
Logger::log("statusnet_fetchhometimeline: Error fetching home timeline: " . $errormsg, Logger::DEBUG);
Logger::info("statusnet_fetchhometimeline: Error fetching home timeline: " . $errormsg);
return;
}
$posts = array_reverse($items);
Logger::log("statusnet_fetchhometimeline: Fetching timeline for user " . $uid . " " . sizeof($posts) . " items", Logger::DEBUG);
Logger::info("statusnet_fetchhometimeline: Fetching timeline for user " . $uid . " " . sizeof($posts) . " items");
if (count($posts)) {
foreach ($posts as $post) {
@ -1319,7 +1319,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1)
$item = Item::insert($postarray);
$postarray["id"] = $item;
Logger::log('statusnet_fetchhometimeline: User ' . $self["nick"] . ' posted home timeline item ' . $item);
Logger::notice('statusnet_fetchhometimeline: User ' . $self["nick"] . ' posted home timeline item ' . $item);
}
}
}
@ -1337,13 +1337,13 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1)
$items = $connection->get('statuses/mentions_timeline', $parameters);
if (!is_array($items)) {
Logger::log("statusnet_fetchhometimeline: Error fetching mentions: " . print_r($items, true), Logger::DEBUG);
Logger::info("statusnet_fetchhometimeline: Error fetching mentions: " . print_r($items, true));
return;
}
$posts = array_reverse($items);
Logger::log("statusnet_fetchhometimeline: Fetching mentions for user " . $uid . " " . sizeof($posts) . " items", Logger::DEBUG);
Logger::info("statusnet_fetchhometimeline: Fetching mentions for user " . $uid . " " . sizeof($posts) . " items");
if (count($posts)) {
foreach ($posts as $post) {
@ -1369,7 +1369,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1)
$item = Item::insert($postarray);
Logger::log('statusnet_fetchhometimeline: User ' . $self["nick"] . ' posted mention timeline item ' . $item);
Logger::notice('statusnet_fetchhometimeline: User ' . $self["nick"] . ' posted mention timeline item ' . $item);
}
}
}
@ -1404,7 +1404,7 @@ function statusnet_complete_conversation(App $a, $uid, $self, $create_user, $nic
$item = Item::insert($postarray);
$postarray["id"] = $item;
Logger::log('statusnet_complete_conversation: User ' . $self["nick"] . ' posted home timeline item ' . $item);
Logger::notice('statusnet_complete_conversation: User ' . $self["nick"] . ' posted home timeline item ' . $item);
}
}
}
@ -1425,7 +1425,7 @@ function statusnet_convertmsg(App $a, $body)
foreach ($matches AS $match) {
$search = "[url=" . $match[1] . "]" . $match[2] . "[/url]";
Logger::log("statusnet_convertmsg: expanding url " . $match[1], Logger::DEBUG);
Logger::info("statusnet_convertmsg: expanding url " . $match[1]);
try {
$expanded_url = DI::httpClient()->finalUrl($match[1]);
@ -1434,11 +1434,11 @@ function statusnet_convertmsg(App $a, $body)
$expanded_url = $match[1];
}
Logger::log("statusnet_convertmsg: fetching data for " . $expanded_url, Logger::DEBUG);
Logger::info("statusnet_convertmsg: fetching data for " . $expanded_url);
$oembed_data = OEmbed::fetchURL($expanded_url, true);
Logger::log("statusnet_convertmsg: fetching data: done", Logger::DEBUG);
Logger::info("statusnet_convertmsg: fetching data: done");
if ($type == "") {
$type = $oembed_data->type;
@ -1575,13 +1575,13 @@ function statusnet_is_retweet(App $a, $uid, $body)
return false;
}
Logger::log('statusnet_is_retweet: Retweeting id ' . $id . ' for user ' . $uid, Logger::DEBUG);
Logger::info('statusnet_is_retweet: Retweeting id ' . $id . ' for user ' . $uid);
$connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret);
$result = $connection->post('statuses/retweet/' . $id);
Logger::log('statusnet_is_retweet: result ' . print_r($result, true), Logger::DEBUG);
Logger::info('statusnet_is_retweet: result ' . print_r($result, true));
return isset($result->id);
}