Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

[MOD] Inline PDF

So, I've finally upgraded, and wanted to restore my previews mod, but didn't want to have to generate preview images again.. that was horrible and sometimes didn't work. 

This time, I've spent a few hours figuring out the plugin interfaces.. and generally failing to figure them out. :-(

Got it to work anyway. 


image

Basically, it takes PDF's or Images and embeds them in the thread entries responsible for uploading them. Without modifying core! :D My best mod yet. The PDF is fully scrollable/rotatable/printable etc, the links are preserved should you need to download them. Images are linked to the full image and are not rotated etc, the PDF rendering is fully standard browser dependant etc..  Tested with Firefox/Chrome/IE11, not successful on IE11.. can't figure out why, as browser is broken. Added a message about the browser sucking and providing the normal link.. This also happens in Opera if you don't have a PDF plugin.

It's pretty simple, the bulk of the work is done in javascript, which get's injected into the footer. Tested and works on 1.8-git. SHOULD work on future versions, depending on how the files are attached.. haven't tested on anything else though, let me know! This means it gracefully falls back to complete stock by disabling javascript, and the plugin is self-contained, so ZERO MODS to core are required. You simply clone the repo or download the zip from github and extract into /includes/plugins/ which should make a folder: "pdf_preview", but it could be called anything. 

Current features:
  • PDF Files attached to a thread entry (note/message/reply etc) are embedded as full PDF objects in the entry.
  • Images attached to a thread entry are inserted as normal <img> tags.
    • png
    • jpg
    • gif
    • svg
    • bmp
  • Text files attached to a thread entry are fetched via AJAX and inserted into the thread entry using <pre> (If enabled). 
  • HTML files are also fetched via AJAX and inserted (If enabled). 
  • Detects pjax and falls back to stock jQuery if not found.
Message me if you want more features, I'm thinking of adding a "Tick the box extension selection" or something to pick what to display.

TODO:
  • Extrude CSS into file
  • Add admin options for file-types
  • Maybe modify the output in PHP rather than JS.. haven't decided, see what people say. This is working for now.
«1

Comments

  • Just realised it would be fairly trivial to convert YouTube links into players and mp4 video attachments into embedded players as well.
  • Done: https://github.com/clonemeagain/attachment_preview

    New version is just called "Attachment Preview".. it's almost a complete rewrite in PHP rather than any javascript.

    I'm pretty proud of that, it includes the Youtube player feature, the admin inline-types options (as drop-down of groupings: All, PDF's only, Images only, PDF's & Images, All. Where All includes text & html. I use the osTickets html filters to prepare HTML & text before insertion. 

    The users are loving it! 

    Hmm, forgot about mp4.. 
  • MP4 and other HTML5 capable video formats enabled.. They work too. :-)

    If you choose "All " attachments, it now includes all video formats, and a Google Docs viewer for xls/xlsx/doc/docx attachments. This means all video attachments are replaced with players as well. 

    NOTE: You can't attach a youtube video, so that is why it is still separate.

    If I've missed your favourite attachment, let me know, I'm sure we can figure out how to embed it! :D

  • Check out my Plugin-API ! Yes, I've gone mad with power:


    Basically, the attachment_preview function modifies the DOM right? Why not expose that via Signals, so other plugins can send changes to the DOM in a simplified way?  Yeah. Because XPath is Super Simple! :D Also, because I didn't want to write my own customized version of this threads mod just for my team, in this way, I can throw things at it based on ticket_id/url/staff whatever, and edit the output in one go, rather than each plugin being responsible for converting HTML into DOMDocument and back again.. in turn.. wow that sounds really wasteful when you type it out, but that is the way this works. So, my idea was to subvert that, and inject new DOM elements into the single DOMDocument structure.. that way, it only has to be converted/printed once. Sweet. 
    It works too, I've got almost all my customisations already changed into Plugins for this, the only thing that doesn't work directly, is my mods to class.ticket.php.. which I probably shouldn't have made in the first place.. but you live you learn. 



    It depends on the attachments_preview plugin being enabled (you don't need to have it actually attaching things, it just needs to be enabled in osTicket for the bootstrap code to work). Currently the Signals stuff is in the develop branch, but I'll port it over when I've finished testing it. That reminds me, write tests. :-)
    It uses the same mechanism as attachments_preview, via Signal's (the osTicket internal comms system). Pretty cool.  Likely overkill for such a simple task, but it does work well, and doesn't change core.. so there's that.  Using this, any plugin can edit/replace/delete any part of the rendered HTML & inject scripts/stylesheets/html anywhere.. it works pretty well. 
    Might even write a "theme" plugin around it.. that could be cool. :-)
  • You're quickly becoming my favorite community member @grizly  :)
  • Cheers mate, I'm looking at compiling a phar to make install easier. 

    Just written a wiki page or two. 

    Thinking of making a css editor as well. Maybe with those color wheels like drupal's color module. 

    Then I was all.. what if I can allow Admins to install/uninstall older style [MOD]'s directly.. without having to edit the files themselves.. best of both worlds right? MOD's that NEED to edit core, can simply be created as a git formatted patch-set and ship them as mods for this plugin: https://github.com/clonemeagain/osticket-mod-to-plugin haven't even tested it a little bit, so it's probably very broken, but if it intrigues, I'll keep working on it. I like the idea of keeping my patches in one place, that I can easily install/uninstall.. And it could be sweet for all those "well, that sounds OK, but it's never going in core" type things. And it might help people upgrade, if they don't have to lose all their sweet customization from past versions.
  • Can this be modified to work with the Knowledgebase FAQ? Works great for tickets. Thank you.
  • Do you mean embedding attachments in KB articles? Hmm, sounds like a challenge. :-)

    Submitted a testable patch in this branch:

    And started a github issue for you here: 

    If you can test it, that would be great, I'll have a crack tomorrow, lost my demo server in all the fun, and now it's home time. 


  • Didn't work. I selected the option for KB under Manage Plugin as well. For reference I'm using osTicket (v1.9.14) on Ubuntu 14.04.4. Any relevant log files I can look at? Thanks.
  • @Grizly It's working now. I updated my system and rebooted. I did add the plugin and reboot prior. 
  • @grizly OK it stopped working again. I notice if I click the link to view, then press back on my browser it works as expected. Weird.
  • That would be pjax, I'll see what I can do.
  • Yeah, I initiallyt removed that thinking it "wouldn't be an issue with KB".. :-(

    It's fixed. I'll merge it with the master branch. Sweet idea mate, cheers!
  • That update seemed to fix the issue. Everything works as expected now. Thank you.
  • Awesome plugin @grizly, it's very helpful to our support system. The only problem we encountered (at least for us) was that when showing all the attachments straight away (attachments more than 1) the thread becomes quite large.

    So, we customized ticket-view-inc.php by adding a show/hide preview attachment button. By clicking on show the attachments are expanded, by clicking on hide all the attachments are closed again. It will be great if that already include in your plugin.
  • That's a great idea!
  • Works great in the admin panel ticket view but doesn't show on the client side. Should I be able to see the embedded attachments on the client side?
  • Hmm, no?

    This was written as a productivity enhancer for staff who have to use the software all day. I figured most customers would be interacting via email anyway, so it didn't seem worth it to figure out. 

    If you want to submit a pull-request, I'd be happy to integrate it. 
  • This should be added as a downloadable plugin on OSTicket, it's amazing to have the preview aspect.

    Also, I agree that it should only be on the staff side and not needed on client side. Unless this is going to be a social media helpdesk system :-D
  • Thanks for your support, makes me want to work on it some more. :)


    • This has been upgraded with PHP7 support. 
    • Images inlined are now clickable to the original image. 
    • CSS has been streamlined a bit, and updated to match the latest release.

  • Added audio player support for HTML5 <audio> objects. Works well for supported browsers. 

    If you're like me and have voicemail to email configured, then you'll be not wanting to download attached audio files to listen to them. 

    Also added more patches to the ::isTicketsView() function.. Still not perfect. If you've found any bugs, let me know ASAP. 
  • Plugin has been upgraded, faster than ever, less regex, more AJAX, another admin option:
    Now you can specify how many attachments to preview by default. Thanks @dhanykoe for the idea!

    Basically removed the client admin option, it doesn't work for them, so no point suggesting it might.

    It works properly with pjax now, apparently I needed to trick DOMDocument into loading snippets as XML.

    Appreciate the feedback everyone!
  • Hi Grizly!
    This mod is working perfectly.
    Will you have time to implement a button which can show/hide attachments?
  • Hi @vdb86, this was added to the new version https://github.com/clonemeagain/attachment_preview

    It let's you specify how many to preload, then adds buttons for the rest which load via ajax when clicked. 
  • Hi @Grizly!
    Saw that option!
    Although for some reason it won't save a different number for me.
    It's stuck to all.
    I've got to investigate.

    By the way, if you get a chance, please take a look at my attempt to "fix" behavior of separator tag.
    From what I can tell you're quite knowledgeable and understand some of the inner workings of osticket.
  • Hmm, odd. I'd love to see any logs you have from trying to save it. 

    Sometimes plugin configs get broken, you can rebuild the config by deleting the plugin, then "installing" it again. (Leave the files alone, just delete in the admin screen, and install again in the admin screen). This will reset the config back to defaults, and you can reconfigure them. 
  • That fixed it!
    Thank you :)

    Any chance you would let us select 0 as a number of initially shown attachments?
    That way they are not expanded right away but when we need them.
  • Ahh, I've used zero to indicate "show all". But it's possible. 
Sign In or Register to comment.