Serendipity + PEAR::HTML_TreeMenu = Goodness
I did a little playing today and implemented a Serendipity plugin for a PEAR::HTML_TreeMenu category listing. I am pasting the code here but it is nothing special. You can see an example on the right side of my blog.
THIS ONLY WORKS WITH PHP5! since PHP4 is dead to me
(PHP4 compatibility should just mean adding some ‘&’ to pass by reference, but I don’t have an install to test it with)
To install just create a folder in your serendipity plugins forder called "serendipity_plugin_categorytreemenu", create a file of the same name, paste the code below into that file. It assumes that you have PEAR::HTML_TreeMenu installed and that it is in your include path.
There was one cool discovery that I had when writing this. OOP and references eliminate the need for recursion when nesting. I was able to do all of the nesting with just two passes through the categories array. One the first pass I created an object (HTML_TreeNode) for that category. On the second pass I added all categories with a parentid as a child to their parent. Since all of the objects are references, the second pass can nest them indefinately deep. This would be a great demonstration with a nested message board. However, it is my taking advantage of pass-by-reference (default) in PHP5 that makes this probably not work in PHP4. I could make it work in PHP4, but I don’t care to.
Thanks to the HTML_TreeMenu guys. Nice package.
[UPDATE]
I created a static page for downloads and have put a tarball there for download. You can get up-to-date code there.
[/UPDATE]
[UPDATE]
I have committed this to CVS at SourceForge and it will be maintained there. I have already started to add a few more features (configurable images directory, configurable javascript file location, expand all categories by default, etc).
[/UPDATE]





















Really like your category tree. Will have a look at patching it to PHP4.
Let me know how it goes. I have committed this to the additional_plugins module in serendipity’s CVS at sourceforge.
I would be happy to put in tested patches (or you can if you are a plugin developer).
Thanks for the feedback.
-Jackson
Some cool plugins have been added to Serendipity…
Jackson Miller has added two new plugins…
He added a DHTML Category Menu plugin and a word of the day (serendipity_plugin_wotd) plugin…
Both can be download from Mr. Miller’s site, and the D
The plugin works as is for PHP4, no changes are required. The thing that stumped me was the javascript. It wasn’t until I read your comment on the trackback link at Theledge.net that I realised the javascript was from the pear package itself. (It isn’t obvious if you type pear install HTML_TreeMenu to install it). Maybe a comment at the beginning of the file? Like copy the /path/to/phpfiles/doc/data/HTML_TreeMenu directory to /some/where/on/web/space.
Also, your plugin gives the following error when there are no categories (shouldn’t happen unless the person has a fresh install):
Warning: Invalid argument supplied for foreach() in /var/www/serendipity/plugins/serendipity_plugin_categorytreemenu/serendipity_plugin_categorytreemenu.php on line 48, (and 53, 65)
hello
my isp uses php 4.3.10
serndipity was installed by my isp
im not a php expert
i allready have installed plus for seredipity without prob
i copied your file and his directory to plugins dir
i copied the pearl lib in a subdirectory of your plug
i can install plugin in serendipity by the “plugin management” page and i can acces the options of your plug.
(ive seen the line in code where your refer to treemenu.php file)
with a wrong path of the treemenu.php file, the browser answers a wrong path.
with a good path, the browser returnes nothing (just like i didnt install plugin)
do i need to change some code ? may i change the apache settings ? (i think i cant)
i dont know what is pass by reference
Can someone write a php 4 version ?
good luck and long life
i forgot to give you my mail if you want to tell me how to make the tree menu works under my isp php 4.3.10