define('STATUSNET_DEFAULT_POLL_INTERVAL', 5); // given in minutes
require_once __DIR__ . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'statusnetoauth.php';
-require_once 'include/enotify.php';
use CodebirdSN\CodebirdSN;
use Friendica\App;
use Friendica\Content\OEmbed;
use Friendica\Content\Text\HTML;
use Friendica\Content\Text\Plaintext;
-use Friendica\Core\Addon;
use Friendica\Core\Config;
+use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\PConfig;
use Friendica\Core\Protocol;
+use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
-use Friendica\Model\GContact;
use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\ItemContent;
use Friendica\Model\Photo;
use Friendica\Model\User;
+use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
+use Friendica\Util\Strings;
function statusnet_install()
{
// we need some hooks, for the configuration and for sending tweets
- Addon::registerHook('connector_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings');
- Addon::registerHook('connector_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
- Addon::registerHook('notifier_normal', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
- Addon::registerHook('post_local', 'addon/statusnet/statusnet.php', 'statusnet_post_local');
- Addon::registerHook('jot_networks', 'addon/statusnet/statusnet.php', 'statusnet_jot_nets');
- Addon::registerHook('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron');
- Addon::registerHook('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body');
- Addon::registerHook('check_item_notification', 'addon/statusnet/statusnet.php', 'statusnet_check_item_notification');
+ Hook::register('connector_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings');
+ Hook::register('connector_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
+ Hook::register('notifier_normal', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
+ Hook::register('hook_fork', 'addon/statusnet/statusnet.php', 'statusnet_hook_fork');
+ Hook::register('post_local', 'addon/statusnet/statusnet.php', 'statusnet_post_local');
+ Hook::register('jot_networks', 'addon/statusnet/statusnet.php', 'statusnet_jot_nets');
+ 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");
}
function statusnet_uninstall()
{
- Addon::unregisterHook('connector_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings');
- Addon::unregisterHook('connector_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
- Addon::unregisterHook('notifier_normal', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
- Addon::unregisterHook('post_local', 'addon/statusnet/statusnet.php', 'statusnet_post_local');
- Addon::unregisterHook('jot_networks', 'addon/statusnet/statusnet.php', 'statusnet_jot_nets');
- Addon::unregisterHook('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron');
- Addon::unregisterHook('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body');
- Addon::unregisterHook('check_item_notification', 'addon/statusnet/statusnet.php', 'statusnet_check_item_notification');
+ Hook::unregister('connector_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings');
+ Hook::unregister('connector_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
+ Hook::unregister('notifier_normal', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
+ Hook::unregister('hook_fork', 'addon/statusnet/statusnet.php', 'statusnet_hook_fork');
+ Hook::unregister('post_local', 'addon/statusnet/statusnet.php', 'statusnet_post_local');
+ Hook::unregister('jot_networks', 'addon/statusnet/statusnet.php', 'statusnet_jot_nets');
+ Hook::unregister('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron');
+ Hook::unregister('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body');
+ Hook::unregister('check_item_notification', 'addon/statusnet/statusnet.php', 'statusnet_check_item_notification');
// old setting - remove only
- Addon::unregisterHook('post_local_end', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
- Addon::unregisterHook('addon_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings');
- Addon::unregisterHook('addon_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
+ Hook::unregister('post_local_end', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
+ Hook::unregister('addon_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings');
+ Hook::unregister('addon_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
}
function statusnet_check_item_notification(App $a, &$notification_data)
}
}
-function statusnet_jot_nets(App $a, &$b)
+function statusnet_jot_nets(App $a, array &$jotnets_fields)
{
if (!local_user()) {
return;
}
- $statusnet_post = PConfig::get(local_user(), 'statusnet', 'post');
- if (intval($statusnet_post) == 1) {
- $statusnet_defpost = PConfig::get(local_user(), 'statusnet', 'post_by_default');
- $selected = ((intval($statusnet_defpost) == 1) ? ' checked="checked" ' : '');
- $b .= '<div class="profile-jot-net"><input type="checkbox" name="statusnet_enable"' . $selected . ' value="1" /> '
- . L10n::t('Post to GNU Social') . '</div>';
+ if (PConfig::get(local_user(), 'statusnet', 'post')) {
+ $jotnets_fields[] = [
+ 'type' => 'checkbox',
+ 'field' => [
+ 'statusnet_enable',
+ L10n::t('Post to GNU Social'),
+ PConfig::get(local_user(), 'statusnet', 'post_by_default')
+ ]
+ ];
}
}
return;
}
// don't check GNU Social settings if GNU Social submit button is not clicked
- if (!x($_POST, 'statusnet-submit')) {
+ if (empty($_POST['statusnet-submit'])) {
return;
}
$s .= '</div><div class="clear"></div>';
}
+function statusnet_hook_fork(App $a, array &$b)
+{
+ if ($b['name'] != 'notifier_normal') {
+ return;
+ }
+
+ $post = $b['data'];
+
+ // Deleting and editing is not supported by the addon
+ if ($post['deleted'] || ($post['created'] !== $post['edited'])) {
+ $b['execute'] = false;
+ return;
+ }
+
+ // if post comes from GNU Social don't send it back
+ if ($post['extid'] == Protocol::STATUSNET) {
+ $b['execute'] = false;
+ return;
+ }
+
+ if ($post['app'] == 'StatusNet') {
+ $b['execute'] = false;
+ return;
+ }
+
+ if (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']) && !Item::exists(['id' => $post['parent'], 'network' => Protocol::STATUSNET])) {
+ Logger::log('No GNU Social parent found for item ' . $post['id']);
+ $b['execute'] = false;
+ return;
+ }
+ } else {
+ // Comments are never exported when we don't import the GNU Social timeline
+ if (!strstr($post['postopts'], 'statusnet') || ($post['parent'] != $post['id']) || $post['private']) {
+ $b['execute'] = false;
+ return;
+ }
+ }
+}
+
function statusnet_post_local(App $a, &$b)
{
if ($b['edit']) {
}
$statusnet_post = PConfig::get(local_user(), 'statusnet', 'post');
- $statusnet_enable = (($statusnet_post && x($_REQUEST, 'statusnet_enable')) ? intval($_REQUEST['statusnet_enable']) : 0);
+ $statusnet_enable = (($statusnet_post && !empty($_REQUEST['statusnet_enable'])) ? intval($_REQUEST['statusnet_enable']) : 0);
// if API is used, default to the chosen settings
if ($b['api_source'] && intval(PConfig::get(local_user(), 'statusnet', 'post_by_default'))) {
}
}
- if (($b['verb'] == ACTIVITY_POST) && $b['deleted']) {
+ if (($b['verb'] == Activity::POST) && $b['deleted']) {
statusnet_action($a, $b["uid"], substr($orig_post["uri"], $hostlength), "delete");
}
- if ($b['verb'] == ACTIVITY_LIKE) {
+ if ($b['verb'] == Activity::LIKE) {
Logger::log("statusnet_post_hook: parameter 2 " . substr($b["thr-parent"], $hostlength), Logger::DEBUG);
if ($b['deleted'])
statusnet_action($a, $b["uid"], substr($b["thr-parent"], $hostlength), "unlike");
}
$secret = trim($_POST['secret'][$id]);
$key = trim($_POST['key'][$id]);
- //$applicationname = ((x($_POST, 'applicationname')) ? notags(trim($_POST['applicationname'][$id])):'');
+ //$applicationname = (!empty($_POST['applicationname']) ? Strings::escapeTags(trim($_POST['applicationname'][$id])):'');
if ($sitename != "" &&
$apiurl != "" &&
$secret != "" &&
$key != "" &&
- !x($_POST['delete'][$id])) {
+ empty($_POST['delete'][$id])) {
$sites[] = [
'sitename' => $sitename,
//'applicationname' => Array("applicationname[$id]", L10n::t("Application name"), "", ""),
];
- $t = get_markup_template("admin.tpl", "addon/statusnet/");
- $o = replace_macros($t, [
+ $t = Renderer::getMarkupTemplate("admin.tpl", "addon/statusnet/");
+ $o = Renderer::replaceMacros($t, [
'$submit' => L10n::t('Save Settings'),
'$sites' => $sitesform,
]);
}
$item = $b["item"];
- $item["plink"] = $a->getBaseURL() . "/display/" . $a->user["nickname"] . "/" . $item["parent"];
+ $item["plink"] = $a->getBaseURL() . "/display/" . $item["guid"];
$condition = ['uri' => $item["thr-parent"], 'uid' => local_user()];
$orig_post = Item::selectFirst(['author-link', 'uri'], $condition);
$lastid = PConfig::get($uid, 'statusnet', 'lastid');
require_once 'mod/item.php';
- require_once 'include/items.php';
-
// get the application name for the SN app
// 1st try personal config, then system config and fallback to the
// hostname of the node if neither one is set.
function statusnet_address($contact)
{
- $hostname = normalise_link($contact->statusnet_profile_url);
+ $hostname = Strings::normaliseLink($contact->statusnet_profile_url);
$nickname = $contact->screen_name;
$hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $contact->statusnet_profile_url);
function statusnet_fetch_contact($uid, $contact, $create_user)
{
- if ($contact->statusnet_profile_url == "") {
+ if (empty($contact->statusnet_profile_url)) {
return -1;
}
- GContact::update(["url" => $contact->statusnet_profile_url,
- "network" => Protocol::STATUSNET, "photo" => $contact->profile_image_url,
- "name" => $contact->name, "nick" => $contact->screen_name,
- "location" => $contact->location, "about" => $contact->description,
- "addr" => statusnet_address($contact), "generation" => 3]);
-
- $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' AND `network` = '%s'LIMIT 1", intval($uid), DBA::escape(normalise_link($contact->statusnet_profile_url)), DBA::escape(Protocol::STATUSNET));
+ $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' AND `network` = '%s'LIMIT 1", intval($uid), DBA::escape(Strings::normaliseLink($contact->statusnet_profile_url)), DBA::escape(Protocol::STATUSNET));
if (!DBA::isResult($r) && !$create_user) {
return 0;
intval($uid),
DBA::escape(DateTimeFormat::utcNow()),
DBA::escape($contact->statusnet_profile_url),
- DBA::escape(normalise_link($contact->statusnet_profile_url)),
+ DBA::escape(Strings::normaliseLink($contact->statusnet_profile_url)),
DBA::escape(statusnet_address($contact)),
- DBA::escape(normalise_link($contact->statusnet_profile_url)),
+ DBA::escape(Strings::normaliseLink($contact->statusnet_profile_url)),
DBA::escape(''),
DBA::escape(''),
DBA::escape($contact->name),
DBA::escape(DateTimeFormat::utcNow()),
DBA::escape(DateTimeFormat::utcNow()),
DBA::escape($contact->statusnet_profile_url),
- DBA::escape(normalise_link($contact->statusnet_profile_url)),
+ DBA::escape(Strings::normaliseLink($contact->statusnet_profile_url)),
DBA::escape(statusnet_address($contact)),
DBA::escape($contact->name),
DBA::escape($contact->screen_name),
$postarray['thr-parent'] = $item['uri'];
$postarray['parent-uri'] = $item['parent-uri'];
$postarray['parent'] = $item['parent'];
- $postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
+ $postarray['object-type'] = Activity\ObjectType::COMMENT;
} else {
$postarray['thr-parent'] = $postarray['uri'];
$postarray['parent-uri'] = $postarray['uri'];
- $postarray['object-type'] = ACTIVITY_OBJ_NOTE;
+ $postarray['object-type'] = Activity\ObjectType::NOTE;
}
// Is it me?
$create_user = false;
} else {
$postarray['parent-uri'] = $postarray['uri'];
- $postarray['object-type'] = ACTIVITY_OBJ_NOTE;
+ $postarray['object-type'] = Activity\ObjectType::NOTE;
}
if ($contactid == 0) {
$postarray['contact-id'] = $contactid;
- $postarray['verb'] = ACTIVITY_POST;
+ $postarray['verb'] = Activity::POST;
$postarray['author-name'] = $content->user->name;
$postarray['author-link'] = $content->user->statusnet_profile_url;
Logger::log("statusnet_fetchhometimeline: Fetching for user " . $uid, Logger::DEBUG);
- require_once 'include/items.php';
-
$connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret);
$own_contact = statusnet_fetch_own_contact($a, $uid);
+ if (empty($own_contact)) {
+ return;
+ }
+
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($own_contact),
intval($uid));
function statusnet_convertmsg(App $a, $body, $no_tags = false)
{
- require_once "include/items.php";
-
$body = preg_replace("=\[url\=https?://([0-9]*).([0-9]*).([0-9]*).([0-9]*)/([0-9]*)\](.*?)\[\/url\]=ism", "$1.$2.$3.$4/$5", $body);
$URLSearchString = "^\[\]";
} elseif ($oembed_data->type != "link") {
$body = str_replace($search, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body);
} else {
- $img_str = Network::fetchUrl($expanded_url, true, $redirects, 4);
+ $img_str = Network::fetchUrl($expanded_url, true, 4);
$tempfile = tempnam(get_temppath(), "cache");
file_put_contents($tempfile, $img_str);
if ($mtch[1] == "#") {
// Replacing the hash tags that are directed to the GNU Social server with internal links
$snhash = "#[url=" . $mtch[2] . "]" . $mtch[3] . "[/url]";
- $frdchash = '#[url=' . $a->getBaseURL() . '/search?tag=' . rawurlencode($mtch[3]) . ']' . $mtch[3] . '[/url]';
+ $frdchash = '#[url=' . $a->getBaseURL() . '/search?tag=' . $mtch[3] . ']' . $mtch[3] . '[/url]';
$body = str_replace($snhash, $frdchash, $body);
$str_tags .= $frdchash;
// Fetching user data
$user = $connection->get('account/verify_credentials');
- PConfig::set($uid, 'statusnet', 'own_url', normalise_link($user->statusnet_profile_url));
+ if (empty($user)) {
+ return false;
+ }
+
+ PConfig::set($uid, 'statusnet', 'own_url', Strings::normaliseLink($user->statusnet_profile_url));
$contact_id = statusnet_fetch_contact($uid, $user, true);
} else {