Hacking web things

Drupal modal dialogs can have various properties set through the data-dialog-options attribute. In fact, this attribute is implemented in the JQuery dialog widget API. One can write for instance

<a href="https://my-url" 
   class="edit-button use-ajax" 
   data-dialog-type="dialog" 
   data-dialog-renderer="off_canvas" 
   data-dialog-options="{&quot;width&quot;:400}">Edit</a>

This will open mi-url in an off-canvas dialog with a width of 400px.

The data-dialog-options attribute requires a json array. In the example above we use &quot; to write the quotes of the json array. The "normal" surrounding quotes open and close the html attribute.

The title of the modal can also be set by adding something like &quot;title&quot;:&quot;MyTitle&quot;. But in a twig template this doesn’t work if the title string is rendered through a variable. So one can’t write:

data-dialog-options="{&quot;title&quot;:&quot;" {{myVariable}} "&quot;}">Edit</a>

The first closing quotes, before {{myVariable}}, effectively tell twig to close the attribute. Twig then tries to make sense of what comes later on as different attributes, which results in a mess.

The solution for me was to define all the options separately, as a twig array:

{% set dataDialogOpts = { width: 400, title: maintitle } %}

In the above maintitle is a variable which I set earlier on in the template. I can then pass the variable as attribute to data-dialog-options, but it needs encoding and escaping first. Some of my titles had non-ascii characters which probably made the problem slightly more challenging than plain ascii. The solution was to json encode the twig array before escaping it, and for the latter to use the "html attr" strategy:

data-dialog-options = {{ dataDialogOpts|json_encode()|e('html_attr') }}

The complete link is:

<a
  href="{{ url }}"
  data-dialog-type="dialog"
  data-dialog-options= {{ dataDialogOpts|json_encode()|e('html_attr') }}
  data-dialog-renderer="off_canvas"
  class="use-ajax">{{ label }}</a>

Clicking on the label opens an off-canvas modal with its title set to my maintitle variable.

This Joomla 3.x plugin displays bibliographies from libraries made publicly available on zotero.org. To insert a bibliography in your content write something like {zotbib author="Wittgenstein" itemType="book"}. This will be replaced by a formatted list of all the books authored by Wittgenstein which are in your Zotero library.

Source code and detailed instructions at https://framagit.org/svictor/j3-zotbib.

Zip the files together (or choose the "download zip" option) to install it to your Joomla 3.x website.

Jevents is a Joomla addon to manage events in a calendar. Jevents comes with a module used to display selected events (forthcoming, latest etc.) on any page of the website. The module can display the title of the event, its description etc. However, it cannot natively display however an image inserted in the event’s description. My plugin allows for this.

When making websites with Joomla, I sometimes need to indicate the subcategory titles in category blogs.  The result should look like this:

 Subcat title A
Article 1
Article 2
Article 3

Subcat title B
Article 1
Article 2
Article 3

Subcat title C
Article 1
Article 2
Article 3

On the current website that’s how my publication list is formatted (Books, Edited volumes, Articles etc. are all subcategories of Publications).

Joomla can sort the articles by subcategory, but doesn’t output the subcategory title above the relevant set of articles. I made an override for blog.php for that. It's here on github.

Nowadays most Joomla components give access to ACL (access control list, basically usage permissions for each user groups) in their backend settings. But some very good ones don’t. This happens for components which have their own interface that completely bypasses Joomla’s. Example: the excellent ProFiles file manager by Mooj.

In the _assets table look for the line with your component name (in our case com_profiles). The rules should contain an empty array {}. If it’s not empty, it probably means that there is a permissions tab somewhere and you have missed it. Go back and look for it. Don’t mess with the database any further. If however the rules are just {}, insert instead something like:

{"core.admin":{"xx":1},"core.manage":{"xx":1}}

Where xx is the id of the user group you wish to enable access for. You get that id from the _usergroups table.

This is convenient especially for modules with a “dynamic” mode, like mod_articles_category. It allows to also change the title dynamically depending on the menu item.

Copy the default.php file from your module's tmpl folder into /templates/your_template/html/name_of_your_module/. Towards the begining of the file (but after "defined('_JEXEC') or die;") add this

<?php
// Dynamically assign module title depending on the menu item
// Exclude some modules by adding them to the modexclude[] array
$modexclude = [];
$active = JFactory::getApplication()->getMenu()->getActive();
if ($active && !in_array($module->id,$modexclude)) :
 $module->title = JText::sprintf(htmlspecialchars($active->title));
endif;
?>

The code will give dynamic titles to all instances of the plugin, but you can override specific ones by adding their ids to the modexclude[] array (separate with commas).

If you ever set SSL on parts of your site and later change your mind, you may run into trouble to revert to non-SSL. Of course, you have cleared your browser cache. In Firefox you have also right-clicked on the site name in your history and chose “Forget about this site” while no tab had the site opened. But when you type the non-https address, the browser still redirects you to https://

What’s even worse: you set a redirect like this in your .htaccess

## Disable https on public site. Force redirect to http.
RewriteCond %{HTTPS}       on
RewriteCond %{REQUEST_URI} !^(.*)/administrator/(.*)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} .
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

And then you screw the browser completely in an infinite loop. Ugly ain’t it?

Well, for one thing it probably occurs only in those browsers which have visited the page while https was on. If you just tested for a short period of time, this could be just yours. But still, you need to solve the problem. Try inserting the following line in your .htaccess (above the previous redirect block if using it).

## Unset
Header set Strict-Transport-Security "max-age=0"

If that works and you want to know why, read on here.

See: http://www.en.joomgallery.net/faq/general-faq/show-image-description-in-slimboxthickbox.html

On Community builder pages (and possibly all category views popups) :

In components/com_joomgallery/interface.php change this line:

$link .= '" title="'.htmlspecialchars($obj->imgtitle, ENT_COMPAT, 'UTF-8');

to the following:

$link .= '" title="'.htmlspecialchars($obj->imgtitle, ENT_COMPAT, 'UTF-8') .htmlspecialchars($obj->imgtext, ENT_COMPAT, 'UTF-8');

And also this one

$link .= '" title="'.htmlspecialchars($img->imgtitle, ENT_COMPAT, 'UTF-8');

to the following:

$link .= '" title="'.htmlspecialchars($img->imgtitle, ENT_COMPAT, 'UTF-8') .htmlspecialchars($img->imgtext, ENT_COMPAT, 'UTF-8');

[Subtle difference between the two : in 1st case the object is referred to as $obj and in the second as $img]

Joomgallery module has an option to wrap text (title, author, description...) but you have to specify the number of characters. This is not practical if your images have varying widths, especially if some are in landscape and others in portrait orientation. Here is how to set the output to wrap the text according to the image width.

First disable the wrapping in the module's interface, by setting the value to 0 (for title and description).

Then, in modules/mod_joomimg/helper.php, Look for the last occurence of $imgWidth. It should be in function modcontent(&$objects). Put this on a line after all if parenthesis {} are closed. The value of $imgWidth is calculated differently depending on some parameters. We need to get it after this, but before the end of the function:

$GLOBALS['largimage'] = $imgWidth;

This inserts the value in the $GLOBALS array, making it available for other functions.

Then in function rendercss(), find the line underlined below 

$css .= '.'.$csstag.'imgct {'."\n"
        . 'width:'.$containerwidth.'% !important;'."\n"
        . $csscont
        .'}'."\n";

And replace it with

        . 'width:'.$GLOBALS['largimage'].'px !important;'."\n"

That's it! The container now has the exact width of the image.

 

If you use joomgallery module to display random images uploaded by your users, you can easily display the author's name (that's in the module's options). But it appears in plain text. If you want to have it as a link to their profile, here is how.

Option 1: Use the JoomDisplayCBName plugin. It's actually the easiest and most complete way to do it... But I didn't know about it until after I had tweaked the php code. So I leave the 2nd option below, just in case.

Option 2: In components/com_joomgallery/interface.php, comment out the line which says

$output .= " <li>".JText::sprintf('COM_JOOMGALLERY_COMMON_AUTHOR_VAR', $authorowner);

And replace it by

$lienauteur = "<a href=\"index.php?option=com_comprofiler&task=userprofile&user=$obj->owner\"> $authorowner </a>";
$output .= "  <li>".JText::sprintf('COM_JOOMGALLERY_COMMON_AUTHOR_VAR', $lienauteur);

Of course the href url should be adapted if you use another user manager than community builder.

Problem: we want the styles of, say, the titles or the backgrounds to depend on the chosen menu item.

Solution: in Joomla 2.5 it's as simple as :

<div class="menuid_<?php echo (JRequest::getInt( 'Itemid', 1, 'get' )); ?>"

Then in the css file we just style .menuid_X and its children (X being the id of the menu item).

This is a template override for Joonla 2.5 to split Category blog layouts by category with their respective titles. Joomla 2.5 does sort the articles by categories if instructed to do so in the menu item's options, but it does not display the Subcategory titles when needed. I couldn't find an extension to do that. A simple layout override is enough however.