Attachments images rotation extension

Discussion forum for Extension Writers regarding Extension Development.
User avatar
axe70
Registered User
Posts: 280
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: 280
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: 280
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: 150
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: 280
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
User avatar
axe70
Registered User
Posts: 280
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: Attachments images rotation extension

Post by axe70 »

---
Version 1.0.1 dev fix following issues:
---
Fix files upload directory, to match the phpBB configuration value
Add missed language phrase

Fix images cache issue.

Process: attachments rotation -> new file creation -> addition/removal file records into db. On response, JS code (plupload and custom js) execute to push new values and re-index attachments data into the post

Minor fixes and code cleanup.

phpBB-image-attachments-rotation 1.0.1 dev on github

Relevant changed files about cache solution, are overall_footer_body_after.html and fileRotate.php
... look into file
/ext/w3all/imageattachrotation/styles/prosilver/template/event/overall_footer_body_after.html
to see how has been used the code of plupload lib mixed with custom js code.

Notes:
i'm (quite) sure it can be improved easily. Explored several ways to achieve the result, at moment adopted the one looking faster to me (but maybe it will be discovered soon that instead to go to delete the file in fileRotate.php when the img copy created, would be may better to delete it via js callback, on response, using related phpbb.plupload method? Maybe. I will may return over this aspect doing also in this way, so substantially like when a file added, so, adding the attach row into attachments list like a new file, re-indexing and going to remove the old in this case. The problem would be the substitution of any existent placeholder with the new one in this case. It's possible, but if possible, then it will be even more hard i think (at moment, for what i know). Started it days ago, rebuilt today, so actually switched to this version.
It go to update relevant needed data, do not go to remove/re-add the attachment html row on DOM.
You'll find that all work as expected.

Any help, criticism and improvement would be welcome.

Missing version 1.0.0 dev? It is available here:
Version: 1.0.0 dev
Last edited by axe70 on Tue Sep 22, 2020 8:23 am, edited 2 times in total.
User avatar
ViolaF
Registered User
Posts: 1546
Joined: Tue Aug 14, 2012 11:52 pm

Re: Attachments images rotation extension

Post by ViolaF »

i used from the first day and all works like 100% now.
big thanx to all your effort :D
User avatar
axe70
Registered User
Posts: 280
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: Attachments images rotation extension

Post by axe70 »

It work, but was not perfect.
Particularly, when you reply to a post, it do not let rotate attachments.
The reason of this was just that the request for reply, was not considered.
To switch to, this instruction on top of the
overall_footer_body_after.html
if( w3ReqMode == 'edit' || w3ReqMode == 'post' ){
need to be instead:
if( w3ReqMode == 'edit' || w3ReqMode == 'post' || w3ReqMode == 'reply' ){

But it was not the unique problem: i think i had over complicated things so it's ready the new version that will be committed asap within today:
the code was looping too much to accomplish on adding/removing elements on attach panel.
There was redundant instructions and js observer not well called: a (really) not useful for loop has been removed.
It has been rebuilt to be clear, faster and (more) simple.

It will replace the Rotate text with fontawesome icon like this:
Edit post.png
A reply here asap the code committed on github
User avatar
axe70
Registered User
Posts: 280
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: Attachments images rotation extension

Post by axe70 »

With all the love for this community, which is the first i subscribed into, long, long time ago ;)

phpBB attachments images rotation 1.0.2-dev
download phpBB attachments images rotation on Github

The Rotate link has been replaced by a fontawesome icon.
It now work on edit, post and reply mode.
Code on overall_footer_body_after.html file has been updated to fix several issues and to be shorter and faster and more clean.


Result will be this:
Edit post.png

Any bug? Please report.

P.s: Any help on this? It make me crazy (see overall_footer_body_after.html code)

Code: Select all

   	var i = document.createElement("i");
   	i.className = "icon fas fa-undo fa-rotate-270";
   	i.style = "font-size:70%;margin:0px 0px 0px 5px;";
   	
   	var txt = document.createTextNode("&nbsp;");
   	var ah = document.createElement("a");
   	ah.className = "w3rotate";
   	ah.href = "javascript:void(0);";
   	ah.appendChild(i);
   	// Test this adding a file ... 
   	// before: un-comment the 'alert' and '//this.appendChild(ah);' , so comment 'this.after(p);' to test
    // alert('if i stop code execution here, the element display while stopped: let it be understood where the problem is?');
   	
   	// Both following ways to add the element fails, wont's work: the appended element, suddenly disappear/removed from DOM, after a while it has been added, without a clear reason to me
   	// Do You know why?
   	//this.appendChild(ah); 
    //$(this).append( '<a class="w3rotate" href="javascript:void(0);"><i style="font-size:60%" class="icon fas fa-undo fa-rotate-270"></i></a>'); 
   	this.after(ah); // work
   	// a polyfill for some IE version needed here? // this.after(p);
Last edited by axe70 on Wed Sep 23, 2020 6:10 pm, edited 1 time in total.
User avatar
HaioPaio
Registered User
Posts: 126
Joined: Mon Jan 08, 2018 7:39 pm

Re: Attachments images rotation extension

Post by HaioPaio »

I do not have the skills to support you. So I support you with my best wishes and crossing fingers. I appreciate what you are doing.
rxu
Extensions Development Team
Posts: 3456
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Attachments images rotation extension

Post by rxu »

There's a forum dedicated for such kind of topics: Extensions in Development -> "A place for Extension Authors to post and receive feedback on Extensions still in development.".
User avatar
axe70
Registered User
Posts: 280
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: Attachments images rotation extension

Post by axe70 »

rxu wrote:
Wed Sep 23, 2020 3:27 pm
There's a forum dedicated for such kind of topics: Extensions in Development -> "A place for Extension Authors to post and receive feedback on Extensions still in development.".
Well, you are right, I maybe extended the meaning of the Extension Writers Discussion forum. But this is an extension in effect.
So what we should do now, open another thread into the forum you indicate and you'll close or move this?

I hoped for an answer to the question i did, so i will surely now post the question into the forum you say, thank you.

1.0.2-dev version here until it has not been passed for validation:

phpBB attachments images rotation 1.0.2-dev
download phpBB attachments images rotation on Github
Last edited by axe70 on Wed Sep 23, 2020 6:09 pm, edited 2 times in total.
User avatar
HaioPaio
Registered User
Posts: 126
Joined: Mon Jan 08, 2018 7:39 pm

Re: Attachments images rotation extension

Post by HaioPaio »

composer.json still shows 1.0.2-dev.
Is it the right version at github?
User avatar
axe70
Registered User
Posts: 280
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Contact:

Re: Attachments images rotation extension

Post by axe70 »

HaioPaio wrote:
Wed Sep 23, 2020 5:49 pm
composer.json still shows 1.0.2-dev.
Is it the right version at github?
Yes! Sorry, Wrong version reported here and on github readme
Fixing/editing. It is 1.0.2, it is right!
User avatar
pierredu
Registered User
Posts: 1123
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: Attachments images rotation extension

Post by pierredu »

You can ask a moderator to split the topic and put the lasts posts in the 'Extensions in dev.' forum.
Post Reply

Return to “Extension Writers Discussion”