Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2004-08-08 01:49:58
- 2cats
- Member
- Registered: 2004-07-17
- Posts: 10
this code plugin code isn't working.
<code>
<pre>
function choose($atts){
switch ($_SERVER[“REQUEST_URI”]){
case(strstr($_SERVER[“REQUEST_URI”],”?c=”)):
<txp:article form=“ctoc” listform=“ctoc” />;
break;
case(!strstr($_SERVER[“REQUEST_URI”],”?c=”)):
<txp:article form=“Single” listform=“Single” />;
}
}
</pre>
</code>
What wrong with it?
Last edited by 2cats (2004-08-08 01:50:39)
Offline
#2 2004-08-08 01:52:59
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: this code plugin code isn't working.
The tags. You’re writing PHP code, not a Textpattern page. Try article(array("form"=>"ctoc", "listform"=>"ctoc"));
, etc.
Alex
Offline
Re: this code plugin code isn't working.
I think if you need to do this, you use the function parse(), but I’m not sure offhand.
Offline
Re: this code plugin code isn't working.
> tmacwrig wrote:
> I think if you need to do this, you use the function parse(), but I’m not sure offhand.
The parse function is used where there is a $thing (the second parameter in your plugin’s function. and “something” when you use a tag like: <tag>something</tag>). It allows for nested TXP tags to be processed.
Offline
Re: this code plugin code isn't working.
yeah.. I guess I’m misunderstanding this, but wouldn’t he use parse(“< txp:tags >”); to do this?
Last edited by tmacwrig (2004-08-08 04:41:38)
Offline
#6 2004-08-08 04:42:03
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: this code plugin code isn't working.
Yeah, parse()
would probably work also.
BTW, 2cats – your code is far more complicated than necessary. I think this is what you’re trying to do:
<pre>
<code>
function choose($atts) {
if (gps(“c”))
$atts[“form”] = “ctoc”;
else
$atts[“form”] = “Single”;
article($atts);
}
</code>
</pre>
p.s. spot the deliberate bug.
Last edited by zem (2004-08-08 04:42:39)
Alex
Offline
#7 2004-08-08 15:32:31
- 2cats
- Member
- Registered: 2004-07-17
- Posts: 10
Re: this code plugin code isn't working.
I would like to use the switch(), as I can develop the plugin a little more to allow more options. I also wanted to let the plugin take the <txp statements as atts as this will make the plugin more usable for those who do not know php. A user can see what the <txp statements do as they work building a page.
Anyway, before all this gets done, the basic plugin needs to work, which is still isn’t.
<code>
<pre>
function nca_choose($atts){
switch ($_SERVER[“REQUEST_URI”]){
case(strstr($_SERVER[“REQUEST_URI”],”?c=”)):
article(“form”=>“ctoc”, “listform”=>“ctoc”);
break;
case(!strstr($_SERVER[“REQUEST_URI”],”?c=”)):
article(“form”=>“Single”, “listform”=>“Single”);
}
}
</pre>
</code>
This is prodicing an error on line 113 in publish.php. Any suggestions?
Offline
Re: this code plugin code isn't working.
> 2cats wrote:
> This is prodicing an error on line 113 in publish.php. Any suggestions?
<code>article()</code> takes an array as its only argument. Wrap the parameters in an <code>array()</code> like zem demonstrated originally. _;;
To reiterate sentiment from further down, you don’t need to parse the URL string yourself. There are already ways to check the current category, like the global <code>$c</code>, <code>$pretext[‘c’]</code>, or <code>gps(‘c’)</code>.
Edit: Er, I guess you could have a reason for using the query string directly, but it looks like you’re just doing the work txp:article already does for you. I’ll just assume it is a reference implementation and back away slowly…
Last edited by takshaka (2004-08-08 17:10:30)
Offline
#9 2004-08-08 17:35:53
- 2cats
- Member
- Registered: 2004-07-17
- Posts: 10
Re: this code plugin code isn't working.
well, this just goes to show you that one shouldn’t code php after being up on a hot roof working on it. I don’t know how I missed the missing array part.
any way. the reason why i’m doing this in this manner is so that this plugin will work in conjunction with another plugin. The other plugin is a mod of Dean’s Articles_by_category which creates a category/article menu, much like the original plugin. The category names are links to (what will be) a article list for the category. My plugin mod allows for a limit to the number of articles listed in the menu, plus a ‘more’ link. both the more link and category name will produce the category/article list. An artcile listed in the menu will produce the article when clicked.
The problem was that when you clicked on an article from the menu, the uri would become http://my.com/artcile/x/the-title. When you then clicked on a category name, the sent uri became http://my.com/artcile/x/the-title?c=my-category, which didn’t work.
To fix this, I changed the menu plugin script to produce absolute links. Now, the script needs to know what to do when http://my.com?c=my-category is called or when a http://my.com/artcile/x/the-title is called.
One will produce the sinlge article, the other will produce a list of articles in a single catgory.
This make any sence?
I made the correction to the script, which got rid of the error, but it still doesn’t work. nothing is printing to the screen.
<code>
<pre>
function nca_choose($atts){
switch ($_SERVER[“REQUEST_URI”]){
case(strstr($_SERVER[“REQUEST_URI”],”?c=”)):
article(array(“form”=>“ctoc”, “listform”=>“ctoc”));
break;
case(!strstr($_SERVER[“REQUEST_URI”],”?c=”)):
article(array(“form”=>“Single”, “listform”=>“Single”));
}
}
</pre>
</code>
this is at http://www.loveobjects.com/ (not porn)
Last edited by 2cats (2004-08-08 17:46:51)
Offline
Re: this code plugin code isn't working.
> 2cats wrote:
> I made the correction to the script, which got rid of the error, but it still doesn’t work. nothing is printing to the screen.
Oh, I didn’t notice this before (I was, er, up on a hot roof, metaphorically), but plugins — or any tag handlers — must return the text to be displayed. So you have to explicitly return the return value of <code>article()</code>.
<pre><code>
function nca_choose($atts){
switch ($_SERVER[“REQUEST_URI”]){
case(strstr($_SERVER[“REQUEST_URI”],”?c=”)):
$output = article(array(“form”=>“ctoc”, “listform”=>“ctoc”));
break;
case(!strstr($_SERVER[“REQUEST_URI”],”?c=”)):
$output = article(array(“form”=>“Single”, “listform”=>“Single”));
}
return $output;
}
</code></pre>
Offline
#11 2004-08-09 02:36:18
- 2cats
- Member
- Registered: 2004-07-17
- Posts: 10
Re: this code plugin code isn't working.
that doesn’t work either.
Offline
Pages: 1