2021-01-29, 06:16 PM
(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:
And here are my current ideas:
- 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?
- 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?
- Add the following three ACP settings:
- 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.
- Link preview whitelisted/blacklisted domains. (A free-form list of domains, or perhaps of regexes to match domains against).
- Disable link previews for links within this board's domain:
- Yes
- No
- 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.
- 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
.
- Add two directories under
inc/plugins/linktools
:link-helpers-dist
andlink-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.
- 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:
- 3rd-party link helpers take precedence over distributed link helpers.
- Thereafter, the link helper with the highest priority takes precedence. If any two link helpers have the same precedence, the choice is made arbitrarily.
- 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.
- Also, auto-regenerate a preview after a given amount of time has elapsed (say, perhaps, a week?).
- 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.
- 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.
- 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


[MyBB 1.8 Czech translation] [MyBB 1.8 plugins]: Prune old PMs + optimize DB plugin --- Thank you/like system