SMF 2.0 RC3: Flickr HTML code to BBCode mod [working]

We are developing a photographic website (with an SMF 2.0 RC3 forum) and most of our users have their photos hosted in Flickr.

(Note: I have installed WYSIWYG Quick Reply v2 RC3 package)

So I’d like to make their lifes easier when sharing their photos by adding a custom button (here in the post wysiwyg editor) which converts this html structure (the code snippet flickr shows to the user):

<a href="URL1" title="this_is_the_title"><img src="IMGURL" width="342" height="500" alt="alt_text" /></a>

To something like:

[url=URL1][img]IMGURL[/img][/url]

How to do this?

* Edit your Themes/default/GenericControls.template.php
* Locate:

function template_control_richedit($editor_id, $smileyContainer = null, $bbcContainer = null)
{
	global $context, $settings, $options, $txt, $modSettings, $scripturl;
 
	$editor_context = &$context['controls']['richedit'][$editor_id];

* Add after:

?>
	<script language="javascript">
	    function convierteCode(){
	    	// dado un codigo tipo flickr lo convierte a BBCode (def en GenericControls.template.php)
                        var flickr = document.getElementById("flickrcodeinput").value;
			flickr = flickr.replace('<a href="','[url=');
			flickr = flickr.replace('" /></a>','[/img][/url]');
			flickr = flickr.replace(/"(.)+title(.)*><img(.)+src="/,'][img]');
			flickr = flickr.replace(/"(.)+width(.)*\[/,'[');
			flickr = flickr.replace('[/url]','[/img][/url]');											 
			document.getElementById("message").value += flickr;
			window.frames[0].document.write(flickr);
	    }
	</script>
<?php

*Locate:

echo '
		<div>
			<div>
				<textarea class="editor"

* Replace with:

echo '
		<div>
			<div>
			    <!-- flickr input and button-->
                               <input type="text" id="flickrcodeinput" width="100px"></input>&nbsp;
                               <input type="button" value="Inserta IMG flickr" onClick="convierteCode();"></input>
                               <br /><br />
                            <!--flickr input and button end -->
				<textarea class="editor"

* Upload the new GenericControls.template.php

(Note for curious people: I also tried this by adding a custom button which would produce a new bbcode like [flickr][/flickr] and blahblahblah, but I could not make it work. More details here)

Related posts:

  1. dfgallery 2.0: Flickr “this photo is currently unavailable” [SOLVED]
  2. DeepZoom & SEADragon (II)
  3. Spoiler div con HTML and Javascript
  4. Joomla plugin and templating: how to know if you are in the frontpage

One Response to “SMF 2.0 RC3: Flickr HTML code to BBCode mod [working]”

  • Angel says:

    Encontré tu blog buscando específicamente esto. Misma situació: un blog SMF de fotografía, con usuarios usando Flickr. Lo intente, pero sin éxito. :(

Leave a Reply

Paypal donate

Please help me keep this blog up by donating.

Por favor, ayúdame a continuar con el blog donando.