Merge pull request #1180 from annando/more-q

Replacing "q" calls with "DBA" calls
This commit is contained in:
Hypolite Petovan 2021-10-03 19:03:49 -04:00 committed by GitHub
commit a5e15acee9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 292 additions and 392 deletions

View file

@ -16,6 +16,7 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\User;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\XML; use Friendica\Util\XML;
@ -167,15 +168,9 @@ function dwpost_send(App $a, array &$b)
* Hopefully the person's Friendica account * Hopefully the person's Friendica account
* will be set to the same thing. * will be set to the same thing.
*/ */
$tz = 'UTC';
$x = q("SELECT `timezone` FROM `user` WHERE `uid` = %d LIMIT 1", $user = User::getById($b['uid']);
intval($b['uid']) $tz = $user['timezone'] ?: 'UTC';
);
if (DBA::isResult($x) && !empty($x[0]['timezone'])) {
$tz = $x[0]['timezone'];
}
$dw_username = DI::pConfig()->get($b['uid'],'dwpost','dw_username'); $dw_username = DI::pConfig()->get($b['uid'],'dwpost','dw_username');
$dw_password = DI::pConfig()->get($b['uid'],'dwpost','dw_password'); $dw_password = DI::pConfig()->get($b['uid'],'dwpost','dw_password');
@ -221,12 +216,12 @@ function dwpost_send(App $a, array &$b)
EOT; EOT;
Logger::log('dwpost: data: ' . $xml, Logger::DATA); Logger::debug('dwpost: data: ' . $xml);
if ($dw_blog !== 'test') { if ($dw_blog !== 'test') {
$x = DI::httpClient()->post($dw_blog, $xml, ['Content-Type' => 'text/xml'])->getBody(); $x = DI::httpClient()->post($dw_blog, $xml, ['Content-Type' => 'text/xml'])->getBody();
} }
Logger::log('posted to dreamwidth: ' . ($x) ? $x : '', Logger::DEBUG); Logger::info('posted to dreamwidth: ' . ($x) ? $x : '');
} }
} }

View file

@ -23,7 +23,7 @@ function gravatar_install() {
Hook::register('load_config', 'addon/gravatar/gravatar.php', 'gravatar_load_config'); Hook::register('load_config', 'addon/gravatar/gravatar.php', 'gravatar_load_config');
Hook::register('avatar_lookup', 'addon/gravatar/gravatar.php', 'gravatar_lookup'); Hook::register('avatar_lookup', 'addon/gravatar/gravatar.php', 'gravatar_lookup');
Logger::log("registered gravatar in avatar_lookup hook"); Logger::notice("registered gravatar in avatar_lookup hook");
} }
function gravatar_load_config(App $a, ConfigFileLoader $loader) function gravatar_load_config(App $a, ConfigFileLoader $loader)
@ -89,10 +89,7 @@ function gravatar_addon_admin (&$a, &$o) {
]; ];
// Check if Libravatar is enabled and show warning // Check if Libravatar is enabled and show warning
$r = q("SELECT * FROM `addon` WHERE `name` = '%s' and `installed` = 1", if (DBA::exists('addon', ['name' => 'libravatar', 'installed' => true])) {
DBA::escape('libravatar')
);
if (count($r)) {
$o = '<h5>' .DI::l10n()->t('Information') .'</h5><p>' .DI::l10n()->t('Libravatar addon is installed, too. Please disable Libravatar addon or this Gravatar addon.<br>The Libravatar addon will fall back to Gravatar if nothing was found at Libravatar.') .'</p><br><br>'; $o = '<h5>' .DI::l10n()->t('Information') .'</h5><p>' .DI::l10n()->t('Libravatar addon is installed, too. Please disable Libravatar addon or this Gravatar addon.<br>The Libravatar addon will fall back to Gravatar if nothing was found at Libravatar.') .'</p><br><br>';
} }

View file

@ -13,6 +13,7 @@ use Friendica\Core\Hook;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\User;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\XML; use Friendica\Util\XML;
@ -162,15 +163,8 @@ function ijpost_send(&$a, &$b)
// Hopefully the person's Friendica account // Hopefully the person's Friendica account
// will be set to the same thing. // will be set to the same thing.
$tz = 'UTC'; $user = User::getById($b['uid']);
$tz = $user['timezone'] ?: 'UTC';
$x = q("select timezone from user where uid = %d limit 1",
intval($b['uid'])
);
if ($x && strlen($x[0]['timezone'])) {
$tz = $x[0]['timezone'];
}
$ij_username = DI::pConfig()->get($b['uid'], 'ijpost', 'ij_username'); $ij_username = DI::pConfig()->get($b['uid'], 'ijpost', 'ij_username');
$ij_password = DI::pConfig()->get($b['uid'], 'ijpost', 'ij_password'); $ij_password = DI::pConfig()->get($b['uid'], 'ijpost', 'ij_password');
@ -216,11 +210,11 @@ function ijpost_send(&$a, &$b)
EOT; EOT;
Logger::log('ijpost: data: ' . $xml, Logger::DATA); Logger::debug('ijpost: data: ' . $xml);
if ($ij_blog !== 'test') { if ($ij_blog !== 'test') {
$x = DI::httpClient()->post($ij_blog, $xml, ['Content-Type' => 'text/xml'])->getBody(); $x = DI::httpClient()->post($ij_blog, $xml, ['Content-Type' => 'text/xml'])->getBody();
} }
Logger::log('posted to insanejournal: ' . $x ? $x : '', Logger::DEBUG); Logger::info('posted to insanejournal: ' . $x ? $x : '');
} }
} }

View file

@ -14,6 +14,7 @@ use Friendica\Core\Logger;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\User;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\XML; use Friendica\Util\XML;
@ -160,13 +161,8 @@ function ljpost_send(&$a,&$b) {
// Hopefully the person's Friendica account // Hopefully the person's Friendica account
// will be set to the same thing. // will be set to the same thing.
$tz = 'UTC'; $user = User::getById($b['uid']);
$tz = $user['timezone'] ?: 'UTC';
$x = q("select timezone from user where uid = %d limit 1",
intval($b['uid'])
);
if($x && strlen($x[0]['timezone']))
$tz = $x[0]['timezone'];
$lj_username = XML::escape(DI::pConfig()->get($b['uid'],'ljpost','lj_username')); $lj_username = XML::escape(DI::pConfig()->get($b['uid'],'ljpost','lj_username'));
$lj_password = XML::escape(DI::pConfig()->get($b['uid'],'ljpost','lj_password')); $lj_password = XML::escape(DI::pConfig()->get($b['uid'],'ljpost','lj_password'));
@ -231,11 +227,11 @@ function ljpost_send(&$a,&$b) {
EOT; EOT;
Logger::log('ljpost: data: ' . $xml, Logger::DATA); Logger::debug('ljpost: data: ' . $xml);
if ($lj_blog !== 'test') { if ($lj_blog !== 'test') {
$x = DI::httpClient()->post($lj_blog, $xml, ['Content-Type' => 'text/xml'])->getBody(); $x = DI::httpClient()->post($lj_blog, $xml, ['Content-Type' => 'text/xml'])->getBody();
} }
Logger::log('posted to livejournal: ' . ($x) ? $x : '', Logger::DEBUG); Logger::info('posted to livejournal: ' . ($x) ? $x : '');
} }
} }

View file

@ -13,6 +13,7 @@ use Friendica\Core\Renderer;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\User; use Friendica\Model\User;
@ -229,9 +230,8 @@ function mailstream_do_images(&$item, &$attachments)
*/ */
function mailstream_sender($item) function mailstream_sender($item)
{ {
$r = q('SELECT * FROM `contact` WHERE `id` = %d', $item['contact-id']); $contact = Contact::getById($item['contact-id']);
if (DBA::isResult($r)) { if (DBA::isResult($contact)) {
$contact = $r[0];
if ($contact['name'] != $item['author-name']) { if ($contact['name'] != $item['author-name']) {
return $contact['name'] . ' - ' . $item['author-name']; return $contact['name'] . ' - ' . $item['author-name'];
} }
@ -300,12 +300,8 @@ function mailstream_subject($item)
} }
$parent = $parent_item['thr-parent']; $parent = $parent_item['thr-parent'];
} }
$r = q( $contact = Contact::selectFirst([], ['id' => $item['contact-id'], 'uid' => $item['uid']]);
"SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d", if (!DBA::isResult($contact)) {
intval($item['contact-id']),
intval($item['uid'])
);
if (!DBA::isResult($r)) {
Logger::error( Logger::error(
'mailstream_subject no contact for item', 'mailstream_subject no contact for item',
['id' => $item['id'], ['id' => $item['id'],
@ -315,7 +311,6 @@ function mailstream_subject($item)
); );
return DI::l10n()->t("Friendica post"); return DI::l10n()->t("Friendica post");
} }
$contact = $r[0];
if ($contact['network'] === 'dfrn') { if ($contact['network'] === 'dfrn') {
return DI::l10n()->t("Friendica post"); return DI::l10n()->t("Friendica post");
} }
@ -444,20 +439,7 @@ function mailstream_html_wrap(&$text)
*/ */
function mailstream_convert_table_entries() function mailstream_convert_table_entries()
{ {
$query = <<< EOT $ms_item_ids = DBA::selectToArray('mailstream_item', [], ['message-id', 'uri', 'uid', 'contact-id'], ["`mailstream_item`.`completed` IS NULL"]);
SELECT
`message-id`,
`uri`,
`uid`,
`contact-id`
FROM
`mailstream_item`
WHERE
`mailstream_item`.`completed` IS NULL
EOT;
$ms_item_ids = q($query);
if (DBA::isResult($ms_item_ids)) {
Logger::debug('mailstream_convert_table_entries processing ' . count($ms_item_ids) . ' items'); Logger::debug('mailstream_convert_table_entries processing ' . count($ms_item_ids) . ' items');
foreach ($ms_item_ids as $ms_item_id) { foreach ($ms_item_ids as $ms_item_id) {
$send_hook_data = array('uid' => $ms_item_id['uid'], $send_hook_data = array('uid' => $ms_item_id['uid'],
@ -473,8 +455,7 @@ EOT;
Logger::info('mailstream_convert_table_entries: convert item to workerqueue', $send_hook_data); Logger::info('mailstream_convert_table_entries: convert item to workerqueue', $send_hook_data);
Hook::fork(PRIORITY_LOW, 'mailstream_send_hook', $send_hook_data); Hook::fork(PRIORITY_LOW, 'mailstream_send_hook', $send_hook_data);
} }
} DBA::e('DROP TABLE `mailstream_item`');
q('DROP TABLE `mailstream_item`');
} }
/** /**

View file

@ -9,6 +9,7 @@
use Friendica\App; use Friendica\App;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML; use Friendica\Content\Text\HTML;
use Friendica\Core\Addon;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
@ -103,7 +104,7 @@ function pumpio_registerclient(App $a, $host)
$params["logo_url"] = DI::baseUrl()->get()."/images/friendica-256.png"; $params["logo_url"] = DI::baseUrl()->get()."/images/friendica-256.png";
$params["redirect_uris"] = DI::baseUrl()->get()."/pumpio/connect"; $params["redirect_uris"] = DI::baseUrl()->get()."/pumpio/connect";
Logger::log("pumpio_registerclient: ".$url." parameters ".print_r($params, true), Logger::DEBUG); Logger::info("pumpio_registerclient: ".$url." parameters ".print_r($params, true));
$ch = curl_init($url); $ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HEADER, false);
@ -117,10 +118,10 @@ function pumpio_registerclient(App $a, $host)
if ($curl_info["http_code"] == "200") { if ($curl_info["http_code"] == "200") {
$values = json_decode($s); $values = json_decode($s);
Logger::log("pumpio_registerclient: success ".print_r($values, true), Logger::DEBUG); Logger::info("pumpio_registerclient: success ".print_r($values, true));
return $values; return $values;
} }
Logger::log("pumpio_registerclient: failed: ".print_r($curl_info, true), Logger::DEBUG); Logger::info("pumpio_registerclient: failed: ".print_r($curl_info, true));
return false; return false;
} }
@ -133,7 +134,7 @@ function pumpio_connect(App $a)
$hostname = DI::pConfig()->get(local_user(), 'pumpio', 'host'); $hostname = DI::pConfig()->get(local_user(), 'pumpio', 'host');
if ((($consumer_key == "") || ($consumer_secret == "")) && ($hostname != "")) { if ((($consumer_key == "") || ($consumer_secret == "")) && ($hostname != "")) {
Logger::log("pumpio_connect: register client"); Logger::notice("pumpio_connect: register client");
$clientdata = pumpio_registerclient($a, $hostname); $clientdata = pumpio_registerclient($a, $hostname);
DI::pConfig()->set(local_user(), 'pumpio', 'consumer_key', $clientdata->client_id); DI::pConfig()->set(local_user(), 'pumpio', 'consumer_key', $clientdata->client_id);
DI::pConfig()->set(local_user(), 'pumpio', 'consumer_secret', $clientdata->client_secret); DI::pConfig()->set(local_user(), 'pumpio', 'consumer_secret', $clientdata->client_secret);
@ -141,11 +142,11 @@ function pumpio_connect(App $a)
$consumer_key = DI::pConfig()->get(local_user(), 'pumpio', 'consumer_key'); $consumer_key = DI::pConfig()->get(local_user(), 'pumpio', 'consumer_key');
$consumer_secret = DI::pConfig()->get(local_user(), 'pumpio', 'consumer_secret'); $consumer_secret = DI::pConfig()->get(local_user(), 'pumpio', 'consumer_secret');
Logger::log("pumpio_connect: ckey: ".$consumer_key." csecrect: ".$consumer_secret, Logger::DEBUG); Logger::info("pumpio_connect: ckey: ".$consumer_key." csecrect: ".$consumer_secret);
} }
if (($consumer_key == "") || ($consumer_secret == "")) { if (($consumer_key == "") || ($consumer_secret == "")) {
Logger::log("pumpio_connect: ".sprintf("Unable to register the client at the pump.io server '%s'.", $hostname)); Logger::notice("pumpio_connect: ".sprintf("Unable to register the client at the pump.io server '%s'.", $hostname));
return DI::l10n()->t("Unable to register the client at the pump.io server '%s'.", $hostname); return DI::l10n()->t("Unable to register the client at the pump.io server '%s'.", $hostname);
} }
@ -174,7 +175,7 @@ function pumpio_connect(App $a)
if (($success = $client->Initialize())) { if (($success = $client->Initialize())) {
if (($success = $client->Process())) { if (($success = $client->Process())) {
if (strlen($client->access_token)) { if (strlen($client->access_token)) {
Logger::log("pumpio_connect: otoken: ".$client->access_token." osecrect: ".$client->access_token_secret, Logger::DEBUG); Logger::info("pumpio_connect: otoken: ".$client->access_token." osecrect: ".$client->access_token_secret);
DI::pConfig()->set(local_user(), "pumpio", "oauth_token", $client->access_token); DI::pConfig()->set(local_user(), "pumpio", "oauth_token", $client->access_token);
DI::pConfig()->set(local_user(), "pumpio", "oauth_token_secret", $client->access_token_secret); DI::pConfig()->set(local_user(), "pumpio", "oauth_token_secret", $client->access_token_secret);
} }
@ -186,11 +187,11 @@ function pumpio_connect(App $a)
} }
if ($success) { if ($success) {
Logger::log("pumpio_connect: authenticated"); Logger::notice("pumpio_connect: authenticated");
$o = DI::l10n()->t("You are now authenticated to pumpio."); $o = DI::l10n()->t("You are now authenticated to pumpio.");
$o .= '<br /><a href="'.DI::baseUrl()->get().'/settings/connectors">'.DI::l10n()->t("return to the connector page").'</a>'; $o .= '<br /><a href="'.DI::baseUrl()->get().'/settings/connectors">'.DI::l10n()->t("return to the connector page").'</a>';
} else { } else {
Logger::log("pumpio_connect: could not connect"); Logger::notice("pumpio_connect: could not connect");
$o = 'Could not connect to pumpio. Refresh the page or try again later.'; $o = 'Could not connect to pumpio. Refresh the page or try again later.';
} }
@ -391,7 +392,7 @@ function pumpio_hook_fork(App $a, array &$b)
if (DI::pConfig()->get($post['uid'], 'pumpio', 'import')) { if (DI::pConfig()->get($post['uid'], 'pumpio', 'import')) {
// Don't fork if it isn't a reply to a pump.io post // Don't fork if it isn't a reply to a pump.io post
if (($post['parent'] != $post['id']) && !Post::exists(['id' => $post['parent'], 'network' => Protocol::PUMPIO])) { if (($post['parent'] != $post['id']) && !Post::exists(['id' => $post['parent'], 'network' => Protocol::PUMPIO])) {
Logger::log('No pump.io parent found for item ' . $post['id']); Logger::notice('No pump.io parent found for item ' . $post['id']);
$b['execute'] = false; $b['execute'] = false;
return; return;
} }
@ -435,7 +436,7 @@ function pumpio_send(App $a, array &$b)
return; return;
} }
Logger::log("pumpio_send: parameter ".print_r($b, true), Logger::DATA); Logger::debug("pumpio_send: parameter ".print_r($b, true));
$b['body'] = Post\Media::addAttachmentsToBody($b['uri-id'], $b['body']); $b['body'] = Post\Media::addAttachmentsToBody($b['uri-id'], $b['body']);
@ -445,7 +446,7 @@ function pumpio_send(App $a, array &$b)
$orig_post = Post::selectFirst([], $condition); $orig_post = Post::selectFirst([], $condition);
if (!DBA::isResult($orig_post)) { if (!DBA::isResult($orig_post)) {
Logger::log("pumpio_send: no pumpio post ".$b["parent"]); Logger::notice("pumpio_send: no pumpio post ".$b["parent"]);
return; return;
} else { } else {
$iscomment = true; $iscomment = true;
@ -455,7 +456,7 @@ function pumpio_send(App $a, array &$b)
$receiver = pumpio_getreceiver($a, $b); $receiver = pumpio_getreceiver($a, $b);
Logger::log("pumpio_send: receiver ".print_r($receiver, true)); Logger::notice("pumpio_send: receiver ".print_r($receiver, true));
if (!count($receiver) && ($b['private'] || !strstr($b['postopts'], 'pumpio'))) { if (!count($receiver) && ($b['private'] || !strstr($b['postopts'], 'pumpio'))) {
return; return;
@ -463,7 +464,7 @@ function pumpio_send(App $a, array &$b)
// Dont't post if the post doesn't belong to us. // Dont't post if the post doesn't belong to us.
// This is a check for forum postings // This is a check for forum postings
$self = DBA::selectFirst('contact', ['id'], ['uid' => $b['uid'], 'self' => true]); $self = User::getOwnerDataById($b['uid']);
if ($b['contact-id'] != $self['id']) { if ($b['contact-id'] != $self['id']) {
return; return;
} }
@ -587,13 +588,13 @@ function pumpio_send(App $a, array &$b)
} }
$post_id = $user->object->id; $post_id = $user->object->id;
Logger::log('pumpio_send '.$username.': success '.$post_id); Logger::notice('pumpio_send '.$username.': success '.$post_id);
if ($post_id && $iscomment) { if ($post_id && $iscomment) {
Logger::log('pumpio_send '.$username.': Update extid '.$post_id." for post id ".$b['id']); Logger::notice('pumpio_send '.$username.': Update extid '.$post_id." for post id ".$b['id']);
Item::update(['extid' => $post_id], ['id' => $b['id']]); Item::update(['extid' => $post_id], ['id' => $b['id']]);
} }
} else { } else {
Logger::log('pumpio_send '.$username.': '.$url.' general error: ' . print_r($user, true)); Logger::notice('pumpio_send '.$username.': '.$url.' general error: ' . print_r($user, true));
Worker::defer(); Worker::defer();
} }
} }
@ -659,18 +660,16 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "")
} }
if ($success) { if ($success) {
Logger::log('pumpio_action '.$username.' '.$action.': success '.$uri); Logger::notice('pumpio_action '.$username.' '.$action.': success '.$uri);
} else { } else {
Logger::log('pumpio_action '.$username.' '.$action.': general error: '.$uri); Logger::notice('pumpio_action '.$username.' '.$action.': general error: '.$uri);
Worker::defer(); Worker::defer();
} }
} }
function pumpio_sync(App $a) function pumpio_sync(App $a)
{ {
$r = q("SELECT * FROM `addon` WHERE `installed` = 1 AND `name` = 'pumpio'"); if (!Addon::isEnabled('pumpio')) {
if (!DBA::isResult($r)) {
return; return;
} }
@ -681,19 +680,17 @@ function pumpio_sync(App $a)
if ($last) { if ($last) {
$next = $last + ($poll_interval * 60); $next = $last + ($poll_interval * 60);
if ($next > time()) { if ($next > time()) {
Logger::log('pumpio: poll intervall not reached'); Logger::notice('pumpio: poll intervall not reached');
return; return;
} }
} }
Logger::log('pumpio: cron_start'); Logger::notice('pumpio: cron_start');
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'pumpio' AND `k` = 'mirror' AND `v` = '1' ORDER BY RAND() "); $pconfigs = DBA::selectToArray('pconfig', ['uid'], ['cat' => 'pumpio', 'k' => 'mirror', 'v' => '1']);
if (DBA::isResult($r)) { foreach ($pconfigs as $rr) {
foreach ($r as $rr) { Logger::notice('pumpio: mirroring user '.$rr['uid']);
Logger::log('pumpio: mirroring user '.$rr['uid']);
pumpio_fetchtimeline($a, $rr['uid']); pumpio_fetchtimeline($a, $rr['uid']);
} }
}
$abandon_days = intval(DI::config()->get('system', 'account_abandon_days')); $abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
if ($abandon_days < 1) { if ($abandon_days < 1) {
@ -702,18 +699,16 @@ function pumpio_sync(App $a)
$abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400); $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() "); $pconfigs = DBA::selectToArray('pconfig', ['uid'], ['cat' => 'pumpio', 'k' => 'import', 'v' => '1']);
if (DBA::isResult($r)) { foreach ($pconfigs as $rr) {
foreach ($r as $rr) {
if ($abandon_days != 0) { if ($abandon_days != 0) {
$user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); if (DBA::exists('user', ["uid = ? AND `login_date` >= ?", $rr['uid'], $abandon_limit])) {
if (!DBA::isResult($user)) { Logger::notice('abandoned account: timeline from user '.$rr['uid'].' will not be imported');
Logger::log('abandoned account: timeline from user '.$rr['uid'].' will not be imported');
continue; continue;
} }
} }
Logger::log('pumpio: importing timeline from user '.$rr['uid']); Logger::notice('pumpio: importing timeline from user '.$rr['uid']);
pumpio_fetchinbox($a, $rr['uid']); pumpio_fetchinbox($a, $rr['uid']);
// check for new contacts once a day // check for new contacts once a day
@ -729,9 +724,8 @@ function pumpio_sync(App $a)
DI::pConfig()->set($rr['uid'], 'pumpio', 'contact_check', time()); DI::pConfig()->set($rr['uid'], 'pumpio', 'contact_check', time());
} }
} }
}
Logger::log('pumpio: cron_end'); Logger::notice('pumpio: cron_end');
DI::config()->set('pumpio', 'last_poll', time()); DI::config()->set('pumpio', 'last_poll', time());
} }
@ -776,7 +770,7 @@ function pumpio_fetchtimeline(App $a, $uid)
$url = 'https://'.$hostname.'/api/user/'.$username.'/feed/major'; $url = 'https://'.$hostname.'/api/user/'.$username.'/feed/major';
Logger::log('pumpio: fetching for user '.$uid.' '.$url.' C:'.$client->client_id.' CS:'.$client->client_secret.' T:'.$client->access_token.' TS:'.$client->access_token_secret); Logger::notice('pumpio: fetching for user '.$uid.' '.$url.' C:'.$client->client_id.' CS:'.$client->client_secret.' T:'.$client->access_token.' TS:'.$client->access_token_secret);
$useraddr = $username.'@'.$hostname; $useraddr = $username.'@'.$hostname;
@ -788,7 +782,7 @@ function pumpio_fetchtimeline(App $a, $uid)
} }
if (!$success) { if (!$success) {
Logger::log('pumpio: error fetching posts for user '.$uid." ".$useraddr." ".print_r($user, true)); Logger::notice('pumpio: error fetching posts for user '.$uid." ".$useraddr." ".print_r($user, true));
return; return;
} }
@ -857,12 +851,12 @@ function pumpio_fetchtimeline(App $a, $uid)
} }
} }
Logger::log('pumpio: posting for user '.$uid); Logger::notice('pumpio: posting for user '.$uid);
require_once('mod/item.php'); require_once('mod/item.php');
item_post($a); item_post($a);
Logger::log('pumpio: posting done - user '.$uid); Logger::notice('pumpio: posting done - user '.$uid);
} }
} }
} }
@ -887,15 +881,11 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id)
$contactid = 0; $contactid = 0;
if (Strings::compareLink($post->actor->url, $own_id)) { if (Strings::compareLink($post->actor->url, $own_id)) {
$contactid = $self[0]['id']; $contactid = $self['id'];
} else { } else {
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", $contact = Contact::selectFirst([], ['nurl' => Strings::normaliseLink($post->actor->url), 'uid' => $uid, 'blocked' => false, 'readonly' => false]);
DBA::escape(Strings::normaliseLink($post->actor->url)), if (DBA::isResult($contact)) {
intval($uid) $contactid = $contact['id'];
);
if (DBA::isResult($r)) {
$contactid = $r[0]['id'];
} }
if ($contactid == 0) { if ($contactid == 0) {
@ -905,17 +895,17 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id)
Item::markForDeletion(['verb' => Activity::LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]); Item::markForDeletion(['verb' => Activity::LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]);
if (DBA::isResult($r)) { if (DBA::isResult($contact)) {
Logger::log("pumpio_dounlike: unliked existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); Logger::notice("pumpio_dounlike: unliked existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
} else { } else {
Logger::log("pumpio_dounlike: not found. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); Logger::notice("pumpio_dounlike: not found. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
} }
} }
function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = true) function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = true)
{ {
if (empty($post->object->id)) { if (empty($post->object->id)) {
Logger::log('Got empty like: '.print_r($post, true), Logger::DEBUG); Logger::info('Got empty like: '.print_r($post, true));
return; return;
} }
@ -937,18 +927,14 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion =
$contactid = 0; $contactid = 0;
if (Strings::compareLink($post->actor->url, $own_id)) { if (Strings::compareLink($post->actor->url, $own_id)) {
$contactid = $self[0]['id']; $contactid = $self['id'];
$post->actor->displayName = $self[0]['name']; $post->actor->displayName = $self['name'];
$post->actor->url = $self[0]['url']; $post->actor->url = $self['url'];
$post->actor->image->url = $self[0]['photo']; $post->actor->image->url = $self['photo'];
} else { } else {
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", $contact = Contact::selectFirst([], ['nurl' => Strings::normaliseLink($post->actor->url), 'uid' => $uid, 'blocked' => false, 'readonly' => false]);
DBA::escape(Strings::normaliseLink($post->actor->url)), if (DBA::isResult($contact)) {
intval($uid) $contactid = $contact['id'];
);
if (DBA::isResult($r)) {
$contactid = $r[0]['id'];
} }
if ($contactid == 0) { if ($contactid == 0) {
@ -958,7 +944,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion =
$condition = ['verb' => Activity::LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]; $condition = ['verb' => Activity::LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']];
if (Post::exists($condition)) { if (Post::exists($condition)) {
Logger::log("pumpio_dolike: found existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); Logger::notice("pumpio_dolike: found existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
return; return;
} }
@ -992,7 +978,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion =
$ret = Item::insert($likedata); $ret = Item::insert($likedata);
Logger::log("pumpio_dolike: ".$ret." User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); Logger::notice("pumpio_dolike: ".$ret." User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
} }
function pumpio_get_contact($uid, $contact, $no_insert = false) function pumpio_get_contact($uid, $contact, $no_insert = false)
@ -1003,58 +989,42 @@ function pumpio_get_contact($uid, $contact, $no_insert = false)
return $cid; return $cid;
} }
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1", $r = Contact::selectFirst([], ['uid' => $uid, 'nurl' => Strings::normaliseLink($contact->url)]);
intval($uid), DBA::escape(Strings::normaliseLink($contact->url)));
if (!DBA::isResult($r)) { if (!DBA::isResult($r)) {
// create contact record // create contact record
q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, Contact::insert([
`name`, `nick`, `photo`, `network`, `rel`, `priority`, 'uid' => $uid,
`location`, `about`, `writable`, `blocked`, `readonly`, `pending` ) 'created' => DateTimeFormat::utcNow(),
VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', %d, 0, 0, 0)", 'url' => $contact->url,
intval($uid), 'nurl' => Strings::normaliseLink($contact->url),
DBA::escape(DateTimeFormat::utcNow()), 'addr' => str_replace("acct:", "", $contact->id),
DBA::escape($contact->url), 'alias' => '',
DBA::escape(Strings::normaliseLink($contact->url)), 'notify' => $contact->id,
DBA::escape(str_replace("acct:", "", $contact->id)), 'poll' => 'pump.io ' . $contact->id,
DBA::escape(''), 'name' => $contact->displayName,
DBA::escape($contact->id), // What is it for? 'nick' => $contact->preferredUsername,
DBA::escape('pump.io ' . $contact->id), // What is it for? 'photo' => $contact->image->url,
DBA::escape($contact->displayName), 'network' => Protocol::PUMPIO,
DBA::escape($contact->preferredUsername), 'rel' => Contact::FRIEND,
DBA::escape($contact->image->url), 'priority' => 1,
DBA::escape(Protocol::PUMPIO), 'location' => $contact->location->displayName,
intval(Contact::FRIEND), 'about' => $contact->summary,
intval(1), 'writable' => 1,
DBA::escape($contact->location->displayName), 'blocked' => 0,
DBA::escape($contact->summary), 'readonly' => 0,
intval(1) 'pending' => 0
); ]);
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
DBA::escape(Strings::normaliseLink($contact->url)),
intval($uid)
);
$r = Contact::selectFirst([], ['uid' => $uid, 'nurl' => Strings::normaliseLink($contact->url)]);
if (!DBA::isResult($r)) { if (!DBA::isResult($r)) {
return false; return false;
} }
$contact_id = $r[0]['id']; $contact_id = $r['id'];
Group::addMember(User::getDefaultGroup($uid), $contact_id); Group::addMember(User::getDefaultGroup($uid), $contact_id);
} else { } else {
$contact_id = $r[0]["id"]; $contact_id = $r["id"];
/* if (DB_UPDATE_VERSION >= "1177")
q("UPDATE `contact` SET `location` = '%s',
`about` = '%s'
WHERE `id` = %d",
dbesc($contact->location->displayName),
dbesc($contact->summary),
intval($r[0]['id'])
);
*/
} }
if (!empty($contact->image->url)) { if (!empty($contact->image->url)) {
@ -1138,43 +1108,30 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp
$contact_id = pumpio_get_contact($uid, $post->actor); $contact_id = pumpio_get_contact($uid, $post->actor);
if (!$contact_id) { if (!$contact_id) {
$contact_id = $self[0]['id']; $contact_id = $self['id'];
} }
$postarray['thr-parent'] = $post->object->id; $postarray['thr-parent'] = $post->object->id;
if (!$public) { if (!$public) {
$postarray['private'] = 1; $postarray['private'] = 1;
$postarray['allow_cid'] = '<' . $self[0]['id'] . '>'; $postarray['allow_cid'] = '<' . $self['id'] . '>';
} }
} else { } else {
$contact_id = pumpio_get_contact($uid, $post->actor, true); $contact_id = pumpio_get_contact($uid, $post->actor, true);
if (Strings::compareLink($post->actor->url, $own_id)) { if (Strings::compareLink($post->actor->url, $own_id)) {
$contact_id = $self[0]['id']; $contact_id = $self['id'];
$post->actor->displayName = $self[0]['name']; $post->actor->displayName = $self['name'];
$post->actor->url = $self[0]['url']; $post->actor->url = $self['url'];
$post->actor->image->url = $self[0]['photo']; $post->actor->image->url = $self['photo'];
} elseif ($contact_id == 0) { } elseif ($contact_id == 0) {
// Take an existing contact, the contact of the note or - as a fallback - the id of the user // 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", $contact = Contact::selectFirst([], ['nurl' => Strings::normaliseLink($post->actor->url), 'uid' => $uid, 'blocked' => false, 'readonly' => false]);
DBA::escape(Strings::normaliseLink($post->actor->url)), if (DBA::isResult($contact)) {
intval($uid) $contact_id = $contact['id'];
);
if (DBA::isResult($r)) {
$contact_id = $r[0]['id'];
} else { } else {
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", $contact_id = $self['id'];
DBA::escape(Strings::normaliseLink($post->actor->url)),
intval($uid)
);
if (DBA::isResult($r)) {
$contact_id = $r[0]['id'];
} else {
$contact_id = $self[0]['id'];
}
} }
} }
@ -1299,8 +1256,7 @@ function pumpio_fetchinbox(App $a, $uid)
$own_id = "https://".$hostname."/".$username; $own_id = "https://".$hostname."/".$username;
$self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", $self = User::getOwnerDataById($uid);
intval($uid));
$lastitems = q("SELECT `uri` FROM `post-thread-user` $lastitems = q("SELECT `uri` FROM `post-thread-user`
INNER JOIN `post-view` ON `post-view`.`id` = `post-thread-user`.`id` INNER JOIN `post-view` ON `post-view`.`id` = `post-thread-user`.`id`
@ -1427,18 +1383,13 @@ function pumpio_getreceiver(App $a, array $b)
foreach ($cids AS $cid) { foreach ($cids AS $cid) {
$cid = trim($cid, " <>"); $cid = trim($cid, " <>");
$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", $contact = Contact::selectFirst(['name', 'nick', 'url'], ['id' => $cid, 'uid' => $b["uid"], 'network' => Protocol::PUMPIO, 'blocked' => false, 'readonly' => false]);
intval($cid), if (DBA::isResult($contact)) {
intval($b["uid"]),
DBA::escape(Protocol::PUMPIO)
);
if (DBA::isResult($r)) {
$receiver["bcc"][] = [ $receiver["bcc"][] = [
"displayName" => $r[0]["name"], "displayName" => $contact["name"],
"objectType" => "person", "objectType" => "person",
"preferredUsername" => $r[0]["nick"], "preferredUsername" => $contact["nick"],
"url" => $r[0]["url"]]; "url" => $contact["url"]];
} }
} }
foreach ($gids AS $gid) { foreach ($gids AS $gid) {
@ -1470,18 +1421,13 @@ function pumpio_getreceiver(App $a, array $b)
$cid = str_replace("cid:", "", $cid); $cid = str_replace("cid:", "", $cid);
$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", $contact = Contact::selectFirst(['name', 'nick', 'url'], ['id' => $cid, 'uid' => $b["uid"], 'network' => Protocol::PUMPIO, 'blocked' => false, 'readonly' => false]);
intval($cid), if (DBA::isResult($contact)) {
intval($b["uid"]),
DBA::escape(Protocol::PUMPIO)
);
if (DBA::isResult($r)) {
$receiver["to"][] = [ $receiver["to"][] = [
"displayName" => $r[0]["name"], "displayName" => $contact["name"],
"objectType" => "person", "objectType" => "person",
"preferredUsername" => $r[0]["nick"], "preferredUsername" => $contact["nick"],
"url" => $r[0]["url"]]; "url" => $contact["url"]];
} }
} }
} }
@ -1498,12 +1444,11 @@ function pumpio_fetchallcomments(App $a, $uid, $id)
$hostname = DI::pConfig()->get($uid, 'pumpio', 'host'); $hostname = DI::pConfig()->get($uid, 'pumpio', 'host');
$username = DI::pConfig()->get($uid, "pumpio", "user"); $username = DI::pConfig()->get($uid, "pumpio", "user");
Logger::log("pumpio_fetchallcomments: completing comment for user ".$uid." post id ".$id); Logger::notice("pumpio_fetchallcomments: completing comment for user ".$uid." post id ".$id);
$own_id = "https://".$hostname."/".$username; $own_id = "https://".$hostname."/".$username;
$self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", $self = User::getOwnerDataById($uid);
intval($uid));
// Fetching the original post // Fetching the original post
$condition = ["`uri` = ? AND `uid` = ? AND `extid` != ''", $id, $uid]; $condition = ["`uri` = ? AND `uid` = ? AND `extid` != ''", $id, $uid];
@ -1524,7 +1469,7 @@ function pumpio_fetchallcomments(App $a, $uid, $id)
$client->access_token = $otoken; $client->access_token = $otoken;
$client->access_token_secret = $osecret; $client->access_token_secret = $osecret;
Logger::log("pumpio_fetchallcomments: fetching comment for user ".$uid." url ".$url); Logger::notice("pumpio_fetchallcomments: fetching comment for user ".$uid." url ".$url);
if (pumpio_reachable($url)) { if (pumpio_reachable($url)) {
$success = $client->CallAPI($url, 'GET', [], ['FailOnAccessError'=>true], $item); $success = $client->CallAPI($url, 'GET', [], ['FailOnAccessError'=>true], $item);
@ -1587,7 +1532,7 @@ function pumpio_fetchallcomments(App $a, $uid, $id)
$post->object = $item; $post->object = $item;
Logger::log("pumpio_fetchallcomments: posting comment ".$post->object->id." ".print_r($post, true)); Logger::notice("pumpio_fetchallcomments: posting comment ".$post->object->id." ".print_r($post, true));
pumpio_dopost($a, $client, $uid, $self, $post, $own_id, false); pumpio_dopost($a, $client, $uid, $self, $post, $own_id, false);
} }
} }

View file

@ -72,7 +72,7 @@ function statusnet_install()
Hook::register('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron'); Hook::register('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron');
Hook::register('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body'); Hook::register('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body');
Hook::register('check_item_notification', 'addon/statusnet/statusnet.php', 'statusnet_check_item_notification'); 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) 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')) { if (DI::pConfig()->get($post['uid'], 'statusnet', 'import')) {
// Don't fork if it isn't a reply to a GNU Social post // 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])) { 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; $b['execute'] = false;
return; return;
} }
@ -459,7 +459,7 @@ function statusnet_action(App $a, $uid, $pid, $action)
$connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret); $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) { switch ($action) {
case "delete": case "delete":
@ -472,7 +472,7 @@ function statusnet_action(App $a, $uid, $pid, $action)
$result = $connection->post("favorites/destroy/" . $pid); $result = $connection->post("favorites/destroy/" . $pid);
break; 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) 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); $hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $api);
if ($b['parent'] != $b['id']) { 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 // Looking if its a reply to a GNU Social post
$hostlength = strlen($hostname) + 2; $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 . "::")) { 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; return;
} }
$condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]]; $condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]];
$orig_post = Post::selectFirst(['author-link', 'uri'], $condition); $orig_post = Post::selectFirst(['author-link', 'uri'], $condition);
if (!DBA::isResult($orig_post)) { 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; return;
} else { } else {
$iscomment = true; $iscomment = true;
@ -514,12 +514,12 @@ function statusnet_post_hook(App $a, &$b)
$nickname = "@[url=" . $orig_post["author-link"] . "]" . $nick . "[/url]"; $nickname = "@[url=" . $orig_post["author-link"] . "]" . $nick . "[/url]";
$nicknameplain = "@" . $nick; $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)) { if ((strpos($b["body"], $nickname) === false) && (strpos($b["body"], $nicknameplain) === false)) {
$b["body"] = $nickname . " " . $b["body"]; $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 { } else {
$iscomment = false; $iscomment = false;
@ -540,7 +540,7 @@ function statusnet_post_hook(App $a, &$b)
} }
if ($b['verb'] == Activity::LIKE) { 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']) if ($b['deleted'])
statusnet_action($a, $b["uid"], substr($b["thr-parent"], $hostlength), "unlike"); statusnet_action($a, $b["uid"], substr($b["thr-parent"], $hostlength), "unlike");
else else
@ -561,7 +561,7 @@ function statusnet_post_hook(App $a, &$b)
return; return;
} }
Logger::log('GNU Socialpost invoked'); Logger::notice('GNU Socialpost invoked');
DI::pConfig()->load($b['uid'], 'statusnet'); DI::pConfig()->load($b['uid'], 'statusnet');
@ -610,7 +610,7 @@ function statusnet_post_hook(App $a, &$b)
if (strlen($msg)) { if (strlen($msg)) {
if ($iscomment) { if ($iscomment) {
$postdata["in_reply_to_status_id"] = substr($orig_post["uri"], $hostlength); $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 // New code that is able to post pictures
@ -621,17 +621,17 @@ function statusnet_post_hook(App $a, &$b)
$cb->setToken($otoken, $osecret); $cb->setToken($otoken, $osecret);
$result = $cb->statuses_update($postdata); $result = $cb->statuses_update($postdata);
//$result = $dent->post('statuses/update', $postdata); //$result = $dent->post('statuses/update', $postdata);
Logger::log('statusnet_post send, result: ' . print_r($result, true) . Logger::info('statusnet_post send, result: ' . print_r($result, true) .
"\nmessage: " . $msg . "\nOriginal post: " . print_r($b, true) . "\nPost Data: " . print_r($postdata, true), Logger::DEBUG); "\nmessage: " . $msg . "\nOriginal post: " . print_r($b, true) . "\nPost Data: " . print_r($postdata, true));
if (!empty($result->source)) { if (!empty($result->source)) {
DI::pConfig()->set($b["uid"], "statusnet", "application_name", strip_tags($result->source)); DI::pConfig()->set($b["uid"], "statusnet", "application_name", strip_tags($result->source));
} }
if (!empty($result->error)) { if (!empty($result->error)) {
Logger::log('Send to GNU Social failed: "' . $result->error . '"'); Logger::notice('Send to GNU Social failed: "' . $result->error . '"');
} elseif ($iscomment) { } 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']]); Item::update(['extid' => $hostname . "::" . $result->id, 'body' => $result->text], ['id' => $b['id']]);
} }
} }
@ -761,16 +761,16 @@ function statusnet_cron(App $a, $b)
if ($last) { if ($last) {
$next = $last + ($poll_interval * 60); $next = $last + ($poll_interval * 60);
if ($next > time()) { if ($next > time()) {
Logger::log('statusnet: poll intervall not reached'); Logger::notice('statusnet: poll intervall not reached');
return; 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() "); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'mirror_posts' AND `v` = '1' ORDER BY RAND() ");
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
foreach ($r as $rr) { 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']); statusnet_fetchtimeline($a, $rr['uid']);
} }
} }
@ -788,17 +788,17 @@ function statusnet_cron(App $a, $b)
if ($abandon_days != 0) { if ($abandon_days != 0) {
$user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit);
if (!DBA::isResult($user)) { 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; 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"]); statusnet_fetchhometimeline($a, $rr["uid"], $rr["v"]);
} }
} }
Logger::log('statusnet: cron_end'); Logger::notice('statusnet: cron_end');
DI::config()->set('statusnet', 'last_poll', time()); DI::config()->set('statusnet', 'last_poll', time());
} }
@ -901,7 +901,7 @@ function statusnet_fetchtimeline(App $a, $uid)
//print_r($_REQUEST); //print_r($_REQUEST);
if ($_REQUEST["body"] != "") { if ($_REQUEST["body"] != "") {
Logger::log('statusnet: posting for user ' . $uid); Logger::notice('statusnet: posting for user ' . $uid);
item_post($a); 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"])) { 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; 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 // 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)) { 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']); $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) 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'); $api = DI::pConfig()->get($uid, 'statusnet', 'baseapi');
$hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $api); $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]; $postarray["coord"] = $content->coordinates->coordinates[1] . " " . $content->coordinates->coordinates[0];
} }
Logger::log("statusnet_createpost: end", Logger::DEBUG); Logger::info("statusnet_createpost: end");
return $postarray; 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" is deactivated, since currently you cannot add users manually by now
$create_user = true; $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); $connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret);
@ -1237,7 +1237,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1)
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
$nick = $r[0]["nick"]; $nick = $r[0]["nick"];
} else { } 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; return;
} }
@ -1247,14 +1247,14 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1)
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
$self = $r[0]; $self = $r[0];
} else { } 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; return;
} }
$u = q("SELECT * FROM user WHERE uid = %d LIMIT 1", $u = q("SELECT * FROM user WHERE uid = %d LIMIT 1",
intval($uid)); intval($uid));
if (!DBA::isResult($u)) { 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; return;
} }
@ -1285,13 +1285,13 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1)
$errormsg = "Unknown error"; $errormsg = "Unknown error";
} }
Logger::log("statusnet_fetchhometimeline: Error fetching home timeline: " . $errormsg, Logger::DEBUG); Logger::info("statusnet_fetchhometimeline: Error fetching home timeline: " . $errormsg);
return; return;
} }
$posts = array_reverse($items); $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)) { if (count($posts)) {
foreach ($posts as $post) { foreach ($posts as $post) {
@ -1319,7 +1319,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1)
$item = Item::insert($postarray); $item = Item::insert($postarray);
$postarray["id"] = $item; $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); $items = $connection->get('statuses/mentions_timeline', $parameters);
if (!is_array($items)) { 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; return;
} }
$posts = array_reverse($items); $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)) { if (count($posts)) {
foreach ($posts as $post) { foreach ($posts as $post) {
@ -1369,7 +1369,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1)
$item = Item::insert($postarray); $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); $item = Item::insert($postarray);
$postarray["id"] = $item; $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) { foreach ($matches AS $match) {
$search = "[url=" . $match[1] . "]" . $match[2] . "[/url]"; $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 { try {
$expanded_url = DI::httpClient()->finalUrl($match[1]); $expanded_url = DI::httpClient()->finalUrl($match[1]);
@ -1434,11 +1434,11 @@ function statusnet_convertmsg(App $a, $body)
$expanded_url = $match[1]; $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); $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 == "") { if ($type == "") {
$type = $oembed_data->type; $type = $oembed_data->type;
@ -1575,13 +1575,13 @@ function statusnet_is_retweet(App $a, $uid, $body)
return false; 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); $connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret);
$result = $connection->post('statuses/retweet/' . $id); $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); return isset($result->id);
} }

View file

@ -8,7 +8,6 @@
*/ */
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Database\DBA; use Friendica\Database\DBA;
@ -17,7 +16,7 @@ use Friendica\DI;
function widgets_install() { function widgets_install() {
Hook::register('addon_settings', 'addon/widgets/widgets.php', 'widgets_settings'); Hook::register('addon_settings', 'addon/widgets/widgets.php', 'widgets_settings');
Hook::register('addon_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post'); Hook::register('addon_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post');
Logger::log("installed widgets"); Logger::notice("installed widgets");
} }
function widgets_settings_post(){ function widgets_settings_post(){

View file

@ -53,7 +53,7 @@ function windowsphonepush_install()
Hook::register('addon_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings'); Hook::register('addon_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings');
Hook::register('addon_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post'); Hook::register('addon_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post');
Logger::log("installed windowsphonepush"); Logger::notice("installed windowsphonepush");
} }
/* declare the windowsphonepush function so that /windowsphonepush url requests will land here */ /* declare the windowsphonepush function so that /windowsphonepush url requests will land here */
@ -135,9 +135,8 @@ function windowsphonepush_settings(&$a, &$s)
function windowsphonepush_cron() function windowsphonepush_cron()
{ {
// retrieve all UID's for which the addon windowsphonepush is enabled and loop through every user // retrieve all UID's for which the addon windowsphonepush is enabled and loop through every user
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'windowsphonepush' AND `k` = 'enable' AND `v` = 1"); $pconfigs = DBA::selectToArray('pconfig', ['uid'], ['cat' => 'windowsphonepush', 'k' => 'enable', 'v' => true]);
if (count($r)) { foreach ($pconfigs as $rr) {
foreach ($r as $rr) {
// load stored information for the user-id of the current loop // load stored information for the user-id of the current loop
$device_url = DI::pConfig()->get($rr['uid'], 'windowsphonepush', 'device_url'); $device_url = DI::pConfig()->get($rr['uid'], 'windowsphonepush', 'device_url');
$lastpushid = DI::pConfig()->get($rr['uid'], 'windowsphonepush', 'lastpushid'); $lastpushid = DI::pConfig()->get($rr['uid'], 'windowsphonepush', 'lastpushid');
@ -146,7 +145,7 @@ function windowsphonepush_cron()
// by app if user has switched the server setting in app - sending blank not possible as this would return an update error) // by app if user has switched the server setting in app - sending blank not possible as this would return an update error)
if (( $device_url == "" ) || ( $device_url == "NA" )) { if (( $device_url == "" ) || ( $device_url == "NA" )) {
// no Device-URL for the user availabe, but addon is enabled --> write info to Logger // no Device-URL for the user availabe, but addon is enabled --> write info to Logger
Logger::log("WARN: windowsphonepush is enable for user " . $rr['uid'] . ", but no Device-URL is specified for the user."); Logger::notice("WARN: windowsphonepush is enable for user " . $rr['uid'] . ", but no Device-URL is specified for the user.");
} else { } else {
// retrieve the number of unseen items and the id of the latest one (if there are more than // retrieve the number of unseen items and the id of the latest one (if there are more than
// one new entries since last poller run, only the latest one will be pushed) // one new entries since last poller run, only the latest one will be pushed)
@ -163,11 +162,11 @@ function windowsphonepush_cron()
break; break;
case "QueueFull": case "QueueFull":
// maximum of 30 messages reached, server rejects any further push notification until device reconnects // maximum of 30 messages reached, server rejects any further push notification until device reconnects
Logger::log("INFO: Device-URL '" . $device_url . "' returns a QueueFull."); Logger::notice("INFO: Device-URL '" . $device_url . "' returns a QueueFull.");
break; break;
case "Suppressed": case "Suppressed":
// notification received and dropped as something in app was not enabled // notification received and dropped as something in app was not enabled
Logger::log("WARN. Device-URL '" . $device_url . "' returns a Suppressed. Unexpected error in Mobile App?"); Logger::notice("WARN. Device-URL '" . $device_url . "' returns a Suppressed. Unexpected error in Mobile App?");
break; break;
case "Dropped": case "Dropped":
// mostly combines with Expired, in that case Device-URL will be deleted from pconfig (function send_push) // mostly combines with Expired, in that case Device-URL will be deleted from pconfig (function send_push)
@ -175,7 +174,7 @@ function windowsphonepush_cron()
default: default:
// error, mostly called by "" which means that the url (not "" which has been checked) // error, mostly called by "" which means that the url (not "" which has been checked)
// didn't not received Microsoft Notification Server -> wrong url // didn't not received Microsoft Notification Server -> wrong url
Logger::log("ERROR: specified Device-URL '" . $device_url . "' didn't produced any response."); Logger::notice("ERROR: specified Device-URL '" . $device_url . "' didn't produced any response.");
} }
// additionally user receives the text of the newest item (function checks against last successfully pushed item) // additionally user receives the text of the newest item (function checks against last successfully pushed item)
@ -222,7 +221,6 @@ function windowsphonepush_cron()
} }
} }
} }
}
} }
/* Tile push notification change the number in the icon of the App in Start Screen of /* Tile push notification change the number in the icon of the App in Start Screen of
@ -292,7 +290,7 @@ function send_push($device_url, $headers, $msg)
$subscriptionStatus = get_header_value($output, 'X-SubscriptionStatus'); $subscriptionStatus = get_header_value($output, 'X-SubscriptionStatus');
if ($subscriptionStatus == "Expired") { if ($subscriptionStatus == "Expired") {
DI::pConfig()->set(local_user(), 'windowsphonepush', 'device_url', ""); DI::pConfig()->set(local_user(), 'windowsphonepush', 'device_url', "");
Logger::log("ERROR: the stored Device-URL " . $device_url . "returned an 'Expired' error, it has been deleted now."); Logger::notice("ERROR: the stored Device-URL " . $device_url . "returned an 'Expired' error, it has been deleted now.");
} }
// the notification status shall be returned to windowsphonepush_cron (will // the notification status shall be returned to windowsphonepush_cron (will
@ -393,7 +391,7 @@ function windowsphonepush_updatesettings()
// check if sent url is empty - don't save and send return code to app // check if sent url is empty - don't save and send return code to app
$device_url = $_POST['deviceurl']; $device_url = $_POST['deviceurl'];
if ($device_url == "") { if ($device_url == "") {
Logger::log("ERROR: no valid Device-URL specified - client transferred '" . $device_url . "'"); Logger::notice("ERROR: no valid Device-URL specified - client transferred '" . $device_url . "'");
return "No valid Device-URL specified"; return "No valid Device-URL specified";
} }
@ -401,20 +399,15 @@ function windowsphonepush_updatesettings()
// the user on the Windows Phone device and that device url is no longer true for the other user, so we // the user on the Windows Phone device and that device url is no longer true for the other user, so we
// et the device_url for the OTHER user blank (should normally not occur as App should include User/server // et the device_url for the OTHER user blank (should normally not occur as App should include User/server
// in url request to Microsoft Push Notification server) // in url request to Microsoft Push Notification server)
$r = q("SELECT * FROM `pconfig` WHERE `uid` <> " . local_user() . " AND $pconfigs = DBA::selectToArray('pconfig', ['uid'], ["`uid` != ? AND `cat` = ? AND `k` = ? AND `v` = ?", local_user(), 'windowsphonepush', 'device_url', $device_url]);
`cat` = 'windowsphonepush' AND foreach ($pconfigs as $rr) {
`k` = 'device_url' AND
`v` = '" . $device_url . "'");
if (count($r)) {
foreach ($r as $rr) {
DI::pConfig()->set($rr['uid'], 'windowsphonepush', 'device_url', ''); DI::pConfig()->set($rr['uid'], 'windowsphonepush', 'device_url', '');
Logger::log("WARN: the sent URL was already registered with user '" . $rr['uid'] . "'. Deleted for this user as we expect to be correct now for user '" . local_user() . "'."); Logger::notice("WARN: the sent URL was already registered with user '" . $rr['uid'] . "'. Deleted for this user as we expect to be correct now for user '" . local_user() . "'.");
}
} }
DI::pConfig()->set(local_user(), 'windowsphonepush', 'device_url', $device_url); DI::pConfig()->set(local_user(), 'windowsphonepush', 'device_url', $device_url);
// output the successfull update of the device URL to the logger for error analysis if necessary // output the successfull update of the device URL to the logger for error analysis if necessary
Logger::log("INFO: Device-URL for user '" . local_user() . "' has been updated with '" . $device_url . "'"); Logger::notice("INFO: Device-URL for user '" . local_user() . "' has been updated with '" . $device_url . "'");
return "Device-URL updated successfully!"; return "Device-URL updated successfully!";
} }
@ -441,7 +434,7 @@ function windowsphonepush_updatecounterunseen()
function windowsphonepush_login(App $a) function windowsphonepush_login(App $a)
{ {
if (!isset($_SERVER['PHP_AUTH_USER'])) { if (!isset($_SERVER['PHP_AUTH_USER'])) {
Logger::log('API_login: ' . print_r($_SERVER, true), Logger::DEBUG); Logger::info('API_login: ' . print_r($_SERVER, true));
header('WWW-Authenticate: Basic realm="Friendica"'); header('WWW-Authenticate: Basic realm="Friendica"');
header('HTTP/1.0 401 Unauthorized'); header('HTTP/1.0 401 Unauthorized');
die('This api requires login'); die('This api requires login');
@ -452,7 +445,7 @@ function windowsphonepush_login(App $a)
if ($user_id) { if ($user_id) {
$record = DBA::selectFirst('user', [], ['uid' => $user_id]); $record = DBA::selectFirst('user', [], ['uid' => $user_id]);
} else { } else {
Logger::log('API_login failure: ' . print_r($_SERVER, true), Logger::DEBUG); Logger::info('API_login failure: ' . print_r($_SERVER, true));
header('WWW-Authenticate: Basic realm="Friendica"'); header('WWW-Authenticate: Basic realm="Friendica"');
header('HTTP/1.0 401 Unauthorized'); header('HTTP/1.0 401 Unauthorized');
die('This api requires login'); die('This api requires login');