Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Using TXP Tags within Stylesheets
I am still looking at hacking the css.php file directly, as I think that having the css content parsed by the textpattern tag handler should be blindingly simple (the current, simple way of handling css is great and all, but I think, like ma_smith, that the opportunities available are mind-blowing).
Appealing to the gurus / powers that be, which function (is it textpattern()
?) within which file (index.php or publish.php?) would I be wanting to duplicate, rename and adapt to interrogate the txp_css
table?
Offline
Re: Using TXP Tags within Stylesheets
You don’t have to hack any files. Create a plugin that carries this code:
if (txpinterface=='css') ob_start('parse');
[edit:fixed typo]
Offline
Re: Using TXP Tags within Stylesheets
Sencer wrote:
You don’t have to hack any files. Create a plugin that carries this code:
if (txpinterface='css') ob_start('parse');
Tried that… Didn’t work.
Used the <a href=“http://www.textpattern.de/hacks/11/jg-plug-in-creater-v10”>j|g Plug-In Creater v1.0</a> to make a plugin containing just that line and I get an error:
<code>Parse error: parse error, unexpected ‘=’ in /home/lucanos/public_html/portal/textpattern/lib/txplib_misc.php(459) : eval()’d code on line 1
The above errors were caused by the plugin:TXP Tags in CSS</code>
Offline
Re: Using TXP Tags within Stylesheets
Further…
I added a second “=” sign into the if statement.
That one didn’t generate a PHP Error on the main screen, as the one previous did.
Instead the CSS.php?n=XXX code contained an error:
“<b>Fatal error</b>: ob_start(): Cannot use output buffering in output buffering display handlers in <b>/home/lucanos/public_html/portal/textpattern/publish/taghandlers.php</b> on line <b>1723</b>”
Offline
Re: Using TXP Tags within Stylesheets
Well, ahem, it should be ==
, not =
. Little typo there.
Offline
Re: Using TXP Tags within Stylesheets
The limitation of that approach is, that you cannot use tags which use output-buffering themselves, there is very, very few tags that do. txp:php
is one of them, though. (And you can work around that by replacing direct php-code with proper plugins).
Offline
Re: Using TXP Tags within Stylesheets
Funnily enough, the tag I was trying to use was txp:php
, just for the fact that it was an easy test – echo "/* It Works! */";
…
I’ll have to retest with standard TXP tags.
It would be good though, if, eventually, it would be possible to include the txp:php
tags in the CSS code – it would allow funky things like having the shades of a color automatically calculated, etc.
Offline
Re: Using TXP Tags within Stylesheets
Lucanos,
Where are you at with this? Any movement toward including the tags inside the internal css?
- I am Squared Eye and I
am launchinghave launched Pattern Tap
Offline
Re: Using TXP Tags within Stylesheets
ma_smith,
At present I am looking through the coding, and reverse-engineering the way that the standard content is processed. As far as I can tell (at the moment), and correct me if I’m wrong, the function testpattern()
actually performs the SQL query and then processes the txp tags therein before rendering the page’s source for display…
If that is the case, then what I am thinking of doing is creating a duplicate of that function (with a different name, of course) and then including that within the css.php
page.
I’ll be working towards that this week, as I now have the luxury of 2 weeks project work on a TXP-based intranet site at work.
I’ll be sure to update you if and when I make any progress.
If you see my headed off-track though, let me know as I am still very new to TXP.
Thanks
Offline
Re: Using TXP Tags within Stylesheets
Lucanos,
Unfortunately, I’m not well versed in php. That might be the kind of question you could ask on the dev mailing list, although they often request many “how do I’s” here in this forum. I am eager to know what you come up with, feel free to ask for beta testing and I’ll give you a hand there.
Cheers,
Matthew
- I am Squared Eye and I
am launchinghave launched Pattern Tap
Offline
Re: Using TXP Tags within Stylesheets
I Got One!
I have changed the css.php
file, using the functions which handle the normal page content, so that TXP tags (and PHP scripts, if you have chosen to allow them) can now be used within your stylesheets for further flexibility.
In conjunction with the Plugin: ako_ifBrowser this should also allow for browser-dependant CSS hacks to be easily applied to TextPattern sites, rather than relying on less-than-dependable tricks…
How to do it
Simply perform the following replacements inside the “@/textpattern/css.php@” file.
( – = Remove this line. + = Add this line. )
<code>if (@ini_get(‘register_globals’))
foreach ( $_REQUEST as $name => $value )
unset($$name);
- header(‘Content-type: text/css’);
ob_start(NULL, 2048);
include ‘./config.php’;
ob_end_clean();
$nolog = 1;
define(“txpinterface”, “css”);
include $txpcfg[‘txpath’].’/publish.php’;
- $s = gps(‘s’);
- $n = gps(‘n’);
- output_css($s,$n);
+ if (gps(‘n’)) {
+ $cssname = $n;
+ } elseif (gps(‘s’)) {
+ $cssname = safe_field(‘css’,‘txp_section’,“name=’”.doSlash($s).”’”);
+ }
+ $css = safe_field(‘css’,‘txp_css’,“name=’”.doSlash($cssname).”’”);
+ if ($css) {
+ $css = base64_decode($css);
+ $css = parse($css);
+ $css = parse($css); // the function so nice, he ran it twice
+ $css = ($prefs[‘allow_page_php_scripting’]) ? evalString($css) : $css;
+ } else {
+ $css = “/* No CSS Content retrieved */”;
+ }
+ header(‘Content-type: text/css’);
+ echo $css</code>
I am pretty sure that some of the editing I did stripped the debugging information which I have sometimes seen displayed at the bottom of the source code for TXP pages, but, at a basic level at least, this works.
If someone wants to tidy it up, and replace any essential items I have (naively) removed, please feel free.
If editing the PHP file is a bit of a stretch for you, then you can download a copy, with the above changes already made, at www.lucanos.com/css_php.zip
Offline
Re: Using TXP Tags within Stylesheets
OK…. I was a little premature…
The above works like a charm when you use the ...css.php?s=XXX
method to call it. Unfortunately, the ...css.php?n=XXX
method… She no work so good…
Figuring it out now…
Offline