mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2025-07-07 00:48:55 +00:00
app.net, facebook, twitter and statusnet: Preview now shows the post like it will appear on other networks.
This commit is contained in:
parent
f0efa3cae2
commit
9177ee2ecb
5 changed files with 166 additions and 4 deletions
|
@ -73,6 +73,7 @@ function twitter_install() {
|
|||
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');
|
||||
logger("installed twitter");
|
||||
}
|
||||
|
||||
|
@ -87,6 +88,7 @@ function twitter_uninstall() {
|
|||
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');
|
||||
|
||||
// old setting - remove only
|
||||
unregister_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook');
|
||||
|
@ -472,7 +474,7 @@ function twitter_post_hook(&$a,&$b) {
|
|||
|
||||
if (isset($msgarr["url"]))
|
||||
$msg .= "\n".$msgarr["url"];
|
||||
elseif (isset($msgarr["image"]))
|
||||
elseif (isset($msgarr["image"]) AND ($msgarr["type"] != "video"))
|
||||
$image = $msgarr["image"];
|
||||
|
||||
// and now tweet it :-)
|
||||
|
@ -652,6 +654,45 @@ function twitter_expire($a,$b) {
|
|||
logger('twitter_expire: expire_end');
|
||||
}
|
||||
|
||||
function twitter_prepare_body(&$a,&$b) {
|
||||
if ($b["item"]["network"] != NETWORK_TWITTER)
|
||||
return;
|
||||
|
||||
if ($b["preview"]) {
|
||||
$max_char = 140;
|
||||
require_once("include/plaintext.php");
|
||||
$item = $b["item"];
|
||||
$item["plink"] = $a->get_baseurl()."/display/".$a->user["nickname"]."/".$item["parent"];
|
||||
|
||||
$r = q("SELECT `author-link` FROM item WHERE item.uri = '%s' AND item.uid = %d LIMIT 1",
|
||||
dbesc($item["thr-parent"]),
|
||||
intval(local_user()));
|
||||
|
||||
if(count($r)) {
|
||||
$orig_post = $r[0];
|
||||
|
||||
$nicknameplain = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $orig_post["author-link"]);
|
||||
$nickname = "@[url=".$orig_post["author-link"]."]".$nicknameplain."[/url]";
|
||||
$nicknameplain = "@".$nicknameplain;
|
||||
|
||||
if ((strpos($item["body"], $nickname) === false) AND (strpos($item["body"], $nicknameplain) === false))
|
||||
$item["body"] = $nickname." ".$item["body"];
|
||||
}
|
||||
|
||||
|
||||
$msgarr = plaintext($a, $item, $max_char, true);
|
||||
$msg = $msgarr["text"];
|
||||
|
||||
if (isset($msgarr["url"]))
|
||||
$msg .= " ".$msgarr["url"];
|
||||
|
||||
if (isset($msgarr["image"]))
|
||||
$msg .= " ".$msgarr["image"];
|
||||
|
||||
$b['html'] = nl2br(htmlspecialchars($msg));
|
||||
}
|
||||
}
|
||||
|
||||
function twitter_fetchtimeline($a, $uid) {
|
||||
$ckey = get_config('twitter', 'consumerkey');
|
||||
$csecret = get_config('twitter', 'consumersecret');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue