X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=twitter%2Ftwitter.php;h=5168aa0ecfda12c57df03abcb4ea64f2ffa13173;hb=f1514063559930de791c0bff18a3f6ae4b455f7c;hp=807445b6de536fcb368760666d5f78017ea21c27;hpb=27b60e003f92dd9f3aebbeddb34ebb905488ca82;p=friendica-addons.git
diff --git a/twitter/twitter.php b/twitter/twitter.php
index 807445b6..5168aa0e 100644
--- a/twitter/twitter.php
+++ b/twitter/twitter.php
@@ -1,5 +1,4 @@
config['twitter']['consumerkey'] = 'your consumer_key here';
* $a->config['twitter']['consumersecret'] = 'your consumer_secret here';
*
- * To activate the plugin itself add it to the $a->config['system']['addon']
+ * To activate the addon itself add it to the $a->config['system']['addon']
* setting. After this, your user can configure their Twitter account settings
- * from "Settings -> Plugin Settings".
+ * from "Settings -> Addon Settings".
*
* Requirements: PHP5, curl [Slinky library]
*/
use Friendica\App;
use Friendica\Content\OEmbed;
+use Friendica\Content\Text\BBCode;
+use Friendica\Content\Text\Plaintext;
+use Friendica\Core\Addon;
use Friendica\Core\Config;
+use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\Worker;
use Friendica\Model\GContact;
use Friendica\Model\Group;
use Friendica\Model\Photo;
+use Friendica\Model\Queue;
use Friendica\Model\User;
use Friendica\Object\Image;
+use Friendica\Util\Network;
require_once 'include/enotify.php';
@@ -78,38 +83,38 @@ define('TWITTER_DEFAULT_POLL_INTERVAL', 5); // given in minutes
function twitter_install()
{
// we need some hooks, for the configuration and for sending tweets
- register_hook('connector_settings', 'addon/twitter/twitter.php', 'twitter_settings');
- register_hook('connector_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
- register_hook('post_local', 'addon/twitter/twitter.php', 'twitter_post_local');
- register_hook('notifier_normal', 'addon/twitter/twitter.php', 'twitter_post_hook');
- register_hook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets');
- register_hook('cron', 'addon/twitter/twitter.php', 'twitter_cron');
- register_hook('queue_predeliver', 'addon/twitter/twitter.php', 'twitter_queue_hook');
- register_hook('follow', 'addon/twitter/twitter.php', 'twitter_follow');
- register_hook('expire', 'addon/twitter/twitter.php', 'twitter_expire');
- register_hook('prepare_body', 'addon/twitter/twitter.php', 'twitter_prepare_body');
- register_hook('check_item_notification', 'addon/twitter/twitter.php', 'twitter_check_item_notification');
+ Addon::registerHook('connector_settings', 'addon/twitter/twitter.php', 'twitter_settings');
+ Addon::registerHook('connector_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
+ Addon::registerHook('post_local', 'addon/twitter/twitter.php', 'twitter_post_local');
+ Addon::registerHook('notifier_normal', 'addon/twitter/twitter.php', 'twitter_post_hook');
+ Addon::registerHook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets');
+ Addon::registerHook('cron', 'addon/twitter/twitter.php', 'twitter_cron');
+ Addon::registerHook('queue_predeliver', 'addon/twitter/twitter.php', 'twitter_queue_hook');
+ Addon::registerHook('follow', 'addon/twitter/twitter.php', 'twitter_follow');
+ Addon::registerHook('expire', 'addon/twitter/twitter.php', 'twitter_expire');
+ Addon::registerHook('prepare_body', 'addon/twitter/twitter.php', 'twitter_prepare_body');
+ Addon::registerHook('check_item_notification', 'addon/twitter/twitter.php', 'twitter_check_item_notification');
logger("installed twitter");
}
function twitter_uninstall()
{
- unregister_hook('connector_settings', 'addon/twitter/twitter.php', 'twitter_settings');
- unregister_hook('connector_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
- unregister_hook('post_local', 'addon/twitter/twitter.php', 'twitter_post_local');
- unregister_hook('notifier_normal', 'addon/twitter/twitter.php', 'twitter_post_hook');
- unregister_hook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets');
- unregister_hook('cron', 'addon/twitter/twitter.php', 'twitter_cron');
- unregister_hook('queue_predeliver', 'addon/twitter/twitter.php', 'twitter_queue_hook');
- unregister_hook('follow', 'addon/twitter/twitter.php', 'twitter_follow');
- unregister_hook('expire', 'addon/twitter/twitter.php', 'twitter_expire');
- unregister_hook('prepare_body', 'addon/twitter/twitter.php', 'twitter_prepare_body');
- unregister_hook('check_item_notification', 'addon/twitter/twitter.php', 'twitter_check_item_notification');
+ Addon::unregisterHook('connector_settings', 'addon/twitter/twitter.php', 'twitter_settings');
+ Addon::unregisterHook('connector_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
+ Addon::unregisterHook('post_local', 'addon/twitter/twitter.php', 'twitter_post_local');
+ Addon::unregisterHook('notifier_normal', 'addon/twitter/twitter.php', 'twitter_post_hook');
+ Addon::unregisterHook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets');
+ Addon::unregisterHook('cron', 'addon/twitter/twitter.php', 'twitter_cron');
+ Addon::unregisterHook('queue_predeliver', 'addon/twitter/twitter.php', 'twitter_queue_hook');
+ Addon::unregisterHook('follow', 'addon/twitter/twitter.php', 'twitter_follow');
+ Addon::unregisterHook('expire', 'addon/twitter/twitter.php', 'twitter_expire');
+ Addon::unregisterHook('prepare_body', 'addon/twitter/twitter.php', 'twitter_prepare_body');
+ Addon::unregisterHook('check_item_notification', 'addon/twitter/twitter.php', 'twitter_check_item_notification');
// old setting - remove only
- unregister_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook');
- unregister_hook('plugin_settings', 'addon/twitter/twitter.php', 'twitter_settings');
- unregister_hook('plugin_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
+ Addon::unregisterHook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook');
+ Addon::unregisterHook('addon_settings', 'addon/twitter/twitter.php', 'twitter_settings');
+ Addon::unregisterHook('addon_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
}
function twitter_check_item_notification(App $a, &$notification_data)
@@ -178,7 +183,7 @@ function twitter_jot_nets(App $a, &$b)
$tw_defpost = PConfig::get(local_user(), 'twitter', 'post_by_default');
$selected = ((intval($tw_defpost) == 1) ? ' checked="checked" ' : '');
$b .= '
'
- . t('Post to Twitter') . '
';
+ . L10n::t('Post to Twitter') . '';
}
}
@@ -239,7 +244,7 @@ function twitter_settings_post(App $a, $post)
PConfig::delete(local_user(), 'twitter', 'lastid');
}
- info(t('Twitter settings updated.') . EOL);
+ info(L10n::t('Twitter settings updated.') . EOL);
}
}
}
@@ -269,11 +274,11 @@ function twitter_settings(App $a, &$s)
$css = (($enabled) ? '' : '-disabled');
$s .= '';
$s .= '';
$s .= '
';
- $s .= '' . t('Twitter Import/Export/Mirror') . ' ';
+ $s .= '' . L10n::t('Twitter Import/Export/Mirror') . ' ';
$s .= ' ';
if ((!$ckey) && (!$csecret)) {
@@ -281,7 +286,7 @@ function twitter_settings(App $a, &$s)
* no global consumer keys
* display warning and skip personal config
*/
- $s .= '
' . t('No consumer key pair for Twitter found. Please contact your site administrator.') . '
';
+ $s .= '
' . L10n::t('No consumer key pair for Twitter found. Please contact your site administrator.') . '
';
} else {
/* * *
* ok we have a consumer key pair now look into the OAuth stuff
@@ -300,15 +305,15 @@ function twitter_settings(App $a, &$s)
/* * *
* make some nice form
*/
- $s .= '
' . t('At this Friendica instance the Twitter plugin was enabled but you have not yet connected your account to your Twitter account. To do so click the button below to get a PIN from Twitter which you have to copy into the input box below and submit the form. Only your public posts will be posted to Twitter.') . '
';
- $s .= '
';
+ $s .= '
' . L10n::t('At this Friendica instance the Twitter addon was enabled but you have not yet connected your account to your Twitter account. To do so click the button below to get a PIN from Twitter which you have to copy into the input box below and submit the form. Only your public posts will be posted to Twitter.') . '
';
+ $s .= '
';
$s .= '
';
- $s .= '
';
+ $s .= '
';
} else {
/* * *
* we have an OAuth key / secret pair for the user
@@ -321,8 +326,8 @@ function twitter_settings(App $a, &$s)
$field_checkbox = get_markup_template('field_checkbox.tpl');
$s .= '
';
@@ -420,8 +425,6 @@ function twitter_action(App $a, $uid, $pid, $action)
function twitter_post_hook(App $a, &$b)
{
// Post to Twitter
- require_once "include/network.php";
-
if (!PConfig::get($b["uid"], 'twitter', 'import')
&& ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))) {
return;
@@ -522,12 +525,11 @@ function twitter_post_hook(App $a, &$b)
$tweet = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
$max_char = 280;
- require_once "include/plaintext.php";
- $msgarr = plaintext($b, $max_char, true, 8);
+ $msgarr = BBCode::toPlaintext($b, $max_char, true, 8);
$msg = $msgarr["text"];
if (($msg == "") && isset($msgarr["title"])) {
- $msg = shortenmsg($msgarr["title"], $max_char - 50);
+ $msg = Plaintext::shorten($msgarr["title"], $max_char - 50);
}
$image = "";
@@ -542,7 +544,7 @@ function twitter_post_hook(App $a, &$b)
// and now tweet it :-)
if (strlen($msg) && ($image != "")) {
- $img_str = fetch_url($image);
+ $img_str = Network::fetchUrl($image);
$tempfile = tempnam(get_temppath(), "cache");
file_put_contents($tempfile, $img_str);
@@ -591,12 +593,11 @@ function twitter_post_hook(App $a, &$b)
if (strlen($msg) && ($image == "")) {
// -----------------
$max_char = 280;
- require_once "include/plaintext.php";
- $msgarr = plaintext($b, $max_char, true, 8);
+ $msgarr = BBCode::toPlaintext($b, $max_char, true, 8);
$msg = $msgarr["text"];
if (($msg == "") && isset($msgarr["title"])) {
- $msg = shortenmsg($msgarr["title"], $max_char - 50);
+ $msg = Plaintext::shorten($msgarr["title"], $max_char - 50);
}
if (isset($msgarr["url"])) {
@@ -626,9 +627,9 @@ function twitter_post_hook(App $a, &$b)
}
$s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $post]);
- require_once 'include/queue_fn.php';
- add_to_queue($a->contact, NETWORK_TWITTER, $s);
- notice(t('Twitter post failed. Queued for retry.') . EOL);
+
+ Queue::add($a->contact, NETWORK_TWITTER, $s);
+ notice(L10n::t('Twitter post failed. Queued for retry.') . EOL);
} elseif ($iscomment) {
logger('twitter_post: Update extid ' . $result->id_str . " for post id " . $b['id']);
q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d",
@@ -640,24 +641,24 @@ function twitter_post_hook(App $a, &$b)
}
}
-function twitter_plugin_admin_post(App $a)
+function twitter_addon_admin_post(App $a)
{
$consumerkey = x($_POST, 'consumerkey') ? notags(trim($_POST['consumerkey'])) : '';
$consumersecret = x($_POST, 'consumersecret') ? notags(trim($_POST['consumersecret'])) : '';
Config::set('twitter', 'consumerkey', $consumerkey);
Config::set('twitter', 'consumersecret', $consumersecret);
- info(t('Settings updated.') . EOL);
+ info(L10n::t('Settings updated.') . EOL);
}
-function twitter_plugin_admin(App $a, &$o)
+function twitter_addon_admin(App $a, &$o)
{
$t = get_markup_template("admin.tpl", "addon/twitter/");
$o = replace_macros($t, [
- '$submit' => t('Save Settings'),
+ '$submit' => L10n::t('Save Settings'),
// name, label, value, help, [extra values]
- '$consumerkey' => ['consumerkey', t('Consumer key'), Config::get('twitter', 'consumerkey'), ''],
- '$consumersecret' => ['consumersecret', t('Consumer secret'), Config::get('twitter', 'consumersecret'), ''],
+ '$consumerkey' => ['consumerkey', L10n::t('Consumer key'), Config::get('twitter', 'consumerkey'), ''],
+ '$consumersecret' => ['consumersecret', L10n::t('Consumer secret'), Config::get('twitter', 'consumersecret'), ''],
]);
}
@@ -769,7 +770,6 @@ function twitter_prepare_body(App $a, &$b)
if ($b["preview"]) {
$max_char = 280;
- require_once "include/plaintext.php";
$item = $b["item"];
$item["plink"] = $a->get_baseurl() . "/display/" . $a->user["nickname"] . "/" . $item["parent"];
@@ -789,7 +789,7 @@ function twitter_prepare_body(App $a, &$b)
}
}
- $msgarr = plaintext($item, $max_char, true, 8);
+ $msgarr = BBCode::toPlaintext($item, $max_char, true, 8);
$msg = $msgarr["text"];
if (isset($msgarr["url"]) && ($msgarr["type"] != "photo")) {
@@ -924,8 +924,6 @@ function twitter_queue_hook(App $a, &$b)
return;
}
- require_once 'include/queue_fn.php';
-
foreach ($qi as $x) {
if ($x['network'] !== NETWORK_TWITTER) {
continue;
@@ -971,7 +969,7 @@ function twitter_queue_hook(App $a, &$b)
logger('twitter_queue: Send to Twitter failed: "' . print_r($result->errors, true) . '"');
} else {
$success = true;
- remove_queue_item($x['id']);
+ Queue::removeItem($x['id']);
}
} else {
logger("twitter_queue: Error getting tokens for user " . $user['uid']);
@@ -979,7 +977,7 @@ function twitter_queue_hook(App $a, &$b)
if (!$success) {
logger('twitter_queue: delayed');
- update_queue_time($x['id']);
+ Queue::updateTime($x['id']);
}
}
}
@@ -1173,8 +1171,6 @@ function twitter_fetchuser(App $a, $uid, $screen_name = "", $user_id = "")
function twitter_expand_entities(App $a, $body, $item, $no_tags = false, $picture)
{
- require_once "include/network.php";
-
$tags = "";
$plain = $body;
@@ -1185,11 +1181,11 @@ function twitter_expand_entities(App $a, $body, $item, $no_tags = false, $pictur
$footerlink = "";
$footer = "";
- foreach ($item->entities->urls AS $url) {
+ foreach ($item->entities->urls as $url) {
$plain = str_replace($url->url, '', $plain);
if ($url->url && $url->expanded_url && $url->display_url) {
- $expanded_url = original_url($url->expanded_url);
+ $expanded_url = Network::finalUrl($url->expanded_url);
$oembed_data = OEmbed::fetchURL($expanded_url);
@@ -1218,7 +1214,7 @@ function twitter_expand_entities(App $a, $body, $item, $no_tags = false, $pictur
} elseif ($oembed_data->type != "link") {
$body = str_replace($url->url, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body);
} else {
- $img_str = fetch_url($expanded_url, true, $redirects, 4);
+ $img_str = Network::fetchUrl($expanded_url, true, $redirects, 4);
$tempfile = tempnam(get_temppath(), "cache");
file_put_contents($tempfile, $img_str);