use Friendica\DI;
use Friendica\Model\Post;
use Friendica\Model\Tag;
+use Friendica\Model\User;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\XML;
* 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');
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 : '');
}
}
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)
];
// 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>';
}
use Friendica\Core\Logger;
use Friendica\DI;
use Friendica\Model\Tag;
+use Friendica\Model\User;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\XML;
// 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');
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 : '');
}
}
use Friendica\DI;
use Friendica\Model\Post;
use Friendica\Model\Tag;
+use Friendica\Model\User;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\XML;
// 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'));
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 : '');
}
}
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;
*/
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'];
}
}
$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'],
);
return DI::l10n()->t("Friendica post");
}
- $contact = $r[0];
if ($contact['network'] === 'dfrn') {
return DI::l10n()->t("Friendica post");
}
*/
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);
+ $ms_item_ids = DBA::selectToArray('mailstream_item', ['message-id', 'uri', 'uid', 'contact-id'], ["`mailstream_item`.`completed` IS NULL"]);
if (DBA::isResult($ms_item_ids)) {
Logger::debug('mailstream_convert_table_entries processing ' . count($ms_item_ids) . ' items');
foreach ($ms_item_ids as $ms_item_id) {
Hook::fork(PRIORITY_LOW, 'mailstream_send_hook', $send_hook_data);
}
}
- q('DROP TABLE `mailstream_item`');
+ DBA::e('DROP TABLE `mailstream_item`');
}
/**
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;
$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);
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;
}
$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);
$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);
}
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);
}
}
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.';
}
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;
}
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']);
$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;
$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;
// 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;
}
}
$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();
}
}
}
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;
}
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', ['cat' => 'pumpio', 'k' => 'mirror', 'v' => '1']);
+ if (DBA::isResult($pconfigs)) {
+ foreach ($pconfigs as $rr) {
+ Logger::notice('pumpio: mirroring user '.$rr['uid']);
pumpio_fetchtimeline($a, $rr['uid']);
}
}
$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', ['cat' => 'pumpio', 'k' => 'import', 'v' => '1']);
+ if (DBA::isResult($pconfigs)) {
+ 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
}
}
- Logger::log('pumpio: cron_end');
+ Logger::notice('pumpio: cron_end');
DI::config()->set('pumpio', 'last_poll', time());
}
$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;
}
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;
}
}
}
- 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);
}
}
}
$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) {
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;
}
$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) {
$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;
}
$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)
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)) {
$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'];
}
}
$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`
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) {
$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"]];
}
}
}
$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];
$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);
$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);
}
}
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)
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;
}
$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":
$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)
$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;
$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;
}
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
return;
}
- Logger::log('GNU Socialpost invoked');
+ Logger::notice('GNU Socialpost invoked');
DI::pConfig()->load($b['uid'], 'statusnet');
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
$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']]);
}
}
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']);
}
}
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());
}
//print_r($_REQUEST);
if ($_REQUEST["body"] != "") {
- Logger::log('statusnet: posting for user ' . $uid);
+ Logger::notice('statusnet: posting for user ' . $uid);
item_post($a);
}
}
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;
}
// 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']);
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);
$postarray["coord"] = $content->coordinates->coordinates[1] . " " . $content->coordinates->coordinates[0];
}
- Logger::log("statusnet_createpost: end", Logger::DEBUG);
+ Logger::info("statusnet_createpost: end");
return $postarray;
}
// "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);
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;
}
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;
}
$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) {
$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);
}
}
}
$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) {
$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);
}
}
}
$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);
}
}
}
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]);
$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;
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);
}
*/
use Friendica\Core\Hook;
-use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
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(){
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 */
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) {
- // 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');
-
- // pushing only possible if device_url (the URI on Microsoft server) is available or not "NA" (which will be sent
- // 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.");
- } 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)
- $count = q("SELECT count(`id`) as count, max(`id`) as max FROM `post-view` WHERE `unseen` = 1 AND `type` <> 'activity' AND `uid` = %d", intval($rr['uid']));
-
- // send number of unseen items to the device (the number will be displayed on Start screen until
- // App will be started by user) - this update will be sent every 10 minutes to update the number to 0 if
- // user has loaded the timeline through app or website
- $res_tile = send_tile_update($device_url, "", $count[0]['count'], "");
- switch (trim($res_tile)) {
- case "Received":
- // ok, count has been pushed, let's save it in personal settings
- DI::pConfig()->set($rr['uid'], 'windowsphonepush', 'counterunseen', $count[0]['count']);
- 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.");
- 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?");
- break;
- case "Dropped":
- // mostly combines with Expired, in that case Device-URL will be deleted from pconfig (function send_push)
- break;
- 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.");
- }
+ $pconfigs = DBA::selectToArray('pconfig', ['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');
+
+ // pushing only possible if device_url (the URI on Microsoft server) is available or not "NA" (which will be sent
+ // 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::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)
+ $count = q("SELECT count(`id`) as count, max(`id`) as max FROM `post-view` WHERE `unseen` = 1 AND `type` <> 'activity' AND `uid` = %d", intval($rr['uid']));
+
+ // send number of unseen items to the device (the number will be displayed on Start screen until
+ // App will be started by user) - this update will be sent every 10 minutes to update the number to 0 if
+ // user has loaded the timeline through app or website
+ $res_tile = send_tile_update($device_url, "", $count[0]['count'], "");
+ switch (trim($res_tile)) {
+ case "Received":
+ // ok, count has been pushed, let's save it in personal settings
+ DI::pConfig()->set($rr['uid'], 'windowsphonepush', 'counterunseen', $count[0]['count']);
+ break;
+ case "QueueFull":
+ // maximum of 30 messages reached, server rejects any further push notification until device reconnects
+ 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::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)
+ break;
+ 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::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)
- if (intval($count[0]['max']) > intval($lastpushid)) {
- // user can define if he wants to see the text of the item in the push notification
- // this has been implemented as the device_url is not a https uri (not so secure)
- $senditemtext = DI::pConfig()->get($rr['uid'], 'windowsphonepush', 'senditemtext');
- if ($senditemtext == 1) {
- // load item with the max id
- $item = Post::selectFirst(['author-name', 'body', 'uri-id'], ['id' => $count[0]['max']]);
-
- // as user allows to send the item, we want to show the sender of the item in the toast
- // toasts are limited to one line, therefore place is limited - author shall be in
- // max. 15 chars (incl. dots); author is displayed in bold font
- $author = $item['author-name'];
- $author = ((strlen($author) > 12) ? substr($author, 0, 12) . "..." : $author);
-
- // normally we show the body of the item, however if it is an url or an image we cannot
- // show this in the toast (only test), therefore changing to an alternate text
- // Otherwise BBcode-Tags will be eliminated and plain text cutted to 140 chars (incl. dots)
- // BTW: information only possible in English
- $body = $item['body'];
- if (substr($body, 0, 4) == "[url") {
- $body = "URL/Image ...";
- } else {
- $body = BBCode::convertForUriId($item['uri-id'], $body, BBCode::API);
- $body = HTML::toPlaintext($body, 0);
- $body = ((strlen($body) > 137) ? substr($body, 0, 137) . "..." : $body);
- }
+ // additionally user receives the text of the newest item (function checks against last successfully pushed item)
+ if (intval($count[0]['max']) > intval($lastpushid)) {
+ // user can define if he wants to see the text of the item in the push notification
+ // this has been implemented as the device_url is not a https uri (not so secure)
+ $senditemtext = DI::pConfig()->get($rr['uid'], 'windowsphonepush', 'senditemtext');
+ if ($senditemtext == 1) {
+ // load item with the max id
+ $item = Post::selectFirst(['author-name', 'body', 'uri-id'], ['id' => $count[0]['max']]);
+
+ // as user allows to send the item, we want to show the sender of the item in the toast
+ // toasts are limited to one line, therefore place is limited - author shall be in
+ // max. 15 chars (incl. dots); author is displayed in bold font
+ $author = $item['author-name'];
+ $author = ((strlen($author) > 12) ? substr($author, 0, 12) . "..." : $author);
+
+ // normally we show the body of the item, however if it is an url or an image we cannot
+ // show this in the toast (only test), therefore changing to an alternate text
+ // Otherwise BBcode-Tags will be eliminated and plain text cutted to 140 chars (incl. dots)
+ // BTW: information only possible in English
+ $body = $item['body'];
+ if (substr($body, 0, 4) == "[url") {
+ $body = "URL/Image ...";
} else {
- // if user wishes higher privacy, we only display "Friendica - New timeline entry arrived"
- $author = "Friendica";
- $body = "New timeline entry arrived ...";
- }
- // only if toast push notification returns the Notification status "Received" we will update th settings with the
- // new indicator max-id is checked against (QueueFull, Suppressed, N/A, Dropped shall qualify to resend
- // the push notification some minutes later (BTW: if resulting in Expired for subscription status the
- // device_url will be deleted (no further try on this url, see send_push)
- // further log information done on count pushing with send_tile (see above)
- $res_toast = send_toast($device_url, $author, $body);
- if (trim($res_toast) === 'Received') {
- DI::pConfig()->set($rr['uid'], 'windowsphonepush', 'lastpushid', $count[0]['max']);
+ $body = BBCode::convertForUriId($item['uri-id'], $body, BBCode::API);
+ $body = HTML::toPlaintext($body, 0);
+ $body = ((strlen($body) > 137) ? substr($body, 0, 137) . "..." : $body);
}
+ } else {
+ // if user wishes higher privacy, we only display "Friendica - New timeline entry arrived"
+ $author = "Friendica";
+ $body = "New timeline entry arrived ...";
+ }
+ // only if toast push notification returns the Notification status "Received" we will update th settings with the
+ // new indicator max-id is checked against (QueueFull, Suppressed, N/A, Dropped shall qualify to resend
+ // the push notification some minutes later (BTW: if resulting in Expired for subscription status the
+ // device_url will be deleted (no further try on this url, see send_push)
+ // further log information done on count pushing with send_tile (see above)
+ $res_toast = send_toast($device_url, $author, $body);
+ if (trim($res_toast) === 'Received') {
+ DI::pConfig()->set($rr['uid'], 'windowsphonepush', 'lastpushid', $count[0]['max']);
}
}
}
$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
// 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";
}
// 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) {
- 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() . "'.");
- }
+ $pconfigs = DBA::selectToArray('pconfig', ["`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::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!";
}
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');
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');