Skip to content

Commit

Permalink
added error handling options and a new version of Tooltipster plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nida78 committed Feb 23, 2018
1 parent 0631584 commit 49d71f9
Show file tree
Hide file tree
Showing 56 changed files with 618 additions and 4,080 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Tags: wiki, wikipedia, mediawiki, tooltip, tooltipster, shortcode

Requires at least: 3.0

Tested up to: 4.8
Tested up to: 4.9.4

Stable tag: 1.7.4
Stable tag: 1.8.0

Donate link: https://n1da.net/specials/wp-wiki-tooltip/spenden/

Expand Down Expand Up @@ -64,6 +64,14 @@ Since version 1.7.0 you can define a minimum screen width that is necessary to s
# Changelog
Here the last three major releases are listed, only. Find complete log of all changes in the [extra changelog file](https://github.com/nida78/wp-wiki-tooltip/blob/master/CHANGELOG.md)!

## [1.8.0 - C6H9N3O2 | Histidine]
*Release Date - February 23rd, 2018*

* if tooltip trigger 'hover' is selected you can set explicitly how the link has to work
* special options for handling errors are available
* a new version of Tooltipster plugin was released that leads to some programmatic and design changes
* a preview for every tooltip designs is available at options page now

## [1.7.0 - C2H5NO2 | Glycine]
*Release Date - October 22nd, 2016*

Expand All @@ -76,12 +84,6 @@ Here the last three major releases are listed, only. Find complete log of all ch
* the plugin comes with a [TinyMCE](https://codex.wordpress.org/TinyMCE) plugin that helps users creating the shortcodes
* some new graphical assets have been added to support high-DPI displays (aka ‘retina’) and Right-to-Left languages

## [1.5.0 - C5H10N2O3 | Glutamine]
*Release Date - December 29th, 2015*

* New feature: thumbnail pictures can be enabled and styled - both, globally and by shortcode
* Minor bug-fix that uses the complete right Wiki URL when requesting the tooltip content

# Upgrade Notice

## Upgrade to 1.4.0
Expand All @@ -90,6 +92,6 @@ The former Wiki URL is not transferred into this version. Review the settings pa
## Elder Upgrades
Nothing special to consider.

[1.8.0 - C6H9N3O2 | Histidine]: https://github.com/nida78/wp-wiki-tooltip/releases/tag/1.8.0
[1.7.0 - C2H5NO2 | Glycine]: https://github.com/nida78/wp-wiki-tooltip/releases/tag/1.7.0
[1.6.0 - C5H9NO4 | Glutamic Acid]: https://github.com/nida78/wp-wiki-tooltip/releases/tag/1.6.0
[1.5.0 - C5H10N2O3 | Glutamine]: https://github.com/nida78/wp-wiki-tooltip/releases/tag/1.5.0
Binary file modified assets/screenshot-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/screenshot-3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 72 additions & 21 deletions class.wp-wiki-tooltip-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@ public function __construct( $name='' ) {
}

public function init() {
wp_enqueue_style( 'tooltipster-css', plugins_url( 'static/external/tooltipster/dist/css/tooltipster.bundle.min.css', __FILE__ ), array(), '4.2.5', 'all' );
wp_enqueue_style( 'tooltipster-light-css', plugins_url( 'static/external/tooltipster/dist/css/plugins/tooltipster/sideTip/themes/tooltipster-sideTip-light.min.css', __FILE__ ), array(), '4.2.5', 'all' );
wp_enqueue_style( 'tooltipster-noir-css', plugins_url( 'static/external/tooltipster/dist/css/plugins/tooltipster/sideTip/themes/tooltipster-sideTip-noir.min.css', __FILE__ ), array(), '4.2.5', 'all' );
wp_enqueue_style( 'tooltipster-punk-css', plugins_url( 'static/external/tooltipster/dist/css/plugins/tooltipster/sideTip/themes/tooltipster-sideTip-punk.min.css', __FILE__ ), array(), '4.2.5', 'all' );
wp_enqueue_style( 'tooltipster-shadow-css', plugins_url( 'static/external/tooltipster/dist/css/plugins/tooltipster/sideTip/themes/tooltipster-sideTip-shadow.min.css', __FILE__ ), array(), '4.2.5', 'all' );

wp_enqueue_style( 'wp-wiki-tooltip-admin-css', plugins_url( 'static/css/wp-wiki-tooltip-admin.css', __FILE__ ), array(), $this->version, 'all' );
wp_enqueue_style( 'wp-wiki-tooltip-mce-css', plugins_url( 'static/css/wp-wiki-tooltip-mce.css', __FILE__ ), array(), $this->version, 'all' );

wp_enqueue_script( 'tooltipster-js', plugins_url( 'static/external/tooltipster/dist/js/tooltipster.bundle.min.js', __FILE__ ), array( 'jquery' ), '3.0', false );

wp_register_script( 'wp-wiki-tooltip-admin-js', plugins_url( 'static/js/wp-wiki-tooltip-admin.js', __FILE__ ), array( 'jquery' ), $this->version, false );
wp_localize_script( 'wp-wiki-tooltip-admin-js', 'wp_wiki_tooltip_admin', array(
'alert_remove' => __( 'Rows that is marked as "Standard" could not be deleted!', 'wp-wiki-tooltip' ),
Expand Down Expand Up @@ -112,22 +120,31 @@ public function register_settings() {
add_settings_field(
'trigger',
__( 'Tooltips are triggered on', 'wp-wiki-tooltip' ),
array( $this, 'print_trigger_field' ),
'wp-wiki-tooltip-settings-base',
'wp-wiki-tooltip-settings-base',
$wp_wiki_tooltip_default_options
);

add_settings_field(
'min-screen-width',
__( 'Minimum screen width', 'wp-wiki-tooltip' ),
array( $this, 'print_min_screen_width_field' ),
array( $this, 'print_trigger_fields' ),
'wp-wiki-tooltip-settings-base',
'wp-wiki-tooltip-settings-base',
$wp_wiki_tooltip_default_options
);

/*** Design Settings ***/
add_settings_field(
'min-screen-width',
__( 'Minimum screen width', 'wp-wiki-tooltip' ),
array( $this, 'print_min_screen_width_field' ),
'wp-wiki-tooltip-settings-base',
'wp-wiki-tooltip-settings-base',
$wp_wiki_tooltip_default_options
);

add_settings_field(
'error-handling',
__( 'Error handling', 'wp-wiki-tooltip' ),
array( $this, 'print_error_handling_fields' ),
'wp-wiki-tooltip-settings-base',
'wp-wiki-tooltip-settings-base',
$wp_wiki_tooltip_default_options
);

/*** Design Settings ***/
add_settings_section(
'wp-wiki-tooltip-settings-design',
__( 'Design Settings', 'wp-wiki-tooltip' ),
Expand Down Expand Up @@ -292,11 +309,19 @@ public function print_a_target_field( $args ) {
echo '<p><label><input type="radio" id="rdo-a-target-self" name="wp-wiki-tooltip-settings[a-target]" value="_self" ' . checked( $used_target, '_self', false ) . ' />' . __( 'current window / tab', 'wp-wiki-tooltip' ) . '</label></p>';
}

public function print_trigger_field( $args ) {
$used_trigger = isset( $this->options[ 'trigger' ] ) ? $this->options[ 'trigger' ] : $args[ 'trigger' ];

echo '<p><label><input type="radio" id="rdo-a-trigger-hover" name="wp-wiki-tooltip-settings[trigger]" value="hover"' . checked( $used_trigger, 'hover', false ) . ' />' . __( 'hover', 'wp-wiki-tooltip' ) . '</label></p>';
echo '<p><label><input type="radio" id="rdo-a-trigger-click" name="wp-wiki-tooltip-settings[trigger]" value="click" ' . checked( $used_trigger, 'click', false ) . ' />' . __( 'click', 'wp-wiki-tooltip' ) . '</label></p>';
public function print_trigger_fields( $args ) {
$used_trigger = isset( $this->options[ 'trigger' ] ) ? $this->options[ 'trigger' ] : $args[ 'trigger' ];
$used_action = isset( $this->options[ 'trigger-hover-action' ] ) ? $this->options[ 'trigger-hover-action' ] : $args[ 'trigger-hover-action' ];

echo '<p><label><input type="radio" id="rdo-a-trigger-click" name="wp-wiki-tooltip-settings[trigger]" value="click" ' . checked( $used_trigger, 'click', false ) . ' onclick="disable_trigger_hover_action( true );" />' . __( 'click', 'wp-wiki-tooltip' ) . '</label></p>';
echo '<p><label><input type="radio" id="rdo-a-trigger-hover" name="wp-wiki-tooltip-settings[trigger]" value="hover"' . checked( $used_trigger, 'hover', false ) . ' onclick="disable_trigger_hover_action( false );" />' . __( 'hover', 'wp-wiki-tooltip' ) . '</label></p>';
?>
<p class="wiki-form-indent-left description"><?php _e( 'What happens by clicking the link, too?', 'wp-wiki-tooltip' ); ?></p>
<ul class="wiki-form-indent-left">
<li><label><input type="radio" id="rdo-a-trigger-hover-action-none" name="wp-wiki-tooltip-settings[trigger-hover-action]" value="none" <?php checked( $used_action, 'none', true ) ?> <?php disabled( $used_trigger, 'click', true ) ?> /><?php _e( 'Nothing! The link has no further function.', 'wp-wiki-tooltip' ); ?></label></li>
<li><label><input type="radio" id="rdo-a-trigger-hover-action-open" name="wp-wiki-tooltip-settings[trigger-hover-action]" value="open" <?php checked( $used_action, 'open', true ) ?> <?php disabled( $used_trigger, 'click', true ) ?> /><?php _e( 'The linked Wiki page will be opened!', 'wp-wiki-tooltip' ); ?></label></li>
</ul>
<?php
}

public function print_min_screen_width_field( $args ) {
Expand All @@ -307,17 +332,43 @@ public function print_min_screen_width_field( $args ) {
echo '<p class="description">' . __( 'Enable tooltips only if the width of the used display is greater than this defined number of pixel.', 'wp-wiki-tooltip' ) . '</p>';
}

public function print_error_handling_fields( $args ) {
$used_error_handling = isset( $this->options[ 'error-handling' ] ) ? $this->options[ 'error-handling' ] : $args[ 'error-handling' ];
$not_used_show_own = ( $used_error_handling === 'show-own' ) ? false : true;
$not_used_show_page = ( $used_error_handling === 'show-page' ) ? false : true;

echo '<p>' . __( 'What should happen if the linked Wiki page is not available, e.g. if the Wiki is under construction?', 'wp-wiki-tooltip' ) . '</p>';
echo '<p><label><input type="radio" id="rdo-error-handling-show-default" name="wp-wiki-tooltip-settings[error-handling]" value="show-default" ' . checked( $used_error_handling, 'show-default', false ) . ' onclick="disable_error_handling_fields( true, true );" />' . __( 'show default error title and message in tooltip', 'wp-wiki-tooltip' ) . '</label></p>';
echo '<p><label><input type="radio" id="rdo-error-handling-show-own" name="wp-wiki-tooltip-settings[error-handling]" value="show-own" ' . checked( $used_error_handling, 'show-own', false ) . ' onclick="disable_error_handling_fields( false, true );" />' . __( 'show your own error title and message in tooltip', 'wp-wiki-tooltip' ) . '</label></p>';
echo '<ul class="wiki-form-indent-left wiki-error-handling-list">';
printf(
'<li><label for="own-error-title">' . __( 'Title:', 'wp-wiki-tooltip' ) . '</label><input type="text" id="own-error-title" name="wp-wiki-tooltip-settings[own-error-title]" value="%s" class="regular-text" ' . disabled( true, $not_used_show_own, false ) . ' /></li>',
isset( $this->options['own-error-title'] ) ? esc_attr( $this->options[ 'own-error-title' ] ) : $args[ 'own-error-title' ]
);
printf(
'<li><label for="own-error-message">' . __( 'Message:', 'wp-wiki-tooltip' ) . '</label><textarea id="own-error-message" name="wp-wiki-tooltip-settings[own-error-message]" class="regular-text" ' . disabled( true, $not_used_show_own, false ) . ' >%s</textarea><br /><span id="own-error-message-desc" class="description">' . __( 'You can enter HTML here!', 'wp-wiki-tooltip' ) . '</span></span></li>',
isset( $this->options['own-error-message'] ) ? esc_attr( $this->options[ 'own-error-message' ] ) : $args[ 'own-error-message' ]
);
echo '</ul>';
echo '<p><label><input type="radio" id="rdo-error-handling-remove-link" name="wp-wiki-tooltip-settings[error-handling]" value="remove-link" ' . checked( $used_error_handling, 'remove-link', false ) . ' onclick="disable_error_handling_fields( true, true );" />' . __( 'remove the link completely', 'wp-wiki-tooltip' ) . '</label></p>';
}

public function print_theme_field( $args ) {
$used_theme = isset( $this->options[ 'theme' ] ) ? $this->options[ 'theme' ] : $args[ 'theme' ];

echo '<ul id="wiki-tooltip-admin-theme-list">';
foreach( array( 'default', 'light', 'noir', 'punk', 'shadow' ) as $theme ) {
echo '<li><label>';
echo '<input type="radio" id="rdo-theme-' . $theme . '" name="wp-wiki-tooltip-settings[theme]" value="' . $theme . '"' . checked($used_theme, $theme, false) . ' />';
echo '<span class="tooltipster-' . $theme . '-preview">' . $theme . '</span>';
echo '</label></li>';
foreach( array( 'default', 'light', 'borderless', 'noir', 'punk', 'shadow' ) as $theme ) {
?> <li>
<label>
<input type="radio" id="rdo-theme-<?php echo $theme; ?>" name="wp-wiki-tooltip-settings[theme]" value="<?php echo $theme; ?>" <?php checked( $used_theme, $theme, true ); ?> />
<span id="tooltipster-<?php echo $theme; ?>-preview" class="tooltipster-preview" title="<?php printf(__( 'This is a tooltip demo with &raquo;%s&laquo; theme...', 'wp-wiki-tooltip' ), $theme ); ?>"><?php echo $theme; ?></span>
</label>
<script>$wwtj( document ).ready( function() { enable_tooltip_demo( '<?php echo $theme; ?>' ); } );</script>
</li>
<?php
}
echo '</ul>';
echo '<p class="description">' . __( 'Hover over the icons to see a tooltip preview!', 'wp-wiki-tooltip' ) . '</p>';
}

public function print_tooltip_head_field( $args ) {
Expand Down
2 changes: 1 addition & 1 deletion class.wp-wiki-tooltip-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
class WP_Wiki_Tooltip_Base {

protected $version = '1.7.4';
protected $version = '1.8.0';

protected $options = false;
}
16 changes: 12 additions & 4 deletions class.wp-wiki-tooltip-comm.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,18 @@ public function ajax_get_wiki_page() {
$wiki_url = $_REQUEST[ 'wurl' ];
$page_url = $_REQUEST[ 'purl' ];
$thumb_enable = $_REQUEST[ 'tenable' ];
$thumb_width = $_REQUEST[ 'twidth' ];
$thumb_width = $_REQUEST[ 'twidth' ];
$error_title = $_REQUEST[ 'errtit' ];
$error_message = $_REQUEST[ 'errmsg' ];

$error_result = array(
'code' => -1,
'title' => $error_title,
'content' => $error_message
);

if( $wiki_id == -1 ) {
$result = array( 'code' => -1 );
$result = $error_result;
} else {
$this->page_query_args[ 'pageid' ] = $wiki_id;
$response = wp_remote_get( $wiki_url . '?' . http_build_query( $this->page_query_args ) );
Expand Down Expand Up @@ -90,7 +98,7 @@ public function ajax_get_wiki_page() {
}

} else {
$result = array( 'code' => -1 );
$result = $error_result;
}
}

Expand All @@ -112,7 +120,7 @@ public function get_wiki_page_info( $title = '', $wiki_url = '' ) {

$result = array(
'wiki-id' => -1,
'wiki-title' => __( 'Error!', 'wp-wiki-tooltip' ),
'wiki-title' => '',
'wiki-url' => ''
);

Expand Down
32 changes: 20 additions & 12 deletions class.wp-wiki-tooltip.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public function __construct() {
}

public function init() {
wp_enqueue_style( 'tooltipster-css', plugins_url( 'static/external/tooltipster/css/tooltipster.css', __FILE__ ), array(), '3.0', 'all' );
wp_enqueue_style( 'tooltipster-light-css', plugins_url( 'static/external/tooltipster/css/themes/tooltipster-light.css', __FILE__ ), array(), '3.0', 'all' );
wp_enqueue_style( 'tooltipster-noir-css', plugins_url( 'static/external/tooltipster/css/themes/tooltipster-noir.css', __FILE__ ), array(), '3.0', 'all' );
wp_enqueue_style( 'tooltipster-punk-css', plugins_url( 'static/external/tooltipster/css/themes/tooltipster-punk.css', __FILE__ ), array(), '3.0', 'all' );
wp_enqueue_style( 'tooltipster-shadow-css', plugins_url( 'static/external/tooltipster/css/themes/tooltipster-shadow.css', __FILE__ ), array(), '3.0', 'all' );
wp_enqueue_style( 'tooltipster-css', plugins_url( 'static/external/tooltipster/dist/css/tooltipster.bundle.min.css', __FILE__ ), array(), '4.2.5', 'all' );
wp_enqueue_style( 'tooltipster-light-css', plugins_url( 'static/external/tooltipster/dist/css/plugins/tooltipster/sideTip/themes/tooltipster-sideTip-light.min.css', __FILE__ ), array(), '4.2.5', 'all' );
wp_enqueue_style( 'tooltipster-noir-css', plugins_url( 'static/external/tooltipster/dist/css/plugins/tooltipster/sideTip/themes/tooltipster-sideTip-noir.min.css', __FILE__ ), array(), '4.2.5', 'all' );
wp_enqueue_style( 'tooltipster-punk-css', plugins_url( 'static/external/tooltipster/dist/css/plugins/tooltipster/sideTip/themes/tooltipster-sideTip-punk.min.css', __FILE__ ), array(), '4.2.5', 'all' );
wp_enqueue_style( 'tooltipster-shadow-css', plugins_url( 'static/external/tooltipster/dist/css/plugins/tooltipster/sideTip/themes/tooltipster-sideTip-shadow.min.css', __FILE__ ), array(), '4.2.5', 'all' );
wp_enqueue_style( 'wp-wiki-tooltip-css', plugins_url( 'static/css/wp-wiki-tooltip.css', __FILE__ ), array( 'tooltipster-css' ), $this->version, 'all' );
wp_add_inline_style(
'wp-wiki-tooltip-css',
Expand All @@ -39,21 +39,25 @@ public function init() {
'div.wiki-tooltip-balloon img.thumb { ' . $this->options[ 'thumb-style' ] . ' }'
);

wp_enqueue_script( 'tooltipster-js', plugins_url( 'static/external/tooltipster/js/jquery.tooltipster.min.js', __FILE__ ), array( 'jquery' ), '3.0', false );
wp_enqueue_script( 'tooltipster-js', plugins_url( 'static/external/tooltipster/dist/js/tooltipster.bundle.min.js', __FILE__ ), array( 'jquery' ), '3.0', false );
wp_register_script( 'wp-wiki-tooltip-js', plugins_url( 'static/js/wp-wiki-tooltip.js', __FILE__ ), array( 'tooltipster-js' ), $this->version, false );
wp_localize_script( 'wp-wiki-tooltip-js', 'wp_wiki_tooltip', array(
'wp_ajax_url' => admin_url( 'admin-ajax.php' ),
'wiki_plugin_url' => plugin_dir_url( __FILE__ ),
'tooltip_theme' => 'tooltipster-' . $this->options[ 'theme' ],
'footer_text' => __( 'Click here to open Wiki page...', 'wp-wiki-tooltip' ),
'error_title' => __( 'Error!', 'wp-wiki-tooltip' ),
'page_not_found_message' => __( 'Sorry, but we were not able to find this page :(', 'wp-wiki-tooltip' ),
'thumb_enable' => ( $this->options[ 'thumb-enable' ] == 'on' ) ? 'on' : 'off',
'thumb_width' => $this->options[ 'thumb-width' ],
'thumb_align' => $this->options[ 'thumb-align' ],
'trigger' => $this->options[ 'trigger' ],
'trigger' => $this->options[ 'trigger' ],
'trigger_hover_action' => $this->options[ 'trigger-hover-action' ],
'a_target' => $this->options[ 'a-target' ],
'min_screen_width' => $this->options[ 'min-screen-width' ]
'min_screen_width' => $this->options[ 'min-screen-width' ],
'error_handling' => $this->options[ 'error-handling' ],
'default_error_title' => __( 'Error!', 'wp-wiki-tooltip' ),
'default_error_message' => __( 'Sorry, but we were not able to find this page :(', 'wp-wiki-tooltip' ),
'own_error_title' => $this->options[ 'own-error-title' ],
'own_error_message' => $this->options[ 'own-error-message' ]
));
wp_enqueue_script( 'wp-wiki-tooltip-js' );
}
Expand Down Expand Up @@ -99,9 +103,13 @@ public function do_wiki_shortcode( $atts, $content ) {
}

$output = '<script>$wwtj( document ).ready( function() { add_wiki_box( ' . $cnt . ', "' . $trans_wiki_data[ 'wiki-id' ] . '", "' . $trans_wiki_data[ 'wiki-title' ] . '", "' . $trans_wiki_data[ 'wiki-base-url' ] . '", "' . $trans_wiki_data[ 'wiki-url' ] . '", "' . $params[ 'thumbnail' ] . '" ); } );</script>';
// $output .= '<span id="wiki-tooltip-' . $cnt . '" class="wiki-tooltip">' . $content . '</span>';
$relno = ( $this->options[ 'a-target' ] == '_blank' ) ? ' rel="noopener noreferrer"' : '';
$output .= '<a id="wiki-tooltip-' . $cnt . '" class="wiki-tooltip" href="' . $trans_wiki_data[ 'wiki-url' ] . '" target="' . $this->options[ 'a-target' ] . '"' . $relno . ' onclick="return isTooSmall();">' . $content . '</a>';

if( ( $trans_wiki_data[ 'wiki-id' ] == '-1' ) && ( $this->options[ 'error-handling' ] == 'remove-link' ) ) {
$output .= $content;
} else {
$output .= '<a id="wiki-tooltip-' . $cnt . '" data-tooltip-content="wiki-tooltip-box-' . $cnt . '" class="wiki-tooltip" href="' . $trans_wiki_data['wiki-url'] . '" target="' . $this->options['a-target'] . '"' . $relno . ' onclick="return isClickEnabled( \'' . $this->options['trigger'] . '\', \'' . $this->options['trigger-hover-action'] . '\' );">' . $content . '</a>';
}

return $output;
}
Expand Down
Loading

0 comments on commit 49d71f9

Please sign in to comment.