Board index ‹ Plugins ‹ How do I change comments before saving them?
23 posts
• Page 2 of 2 • 1, 2
Re: How do I change comments before saving them?humm...
Re: How do I change comments before saving them?Or maybe one last try in English
Please forget everything I posted in this thread before. I have this function in my plugin:
The logfile of the plugin says, that addData was changed the way I would expect it: The addData['comment'] is changed. But the comment will be saved the same way it was before I changed it using this plugin. Why is it like that, what went wrong?
Re: How do I change comments before saving them?Oh.. Now I have found the reason of my problem by myself.. It's simple and it is like documented: addData can not be changed in the plugins event_hook, no matter how I define the interface of my event_hook.
The reason is: in plugin_api.inc.php the called function is defined like that:
So addData will be "restored" after all event_hooks are called, as addData is not handed by reference but copied. Hmm.. Bad.. Why is it like that, that we are not allowed to change a comment before saving it? So I have to hook into frontend_saveComment_finish to be able to change the comment and resave it. (and I have to make sure, that that does not produce an endless recursion, as saving the comment in frontend_saveComment_finish will emit another frontend_saveComment_finish event)
Re: How do I change comments before saving them?
Yes, that is what we were trying to say all the time About changing addData data - I don't get why you want to change usercontent... The plugin api is able to re-act on user actions via eventData (set to moderate, erase, etc.) which should be enough by POST. Regards,
Ian
Re: How do I change comments before saving them?
Yes, I knew from the beginning, that this is the case. It is even documented. My question was all the time: why is that the case (or being more precise: what code made it readonly).
Well.. There are many reasons why you want to do it. Remove URLs, add BRs, what ever. In my case I wanted to fetch content for pingbacks. But I managed to do it in another way.
Re: How do I change comments before saving them?Well then we did not quite understand each other...
That would be interesting to see here, after so many posts! Regards,
Ian
Re: How do I change comments before saving them?
I'm not offended or something like that, but didn't i answer exactly that question in my very first and with more certainty in my second answer? But I'm happy you found a way to solve the problem and would also like to encourage you to post your solution, in case someone finds this thread searching for the same question.
Re: How do I change comments before saving them?Reading back: Yes, onli, you exactly answered my question, but it seems, I didn't understand it when first reading.
About my problem: The problem described here can't be solved, as it is a feature not a problem (although I still think it is a problematic feature in this case). Well, to tell the complete truth: It can be done, but it is tricky. You have to hook the commentSaved event (not the saveComment), save the changed comment on your own again and prevent a recursion by adding and checking a "source" attribute to the addData i.e. But I used a completely other way to fetch pingback content now: I patch the Serendipity config. I added a functionality to the core doing this some years ago, but it is hidden to the "normal user" (you have to patch the local config file manually).
23 posts
• Page 2 of 2 • 1, 2
Who is onlineUsers browsing this forum: No registered users and 2 guests |