Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2005-12-24 01:34:31
- Ji31
- Member
- Registered: 2005-08-24
- Posts: 103
I make new, what is wrong?
I want to make new plugin, which replaace text smiles for pictures.
..
..
31 function wsp_smile_replace($atts) {
32 extract($atts);
33 $replace = $thisarticle['BODY'];
34 $replace = str_replace(":-)","<img src=\"/images/site/3.gif\" />", $replace);
35 echo $replace;
36 }
..
..
If I put this intoo the Texpattern Plugin Template, that writes “Parse error: parse error, expecting `T_STRING’ or `T_VARIABLE’ or `T_NUM_STRING’ in /3w/xf.cz/w/wordstudio/plugin.php on line 33”
What is wrong? And will it function?
(Edit: updated so your posted code displays properly. :) -Mary)
Last edited by Mary (2005-12-24 03:08:01)
Offline
#2 2005-12-24 03:17:33
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: I make new, what is wrong?
function wsp_smile_replace($atts)
{
// you need to declare $thisarticle as global, otherwise it will be empty
global $thisarticle;
// text to replace with html
$smilies = array(
':-)' => '<img src="/images/site/3.gif" />'
);
// return the results
return str_replace(array_keys($smilies), array_values($smilies), $thisarticle['body']);
}
(Edit: corrected the code)
Last edited by Mary (2005-12-26 01:08:16)
Offline
#3 2005-12-25 18:21:23
- Ji31
- Member
- Registered: 2005-08-24
- Posts: 103
Re: I make new, what is wrong?
31 function wsp_smile_replace($atts)
32 {
33 // you need to declare $thisarticle as global, otherwise it will be empty
34 global $thisarticle;
35
36 // text to replace with html
37 $smilies = array(
38 ‘:-)’ => ‘<img src=”/images/site/3.gif” />’
39 );
40
41 // return the results
42 return str_replace(array_keys($smilies), array_values($smilies), $thisarticle[‘Body’]);
43 }
Parse error: parse error, expecting `T_STRING’ or `T_VARIABLE’ or `T_NUM_STRING’ in /3w/xf.cz/w/wordstudio/plugin.php on line 42
Offline
#4 2005-12-26 01:07:49
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: I make new, what is wrong?
Sorry I missed one thing: the correct name is $thisarticle['body'], all lowercase (otherwise, you’ll get undefined index errors).
I don’t get your error at all, it works just fine for me, so you need to look at the plugin template, you must’ve accidentally deleted/added something.
Offline
#5 2005-12-26 09:14:10
- Ji31
- Member
- Registered: 2005-08-24
- Posts: 103
Re: I make new, what is wrong?
> mary wrote:
> Sorry I missed one thing: the correct name is $thisarticle['body'], all lowercase (otherwise, you’ll get undefined index errors).
Yes, after the array is missing comma “,” but even if I wrote “body” with small, it’s still error.. :-) I will look at my template and write back.
Offline
#6 2005-12-28 12:54:39
- Ji31
- Member
- Registered: 2005-08-24
- Posts: 103
Re: I make new, what is wrong?
It’s still not working. I have it all lowercase, but it’s still Parse error: parse error, expecting `T_STRING’ or `T_VARIABLE’ or `T_NUM_STRING’ in /3w/xf.cz/w/wordstudio/plugin.php on line 42
Why?
(line 42 is: return str_replace(array_keys($smilies), array_values($smilies), $thisarticle[‘body’]); )
Offline
#7 2005-12-28 16:53:57
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: I make new, what is wrong?
The lettercase isn’t the problem, this is the problem:
<notextile>expecting `T_STRING` or `T_VARIABLE` or `T_NUM_STRING`</notextile>
That means you haven’t closed something somewhere before line 42.
Offline
#8 2005-12-28 17:01:45
- Ji31
- Member
- Registered: 2005-08-24
- Posts: 103
Re: I make new, what is wrong?
No no, everything is ok, I think
1 <?php
2
3 // plugin name must be url-friendly, with no spaces
4 // please prepend the plugin name with a 3-letter developer identifier
5
6 $plugin[‘name’] = ‘wsp_smile_replace’;
7 $plugin[‘author’] = ‘Ji31’;
8 $plugin[‘author_uri’] = ‘http://wordstudio.xf.cz’;
9 $plugin[‘version’] = ‘0.1’;
10 // short description of the plugin
11 $plugin[‘description’] = ‘Replace the text smilies for images.’;
12 // short helpfile (xhtml) – please be explicit in describing how the plugin
13 // is called, and any parameters that may be edited by the site publisher
14
15 $plugin[‘help’] = ‘
16
17 <p>Extended help</p>
18
19 ‘;
20
21
22 // The plugin code, as a string. NO PHP open/close tags please
23
24 $plugin[‘code’] = <<<eod
25 function wsp_smile_replace($atts)
26 {
27 // you need to declare $thisarticle as global, otherwise it will be empty
28 global $thisarticle;
29
30 // text to replace with html
31 $smilies = array(
32 “;-)” => “<img src=\”/images/site/1.gif\” />,
33” => “<img src=\”/images/site/2.gif\” />,
34)” => “<img src=\”/images/site/3.gif\” />,
35” => “<img src=\”/images/site/4.gif\” />”,
36 “B-)” => “<img src=\”/images/site/5.gif\” />,
37” => “<img src=\”/images/site/6.gif\” />,
38” => “<img src=\”/images/site/7.gif\” />”
39 );
40
41 // return the results
42 return str_replace(array_keys($smilies), array_values($smilies), $thisarticle[body]);
43 }
44
45 eod;
46
47
48
49 $plugin[‘md5’] = md5( $plugin[‘code’] );
50
51 // to produce a copy of the plugin for distribution, load this file in a browser.
52
53 echo base64_encode(serialize($plugin));
54
55 ?>
Offline
#9 2005-12-28 17:41:45
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: I make new, what is wrong?
You aren’t using the correct plugin template. That’s an older one, which requires that you escape all variables, not quotes. Use this one.
Offline
#10 2005-12-28 23:53:46
- Ji31
- Member
- Registered: 2005-08-24
- Posts: 103
Re: I make new, what is wrong?
Ok, may be I’am stupid.
I have written with some help this code:
global $thisarticle;
// text to replace with html
$smilies = array(
“;-)” => “<img src=\”/images/site/1.gif\” />,” => “<img src=\”/images/site/2.gif\” />,)” => “<img src=\”/images/site/3.gif\” />,” => “<img src=\”/images/site/4.gif\” />”,
“B-)” => “<img src=\”/images/site/5.gif\” />,” => “<img src=\”/images/site/6.gif\” />,” => “<img src=\”/images/site/7.gif\” />”
);
// return the results
return str_replace(array_keys($smilies), array_values($smilies), $thisarticle[body]);
I have it inserted between this:
… … @include_once(‘zem_tpl.php’); if (0) { ?>- —- BEGIN PLUGIN HELP —-
Textile-formatted help goes here - —- END PLUGIN HELP —-
<?php
} - —- BEGIN PLUGIN CODE —-
and this
// return the results return str_replace(array_keys($smilies), array_values($smilies), $thisarticle[body]);- —- END PLUGIN CODE —-
?>
I saved this as wsp_smilies.php into some folder with zem_tpl.php.
I have genered the code and pasted it into my plugin page. I have switched to “on” and inserted the tag <txp:wsp_smilies /> into my page, but nothing was happened.
What I do wrong? Am I so stupid? (May be my english isn’t so good..?)
Last edited by Ji31 (2005-12-29 00:07:44)
Offline
#11 2005-12-29 06:37:59
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: I make new, what is wrong?
Offline
Re: I make new, what is wrong?
So… is this plug-in ready? Could somebody be so kind to compile it? =) Ple-e-ea-a-ase =)
There are 10 types of people in the world – those who understand binary and those who don’t.
Offline