Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2004-09-08 23:20:44

jonhicks
Member
From: Oxfordshire UK
Registered: 2004-03-22
Posts: 256
Website

Could my comments.php hacks be a plug-in?

I’ve done a lot of hacking to my publish/comments.php file to do things like allow commentors to post without previewing, prevent email notifications of my own comments, etc. Is that the kind of thing that could saved as a plug-in to avoid having to redo it all at upgrade time?


Cheers,
Jon VC#9

Offline

#2 2004-09-09 05:53:54

greenrift
Archived Plugin Author
Registered: 2004-03-08
Posts: 186
Website

Re: Could my comments.php hacks be a plug-in?

I can’t test this out, but it might work.

If you copied all of the stuff from your comments.php file into a plugin, and then just made the current comments.php file be empty (don’t delete it from the filesystem, just make it empty. otherwise PHP might throw up errors about it missing). Make sure the plugin is activated, and it should be good to go.

This should work (all the plugin code is loaded before anything else runs) but you’ll still want to double check when you upgrade for any big changes to the way TXP handles comments (I’d think that database changes would cause the biggest problem).

This solution isn’t much different than just replacing the upgraded comments.php file with your hacked version. Although if all of your hacks were just quick function calls (to functions you’ve written), you could throw the functions into a plugin and then just add the functions calls to comments.php when you upgrade.

Offline

#3 2004-09-09 19:56:09

jonhicks
Member
From: Oxfordshire UK
Registered: 2004-03-22
Posts: 256
Website

Re: Could my comments.php hacks be a plug-in?

thanks Greenrift. I tried both the templates offered here in the plugin forum, but the first (Deans) wouldn’t compile. It had a a problem with the very last ‘; after the plugin function (does that need to be escaped too). The version created by Zem (http://forum.textpattern.com/viewtopic.php?id=3558) complied, but then when viewed in the plugin panel, the code had ‘spilled over’ into the help text below. I sort of know enough php to be dangerous, so this maybe a skill level too far.


Cheers,
Jon VC#9

Offline

#4 2004-09-14 17:31:44

igner
Plugin Author
Registered: 2004-06-03
Posts: 337

Re: Could my comments.php hacks be a plug-in?

My best guess is that in order to properly implement this as a plug-in would require creating a custom article function, which in turn calls your customized comment functions.

If you want, I’d be glad to take a stab at it…I’d just need copies of your hacks.

In the meantime, to protect against inadvertent overwriting of your custom comments – just save a copy of your hacked comment.php as something different (jh_comment.php), and if so desired, remove it from the txp hierarchy (I’d probably put it outside the document root). Then, replace the contents of comment.php with require(‘/path/to/jh_comment.php’);

This effectively removes the risk of overwriting your hacks with the next upgrade. Of course, there’s still the issue of having to compare the non-hacked pieces of your comment.php to the new version, when released, but you should be able to use the diff utilility included with the OS X developer tools.

Hope that helps.


And then my dog ate my badger, and the love was lost.

Offline

#5 2004-09-14 18:09:50

jonhicks
Member
From: Oxfordshire UK
Registered: 2004-03-22
Posts: 256
Website

Re: Could my comments.php hacks be a plug-in?

igner, I like the idea of saving it into a different file. Just trying to find the Diff utility you mentioned – is that in xCode itself, or one of the smaller apps bundled with it?


Cheers,
Jon VC#9

Offline

#6 2004-09-14 18:28:59

igner
Plugin Author
Registered: 2004-06-03
Posts: 337

Re: Could my comments.php hacks be a plug-in?

You would ask that when I’m not in front of my Mac :)

diff is the *NIX command line tool, the GUI is called FileMerge. I think it’s still included as a separate app with 10.3, but I’m not positive. I can confirm tonight. Otherwise it may be rolled into Xcode.

Jer


And then my dog ate my badger, and the love was lost.

Offline

#7 2004-09-14 18:35:28

jonhicks
Member
From: Oxfordshire UK
Registered: 2004-03-22
Posts: 256
Website

Re: Could my comments.php hacks be a plug-in?

No worries, thats enough of a lead! Thanks!


Cheers,
Jon VC#9

Offline

#8 2004-09-14 18:58:17

igner
Plugin Author
Registered: 2004-06-03
Posts: 337

Re: Could my comments.php hacks be a plug-in?

Glad to help.

I’m still up for a having a go at plug-in implementation, if you’re willing to share your hacks :)

I’m also thinking Sean might look at implementing diff support in skedit in a future release…I’ll have to shoot him an email.


And then my dog ate my badger, and the love was lost.

Offline

#9 2004-09-14 20:03:00

jonhicks
Member
From: Oxfordshire UK
Registered: 2004-03-22
Posts: 256
Website

Re: Could my comments.php hacks be a plug-in?

Well skEdit support would just make my day!

I’ve documented all the changes I made here:

http://www.hicksdesign.co.uk/journal/527/textpattern-notes-part-2

http://www.hicksdesign.co.uk/journal/528/textpattern-notes-part-3

The large part of the changes were from Justin Low, who worked out how to remove the need to preview comments first. The whole comments.php file can be downloaded here


Cheers,
Jon VC#9

Offline

#10 2004-09-14 20:30:28

igner
Plugin Author
Registered: 2004-06-03
Posts: 337

Re: Could my comments.php hacks be a plug-in?

Right – I’d forgotten you went into such juicy detail on your site.

I’ll see if I can’t get this knocked out this evening…


And then my dog ate my badger, and the love was lost.

Offline

#11 2004-09-14 21:42:56

jonhicks
Member
From: Oxfordshire UK
Registered: 2004-03-22
Posts: 256
Website

Re: Could my comments.php hacks be a plug-in?

The changes in the actual comments.php file are more specific to me, but the way i documented it on my site was more general, which may be more useful to others as a plugin.


Cheers,
Jon VC#9

Offline

#12 2004-09-15 14:31:01

igner
Plugin Author
Registered: 2004-06-03
Posts: 337

Re: Could my comments.php hacks be a plug-in?

So close I could taste it, then ran into something of a deal-breaker.

The actual saveComment call comes from publish.php, not comment.php. Looking at the flow, I don’t think it’s possible to change that, without hacking publish.php…

A couple notes on things to streamline your hacks a bit, though:

1) rather than hack the checkNonce() function, just remove the check from the saveComment function – comment out lines 307 & 331
<code>if (checkNonce($nonce)) {</code>
and
<code>} //end checkNonce</code>
That eliminates the check entirely. As it stands currently, were someone to partially implement the hack (e.g. allow direct submission but keep the preview button…) if $nonce is set, it’s still evaluated and the $nonce table is checked. No need to do that processing since we’re always returning true.

2) Change the point where you output the < div > to read
<code>$out .= n.t.’<div id=“c’.$discussid.’” class=”’.$class.’”><span class=“cno”>’.$cno++.’</span> // ‘.$temp.’</div>’;</code> and eliminate the line
<code>$cno = $cno + 1;</code>
This’ll increment $cno immediately after reading in the value. (Admittedly, this is an insignificant point, but I figure why not share what little I can contribute… :)

3) Since we’re numbering the comments, we can also use that number to handle the class assignment, so I’d add a function (lifted from the php.net documentation):
<code>function oddeven($x){ if($x & 1) return “odd”; else return “even”;
}</code>

and rework the output line from above to read:

<code>$out .= n.t.’<div id=“c’.$discussid.’” class=”’.oddeven($cno).’”><span class=“cno”>’.$cno++.’</span> // ‘.$temp.’</div>’;</code>

In addition, I figured out why you were getting funky results with Zem’s plugin template – the <code></textarea></code> in the commentForm function is prematurely closing the textarea on the plugins page. I “fixed” it by changing the php to break up the tag:
<code>’<’.’/textarea.’</code>
I suspect that your plugin was functional, it just displayed funky when viewed in the admin section. Such is the joy of displaying code and keeping it editable.

Hopefully these are useful comments (and in no way are they intended to be too nitpicky…just trying to do my part and give back to the community. I’m not giving up on the plugin yet, but it’s not looking good at this point.

J


And then my dog ate my badger, and the love was lost.

Offline

Board footer

Powered by FluxBB