Replacing "q" calls with "DBA" calls #1180

Merged
annando merged 8 commits from more-q into develop 2021-10-04 01:03:49 +02:00
9 changed files with 292 additions and 392 deletions

View file

@ -16,6 +16,7 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Post;
use Friendica\Model\Tag;
use Friendica\Model\User;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\XML;
@ -167,15 +168,9 @@ function dwpost_send(App $a, array &$b)
* Hopefully the person's Friendica account
* will be set to the same thing.
*/
$tz = 'UTC';
$x = q("SELECT `timezone` FROM `user` WHERE `uid` = %d LIMIT 1",
intval($b['uid'])
);
if (DBA::isResult($x) && !empty($x[0]['timezone'])) {
$tz = $x[0]['timezone'];
}
$user = User::getById($b['uid']);
$tz = $user['timezone'] ?: 'UTC';
$dw_username = DI::pConfig()->get($b['uid'],'dwpost','dw_username');
$dw_password = DI::pConfig()->get($b['uid'],'dwpost','dw_password');
@ -221,12 +216,12 @@ function dwpost_send(App $a, array &$b)
EOT;
Logger::log('dwpost: data: ' . $xml, Logger::DATA);
Logger::debug('dwpost: data: ' . $xml);
if ($dw_blog !== 'test') {
$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('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)
@ -89,10 +89,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",
DBA::escape('libravatar')
);
if (count($r)) {
if (DBA::exists('addon', ['name' => 'libravatar', 'installed' => true])) {
$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\DI;
use Friendica\Model\Tag;
use Friendica\Model\User;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\XML;
@ -162,15 +163,8 @@ function ijpost_send(&$a, &$b)
// Hopefully the person's Friendica account
// will be set to the same thing.
$tz = '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'];
}
$user = User::getById($b['uid']);
$tz = $user['timezone'] ?: 'UTC';
$ij_username = DI::pConfig()->get($b['uid'], 'ijpost', 'ij_username');
$ij_password = DI::pConfig()->get($b['uid'], 'ijpost', 'ij_password');
@ -216,11 +210,11 @@ function ijpost_send(&$a, &$b)
EOT;
Logger::log('ijpost: data: ' . $xml, Logger::DATA);
Logger::debug('ijpost: data: ' . $xml);
if ($ij_blog !== 'test') {
$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\Model\Post;
use Friendica\Model\Tag;
use Friendica\Model\User;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\XML;
@ -160,13 +161,8 @@ function ljpost_send(&$a,&$b) {
// Hopefully the person's Friendica account
// will be set to the same thing.
$tz = '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'];
$user = User::getById($b['uid']);
$tz = $user['timezone'] ?: 'UTC';
$lj_username = XML::escape(DI::pConfig()->get($b['uid'],'ljpost','lj_username'));
$lj_password = XML::escape(DI::pConfig()->get($b['uid'],'ljpost','lj_password'));
@ -231,11 +227,11 @@ function ljpost_send(&$a,&$b) {
EOT;
Logger::log('ljpost: data: ' . $xml, Logger::DATA);
Logger::debug('ljpost: data: ' . $xml);
if ($lj_blog !== 'test') {
$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\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\User;
@ -229,9 +230,8 @@ function mailstream_do_images(&$item, &$attachments)
*/
function mailstream_sender($item)
{
$r = q('SELECT * FROM `contact` WHERE `id` = %d', $item['contact-id']);
if (DBA::isResult($r)) {
$contact = $r[0];
$contact = Contact::getById($item['contact-id']);
if (DBA::isResult($contact)) {
if ($contact['name'] != $item['author-name']) {
return $contact['name'] . ' - ' . $item['author-name'];
}
@ -300,12 +300,8 @@ function mailstream_subject($item)
}
$parent = $parent_item['thr-parent'];
}
$r = q(
"SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d",
intval($item['contact-id']),
intval($item['uid'])
);
if (!DBA::isResult($r)) {
$contact = Contact::selectFirst([], ['id' => $item['contact-id'], 'uid' => $item['uid']]);
if (!DBA::isResult($contact)) {
Logger::error(
'mailstream_subject no contact for item',
['id' => $item['id'],
@ -315,7 +311,6 @@ function mailstream_subject($item)
);
return DI::l10n()->t("Friendica post");
}
$contact = $r[0];
if ($contact['network'] === 'dfrn') {
return DI::l10n()->t("Friendica post");
}
@ -444,20 +439,7 @@ function mailstream_html_wrap(&$text)
*/
function mailstream_convert_table_entries()
{
$query = <<< EOT
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)) {
$ms_item_ids = DBA::selectToArray('mailstream_item', [], ['message-id', 'uri', 'uid', 'contact-id'], ["`mailstream_item`.`completed` IS NULL"]);
Logger::debug('mailstream_convert_table_entries processing ' . count($ms_item_ids) . ' items');
foreach ($ms_item_ids as $ms_item_id) {
$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);
Hook::fork(PRIORITY_LOW, 'mailstream_send_hook', $send_hook_data);
}
}
q('DROP TABLE `mailstream_item`');
DBA::e('DROP TABLE `mailstream_item`');
}
/**

View file

@ -9,6 +9,7 @@
use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\Addon;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
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["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);
curl_setopt($ch, CURLOPT_HEADER, false);
@ -117,10 +118,10 @@ function pumpio_registerclient(App $a, $host)
if ($curl_info["http_code"] == "200") {
$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;
}
Logger::log("pumpio_registerclient: failed: ".print_r($curl_info, true), Logger::DEBUG);
Logger::info("pumpio_registerclient: failed: ".print_r($curl_info, true));
return false;
}
@ -133,7 +134,7 @@ function pumpio_connect(App $a)
$hostname = DI::pConfig()->get(local_user(), 'pumpio', 'host');
if ((($consumer_key == "") || ($consumer_secret == "")) && ($hostname != "")) {
Logger::log("pumpio_connect: register client");
Logger::notice("pumpio_connect: register client");
$clientdata = pumpio_registerclient($a, $hostname);
DI::pConfig()->set(local_user(), 'pumpio', 'consumer_key', $clientdata->client_id);
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_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 == "")) {
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);
}
@ -174,7 +175,7 @@ function pumpio_connect(App $a)
if (($success = $client->Initialize())) {
if (($success = $client->Process())) {
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_secret", $client->access_token_secret);
}
@ -186,11 +187,11 @@ function pumpio_connect(App $a)
}
if ($success) {
Logger::log("pumpio_connect: authenticated");
Logger::notice("pumpio_connect: authenticated");
$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>';
} 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.';
}
@ -391,7 +392,7 @@ function pumpio_hook_fork(App $a, array &$b)
if (DI::pConfig()->get($post['uid'], 'pumpio', 'import')) {
// 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])) {
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;
return;
}
@ -435,7 +436,7 @@ function pumpio_send(App $a, array &$b)
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']);
@ -445,7 +446,7 @@ function pumpio_send(App $a, array &$b)
$orig_post = Post::selectFirst([], $condition);
if (!DBA::isResult($orig_post)) {
Logger::log("pumpio_send: no pumpio post ".$b["parent"]);
Logger::notice("pumpio_send: no pumpio post ".$b["parent"]);
return;
} else {
$iscomment = true;
@ -455,7 +456,7 @@ function pumpio_send(App $a, array &$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'))) {
return;
@ -463,7 +464,7 @@ function pumpio_send(App $a, array &$b)
// 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]);
$self = User::getOwnerDataById($b['uid']);
if ($b['contact-id'] != $self['id']) {
return;
}
@ -587,13 +588,13 @@ function pumpio_send(App $a, array &$b)
}
$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) {
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']]);
}
} 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();
}
}
@ -659,18 +660,16 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "")
}
if ($success) {
Logger::log('pumpio_action '.$username.' '.$action.': success '.$uri);
Logger::notice('pumpio_action '.$username.' '.$action.': success '.$uri);
} else {
Logger::log('pumpio_action '.$username.' '.$action.': general error: '.$uri);
Logger::notice('pumpio_action '.$username.' '.$action.': general error: '.$uri);
Worker::defer();
}
}
function pumpio_sync(App $a)
{
$r = q("SELECT * FROM `addon` WHERE `installed` = 1 AND `name` = 'pumpio'");
if (!DBA::isResult($r)) {
if (!Addon::isEnabled('pumpio')) {
return;
}
@ -681,19 +680,17 @@ function pumpio_sync(App $a)
if ($last) {
$next = $last + ($poll_interval * 60);
if ($next > time()) {
Logger::log('pumpio: poll intervall not reached');
Logger::notice('pumpio: poll intervall not reached');
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() ");
if (DBA::isResult($r)) {
foreach ($r as $rr) {
Logger::log('pumpio: mirroring user '.$rr['uid']);
$pconfigs = DBA::selectToArray('pconfig', ['uid'], ['cat' => 'pumpio', 'k' => 'mirror', 'v' => '1']);
foreach ($pconfigs as $rr) {
Logger::notice('pumpio: mirroring user '.$rr['uid']);
pumpio_fetchtimeline($a, $rr['uid']);
}
}
$abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
if ($abandon_days < 1) {
@ -702,18 +699,16 @@ 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::isResult($r)) {
foreach ($r as $rr) {
$pconfigs = DBA::selectToArray('pconfig', ['uid'], ['cat' => 'pumpio', 'k' => 'import', 'v' => '1']);
foreach ($pconfigs 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::isResult($user)) {
Logger::log('abandoned account: timeline from user '.$rr['uid'].' will not be imported');
if (DBA::exists('user', ["uid = ? AND `login_date` >= ?", $rr['uid'], $abandon_limit])) {
Logger::notice('abandoned account: timeline from user '.$rr['uid'].' will not be imported');
continue;
}
}
Logger::log('pumpio: importing timeline from user '.$rr['uid']);
Logger::notice('pumpio: importing timeline from user '.$rr['uid']);
pumpio_fetchinbox($a, $rr['uid']);
// 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());
}
}
}
Logger::log('pumpio: cron_end');
Logger::notice('pumpio: cron_end');
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';
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;
@ -788,7 +782,7 @@ function pumpio_fetchtimeline(App $a, $uid)
}
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;
}
@ -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');
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;
if (Strings::compareLink($post->actor->url, $own_id)) {
$contactid = $self[0]['id'];
$contactid = $self['id'];
} else {
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
DBA::escape(Strings::normaliseLink($post->actor->url)),
intval($uid)
);
if (DBA::isResult($r)) {
$contactid = $r[0]['id'];
$contact = Contact::selectFirst([], ['nurl' => Strings::normaliseLink($post->actor->url), 'uid' => $uid, 'blocked' => false, 'readonly' => false]);
if (DBA::isResult($contact)) {
$contactid = $contact['id'];
}
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']]);
if (DBA::isResult($r)) {
Logger::log("pumpio_dounlike: unliked existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
if (DBA::isResult($contact)) {
Logger::notice("pumpio_dounlike: unliked existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
} 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)
{
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;
}
@ -937,18 +927,14 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion =
$contactid = 0;
if (Strings::compareLink($post->actor->url, $own_id)) {
$contactid = $self[0]['id'];
$post->actor->displayName = $self[0]['name'];
$post->actor->url = $self[0]['url'];
$post->actor->image->url = $self[0]['photo'];
$contactid = $self['id'];
$post->actor->displayName = $self['name'];
$post->actor->url = $self['url'];
$post->actor->image->url = $self['photo'];
} else {
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
DBA::escape(Strings::normaliseLink($post->actor->url)),
intval($uid)
);
if (DBA::isResult($r)) {
$contactid = $r[0]['id'];
$contact = Contact::selectFirst([], ['nurl' => Strings::normaliseLink($post->actor->url), 'uid' => $uid, 'blocked' => false, 'readonly' => false]);
if (DBA::isResult($contact)) {
$contactid = $contact['id'];
}
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']];
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;
}
@ -992,7 +978,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion =
$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)
@ -1003,58 +989,42 @@ function pumpio_get_contact($uid, $contact, $no_insert = false)
return $cid;
}
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1",
intval($uid), DBA::escape(Strings::normaliseLink($contact->url)));
$r = Contact::selectFirst([], ['uid' => $uid, 'nurl' => Strings::normaliseLink($contact->url)]);
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`,
`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),
DBA::escape(DateTimeFormat::utcNow()),
DBA::escape($contact->url),
DBA::escape(Strings::normaliseLink($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(Protocol::PUMPIO),
intval(Contact::FRIEND),
intval(1),
DBA::escape($contact->location->displayName),
DBA::escape($contact->summary),
intval(1)
);
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
DBA::escape(Strings::normaliseLink($contact->url)),
intval($uid)
);
Contact::insert([
'uid' => $uid,
'created' => DateTimeFormat::utcNow(),
'url' => $contact->url,
'nurl' => Strings::normaliseLink($contact->url),
'addr' => str_replace("acct:", "", $contact->id),
'alias' => '',
'notify' => $contact->id,
'poll' => 'pump.io ' . $contact->id,
'name' => $contact->displayName,
'nick' => $contact->preferredUsername,
'photo' => $contact->image->url,
'network' => Protocol::PUMPIO,
'rel' => Contact::FRIEND,
'priority' => 1,
'location' => $contact->location->displayName,
'about' => $contact->summary,
'writable' => 1,
'blocked' => 0,
'readonly' => 0,
'pending' => 0
]);
$r = Contact::selectFirst([], ['uid' => $uid, 'nurl' => Strings::normaliseLink($contact->url)]);
if (!DBA::isResult($r)) {
return false;
}
$contact_id = $r[0]['id'];
$contact_id = $r['id'];
Group::addMember(User::getDefaultGroup($uid), $contact_id);
} else {
$contact_id = $r[0]["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'])
);
*/
$contact_id = $r["id"];
}
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);
if (!$contact_id) {
$contact_id = $self[0]['id'];
$contact_id = $self['id'];
}
$postarray['thr-parent'] = $post->object->id;
if (!$public) {
$postarray['private'] = 1;
$postarray['allow_cid'] = '<' . $self[0]['id'] . '>';
$postarray['allow_cid'] = '<' . $self['id'] . '>';
}
} else {
$contact_id = pumpio_get_contact($uid, $post->actor, true);
if (Strings::compareLink($post->actor->url, $own_id)) {
$contact_id = $self[0]['id'];
$post->actor->displayName = $self[0]['name'];
$post->actor->url = $self[0]['url'];
$post->actor->image->url = $self[0]['photo'];
$contact_id = $self['id'];
$post->actor->displayName = $self['name'];
$post->actor->url = $self['url'];
$post->actor->image->url = $self['photo'];
} 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",
DBA::escape(Strings::normaliseLink($post->actor->url)),
intval($uid)
);
if (DBA::isResult($r)) {
$contact_id = $r[0]['id'];
$contact = Contact::selectFirst([], ['nurl' => Strings::normaliseLink($post->actor->url), 'uid' => $uid, 'blocked' => false, 'readonly' => false]);
if (DBA::isResult($contact)) {
$contact_id = $contact['id'];
} else {
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
DBA::escape(Strings::normaliseLink($post->actor->url)),
intval($uid)
);
if (DBA::isResult($r)) {
$contact_id = $r[0]['id'];
} else {
$contact_id = $self[0]['id'];
}
$contact_id = $self['id'];
}
}
@ -1299,8 +1256,7 @@ function pumpio_fetchinbox(App $a, $uid)
$own_id = "https://".$hostname."/".$username;
$self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
intval($uid));
$self = User::getOwnerDataById($uid);
$lastitems = q("SELECT `uri` FROM `post-thread-user`
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) {
$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",
intval($cid),
intval($b["uid"]),
DBA::escape(Protocol::PUMPIO)
);
if (DBA::isResult($r)) {
$contact = Contact::selectFirst(['name', 'nick', 'url'], ['id' => $cid, 'uid' => $b["uid"], 'network' => Protocol::PUMPIO, 'blocked' => false, 'readonly' => false]);
if (DBA::isResult($contact)) {
$receiver["bcc"][] = [
"displayName" => $r[0]["name"],
"displayName" => $contact["name"],
"objectType" => "person",
"preferredUsername" => $r[0]["nick"],
"url" => $r[0]["url"]];
"preferredUsername" => $contact["nick"],
"url" => $contact["url"]];
}
}
foreach ($gids AS $gid) {
@ -1470,18 +1421,13 @@ function pumpio_getreceiver(App $a, array $b)
$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",
intval($cid),
intval($b["uid"]),
DBA::escape(Protocol::PUMPIO)
);
if (DBA::isResult($r)) {
$contact = Contact::selectFirst(['name', 'nick', 'url'], ['id' => $cid, 'uid' => $b["uid"], 'network' => Protocol::PUMPIO, 'blocked' => false, 'readonly' => false]);
if (DBA::isResult($contact)) {
$receiver["to"][] = [
"displayName" => $r[0]["name"],
"displayName" => $contact["name"],
"objectType" => "person",
"preferredUsername" => $r[0]["nick"],
"url" => $r[0]["url"]];
"preferredUsername" => $contact["nick"],
"url" => $contact["url"]];
}
}
}
@ -1498,12 +1444,11 @@ function pumpio_fetchallcomments(App $a, $uid, $id)
$hostname = DI::pConfig()->get($uid, 'pumpio', 'host');
$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;
$self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
intval($uid));
$self = User::getOwnerDataById($uid);
// Fetching the original post
$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_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)) {
$success = $client->CallAPI($url, 'GET', [], ['FailOnAccessError'=>true], $item);
@ -1587,7 +1532,7 @@ function pumpio_fetchallcomments(App $a, $uid, $id)
$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);
}
}

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);
}

View file

@ -8,7 +8,6 @@
*/
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
@ -17,7 +16,7 @@ use Friendica\DI;
function widgets_install() {
Hook::register('addon_settings', 'addon/widgets/widgets.php', 'widgets_settings');
Hook::register('addon_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post');
Logger::log("installed widgets");
Logger::notice("installed widgets");
}
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_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 */
@ -135,9 +135,8 @@ function windowsphonepush_settings(&$a, &$s)
function windowsphonepush_cron()
{
// 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");
if (count($r)) {
foreach ($r as $rr) {
$pconfigs = DBA::selectToArray('pconfig', ['uid'], ['cat' => 'windowsphonepush', 'k' => 'enable', 'v' => true]);
foreach ($pconfigs as $rr) {
// load stored information for the user-id of the current loop
$device_url = DI::pConfig()->get($rr['uid'], 'windowsphonepush', 'device_url');
$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)
if (( $device_url == "" ) || ( $device_url == "NA" )) {
// 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 {
// 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)
@ -163,11 +162,11 @@ function windowsphonepush_cron()
break;
case "QueueFull":
// 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;
case "Suppressed":
// 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;
case "Dropped":
// 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:
// error, mostly called by "" which means that the url (not "" which has been checked)
// 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)
@ -222,7 +221,6 @@ function windowsphonepush_cron()
}
}
}
}
}
/* 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');
if ($subscriptionStatus == "Expired") {
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
@ -393,7 +391,7 @@ function windowsphonepush_updatesettings()
// check if sent url is empty - don't save and send return code to app
$device_url = $_POST['deviceurl'];
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";
}
@ -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
// 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)
$r = q("SELECT * FROM `pconfig` WHERE `uid` <> " . local_user() . " AND
`cat` = 'windowsphonepush' AND
`k` = 'device_url' AND
`v` = '" . $device_url . "'");
if (count($r)) {
foreach ($r as $rr) {
$pconfigs = DBA::selectToArray('pconfig', ['uid'], ["`uid` != ? AND `cat` = ? AND `k` = ? AND `v` = ?", local_user(), 'windowsphonepush', 'device_url', $device_url]);
foreach ($pconfigs as $rr) {
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);
// 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!";
}
@ -441,7 +434,7 @@ function windowsphonepush_updatecounterunseen()
function windowsphonepush_login(App $a)
{
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('HTTP/1.0 401 Unauthorized');
die('This api requires login');
@ -452,7 +445,7 @@ function windowsphonepush_login(App $a)
if ($user_id) {
$record = DBA::selectFirst('user', [], ['uid' => $user_id]);
} 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('HTTP/1.0 401 Unauthorized');
die('This api requires login');