Changeset 2176
- Timestamp:
- 04/11/10 14:48:21 (13 years ago)
- Location:
- plugins/contribute
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/contribute/_admin.php
r2172 r2176 109 109 $str = ''; 110 110 111 if (!empty($author) )111 if (!empty($author) OR !empty($mail) OR !empty($site)) 112 112 { 113 113 $str .= '<p>'. -
plugins/contribute/_define.php
r2172 r2176 28 28 /* Description*/ "Allow visitors to write an entry for your blog", 29 29 /* Author */ "Moe (http://gniark.net/)", 30 /* Version */ '1.0-alpha2 4',30 /* Version */ '1.0-alpha25', 31 31 /* Permissions */ 'admin' 32 32 ); -
plugins/contribute/_public.php
r1633 r2176 2 2 # ***** BEGIN LICENSE BLOCK ***** 3 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. 4 # This file is part of Contribute, a plugin for Dotclear 2 5 # Copyright (C) 2008,2009,2010 Moe (http://gniark.net/) 6 # 7 # Contribute is free software; you can redistribute it and/or 8 # modify it under the terms of the GNU General Public License v2.0 9 # as published by the Free Software Foundation. 11 10 # 12 11 # Contribute is distributed in the hope that it will be useful, 13 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 14 # GNU General Public License for more details. 16 15 # 17 16 # 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/ 17 # along with this program; if not, see <http://www.gnu.org/licenses/>. 18 # 19 # Icon (icon.png) is from Silk Icons : 20 # <http://www.famfamfam.com/lab/icons/silk/> 21 21 # 22 22 # ***** END LICENSE BLOCK ***** … … 26 26 l10n::set(dirname(__FILE__).'/locales/'.$_lang.'/public'); 27 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 28 # template tags 29 require_once(dirname(__FILE__).'/inc/lib.contribute.tpl.php'); 30 688 31 $core->tpl->addValue('ContributeMessage', 689 32 array('contributeTpl','ContributeMessage')); … … 748 91 $core->tpl->addValue('ContributeEntryNotes', 749 92 array('contributeTpl','ContributeEntryNotes')); 750 751 /**752 @ingroup Contribute753 @brief Template754 */755 class contributeTpl756 {757 /**758 display a message759 @return <b>string</b> PHP block760 */761 public static function ContributeMessage()762 {763 return('<?php echo($_ctx->contribute->message); ?>');764 }765 766 /**767 display the help768 @return <b>string</b> PHP block769 */770 public static function ContributeHelp()771 {772 return('<?php echo($_ctx->contribute->help); ?>');773 }774 775 /**776 display preview777 @param attr <b>array</b> Attribute778 @param content <b>string</b> Content779 @return <b>string</b> PHP block780 */781 public static function ContributePreview($attr,$content)782 {783 return784 '<?php if ($_ctx->contribute->preview) : ?>'."\n".785 $content."\n".786 '<?php endif; ?>';787 }788 789 /**790 display form791 @param attr <b>array</b> Attribute792 @param content <b>string</b> Content793 @return <b>string</b> PHP block794 */795 public static function ContributeForm($attr,$content)796 {797 return798 '<?php if ($_ctx->contribute->form) : ?>'."\n".799 $content."\n".800 '<?php endif; ?>';801 }802 803 /**804 if805 @param attr <b>array</b> Attribute806 @param content <b>string</b> Content807 @return <b>string</b> PHP block808 809 we can't use <tpl:ContributeIf> in another <tpl:ContributeIf> block yet810 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 else841 {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 operator902 @param op <b>string</b> Operator903 @return <b>string</b> Operator904 \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 required922 @param attr <b>array</b> Attribute923 @param content <b>string</b> Content924 @return <b>string</b> PHP block925 */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 selected938 @param attr <b>array</b> Attribute939 @param content <b>string</b> Content940 @return <b>string</b> PHP block941 */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 Formaters974 @param attr <b>array</b> Attribute975 @param content <b>string</b> Content976 @return <b>string</b> PHP block977 */978 public static function ContributeFormaters($attr,$content)979 {980 return981 '<?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 Format991 @param attr <b>array</b> Attribute992 @param content <b>string</b> Content993 @return <b>string</b> PHP block994 */995 public static function ContributeFormat($attr,$content)996 {997 return('<?php echo(html::escapeHTML($_ctx->formaters->format)); ?>');998 }999 1000 /**1001 Entry Excerpt1002 @param attr <b>array</b> Attribute1003 @return <b>string</b> PHP block1004 */1005 public static function ContributeEntryExcerpt($attr)1006 {1007 return('<?php echo(html::escapeHTML($_ctx->posts->post_excerpt)); ?>');1008 }1009 1010 /**1011 Entry Content1012 @param attr <b>array</b> Attribute1013 @return <b>string</b> PHP block1014 */1015 public static function ContributeEntryContent($attr)1016 {1017 return('<?php echo(html::escapeHTML($_ctx->posts->post_content)); ?>');1018 }1019 1020 /**1021 Category ID1022 @param attr <b>array</b> Attribute1023 @return <b>string</b> PHP block1024 */1025 public static function ContributeCategoryID($attr)1026 {1027 return('<?php echo($_ctx->categories->cat_id); ?>');1028 }1029 1030 /**1031 Category spacer1032 @param attr <b>array</b> Attribute1033 @return <b>string</b> PHP block1034 */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 tags1047 @param attr <b>array</b> Attribute1048 @param content <b>string</b> Content1049 @return <b>string</b> PHP block1050 */1051 public static function ContributeEntryTagsFilter($attr,$content)1052 {1053 return1054 '<?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 values1062 @param attr <b>array</b> Attribute1063 @param content <b>string</b> Content1064 @return <b>string</b> PHP block1065 */1066 public static function ContributeEntryMyMeta($attr,$content)1067 {1068 return1069 '<?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 values1079 @param attr <b>array</b> Attribute1080 @param content <b>string</b> Content1081 @return <b>string</b> PHP block1082 */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 ID1104 @param attr <b>array</b> Attribute1105 @return <b>string</b> PHP block1106 */1107 public static function ContributeEntryMyMetaID($attr)1108 {1109 return('<?php echo($_ctx->mymeta->id); ?>');1110 }1111 1112 /**1113 My Meta Prompt1114 @param attr <b>array</b> Attribute1115 @return <b>string</b> PHP block1116 */1117 public static function ContributeEntryMyMetaPrompt($attr)1118 {1119 return('<?php echo($_ctx->mymeta->prompt); ?>');1120 }1121 1122 /**1123 My Meta value1124 @param attr <b>array</b> Attribute1125 @return <b>string</b> PHP block1126 */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 values1137 @param attr <b>array</b> Attribute1138 @return <b>string</b> PHP block1139 */1140 public static function ContributeEntryMyMetaValues($attr,$content)1141 {1142 return1143 '<?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 : ID1153 @param attr <b>array</b> Attribute1154 @return <b>string</b> PHP block1155 */1156 public static function ContributeEntryMyMetaValuesID($attr)1157 {1158 return('<?php echo($_ctx->mymetavalues->id); ?>');1159 }1160 1161 /**1162 My Meta values : Description1163 @param attr <b>array</b> Attribute1164 @return <b>string</b> PHP block1165 */1166 public static function ContributeEntryMyMetaValuesDescription($attr)1167 {1168 return('<?php echo($_ctx->mymetavalues->description); ?>');1169 }1170 1171 /**1172 Entry notes1173 @param attr <b>array</b> Attribute1174 @return <b>string</b> PHP block1175 */1176 public static function ContributeEntryNotes($attr)1177 {1178 return('<?php echo(html::escapeHTML($_ctx->posts->post_notes)); ?>');1179 }1180 }1181 93 1182 94 $core->addBehavior('coreBlogGetPosts',array('contributeBehaviors', -
plugins/contribute/inc/lib.contribute.document.php
r2172 r2176 57 57 } 58 58 59 $disabled_plugins = $core->plugins->getDisabledModules(); 60 59 61 $_ctx =& $GLOBALS['_ctx']; 60 62 … … 69 71 70 72 # Metadata 71 if ($core->plugins->moduleExists('metadata')) 73 if ($core->plugins->moduleExists('metadata') 74 && !array_key_exists('metadata',$disabled_plugins)) 72 75 { 73 76 $meta = new dcMeta($core); … … 80 83 # My Meta 81 84 if ($core->plugins->moduleExists('mymeta') 82 && ($settings->contribute_allow_mymeta)) 85 && ($settings->contribute_allow_mymeta) 86 && !array_key_exists('mymeta',$disabled_plugins)) 83 87 { 84 88 $mymeta_values = array(); … … 264 268 265 269 # avoid Notice: Indirect modification of overloaded property 266 # record::$post_excerpt has no effect in .../contribute/_public.php 267 # on line 146 268 $post_excerpt = $post->post_excerpt; 269 $post_excerpt_xhtml = $post->post_excerpt_xhtml; 270 $post_content = $post->post_content; 271 $post_content_xhtml = $post->post_content_xhtml; 272 273 # HTML filter 274 # get the setting value 275 $enable_html_filter = $settings->enable_html_filter; 276 # set the setting to true 277 $settings->enable_html_filter = true; 270 # record::$post_excerpt has no effect in [this file] 271 # on line [...] 272 273 # filter to remove JavaScript 274 $post_excerpt = contribute::HTMLfilter($post->post_excerpt); 275 $post_excerpt_xhtml = contribute::HTMLfilter($post->post_excerpt_xhtml); 276 $post_content = contribute::HTMLfilter($post->post_content); 277 $post_content_xhtml = contribute::HTMLfilter($post->post_content_xhtml); 278 278 279 279 $core->blog->setPostContent( … … 282 282 $post_content,$post_content_xhtml 283 283 ); 284 285 # set the old value to the setting286 $settings->enable_html_filter = $enable_html_filter;287 unset($enable_html_filter);288 284 289 285 $post->post_excerpt = $post_excerpt; … … 398 394 && (isset($_POST['post_notes']))) 399 395 { 400 $post->post_notes = $_POST['post_notes'];396 $post->post_notes = contribute::HTMLfilter($_POST['post_notes']); 401 397 } 402 398 … … 492 488 # antispam 493 489 if ($settings->contribute_enable_antispam 494 && $core->plugins->moduleExists('antispam')) 490 && $core->plugins->moduleExists('antispam') 491 && !array_key_exists('antispam',$disabled_plugins)) 495 492 { 496 493 $cur = $core->con->openCursor($core->prefix.'comment'); -
plugins/contribute/inc/lib.contribute.php
r2172 r2176 136 136 return(staticRecord::newFromArray($array)); 137 137 } 138 139 /** 140 filter HTML 141 @param str <b>string</b> String to filter 142 @return <b>string</b> Filtered string 143 \see /dotclear/inc/core/class.dc.core.php 144 */ 145 public static function HTMLfilter($str) 146 { 147 $filter = new htmlFilter; 148 $str = trim($filter->apply($str)); 149 return $str; 150 } 138 151 } 139 152
Note: See TracChangeset
for help on using the changeset viewer.