I've created a plugin that allows you to use custom tags and use them in the editor. The idea is that these tags will be preprocessed by a php (or any other) script before they are actually displayed on the page. This particular file currently handles inclusion of videos from YouTube, Vimeo, and Czech Stream.cz. I've uploaded this file in the general "ckeditor 3" thread but I feel it rather belongs here.
The plugin now processes <youtube /> tags (works for vimeo and stream.cz as well) by default but you can create new optional tags by editing the config file (as of version 1.1).
The dialog currently relies on text fields only (I didn't need checkboxes so I didn't bother to include them yet) but in general, it works as expected.
To add an icon to the main menu, simply add 'youtube' to the toolbar definition in your config file.
To add a custom tag of your own, edit the config file (if you want to keep the youtube tag as well):
config.pubMeCustomTags = { youtube : { dtd : [ '$empty','$inline','$body','div' ] }, testtag : { dtd : [ '$empty','$inline','$body','div' ] } };
Then create relevant icons (images/testtag-icon.png and images/testtag-placeholder.png) and dialg file (dialogs/testtag-dialog.js). Add the icon to the toolbar as well and voila, it should be working now.
BTW: there there is a bug in the fakeobject handling. As it uses images as fakeobject placeholders, it forces paragraphs around any custom tag. I haven't been able to override this behavior yet. So block custom tags would need a little more php processing.
The appended file contains the plugin itself. You will also want to update the language file and add some php preprocessing so I've added the needed codes too:
Append the language file with:
// ... here is the original language file pubme : { // ... here I have some more language definitions for my cms system _pubme_extratags : { youtube : { fakeObjectTitle : "Video object (YouTube, Vimeo, Stream.cz)", mainMenu : "Video (YouTube, Vimeo, Stream.cz)", properties : "Video properties (YouTube, Vimeo, Stream.cz)", source : "Video source", explainsource : "YouTube: link generated by the 'Share' button<br />Others: url of the website with the video<br /> ", width : 'Video width (px)', height : 'Video height (px)', title : 'Title (name of the video)' } } }
PHP post-processing of the custom tag:
preg_match_all ("/<youtube([^>]*)>/i",$Article,$Matches); if (!empty($Matches[0])) { $DefaultWidth = 640; // 16/9 default $DefaultHeight = 360; $i=0; while (isset($Matches[0][$i])) { $inner = $Matches[1][$i]; $attributes = Array (); while ( strpos($inner,"=") !== false ) { $pos = strpos($inner,"="); $attribute = substr ( $inner, 0, $pos ); if (strpos($inner," ") !== false ) $attribute = substr($attribute,strrpos($attribute," ")+1); $attribute = trim ($attribute); $pos = false; $pos1 = strpos($inner,"'"); $pos2 = strpos($inner,'"'); $pos3 = strpos($inner,'>'); if ($pos1 !== false) $pos = $pos1; if ($pos2 !== false && ($pos2<$pos || $pos === false) ) $pos = $pos2; if ($pos3 !== false && ($pos3<$pos || $pos === false) ) $inner = ""; $useChar = substr ( $inner, $pos, 1 ); $inner = substr ( $inner , $pos + 1 ); if ( strpos ( $inner, $useChar ) !== false ) { $pos = strpos ($inner, $useChar ); $attributeValue = trim (substr ( $inner, 0, $pos )); $inner = substr ( $inner, $pos + 1 ); $attributes [ $attribute ] = $attributeValue; } else $inner = ""; } if ( empty ($attributes["width"]) && empty ($attributes["height"]) ) { $attributes["width"] = $DefaultWidth; $attributes["height"] = $DefaultHeight; } elseif ( empty ($attributes["width"]) ) $attributes["width"] = round ( $DefaultWidth / $DefaultHeight * $attributes["height"] ); elseif ( empty ($attributes["height"]) ) $attributes["height"] = round ( $DefaultHeight / $DefaultWidth * $attributes["width"] ); $usePlayer = "default"; if ( strpos ( $attributes["src"], "vimeo.com" ) !== false ) $usePlayer = "vimeo"; elseif ( strpos ( $attributes["src"], "stream.cz" ) !== false ) $usePlayer = "stream"; if ( strpos ($attributes["src"],"/") === false ) $attributes["src"] = "/" . $attributes["src"]; $attributes["src"] = substr ( $attributes["src"], strrpos ( $attributes["src"], "/" ) + 1 ); $title = ""; if ( !empty ($attributes["title"]) ) $title = " title = \"" . cms_htmlspecialchars ($attributes["title"]) . "\""; switch ( $usePlayer ) { case "vimeo": $youtubeTag = "<iframe src=\"http://player.vimeo.com/video/{$attributes["src"]}?title=0&byline=0&portrait=0\" width=\"{$attributes["width"]}\" height=\"{$attributes["height"]}\"{$title} class=\"pubmevideo pubmevideo_vimeo\" frameborder=\"0\" webkitAllowFullScreen=\"true\" mozallowfullscreen=\"true\" allowFullScreen=\"true\"></iframe>"; break; case "stream": $youtubeTag = "<object value=\"http://www.stream.cz/object/{$attributes["src"]}\" width=\"{$attributes["width"]}\" height=\"{$attributes["height"]}\"{$title} class=\"pubmevideo pubmevideo_stream\">" . "<param name=\"movie\" id=\"VideoSpot\">" . "<param name=\"allowfullscreen\" value=\"true\">" . "<param name=\"allowscriptaccess\" value=\"always\">" . "<embed src=\"http://www.stream.cz/object/{$attributes["src"]}\" width=\"{$attributes["width"]}\" height=\"{$attributes["height"]}\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\">" . "</object>" ; break; default: if ( strpos ( $attributes["src"], "watch?" ) === 0 && strpos ( $attributes["src"], "=" ) !== false ) $attributes["src"] = substr ( $attributes["src"], strpos ( $attributes["src"], "=" ) + 1 ); $youtubeTag = "<iframe src=\"http://www.youtube.com/embed/{$attributes["src"]}\" width=\"{$attributes["width"]}\" height=\"{$attributes["height"]}\"{$title} frameborder=\"0\" allowfullscreen=\"true\" class=\"pubmevideo pubmevideo_youtube\"></iframe>"; break; } $Article = str_replace ( $Matches[0][$i], $youtubeTag, $Article ); $i++; } }
Enjoy it!
Malis @ Pub-Me Content Management System
Re: Custom tags (YouTube, Vimeo, Stream.cz)
Customer and Community Manager, CKSource
Follow us on: Facebook, Twitter, LinkedIn
If you think you found a bug in CKEditor, read this!
Re: Custom tags (YouTube, Vimeo, Stream.cz)
2) extraPlugins : '_pubme_extratags', section
2)placed in proper location in toolbar and
3) kept the folder in in ckeditor/plugins .
Still i m unable to get this plugin . Is there anything else to be done ?
Re: Custom tags (YouTube, Vimeo, Stream.cz)
Also note that the pugin name is _pubme_extratags (this comes to the config.extraPlugins) while the toolbar icon name is youtube. It is so because the plugin is actually designed for various extra tags to be processed (although at this very moment, it handles only youtube and other video formats).
Also note that if you use more extraPlugins, no spaces are allowed in the config.extraPlugins definition i.e. you must not put a space after the comma in the following:
The minimum config file should thus be:
Re: Custom tags (YouTube, Vimeo, Stream.cz)
hi,

i manage to get the youtube icon up on the toolbar. However when i try to insert a video. all i get is an image of the youtube. how am i able to get the video to play?
Re: Custom tags (YouTube, Vimeo, Stream.cz)
Before displaying the page itself, you need to process the tag with php (or whatever programming language you use). The plugin description includes information on how to do it for the video formats mentioned in the heading of this thread.
Re: Custom tags (YouTube, Vimeo, Stream.cz)
Your plugin is exactly what I needed : flexible and easy to use! Thank you very much
Re: Custom tags (YouTube, Vimeo, Stream.cz)
Hi malis
I tried to use your plugin to handle some custom tags : <myvideo> & <mymusic> which aim at adding multimedia content.
So I wanted to set up a few tags :
The issue was the following :
If I insert a myvideo or a youtube tag, a mymusic tag was inserted instead, even when right-clicking the fake image it opened the mymusic configuration window.
After spending a few moments trying to figure out your code works, I finally pointed out where does this issue come from. The var you used "pubmeTagName" was always referencing to the last tag of the list. So here it was <mymusic>.
So I made a little fix for this that you can find attached to this post or on pastebin : http://pastebin.com/g2ygMKaS
- Line 18 : I add to make a little utility function InArray which will be used later in the code
- Line 85 : Init tagName with contextual value : tagName = t._.name;
- Lines 214 - 265 : context menu and double click have been taken away from the for loop, instead we will make one function for handling the context menu and one for the double click whatever the number of custom tags we use
- Lines 280 - 317 : context menu and double click are now managed here working with the contextual information and the list of registered custom tags
Feel free to update your plugin. On my installation of CKEditor this fix worked perfectly.
Regards, Leward.
Re: Custom tags (YouTube, Vimeo, Stream.cz)
Great plugin!
I'm using your (Leward) fix with 2 other tags and it works.
But when I switch from viewing the "source" and back, the icon changes back to "youtube"-icon..
The tag doesn't change, but when I click on it I'll get the youtube dialog..
What could be wrong?
Custom tags v 1.1
April 23, 2012 - v 1.1 - Plugin update and fix:
- Fixed: The first version was buggy if you tried to use it with more than 1 tag. This update fixes it.
- New: It adds a possibility of adding new tags from the config file - you do not need to edit the plugin itself at all. Just add a dialog script, some icons and register the new tag in the config file and that's it.
Download
_pubme_extratags_1_1.zip
PS: Sorry for taking so long, I had some higher-priority work to do. But better late than never, right?
Attachments:
Re: Custom tags (YouTube, Vimeo, Stream.cz)