X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=windowsphonepush%2Fwindowsphonepush.php;h=908eeb31e6de037e3e632c5362a2cd6beed64367;hb=70617811eb3daa18b1f9df95e9efd4c1a6b65e11;hp=30c6cf60f399642b1e705d5d017a1b6a3400965f;hpb=2394700e29d184f1bd6d5403387b3c4293a58940;p=friendica-addons.git diff --git a/windowsphonepush/windowsphonepush.php b/windowsphonepush/windowsphonepush.php index 30c6cf60..908eeb31 100644 --- a/windowsphonepush/windowsphonepush.php +++ b/windowsphonepush/windowsphonepush.php @@ -30,11 +30,9 @@ use Friendica\App; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; use Friendica\Core\Hook; -use Friendica\Core\L10n; use Friendica\Core\Logger; -use Friendica\Core\PConfig; -use Friendica\Core\Session; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\User; @@ -57,18 +55,6 @@ function windowsphonepush_install() Logger::log("installed windowsphonepush"); } -function windowsphonepush_uninstall() -{ - /* uninstall unregisters any hooks created with register_hook - * during install. Don't delete data in table `pconfig`. - */ - Hook::unregister('cron', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_cron'); - Hook::unregister('addon_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings'); - Hook::unregister('addon_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post'); - - Logger::log("removed windowsphonepush"); -} - /* declare the windowsphonepush function so that /windowsphonepush url requests will land here */ function windowsphonepush_module() { @@ -86,15 +72,13 @@ function windowsphonepush_settings_post($a, $post) return; } $enable = intval($_POST['windowsphonepush']); - PConfig::set(local_user(), 'windowsphonepush', 'enable', $enable); + DI::pConfig()->set(local_user(), 'windowsphonepush', 'enable', $enable); if ($enable) { - PConfig::set(local_user(), 'windowsphonepush', 'counterunseen', 0); + DI::pConfig()->set(local_user(), 'windowsphonepush', 'counterunseen', 0); } - PConfig::set(local_user(), 'windowsphonepush', 'senditemtext', intval($_POST['windowsphonepush-senditemtext'])); - - info(L10n::t('WindowsPhonePush settings updated.') . EOL); + DI::pConfig()->set(local_user(), 'windowsphonepush', 'senditemtext', intval($_POST['windowsphonepush-senditemtext'])); } /* Called from the Addon Setting form. @@ -107,33 +91,33 @@ function windowsphonepush_settings(&$a, &$s) } /* Add our stylesheet to the page so we can make our settings look nice */ - $a->page['htmlhead'] .= '' . "\r\n"; + DI::page()['htmlhead'] .= '' . "\r\n"; /* Get the current state of our config variables */ - $enabled = PConfig::get(local_user(), 'windowsphonepush', 'enable'); + $enabled = DI::pConfig()->get(local_user(), 'windowsphonepush', 'enable'); $checked_enabled = (($enabled) ? ' checked="checked" ' : ''); - $senditemtext = PConfig::get(local_user(), 'windowsphonepush', 'senditemtext'); + $senditemtext = DI::pConfig()->get(local_user(), 'windowsphonepush', 'senditemtext'); $checked_senditemtext = (($senditemtext) ? ' checked="checked" ' : ''); - $device_url = PConfig::get(local_user(), 'windowsphonepush', 'device_url'); + $device_url = DI::pConfig()->get(local_user(), 'windowsphonepush', 'device_url'); /* Add some HTML to the existing form */ $s .= '
'; - $s .= '

' . L10n::t('WindowsPhonePush Settings') . '

'; + $s .= '

' . DI::l10n()->t('WindowsPhonePush Settings') . '

'; $s .= '
'; - $s .= ''; + $s .= ''; $s .= ''; $s .= '
'; $s .= '
'; - $s .= ''; + $s .= ''; $s .= ''; $s .= '
'; /* provide a submit button - enable und senditemtext can be changed by the user */ - $s .= '
'; + $s .= '
'; /* provide further read-only information concerning the addon (useful for */ $s .= '
'; @@ -154,8 +138,8 @@ function windowsphonepush_cron() if (count($r)) { foreach ($r as $rr) { // load stored information for the user-id of the current loop - $device_url = PConfig::get($rr['uid'], 'windowsphonepush', 'device_url'); - $lastpushid = PConfig::get($rr['uid'], 'windowsphonepush', 'lastpushid'); + $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) @@ -174,7 +158,7 @@ function windowsphonepush_cron() switch (trim($res_tile)) { case "Received": // ok, count has been pushed, let's save it in personal settings - PConfig::set($rr['uid'], 'windowsphonepush', 'counterunseen', $count[0]['count']); + 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 @@ -197,7 +181,7 @@ function windowsphonepush_cron() 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 = PConfig::get($rr['uid'], 'windowsphonepush', 'senditemtext'); + $senditemtext = DI::pConfig()->get($rr['uid'], 'windowsphonepush', 'senditemtext'); if ($senditemtext == 1) { // load item with the max id $item = Item::selectFirst(['author-name', 'body'], ['id' => $count[0]['max']]); @@ -216,7 +200,7 @@ function windowsphonepush_cron() if (substr($body, 0, 4) == "[url") { $body = "URL/Image ..."; } else { - $body = BBCode::convert($body, false, 2, true); + $body = BBCode::convert($body, false, BBCode::API, true); $body = HTML::toPlaintext($body, 0); $body = ((strlen($body) > 137) ? substr($body, 0, 137) . "..." : $body); } @@ -232,7 +216,7 @@ function windowsphonepush_cron() // 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') { - PConfig::set($rr['uid'], 'windowsphonepush', 'lastpushid', $count[0]['max']); + DI::pConfig()->set($rr['uid'], 'windowsphonepush', 'lastpushid', $count[0]['max']); } } } @@ -306,7 +290,7 @@ function send_push($device_url, $headers, $msg) // and log this fact $subscriptionStatus = get_header_value($output, 'X-SubscriptionStatus'); if ($subscriptionStatus == "Expired") { - PConfig::set(local_user(), 'windowsphonepush', 'device_url', ""); + DI::pConfig()->set(local_user(), 'windowsphonepush', 'device_url', ""); Logger::log("ERROR: the stored Device-URL " . $device_url . "returned an 'Expired' error, it has been deleted now."); } @@ -365,11 +349,11 @@ function windowsphonepush_showsettings() return; } - $enable = PConfig::get(local_user(), 'windowsphonepush', 'enable'); - $device_url = PConfig::get(local_user(), 'windowsphonepush', 'device_url'); - $senditemtext = PConfig::get(local_user(), 'windowsphonepush', 'senditemtext'); - $lastpushid = PConfig::get(local_user(), 'windowsphonepush', 'lastpushid'); - $counterunseen = PConfig::get(local_user(), 'windowsphonepush', 'counterunseen'); + $enable = DI::pConfig()->get(local_user(), 'windowsphonepush', 'enable'); + $device_url = DI::pConfig()->get(local_user(), 'windowsphonepush', 'device_url'); + $senditemtext = DI::pConfig()->get(local_user(), 'windowsphonepush', 'senditemtext'); + $lastpushid = DI::pConfig()->get(local_user(), 'windowsphonepush', 'lastpushid'); + $counterunseen = DI::pConfig()->get(local_user(), 'windowsphonepush', 'counterunseen'); $addonversion = "2.0"; if (!$device_url) { @@ -400,7 +384,7 @@ function windowsphonepush_updatesettings() } // no updating if user hasn't enabled the addon - $enable = PConfig::get(local_user(), 'windowsphonepush', 'enable'); + $enable = DI::pConfig()->get(local_user(), 'windowsphonepush', 'enable'); if (!$enable) { return "Plug-in not enabled"; } @@ -422,12 +406,12 @@ function windowsphonepush_updatesettings() `v` = '" . $device_url . "'"); if (count($r)) { foreach ($r as $rr) { - PConfig::set($rr['uid'], 'windowsphonepush', 'device_url', ''); + DI::pConfig()->set($rr['uid'], 'windowsphonepush', 'device_url', ''); Logger::log("WARN: the sent URL was already registered with user '" . $rr['uid'] . "'. Deleted for this user as we expect to be correct now for user '" . local_user() . "'."); } } - PConfig::set(local_user(), 'windowsphonepush', 'device_url', $device_url); + DI::pConfig()->set(local_user(), 'windowsphonepush', 'device_url', $device_url); // output the successfull update of the device URL to the logger for error analysis if necessary Logger::log("INFO: Device-URL for user '" . local_user() . "' has been updated with '" . $device_url . "'"); return "Device-URL updated successfully!"; @@ -441,12 +425,12 @@ function windowsphonepush_updatecounterunseen() } // no updating if user hasn't enabled the addon - $enable = PConfig::get(local_user(), 'windowsphonepush', 'enable'); + $enable = DI::pConfig()->get(local_user(), 'windowsphonepush', 'enable'); if (!$enable) { return "Plug-in not enabled"; } - PConfig::set(local_user(), 'windowsphonepush', 'counterunseen', 0); + DI::pConfig()->set(local_user(), 'windowsphonepush', 'counterunseen', 0); return "Counter set to zero"; } @@ -473,7 +457,7 @@ function windowsphonepush_login(App $a) die('This api requires login'); } - Session::setAuthenticatedForUser($a, $record); - $_SESSION["allow_api"] = true; + DI::auth()->setForUser($a, $record); + DI::session()->set('allow_api', true); Hook::callAll('logged_in', $a->user); }