Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-09-03 14:12:06

phpnotebook
New Member
Registered: 2012-09-03
Posts: 4

adding and editing posts with php syntax highlighting

hi folks

I’ve set up a new blog regarding PHP, and I’ve set up the blog so that when I add or edit posts the format of the content I type is like so:

This is a sentance.
<?php echo “this is some PHP”; ?>

I’ve hacked around with textpattern so that the correct p elements wrap the paragraphs and I’ve also made it so that any PHP blocks have their syntax highlighted automatically (using the highlight_string() function) like so.

However, I’m doing this on runtime which I think is going to have a massive performance impact when the website gets bigger. The reason for doing so is because when I go back and edit content I still want it to display like so:
This is a sentance.
<?php echo “this is some PHP”; ?>

The idea is that it is quick and easy to add and edit posts. The whole thing works great, but as I say I think the hacking around isn’t very sustainable as the other problem is that the full page is parsed for PHP blocks which is very slow.

I’ve not had a chance yet to rip textpattern apart, so I’m wondering if there are any suggestions on a better approach to doing this while maintaining a simple method of adding and editing posts along with keeping the highlight_string() syntax highlighting.

Cheers.

…Edit…
Another thing I should add is that I’m wanting to avoid textile, not because I don’t like it but because I really do want it as simple as typing sentences of text, hitting the return key, and then copying and pasting PHP code.

…Edit…
I’ve also thought about a caching system whereby pages are cached and the cache is refreshed once an hour, this is something I might end up going for however when the time comes to refresh the cache I’m slightly worried that the website will go really slow.

Last edited by phpnotebook (2012-09-03 17:21:37)

Offline

#2 2012-09-03 14:55:27

etc
Developer
Registered: 2010-11-11
Posts: 5,397
Website GitHub

Re: adding and editing posts with php syntax highlighting

You could wrap your posts in aks_cache, it gets refreshed on demand only when the site is updated.

Offline

#3 2012-09-03 14:56:05

phpnotebook
New Member
Registered: 2012-09-03
Posts: 4

Re: adding and editing posts with php syntax highlighting

I think I’ve came up with a solution (but it isn’t ideal as it could be a lot of work), I haven’t developed it yet but it will involve the use of an extra table field to store the parsed post content, and then when outputting the posts I’m going to modify each script so that the content from the extra field is output opposed to the original content. That way I can still add and edit posts how I want to with the added benefit of having the parsed content stored in the database which avoids having to mess about with the final output before the response is flushed to the client.

Offline

#4 2012-09-03 14:56:54

phpnotebook
New Member
Registered: 2012-09-03
Posts: 4

Re: adding and editing posts with php syntax highlighting

etc wrote:

You could wrap your posts in aks_cache, it gets refreshed on demand only when the site is updated.

Cool, I’ll look into that as I’m really after a simple solution and that sounds like it might work.

Offline

Board footer

Powered by FluxBB