MyBB Community Forums

Full Version: Link Highlighter Plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(2021-01-28, 05:43 PM)Laird Wrote: [ -> ]Today I woke up inspired to add this feature to Link Tools as flagged as a possibility here. I have a bunch of ideas, but would love to hear what you guys are actually looking for. Am about to start coding, so get in quick. :-)

Here are some preliminary questions that I have:
  1. Should link previews be auto-inserted into the post during drafting of the post, perhaps as a tag which the editor then renders: [linkpreview]https://link.to/preview.html[/linkpreview]? Advantage of this approach: the poster can delete or move them before posting. Or should they be auto-inserted (without tags to control their placement/existence) only when the post is rendered? Advantages of this approach: the previews cannot be removed, and are consistently placed - which admins might appreciate. Should either approach be configurable either per-forum, per-usergroup, or for the board as as whole?
  2. Where in the post should link previews be inserted? If the sole contents of a post is a link, then the answer is easy: just append the preview to the post. But what if it is in the middle of a paragraph, or a list? Should the preview then be inserted after the paragraph/list (or at the end of the list item?)? Or should previews simply always be appended to the end of the post (kind of like attachments)? Finally, should each of these options be configurable, either per-post or for the board as a whole?
And here are my current ideas:
  1. Add the following three ACP settings:
       
    1.    
    2. Enable link previews for:
             
      •        
      • All domains.
               
      • No domains.
               
      • Only domains with link helpers.
               
      • Only domains with 3rd-party link helpers. [see below]
               
      • Only the following domains.
               
      • All domains except the following domains.
               
    3.    
    4. Link preview whitelisted/blacklisted domains. (A free-form list of domains, or perhaps of regexes to match domains against).
         
    5. Disable link previews for links within this board's domain:
             
      •        
      • Yes
               
      • No
               
    6.    
  2. Create a new base/default class "LinkHelper". This class would provide basic/generic functionality to generate a link preview given the link and its HTML. The preview's code would be stored in the plugin's urls database table - a new column would be added for this purpose. Another column would be added to indicate the datetime at which the preview was last generated.
  3. Any preview images downloaded (and optionally resized or otherwise manipulated) by an object of the LinkHelper class would be stored in a custom directory under uploads.
  4. Add two directories under inc/plugins/linktools: link-helpers-dist and link-helpers-3rd-party. These would contain classes which extend the LinkHelper class, and which Link Tools would auto-load. The first directory would contain link helpers distributed with the plugin and officially supported. The second would contain helpers obtained elsewhere or custom-written.
  5. Each link helper would stipulate the domain(s) for which it generates previews, potentially via a (set of) regex(es), as well as an integer priority (negative, zero, or positive). If multiple link helpers match the domain of a link for which a preview is to be generated, the link helper to be used is chosen by the following simple criteria:
       
    1.    
    2. 3rd-party link helpers take precedence over distributed link helpers.
         
    3. Thereafter, the link helper with the highest priority takes precedence. If any two link helpers have the same precedence, the choice is made arbitrarily.
         
  6. Make a manual "Regenerate Preview" feature available for any given link in case its target page has changed since the preview was last generated. Check the datetime at which the link was last regenerated to prevent flooding.
  7. Also, auto-regenerate a preview after a given amount of time has elapsed (say, perhaps, a week?).
  8. Provide a new entry under Tools & Maintenance => Recount & Rebuild to regenerate all link previews. This would be especially useful when either of the two new ACP settings were changed.
  9. Also, though, auto-generate missing previews on-the-fly as needed, so that the Recount/Rebuild tool doesn't need to be run - that Recount/Rebuild tool would simply be useful to speed up page rendering by ensuring that on-the-fly generation is not necessary.
  10. Finally, provide a function to invalidate all cached link previews (another database column would be provided for this purpose) so that every preview was auto-generated on-the-fly the next time it was needed, again making it unnecessary to use the Recount/Rebuild tool.

OK, that's about it so far. Suggestions and comments welcome.

Wow, another interesting project Smile When you will be ready, let us know, I will help with testing Smile
Hi, also consider adding some way to disable or remove embeds by post, freely by the author, just as you can remove embeds from Discord messages.
Great idea. Perhaps a little checkbox to append to the "Signature" and "Disable Smilies" checkboxes in the "Post Options" panel below the editor.

Here's an update. Auto-generated link previews are now functional, as you can see in the image below from working code:

[attachment=43711]

Everything's done except the items I numbered in my post above as 6, 8, and 10, plus Omar's suggestion of per-post disabling. Also, link previews currently appear only at the very end of each post, which may not satisfy everybody's needs, so I might need to improve that functionality to ensure they appear as close to the link itself as is reasonably possible. I've also realised that it would be useful to be able to clear the cached link previews of an individual Link Helper.

That's a remaining TODO list of about six items.

Will keep you updated on progress.
Another update: everything's now implemented except for the new Recount & Rebuild entry to regenerate link previews. Also, link previews still show at the very bottom of posts, but I probably won't change that for the initial development release.

That release isn't too far away.
I'll stop updating development progress in this thread and move over to the Link Tools thread, from this post onwards. The short version of the post is that I've pushed a bunch of commits which implement link previews to the public GitHub Link Tools repository.
Cross-posting from the Link Tools plugin thread:

Released version 1.1.0, with the following new feature:
  • Adds link preview functionality. A preview box at the bottom of the post is generated for each link in a post. Different types of preview can be generated for different sites/content, as supported by a customisable Link Previewer framework.
This is marked as a Development rather than Stable release simply because there is so much new code that it is very possible that undiscovered bugs lurk. It probably is safe to use on a production site, but exercise caution, and please report any bugs you encounter.
@Laird @Omar G WOW!!! Haven't checked this thread for quite a while now... I am speechless with all the development.


Anyway, I will check out the plugin and let you guys know.
Will be interested to know what you think, @vk_knight!
@Laird @Omar G.

Since this is a plugin request thread. And it has be done.. So, I am asking mods to lock this thread..
Pages: 1 2