Tiny Tiny RSS: Community

Hook for article attachments?


After testing with the HOOK_ARTICLE_FILTER I realized the $article object that is passed does not contain any attachment URLs. The Android app does a fantastic job of grabbing the highest resolution attachment and building a preview out of it, and I was hoping to build a plugin to accomplish that on the web-view.

Is there a hook that I’m missing that would allow me to grab an attachment URL and add it to the top of the content field as an img tag?


I thought it did? But I haven’t coded anything new with that hook I a while. Regardless, you get the article ID and can query the database for attachments.


Ahhh, didn’t realize DB queries weren’t frowned upon in plugins. Is there a sample plugin that has a query in it already so I can use the dev’s formatting?


cache_starred_images comes to mind as it looks for newly starred articles to save the images.


Great, thanks! Assuming the article is inserted before the hook is processed, should be a piece of cake with

select content_url from ttrss_enclosures where post_id=(select id from ttrss_entries where guid='GUID') order by width desc limit 1;


Depends on what you want to do.

You can dynamically modify the article in real-time when the user loads it in the front end (this is what I normally do so the original article is left as-is in the database). In this case enclosures will be there.

Or you can modify the article before it’s inserted, saving real-time processing. I typically do this for things that have to happen before, like removing certain images that I don’t want cached, etc. In this case, I can’t remember if enclosures have been processed you’d have to check the order of events.


Which hook do you use for each? Could you point me to your plugins? The former sounds great for something I’m thinking about trying, which is making a toggle for the combined view to show the first few lines of an article with a thumbnail and expand button to go with the Feedly theme.

I ended up using HOOK_ARTICLE_FILTER though I admit I’m not sure when these hooks run. Plugin is here: New Plugin: Inline attachments in feed


You can look at the PluginHost class for all the available hooks then grep them in the code to see where and how they are used. Then you can decide which one to use based on what you’re trying to do in the plugin.

As an example, I have follow a site that does something stupid with its images:

<img src="placeholder.gif" data-src-200="200px.jpg" data-src-800="800px.jpg" alt="">

It’s relying on JavaScript to pick the best image for the visitor and this obviously doesn’t work over an RSS feed. For the site in question I cache images because I read most of the articles and want the images readily available from my server. The problem, of course, is there’s no real image in the src attribute and TT-RSS sanitizes the content–stripping away the data-* attributes. So if I want to have TT-RSS serve the images cached I need to filter this before it’s inserted into the database. I use HOOK_ARTICLE_FILTER.

I also like to manipulate the article content served via the API when I use my mobile device, so for that I use HOOK_RENDER_ARTICLE_API, only this hook because else where I want the content to remain unchanged. It changes the content dynamically before it’s delivered to the client device (i.e. the content is rendered differently when I view it on a desktop machine versus my phone).

Pick the best hook for what you’re trying to do. For me, my general rule is to leave the content as original as possible in the database because I find it helps to troubleshoot things when they break. Therefore, I filter the content before delivering to the client where possible. This is just my preference though.


Super helpful. Thank you!


@JustAMAcUser Maybe you can help me out one last bit. I noticed in hunting that HOOK_RENDER_ENCLOSURE returns back a place I could push out HTML (or JS). This is what I need to add a plugin that alters the view. However, this doesn’t seem to run in the web view (I’m thinking maybe it’s for the API?). Do you know which hook would be best in the following use case:

  • Needs to run for each article list item
  • Needs to run after article list items are drawn/redrawn

The goal will be to alter the HTML/CSS in the listing to create a view with a thumbnail image.


If you’re trying to put the largest attachment at the top of the article content, then use HOOK_RENDER_ARTICLE_CDM and HOOK_RENDER_ARTICLE.

Attach to these, get the largest largest image, prepend it to the article’s content.

e: The enclosure hooks run when enclosures are being handled, at the end of the article content. This is useful for embedding media players, maybe creating a gallery view for images, etc. Some enclosure hooks can filter to remove attachments, etc.


Oh I’ve finished the attachment plugin (link above). I’m working on another one now that needs to modify the HTML of the article listing. Based on your description of enclosures, I don’t think that’s what I need. I need something that runs anytime new articles are added to the listing that also allows me to inject code.


If I understand you correctly, you probably want one of the headline hooks. They’re used when generating the the actual line item that you would click to open (in combined mode) or as a title (in expanded).