Loading...
 
Features / Usability

Features / Usability


Re: Adding HTML to captions using PluginImg

posts: 214

There is a change that you can make to the img plugin which would then allow you to put HTML in the desc parameter. If you do make this change, future Tiki upgrades could replace the img plugin code, and then you would lose your change. And, allowing someone to insert HTML into the desc parameter may allow them to insert malicious code, so it might not be safe.

If you are willing to take the risk, here is what you need to do.

Edit lib/wiki-plugins/wikiplugin_img.php, and in the first "wikiplugin_img_info()" function, change the 'filter' specified for the 'desc' parameter.

Copy to clipboard
'desc' => array( 'required' => false, 'name' => tra('Caption'), 'since' => '3.0', 'doctype' => 'text', 'filter' => 'text', 'description' => tr('Image caption. Use %0name%1 or %0desc%1 or %0namedesc%1 for Tiki name and description properties, %0idesc%1 or %0ititle%1 for metadata from the image itself, otherwise enter your own description.', '<code>', '</code>'), 'default' => '', ),


Change the filter option from 'text', which is what is currently preventing you from using HTML, to 'rawhtml_unsafe' (you can find the filter options in lib/core/TikiFilter.php).

Copy to clipboard
'desc' => array( 'required' => false, 'name' => tra('Caption'), 'since' => '3.0', 'doctype' => 'text', 'filter' => 'rawhtml_unsafe', 'description' => tr('Image caption. Use %0name%1 or %0desc%1 or %0namedesc%1 for Tiki name and description properties, %0idesc%1 or %0ititle%1 for metadata from the image itself, otherwise enter your own description.', '<code>', '</code>'), 'default' => '', ),

That is all you need to do to be able to put HTML in the desc parameter. I am not sure what HTML you are thinking of using, but I only tested it with bold, heading 1, and italics tags, which all worked fine.


If you would rather change the plugin so that you could use wiki syntax in the desc parameter, then along with changing the filter, you would also need to change one of the other lines of code.

To allow wiki syntax in the img plugin, first change the filter to 'wikicontent':

Copy to clipboard
'desc' => array( 'required' => false, 'name' => tra('Caption'), 'since' => '3.0', 'doctype' => 'text', 'filter' => 'wikicontent', 'description' => tr('Image caption. Use %0name%1 or %0desc%1 or %0namedesc%1 for Tiki name and description properties, %0idesc%1 or %0ititle%1 for metadata from the image itself, otherwise enter your own description.', '<code>', '</code>'), 'default' => '', ),

Then you have to change a line of code in the wikiplugin_img function to parse the wiki code that you put in the desc parameter. Change:

Copy to clipboard
//Add description based on user setting (use $desconly from above) and close divs isset($desconly) ? $repl .= $desconly : '';

to:

Copy to clipboard
//Add description based on user setting (use $desconly from above) and close divs isset($desconly) ? $repl .= TikiLib::lib("parser")->parse_data($desconly) : '';


With that change, you could put wiki code into the desc parameter, and it will be wiki parsed (I even tried using the mouseover plugin in the desc and it worked fine).

Another option is to make your own version of the img plugin and make the above changes to that, however there are some complications because every function in every one of the plugins has to have a unique name. If the functions don't all have unique names, you will find some things in your Tiki stop working. And the img plugin has 2 other function definitions within it. Those other 2 functions would have to be renamed so they are unique from their counterparts in the original img plugin, and the 3 lines of code that call those functions would have to be changed to use the new names.

Tom

There are no comments at this time.