Howto: change the notification subject and allow KB images in GLPI version 0.90.3

GLPI released their new version 0.90.3.
With new each release two questions seem to be very persistent. These questions are:

  1. How can we change the default notification prefix: [GLPI ] in the email  subject.
  2. How do we enable images in the KB articles.

In this article you will be able to read my personal  opinion on the matter and how to change this GLPI behavior.

Why do you want to change the GLPI  notification prefix.

The most obvious reason is to allow your customer to quickly identify your companies tickets. The rule of thumb in modern system view design is enabling users to quickly: ‘scan, select. act’ Changing the subject to something intuitive enables your customers to do so.

Another point of interest is the possibility to daisy-chain multiple installations of GLPI. By configuring the notification subjects and schemes correctly you can daisy chain multiple installations allowing cross organization enterprise environments to be set up. This is impossible when all installations identify themselfs as ‘GLPI [key].’

How to alter the code to support your custom prefix in GLPI 0.90

In order to alter the subject prefix in GLPI 0.90,  firstly you need to configure your prefix in the Administration>Entities>[your entity]>notifications>Prefix for notifications. Changing this configuration field will correctly alter the prefix to that of your liking. No further code-hacks are required or advised.

Why do you want images in your KB.

Well this is -in my humble opinion- an no brainer. One images shows more detail then i can describe in a thousand words. Images also help speed up the resolution process, especially during nightly hours. It also allows the engineer to intuitively compare the version of the actual situation with the situation documented. Is it all positive then? no, there are some downsides to consider as well.

An image doesn’t replace the engineers know-how and sometimes you want to explicitly trigger this knowledge by not showing any images. Updated applications might look different, actually slowing down the resolution process. Another more technical downside is web server storage. All images need to be stored somewhere and might needlessly clutter the support-system. My point of view is that you need to decide whats best for your situation. Sadly GLPI doesnt allow you to choose yet, it forces images to be removed. If you do need image support, please apply the code-hack below.

Be aware, This wont enable image export to pdf.

How to enable images in the KB

First we need to enable the INSERT function that enables us to add images using the TinyMCE editor. In order to do this two changes need to be made.

In the inc/html.class.php file on line:3837 and line:3871 comment out ( // ) the lines that reads _html = _html.replace .. See screenshots for more details.

Optionally you can enable the ‘image’ button by adding image to the ‘theme_advanced_buttons2 : ‘ line. See images underneath for more details.

 

The next step is to enable the images to be shown. Without this change the HTMLAWED plugin will add a denied tag to the actual images effectivly telling the browser not to show the image. Additionally the resulting HTML code including the denied: tag will be stored in database also disabling this specific image after the next code modification. Enabling the images afterward requires an search and replace statement in the database. (See comments below).

In the file /lib/htmlawed/htmLawed.php on line 47 add ‘;src: data’ to the end of the line.

Make sure you use an screenshot tool that generates an inline HTML image on the clipboard. Greenshot is an free alternative that does this out of the box.

Enjoy!

About Chris Gralike

Momenteel ben ik manager van de afdeling business continuity bij de zakelijke IT dienstverlener AMIS Services BV. Sinds 2003 ben ik actief in de ICT branche. Tussen 2003 en nu heb ik verschillende rollen vervuld. In de rollen: systeem- en netwerkbeheer, system engineer, servicemanager en nu practice manager ben ik in contact gekomen met uiteenlopende technologieën, methodologieën, ideeën, oplossingen en innovaties. Een rijke ervaring waarmee ik de klanten van Conclusion en AMIS elke dag probeer te ondersteunen. Mijn credo: 'Altijd opzoek een win-win tussen business en technologie.'

Posted on December 6, 2015, in Apache 2.2 Linux, GLPI, Linux, PHP, Tooling and tagged , , , , , , , , , , , . Bookmark the permalink. 21 Comments.

  1. Hi Chris
    Thanks for this, unfortunately the images I paste in are showing up when editing the kb article but not when viewing it.
    This is what the source shows:

    This is for a newly created post, so I’m guessing I’ve missed something obvious

    Any ideas?

    Many thanks

    David

  2. Hi David,

    If my memory serves me right the articles are stored in the database. So you might need to remove the denied: tag from the database table holding the articles html source.

    Please check the next SQL statement on a development database first. It should remove any stored denied: tags from the <img src="denied:base64 html source.

    update glpi_knowbaseitems set answer =REPLACE(answer, 'denied:', '');

  3. Hi Chris.

    I made this changes in brand new GLPI 0.90.3.
    I still can not paste a picture.

    Could you help me?

    Richard

  4. Hi Richard,

    Sadly we didnt install that version yet. When i find the time I will have a look.

    If i may ask, what tool are you using to paste the images?

    We are using Greenshot ourselfs and works quite nicely.

  5. Hi,
    Thanks for your tips.
    I have made your advice and now i can paste image but when i paste more than one image i have a bug:
    the first image is pasted at the cursor position but the other image was pasted at the begining of the post.
    I have to edit the html code to put the image at the good place.
    Could you help me ?
    Regards,
    vlepetit

    • Hi Vlepetit,

      Im not sure what causes the behavior you describe. This might be an tinyMCE related bug in which case you could search the tinyMCE fora. You might also want to review the changes made in the html.class.php file. Typos might also cause unintended behavior. You might want to review the images above to see my version.

      I hope these tips will help you out.

    • Same problem for me. Only the first image is correctly placed under the cursor location. I’m looking for solution, but it also happens in 0.90.5.

      And a tip: Images 250KB are not shown “as images”. They are shown as:
      <img src="data:image/png;base64,iVBORw0……………………..
      but only in the global article's view. TinyMCE shows it perfectly.

    • A workaround for this problem is not only to comment the lines 3837 and 3871 in “html.class.php”, but also: 3836, 3837, 3838, 3839, 3840, 3841, 3842, 3843, 3844, 3845, 3846, 3847, 3870, 3871, 3872 and 3873. Like this:

      […]
      if(_html != undefined) {
      // if (_html.match(/]+src=\”data:image.*?;base64[^>]*?>/g)){
      // _html = _html.replace(/]+src=\”data:image.*?;base64[^>]*?>/g, ”);
      // tinyMCE.activeEditor.setContent(_html);
      // } else {
      // that = {
      // e: elem
      // }
      // that.callself = function () {
      // waitforpastedata(that.e)
      // }
      // setTimeout(that.callself,20);
      // }
      }
      }

      […]

      paste_preprocess : function(pl, o) {
      _html = o.content;
      // if (_html.match(/]+src=\”data:image.*?;base64[^>]*?>/g)){
      // _html = _html.replace(/]+src=\”data:image.*?;base64[^>]*?>/g, ”);
      // o.content = _html;
      // }
      },

      […]

      It is working for me now, but I’m not sure about the reason of why it works🙂

  6. Goemaere Kevin

    Did you ever found how to make this work in the latest version?

  7. Goemaere Kevin

    Also i don’t get the last bit
    In /lib/htmlawed/htmLawed.php:47 alter the $x and add ;src data’ to the end.

    The syntax is all messed up. Can you specify where the ;src data’ should be added?
    Thanks

  8. Goemaere Kevin

    Ok now i can add the last src:data correct but when i copy a picture it only adds a tag with nothing in it.

    Thanks by the way for the pictures.

  9. Hi Chris,

    Probably on you environment works fine. But I just tried on 90.4 do the same actions as you wrote. Line numbers match. But by default “In the inc/html.class.php file on line:3837 and line:3871 comment out ( // )” lines are not commented. And seems that by default image paste should be work. But something is stops to paste in and create <img src:data content.

    • Hi Tadas,

      There are two components that you need to take into account. Firstly TinyMCE has an editing function (past) and view function (content in the tinyMCE editor). The second component is the content shown by GLPI when it is not being edited.

      Concerning the tinyMCE component.

      The lines you describe are part of the input and output filters used by tinyMCE. The specific lines use a regex formula to find all [<img src="data:image base64] tags in the input (paste) and output (print) functions of tinyMCE and replace them with nothing ''. This effectively removes the images. But only within tinyMCE.

      Putting a comment in front of those lines will stop tinyMCE from replacing these image tags with nothing. Effectively allowing images to be processed and being passed to GLPI.

      Concerning GLPI.

      When the content is passed by tinyMCE to GLPI it is saved in the GLPI database. Before the content is actually saved in the database it is 'made save' and being filtered by the htmLawed lib. The default behaviour of this lib is to add the html tag :disabled to all 'unallowed' html tags. Adding the img src as allowed tag will stop the htmLawed lib from adding :disabled to the image tags. This will effectively allow images to be shown in KB articles when they are being viewed from GLPI.

      Be aware, once content is saved in the database without this modification, the saved content will have this :disabled tag and will not show up. Not even after changing the htmLawed module. To fix this i spammed a 'search replace' sql statement somewhere in the comments.

      Hope this helps understanding the change in more depth.

  10. in addition,

    Be sure you have an snippet tool that stores the images on the clipboard in an ‘inline HTML’ format. If you are not sure about this, please download Greenshot (opensource) and give that tool a go.

    http://getgreenshot.org/

    The previous poster got his issues fixed by downloading and using Greenshot.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: