/[drupal]/contributions/modules/dript/dript.module
ViewVC logotype

Contents of /contributions/modules/dript/dript.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Tue Jan 23 18:16:27 2007 UTC (2 years, 10 months ago) by chelah
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +2 -2 lines
File MIME type: text/x-php
Corrected string escape character handling bug where "\n" was not parsed properly. Remove slash infront of quote, which where inappropriately added during internal string conversion. HTML tags are now allowed inside string.
1 <?php
2 /**
3 * @file
4 * dript scripting language filter
5 * By Abdullah "chelah" Daud
6 * 1 January 2007
7 * mailto:chelah@bootbox.net
8 * http://chelah.cara-cerna.com
9 */
10
11 /**
12 * Implementation of hook_help()
13 * Display help text for this module
14 */
15 function dript_help($section)
16 {
17 switch ($section)
18 {
19 case 'admin/help#dript':
20 $o .= '<p>' .
21
22 t('Dript is a dialect of lisp programming language. ' .
23 'It allows user of Drupal to apply scripting on contents. ' .
24 'Dript is safer than PHP since the usage of the former ' .
25 'functions can be fully controlled. In fact Dript itself is ' .
26 'developed using PHP. Each Dript function is kept in an ' .
27 'individual file that can be added or removed without any ' .
28 'need to reconfigure Dript. When a function is missing ' .
29 'Dript will simply not evaluate it.') .
30
31 '</p></p>' .
32
33 t('Dript script for filter must be enclosed with the ' .
34 'following tags:') .
35
36 '</p></p>' .
37
38 t('[dript /] - The script will be replaced with text ' .
39 'passed by function (print \'msg).') .
40
41 '</p></p>' .
42
43 t('[dripte /] - The script will be replaced with ' .
44 'the result of the last expression.') .
45
46 '</p></p>' .
47
48 t('Dript script for node (auto-filter) must be enclosed ' .
49 'with the following tags:') .
50
51 '</p></p>' .
52
53 t('[driptn /] - The script will be replaced with text ' .
54 'passed by function (print \'msg). All function that takes ' .
55 'nid can use \'this to refer to the current node.') .
56
57 '</p></p>' .
58
59 t('[driptne /] - The script will be replaced with ' .
60 'the result of the last expression. All function that takes ' .
61 'nid can use \'this to refer to the current node.');
62
63 return $o;
64
65 case 'admin/modules#description':
66 return t('Allows users to filter content with dript.');
67 }
68 }
69
70 /**
71 * Get lisp object
72 */
73 function dript_get_lisp_object($node_tag = false)
74 {
75 $path = './'. drupal_get_path('module', 'dript') . '/lisp/';
76 $user_path = './'. file_directory_path() . '/';
77 include_once $path . 'lisp.inc';
78 $l = new lisp();
79 $l->init($path, $user_path);
80
81 if ($node_tag)
82 $l->start_tag = '[driptn';
83 else
84 $l->start_tag = '[dript';
85
86 return $l;
87 }
88
89 /**
90 * Evaluate expression.
91 */
92 function dript_eval($expr, $source, &$node)
93 {
94 if (is_object($node))
95 $node_tag = true;
96 else
97 $node_tag = false;
98
99 $l = dript_get_lisp_object($node_tag);
100
101 global $dript_global_var_this_node;
102 $xnode = $dript_global_var_this_node;
103 $dript_global_var_this_node = $node;
104
105 $l->go();
106 $rst = $l->evaluate($expr, $source, $dre);
107
108 $dript_global_var_this_node = $xnode;
109
110 if ($l->is_err())
111 return $l->err_str();
112
113 return stripcslashes($rst);
114 }
115
116 /**
117 * Evaluate text with embedded script.
118 */
119 function dript_eval_text($text, $source, $node_tag)
120 {
121 $l = dript_get_lisp_object($node_tag);
122 $l->go();
123 return stripcslashes($l->eval_text($text, $source));
124 }
125
126 /**
127 * Implementation of hook_nodeapi().
128 */
129 function dript_nodeapi(&$node, $op)
130 {
131 if ($op == 'alter')
132 {
133 global $dript_global_var_this_node;
134 $xnode = $dript_global_var_this_node;
135 $dript_global_var_this_node = $node;
136
137 $node->body = dript_eval_text($node->body, $node->title, true);
138 $node->teaser = dript_eval_text($node->teaser, $node->title, true);
139
140 $dript_global_var_this_node = $xnode;
141 }
142 }
143
144 /**
145 * Implementation of hook_filter().
146 */
147 function dript_filter($op, $delta = 0, $format = -1, $text = '')
148 {
149
150 if ($op == 'list')
151 {
152 return array(0 => t('Dript expression'),
153 1 => t('Embedded Dript expression'));
154 }
155
156 switch ($delta)
157 {
158 case 0:
159
160 switch ($op)
161 {
162 case 'description':
163 return t('Evaluate the text as the whole expression.');
164
165 case 'no cache':
166 return TRUE;
167
168 case 'prepare':
169 return $text;
170
171 case 'process':
172 return dript_eval($text, 'filter');
173 }
174
175 break;
176
177 case 1:
178
179 switch ($op)
180 {
181 case 'description':
182 return t('Evaluate script embedded within [dript /] ' .
183 'and/or [dripte /] tags.');
184
185 case 'no cache':
186 return TRUE;
187
188 case 'prepare':
189 return $text;
190
191 case 'process':
192 return dript_eval_text($text, 'filter', false);
193 }
194
195 break;
196 }
197 }
198
199 /**
200 * Implementation of hook_filter_tips().
201 */
202 function dript_filter_tips($delta, $format, $long = FALSE)
203 {
204 switch ($delta)
205 {
206 case 0:
207
208 if ($long)
209 return t('Expression will be evaluated and the result will be ' .
210 'returned.');
211
212 break;
213
214 case 1:
215
216 if ($long)
217 return t('Embedded expression will be evaluated and the result ' .
218 'will be written back in place.');
219 else
220 return t('Embed expression inside [dript /] and/or ' .
221 '[dripte /] tags.');
222
223 break;
224 }
225 }
226
227
228

  ViewVC Help
Powered by ViewVC 1.1.2