Page 1 of 2
New event plugin: Table of Contents for Articles
Posted: Sat Feb 07, 2009 11:20 pm
by Slideshow Bob
Hey there,
first post and I'd like to contribute a new event plugin I desperately needed for my blog. I couldn't find any solution on the net, so I created it on my own.
My plugin automagically creates a table of contents for blog entries based on header tags (h3 to h6). You can insert the table of contents anywhere in your article by typing the special tag [TOCx] where x is a number from 3 to 6 - indicating the desired header order number to index.
The event plugin is designed to play along with serendipity_event_entrysplit and is therefore able to reference the proper sub-page. However, this feature currently only works if the page break tag is manually put into the article text.
I hacked this thing together over night and it seems to be stable so far (at least in my blog).
The table of contents makes use of the CSS-class name "articletoc" for all generated HTML tags (div, ul, li), so changing its appearance to make it fit nicely into a template shouldn't be too difficult.
I hope you find it useful
Thomas
Re: New event plugin: Table of Contents for Articles
Posted: Mon Feb 09, 2009 12:14 pm
by garvinhicking
Hi!
Great, many thanks for sharing your code!
Looking at the code, I suspect it should work just fine, however some ideas:
1. Since it already depends a lot on serendipity_event_Entrysplit, would you like to combine your code into the existing plugin and then I could submit your patch into the official plugin?
2. I see that it seems to work on the extended body, wouldn't it be nice to be able to also put the TOC immediately into the normal entry body?
3. You use preg_replace for a [TOCx] replacement; you could speed the loop up a bit, if you simply use str_replace?
Best regards,
Garvin
Re: New event plugin: Table of Contents for Articles
Posted: Mon Feb 09, 2009 7:33 pm
by Slideshow Bob
Hi Garvin,
you are right about merging it with "entrysplit". I also have to admit that I felt a "little bit dirty" letting my new plugin redundantly do entrysplit's work, so merging both makes a lot of sense.
I'll give it a go in a few days, also considering your other suggestions, and I will post an updated entrysplit-plugin into this thread.
See you!
Thomas
Re: New event plugin: Table of Contents for Articles
Posted: Tue Feb 10, 2009 10:17 am
by garvinhicking
Hi!
That's great news! Keep me posted.
Regards,
Garvin
Re: New event plugin: Table of Contents for Articles
Posted: Fri Feb 13, 2009 1:01 pm
by Slideshow Bob
Hi Garvin,
as promised, I've modified the entrysplit plugin considering your additional suggestions.
The TOC can now also be applied to the entry's body. However, indexing header tags is currently only applied to the extended text, since this is also the working scope of the original entrysplit plugin. I hope that this restriction is okay with you
Thomas
EDIT: Woops... I noticed a bug when two entry bodies with a TOC are displayed on the entries list page. I'm going to fix it now and upload the updated version
EDIT 2: Fixed and uploaded - see attachment
Re: New event plugin: Table of Contents for Articles
Posted: Fri Feb 13, 2009 1:51 pm
by garvinhicking
Hi!
Phew. That's more changes I anticpated. But it seems to work fine in my tests, so I've committed it and will see what the feedback will be
Regards,
Garvin
Re: New event plugin: Table of Contents for Articles
Posted: Tue Feb 24, 2009 8:25 am
by bugrep
hello
im hijacking this thread, i dont know if this problem is related to the latest changes (toc).
i installed s9y today and before adding an entry i also installed a lot of plugins (those descriptions in spartacus could be more verbose or contain wiki links btw!).
when i view my empty blog is see this warnings:
Warning: Cannot use a scalar value as an array in /web/plugins/serendipity_event_entrysplit/serendipity_event_entrysplit.php on line 93
Warning: Cannot use a scalar value as an array in /web/plugins/serendipity_event_entrysplit/serendipity_event_entrysplit.php on line 94
i did not look at the code (php disgusts me actually ;) but i guess its an easy fix.
google finds two others blogs that contain this warnings... but they are only in googles cache and not on the current (no more empty) blogs
cheers!
edit1:
i noticed the same problem in the pdf plugin.
its not really a problem, but i think it should be corrected anyway :)
Warning: Cannot use a scalar value as an array in /web/plugins/serendipity_event_entrylastmodified/serendipity_event_entrylastmodified.php on line 100
Warning: Cannot use a scalar value as an array in /web/plugins/serendipity_event_entrylastmodified/serendipity_event_entrylastmodified.php on line 104
Re: New event plugin: Table of Contents for Articles
Posted: Tue Feb 24, 2009 9:12 am
by garvinhicking
Hi!
could it be that you don't have any blog entry yet? At which place do you see the error, on the blog overview, or on a detailed blog entry page?
I'm sorry for the short descriptions...we really do need help to describe the plugins more in detail on the wiki.
Best regards,
Garvin
Re: New event plugin: Table of Contents for Articles
Posted: Tue Feb 24, 2009 9:32 am
by bugrep
fast reply!
yes, there are were entries (should have made that clearer in the prev post).
after adding an entry those warnings are gone.
so its not really a big issue....
(at the moment im wrestling with the blogpdf plugin... doesnt output the corret content-type. neighter HTML2PDF nor fpdf. should i open another thread for that, if i cant solve it myself or abuse this thread further?)
Re: New event plugin: Table of Contents for Articles
Posted: Tue Feb 24, 2009 9:34 am
by garvinhicking
Hi!
(at the moment im wrestling with the blogpdf plugin... doesnt output the corret content-type. neighter HTML2PDF nor fpdf. should i open another thread for that, if i cant solve it myself or abuse this thread further?)
You could tell us the URL to your blog, then I could check a few header-related things?
Regards,
Garvin
Re: New event plugin: Table of Contents for Articles
Posted: Tue Feb 24, 2009 9:46 am
by bugrep
sure
http://blog.0wnz.at
the pdf generation seems to work with both options. but the header is wrong (tested in firefox and opera and confirmed by using fiddler).
im using a chrooted lighttpd with a very basic environment, so maybe php/the plugin is missing something, but doesnt tell (couldnt use spartacus before, because libnss_dns.so was not available).
Re: New event plugin: Table of Contents for Articles
Posted: Tue Feb 24, 2009 10:01 am
by garvinhicking
Hi!
Hm, sadly I have no real-life experience with lightttpd. Is PHP running as CGI, FastCGI or what? When you write a test.php script with something like:
Code: Select all
<?php
header('Content-Type: application/pdf');
echo 'blabla'
Does that produce the right header? Because I believe it doesn't generally work on your isntall then?
Regards,
Garvin
Re: New event plugin: Table of Contents for Articles
Posted: Tue Feb 24, 2009 10:16 am
by bugrep
php uses fast-cgi there.
i tried the proposed test script on the command line (inside the chroot) and served via lighty and both ways work ok.
"php5-cgi pdf.php
X-Powered-By: PHP/5.2.6-2+b1
Content-Type: application/pdf
blabla"
Re: New event plugin: Table of Contents for Articles
Posted: Tue Feb 24, 2009 10:33 am
by garvinhicking
Hi!
I've checked the fpdf.php library. It only sents headers when $HTTP_SERVER_VARS['SERVER_NAME'] is set. Usually, for Apache this is a mandatory variable, so I can only guess it's not getting set in lighty/CGI?
Regards,
Garvin
Re: New event plugin: Table of Contents for Articles
Posted: Tue Feb 24, 2009 11:42 am
by bugrep
thanks that pushed me in the right direction.
the problem was the php config, not lighttpd:
; Whether or not to register the old-style input arrays, HTTP_GET_VARS
; and friends. If you're not using them, it's recommended to turn them off,
; for performance reasons.
register_long_arrays = On
this was set to Off.
thanks for this excellent support!