Skip to content

Commit

Permalink
Added picking out a specific toot from a conversation + fixed a missi…
Browse files Browse the repository at this point in the history
…ng parameter.
  • Loading branch information
Fabian Wolf committed May 17, 2017
1 parent d6247cc commit b0df48c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
17 changes: 15 additions & 2 deletions mastodon-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* Plugin Name: Mastodon Embed Improved
* Plugin URI: http://f2w.de/mastodon-embed
* Description: A plugin to embed Mastodon statuses. Complete rewrite of <a href="https://github.com/DavidLibeau/mastodon-tools">Mastodon embed</a> by David Libeau. Tested up to WP 4.8-nightly
* Version: 2.3
* Version: 2.3.4
* Author: Fabian Wolf
* Author URI: http://usability-idealist.de
* License: GNU GPL v2 or later
*
* Features:
Expand All @@ -21,6 +22,7 @@
* - improved debugging (WP_DEBUG + extended constants)
* - alias for no_iframe attribute: disable_iframe
* - force URL scheme attribute ('force_scheme') to further improve SSL only vs. unencrypted http-only sites (ie. fun with SSL enforcement in WP ;))
* - pick out specific single toot ('center'; enabled by default; to display the complete conversation, set to 0);
*/

if( !class_exists( 'simple_html_dom' ) ) {
Expand Down Expand Up @@ -134,6 +136,8 @@ function shortcode( $atts = null, $content = null ) {
'force_scheme' => '',
'no_fa' => 0,
'flush' => 0, // intentionally flush the cache
'center' => 1, // picks out only the main toot out of a conversation (entry-center class)
'enable_debug' => 0, // specific debug parameter
);

$atts = shortcode_atts( $default_atts, $atts );
Expand Down Expand Up @@ -239,8 +243,17 @@ function shortcode( $atts = null, $content = null ) {

} else { // use direct embed
$embed_content = $dom->find( '.activity-stream', 0 );

if( !empty( $embed_content ) ) {
if( !empty( $center ) ) {
$center_content = $embed_content->find( '.entry-center', 0 );

if( !empty( $center_content ) ) {
$_embed_content = $embed_content; // backup original
$embed_content = $center_content; // replace it with the "focused" toot
}
}

wp_enqueue_style( $this->pluginPrefix . 'content' );

if( empty( $disable_font_awesome ) && empty( $no_fa ) ) {
Expand Down
10 changes: 9 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: usability.idealist
Tags: mastodon, social networks, social, opensocial, twitter, embed, shortcode, status, toot
Requires at least: 4.5
Tested up to: 4.8
Stable tag: 2.3
Stable tag: 2.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -27,6 +27,7 @@ Currently implemented features:
* Optional manual cache refresh option via shortcode attribute
* improved debugging (WP_DEBUG + extended constants)
* Force URL scheme attribute ('force_scheme') to further improve SSL only vs. unencrypted http-only sites (ie. fun with SSL enforcement in WP ;))
* Center on a specific toot in a conversation ('center'); enabled by default

= Future plans =

Expand Down Expand Up @@ -77,6 +78,8 @@ All available shortcode attributes:
* no_fa' - Alias
* flush - set this to 1 to refresh the embed cache; update post after this, give its frontend view a spin, and then remove it afterwards ;)
* force_scheme - set this to either 'http' or 'https' to enforce using this URL scheme (ie. protocol); primary use is to improve the SSL behaviour in WP
* center - Pick out a specific toot from a conversation. Enabled by default. To disable, set this parameter to `0`.
* enable_debug - Explicitely enables the debug mode

= Q. The embedding does not work =
A. First test if there are any shortcode-interferring plugins. That could also be the original mastodon-embed. Aside of that, there was a mistake in the documentation before version 2.2.3, incorrectly stating the shortcode tag is 'mastodon_embed', while in reality it's **mastodon**.
Expand All @@ -87,6 +90,11 @@ http://github.com/ginsterbusch/mastodon-embed/issues

== Changelog ==

= 2.4 =

* Added function to automatically pick out a single status from a conversation; enabled by default
* Fixed missing 'enable_debug' parameter

= 2.3 =

* Fixed weird SSL embed behaviour (for now)
Expand Down

0 comments on commit b0df48c

Please sign in to comment.