* Pre-requisite: Windows Phone mobile device (at least WP 7.0)
* Friendica mobile app on Windows Phone
*
- * When plugin is installed, the system calls the plugin
+ * When addon is installed, the system calls the addon
* name_install() function, located in 'addon/name/name.php',
* where 'name' is the name of the addon.
* If the addon is removed from the configuration list, the
* sets the counter back
* count only unseen elements which are not type=activity (likes and dislikes not seen as new elements)
*/
+
use Friendica\App;
+use Friendica\Content\Text\BBCode;
+use Friendica\Content\Text\HTML;
+use Friendica\Core\Addon;
+use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Model\User;
+use Friendica\Model\Item;
function windowsphonepush_install()
{
- /* Our plugin will attach in three places.
+ /* Our addon will attach in three places.
* The first is within cron - so the push notifications will be
* sent every 10 minutes (or whatever is set in crontab).
*/
- register_hook('cron', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_cron');
+ Addon::registerHook('cron', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_cron');
- /* Then we'll attach into the plugin settings page, and also the
+ /* Then we'll attach into the addon settings page, and also the
* settings post hook so that we can create and update
- * user preferences. User shall be able to activate the plugin and
+ * user preferences. User shall be able to activate the addon and
* define whether he allows pushing first characters of item text
*/
- register_hook('plugin_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings');
- register_hook('plugin_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post');
+ Addon::registerHook('addon_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings');
+ Addon::registerHook('addon_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post');
logger("installed windowsphonepush");
}
/* uninstall unregisters any hooks created with register_hook
* during install. Don't delete data in table `pconfig`.
*/
- unregister_hook('cron', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_cron');
- unregister_hook('plugin_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings');
- unregister_hook('plugin_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post');
+ Addon::unregisterHook('cron', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_cron');
+ Addon::unregisterHook('addon_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings');
+ Addon::unregisterHook('addon_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post');
logger("removed windowsphonepush");
}
PConfig::set(local_user(), 'windowsphonepush', 'senditemtext', intval($_POST['windowsphonepush-senditemtext']));
- info(t('WindowsPhonePush settings updated.') . EOL);
+ info(L10n::t('WindowsPhonePush settings updated.') . EOL);
}
-/* Called from the Plugin Setting form.
+/* Called from the Addon Setting form.
* Add our own settings info to the page.
*/
function windowsphonepush_settings(&$a, &$s)
/* Add some HTML to the existing form */
$s .= '<div class="settings-block">';
- $s .= '<h3>' . t('WindowsPhonePush Settings') . '</h3>';
+ $s .= '<h3>' . L10n::t('WindowsPhonePush Settings') . '</h3>';
$s .= '<div id="windowsphonepush-enable-wrapper">';
- $s .= '<label id="windowsphonepush-enable-label" for="windowsphonepush-enable-chk">' . t('Enable WindowsPhonePush Plugin') . '</label>';
+ $s .= '<label id="windowsphonepush-enable-label" for="windowsphonepush-enable-chk">' . L10n::t('Enable WindowsPhonePush Addon') . '</label>';
$s .= '<input id="windowsphonepush-enable-chk" type="checkbox" name="windowsphonepush" value="1" ' . $checked_enabled . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="windowsphonepush-senditemtext-wrapper">';
- $s .= '<label id="windowsphonepush-senditemtext-label" for="windowsphonepush-senditemtext-chk">' . t('Push text of new item') . '</label>';
+ $s .= '<label id="windowsphonepush-senditemtext-label" for="windowsphonepush-senditemtext-chk">' . L10n::t('Push text of new item') . '</label>';
$s .= '<input id="windowsphonepush-senditemtext-chk" type="checkbox" name="windowsphonepush-senditemtext" value="1" ' . $checked_senditemtext . '/>';
$s .= '</div><div class="clear"></div>';
/* provide a submit button - enable und senditemtext can be changed by the user */
- $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="windowsphonepush-submit" name="windowsphonepush-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div><div class="clear"></div>';
+ $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="windowsphonepush-submit" name="windowsphonepush-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div><div class="clear"></div>';
/* provide further read-only information concerning the addon (useful for */
$s .= '<div id="windowsphonepush-device_url-wrapper">';
return;
}
-/* Cron function used to regularly check all users on the server with active windowsphonepushplugin and send
+/* Cron function used to regularly check all users on the server with active windowsphonepushaddon and send
* notifications to the Microsoft servers and consequently to the Windows Phone device
*/
function windowsphonepush_cron()
{
- // retrieve all UID's for which the plugin windowsphonepush is enabled and loop through every user
+ // retrieve all UID's for which the addon windowsphonepush is enabled and loop through every user
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'windowsphonepush' AND `k` = 'enable' AND `v` = 1");
if (count($r)) {
foreach ($r as $rr) {
// 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 plugin is enabled --> write info to Logger
+ // no Device-URL for the user availabe, but addon is enabled --> write info to Logger
logger("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
$senditemtext = PConfig::get($rr['uid'], 'windowsphonepush', 'senditemtext');
if ($senditemtext == 1) {
// load item with the max id
- $item = q("SELECT `author-name` as author, `body` as body FROM `item` where `id` = %d", intval($count[0]['max']));
+ $item = Item::selectFirst(local_user(), ['author-name', 'body'], ['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[0]['author'];
+ $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[0]['body'];
+ $body = $item['body'];
if (substr($body, 0, 4) == "[url") {
$body = "URL/Image ...";
} else {
- require_once('include/bbcode.php');
- require_once("include/html2plain.php");
- $body = bbcode($body, false, false, 2, true);
- $body = html2plain($body, 0);
+ $body = BBCode::convert($body, false, 2, true);
+ $body = HTML::toPlaintext($body, 0);
$body = ((strlen($body) > 137) ? substr($body, 0, 137) . "..." : $body);
}
} else {
"</wp:Tile> " .
"</wp:Notification>";
- $result = send_push($device_url, array(
+ $result = send_push($device_url, [
'X-WindowsPhone-Target: token',
'X-NotificationClass: ' . $priority,
- ), $msg);
+ ], $msg);
return $result;
}
"</wp:Toast>" .
"</wp:Notification>";
- $result = send_push($device_url, array(
+ $result = send_push($device_url, [
'X-WindowsPhone-Target: toast',
'X-NotificationClass: ' . $priority,
- ), $msg);
+ ], $msg);
return $result;
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers + array(
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers + [
'Content-Type: text/xml',
'charset=utf-8',
'Accept: application/*',
- )
+ ]
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $msg);
case "update_settings":
$ret = windowsphonepush_updatesettings($a);
header("Content-Type: application/json; charset=utf-8");
- echo json_encode(array('status' => $ret));
+ echo json_encode(['status' => $ret]);
killme();
break;
case "update_counterunseen":
$ret = windowsphonepush_updatecounterunseen();
header("Content-Type: application/json; charset=utf-8");
- echo json_encode(array('status' => $ret));
+ echo json_encode(['status' => $ret]);
killme();
break;
default:
}
header("Content-Type: application/json");
- echo json_encode(array('uid' => local_user(),
+ echo json_encode(['uid' => local_user(),
'enable' => $enable,
'device_url' => $device_url,
'senditemtext' => $senditemtext,
'lastpushid' => $lastpushid,
'counterunseen' => $counterunseen,
- 'addonversion' => $addonversion));
+ 'addonversion' => $addonversion]);
}
/* update_settings is used to transfer the device_url from WP device to the Friendica server
return "Not Authenticated";
}
- // no updating if user hasn't enabled the plugin
+ // no updating if user hasn't enabled the addon
$enable = PConfig::get(local_user(), 'windowsphonepush', 'enable');
if (!$enable) {
return "Plug-in not enabled";
return "Not Authenticated";
}
- // no updating if user hasn't enabled the plugin
+ // no updating if user hasn't enabled the addon
$enable = PConfig::get(local_user(), 'windowsphonepush', 'enable');
if (!$enable) {
return "Plug-in not enabled";
$user_id = User::authenticate($_SERVER['PHP_AUTH_USER'], trim($_SERVER['PHP_AUTH_PW']));
if ($user_id) {
- $record = dba::select('user', [], ['uid' => $user_id], ['limit' => 1]);
+ $record = dba::selectFirst('user', [], ['uid' => $user_id]);
} else {
logger('API_login failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
header('WWW-Authenticate: Basic realm="Friendica"');
require_once 'include/security.php';
authenticate_success($record);
$_SESSION["allow_api"] = true;
- call_hooks('logged_in', $a->user);
+ Addon::callHooks('logged_in', $a->user);
}