Attachments images rotation extension

Discussion forum for Extension Writers regarding Extension Development.
User avatar
axe70
Registered User
Posts: 188
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: Attachments images rotation extension

Post by axe70 »

I little rebuilt the code, to fix all remaining issues. Still not committed.

Fix if storage folder is not files
Fix code to save images, correctly handled under any aspect.

Fix as last issue, the cache issue, if the post is in "edit mode".

But it come out a problem to me, little hard to explain, hope someone will understand what i mean.

Let say i added the code that after image as been processed/rotated, delete the attach id row into db, then return the new assigned file ID. So it return an ajax response to setup immediately the new file ID to the just rotated attachment, into the attachments panel that display on post.
What i had to do, for what i see, was to push this new id into the src url of the image.
But when i go to save the post, the response from phpBB when post edited then saved, is an error, that's right, because the request do not contain the new id, but the old one that do not exist anymore, and it need to be changed into this specific hidden element inside the attachments panel:
"td.attach-comment > input"
where there is an input with value of the id of the image, that then i go to update also, together with URL of the image, that point to the new id:
<input type="hidden" name="attachment_data[0][attach_id]" value="15">
where 15 is the old image id, updated with new one.

When i save the post, now phpBB correctly process the post, images correctly shows in the new position.
But there is a but.
I note that if i process any of the attachments, doing this update to more then an attached image, and i go to save the edited post, the last image processed, even if not inserted into the post, display inside the post, despite it do not contained inside the post body via his callback: let say there is [attachment=1]Andorra.png[/attachment]
But the new image id do not refer to Andorra.png, obvious, but let say for example another.png, that even if a callback do not exist into the post, it display inside the post, on top of Andorra.png

Anybody know by what it is caused? which elements require to be updated, before to save the edited post, to avoid this result and why it come out?

Sure i will find the reason and why, but an help would avoid me the recurring headache!

[EDITED]
User avatar
axe70
Registered User
Posts: 188
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: Attachments images rotation extension

Post by axe70 »

So after an hour a solution come out, reversing things and problems:
on response, after image has been rotated, it is necessary to setup plupload lib to match the new rotated entry ID.
If this is not done, when after image rotated and changed ID, if you click into add attach inline and the placeholder should be added inline on the post text, it will return error.

The solution has been like this:

Code: Select all

	 $( "tr.attach-row[data-attach-id=\'"+fid+"\'" ).each(function () {
	 $( this ).attr("data-attach-id", fnew_id); 

var w3pushObj = new Object();
//Object { attach_id: 224, is_orphan: 1, real_filename: "Italy.png", attach_comment: "", filesize: 3200 }
w3pushObj['attach_id'] = fnew_id;
w3pushObj['is_orphan']   = forphan;
w3pushObj['real_filename'] = fn;
w3pushObj['attach_comment'] = 'comment';
w3pushObj['filesize'] = fsize;
phpbb.plupload.update(w3pushObj, 'addition', 0);
phpbb.plupload.data = w3pushObj;
I will test asap what really needed and what can be discarded, but as is works fine.

There is a problem, but it easily solvable in respect to the above: the eventual comment?
It can be passed just retrieving on related td row, the related text, if there is.
I should study a little more plupload, to understand if instead to achieve via the code above, it implements some method to be shorter.
Anybody know? Anyway it is short also in this way, and it work.

I will commit the mess asap
User avatar
axe70
Registered User
Posts: 188
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: Attachments images rotation extension

Post by axe70 »

Hello cool people, after, the follow at proper time into response callback function seem to resolve all the mess:

Code: Select all

var w3pushObj = new Object();
//Object { attach_id: 224, is_orphan: 1, real_filename: "Armenia.png", attach_comment: "", filesize: 3200 }
w3pushObj['attach_id'] = fnew_id;
w3pushObj['is_orphan']   = forphan;
w3pushObj['real_filename'] = fn;
w3pushObj['attach_comment'] = '';// add comment
w3pushObj['filesize'] = fsize;

var t = phpbb.plupload.data;
//t = t.push(w3pushObj); // won't work
t = t.unshift(w3pushObj); // work, any added need to be 0

console.log(phpbb.plupload.data);
phpbb.plupload.setData(phpbb.plupload.data);
phpbb.plupload.update(phpbb.plupload.data, 'addition', 0);
Do not much time to dedicate at moment, but following any time i can and if nothing more wrong come out: all seem to work as expected now, after an attach has been rotated then inserted with his placeholder. At this time, the passed index for the attach need to be 0 because after rotation the file deleted, and a new id assigned. It is added into /event/overall_footer_body_after.html, with few lines more. Working. asap i will post all the code!
User avatar
Siava
Registered User
Posts: 146
Joined: Wed Jan 26, 2005 10:07 am
Contact:

Re: Attachments images rotation extension

Post by Siava »

Preview attachments and rotate extension... was written a long time ago by Shredder.
User avatar
axe70
Registered User
Posts: 188
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: Attachments images rotation extension

Post by axe70 »

Siava wrote:
Fri Sep 18, 2020 9:39 pm
Preview attachments and rotate extension... was written a long time ago by Shredder.
It rotate images you say, or just preview?
Because if just preview, it is not what this ext aim to do.
And since people like me do not speak russian, nor read cyrillic (and just little Eng)...
It do not appear into adminCP to be installed, so i even can't test.
There is something i have not understand? Can you explain please, what this mod do and how should be installed "la patatina pai"?
In cyrillic?

phpBB-image-attachments-rotation on github
Post Reply

Return to “Extension Writers Discussion”