Skip to content

Commit

Permalink
Fixed a documentation issue + improved the debugging behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Wolf committed Apr 22, 2017
1 parent 945029d commit f66ea9c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 23 deletions.
40 changes: 29 additions & 11 deletions mastodon-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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.2
* Version: 2.2.3
* Author: Fabian Wolf
* License: GNU GPL v2 or later
*
Expand All @@ -18,6 +18,7 @@
* - uses different shortcode ('mastodon_embed' instead of 'mastodon') if the original mastodon-embed is active as well
* - uses simple_html_dom instead of XPath
* - cache refresh via attribute ('flush')
* - improved debugging (WP_DEBUG + extended constants)
*/

if( !class_exists( 'simple_html_dom' ) ) {
Expand All @@ -28,7 +29,8 @@ class __mastodon_embed_plugin {
public $pluginName = 'Mastodon Embed Improved',
$pluginPrefix = 'mastodon_embed_';

public $shortcode_name = 'mastodon';
public $shortcode_name = 'mastodon',
$is_compatiblity_mode = false;
/**
* Plugin instance.
*
Expand All @@ -55,9 +57,11 @@ function __construct( $plugin_init = false ) {

// check if the original mastodon is active and change the shortcode name accordingly
if( function_exists( 'mastodon_embed_callback' ) ) {
$this->is_compatiblity_mode = true;
$this->shortcode_name = 'mastodon_embed';
}


$this->init_assets();

add_shortcode( $this->shortcode_name, array( $this, 'shortcode' ) );
Expand Down Expand Up @@ -89,10 +93,20 @@ function init_assets() {
*/
function is_debug() {
$return = false;
if( ( defined( 'WP_DEBUG' ) && WP_DEBUG != false) || current_user_can( 'manage_options' ) != false ) {
if( ( defined( 'WP_DEBUG' ) && WP_DEBUG != false ) || current_user_can( 'manage_options' ) != false ) {
$return = true;
}

/**
* Enhanced mode
* NOTE: Looks a bit awkward, but this stuff is reallly complicated to handle .. o.O
*/
if( defined( 'WP_DEBUG' ) && WP_DEBUG != false ) {
if( ( defined('WP_DEBUG_LOG' ) && WP_DEBUG_LOG != false ) || ( defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY == false ) ) {
$return = false;
}
}

return $return;
}

Expand Down Expand Up @@ -220,7 +234,13 @@ function shortcode( $atts = null, $content = null ) {
if( !empty( $host_url ) ) {

foreach( $embed_content->find( 'img' ) as $image ) {
$image->src = esc_url( '//' .$host_url . $image->src );
/**
* NOTE: Explicitely check for pre-existing URL scheme - to avoid display issues.
*/

if( strpos( $image->src, 'http://' ) === false && strpos( $image->src, 'https://' ) === false ) {
$image->src = esc_url( '//' .$host_url . $image->src );
}
}
}
}
Expand All @@ -235,12 +255,12 @@ function shortcode( $atts = null, $content = null ) {
}
}

if( $this->is_debug() != false ) {
if( $this->is_debug() != false || !empty( $enable_debug ) ) {
$debug = "\n\nDebug:\n" . $debug . print_r( array(
'content' => $content,
'url' => $url,
'attributes' => $atts,
'response_code' => $httpCode,
'response_code' => $http_code,
'response_body' => $body,
), true ) . "\n";
}
Expand All @@ -256,9 +276,8 @@ function shortcode( $atts = null, $content = null ) {
/**
* NOTE: Wrap return code with container div
*/


if( !empty( $return ) && empty( $error ) ) {

if( !empty( $return ) && empty( $error ) ) { // avoids adding the debug data twice!
$strWrap = '<div class="' . $container_class . '">%s</div>';

/*
Expand All @@ -273,8 +292,7 @@ function shortcode( $atts = null, $content = null ) {
$return .= "\n<!-- mastodon embed: $debug -->\n\n";
}
}



return $return;
}

Expand Down
35 changes: 23 additions & 12 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
=== Mastodon Embed Improved ===
Contributors: usability.idealist
Tags: mastodon, social networks, social, opensocial, twitter, embed, shortcode, status
Tags: mastodon, social networks, social, opensocial, twitter, embed, shortcode, status, toot
Requires at least: 4.5
Tested up to: 4.8
Stable tag: trunk
License: GPLv2
Stable tag: 2.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Version: 2.2

Includes simple_html_dom DOM Parser (Revision 210), which is licensed under The MIT License (http://sourceforge.net/projects/simplehtmldom/)
Plugin to easily embed Mastodon statuses (so-called "toot").

== Description ==

A plugin to embed Mastodon statuses. Complete rewrite of [Mastodon embed](https://github.com/DavidLibeau/mastodon-tools) by David Libeau. Tested up to WP 4.8-nightly
A plugin to embed Mastodon statuses. Complete rewrite of [Mastodon embed](https://github.com/DavidLibeau/mastodon-tools) by David Libeau.

Currently implemented features:

Expand All @@ -21,9 +20,9 @@ Currently implemented features:
* working caching
* proper shortcode initialization
* backward compatiblity for mastodon-embed
* fallback to "direct" embeds if embed via iframe is forbidden (eg. when testing on localhost); use shortcode attribute `no_iframe` and set it to `1` (eg. `[mastodon_embed no_iframe="1"]http://my.mastodon.instance/@mastodon_user/12345[/mastodon_embed]`)
* Reverse-engineered CSS file (including LESS base) and override option (filter: mastodon_embed_content_style)
* Uses different shortcode ('mastodon_embed' instead of 'mastodon') if the original mastodon-embed is active as well
* fallback to "direct" embeds if embed via iframe is forbidden (eg. when testing on localhost); use shortcode attribute `no_iframe` and set it to `1` (eg. `[mastodon no_iframe="1"]http://my.mastodon.instance/@mastodon_user/12345[/mastodon]`)
* Reverse-engineered CSS file (including LESS base) and override option (filter: mastodon_content_style)
* Uses different shortcode ('mastodon' instead of 'mastodon') if the original mastodon-embed is active as well
* Uses simple_html_dom class instead of XPath
* Optional manual cache refresh option via shortcode attribute

Expand All @@ -33,6 +32,10 @@ Currently implemented features:
* Maybe a settings page or a custom config file
* Properly implemented shortcode asset loading via a separate class / plugin

= Third-party libraries =

* Includes the [simple_html_dom](http://sourceforge.net/projects/simplehtmldom/) DOM Parser class (Revision 210), which is licensed under The MIT License (aka Expat License)

= Website =

http://f2w.de/mastodon-embed
Expand All @@ -47,15 +50,15 @@ Your votes really make a difference! Thanks.
1. Upload 'mastodon-embed' to the '/wp-content/plugins/' directory
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Edit an existing post or page - or create a new one
4. Insert toot / status URL and surround it with the shortcode '[mastodon_embed]' (eg. `[mastodon_embed]http://my.mastodon.instance/@mastodon_user/12345[/mastodon_embed]`)
4. Insert toot / status URL and surround it with the shortcode '[mastodon]' (eg. `[mastodon]http://my.mastodon.instance/@mastodon_user/12345[/mastodon]`)
5. Read the documentation for better customization :)

== Frequently Asked Questions ==

= Shortcode documentation =

Regular shortcode: `[mastodon_embed]http://my.mastodon.instance/@mastodon_user/12345[/mastodon_embed]`
Shortcode using direct embed method: `[mastodon_embed no_iframe="1"]http://my.mastodon.instance/@mastodon_user/12345[/mastodon_embed]``
Regular shortcode: `[mastodon]http://my.mastodon.instance/@mastodon_user/12345[/mastodon]`
Shortcode using direct embed method: `[mastodon no_iframe="1"]http://my.mastodon.instance/@mastodon_user/12345[/mastodon]``

All available shortcode attributes:

Expand All @@ -70,12 +73,20 @@ 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 ;)

= 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**.

= Q. I have a question =
A. Chances are, someone else has asked it. Either check out the support forum at WP or take a look at the official issue tracker:
http://github.com/ginsterbusch/mastodon-embed/issues

== Changelog ==

= 2.2.3 =

* Fix: Fixed
* Improved WP_DEBUG behaviour - if WP_DEBUG_LOG is enabled, or WP_DEBUG_DISPLAY is set to false, the debugging data will not be displayed, EVEN IF the current user has the 'manage_options' capability (ie. administrator level).

= 2.2 =

* Fix: Corrected the cache_timeout (originally a constant was used, but I removed it from default usage and forgot to set the default attribute to something sensible); now set to 1 day (in seconds)
Expand Down

0 comments on commit f66ea9c

Please sign in to comment.