1 | <?php |
---|
2 | # ***** BEGIN LICENSE BLOCK ***** |
---|
3 | # |
---|
4 | # This file is part of Contribute. |
---|
5 | # Copyright 2008,2009 Moe (http://gniark.net/) |
---|
6 | # |
---|
7 | # Contribute is free software; you can redistribute it and/or modify |
---|
8 | # it under the terms of the GNU General Public License as published by |
---|
9 | # the Free Software Foundation; either version 3 of the License, or |
---|
10 | # (at your option) any later version. |
---|
11 | # |
---|
12 | # Contribute is distributed in the hope that it will be useful, |
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | # GNU General Public License for more details. |
---|
16 | # |
---|
17 | # You should have received a copy of the GNU General Public License |
---|
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | # |
---|
20 | # Icon (icon.png) is from Silk Icons : http://www.famfamfam.com/lab/icons/silk/ |
---|
21 | # |
---|
22 | # ***** END LICENSE BLOCK ***** |
---|
23 | |
---|
24 | if (!defined('DC_RC_PATH')) {return;} |
---|
25 | |
---|
26 | l10n::set(dirname(__FILE__).'/locales/'.$_lang.'/public'); |
---|
27 | |
---|
28 | /** |
---|
29 | @ingroup Contribute |
---|
30 | @brief Document |
---|
31 | */ |
---|
32 | class contributeDocument extends dcUrlHandlers |
---|
33 | { |
---|
34 | /** |
---|
35 | serve the document |
---|
36 | @param args <b>string</b> Argument |
---|
37 | */ |
---|
38 | public static function page($args) |
---|
39 | { |
---|
40 | # from /dotclear/inc/public/lib.urlhandlers.php |
---|
41 | # Spam trap |
---|
42 | if (!empty($_POST['f_mail'])) |
---|
43 | { |
---|
44 | http::head(412,'Precondition Failed'); |
---|
45 | header('Content-Type: text/plain'); |
---|
46 | echo "So Long, and Thanks For All the Fish"; |
---|
47 | exit; |
---|
48 | } |
---|
49 | # /from /dotclear/inc/public/lib.urlhandlers.php |
---|
50 | |
---|
51 | global $core; |
---|
52 | |
---|
53 | $settings =& $core->blog->settings; |
---|
54 | |
---|
55 | if (!$settings->contribute_active) |
---|
56 | { |
---|
57 | self::p404(); |
---|
58 | return; |
---|
59 | } |
---|
60 | |
---|
61 | $_ctx =& $GLOBALS['_ctx']; |
---|
62 | |
---|
63 | $_ctx->contribute = new ArrayObject(); |
---|
64 | $_ctx->contribute->help = @base64_decode($settings->contribute_help); |
---|
65 | $_ctx->contribute->message = ''; |
---|
66 | $_ctx->contribute->preview = false; |
---|
67 | $_ctx->contribute->form = true; |
---|
68 | $_ctx->contribute->choose_format = false; |
---|
69 | # selected tags |
---|
70 | $_ctx->contribute->selected_tags = array(); |
---|
71 | |
---|
72 | # Metadata |
---|
73 | if ($core->plugins->moduleExists('metadata')) |
---|
74 | { |
---|
75 | $meta = new dcMeta($core); |
---|
76 | } |
---|
77 | else |
---|
78 | { |
---|
79 | $meta = false; |
---|
80 | } |
---|
81 | |
---|
82 | # My Meta |
---|
83 | if ($core->plugins->moduleExists('mymeta') |
---|
84 | && ($settings->contribute_allow_mymeta)) |
---|
85 | { |
---|
86 | $mymeta_values = array(); |
---|
87 | |
---|
88 | $_ctx->contribute->mymeta = new myMeta($core); |
---|
89 | |
---|
90 | if ($_ctx->contribute->mymeta->hasMeta()) |
---|
91 | { |
---|
92 | $mymeta_values = @unserialize(@base64_decode( |
---|
93 | $settings->contribute_mymeta_values)); |
---|
94 | |
---|
95 | if (!is_array($mymeta_values)) {$mymeta_values = array();} |
---|
96 | |
---|
97 | $mymeta = array(); |
---|
98 | |
---|
99 | foreach ($_ctx->contribute->mymeta->getAll() as $k => $v) |
---|
100 | { |
---|
101 | if (((bool) $v->enabled) && in_array($k,$mymeta_values)) |
---|
102 | { |
---|
103 | $mymeta[] = $k; |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | unset($mymeta_values); |
---|
108 | } |
---|
109 | else |
---|
110 | { |
---|
111 | $_ctx->contribute->mymeta = false; |
---|
112 | } |
---|
113 | } |
---|
114 | else |
---|
115 | { |
---|
116 | $_ctx->contribute->mymeta = false; |
---|
117 | } |
---|
118 | # /My Meta |
---|
119 | |
---|
120 | # name, mail and site of the contributor |
---|
121 | |
---|
122 | $name = ''; |
---|
123 | $mail = ''; |
---|
124 | $site = ''; |
---|
125 | |
---|
126 | # inspired by contactMe/_public.php |
---|
127 | if ($args == 'sent') |
---|
128 | { |
---|
129 | $_ctx->contribute->message = 'sent'; |
---|
130 | $_ctx->contribute->preview = false; |
---|
131 | $_ctx->contribute->form = false; |
---|
132 | # avoid error with <tpl:ContributeIf format="xhtml"> |
---|
133 | $_ctx->posts = new ArrayObject(); |
---|
134 | $_ctx->posts->post_format = ''; |
---|
135 | } |
---|
136 | else |
---|
137 | { |
---|
138 | try |
---|
139 | { |
---|
140 | # default post |
---|
141 | $default_post = $settings->contribute_default_post; |
---|
142 | if (is_int($default_post) && ($default_post > 0)) |
---|
143 | { |
---|
144 | # get default post |
---|
145 | $_ctx->posts = $core->auth->sudo(array($core->blog,'getPosts'), |
---|
146 | array('post_id' => $default_post)); |
---|
147 | |
---|
148 | if ($_ctx->posts->isEmpty()) |
---|
149 | { |
---|
150 | throw new Exception(__('No default post.')); |
---|
151 | } |
---|
152 | |
---|
153 | # modify $_ctx->posts for preview |
---|
154 | $post =& $_ctx->posts; |
---|
155 | |
---|
156 | # tags |
---|
157 | # remove selected tags |
---|
158 | $post_meta = unserialize($_ctx->posts->post_meta); |
---|
159 | |
---|
160 | if (isset($post_meta['tag']) && !empty($post_meta['tag'])) |
---|
161 | { |
---|
162 | foreach ($post_meta['tag'] as $k => $tag) |
---|
163 | { |
---|
164 | $_ctx->contribute->selected_tags[] = $tag; |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | # My Meta |
---|
169 | $post->mymeta = array(); |
---|
170 | |
---|
171 | if ($_ctx->contribute->mymeta !== false) |
---|
172 | { |
---|
173 | foreach ($mymeta as $k => $v) |
---|
174 | { |
---|
175 | $post->mymeta[$v] = $meta->getMetaStr($post->post_meta,$v); |
---|
176 | } |
---|
177 | } |
---|
178 | # /My Meta |
---|
179 | } |
---|
180 | # empty post |
---|
181 | else |
---|
182 | { |
---|
183 | # create empty fields from default columns |
---|
184 | $record = array(); |
---|
185 | $empty_post = $core->auth->sudo(array($core->blog,'getPosts'), |
---|
186 | array('post_id' => -1)); |
---|
187 | |
---|
188 | $record[0] = array(); |
---|
189 | |
---|
190 | foreach ($empty_post->columns() as $k => $v) |
---|
191 | { |
---|
192 | $record[0][$v] = ''; |
---|
193 | } |
---|
194 | $_ctx->posts = staticRecord::newFromArray($record); |
---|
195 | |
---|
196 | unset($empty_post,$record); |
---|
197 | |
---|
198 | $_ctx->posts->core = $core; |
---|
199 | $_ctx->posts->extend('rsExtPost'); |
---|
200 | |
---|
201 | # --BEHAVIOR-- coreBlogGetPosts |
---|
202 | $core->callBehavior('coreBlogGetPosts',$_ctx->posts); |
---|
203 | |
---|
204 | # modify $_ctx->posts for preview |
---|
205 | $post =& $_ctx->posts; |
---|
206 | |
---|
207 | # My Meta |
---|
208 | $post->mymeta = array(); |
---|
209 | # /My Meta |
---|
210 | |
---|
211 | # formats |
---|
212 | # default format setting |
---|
213 | $post->post_format = $settings->contribute_format; |
---|
214 | |
---|
215 | # contributor can choose the post format, |
---|
216 | # it overrides the default format |
---|
217 | if ($settings->contribute_format == '') |
---|
218 | |
---|
219 | { |
---|
220 | $_ctx->contribute->choose_format = true; |
---|
221 | |
---|
222 | if ((isset($_POST['post_format'])) |
---|
223 | && in_array($_POST['post_format'],$core->getFormaters())) |
---|
224 | { |
---|
225 | $post->post_format = $_POST['post_format']; |
---|
226 | } |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | unset($default_post); |
---|
231 | |
---|
232 | # formats |
---|
233 | $formaters_combo = array(); |
---|
234 | # Formaters combo |
---|
235 | foreach ($core->getFormaters() as $v) |
---|
236 | { |
---|
237 | $formaters_combo[] = array('format' => $v); |
---|
238 | } |
---|
239 | $_ctx->contribute->formaters = |
---|
240 | staticRecord::newFromArray($formaters_combo); |
---|
241 | |
---|
242 | unset($formaters_combo); |
---|
243 | |
---|
244 | # current date |
---|
245 | $post->post_dt = dt::str('%Y-%m-%d %T',null, |
---|
246 | $settings->blog_timezone); |
---|
247 | # remove URL |
---|
248 | $post->post_url = ''; |
---|
249 | |
---|
250 | if (isset($_POST['post_title'])) |
---|
251 | { |
---|
252 | $post->post_title = $_POST['post_title']; |
---|
253 | } |
---|
254 | |
---|
255 | # excerpt |
---|
256 | if (($settings->contribute_allow_excerpt) |
---|
257 | && (isset($_POST['post_excerpt']))) |
---|
258 | { |
---|
259 | $post->post_excerpt = $_POST['post_excerpt']; |
---|
260 | } |
---|
261 | # content |
---|
262 | if (isset($_POST['post_content'])) |
---|
263 | { |
---|
264 | $post->post_content = $_POST['post_content']; |
---|
265 | } |
---|
266 | |
---|
267 | # avoid Notice: Indirect modification of overloaded property |
---|
268 | # record::$post_excerpt has no effect in .../contribute/_public.php |
---|
269 | # on line 146 |
---|
270 | $post_excerpt = $post->post_excerpt; |
---|
271 | $post_excerpt_xhtml = $post->post_excerpt_xhtml; |
---|
272 | $post_content = $post->post_content; |
---|
273 | $post_content_xhtml = $post->post_content_xhtml; |
---|
274 | |
---|
275 | # HTML filter |
---|
276 | # get the setting value |
---|
277 | $enable_html_filter = $settings->enable_html_filter; |
---|
278 | # set the setting to true |
---|
279 | $settings->enable_html_filter = true; |
---|
280 | |
---|
281 | $core->blog->setPostContent( |
---|
282 | '',$post->post_format,$settings->lang, |
---|
283 | $post_excerpt,$post_excerpt_xhtml, |
---|
284 | $post_content,$post_content_xhtml |
---|
285 | ); |
---|
286 | |
---|
287 | # set the old value to the setting |
---|
288 | $settings->enable_html_filter = $enable_html_filter; |
---|
289 | unset($enable_html_filter); |
---|
290 | |
---|
291 | $post->post_excerpt = $post_excerpt; |
---|
292 | $post->post_excerpt_xhtml = $post_excerpt_xhtml; |
---|
293 | $post->post_content = $post_content; |
---|
294 | $post->post_content_xhtml = $post_content_xhtml; |
---|
295 | |
---|
296 | unset($post_excerpt,$post_excerpt_xhtml,$post_content, |
---|
297 | $post_content_xhtml); |
---|
298 | |
---|
299 | if ($_ctx->contribute->choose_format |
---|
300 | && (isset($_POST['convert-xhtml'])) |
---|
301 | && ($post->post_format != 'xhtml')) |
---|
302 | { |
---|
303 | $post->post_excerpt = $post->post_excerpt_xhtml; |
---|
304 | $post->post_content = $post->post_content_xhtml; |
---|
305 | $post->post_format = 'xhtml'; |
---|
306 | } |
---|
307 | |
---|
308 | $_ctx->formaters = new ArrayObject; |
---|
309 | $_ctx->formaters->format = $post->post_format; |
---|
310 | |
---|
311 | # category |
---|
312 | if (($settings->contribute_allow_category) |
---|
313 | && (isset($_POST['cat_id']))) |
---|
314 | { |
---|
315 | # check category |
---|
316 | if (($_POST['cat_id'] != '') |
---|
317 | && (!preg_match('/^[0-9]+$/',$_POST['cat_id']))) |
---|
318 | { |
---|
319 | throw new Exception(__('Invalid cat_id')); |
---|
320 | } |
---|
321 | |
---|
322 | $cat = $core->blog->getCategories(array( |
---|
323 | 'start' => $_POST['cat_id'], |
---|
324 | 'level' => 1, |
---|
325 | 'cat_id' => $_POST['cat_id'] |
---|
326 | )); |
---|
327 | |
---|
328 | while ($cat->fetch()) |
---|
329 | { |
---|
330 | # set category |
---|
331 | $post->cat_id = $cat->cat_id; |
---|
332 | $post->cat_title = $cat->cat_title; |
---|
333 | $post->cat_url = $cat->cat_url; |
---|
334 | break; |
---|
335 | } |
---|
336 | |
---|
337 | unset($cat); |
---|
338 | } |
---|
339 | # /category |
---|
340 | |
---|
341 | if ($meta !== false) |
---|
342 | { |
---|
343 | # tags |
---|
344 | if (($settings->contribute_allow_tags) |
---|
345 | && (isset($_POST['post_tags']))) |
---|
346 | { |
---|
347 | $post_meta = unserialize($_ctx->posts->post_meta); |
---|
348 | |
---|
349 | # remove post tags |
---|
350 | unset($post_meta['tag']); |
---|
351 | |
---|
352 | # get all the existing tags |
---|
353 | $available_tags = contribute::getTags(); |
---|
354 | |
---|
355 | # set post tags |
---|
356 | # from /dotclear/plugins/metadata/_admin.php |
---|
357 | foreach ($meta->splitMetaValues($_POST['post_tags']) |
---|
358 | as $k => $tag) |
---|
359 | { |
---|
360 | # /from /dotclear/plugins/metadata/_admin.php |
---|
361 | $tag = dcMeta::sanitizeMetaID($tag); |
---|
362 | |
---|
363 | if ($settings->contribute_allow_new_tags) |
---|
364 | { |
---|
365 | $post_meta['tag'][] = $tag; |
---|
366 | $_ctx->contribute->selected_tags[] = $tag; |
---|
367 | } |
---|
368 | else |
---|
369 | { |
---|
370 | # check that this tag already exists |
---|
371 | if (in_array($tag,$available_tags)) |
---|
372 | { |
---|
373 | $post_meta['tag'][] = $tag; |
---|
374 | $_ctx->contribute->selected_tags[] = $tag; |
---|
375 | } |
---|
376 | } |
---|
377 | } |
---|
378 | |
---|
379 | unset($available_tags); |
---|
380 | |
---|
381 | $_ctx->posts->post_meta = serialize($post_meta); |
---|
382 | unset($post_meta); |
---|
383 | |
---|
384 | } |
---|
385 | |
---|
386 | # My Meta |
---|
387 | if ($_ctx->contribute->mymeta !== false) |
---|
388 | { |
---|
389 | foreach ($mymeta as $k => $v) |
---|
390 | { |
---|
391 | $post->mymeta[$v] = (isset($_POST['mymeta_'.$v]) |
---|
392 | ? $_POST['mymeta_'.$v] : ''); |
---|
393 | } |
---|
394 | } |
---|
395 | # /My Meta |
---|
396 | } |
---|
397 | |
---|
398 | # notes |
---|
399 | if (($settings->contribute_allow_notes) |
---|
400 | && (isset($_POST['post_notes']))) |
---|
401 | { |
---|
402 | $post->post_notes = $_POST['post_notes']; |
---|
403 | } |
---|
404 | |
---|
405 | # author |
---|
406 | if (($meta !== false) |
---|
407 | && ($settings->contribute_allow_author)) |
---|
408 | { |
---|
409 | $post_meta = unserialize($_ctx->posts->post_meta); |
---|
410 | |
---|
411 | if (isset($_POST['c_name']) && (!empty($_POST['c_name']))) |
---|
412 | { |
---|
413 | $post_meta['contribute_author'][] = $name = $_POST['c_name']; |
---|
414 | } |
---|
415 | if (isset($_POST['c_mail']) && (!empty($_POST['c_mail']))) |
---|
416 | { |
---|
417 | $post_meta['contribute_mail'][] = $mail = $_POST['c_mail']; |
---|
418 | } |
---|
419 | # inspired by dcBlog > getCommentCursor() |
---|
420 | if (isset($_POST['c_site']) && (!empty($_POST['c_site']))) |
---|
421 | { |
---|
422 | $site = $_POST['c_site']; |
---|
423 | |
---|
424 | if (!preg_match('|^http(s?)://|',$site)) |
---|
425 | { |
---|
426 | $site = 'http://'.$site; |
---|
427 | } |
---|
428 | # /inspired by dcBlog > getCommentCursor() |
---|
429 | |
---|
430 | $post_meta['contribute_site'][] = $site; |
---|
431 | } |
---|
432 | |
---|
433 | $_ctx->posts->post_meta = serialize($post_meta); |
---|
434 | unset($post_meta); |
---|
435 | } |
---|
436 | |
---|
437 | # check some inputs |
---|
438 | if ((isset($_POST['preview'])) || (isset($_POST['add']))) |
---|
439 | { |
---|
440 | # these fields can't be empty |
---|
441 | if (isset($_POST['post_content']) && empty($post->post_content)) |
---|
442 | { |
---|
443 | throw new Exception(__('No entry content')); |
---|
444 | } elseif (isset($_POST['post_title']) && empty($post->post_title)) |
---|
445 | { |
---|
446 | throw new Exception(__('No entry title')); |
---|
447 | } |
---|
448 | |
---|
449 | # if name and email address are required |
---|
450 | if (($settings->contribute_allow_author) |
---|
451 | && ($settings->contribute_require_name_email)) |
---|
452 | { |
---|
453 | if (empty($name)) |
---|
454 | { |
---|
455 | $_ctx->contribute->preview = false; |
---|
456 | $_ctx->contribute->message = ''; |
---|
457 | throw new Exception(__('You must provide an author name')); |
---|
458 | } elseif (!text::isEmail($mail)) |
---|
459 | { |
---|
460 | $_ctx->contribute->preview = false; |
---|
461 | $_ctx->contribute->message = ''; |
---|
462 | throw new Exception( |
---|
463 | __('You must provide a valid email address.')); |
---|
464 | } |
---|
465 | } |
---|
466 | } |
---|
467 | |
---|
468 | if (isset($_POST['preview'])) |
---|
469 | { |
---|
470 | $_ctx->contribute->preview = true; |
---|
471 | $_ctx->contribute->message = 'preview'; |
---|
472 | } |
---|
473 | |
---|
474 | if (isset($_POST) && empty($_POST)) |
---|
475 | { |
---|
476 | $_ctx->contribute->preview = false; |
---|
477 | $_ctx->contribute->message = ''; |
---|
478 | } |
---|
479 | |
---|
480 | if (isset($_POST['add'])) |
---|
481 | { |
---|
482 | # log in as the user |
---|
483 | # usage OR contentadmin permission is needed |
---|
484 | $core->auth->checkUser($settings->contribute_user); |
---|
485 | |
---|
486 | if (!$core->auth->check('usage,contentadmin',$core->blog->id)) |
---|
487 | { |
---|
488 | throw new Exception( |
---|
489 | __('The user is not allowed to create an entry')); |
---|
490 | } |
---|
491 | |
---|
492 | $post_status = 0; |
---|
493 | |
---|
494 | # antispam |
---|
495 | if ($settings->contribute_enable_antispam |
---|
496 | && $core->plugins->moduleExists('antispam')) |
---|
497 | { |
---|
498 | $cur = $core->con->openCursor($core->prefix.'comment'); |
---|
499 | |
---|
500 | $cur->comment_trackback = 0; |
---|
501 | $cur->comment_author = $name; |
---|
502 | $cur->comment_email = $mail; |
---|
503 | $cur->comment_site = $site; |
---|
504 | $cur->comment_ip = http::realIP(); |
---|
505 | $cur->comment_content = $post->post_excerpt."\n". |
---|
506 | $post->post_content; |
---|
507 | $cur->post_id = $core->con->select( |
---|
508 | 'SELECT MAX(post_id) '. |
---|
509 | 'FROM '.$core->prefix.'post ')->f(0) + 1; |
---|
510 | $cur->comment_status = 0; |
---|
511 | |
---|
512 | $is_spam = contributeAntispam::isSpam($cur); |
---|
513 | |
---|
514 | if ($is_spam === true) |
---|
515 | { |
---|
516 | $post_status = -2; |
---|
517 | |
---|
518 | # if the auto deletion is enable, don't save the post and exit |
---|
519 | # empty() doesn't work with $cur->comment_content |
---|
520 | $comment_content = $cur->comment_content; |
---|
521 | if (empty($comment_content)) |
---|
522 | { |
---|
523 | http::redirect($core->blog->url. |
---|
524 | $core->url->getBase('contribute').'/sent'); |
---|
525 | } |
---|
526 | unset($comment_content,$cur); |
---|
527 | } |
---|
528 | } |
---|
529 | # /antispam |
---|
530 | |
---|
531 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
532 | |
---|
533 | $cur->user_id = $core->auth->userID(); |
---|
534 | $cur->cat_id = ((empty($post->cat_id)) ? NULL : $post->cat_id); |
---|
535 | $cur->post_dt = $post->post_dt; |
---|
536 | $cur->post_status = $post_status; |
---|
537 | $cur->post_title = $post->post_title; |
---|
538 | $cur->post_format = $post->post_format; |
---|
539 | $cur->post_excerpt = $post->post_excerpt; |
---|
540 | $cur->post_content = $post->post_content; |
---|
541 | $cur->post_notes = $post->post_notes; |
---|
542 | $cur->post_lang = $core->auth->getInfo('user_lang'); |
---|
543 | $cur->post_open_comment = (integer) $settings->allow_comments; |
---|
544 | $cur->post_open_tb = (integer) $settings->allow_trackbacks; |
---|
545 | |
---|
546 | unset($post_status); |
---|
547 | |
---|
548 | # --BEHAVIOR-- publicBeforePostCreate |
---|
549 | $core->callBehavior('publicBeforePostCreate',$cur); |
---|
550 | |
---|
551 | $post_id = $core->blog->addPost($cur); |
---|
552 | |
---|
553 | # l10n from $core->blog->addPost(); |
---|
554 | __('You are not allowed to create an entry'); |
---|
555 | |
---|
556 | # --BEHAVIOR-- publicAfterPostCreate |
---|
557 | $core->callBehavior('publicAfterPostCreate',$cur,$post_id); |
---|
558 | |
---|
559 | if ($meta !== false) |
---|
560 | { |
---|
561 | # inspired by planet/insert_feeds.php |
---|
562 | if (!empty($name)) |
---|
563 | { |
---|
564 | $meta->setPostMeta($post_id,'contribute_author',$name); |
---|
565 | } |
---|
566 | if (!empty($mail)) |
---|
567 | { |
---|
568 | $meta->setPostMeta($post_id,'contribute_mail',$mail); |
---|
569 | } |
---|
570 | if (!empty($site)) |
---|
571 | { |
---|
572 | $meta->setPostMeta($post_id,'contribute_site',$site); |
---|
573 | } |
---|
574 | |
---|
575 | # tags |
---|
576 | $post_meta = unserialize($_ctx->posts->post_meta); |
---|
577 | if (($settings->contribute_allow_tags) |
---|
578 | && (isset($post_meta['tag'])) |
---|
579 | && (is_array($post_meta['tag']))) |
---|
580 | { |
---|
581 | foreach ($post_meta['tag'] as $k => $tag) |
---|
582 | { |
---|
583 | # from /dotclear/plugins/metadata/_admin.php |
---|
584 | $meta->setPostMeta($post_id,'tag',$tag); |
---|
585 | } |
---|
586 | |
---|
587 | unset($post_meta); |
---|
588 | } |
---|
589 | # /tags |
---|
590 | |
---|
591 | # My Meta |
---|
592 | if ($_ctx->contribute->mymeta !== false) |
---|
593 | { |
---|
594 | foreach ($post->mymeta as $k => $v) |
---|
595 | { |
---|
596 | $meta->setPostMeta($post_id,$k,$v); |
---|
597 | } |
---|
598 | } |
---|
599 | # /My Meta |
---|
600 | } |
---|
601 | |
---|
602 | # send email notification |
---|
603 | if ($settings->contribute_email_notification) |
---|
604 | { |
---|
605 | $headers = array( |
---|
606 | 'From: '.'dotclear@'.$_SERVER['HTTP_HOST'], |
---|
607 | 'MIME-Version: 1.0', |
---|
608 | 'Content-Type: text/plain; charset=UTF-8;', |
---|
609 | 'X-Mailer: Dotclear' |
---|
610 | ); |
---|
611 | |
---|
612 | $subject = sprintf(__('New post submitted on %s'), |
---|
613 | $core->blog->name); |
---|
614 | |
---|
615 | $content = sprintf(__('Title: %s'),$post->post_title); |
---|
616 | $content .= "\n\n"; |
---|
617 | |
---|
618 | if (!empty($name)) |
---|
619 | { |
---|
620 | $content .= sprintf(__('Author: %s'),$name); |
---|
621 | $content .= "\n\n"; |
---|
622 | } |
---|
623 | |
---|
624 | if (!empty($mail)) |
---|
625 | { |
---|
626 | $headers[] = 'Reply-To: '.$mail; |
---|
627 | |
---|
628 | $content .= sprintf(__('Email address: %s'),$mail); |
---|
629 | $content .= "\n\n"; |
---|
630 | } |
---|
631 | |
---|
632 | $params = array(); |
---|
633 | $params['post_id'] = $post_id; |
---|
634 | |
---|
635 | $post = $core->blog->getPosts($params); |
---|
636 | |
---|
637 | $content .= __('URL:').' '.$post->getURL(); |
---|
638 | unset($post); |
---|
639 | $content .= "\n\n"; |
---|
640 | |
---|
641 | $content .= __('Edit this entry:').' '.DC_ADMIN_URL. |
---|
642 | ((substr(DC_ADMIN_URL,-1) == '/') ? '' : '/'). |
---|
643 | 'post.php?id='.$post_id.'&switchblog='.$core->blog->id; |
---|
644 | $content .= "\n\n". |
---|
645 | __('You must log in on the backend before clicking on this link to go directly to the post.'); |
---|
646 | |
---|
647 | foreach(explode(',', |
---|
648 | $settings->contribute_email_notification) |
---|
649 | as $to) |
---|
650 | { |
---|
651 | $to = trim($to); |
---|
652 | if (text::isEmail($to)) |
---|
653 | { |
---|
654 | # don't display errors |
---|
655 | try { |
---|
656 | # from /dotclear/admin/auth.php : mail::B64Header($subject) |
---|
657 | mail::sendMail($to,mail::B64Header($subject), |
---|
658 | wordwrap($content,70),$headers); |
---|
659 | } catch (Exception $e) {} |
---|
660 | } |
---|
661 | } |
---|
662 | } |
---|
663 | # /send email notification |
---|
664 | |
---|
665 | http::redirect($core->blog->url. |
---|
666 | $core->url->getBase('contribute').'/sent'); |
---|
667 | } |
---|
668 | |
---|
669 | $_ctx->comment_preview = new ArrayObject(); |
---|
670 | $_ctx->comment_preview['name'] = $name; |
---|
671 | $_ctx->comment_preview['mail'] = $mail; |
---|
672 | $_ctx->comment_preview['site'] = $site; |
---|
673 | } |
---|
674 | catch (Exception $e) |
---|
675 | { |
---|
676 | $_ctx->form_error = $e->getMessage(); |
---|
677 | } |
---|
678 | } |
---|
679 | |
---|
680 | $core->tpl->setPath($core->tpl->getPath(), |
---|
681 | dirname(__FILE__).'/default-templates/'); |
---|
682 | |
---|
683 | self::serveDocument('contribute.html','text/html'); |
---|
684 | } |
---|
685 | } |
---|
686 | |
---|
687 | # message |
---|
688 | $core->tpl->addValue('ContributeMessage', |
---|
689 | array('contributeTpl','ContributeMessage')); |
---|
690 | |
---|
691 | $core->tpl->addValue('ContributeHelp', |
---|
692 | array('contributeTpl','ContributeHelp')); |
---|
693 | |
---|
694 | $core->tpl->addBlock('ContributePreview', |
---|
695 | array('contributeTpl','ContributePreview')); |
---|
696 | $core->tpl->addBlock('ContributeForm', |
---|
697 | array('contributeTpl','ContributeForm')); |
---|
698 | |
---|
699 | $core->tpl->addBlock('ContributeIf', |
---|
700 | array('contributeTpl','ContributeIf')); |
---|
701 | $core->tpl->addBlock('ContributeIfNameAndEmailAreNotRequired', |
---|
702 | array('contributeTpl','ContributeIfNameAndEmailAreNotRequired')); |
---|
703 | |
---|
704 | $core->tpl->addBlock('ContributeFormaters', |
---|
705 | array('contributeTpl','ContributeFormaters')); |
---|
706 | |
---|
707 | $core->tpl->addValue('ContributeFormat', |
---|
708 | array('contributeTpl','ContributeFormat')); |
---|
709 | |
---|
710 | $core->tpl->addValue('ContributeEntryExcerpt', |
---|
711 | array('contributeTpl','ContributeEntryExcerpt')); |
---|
712 | $core->tpl->addValue('ContributeEntryContent', |
---|
713 | array('contributeTpl','ContributeEntryContent')); |
---|
714 | |
---|
715 | $core->tpl->addBlock('ContributeIfSelected', |
---|
716 | array('contributeTpl','ContributeIfSelected')); |
---|
717 | |
---|
718 | $core->tpl->addValue('ContributeCategoryID', |
---|
719 | array('contributeTpl','ContributeCategoryID')); |
---|
720 | |
---|
721 | $core->tpl->addValue('ContributeCategorySpacer', |
---|
722 | array('contributeTpl','ContributeCategorySpacer')); |
---|
723 | |
---|
724 | $core->tpl->addBlock('ContributeEntryTagsFilter', |
---|
725 | array('contributeTpl','ContributeEntryTagsFilter')); |
---|
726 | |
---|
727 | $core->tpl->addBlock('ContributeEntryMyMeta', |
---|
728 | array('contributeTpl','ContributeEntryMyMeta')); |
---|
729 | |
---|
730 | $core->tpl->addBlock('ContributeEntryMyMetaIf', |
---|
731 | array('contributeTpl','ContributeEntryMyMetaIf')); |
---|
732 | |
---|
733 | $core->tpl->addValue('ContributeEntryMyMetaValue', |
---|
734 | array('contributeTpl','ContributeEntryMyMetaValue')); |
---|
735 | |
---|
736 | $core->tpl->addBlock('ContributeEntryMyMetaValues', |
---|
737 | array('contributeTpl','ContributeEntryMyMetaValues')); |
---|
738 | $core->tpl->addValue('ContributeEntryMyMetaValuesID', |
---|
739 | array('contributeTpl','ContributeEntryMyMetaValuesID')); |
---|
740 | $core->tpl->addValue('ContributeEntryMyMetaValuesDescription', |
---|
741 | array('contributeTpl','ContributeEntryMyMetaValuesDescription')); |
---|
742 | |
---|
743 | $core->tpl->addValue('ContributeEntryMyMetaID', |
---|
744 | array('contributeTpl','ContributeEntryMyMetaID')); |
---|
745 | $core->tpl->addValue('ContributeEntryMyMetaPrompt', |
---|
746 | array('contributeTpl','ContributeEntryMyMetaPrompt')); |
---|
747 | |
---|
748 | $core->tpl->addValue('ContributeEntryNotes', |
---|
749 | array('contributeTpl','ContributeEntryNotes')); |
---|
750 | |
---|
751 | /** |
---|
752 | @ingroup Contribute |
---|
753 | @brief Template |
---|
754 | */ |
---|
755 | class contributeTpl |
---|
756 | { |
---|
757 | /** |
---|
758 | display a message |
---|
759 | @return <b>string</b> PHP block |
---|
760 | */ |
---|
761 | public static function ContributeMessage() |
---|
762 | { |
---|
763 | return('<?php echo($_ctx->contribute->message); ?>'); |
---|
764 | } |
---|
765 | |
---|
766 | /** |
---|
767 | display the help |
---|
768 | @return <b>string</b> PHP block |
---|
769 | */ |
---|
770 | public static function ContributeHelp() |
---|
771 | { |
---|
772 | return('<?php echo($_ctx->contribute->help); ?>'); |
---|
773 | } |
---|
774 | |
---|
775 | /** |
---|
776 | display preview |
---|
777 | @param attr <b>array</b> Attribute |
---|
778 | @param content <b>string</b> Content |
---|
779 | @return <b>string</b> PHP block |
---|
780 | */ |
---|
781 | public static function ContributePreview($attr,$content) |
---|
782 | { |
---|
783 | return |
---|
784 | '<?php if ($_ctx->contribute->preview) : ?>'."\n". |
---|
785 | $content."\n". |
---|
786 | '<?php endif; ?>'; |
---|
787 | } |
---|
788 | |
---|
789 | /** |
---|
790 | display form |
---|
791 | @param attr <b>array</b> Attribute |
---|
792 | @param content <b>string</b> Content |
---|
793 | @return <b>string</b> PHP block |
---|
794 | */ |
---|
795 | public static function ContributeForm($attr,$content) |
---|
796 | { |
---|
797 | return |
---|
798 | '<?php if ($_ctx->contribute->form) : ?>'."\n". |
---|
799 | $content."\n". |
---|
800 | '<?php endif; ?>'; |
---|
801 | } |
---|
802 | |
---|
803 | /** |
---|
804 | if |
---|
805 | @param attr <b>array</b> Attribute |
---|
806 | @param content <b>string</b> Content |
---|
807 | @return <b>string</b> PHP block |
---|
808 | |
---|
809 | we can't use <tpl:ContributeIf> in another <tpl:ContributeIf> block yet |
---|
810 | |
---|
811 | <tpl:ContributeIf something="1"> |
---|
812 | <tpl:ContributeIf something_again="1"> |
---|
813 | </tpl:ContributeIf> |
---|
814 | </tpl:ContributeIf> |
---|
815 | |
---|
816 | will return : |
---|
817 | |
---|
818 | <?php if () : ?> |
---|
819 | <tpl:ContributeIf something_again="1"> |
---|
820 | <?php endif; ?>> |
---|
821 | </tpl:ContributeIf> |
---|
822 | */ |
---|
823 | public static function ContributeIf($attr,$content) |
---|
824 | { |
---|
825 | $if = array(); |
---|
826 | $operator = isset($attr['operator']) ? |
---|
827 | self::getOperator($attr['operator']) : '&&'; |
---|
828 | |
---|
829 | if (isset($attr['message'])) |
---|
830 | { |
---|
831 | $if[] = '$_ctx->contribute->message == \''.$attr['message'].'\''; |
---|
832 | } |
---|
833 | |
---|
834 | if (isset($attr['choose_format'])) |
---|
835 | { |
---|
836 | if ($attr['choose_format'] == '1') |
---|
837 | { |
---|
838 | $if[] = '$_ctx->contribute->choose_format'; |
---|
839 | } |
---|
840 | else |
---|
841 | { |
---|
842 | $if[] = '$_ctx->contribute->choose_format !== true'; |
---|
843 | } |
---|
844 | } |
---|
845 | |
---|
846 | if (isset($attr['format'])) |
---|
847 | { |
---|
848 | $format = trim($attr['format']); |
---|
849 | $sign = '='; |
---|
850 | if (substr($format,0,1) == '!') |
---|
851 | { |
---|
852 | $sign = '!'; |
---|
853 | $format = substr($format,1); |
---|
854 | } |
---|
855 | foreach (explode(',',$format) as $format) |
---|
856 | { |
---|
857 | $if[] = '$_ctx->posts->post_format '.$sign.'= "'.$format.'"'; |
---|
858 | } |
---|
859 | } |
---|
860 | |
---|
861 | if (isset($attr['excerpt'])) |
---|
862 | { |
---|
863 | $if[] = '$core->blog->settings->contribute_allow_excerpt'; |
---|
864 | } |
---|
865 | |
---|
866 | if (isset($attr['category'])) |
---|
867 | { |
---|
868 | $if[] = '$core->blog->settings->contribute_allow_category'; |
---|
869 | } |
---|
870 | |
---|
871 | if (isset($attr['tags'])) |
---|
872 | { |
---|
873 | $if[] = '$core->blog->settings->contribute_allow_tags'; |
---|
874 | } |
---|
875 | |
---|
876 | if (isset($attr['mymeta'])) |
---|
877 | { |
---|
878 | $if[] = '$core->blog->settings->contribute_allow_mymeta'; |
---|
879 | } |
---|
880 | |
---|
881 | if (isset($attr['notes'])) |
---|
882 | { |
---|
883 | $if[] = '$core->blog->settings->contribute_allow_notes'; |
---|
884 | } |
---|
885 | |
---|
886 | if (isset($attr['author'])) |
---|
887 | { |
---|
888 | $if[] = '$core->blog->settings->contribute_allow_author'; |
---|
889 | } |
---|
890 | |
---|
891 | if (!empty($if)) { |
---|
892 | return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'. |
---|
893 | $content."\n". |
---|
894 | '<?php endif; ?>'; |
---|
895 | } else { |
---|
896 | return $content; |
---|
897 | } |
---|
898 | } |
---|
899 | |
---|
900 | /** |
---|
901 | Get operator |
---|
902 | @param op <b>string</b> Operator |
---|
903 | @return <b>string</b> Operator |
---|
904 | \see /dotclear/inc/public/class.dc.template.php > getOperator() |
---|
905 | */ |
---|
906 | protected static function getOperator($op) |
---|
907 | { |
---|
908 | switch (strtolower($op)) |
---|
909 | { |
---|
910 | case 'or': |
---|
911 | case '||': |
---|
912 | return '||'; |
---|
913 | case 'and': |
---|
914 | case '&&': |
---|
915 | default: |
---|
916 | return '&&'; |
---|
917 | } |
---|
918 | } |
---|
919 | |
---|
920 | /** |
---|
921 | if name and email are required |
---|
922 | @param attr <b>array</b> Attribute |
---|
923 | @param content <b>string</b> Content |
---|
924 | @return <b>string</b> PHP block |
---|
925 | */ |
---|
926 | public static function ContributeIfNameAndEmailAreNotRequired($attr, |
---|
927 | $content) |
---|
928 | { |
---|
929 | $if = '$core->blog->settings->contribute_require_name_email !== true'; |
---|
930 | |
---|
931 | return '<?php if('.$if.') : ?>'. |
---|
932 | $content."\n". |
---|
933 | '<?php endif; ?>'; |
---|
934 | } |
---|
935 | |
---|
936 | /** |
---|
937 | if an element is selected |
---|
938 | @param attr <b>array</b> Attribute |
---|
939 | @param content <b>string</b> Content |
---|
940 | @return <b>string</b> PHP block |
---|
941 | */ |
---|
942 | public static function ContributeIfSelected($attr,$content) |
---|
943 | { |
---|
944 | $if = array(); |
---|
945 | $operator = '&&'; |
---|
946 | |
---|
947 | if (isset($attr['format'])) |
---|
948 | { |
---|
949 | $if[] = '$_ctx->formaters->format === $_ctx->posts->post_format'; |
---|
950 | } |
---|
951 | |
---|
952 | if (isset($attr['category'])) |
---|
953 | { |
---|
954 | $if[] = '$_ctx->categories->cat_id == $_ctx->posts->cat_id'; |
---|
955 | } |
---|
956 | |
---|
957 | if (isset($attr['mymeta'])) |
---|
958 | { |
---|
959 | $if[] = 'isset($_ctx->posts->mymeta[$_ctx->mymeta->id])'; |
---|
960 | $if[] = '$_ctx->mymetavalues->id == $_ctx->posts->mymeta[$_ctx->mymeta->id]'; |
---|
961 | } |
---|
962 | |
---|
963 | if (!empty($if)) { |
---|
964 | return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'. |
---|
965 | $content."\n". |
---|
966 | '<?php endif; ?>'; |
---|
967 | } else { |
---|
968 | return $content; |
---|
969 | } |
---|
970 | } |
---|
971 | |
---|
972 | /** |
---|
973 | Formaters |
---|
974 | @param attr <b>array</b> Attribute |
---|
975 | @param content <b>string</b> Content |
---|
976 | @return <b>string</b> PHP block |
---|
977 | */ |
---|
978 | public static function ContributeFormaters($attr,$content) |
---|
979 | { |
---|
980 | return |
---|
981 | '<?php '. |
---|
982 | # initialize for <tpl:LoopPosition> |
---|
983 | '$_ctx->formaters = $_ctx->contribute->formaters;'. |
---|
984 | 'while ($_ctx->formaters->fetch()) : ?>'."\n". |
---|
985 | $content."\n". |
---|
986 | '<?php endwhile; ?>'; |
---|
987 | } |
---|
988 | |
---|
989 | /** |
---|
990 | Format |
---|
991 | @param attr <b>array</b> Attribute |
---|
992 | @param content <b>string</b> Content |
---|
993 | @return <b>string</b> PHP block |
---|
994 | */ |
---|
995 | public static function ContributeFormat($attr,$content) |
---|
996 | { |
---|
997 | return('<?php echo(html::escapeHTML($_ctx->formaters->format)); ?>'); |
---|
998 | } |
---|
999 | |
---|
1000 | /** |
---|
1001 | Entry Excerpt |
---|
1002 | @param attr <b>array</b> Attribute |
---|
1003 | @return <b>string</b> PHP block |
---|
1004 | */ |
---|
1005 | public static function ContributeEntryExcerpt($attr) |
---|
1006 | { |
---|
1007 | return('<?php echo(html::escapeHTML($_ctx->posts->post_excerpt)); ?>'); |
---|
1008 | } |
---|
1009 | |
---|
1010 | /** |
---|
1011 | Entry Content |
---|
1012 | @param attr <b>array</b> Attribute |
---|
1013 | @return <b>string</b> PHP block |
---|
1014 | */ |
---|
1015 | public static function ContributeEntryContent($attr) |
---|
1016 | { |
---|
1017 | return('<?php echo(html::escapeHTML($_ctx->posts->post_content)); ?>'); |
---|
1018 | } |
---|
1019 | |
---|
1020 | /** |
---|
1021 | Category ID |
---|
1022 | @param attr <b>array</b> Attribute |
---|
1023 | @return <b>string</b> PHP block |
---|
1024 | */ |
---|
1025 | public static function ContributeCategoryID($attr) |
---|
1026 | { |
---|
1027 | return('<?php echo($_ctx->categories->cat_id); ?>'); |
---|
1028 | } |
---|
1029 | |
---|
1030 | /** |
---|
1031 | Category spacer |
---|
1032 | @param attr <b>array</b> Attribute |
---|
1033 | @return <b>string</b> PHP block |
---|
1034 | */ |
---|
1035 | public static function ContributeCategorySpacer($attr) |
---|
1036 | { |
---|
1037 | $string = ' '; |
---|
1038 | |
---|
1039 | if (isset($attr['string'])) {$string = $attr['string'];} |
---|
1040 | |
---|
1041 | return('<?php echo(str_repeat(\''.$string.'\','. |
---|
1042 | '$_ctx->categories->level-1)); ?>'); |
---|
1043 | } |
---|
1044 | |
---|
1045 | /** |
---|
1046 | Filter to display only unselected tags |
---|
1047 | @param attr <b>array</b> Attribute |
---|
1048 | @param content <b>string</b> Content |
---|
1049 | @return <b>string</b> PHP block |
---|
1050 | */ |
---|
1051 | public static function ContributeEntryTagsFilter($attr,$content) |
---|
1052 | { |
---|
1053 | return |
---|
1054 | '<?php '. |
---|
1055 | 'if (!in_array($_ctx->meta->meta_id,$_ctx->contribute->selected_tags)) : ?>'."\n". |
---|
1056 | $content."\n". |
---|
1057 | '<?php endif; ?>'; |
---|
1058 | } |
---|
1059 | |
---|
1060 | /** |
---|
1061 | Loop on My Meta values |
---|
1062 | @param attr <b>array</b> Attribute |
---|
1063 | @param content <b>string</b> Content |
---|
1064 | @return <b>string</b> PHP block |
---|
1065 | */ |
---|
1066 | public static function ContributeEntryMyMeta($attr,$content) |
---|
1067 | { |
---|
1068 | return |
---|
1069 | '<?php '. |
---|
1070 | # initialize for <tpl:LoopPosition> |
---|
1071 | '$_ctx->mymeta = contribute::getMyMeta($_ctx->contribute->mymeta);'. |
---|
1072 | 'while ($_ctx->mymeta->fetch()) : ?>'."\n". |
---|
1073 | $content."\n". |
---|
1074 | '<?php endwhile; ?>'; |
---|
1075 | } |
---|
1076 | |
---|
1077 | /** |
---|
1078 | test on My Meta values |
---|
1079 | @param attr <b>array</b> Attribute |
---|
1080 | @param content <b>string</b> Content |
---|
1081 | @return <b>string</b> PHP block |
---|
1082 | */ |
---|
1083 | public static function ContributeEntryMyMetaIf($attr,$content) |
---|
1084 | { |
---|
1085 | $if = array(); |
---|
1086 | $operator = '&&'; |
---|
1087 | |
---|
1088 | if (isset($attr['type'])) |
---|
1089 | { |
---|
1090 | $if[] = '$_ctx->mymeta->type === \''.$attr['type'].'\''; |
---|
1091 | } |
---|
1092 | |
---|
1093 | if (!empty($if)) { |
---|
1094 | return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'. |
---|
1095 | $content."\n". |
---|
1096 | '<?php endif; ?>'; |
---|
1097 | } else { |
---|
1098 | return $content; |
---|
1099 | } |
---|
1100 | } |
---|
1101 | |
---|
1102 | /** |
---|
1103 | My Meta ID |
---|
1104 | @param attr <b>array</b> Attribute |
---|
1105 | @return <b>string</b> PHP block |
---|
1106 | */ |
---|
1107 | public static function ContributeEntryMyMetaID($attr) |
---|
1108 | { |
---|
1109 | return('<?php echo($_ctx->mymeta->id); ?>'); |
---|
1110 | } |
---|
1111 | |
---|
1112 | /** |
---|
1113 | My Meta Prompt |
---|
1114 | @param attr <b>array</b> Attribute |
---|
1115 | @return <b>string</b> PHP block |
---|
1116 | */ |
---|
1117 | public static function ContributeEntryMyMetaPrompt($attr) |
---|
1118 | { |
---|
1119 | return('<?php echo($_ctx->mymeta->prompt); ?>'); |
---|
1120 | } |
---|
1121 | |
---|
1122 | /** |
---|
1123 | My Meta value |
---|
1124 | @param attr <b>array</b> Attribute |
---|
1125 | @return <b>string</b> PHP block |
---|
1126 | */ |
---|
1127 | public static function ContributeEntryMyMetaValue($attr) |
---|
1128 | { |
---|
1129 | return('<?php '. |
---|
1130 | 'if (isset($_ctx->posts->mymeta[$_ctx->mymeta->id])) :'. |
---|
1131 | 'echo($_ctx->posts->mymeta[$_ctx->mymeta->id]);'. |
---|
1132 | 'endif; ?>'); |
---|
1133 | } |
---|
1134 | |
---|
1135 | /** |
---|
1136 | My Meta values |
---|
1137 | @param attr <b>array</b> Attribute |
---|
1138 | @return <b>string</b> PHP block |
---|
1139 | */ |
---|
1140 | public static function ContributeEntryMyMetaValues($attr,$content) |
---|
1141 | { |
---|
1142 | return |
---|
1143 | '<?php '. |
---|
1144 | # initialize for <tpl:LoopPosition> |
---|
1145 | '$_ctx->mymetavalues = contribute::getMyMetaValues($_ctx->mymeta->values);'. |
---|
1146 | 'while ($_ctx->mymetavalues->fetch()) : ?>'."\n". |
---|
1147 | $content."\n". |
---|
1148 | '<?php endwhile; ?>'; |
---|
1149 | } |
---|
1150 | |
---|
1151 | /** |
---|
1152 | My Meta values : ID |
---|
1153 | @param attr <b>array</b> Attribute |
---|
1154 | @return <b>string</b> PHP block |
---|
1155 | */ |
---|
1156 | public static function ContributeEntryMyMetaValuesID($attr) |
---|
1157 | { |
---|
1158 | return('<?php echo($_ctx->mymetavalues->id); ?>'); |
---|
1159 | } |
---|
1160 | |
---|
1161 | /** |
---|
1162 | My Meta values : Description |
---|
1163 | @param attr <b>array</b> Attribute |
---|
1164 | @return <b>string</b> PHP block |
---|
1165 | */ |
---|
1166 | public static function ContributeEntryMyMetaValuesDescription($attr) |
---|
1167 | { |
---|
1168 | return('<?php echo($_ctx->mymetavalues->description); ?>'); |
---|
1169 | } |
---|
1170 | |
---|
1171 | /** |
---|
1172 | Entry notes |
---|
1173 | @param attr <b>array</b> Attribute |
---|
1174 | @return <b>string</b> PHP block |
---|
1175 | */ |
---|
1176 | public static function ContributeEntryNotes($attr) |
---|
1177 | { |
---|
1178 | return('<?php echo(html::escapeHTML($_ctx->posts->post_notes)); ?>'); |
---|
1179 | } |
---|
1180 | } |
---|
1181 | |
---|
1182 | $core->addBehavior('coreBlogGetPosts',array('contributeBehaviors', |
---|
1183 | 'coreBlogGetPosts')); |
---|
1184 | |
---|
1185 | /** |
---|
1186 | @ingroup Contribute |
---|
1187 | @brief Behaviors |
---|
1188 | @see planet/public.php |
---|
1189 | */ |
---|
1190 | class contributeBehaviors |
---|
1191 | { |
---|
1192 | public static function coreBlogGetPosts(&$rs) |
---|
1193 | { |
---|
1194 | if (!$GLOBALS['core']->blog->settings->contribute_active) {return;} |
---|
1195 | $rs->extend('rsExtContributePosts'); |
---|
1196 | } |
---|
1197 | } |
---|
1198 | |
---|
1199 | /** |
---|
1200 | @ingroup Contribute |
---|
1201 | @brief Extend posts |
---|
1202 | |
---|
1203 | EntryAuthorDisplayName and EntryAuthorURL can't be modified |
---|
1204 | |
---|
1205 | @see planet/public.php |
---|
1206 | */ |
---|
1207 | class rsExtContributePosts extends rsExtPostPublic |
---|
1208 | { |
---|
1209 | /** |
---|
1210 | Get metadata of Contribute |
---|
1211 | @param rs <b>recordset</b> Recordset |
---|
1212 | @param info <b>str</b> Information |
---|
1213 | @return <b>string</b> Value |
---|
1214 | */ |
---|
1215 | public static function contributeInfo(&$rs,$info) |
---|
1216 | { |
---|
1217 | $rs = dcMeta::getMetaRecord($rs->core,$rs->post_meta,'contribute_'.$info); |
---|
1218 | if (!$rs->isEmpty()) |
---|
1219 | { |
---|
1220 | return $rs->meta_id; |
---|
1221 | } |
---|
1222 | # else |
---|
1223 | return; |
---|
1224 | } |
---|
1225 | |
---|
1226 | /** |
---|
1227 | getAuthorLink |
---|
1228 | @param rs <b>recordset</b> Recordset |
---|
1229 | @return <b>string</b> String |
---|
1230 | */ |
---|
1231 | public static function getAuthorLink(&$rs) |
---|
1232 | { |
---|
1233 | $author = $rs->contributeInfo('author'); |
---|
1234 | $site = $rs->contributeInfo('site'); |
---|
1235 | |
---|
1236 | # default display |
---|
1237 | if (empty($author)) |
---|
1238 | { |
---|
1239 | return(parent::getAuthorLink($rs)); |
---|
1240 | } |
---|
1241 | else |
---|
1242 | { |
---|
1243 | $author_format = |
---|
1244 | $GLOBALS['core']->blog->settings->contribute_author_format; |
---|
1245 | |
---|
1246 | if (empty($author_format)) {$author_format = '%s';} |
---|
1247 | |
---|
1248 | if (!empty($site)) |
---|
1249 | { |
---|
1250 | $str = sprintf($author_format,'<a href="'.$site.'">'.$author.'</a>'); |
---|
1251 | } |
---|
1252 | else |
---|
1253 | { |
---|
1254 | $str = sprintf($author_format,$author); |
---|
1255 | } |
---|
1256 | return $str; |
---|
1257 | } |
---|
1258 | } |
---|
1259 | |
---|
1260 | /** |
---|
1261 | getAuthorCN |
---|
1262 | @param rs <b>recordset</b> Recordset |
---|
1263 | @return <b>string</b> String |
---|
1264 | */ |
---|
1265 | public static function getAuthorCN(&$rs) |
---|
1266 | { |
---|
1267 | $author = $rs->contributeInfo('author'); |
---|
1268 | if (empty($author)) |
---|
1269 | { |
---|
1270 | # default display |
---|
1271 | return(parent::getAuthorCN($rs)); |
---|
1272 | } else { |
---|
1273 | $author_format = $GLOBALS['core']->blog->settings->contribute_author_format; |
---|
1274 | |
---|
1275 | if (empty($author_format)) {$author_format = '%s';} |
---|
1276 | |
---|
1277 | return sprintf($author_format,$author); |
---|
1278 | } |
---|
1279 | } |
---|
1280 | |
---|
1281 | /** |
---|
1282 | getAuthorEmail |
---|
1283 | @param rs <b>recordset</b> Recordset |
---|
1284 | @param encoded <b>boolean</b> Return encoded email address ? |
---|
1285 | @return <b>string</b> String |
---|
1286 | */ |
---|
1287 | public static function getAuthorEmail(&$rs,$encoded=true) |
---|
1288 | { |
---|
1289 | $mail = $rs->contributeInfo('mail'); |
---|
1290 | if (empty($mail)) |
---|
1291 | { |
---|
1292 | # default display |
---|
1293 | return(parent::getAuthorEmail($rs,$encoded)); |
---|
1294 | } else { |
---|
1295 | if ($encoded) { |
---|
1296 | return strtr($mail,array('@'=>'%40','.'=>'%2e')); |
---|
1297 | } |
---|
1298 | # else |
---|
1299 | return $email; |
---|
1300 | } |
---|
1301 | } |
---|
1302 | |
---|
1303 | /** |
---|
1304 | getAuthorURL |
---|
1305 | @param rs <b>recordset</b> Recordset |
---|
1306 | @return <b>string</b> String |
---|
1307 | */ |
---|
1308 | public static function getAuthorURL(&$rs) |
---|
1309 | { |
---|
1310 | $mail = $rs->contributeInfo('site'); |
---|
1311 | if (empty($mail)) |
---|
1312 | { |
---|
1313 | # default display |
---|
1314 | return(parent::getAuthorEmail($rs,$encoded)); |
---|
1315 | } else { |
---|
1316 | if ($encoded) { |
---|
1317 | return strtr($mail,array('@'=>'%40','.'=>'%2e')); |
---|
1318 | } |
---|
1319 | # else |
---|
1320 | return $email; |
---|
1321 | } |
---|
1322 | } |
---|
1323 | } |
---|
1324 | ?> |
---|