| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wpxero\Marqueex\Integrations\Shortcode; |
| 4 |
|
| 5 |
use Wpxero\Marqueex\Traits\Singleton; |
| 6 |
use Wpxero\Marqueex\Core\Settings; |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Shortcode Integration Class |
| 14 |
*/ |
| 15 |
class ShortcodeIntegration { |
| 16 |
use Singleton; |
| 17 |
|
| 18 |
/** |
| 19 |
* Constructor |
| 20 |
*/ |
| 21 |
private function __construct() { |
| 22 |
add_action('init', [$this, 'init']); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Initialize Shortcode integration |
| 27 |
*/ |
| 28 |
public function init() { |
| 29 |
// Check if integration is enabled |
| 30 |
$shortcode_enabled = Settings::get('builder_support.shortcode.enabled', true); |
| 31 |
|
| 32 |
if (!$shortcode_enabled) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
// Register shortcodes |
| 37 |
add_shortcode('marqueex_slider', [$this, 'render_slider_shortcode']); |
| 38 |
add_shortcode('marqueex_ticker', [$this, 'render_ticker_shortcode']); |
| 39 |
add_shortcode('marqueex_infinite', [$this, 'render_infinite_shortcode']); |
| 40 |
|
| 41 |
// Add shortcode documentation |
| 42 |
add_action('admin_footer', [$this, 'add_shortcode_documentation']); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Render Marquee Slider Shortcode |
| 47 |
*/ |
| 48 |
public function render_slider_shortcode($atts, $content = null) { |
| 49 |
$atts = shortcode_atts([ |
| 50 |
'speed' => '30', |
| 51 |
'direction' => 'left', |
| 52 |
'pause_on_hover' => 'true', |
| 53 |
'class' => '', |
| 54 |
'id' => '', |
| 55 |
], $atts, 'marqueex_slider'); |
| 56 |
|
| 57 |
$unique_id = 'marqueex-slider-' . uniqid(); |
| 58 |
$class = !empty($atts['class']) ? ' ' . esc_attr($atts['class']) : ''; |
| 59 |
$id = !empty($atts['id']) ? ' id="' . esc_attr($atts['id']) . '"' : ''; |
| 60 |
|
| 61 |
$output = sprintf( |
| 62 |
'<div%s class="marqueex-slider%s" data-speed="%s" data-direction="%s" data-hover-paused-enabled="%s">%s</div>', |
| 63 |
$id, |
| 64 |
$class, |
| 65 |
esc_attr($atts['speed']), |
| 66 |
esc_attr($atts['direction']), |
| 67 |
esc_attr($atts['pause_on_hover']), |
| 68 |
do_shortcode($content) |
| 69 |
); |
| 70 |
|
| 71 |
return $output; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Render News Ticker Shortcode |
| 76 |
*/ |
| 77 |
public function render_ticker_shortcode($atts, $content = null) { |
| 78 |
$atts = shortcode_atts([ |
| 79 |
'speed' => '30', |
| 80 |
'direction' => 'left', |
| 81 |
'pause_on_hover' => 'true', |
| 82 |
'label' => 'BREAKING', |
| 83 |
'show_label' => 'true', |
| 84 |
'class' => '', |
| 85 |
'id' => '', |
| 86 |
], $atts, 'marqueex_ticker'); |
| 87 |
|
| 88 |
$unique_id = 'marqueex-ticker-' . uniqid(); |
| 89 |
$class = !empty($atts['class']) ? ' ' . esc_attr($atts['class']) : ''; |
| 90 |
$id = !empty($atts['id']) ? ' id="' . esc_attr($atts['id']) . '"' : ''; |
| 91 |
|
| 92 |
$output = '<div class="marqueex-news-ticker-wrapper">'; |
| 93 |
|
| 94 |
if ($atts['show_label'] === 'true') { |
| 95 |
$output .= sprintf( |
| 96 |
'<div class="marqueex-ticker-label">%s</div>', |
| 97 |
esc_html($atts['label']) |
| 98 |
); |
| 99 |
} |
| 100 |
|
| 101 |
$output .= sprintf( |
| 102 |
'<div%s class="marqueex-news-ticker%s" data-speed="%s" data-direction="%s" data-hover-paused-enabled="%s">%s</div>', |
| 103 |
$id, |
| 104 |
$class, |
| 105 |
esc_attr($atts['speed']), |
| 106 |
esc_attr($atts['direction']), |
| 107 |
esc_attr($atts['pause_on_hover']), |
| 108 |
do_shortcode($content) |
| 109 |
); |
| 110 |
|
| 111 |
$output .= '</div>'; |
| 112 |
|
| 113 |
return $output; |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Render Infinite Slider Shortcode |
| 118 |
*/ |
| 119 |
public function render_infinite_shortcode($atts, $content = null) { |
| 120 |
$atts = shortcode_atts([ |
| 121 |
'speed' => '30', |
| 122 |
'direction' => 'left', |
| 123 |
'pause_on_hover' => 'true', |
| 124 |
'gap' => '20', |
| 125 |
'class' => '', |
| 126 |
'id' => '', |
| 127 |
], $atts, 'marqueex_infinite'); |
| 128 |
|
| 129 |
$unique_id = 'marqueex-infinite-' . uniqid(); |
| 130 |
$class = !empty($atts['class']) ? ' ' . esc_attr($atts['class']) : ''; |
| 131 |
$id = !empty($atts['id']) ? ' id="' . esc_attr($atts['id']) . '"' : ''; |
| 132 |
|
| 133 |
$output = sprintf( |
| 134 |
'<div%s class="marqueex-infinite-slider%s" data-speed="%s" data-direction="%s" data-hover-paused-enabled="%s" data-gap="%s">%s</div>', |
| 135 |
$id, |
| 136 |
$class, |
| 137 |
esc_attr($atts['speed']), |
| 138 |
esc_attr($atts['direction']), |
| 139 |
esc_attr($atts['pause_on_hover']), |
| 140 |
esc_attr($atts['gap']), |
| 141 |
do_shortcode($content) |
| 142 |
); |
| 143 |
|
| 144 |
return $output; |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Add shortcode documentation to admin |
| 149 |
*/ |
| 150 |
public function add_shortcode_documentation() { |
| 151 |
$screen = get_current_screen(); |
| 152 |
|
| 153 |
// Only show on post edit screens |
| 154 |
if (!$screen || !in_array($screen->base, ['post', 'post-new'])) { |
| 155 |
return; |
| 156 |
} |
| 157 |
|
| 158 |
?> |
| 159 |
<div id="marqueex-shortcode-help" style="display: none;"> |
| 160 |
<div class="marqueex-shortcode-docs"> |
| 161 |
<h3><?php esc_html_e('MarqueeX Shortcodes', 'marqueex'); ?></h3> |
| 162 |
|
| 163 |
<h4><?php esc_html_e('Marquee Slider', 'marqueex'); ?></h4> |
| 164 |
<code>[marqueex_slider speed="30" direction="left" pause_on_hover="true"]Your content here[/marqueex_slider]</code> |
| 165 |
|
| 166 |
<h4><?php esc_html_e('News Ticker', 'marqueex'); ?></h4> |
| 167 |
<code>[marqueex_ticker speed="30" direction="left" label="BREAKING" show_label="true"]Your news content here[/marqueex_ticker]</code> |
| 168 |
|
| 169 |
<h4><?php esc_html_e('Infinite Slider', 'marqueex'); ?></h4> |
| 170 |
<code>[marqueex_infinite speed="30" direction="left" gap="20"]Your slider content here[/marqueex_infinite]</code> |
| 171 |
|
| 172 |
<p><strong><?php esc_html_e('Parameters:', 'marqueex'); ?></strong></p> |
| 173 |
<ul> |
| 174 |
<li><strong>speed:</strong> <?php esc_html_e('Animation speed (10-100)', 'marqueex'); ?></li> |
| 175 |
<li><strong>direction:</strong> <?php esc_html_e('left, right, up, down', 'marqueex'); ?></li> |
| 176 |
<li><strong>pause_on_hover:</strong> <?php esc_html_e('true or false', 'marqueex'); ?></li> |
| 177 |
<li><strong>label:</strong> <?php esc_html_e('Label text for ticker (default: BREAKING)', 'marqueex'); ?></li> |
| 178 |
<li><strong>show_label:</strong> <?php esc_html_e('Show/hide label (true or false)', 'marqueex'); ?></li> |
| 179 |
<li><strong>gap:</strong> <?php esc_html_e('Gap between items in pixels', 'marqueex'); ?></li> |
| 180 |
<li><strong>class:</strong> <?php esc_html_e('Additional CSS classes', 'marqueex'); ?></li> |
| 181 |
<li><strong>id:</strong> <?php esc_html_e('Custom ID attribute', 'marqueex'); ?></li> |
| 182 |
</ul> |
| 183 |
</div> |
| 184 |
</div> |
| 185 |
|
| 186 |
<script> |
| 187 |
jQuery(document).ready(function($) { |
| 188 |
// Add shortcode button to toolbar |
| 189 |
if ($('#ed_toolbar').length) { |
| 190 |
$('#ed_toolbar').append('<input type="button" id="marqueex_shortcodes" class="ed_button" value="MarqueeX" title="Insert MarqueeX Shortcodes" />'); |
| 191 |
|
| 192 |
$('#marqueex_shortcodes').click(function() { |
| 193 |
$('#marqueex-shortcode-help').dialog({ |
| 194 |
title: 'MarqueeX Shortcodes', |
| 195 |
width: 600, |
| 196 |
height: 500, |
| 197 |
modal: true |
| 198 |
}); |
| 199 |
}); |
| 200 |
} |
| 201 |
}); |
| 202 |
</script> |
| 203 |
<?php |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Get shortcode examples |
| 208 |
*/ |
| 209 |
public function get_shortcode_examples() { |
| 210 |
return [ |
| 211 |
'slider' => [ |
| 212 |
'shortcode' => '[marqueex_slider speed="30" direction="left"]Your marquee content here[/marqueex_slider]', |
| 213 |
'description' => __('Basic marquee slider with customizable speed and direction.', 'marqueex'), |
| 214 |
], |
| 215 |
'ticker' => [ |
| 216 |
'shortcode' => '[marqueex_ticker label="BREAKING" show_label="true"]Breaking news content here[/marqueex_ticker]', |
| 217 |
'description' => __('News ticker with optional label and customizable settings.', 'marqueex'), |
| 218 |
], |
| 219 |
'infinite' => [ |
| 220 |
'shortcode' => '[marqueex_infinite gap="20" pause_on_hover="true"]Slider item 1 | Slider item 2 | Slider item 3[/marqueex_infinite]', |
| 221 |
'description' => __('Infinite slider with configurable gap and hover pause.', 'marqueex'), |
| 222 |
], |
| 223 |
]; |
| 224 |
} |
| 225 |
|
| 226 |
/** |
| 227 |
* Get integration status |
| 228 |
*/ |
| 229 |
public function get_status() { |
| 230 |
return [ |
| 231 |
'active' => true, |
| 232 |
'shortcodes_registered' => true, |
| 233 |
'shortcodes' => [ |
| 234 |
'marqueex_slider' => shortcode_exists('marqueex_slider'), |
| 235 |
'marqueex_ticker' => shortcode_exists('marqueex_ticker'), |
| 236 |
'marqueex_infinite' => shortcode_exists('marqueex_infinite'), |
| 237 |
], |
| 238 |
]; |
| 239 |
} |
| 240 |
} |
| 241 |
|