This PR introduces the QuickPhoto addon, designed to improve the user experience within the Friendica editor. It addresses the issue of long, cluttered BBCodes (monster-links) that appear when images are inserted via drag-and-drop or the image uploader. Key Features - Automatic Simplification: Replaces complex [url=...][img=...]...[/img][/url] structures with a human-readable shorthand: [img]filename|description[/img]. - Seamless Reconstruction: Automatically restores the full, valid Friendica BBCode before previewing or submitting a post, ensuring 100% compatibility with the server. - Enhanced Readability: Keeps the editor clean and focus-oriented while writing long posts with multiple images. Technical Highlights & Optimizations - Resource Efficient: The JavaScript is strictly scoped. It only becomes active if a textarea is present and visible in the DOM. - Zero Latency Typing: Implements requestIdleCallback and throttling (500ms) to ensure that the simplification process never interferes with the user's typing flow or causes UI lag. - Background Throttling: Logic is suspended when the browser tab is inactive (document.hidden) to save CPU and battery life. - LocalStorage Cache: Uses a local cache for image data (auto-cleaned after 12 hours) to ensure reliability during a single editing session. Testing performed - Tested with the standard "Jot" editor and the newer Compose/Comment templates. - Verified that image previews render correctly (reconstruction triggers on preview click). - Verified that the final post contains the correct full BBCode on the server side. - Confirmed that Drag & Drop inserts are handled immediately.
32 lines
No EOL
1,013 B
PHP
32 lines
No EOL
1,013 B
PHP
<?php
|
|
/**
|
|
* Name: QuickPhoto
|
|
* Description: Client- and server-side reconstruction for maximum compatibility.
|
|
* Version: 1.1
|
|
* Author: Matthias Ebers <https://loma.ml/profile/feb>
|
|
*/
|
|
|
|
use Friendica\Core\Hook;
|
|
|
|
function quickphoto_install() {
|
|
Hook::register('page_header', 'addon/quickphoto/quickphoto.php', 'quickphoto_header');
|
|
// Emergency hook: If the JS fails during transmission
|
|
Hook::register('post_post', 'addon/quickphoto/quickphoto.php', 'quickphoto_post_hook');
|
|
}
|
|
|
|
function quickphoto_header(&$header) {
|
|
$header .= '<script src="/addon/quickphoto/quickphoto.js?v=5.0"></script>' . "\n";
|
|
}
|
|
|
|
/**
|
|
* Processes the text directly upon receipt on the server
|
|
*/
|
|
function quickphoto_post_hook(&$item) {
|
|
if (!isset($item['body'])) {
|
|
return;
|
|
}
|
|
|
|
// If the JS couldn't do the job, we have the problem here
|
|
// that we don't have LocalStorage. That's why the JS is primarily responsible here.
|
|
// We'll leave this hook as a placeholder for future server validations.
|
|
} |