23 class WPDKEditorButton {
50 public $javascript =
'';
73 public function __construct( $id, $title, $javascript, $image =
'' )
75 $this->
id = sanitize_title( $id );
76 $this->title = $title;
77 $this->javascript = $javascript;
78 $this->image = $image;
88 public function html()
92 ed.addButton(
'<?php echo $this->id ?>',
93 <?php echo $this->toObject() ?>
106 public function toObject()
111 id :
"<?php echo $this->id ?>",
112 title :
"<?php echo $this->title ?>",
113 <?php echo $this->image() ?>
114 onclick :
function(){ <?php echo $this->javascript ?> }
127 private function image()
129 if ( empty( $this->image ) ) {
133 if ( is_string( $this->image ) ) {
136 elseif ( is_a( $this->image,
'WPDKHTMLTagImg' ) ) {
137 $url = $this->image->src;
140 return sprintf(
'image : "%s",', $url );
156 class WPDKTinyMCEPlugin {
183 public $description =
'';
201 public $author_url =
'';
219 public $version =
'';
228 public $buttons = array();
237 public $javascript =
'';
252 public function __construct( $name, $description, $javascript, $buttons, $version =
'1.0.0' )
255 $this->
id = sanitize_title( $name );
260 $this->description = $description;
261 $this->version = $version;
262 $this->buttons = $buttons;
263 $this->javascript = $javascript;
265 if ( current_user_can(
'edit_posts' ) && current_user_can(
'edit_pages' ) ) {
266 add_filter(
'mce_buttons', array( $this,
'mce_buttons' ) );
267 add_filter(
'mce_external_plugins', array( $this,
'mce_external_plugins' ) );
270 add_action(
'admin_head-post.php', array( $this,
'admin_head' ) );
271 add_action(
'admin_head-post-new.php', array( $this,
'admin_head' ) );
274 add_action(
'admin_footer-post.php', array( $this,
'admin_footer' ) );
275 add_action(
'admin_footer-post-new.php', array( $this,
'admin_footer' ) );
285 public function admin_footer()
288 <script type=
"text/javascript">
292 QTags.addButton(
'wpdk',
'WPDK', _WPDKShortcodes.open_dialog );
304 public function admin_head()
307 <script type=
'text/javascript'>
308 var _WPDKShortcodes = {
309 wpdk_uri_css :
'<?php echo WPDK_URI_CSS ?>',
310 wpdk_uri_javascript :
'<?php echo WPDK_URI_JAVASCRIPT ?>',
311 open_dialog :
function() { var dialog =
new WPDKTwitterBootstrapModal(
'wpdk-shortcodes-dialog',
'<?php _e( 'WPDK Editor Manager
', WPDK_TEXTDOMAIN ) ?>',
'<?php _e( '<h4>Information</h4><p>This feature coming in next soon release!</p>
', WPDK_TEXTDOMAIN ) ?>' ); dialog.display(); },
318 foreach( $this->buttons as $button ) {
319 $s[] = $button->toObject();
321 echo implode(
',', $s );
337 public function addButton( $button )
339 if ( is_a( $button,
'WPDKEditorButton' ) ) {
340 $this->buttons[] = $button;
353 public function mce_buttons( $buttons )
355 if ( empty( $this->buttons ) ) {
362 foreach ( $this->buttons as $button ) {
363 array_push( $buttons, $button->id );
378 public function mce_external_plugins( $plugin_array )
380 if( !empty( $this->javascript ) ) {
381 $plugin_array[$this->name] = $this->javascript;
383 return $plugin_array;
393 public function html()
396 <script type=
"text/javascript">
399 tinymce.create(
'tinymce.plugins.<?php echo $this->name ?>', {
408 init :
function ( ed, url )
411 ed.addButton(
'dropcap', {
414 image : url +
'/dropcap.jpg'
430 createControl :
function ( n, cm )
441 getInfo :
function ()
444 longname :
'<?php echo $this->description ?>',
445 author :
'<?php echo $this->author ?>',
446 authorurl :
'<?php echo $this->author_url ?>',
447 infourl :
'<?php echo $this->url ?>',
448 version :
'<?php echo $this->version ?>'
454 tinymce.PluginManager.add(
'<?php echo $this->id ?>', tinymce.plugins.<?php echo $this->name ?> );