Make AJAX shortcodes hookable

This commit is contained in:
Brian Miyaji
2015-01-21 23:50:07 +11:00
parent 82fee9dcee
commit 2ad1a7b003
11 changed files with 102 additions and 172 deletions

View File

@@ -1,23 +1,65 @@
<?php
$shortcodes = '';
$options = array(
'event' => array(
'details', 'results', 'performance', 'countdown'
),
'player' => array(
'details', 'statistics'
),
);
if ( 'yes' == get_option( 'sportspress_load_calendars_module', 'yes' ) ) {
$options['event'][] = 'calendar';
$options['event'][] = 'list';
$options['event'][] = 'blocks';
}
if ( 'yes' == get_option( 'sportspress_load_league_tables_module', 'yes' ) ) {
$options['table'] = array( 'table' );
}
if ( 'yes' == get_option( 'sportspress_load_player_lists_module', 'yes' ) ) {
$options['player'][] = 'list';
$options['player'][] = 'gallery';
}
$options = apply_filters( 'sportspress_shortcodes', $options );
foreach ( $options as $name => $group ) {
$shortcodes .= $name . '[' . implode( '|', $group ) . ']';
}
$raw = apply_filters( 'sportspress_tinymce_strings', array(
'shortcodes' => $shortcodes,
'insert' => __( 'SportsPress Shortcodes', 'sportspress' ),
'auto' => __( 'Auto', 'sportspress' ),
'manual' => __( 'Manual', 'sportspress' ),
'select' => __( 'Select...', 'sportspress' ),
'event' => __( 'Event', 'sportspress' ),
'details' => __( 'Details', 'sportspress' ),
'results' => __( 'Results', 'sportspress' ),
'countdown' => __( 'Countdown', 'sportspress' ),
'performance' => __( 'Performance', 'sportspress' ),
'calendar' => __( 'Calendar', 'sportspress' ),
'statistics' => __( 'Statistics', 'sportspress' ),
'table' => __( 'League Table', 'sportspress' ),
'player' => __( 'Player', 'sportspress' ),
'list' => __( 'List', 'sportspress' ),
'blocks' => __( 'Blocks', 'sportspress' ),
'gallery' => __( 'Gallery', 'sportspress' ),
));
$formatted = array();
foreach ( $raw as $key => $value ) {
$formatted[] = $key . ': "' . esc_js( $value ) . '"';
}
$strings = 'tinyMCE.addI18n({' . _WP_Editors::$mce_locale . ':{
sportspress:{
insert: "' . esc_js( __( 'SportsPress Shortcodes', 'sportspress' ) ) . '",
auto: "' . esc_js( __( 'Auto', 'sportspress' ) ) . '",
manual: "' . esc_js( __( 'Manual', 'sportspress' ) ) . '",
select: "' . esc_js( __( 'Select...', 'sportspress' ) ) . '",
event: "' . esc_js( __( 'Event', 'sportspress' ) ) . '",
details: "' . esc_js( __( 'Details', 'sportspress' ) ) . '",
results: "' . esc_js( __( 'Results', 'sportspress' ) ) . '",
countdown: "' . esc_js( __( 'Countdown', 'sportspress' ) ) . '",
performance: "' . esc_js( __( 'Performance', 'sportspress' ) ) . '",
calendar: "' . esc_js( __( 'Calendar', 'sportspress' ) ) . '",
statistics: "' . esc_js( __( 'Statistics', 'sportspress' ) ) . '",
league_table: "' . esc_js( __( 'League Table', 'sportspress' ) ) . '",
player_list: "' . esc_js( __( 'Player List', 'sportspress' ) ) . '",
list: "' . esc_js( __( 'List', 'sportspress' ) ) . '",
blocks: "' . esc_js( __( 'Blocks', 'sportspress' ) ) . '",
player: "' . esc_js( __( 'Player', 'sportspress' ) ) . '",
gallery: "' . esc_js( __( 'Gallery', 'sportspress' ) ) . '"
' . implode( ', ', $formatted ) . '
}
}})';

View File

@@ -2,153 +2,41 @@
( function () {
tinymce.PluginManager.add( 'sp_shortcodes_button', function( editor, url ) {
var ed = tinymce.activeEditor;
var groups = ed.getLang( 'sportspress.shortcodes' ).split("]");
var menu = new Array();
groups.forEach(function(g) {
if ( "" == g ) return;
var p = g.split("[");
var label = p.shift();
var variations = p.shift();
var shortcodes = variations.split("|");
var submenu = new Array();
shortcodes.forEach(function(s) {
submenu.push({
text: ed.getLang( 'sportspress.' + s ),
onclick: function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.' + label ) + ' - ' + ed.getLang( 'sportspress.' + s ), 'admin-ajax.php?action=sportspress_' + label + '_' + s + '_shortcode&width=' + W + '&height=' + H );
}
});
});
menu.push({
text: ed.getLang( 'sportspress.' + label ),
menu: submenu
});
});
editor.addButton( 'sp_shortcodes_button', {
title: ed.getLang('sportspress.insert'),
text: false,
icon: false,
type: 'menubutton',
menu: [
{
text: ed.getLang( 'sportspress.event' ),
menu: [
{
text: ed.getLang( 'sportspress.details' ),
onclick: function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.event' ) + ' - ' + ed.getLang( 'sportspress.details' ), 'admin-ajax.php?action=sportspress_event_details_shortcode&width=' + W + '&height=' + H );
}
},
{
text: ed.getLang( 'sportspress.results' ),
onclick: function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.event' ) + ' - ' + ed.getLang( 'sportspress.results' ), 'admin-ajax.php?action=sportspress_event_results_shortcode&width=' + W + '&height=' + H );
}
},
{
text: ed.getLang( 'sportspress.performance' ),
onclick: function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.event' ) + ' - ' + ed.getLang( 'sportspress.performance' ), 'admin-ajax.php?action=sportspress_event_performance_shortcode&width=' + W + '&height=' + H );
}
},
{
text: ed.getLang( 'sportspress.countdown' ),
onclick: function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.event' ) + ' - ' + ed.getLang( 'sportspress.countdown' ), 'admin-ajax.php?action=sportspress_countdown_shortcode&width=' + W + '&height=' + H );
}
}
]
},
{
text: ed.getLang( 'sportspress.calendar' ),
menu: [
{
text: ed.getLang( 'sportspress.calendar' ),
onclick : function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.calendar' ) + ' - ' + ed.getLang( 'sportspress.calendar' ), 'admin-ajax.php?action=sportspress_event_calendar_shortcode&width=' + W + '&height=' + H );
}
},
{
text: ed.getLang( 'sportspress.list' ),
onclick : function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.calendar' ) + ' - ' + ed.getLang( 'sportspress.list' ), 'admin-ajax.php?action=sportspress_event_list_shortcode&width=' + W + '&height=' + H );
}
},
{
text: ed.getLang( 'sportspress.blocks' ),
onclick : function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.calendar' ) + ' - ' + ed.getLang( 'sportspress.blocks' ), 'admin-ajax.php?action=sportspress_event_blocks_shortcode&width=' + W + '&height=' + H );
}
}
]
},
{
text: ed.getLang( 'sportspress.league_table' ),
onclick : function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.league_table' ), 'admin-ajax.php?action=sportspress_league_table_shortcode&width=' + W + '&height=' + H );
}
},
{
text: ed.getLang( 'sportspress.player' ),
menu: [
{
text: ed.getLang( 'sportspress.details' ),
onclick: function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.player' ) + ' - ' + ed.getLang( 'sportspress.details' ), 'admin-ajax.php?action=sportspress_player_details_shortcode&width=' + W + '&height=' + H );
}
},
{
text: ed.getLang( 'sportspress.statistics' ),
onclick: function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.player' ) + ' - ' + ed.getLang( 'sportspress.statistics' ), 'admin-ajax.php?action=sportspress_player_statistics_shortcode&width=' + W + '&height=' + H );
}
}
]
},
{
text: ed.getLang( 'sportspress.player_list' ),
menu: [
{
text: ed.getLang( 'sportspress.list' ),
onclick : function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.player_list' ) + ' - ' + ed.getLang( 'sportspress.list' ), 'admin-ajax.php?action=sportspress_player_list_shortcode&width=' + W + '&height=' + H );
}
},
{
text: ed.getLang( 'sportspress.gallery' ),
onclick : function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.player_list' ) + ' - ' + ed.getLang( 'sportspress.gallery' ), 'admin-ajax.php?action=sportspress_player_gallery_shortcode&width=' + W + '&height=' + H );
}
}
]
}
]
menu: menu
});
});
})();

View File

@@ -23,14 +23,14 @@ class SP_AJAX {
// sportspress_EVENT => nopriv
$ajax_events = array(
'countdown_shortcode' => false,
'event_countdown_shortcode' => false,
'event_details_shortcode' => false,
'event_results_shortcode' => false,
'event_performance_shortcode' => false,
'event_calendar_shortcode' => false,
'event_list_shortcode' => false,
'event_blocks_shortcode' => false,
'league_table_shortcode' => false,
'table_table_shortcode' => false,
'player_details_shortcode' => false,
'player_statistics_shortcode' => false,
'player_list_shortcode' => false,
@@ -47,9 +47,9 @@ class SP_AJAX {
}
/**
* AJAX countdown shortcode
* AJAX event_countdown shortcode
*/
public function countdown_shortcode() {
public function event_countdown_shortcode() {
?>
<div class="wrap sp-thickbox-content" id="sp-thickbox-event_calendar">
<p>
@@ -393,7 +393,7 @@ class SP_AJAX {
/**
* AJAX league_table shortcode
*/
public function league_table_shortcode() {
public function table_table_shortcode() {
?>
<div class="wrap sp-thickbox-content" id="sp-thickbox-league_table">
<p>

View File

@@ -3,7 +3,7 @@ class SP_Widget_Countdown extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_countdown widget_sp_countdown', 'description' => __( 'A clock that counts down to an upcoming event.', 'sportspress' ) );
parent::__construct('sp_countdown', __( 'Countdown', 'sportspress' ) . ' (' . __( 'SportsPress', 'sportspress' ) . ')', $widget_ops);
parent::__construct('sportspress-countdown', __( 'Countdown', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {

View File

@@ -3,7 +3,7 @@ class SP_Widget_Event_Blocks extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_sp_event_blocks', 'description' => __( 'A list of events.', 'sportspress' ) );
parent::__construct('sp_event_blocks', __( 'Event Blocks', 'sportspress' ) . ' (' . __( 'SportsPress', 'sportspress' ) . ')', $widget_ops);
parent::__construct('sportspress-event-blocks', __( 'Event Blocks', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {

View File

@@ -3,7 +3,7 @@ class SP_Widget_Event_Calendar extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_calendar widget_sp_event_calendar', 'description' => __( 'A calendar of events.', 'sportspress' ) );
parent::__construct('sp_event_calendar', __( 'Event Calendar', 'sportspress' ) . ' (' . __( 'SportsPress', 'sportspress' ) . ')', $widget_ops);
parent::__construct('sportspress-event-calendar', __( 'Event Calendar', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {

View File

@@ -3,7 +3,7 @@ class SP_Widget_Event_List extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_sp_event_list', 'description' => __( 'A list of events.', 'sportspress' ) );
parent::__construct('sp_event_list', __( 'Event List', 'sportspress' ) . ' (' . __( 'SportsPress', 'sportspress' ) . ')', $widget_ops);
parent::__construct('sportspress-event-list', __( 'Event List', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {

View File

@@ -3,7 +3,7 @@ class SP_Widget_League_Table extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_league_table widget_sp_league_table', 'description' => __( 'Display a league table.', 'sportspress' ) );
parent::__construct('sp_league_table', __( 'League Table', 'sportspress' ) . ' (' . __( 'SportsPress', 'sportspress' ) . ')', $widget_ops);
parent::__construct('sportspress-league-table', __( 'League Table', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {

View File

@@ -3,7 +3,7 @@ class SP_Widget_Player_Gallery extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_player_gallery widget_sp_player_gallery', 'description' => __( 'Display a gallery of players.', 'sportspress' ) );
parent::__construct('sp_player_gallery', __( 'Player Gallery', 'sportspress' ) . ' (' . __( 'SportsPress', 'sportspress' ) . ')', $widget_ops);
parent::__construct('sportspress-player-gallery', __( 'Player Gallery', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {

View File

@@ -3,7 +3,7 @@ class SP_Widget_Player_list extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_player_list widget_sp_player_list', 'description' => __( 'Display a list of players.', 'sportspress' ) );
parent::__construct('sp_player_list', __( 'Player List', 'sportspress' ) . ' (' . __( 'SportsPress', 'sportspress' ) . ')', $widget_ops);
parent::__construct('sportspress-player-list', __( 'Player List', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {

View File

@@ -3,7 +3,7 @@ class SP_Widget_Staff extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_staff widget_sp_staff', 'description' => __( 'Display a single staff member.', 'sportspress' ) );
parent::__construct('sp_staff', __( 'Staff', 'sportspress' ) . ' (' . __( 'SportsPress', 'sportspress' ) . ')', $widget_ops);
parent::__construct('sportspress-staff', __( 'Staff', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {