Skip to content

Commit

Permalink
Add Wordpress plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
dlibeau committed Apr 7, 2017
1 parent 77f3d4e commit 6e9fcfa
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 0 deletions.
15 changes: 15 additions & 0 deletions dev/embed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script src="//dav.li/jquery/2.1.4.js"></script>
<script>
var $_GET = {};
document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
function decode(s) {
return decodeURIComponent(s.split("+").join(" "));
}
$_GET[decode(arguments[1])] = decode(arguments[2]);
});
$.ajax({
url: $_GET["url"]
}).done(function (data) {
console.log(data);
});
</script>
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions dev/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
if(isset($_GET["url"]) && $_GET["url"]!=""){
$url = $_GET["url"];
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.23 (Windows NT 5.1; U; en)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

## Below two option will enable the HTTPS option.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($ch);
var_dump($result);
?>
Binary file added wordpress/mastodon-embed.zip
Binary file not shown.
63 changes: 63 additions & 0 deletions wordpress/mastodon-embed/mastodon-embed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Plugin Name: Mastodon embed
* Plugin URI: https://github.com/DavidLibeau/mastodon-widget
* Description: A plugin to embed Mastodon statuses.
* Version: 1.0
* Author: David Libeau
*/


function mastodon_embed_callback($atts=null, $content=null)
{
extract($atts);

if(isset($url) && $url!=""){

// CURL $_GET["url"]
$ch = curl_init(urldecode(str_replace("https://", "http://", $url)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_CAPATH, PATH_TO_CERT_DIR);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Embed");
curl_setopt($ch, CURLOPT_AUTOREFERER, true);

$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

if($httpCode == 404) {
return("<div class='mastodon-embed'>404</div>");
}else if($httpCode == 301){
return("<div class='mastodon-embed'>301</div>");
}else{
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML($content);
$xpath = new DOMXPath($doc);
$atomUrl = $xpath->query("//link[@type='application/atom+xml']");

if($atomUrl->length){
$embedUrl = str_replace(".atom", "/embed", $atomUrl[0]->getAttribute("href"));
return('<div class="mastodon-embed"><iframe src="'. $embedUrl .'" style="overflow: hidden" frameborder="0" width="400" height="150" scrolling="no"></iframe></div>');
}
}

}


}

add_shortcode("mastodon", "mastodon_embed_callback");
48 changes: 48 additions & 0 deletions wordpress/mastodon-embed/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
=== Mastodon Embed ===
Contributors: davidlibeau
Donate link: http://davidlibeau.fr/
Tags: mastodon, embed, status, gnu social
Requires at least: 1.0
Tested up to: 1.0
Stable tag: 1.0
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html

A plugin to embed Mastodon statuses.

== Description ==

A plugin to embed Mastodon statuses.

>Only work with HTTPS non-forced Mastodon instance. See https://github.com/DavidLibeau/mastodon-widget/issues/1

== Installation ==


1. Upload the plugin files to the `/wp-content/plugins/plugin-name` directory, or install the plugin through the WordPress plugins screen directly.
2. Activate the plugin through the 'Plugins' screen in WordPress
3. Write `[mastodon url="`a Mastodon status URL`"][/mastodon]`

Examples :

`[mastodon url="https://mastodon.xyz/@David/15605"][/mastodon]`


== Frequently Asked Questions ==

= It didn't work ! =

Ask [here](https://github.com/DavidLibeau/mastodon-widget/issues/) !

= Can I help ? =

[Yes !](https://github.com/DavidLibeau/mastodon-widget/)

== Screenshots ==

No screenshots

== Changelog ==

= 1.0 =
* First version

0 comments on commit 6e9fcfa

Please sign in to comment.