Changeset 1107:3943962d69b8 for inc/core
- Timestamp:
- 02/27/13 11:48:32 (13 years ago)
- Branch:
- sexy
- Parents:
- 880:02c78f56f430 (diff), 1105:ce855d61f9ce (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- inc/core
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.blog.php
r877 r1107 168 168 } 169 169 170 171 170 172 /// @name Entries management methods 171 173 //@{ … … 696 698 public function updPostStatus($id,$status) 697 699 { 700 $this->updPostsStatus($id,$status); 701 } 702 703 /** 704 Updates posts status. 705 706 @param ids <b>mixed</b> Post(s) ID(s) 707 @param status <b>integer</b> Post status 708 */ 709 public function updPostsStatus($ids,$status) 710 { 698 711 if (!$this->core->auth->check('publish,contentadmin',$this->id)) { 699 712 throw new Exception(__('You are not allowed to change this entry status')); 700 713 } 701 714 702 $ id = (integer) $id;715 $posts_ids = dcUtils::cleanIds($ids); 703 716 $status = (integer) $status; 717 718 $strReq = "WHERE blog_id = '".$this->con->escape($this->id)."' ". 719 "AND post_id ".$this->con->in($posts_ids); 704 720 705 721 #If user can only publish, we need to check the post's owner 706 722 if (!$this->core->auth->check('contentadmin',$this->id)) 707 723 { 708 $strReq = 'SELECT post_id '. 709 'FROM '.$this->prefix.'post '. 710 'WHERE post_id = '.$id.' '. 711 "AND blog_id = '".$this->con->escape($this->id)."' ". 712 "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 713 714 $posts = $this->con->select($strReq); 715 716 if (count($posts) == 0) { 717 throw new Exception(__('You are not allowed to change this entry status')); 718 } 724 $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 719 725 } 720 726 … … 724 730 $cur->post_upddt = date('Y-m-d H:i:s'); 725 731 726 $cur->update( 727 'WHERE post_id = '.$id.' '. 728 "AND blog_id = '".$this->con->escape($this->id)."' " 729 ); 732 $cur->update($strReq); 730 733 $this->triggerBlog(); 731 734 } 732 735 736 /** 737 Updates post selection. 738 739 @param id <b>integer</b> Post ID 740 @param selected <b>integer</b> Is selected post 741 */ 733 742 public function updPostSelected($id,$selected) 734 743 { 735 $id = (integer) $id; 744 $this->updPostsSelected($id,$selected); 745 } 746 747 /** 748 Updates posts selection. 749 750 @param ids <b>mixed</b> Post(s) ID(s) 751 @param selected <b>integer</b> Is selected post(s) 752 */ 753 public function updPostsSelected($ids,$selected) 754 { 755 $posts_ids = dcUtils::cleanIds($ids); 736 756 $selected = (boolean) $selected; 757 758 $strReq = "WHERE blog_id = '".$this->con->escape($this->id)."' ". 759 "AND post_id ".$this->con->in($posts_ids); 737 760 738 761 # If user is only usage, we need to check the post's owner 739 762 if (!$this->core->auth->check('contentadmin',$this->id)) 740 763 { 741 $strReq = 'SELECT post_id '. 742 'FROM '.$this->prefix.'post '. 743 'WHERE post_id = '.$id.' '. 744 "AND blog_id = '".$this->con->escape($this->id)."' ". 745 "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 746 747 $posts = $this->con->select($strReq); 748 749 if (count($posts) == 0) { 750 throw new Exception(__('You are not allowed to mark this entry as selected')); 751 } 764 $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 752 765 } 753 766 … … 757 770 $cur->post_upddt = date('Y-m-d H:i:s'); 758 771 759 $cur->update( 760 'WHERE post_id = '.$id.' '. 761 "AND blog_id = '".$this->con->escape($this->id)."' " 762 ); 772 $cur->update($strReq); 763 773 $this->triggerBlog(); 764 774 } … … 770 780 */ 771 781 public function delPost($id) 782 { 783 $this->delPosts($id); 784 } 785 786 /** 787 Deletes multiple posts. 788 789 @param ids <b>mixed</b> Post(s) ID(s) 790 */ 791 public function delPosts($ids) 772 792 { 773 793 if (!$this->core->auth->check('delete,contentadmin',$this->id)) { … … 775 795 } 776 796 777 $ id = (integer) $id;778 779 if (empty($ id)) {797 $posts_ids = dcUtils::cleanIds($ids); 798 799 if (empty($posts_ids)) { 780 800 throw new Exception(__('No such entry ID')); 781 801 } 802 803 $strReq = 'DELETE FROM '.$this->prefix.'post '. 804 "WHERE blog_id = '".$this->con->escape($this->id)."' ". 805 "AND post_id ".$this->con->in($posts_ids); 782 806 783 807 #If user can only delete, we need to check the post's owner 784 808 if (!$this->core->auth->check('contentadmin',$this->id)) 785 809 { 786 $strReq = 'SELECT post_id '. 787 'FROM '.$this->prefix.'post '. 788 'WHERE post_id = '.$id.' '. 789 "AND blog_id = '".$this->con->escape($this->id)."' ". 790 "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 791 792 $posts = $this->con->select($strReq); 793 794 if (count($posts) == 0) { 795 throw new Exception(__('You are not allowed to delete this entry')); 796 } 797 } 798 799 800 $strReq = 'DELETE FROM '.$this->prefix.'post '. 801 'WHERE post_id = '.$id.' '. 802 "AND blog_id = '".$this->con->escape($this->id)."' "; 810 $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 811 } 803 812 804 813 $this->con->execute($strReq); … … 951 960 $this->core->initWikiPost(); 952 961 $this->core->wiki2xhtml->setOpt('note_prefix','pnote-'.$post_id); 962 switch ($this->settings->system->note_title_tag) { 963 case 1: 964 $tag = 'h3'; 965 break; 966 case 2: 967 $tag = 'p'; 968 break; 969 default: 970 $tag = 'h4'; 971 break; 972 } 973 $this->core->wiki2xhtml->setOpt('note_str','<div class="footnotes"><'.$tag.' class="footnotes-title">'. 974 __('Notes').'</'.$tag.'>%s</div>'); 975 $this->core->wiki2xhtml->setOpt('note_str_single','<div class="footnotes"><'.$tag.' class="footnotes-title">'. 976 __('Note').'</'.$tag.'>%s</div>'); 953 977 if (strpos($lang,'fr') === 0) { 954 978 $this->core->wiki2xhtml->setOpt('active_fr_syntax',1); … … 1067 1091 } 1068 1092 //@} 1093 1069 1094 } 1070 1095 ?> -
inc/core/class.dc.blog.php
r1052 r1107 55 55 56 56 private $post_status = array(); 57 private $comment_status = array();58 59 private $categories;60 57 61 58 /** @var boolean Disallow entries password protection */ … … 95 92 $this->post_status['0'] = __('unpublished'); 96 93 $this->post_status['1'] = __('published'); 97 98 $this->comment_status['-2'] = __('junk'); 99 $this->comment_status['-1'] = __('pending'); 100 $this->comment_status['0'] = __('unpublished'); 101 $this->comment_status['1'] = __('published'); 102 94 103 95 # --BEHAVIOR-- coreBlogConstruct 104 96 $this->core->callBehavior('coreBlogConstruct',$this); … … 145 137 } 146 138 147 /**148 Returns an array of available comment status codes and names.149 150 @return <b>array</b> Simple array with codes in keys and names in value151 */152 public function getAllCommentStatus()153 {154 return $this->comment_status;155 }156 139 157 140 /** … … 185 168 } 186 169 187 /** 188 Updates comment and trackback counters in post table. Should be called 189 every time a comment or trackback is added, removed or changed its status. 190 191 @param id <b>integer</b> Comment ID 192 @param del <b>boolean</b> If comment is delete, set this to true 193 */ 194 public function triggerComment($id,$del=false) 195 { 196 $this->triggerComments($id,$del); 197 } 198 199 /** 200 Updates comments and trackbacks counters in post table. Should be called 201 every time comments or trackbacks are added, removed or changed there status. 202 203 @param ids <b>mixed</b> Comment(s) ID(s) 204 @param del <b>boolean</b> If comment is delete, set this to true 205 */ 206 public function triggerComments($ids,$del=false) 207 { 208 $co_ids = dcUtils::cleanIds($ids); 209 210 # a) Retrieve posts affected by comments edition 211 $strReq = 212 'SELECT post_id, comment_trackback '. 213 'FROM '.$this->prefix.'comment '. 214 'WHERE comment_id'.$this->con->in($co_ids). 215 'GROUP BY post_id,comment_trackback'; 216 217 $rs = $this->con->select($strReq); 218 219 $a_ids = $a_tbs = array(); 220 while ($rs->fetch()) { 221 $a_ids[] = (integer) $rs->post_id; 222 $a_tbs[] = (integer) $rs->comment_trackback; 223 } 224 225 # b) Count comments of each posts previously retrieved 226 # Note that this does not return posts without comment 227 $strReq = 228 'SELECT post_id, COUNT(post_id) AS nb_comment,comment_trackback '. 229 'FROM '.$this->prefix.'comment '. 230 'WHERE post_id'.$this->con->in($a_ids). 231 'AND comment_status = 1 '; 232 233 if ($del) { 234 $strReq .= 235 'AND comment_id NOT'.$this->con->in($co_ids); 236 } 237 238 $strReq .= 239 'GROUP BY post_id,comment_trackback'; 240 241 $rs = $this->con->select($strReq); 242 243 $b_ids = $b_tbs = $b_nbs = array(); 244 while ($rs->fetch()) { 245 $b_ids[] = (integer) $rs->post_id; 246 $b_tbs[] = (integer) $rs->comment_trackback; 247 $b_nbs[] = (integer) $rs->nb_comment; 248 } 249 250 # c) Update comments numbers on posts 251 # This compare previous requests to update also posts without comment 252 $cur = $this->con->openCursor($this->prefix.'post'); 253 254 foreach($a_ids as $a_key => $a_id) 255 { 256 $nb_comment = $nb_trackback = 0; 257 foreach($b_ids as $b_key => $b_id) 258 { 259 if ($a_id != $b_id || $a_tbs[$a_key] != $b_tbs[$b_key]) { 260 continue; 261 } 262 263 if ($b_tbs[$b_key]) { 264 $nb_trackback = $b_nbs[$b_key]; 265 } else { 266 $nb_comment = $b_nbs[$b_key]; 267 } 268 } 269 270 if ($a_tbs[$a_key]) { 271 $cur->nb_trackback = $nb_trackback; 272 } else { 273 $cur->nb_comment = $nb_comment; 274 } 275 $cur->update('WHERE post_id = '.$a_id); 276 } 277 } 278 //@} 279 280 /// @name Categories management methods 281 //@{ 282 public function categories() 283 { 284 if (!($this->categories instanceof dcCategories)) { 285 $this->categories = new dcCategories($this->core); 286 } 287 288 return $this->categories; 289 } 290 291 /** 292 Retrieves categories. <var>$params</var> is an associative array which can 293 take the following parameters: 294 295 - post_type: Get only entries with given type (default "post") 296 - cat_url: filter on cat_url field 297 - cat_id: filter on cat_id field 298 - start: start with a given category 299 - level: categories level to retrieve 300 301 @param params <b>array</b> Parameters 302 @return <b>record</b> 303 */ 304 public function getCategories($params=array()) 305 { 306 $c_params = array(); 307 if (isset($params['post_type'])) { 308 $c_params['post_type'] = $params['post_type']; 309 unset($params['post_type']); 310 } 311 $counter = $this->getCategoriesCounter($c_params); 312 313 $without_empty = $this->core->auth->userID() == false; # For public display 314 315 $start = isset($params['start']) ? (integer) $params['start'] : 0; 316 $l = isset($params['level']) ? (integer) $params['level'] : 0; 317 318 $rs = $this->categories()->getChildren($start,null,'desc'); 319 320 # Get each categories total posts count 321 $data = array(); 322 $stack = array(); 323 $level = 0; 324 $cols = $rs->columns(); 325 while ($rs->fetch()) 326 { 327 $nb_post = isset($counter[$rs->cat_id]) ? (integer) $counter[$rs->cat_id] : 0; 328 329 if ($rs->level > $level) { 330 $nb_total = $nb_post; 331 $stack[$rs->level] = (integer) $nb_post; 332 } elseif ($rs->level == $level) { 333 $nb_total = $nb_post; 334 $stack[$rs->level] += $nb_post; 335 } else { 336 $nb_total = $stack[$rs->level+1] + $nb_post; 337 if (isset($stack[$rs->level])) { 338 $stack[$rs->level] += $nb_total; 339 } else { 340 $stack[$rs->level] = $nb_total; 341 } 342 unset($stack[$rs->level+1]); 343 } 344 345 if ($nb_total == 0 && $without_empty) { 346 continue; 347 } 348 349 $level = $rs->level; 350 351 $t = array(); 352 foreach ($cols as $c) { 353 $t[$c] = $rs->f($c); 354 } 355 $t['nb_post'] = $nb_post; 356 $t['nb_total'] = $nb_total; 357 358 if ($l == 0 || ($l > 0 && $l == $rs->level)) { 359 array_unshift($data,$t); 360 } 361 } 362 363 # We need to apply filter after counting 364 if (isset($params['cat_id']) && $params['cat_id'] !== '') 365 { 366 $found = false; 367 foreach ($data as $v) { 368 if ($v['cat_id'] == $params['cat_id']) { 369 $found = true; 370 $data = array($v); 371 break; 372 } 373 } 374 if (!$found) { 375 $data = array(); 376 } 377 } 378 379 if (isset($params['cat_url']) && ($params['cat_url'] !== '') 380 && !isset($params['cat_id'])) 381 { 382 $found = false; 383 foreach ($data as $v) { 384 if ($v['cat_url'] == $params['cat_url']) { 385 $found = true; 386 $data = array($v); 387 break; 388 } 389 } 390 if (!$found) { 391 $data = array(); 392 } 393 } 394 395 return staticRecord::newFromArray($data); 396 } 397 398 /** 399 Retrieves a category by its ID. 400 401 @param id <b>integer</b> Category ID 402 @return <b>record</b> 403 */ 404 public function getCategory($id) 405 { 406 return $this->getCategories(array('cat_id' => $id)); 407 } 408 409 /** 410 Retrieves parents of a given category. 411 412 @param id <b>integer</b> Category ID 413 @return <b>record</b> 414 */ 415 public function getCategoryParents($id) 416 { 417 return $this->categories()->getParents($id); 418 } 419 420 /** 421 Retrieves first parent of a given category. 422 423 @param id <b>integer</b> Category ID 424 @return <b>record</b> 425 */ 426 public function getCategoryParent($id) 427 { 428 return $this->categories()->getParent($id); 429 } 430 431 /** 432 Retrieves all category's first children 433 434 @param id <b>integer</b> Category ID 435 @return <b>record</b> 436 */ 437 public function getCategoryFirstChildren($id) 438 { 439 return $this->getCategories(array('start' => $id,'level' => $id == 0 ? 1 : 2)); 440 } 441 442 private function getCategoriesCounter($params=array()) 443 { 444 $strReq = 445 'SELECT C.cat_id, COUNT(P.post_id) AS nb_post '. 446 'FROM '.$this->prefix.'category AS C '. 447 'JOIN '.$this->prefix."post P ON (C.cat_id = P.cat_id AND P.blog_id = '".$this->con->escape($this->id)."' ) ". 448 "WHERE C.blog_id = '".$this->con->escape($this->id)."' "; 449 450 if (!$this->core->auth->userID()) { 451 $strReq .= 'AND P.post_status = 1 '; 452 } 453 454 if (!empty($params['post_type'])) { 455 $strReq .= 'AND P.post_type '.$this->con->in($params['post_type']); 456 } 457 458 $strReq .= 'GROUP BY C.cat_id '; 459 460 $rs = $this->con->select($strReq); 461 $counters = array(); 462 while ($rs->fetch()) { 463 $counters[$rs->cat_id] = $rs->nb_post; 464 } 465 466 return $counters; 467 } 468 469 /** 470 Creates a new category. Takes a cursor as input and returns the new category 471 ID. 472 473 @param cur <b>cursor</b> Category cursor 474 @return <b>integer</b> New category ID 475 */ 476 public function addCategory($cur,$parent=0) 477 { 478 if (!$this->core->auth->check('categories',$this->id)) { 479 throw new Exception(__('You are not allowed to add categories')); 480 } 481 482 $url = array(); 483 if ($parent != 0) 484 { 485 $rs = $this->getCategory($parent); 486 if ($rs->isEmpty()) { 487 $url = array(); 488 } else { 489 $url[] = $rs->cat_url; 490 } 491 } 492 493 if ($cur->cat_url == '') { 494 $url[] = text::tidyURL($cur->cat_title,false); 495 } else { 496 $url[] = $cur->cat_url; 497 } 498 499 $cur->cat_url = implode('/',$url); 500 501 $this->getCategoryCursor($cur); 502 $cur->blog_id = (string) $this->id; 503 504 # --BEHAVIOR-- coreBeforeCategoryCreate 505 $this->core->callBehavior('coreBeforeCategoryCreate',$this,$cur); 506 507 $this->categories()->addNode($cur,$parent); 508 509 # --BEHAVIOR-- coreAfterCategoryCreate 510 $this->core->callBehavior('coreAfterCategoryCreate',$this,$cur); 511 $this->triggerBlog(); 512 513 return $cur->cat_id; 514 } 515 516 /** 517 Updates an existing category. 518 519 @param id <b>integer</b> Category ID 520 @param cur <b>cursor</b> Category cursor 521 */ 522 public function updCategory($id,$cur) 523 { 524 if (!$this->core->auth->check('categories',$this->id)) { 525 throw new Exception(__('You are not allowed to update categories')); 526 } 527 528 if ($cur->cat_url == '') 529 { 530 $url = array(); 531 $rs = $this->categories()->getParents($id); 532 while ($rs->fetch()) { 533 if ($rs->index() == $rs->count()-1) { 534 $url[] = $rs->cat_url; 535 } 536 } 537 538 539 $url[] = text::tidyURL($cur->cat_title,false); 540 $cur->cat_url = implode('/',$url); 541 } 542 543 $this->getCategoryCursor($cur,$id); 544 545 # --BEHAVIOR-- coreBeforeCategoryUpdate 546 $this->core->callBehavior('coreBeforeCategoryUpdate',$this,$cur); 547 548 $cur->update( 549 'WHERE cat_id = '.(integer) $id.' '. 550 "AND blog_id = '".$this->con->escape($this->id)."' "); 551 552 # --BEHAVIOR-- coreAfterCategoryUpdate 553 $this->core->callBehavior('coreAfterCategoryUpdate',$this,$cur); 554 555 $this->triggerBlog(); 556 } 557 558 /** 559 DEPRECATED METHOD. Use dcBlog::setCategoryParent and dcBlog::moveCategory 560 instead. 561 562 @param id <b>integer</b> Category ID 563 @param order <b>integer</b> Category position 564 */ 565 public function updCategoryOrder($id,$order) 566 { 567 return; 568 } 569 570 /** 571 Set a category parent 572 573 @param id <b>integer</b> Category ID 574 @param parent <b>integer</b> Parent Category ID 575 */ 576 public function setCategoryParent($id,$parent) 577 { 578 $this->categories()->setNodeParent($id,$parent); 579 $this->triggerBlog(); 580 } 581 582 /** 583 Set category position 584 585 @param id <b>integer</b> Category ID 586 @param sibling <b>integer</b> Sibling Category ID 587 @param move <b>integer</b> Order (before|after) 588 */ 589 public function setCategoryPosition($id,$sibling,$move) 590 { 591 $this->categories()->setNodePosition($id,$sibling,$move); 592 $this->triggerBlog(); 593 } 594 595 /** 596 Deletes a category. 597 598 @param id <b>integer</b> Category ID 599 */ 600 public function delCategory($id) 601 { 602 if (!$this->core->auth->check('categories',$this->id)) { 603 throw new Exception(__('You are not allowed to delete categories')); 604 } 605 606 $strReq = 'SELECT COUNT(post_id) AS nb_post '. 607 'FROM '.$this->prefix.'post '. 608 'WHERE cat_id = '.(integer) $id.' '. 609 "AND blog_id = '".$this->con->escape($this->id)."' "; 610 611 $rs = $this->con->select($strReq); 612 613 if ($rs->nb_post > 0) { 614 throw new Exception(__('This category is not empty.')); 615 } 616 617 $this->categories()->deleteNode($id,true); 618 $this->triggerBlog(); 619 } 620 621 /** 622 Reset categories order and relocate them to first level 623 */ 624 public function resetCategoriesOrder() 625 { 626 if (!$this->core->auth->check('categories',$this->id)) { 627 throw new Exception(__('You are not allowed to reset categories order')); 628 } 629 630 $this->categories()->resetOrder(); 631 $this->triggerBlog(); 632 } 633 634 private function checkCategory($title,$url,$id=null) 635 { 636 $strReq = 'SELECT cat_id '. 637 'FROM '.$this->prefix.'category '. 638 "WHERE cat_url = '".$this->con->escape($url)."' ". 639 "AND blog_id = '".$this->con->escape($this->id)."' "; 640 641 if ($id !== null) { 642 $strReq .= 'AND cat_id <> '.(integer) $id.' '; 643 } 644 645 $rs = $this->con->select($strReq); 646 647 if (!$rs->isEmpty()) { 648 throw new Exception(__('Category URL must be unique.')); 649 } 650 } 651 652 private function getCategoryCursor($cur,$id=null) 653 { 654 if ($cur->cat_title == '') { 655 throw new Exception(__('You must provide a category title')); 656 } 657 658 # If we don't have any cat_url, let's do one 659 if ($cur->cat_url == '') { 660 $cur->cat_url = text::tidyURL($cur->cat_title,false); 661 } 662 663 # Still empty ? 664 if ($cur->cat_url == '') { 665 throw new Exception(__('You must provide a category URL')); 666 } else { 667 $cur->cat_url = text::tidyURL($cur->cat_url,true); 668 } 669 670 # Check if title or url are unique 671 $this->checkCategory($cur->cat_title,$cur->cat_url,$id); 672 673 if ($cur->cat_desc !== null) { 674 $cur->cat_desc = $this->core->HTMLfilter($cur->cat_desc); 675 } 676 } 677 //@} 678 170 171 679 172 /// @name Entries management methods 680 173 //@{ … … 688 181 - post_url: Get entry with given post_url field 689 182 - user_id: (integer) Get entries belonging to given user ID 690 - cat_id: (string or array) Get entries belonging to given category ID691 - cat_id_not: deprecated (use cat_id with "id ?not" instead)692 - cat_url: (string or array) Get entries belonging to given category URL693 - cat_url_not: deprecated (use cat_url with "url ?not" instead)694 183 - post_status: (integer) Get entries with given post_status 695 184 - post_selected: (boolean) Get select flaged entries … … 706 195 - sql_only : return the sql request instead of results. Only ids are selected 707 196 708 Please note that on every cat_id or cat_url, you can add ?not to exclude709 the category and ?sub to get subcategories.710 711 197 @param params <b>array</b> Parameters 712 198 @param count_only <b>boolean</b> Only counts results … … 742 228 743 229 $strReq = 744 'SELECT P.post_id, P.blog_id, P.user_id, P.cat_id,post_dt, '.745 'post_tz, post_creadt, post_upddt, post_format, post_password,'.230 'SELECT P.post_id, P.blog_id, P.user_id, post_dt, '. 231 'post_tz, post_creadt, post_upddt, post_format, '. 746 232 'post_url, post_lang, post_title, '.$content_req. 747 233 'post_type, post_meta, post_status, post_selected, post_position, '. 748 'post_open_comment, post_open_tb, nb_comment, nb_trackback, '.749 234 'U.user_name, U.user_firstname, U.user_displayname, U.user_email, '. 750 'U.user_url, '. 751 'C.cat_title, C.cat_url, C.cat_desc '; 235 'U.user_url '; 752 236 } 753 237 754 238 $strReq .= 755 239 'FROM '.$this->prefix.'post P '. 756 'INNER JOIN '.$this->prefix.'user U ON U.user_id = P.user_id '. 757 'LEFT OUTER JOIN '.$this->prefix.'category C ON P.cat_id = C.cat_id '; 240 'INNER JOIN '.$this->prefix.'user U ON U.user_id = P.user_id '; 758 241 759 242 if (!empty($params['from'])) { … … 765 248 766 249 if (!$this->core->auth->check('contentadmin',$this->id)) { 767 $strReq .= 'AND ((post_status = 1 '; 768 769 if ($this->without_password) { 770 $strReq .= 'AND post_password IS NULL '; 771 } 772 $strReq .= ') '; 250 $strReq .= 'AND ((post_status = 1) '; 773 251 774 252 if ($this->core->auth->userID()) { … … 806 284 if (!empty($params['user_id'])) { 807 285 $strReq .= "AND U.user_id = '".$this->con->escape($params['user_id'])."' "; 808 }809 810 if (isset($params['cat_id']) && $params['cat_id'] !== '')811 {812 if (!is_array($params['cat_id'])) {813 $params['cat_id'] = array($params['cat_id']);814 }815 if (!empty($params['cat_id_not'])) {816 array_walk($params['cat_id'],create_function('&$v,$k','$v=$v." ?not";'));817 }818 $strReq .= 'AND '.$this->getPostsCategoryFilter($params['cat_id'],'cat_id').' ';819 }820 elseif (isset($params['cat_url']) && $params['cat_url'] !== '')821 {822 if (!is_array($params['cat_url'])) {823 $params['cat_url'] = array($params['cat_url']);824 }825 if (!empty($params['cat_url_not'])) {826 array_walk($params['cat_url'],create_function('&$v,$k','$v=$v." ?not";'));827 }828 $strReq .= 'AND '.$this->getPostsCategoryFilter($params['cat_url'],'cat_url').' ';829 286 } 830 287 … … 899 356 } 900 357 901 $rs = $this->con->select($strReq); 902 $rs->core = $this->core; 903 $rs->_nb_media = array(); 904 $rs->extend('rsExtPost'); 358 $posts = $this->con->select($strReq); 359 $posts->core = $this->core; 360 $posts->extend('rsExtPost'); 905 361 906 362 # --BEHAVIOR-- coreBlogGetPosts 907 $this->core->callBehavior('coreBlogGetPosts',$ rs);908 909 return $ rs;363 $this->core->callBehavior('coreBlogGetPosts',$posts); 364 365 return $posts; 910 366 } 911 367 … … 917 373 @param post_id <b>integer</b> Post ID 918 374 @param dir <b>integer</b> Search direction 919 @param restrict_to_category <b>boolean</b> Restrict to post with same category920 375 @param restrict_to_lang <b>boolean</b> Restrict to post with same lang 921 376 @return record 922 377 */ 923 public function getNextPost($post, $dir,$restrict_to_category=false, $restrict_to_lang=false)378 public function getNextPost($post, $dir, $restrict_to_lang=false) 924 379 { 925 380 $dt = $post->post_dt; … … 944 399 ') '; 945 400 946 if ($restrict_to_category) {947 $params['sql'] .= $post->cat_id ? 'AND P.cat_id = '.(integer) $post->cat_id.' ' : 'AND P.cat_id IS NULL ';948 }949 950 401 if ($restrict_to_lang) { 951 402 $params['sql'] .= $post->post_lang ? 'AND P.post_lang = \''. $this->con->escape($post->post_lang) .'\' ': 'AND P.post_lang IS NULL '; 952 403 } 953 404 954 $ rs = $this->getPosts($params);955 956 if ( $rs->isEmpty()) {405 $posts = $this->getPosts($params); 406 407 if (count($posts) == 0) { 957 408 return null; 958 409 } 959 410 960 return $ rs;411 return $posts; 961 412 } 962 413 … … 982 433 983 434 if (!$this->core->auth->check('contentadmin',$this->id)) { 984 $strReq .= 'AND ((post_status = 1 '; 985 986 if ($this->without_password) { 987 $strReq .= 'AND post_password IS NULL '; 988 } 989 $strReq .= ') '; 435 $strReq .= 'AND ((post_status = 1) '; 990 436 991 437 if ($this->core->auth->userID()) { … … 1027 473 - month: (integer) Get dates for given month 1028 474 - day: (integer) Get dates for given day 1029 - cat_id: (integer) Category ID filter1030 - cat_url: Category URL filter1031 475 - post_lang: lang of the posts 1032 476 - next: Get date following match … … 1055 499 $cat_field = $catReq = $limit = ''; 1056 500 1057 if (isset($params['cat_id']) && $params['cat_id'] !== '') {1058 $catReq = 'AND P.cat_id = '.(integer) $params['cat_id'].' ';1059 $cat_field = ', C.cat_url ';1060 } elseif (isset($params['cat_url']) && $params['cat_url'] !== '') {1061 $catReq = "AND C.cat_url = '".$this->con->escape($params['cat_url'])."' ";1062 $cat_field = ', C.cat_url ';1063 }1064 501 if (!empty($params['post_lang'])) { 1065 502 $catReq = 'AND P.post_lang = \''. $params['post_lang'].'\' '; … … 1067 504 1068 505 $strReq = 'SELECT DISTINCT('.$this->con->dateFormat('post_dt',$dt_f).') AS dt '. 1069 $cat_field.1070 506 ',COUNT(P.post_id) AS nb_post '. 1071 'FROM '.$this->prefix.'post P LEFT JOIN '.$this->prefix.'category C '. 1072 'ON P.cat_id = C.cat_id '. 507 'FROM '.$this->prefix.'post P '. 1073 508 "WHERE P.blog_id = '".$this->con->escape($this->id)."' ". 1074 509 $catReq; 1075 510 1076 511 if (!$this->core->auth->check('contentadmin',$this->id)) { 1077 $strReq .= 'AND ((post_status = 1 '; 1078 1079 if ($this->without_password) { 1080 $strReq .= 'AND post_password IS NULL '; 1081 } 1082 $strReq .= ') '; 512 $strReq .= 'AND ((post_status = 1) '; 1083 513 1084 514 if ($this->core->auth->userID()) { … … 1126 556 } 1127 557 1128 $strReq .= 'GROUP BY dt '.$cat_field;1129 1130 558 $order = 'desc'; 1131 559 if (!empty($params['order']) && preg_match('/^(desc|asc)$/i',$params['order'])) { … … 1137 565 $limit; 1138 566 1139 $ rs = $this->con->select($strReq);1140 $ rs->extend('rsExtDates');1141 return $ rs;567 $dates = $this->con->select($strReq); 568 $dates->extend('rsExtDates'); 569 return $dates; 1142 570 } 1143 571 … … 1159 587 { 1160 588 # Get ID 1161 $ rs= $this->con->select(589 $max = $this->con->select( 1162 590 'SELECT MAX(post_id) '. 1163 591 'FROM '.$this->prefix.'post ' 1164 592 ); 1165 593 1166 $cur->post_id = (integer) $rs->f(0) + 1; 594 $max = $max->current(); 595 596 $cur->post_id = (integer) $max->f(0) + 1; 1167 597 $cur->blog_id = (string) $this->id; 1168 598 $cur->post_creadt = date('Y-m-d H:i:s'); … … 1242 672 "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 1243 673 1244 $ rs = $this->con->select($strReq);1245 1246 if ( $rs->isEmpty()) {674 $posts = $this->con->select($strReq); 675 676 if (count($posts) == 0) { 1247 677 throw new Exception(__('You are not allowed to edit this entry')); 1248 678 } … … 1323 753 public function updPostsSelected($ids,$selected) 1324 754 { 1325 if (!$this->core->auth->check('usage,contentadmin',$this->id)) {1326 throw new Exception(__('You are not allowed to change this entry category'));1327 }1328 1329 755 $posts_ids = dcUtils::cleanIds($ids); 1330 756 $selected = (boolean) $selected; … … 1345 771 1346 772 $cur->update($strReq); 1347 $this->triggerBlog();1348 }1349 1350 /**1351 Updates post category. <var>$cat_id</var> can be null.1352 1353 @param id <b>integer</b> Post ID1354 @param cat_id <b>integer</b> Category ID1355 */1356 public function updPostCategory($id,$cat_id)1357 {1358 $this->updPostsCategory($id,$cat_id);1359 }1360 1361 /**1362 Updates posts category. <var>$cat_id</var> can be null.1363 1364 @param ids <b>mixed</b> Post(s) ID(s)1365 @param cat_id <b>integer</b> Category ID1366 */1367 public function updPostsCategory($ids,$cat_id)1368 {1369 if (!$this->core->auth->check('usage,contentadmin',$this->id)) {1370 throw new Exception(__('You are not allowed to change this entry category'));1371 }1372 1373 $posts_ids = dcUtils::cleanIds($ids);1374 $cat_id = (integer) $cat_id;1375 1376 $strReq = "WHERE blog_id = '".$this->con->escape($this->id)."' ".1377 "AND post_id ".$this->con->in($posts_ids);1378 1379 # If user is only usage, we need to check the post's owner1380 if (!$this->core->auth->check('contentadmin',$this->id))1381 {1382 $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' ";1383 }1384 1385 $cur = $this->con->openCursor($this->prefix.'post');1386 1387 $cur->cat_id = ($cat_id ? $cat_id : null);1388 $cur->post_upddt = date('Y-m-d H:i:s');1389 1390 $cur->update($strReq);1391 $this->triggerBlog();1392 }1393 1394 /**1395 Updates posts category. <var>$new_cat_id</var> can be null.1396 1397 @param old_cat_id <b>integer</b> Old category ID1398 @param new_cat_id <b>integer</b> New category ID1399 */1400 public function changePostsCategory($old_cat_id,$new_cat_id)1401 {1402 if (!$this->core->auth->check('contentadmin,categories',$this->id)) {1403 throw new Exception(__('You are not allowed to change entries category'));1404 }1405 1406 $old_cat_id = (integer) $old_cat_id;1407 $new_cat_id = (integer) $new_cat_id;1408 1409 $cur = $this->con->openCursor($this->prefix.'post');1410 1411 $cur->cat_id = ($new_cat_id ? $new_cat_id : null);1412 $cur->post_upddt = date('Y-m-d H:i:s');1413 1414 $cur->update(1415 'WHERE cat_id = '.$old_cat_id.' '.1416 "AND blog_id = '".$this->con->escape($this->id)."' "1417 );1418 773 $this->triggerBlog(); 1419 774 } … … 1470 825 "AND blog_id = '".$this->con->escape($this->id)."' "; 1471 826 1472 $ rs = $this->con->select($strReq);827 $posts = $this->con->select($strReq); 1473 828 1474 829 $now = dt::toUTC(time()); 1475 830 $to_change = new ArrayObject(); 1476 831 1477 if ( $rs->isEmpty()) {832 if (count($posts) == 0) { 1478 833 return; 1479 834 } 1480 835 1481 while ($rs->fetch())836 foreach ($posts as $post) 1482 837 { 1483 838 # Now timestamp with post timezone 1484 $now_tz = $now + dt::getTimeOffset($ rs->post_tz,$now);839 $now_tz = $now + dt::getTimeOffset($post->post_tz,$now); 1485 840 1486 841 # Post timestamp 1487 $post_ts = strtotime($ rs->post_dt);842 $post_ts = strtotime($post->post_dt); 1488 843 1489 844 # If now_tz >= post_ts, we publish the entry 1490 845 if ($now_tz >= $post_ts) { 1491 $to_change[] = (integer) $ rs->post_id;846 $to_change[] = (integer) $post->post_id; 1492 847 } 1493 848 } … … 1534 889 } 1535 890 1536 private function getPostsCategoryFilter($arr,$field='cat_id')1537 {1538 $field = $field == 'cat_id' ? 'cat_id' : 'cat_url';1539 1540 $sub = array();1541 $not = array();1542 $queries = array();1543 1544 foreach ($arr as $v)1545 {1546 $v = trim($v);1547 $args = preg_split('/\s*[?]\s*/',$v,-1,PREG_SPLIT_NO_EMPTY);1548 $id = array_shift($args);1549 $args = array_flip($args);1550 1551 if (isset($args['not'])) { $not[$id] = 1; }1552 if (isset($args['sub'])) { $sub[$id] = 1; }1553 if ($field == 'cat_id') {1554 if (preg_match('/^null$/i',$id)) {1555 $queries[$id] = 'P.cat_id IS NULL';1556 }1557 else {1558 $queries[$id] = 'P.cat_id = '.(integer) $id;1559 }1560 } else {1561 $queries[$id] = "C.cat_url = '".$this->con->escape($id)."' ";1562 }1563 }1564 1565 if (!empty($sub)) {1566 $rs = $this->con->select(1567 'SELECT cat_id, cat_url, cat_lft, cat_rgt FROM '.$this->prefix.'category '.1568 "WHERE blog_id = '".$this->con->escape($this->id)."' ".1569 'AND '.$field.' '.$this->con->in(array_keys($sub))1570 );1571 1572 while ($rs->fetch()) {1573 $queries[$rs->f($field)] = '(C.cat_lft BETWEEN '.$rs->cat_lft.' AND '.$rs->cat_rgt.')';1574 }1575 }1576 1577 # Create queries1578 $sql = array(1579 0 => array(), # wanted categories1580 1 => array() # excluded categories1581 );1582 1583 foreach ($queries as $id => $q) {1584 $sql[(integer) isset($not[$id])][] = $q;1585 }1586 1587 $sql[0] = implode(' OR ',$sql[0]);1588 $sql[1] = implode(' OR ',$sql[1]);1589 1590 if ($sql[0]) {1591 $sql[0] = '('.$sql[0].')';1592 } else {1593 unset($sql[0]);1594 }1595 1596 if ($sql[1]) {1597 $sql[1] = '(P.cat_id IS NULL OR NOT('.$sql[1].'))';1598 } else {1599 unset($sql[1]);1600 }1601 1602 return implode(' AND ',$sql);1603 }1604 1605 891 private function getPostCursor($cur,$post_id=null) 1606 892 { … … 1611 897 if ($cur->post_content == '') { 1612 898 throw new Exception(__('No entry content')); 1613 }1614 1615 if ($cur->post_password === '') {1616 $cur->post_password = null;1617 899 } 1618 900 … … 1765 1047 'ORDER BY post_url DESC'; 1766 1048 1767 $ rs = $this->con->select($strReq);1768 1769 if ( !$rs->isEmpty())1049 $urls = $this->con->select($strReq); 1050 1051 if (count($urls) > 0) 1770 1052 { 1771 1053 if ($this->con->driver() == 'mysql') { … … 1782 1064 'ORDER BY post_url DESC '; 1783 1065 1784 $ rs = $this->con->select($strReq);1066 $urls = $this->con->select($strReq); 1785 1067 $a = array(); 1786 while ($rs->fetch()) {1787 $a[] = $ rs->post_url;1068 foreach ($urls as $u) { 1069 $a[] = $u->post_url; 1788 1070 } 1789 1071 … … 1809 1091 } 1810 1092 //@} 1811 1812 /// @name Comments management methods1813 //@{1814 /**1815 Retrieves comments. <b>$params</b> is an array taking the following1816 optionnal parameters:1817 1818 - no_content: Don't retrieve comment content1819 - post_type: Get only entries with given type (default no type, array for many types)1820 - post_id: (integer) Get comments belonging to given post_id1821 - cat_id: (integer or array) Get comments belonging to entries of given category ID1822 - comment_id: (integer) Get comment with given ID1823 - comment_status: (integer) Get comments with given comment_status1824 - comment_trackback: (integer) Get only comments (0) or trackbacks (1)1825 - comment_ip: (string) Get comments with given IP address1826 - post_url: Get entry with given post_url field1827 - user_id: (integer) Get entries belonging to given user ID1828 - q_author: Search comments by author1829 - sql: Append SQL string at the end of the query1830 - from: Append SQL string after "FROM" statement in query1831 - order: Order of results (default "ORDER BY comment_dt DES")1832 - limit: Limit parameter1833 - sql_only : return the sql request instead of results. Only ids are selected1834 1835 @param params <b>array</b> Parameters1836 @param count_only <b>boolean</b> Only counts results1837 @return <b>record</b> A record with some more capabilities1838 */1839 public function getComments($params=array(),$count_only=false)1840 {1841 if ($count_only)1842 {1843 $strReq = 'SELECT count(comment_id) ';1844 }1845 elseif (!empty($params['sql_only']))1846 {1847 $strReq = 'SELECT P.post_id ';1848 }1849 else1850 {1851 if (!empty($params['no_content'])) {1852 $content_req = '';1853 } else {1854 $content_req = 'comment_content, ';1855 }1856 1857 if (!empty($params['columns']) && is_array($params['columns'])) {1858 $content_req .= implode(', ',$params['columns']).', ';1859 }1860 1861 $strReq =1862 'SELECT C.comment_id, comment_dt, comment_tz, comment_upddt, '.1863 'comment_author, comment_email, comment_site, '.1864 $content_req.' comment_trackback, comment_status, '.1865 'comment_spam_status, comment_spam_filter, comment_ip, '.1866 'P.post_title, P.post_url, P.post_id, P.post_password, P.post_type, '.1867 'P.post_dt, P.user_id, U.user_email, U.user_url ';1868 }1869 1870 $strReq .=1871 'FROM '.$this->prefix.'comment C '.1872 'INNER JOIN '.$this->prefix.'post P ON C.post_id = P.post_id '.1873 'INNER JOIN '.$this->prefix.'user U ON P.user_id = U.user_id ';1874 1875 if (!empty($params['from'])) {1876 $strReq .= $params['from'].' ';1877 }1878 1879 $strReq .=1880 "WHERE P.blog_id = '".$this->con->escape($this->id)."' ";1881 1882 if (!$this->core->auth->check('contentadmin',$this->id)) {1883 $strReq .= 'AND ((comment_status = 1 AND P.post_status = 1 ';1884 1885 if ($this->without_password) {1886 $strReq .= 'AND post_password IS NULL ';1887 }1888 $strReq .= ') ';1889 1890 if ($this->core->auth->userID()) {1891 $strReq .= "OR P.user_id = '".$this->con->escape($this->core->auth->userID())."')";1892 } else {1893 $strReq .= ') ';1894 }1895 }1896 1897 if (!empty($params['post_type']))1898 {1899 $strReq .= 'AND post_type '.$this->con->in($params['post_type']);1900 }1901 1902 if (isset($params['post_id']) && $params['post_id'] !== '') {1903 $strReq .= 'AND P.post_id = '.(integer) $params['post_id'].' ';1904 }1905 1906 if (isset($params['cat_id']) && $params['cat_id'] !== '') {1907 $strReq .= 'AND P.cat_id = '.(integer) $params['cat_id'].' ';1908 }1909 1910 if (isset($params['comment_id']) && $params['comment_id'] !== '') {1911 $strReq .= 'AND comment_id = '.(integer) $params['comment_id'].' ';1912 }1913 1914 if (isset($params['comment_status'])) {1915 $strReq .= 'AND comment_status = '.(integer) $params['comment_status'].' ';1916 }1917 1918 if (!empty($params['comment_status_not']))1919 {1920 $strReq .= 'AND comment_status <> '.(integer) $params['comment_status_not'].' ';1921 }1922 1923 if (isset($params['comment_trackback'])) {1924 $strReq .= 'AND comment_trackback = '.(integer) (boolean) $params['comment_trackback'].' ';1925 }1926 1927 if (isset($params['comment_ip'])) {1928 $comment_ip = $this->con->escape(str_replace('*','%',$params['comment_ip']));1929 $strReq .= "AND comment_ip LIKE '".$comment_ip."' ";1930 }1931 1932 if (isset($params['q_author'])) {1933 $q_author = $this->con->escape(str_replace('*','%',strtolower($params['q_author'])));1934 $strReq .= "AND LOWER(comment_author) LIKE '".$q_author."' ";1935 }1936 1937 if (!empty($params['search']))1938 {1939 $words = text::splitWords($params['search']);1940 1941 if (!empty($words))1942 {1943 # --BEHAVIOR coreCommentSearch1944 if ($this->core->hasBehavior('coreCommentSearch')) {1945 $this->core->callBehavior('coreCommentSearch',$this->core,array(&$words,&$strReq,&$params));1946 }1947 1948 if ($words)1949 {1950 foreach ($words as $i => $w) {1951 $words[$i] = "comment_words LIKE '%".$this->con->escape($w)."%'";1952 }1953 $strReq .= 'AND '.implode(' AND ',$words).' ';1954 }1955 }1956 }1957 1958 if (!empty($params['sql'])) {1959 $strReq .= $params['sql'].' ';1960 }1961 1962 if (!$count_only)1963 {1964 if (!empty($params['order'])) {1965 $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' ';1966 } else {1967 $strReq .= 'ORDER BY comment_dt DESC ';1968 }1969 }1970 1971 if (!$count_only && !empty($params['limit'])) {1972 $strReq .= $this->con->limit($params['limit']);1973 }1974 1093 1975 if (!empty($params['sql_only'])) {1976 return $strReq;1977 }1978 1979 $rs = $this->con->select($strReq);1980 $rs->core = $this->core;1981 $rs->extend('rsExtComment');1982 1983 # --BEHAVIOR-- coreBlogGetComments1984 $this->core->callBehavior('coreBlogGetComments',$rs);1985 1986 return $rs;1987 }1988 1989 /**1990 Creates a new comment. Takes a cursor as input and returns the new comment1991 ID.1992 1993 @param cur <b>cursor</b> Comment cursor1994 @return <b>integer</b> New comment ID1995 */1996 public function addComment($cur)1997 {1998 $this->con->writeLock($this->prefix.'comment');1999 try2000 {2001 # Get ID2002 $rs = $this->con->select(2003 'SELECT MAX(comment_id) '.2004 'FROM '.$this->prefix.'comment '2005 );2006 2007 $cur->comment_id = (integer) $rs->f(0) + 1;2008 $cur->comment_upddt = date('Y-m-d H:i:s');2009 2010 $offset = dt::getTimeOffset($this->settings->system->blog_timezone);2011 $cur->comment_dt = date('Y-m-d H:i:s',time() + $offset);2012 $cur->comment_tz = $this->settings->system->blog_timezone;2013 2014 $this->getCommentCursor($cur);2015 2016 if ($cur->comment_ip === null) {2017 $cur->comment_ip = http::realIP();2018 }2019 2020 # --BEHAVIOR-- coreBeforeCommentCreate2021 $this->core->callBehavior('coreBeforeCommentCreate',$this,$cur);2022 2023 $cur->insert();2024 $this->con->unlock();2025 }2026 catch (Exception $e)2027 {2028 $this->con->unlock();2029 throw $e;2030 }2031 2032 # --BEHAVIOR-- coreAfterCommentCreate2033 $this->core->callBehavior('coreAfterCommentCreate',$this,$cur);2034 2035 $this->triggerComment($cur->comment_id);2036 if ($cur->comment_status != -2) {2037 $this->triggerBlog();2038 }2039 return $cur->comment_id;2040 }2041 2042 /**2043 Updates an existing comment.2044 2045 @param id <b>integer</b> Comment ID2046 @param cur <b>cursor</b> Comment cursor2047 */2048 public function updComment($id,$cur)2049 {2050 if (!$this->core->auth->check('usage,contentadmin',$this->id)) {2051 throw new Exception(__('You are not allowed to update comments'));2052 }2053 2054 $id = (integer) $id;2055 2056 if (empty($id)) {2057 throw new Exception(__('No such comment ID'));2058 }2059 2060 $rs = $this->getComments(array('comment_id' => $id));2061 2062 if ($rs->isEmpty()) {2063 throw new Exception(__('No such comment ID'));2064 }2065 2066 #If user is only usage, we need to check the post's owner2067 if (!$this->core->auth->check('contentadmin',$this->id))2068 {2069 if ($rs->user_id != $this->core->auth->userID()) {2070 throw new Exception(__('You are not allowed to update this comment'));2071 }2072 }2073 2074 $this->getCommentCursor($cur);2075 2076 $cur->comment_upddt = date('Y-m-d H:i:s');2077 2078 if (!$this->core->auth->check('publish,contentadmin',$this->id)) {2079 $cur->unsetField('comment_status');2080 }2081 2082 # --BEHAVIOR-- coreBeforeCommentUpdate2083 $this->core->callBehavior('coreBeforeCommentUpdate',$this,$cur,$rs);2084 2085 $cur->update('WHERE comment_id = '.$id.' ');2086 2087 # --BEHAVIOR-- coreAfterCommentUpdate2088 $this->core->callBehavior('coreAfterCommentUpdate',$this,$cur,$rs);2089 2090 $this->triggerComment($id);2091 $this->triggerBlog();2092 }2093 2094 /**2095 Updates comment status.2096 2097 @param id <b>integer</b> Comment ID2098 @param status <b>integer</b> Comment status2099 */2100 public function updCommentStatus($id,$status)2101 {2102 $this->updCommentsStatus($id,$status);2103 }2104 2105 /**2106 Updates comments status.2107 2108 @param ids <b>mixed</b> Comment(s) ID(s)2109 @param status <b>integer</b> Comment status2110 */2111 public function updCommentsStatus($ids,$status)2112 {2113 if (!$this->core->auth->check('publish,contentadmin',$this->id)) {2114 throw new Exception(__("You are not allowed to change this comment's status"));2115 }2116 2117 $co_ids = dcUtils::cleanIds($ids);2118 $status = (integer) $status;2119 2120 $strReq =2121 'UPDATE '.$this->prefix.'comment tc ';2122 2123 # mySQL uses "JOIN" synthax2124 if ($this->con->driver() == 'mysql') {2125 $strReq .=2126 'JOIN '.$this->prefix.'post tp ON tc.post_id = tp.post_id ';2127 }2128 2129 $strReq .=2130 'SET comment_status = '.$status.' ';2131 2132 # pgSQL uses "FROM" synthax2133 if ($this->con->driver() != 'mysql') {2134 $strReq .=2135 'FROM '.$this->prefix.'post tp ';2136 }2137 2138 $strReq .=2139 "WHERE blog_id = '".$this->con->escape($this->id)."' ".2140 'AND comment_id'.$this->con->in($co_ids);2141 2142 # add pgSQL "WHERE" clause2143 if ($this->con->driver() != 'mysql') {2144 $strReq .=2145 'AND tc.post_id = tp.post_id ';2146 }2147 2148 #If user is only usage, we need to check the post's owner2149 if (!$this->core->auth->check('contentadmin',$this->id))2150 {2151 $strReq .=2152 "AND user_id = '".$this->con->escape($this->core->auth->userID())."' ";2153 }2154 2155 $this->con->execute($strReq);2156 $this->triggerComments($co_ids);2157 $this->triggerBlog();2158 }2159 2160 /**2161 Delete a comment2162 2163 @param id <b>integer</b> Comment ID2164 */2165 public function delComment($id)2166 {2167 $this->delComments($id);2168 }2169 2170 /**2171 Delete comments2172 2173 @param ids <b>mixed</b> Comment(s) ID(s)2174 */2175 public function delComments($ids)2176 {2177 if (!$this->core->auth->check('delete,contentadmin',$this->id)) {2178 throw new Exception(__('You are not allowed to delete comments'));2179 }2180 2181 $co_ids = dcUtils::cleanIds($ids);2182 2183 if (empty($ids)) {2184 throw new Exception(__('No such comment ID'));2185 }2186 2187 # mySQL uses "INNER JOIN" synthax2188 if ($this->con->driver() == 'mysql') {2189 $strReq =2190 'DELETE FROM tc '.2191 'USING '.$this->prefix.'comment tc '.2192 'INNER JOIN '.$this->prefix.'post tp ';2193 }2194 # pgSQL uses nothing special2195 else {2196 $strReq =2197 'DELETE FROM '.$this->prefix.'comment tc '.2198 'USING '.$this->prefix.'post tp ';2199 }2200 2201 $strReq .=2202 'WHERE tc.post_id = tp.post_id '.2203 "AND tp.blog_id = '".$this->con->escape($this->id)."' ".2204 'AND comment_id'.$this->con->in($co_ids);2205 2206 #If user can only delete, we need to check the post's owner2207 if (!$this->core->auth->check('contentadmin',$this->id))2208 {2209 $strReq .=2210 "AND user_id = '".$this->con->escape($this->core->auth->userID())."' ";2211 }2212 2213 $this->con->execute($strReq);2214 $this->triggerComments($co_ids,true);2215 $this->triggerBlog();2216 }2217 2218 public function delJunkComments()2219 {2220 if (!$this->core->auth->check('delete,contentadmin',$this->id)) {2221 throw new Exception(__('You are not allowed to delete comments'));2222 }2223 2224 # mySQL uses "INNER JOIN" synthax2225 if ($this->con->driver() == 'mysql') {2226 $strReq =2227 'DELETE FROM tc '.2228 'USING '.$this->prefix.'comment tc '.2229 'INNER JOIN '.$this->prefix.'post tp ';2230 }2231 # pgSQL uses nothing special2232 else {2233 $strReq =2234 'DELETE FROM '.$this->prefix.'comment tc '.2235 'USING '.$this->prefix.'post tp ';2236 }2237 2238 $strReq .=2239 'WHERE tc.post_id = tp.post_id '.2240 "AND tp.blog_id = '".$this->con->escape($this->id)."' ".2241 'AND comment_status = -2';2242 2243 #If user can only delete, we need to check the post's owner2244 if (!$this->core->auth->check('contentadmin',$this->id))2245 {2246 $strReq .=2247 "AND user_id = '".$this->con->escape($this->core->auth->userID())."' ";2248 }2249 2250 $this->con->execute($strReq);2251 $this->triggerBlog();2252 }2253 2254 private function getCommentCursor($cur)2255 {2256 if ($cur->comment_content !== null && $cur->comment_content == '') {2257 throw new Exception(__('You must provide a comment'));2258 }2259 2260 if ($cur->comment_author !== null && $cur->comment_author == '') {2261 throw new Exception(__('You must provide an author name'));2262 }2263 2264 if ($cur->comment_email != '' && !text::isEmail($cur->comment_email)) {2265 throw new Exception(__('Email address is not valid.'));2266 }2267 2268 if ($cur->comment_site !== null && $cur->comment_site != '') {2269 if (!preg_match('|^http(s?)://|',$cur->comment_site)) {2270 $cur->comment_site = 'http://'.$cur->comment_site;2271 }2272 }2273 2274 if ($cur->comment_status === null) {2275 $cur->comment_status = (integer) $this->settings->system->comments_pub;2276 }2277 2278 # Words list2279 if ($cur->comment_content !== null)2280 {2281 $cur->comment_words = implode(' ',text::splitWords($cur->comment_content));2282 }2283 }2284 //@}2285 1094 } 2286 1095 ?> -
inc/core/class.dc.namespace.php
r879 r1107 259 259 } 260 260 } 261 262 /** 263 Removes an existing setting. Namespace 261 262 /** 263 Rename an existing setting in a Namespace 264 265 @param $oldId <b>string</b> Current setting name 266 @param $newId <b>string</b> New setting name 267 @return <b>boolean</b> 268 */ 269 public function rename($oldId,$newId) 270 { 271 if (!$this->ns) { 272 throw new Exception(__('No namespace specified')); 273 } 274 275 if (!array_key_exists($oldId,$this->settings) || array_key_exists($newId,$this->settings)) { 276 return false; 277 } 278 279 // Rename the setting in the settings array 280 $this->settings[$newId] = $this->settings[$oldId]; 281 unset($this->settings[$oldId]); 282 283 // Rename the setting in the database 284 $strReq = 'UPDATE '.$this->table. 285 " SET setting_id = '".$this->con->escape($newId)."' ". 286 " WHERE setting_ns = '".$this->con->escape($this->ns)."' ". 287 " AND setting_id = '".$this->con->escape($oldId)."' "; 288 $this->con->execute($strReq); 289 return true; 290 } 291 292 /** 293 Removes an existing setting in a Namespace 264 294 265 295 @param id <b>string</b> Setting ID … … 286 316 287 317 /** 318 Removes all existing settings in a Namespace 319 320 @param force_global <b>boolean</b> Force global pref drop 321 */ 322 public function dropAll($force_global=false) 323 { 324 if (!$this->ns) { 325 throw new Exception(__('No namespace specified')); 326 } 327 328 $strReq = 'DELETE FROM '.$this->table.' '; 329 330 if (($force_global) || ($this->blog_id === null)) { 331 $strReq .= 'WHERE blog_id IS NULL '; 332 $global = true; 333 } else { 334 $strReq .= "WHERE blog_id = '".$this->con->escape($this->blog_id)."' "; 335 $global = false; 336 } 337 338 $strReq .= "AND setting_ns = '".$this->con->escape($this->ns)."' "; 339 340 $this->con->execute($strReq); 341 342 $array = $global ? 'global' : 'local'; 343 unset($this->{$array.'_settings'}); 344 $this->{$array.'_settings'} = array(); 345 346 $array = $global ? 'local' : 'global'; 347 $this->settings = $this->{$array.'_settings'}; 348 } 349 350 /** 288 351 Returns $settings property content. 289 352 -
inc/core/class.dc.rs.extensions.php
r852 r1107 117 117 118 118 /** 119 Returns whether post has been updated since publication. 120 121 @return <b>boolean</b> 122 */ 123 public static function isRepublished($rs) 124 { 125 return ($rs->getTS('upddt') + dt::getTimeOffset($rs->post_tz)) > $rs->getTS(); 126 } 127 128 /** 119 129 Returns full post URL. 120 130 -
inc/core/class.dc.rs.extensions.php
r912 r1107 117 117 118 118 /** 119 Returns whether comments are enabled on post.120 121 @param rs Invisible parameter122 @return <b>boolean</b>123 */124 public static function commentsActive($rs)125 {126 return127 $rs->core->blog->settings->system->allow_comments128 && $rs->post_open_comment129 && ($rs->core->blog->settings->system->comments_ttl == 0 ||130 time()-($rs->core->blog->settings->system->comments_ttl*86400) < $rs->getTS());131 }132 133 /**134 Returns whether trackbacks are enabled on post.135 136 @param rs Invisible parameter137 @return <b>boolean</b>138 */139 public static function trackbacksActive($rs)140 {141 return142 $rs->core->blog->settings->system->allow_trackbacks143 && $rs->post_open_tb144 && ($rs->core->blog->settings->system->trackbacks_ttl == 0 ||145 time()-($rs->core->blog->settings->system->trackbacks_ttl*86400) < $rs->getTS());146 }147 148 /**149 Returns whether post has at least one comment.150 151 @param rs Invisible parameter152 @return <b>boolean</b>153 */154 public static function hasComments($rs)155 {156 return $rs->nb_comment > 0;157 }158 159 /**160 Returns whether post has at least one trackbacks.161 162 @return <b>boolean</b>163 */164 public static function hasTrackbacks($rs)165 {166 return $rs->nb_trackback > 0;167 }168 169 /**170 119 Returns whether post has been updated since publication. 171 120 … … 188 137 $rs->post_type,html::sanitizeURL($rs->post_url) 189 138 ); 190 }191 192 /**193 Returns full post category URL.194 195 @param rs Invisible parameter196 @return <b>string</b>197 */198 public static function getCategoryURL($rs)199 {200 return $rs->core->blog->url.$rs->core->url->getURLFor('category',html::sanitizeURL($rs->cat_url));201 139 } 202 140 … … 374 312 375 313 /** 376 Returns trackback RDF information block in HTML comment.377 378 @param rs Invisible parameter379 @return <b>string</b>380 */381 public static function getTrackbackData($rs)382 {383 return384 "<![CDATA[>\n".385 "<!--[\n".386 '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n".387 ' xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n".388 ' xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">'."\n".389 "<rdf:Description\n".390 ' rdf:about="'.$rs->getURL().'"'."\n".391 ' dc:identifier="'.$rs->getURL().'"'."\n".392 ' dc:title="'.htmlspecialchars($rs->post_title,ENT_COMPAT,'UTF-8').'"'."\n".393 ' trackback:ping="'.$rs->getTrackbackLink().'" />'."\n".394 "</rdf:RDF>\n".395 "<!]]><!---->\n";396 }397 398 /**399 Returns post trackback full URL.400 401 @param rs Invisible parameter402 @return <b>string</b>403 */404 public static function getTrackbackLink($rs)405 {406 return $rs->core->blog->url.$rs->core->url->getURLFor('trackback',$rs->post_id);407 }408 409 /**410 314 Returns post content. If <var>$absolute_urls</var> is true, appends full 411 315 blog URL to each relative post URLs. … … 441 345 } 442 346 443 /**444 Returns post media count using a subquery.445 446 @param rs Invisible parameter447 @return <b>integer</b>448 */449 public static function countMedia($rs)450 {451 if (isset($rs->_nb_media[$rs->index()]))452 {453 return $rs->_nb_media[$rs->index()];454 }455 else456 {457 $strReq =458 'SELECT count(media_id) '.459 'FROM '.$rs->core->prefix.'post_media '.460 'WHERE post_id = '.(integer) $rs->post_id.' ';461 462 $res = (integer) $rs->core->con->select($strReq)->f(0);463 $rs->_nb_media[$rs->index()] = $res;464 return $res;465 }466 }467 }468 469 /**470 @ingroup DC_CORE471 @brief Dotclear comment record helpers.472 473 This class adds new methods to database comment results.474 You can call them on every record comming from dcBlog::getComments and similar475 methods.476 477 @warning You should not give the first argument (usualy $rs) of every described478 function.479 */480 class rsExtComment481 {482 /**483 Returns comment date with <var>$format</var> as formatting pattern. If484 format is empty, uses <var>date_format</var> blog setting.485 486 @param rs Invisible parameter487 @param format <b>string</b> Date format pattern488 @param type <b>string</b> (dt|upddt) defaults to comment_dt489 @return <b>string</b>490 */491 public static function getDate($rs,$format,$type='')492 {493 if (!$format) {494 $format = $rs->core->blog->settings->system->date_format;495 }496 497 if ($type == 'upddt') {498 return dt::dt2str($format,$rs->comment_upddt,$rs->comment_tz);499 } else {500 return dt::dt2str($format,$rs->comment_dt);501 }502 }503 504 /**505 Returns comment time with <var>$format</var> as formatting pattern. If506 format is empty, uses <var>time_format</var> blog setting.507 508 @param rs Invisible parameter509 @param format <b>string</b> Date format pattern510 @param type <b>string</b> (dt|upddt) defaults to comment_dt511 @return <b>string</b>512 */513 public static function getTime($rs,$format,$type='')514 {515 if (!$format) {516 $format = $rs->core->blog->settings->system->time_format;517 }518 519 if ($type == 'upddt') {520 return dt::dt2str($format,$rs->comment_updt,$rs->comment_tz);521 } else {522 return dt::dt2str($format,$rs->comment_dt);523 }524 }525 526 /**527 Returns comment timestamp.528 529 @param rs Invisible parameter530 @param type <b>string</b> (dt|upddt) defaults to comment_dt531 @return <b>integer</b>532 */533 public static function getTS($rs,$type='')534 {535 if ($type == 'upddt') {536 return strtotime($rs->comment_upddt);537 } else {538 return strtotime($rs->comment_dt);539 }540 }541 542 /**543 Returns comment date formating according to the ISO 8601 standard.544 545 @param rs Invisible parameter546 @param type <b>string</b> (dt|upddt) defaults to comment_dt547 @return <b>string</b>548 */549 public static function getISO8601Date($rs,$type='')550 {551 if ($type == 'upddt') {552 return dt::iso8601($rs->getTS($type)+dt::getTimeOffset($rs->comment_tz),$rs->comment_tz);553 } else {554 return dt::iso8601($rs->getTS(),$rs->comment_tz);555 }556 }557 558 /**559 Returns comment date formating according to RFC 822.560 561 @param rs Invisible parameter562 @param type <b>string</b> (dt|upddt) defaults to comment_dt563 @return <b>string</b>564 */565 public static function getRFC822Date($rs,$type='')566 {567 if ($type == 'upddt') {568 return dt::rfc822($rs->getTS($type)+dt::getTimeOffset($rs->comment_tz),$rs->comment_tz);569 } else {570 return dt::rfc822($rs->getTS(),$rs->comment_tz);571 }572 }573 574 /**575 Returns comment content. If <var>$absolute_urls</var> is true, appends full576 blog URL to each relative post URLs.577 578 @param rs Invisible parameter579 @param absolute_urls <b>boolean</b> With absolute URLs580 @return <b>string</b>581 */582 public static function getContent($rs,$absolute_urls=false)583 {584 $res = $rs->comment_content;585 586 if ($rs->core->blog->settings->system->comments_nofollow) {587 $res = preg_replace_callback('#<a(.*?href=".*?".*?)>#ms',array('self','noFollowURL'),$res);588 }589 590 if ($absolute_urls) {591 $res = html::absoluteURLs($res,$rs->getPostURL());592 }593 594 return $res;595 }596 597 private static function noFollowURL($m)598 {599 if (preg_match('/rel="nofollow"/',$m[1])) {600 return $m[0];601 }602 603 return '<a'.$m[1].' rel="nofollow">';604 }605 606 /**607 Returns comment author link to his website if he specified one.608 609 @param rs Invisible parameter610 @return <b>string</b>611 */612 public static function getAuthorURL($rs)613 {614 if (trim($rs->comment_site)) {615 return trim($rs->comment_site);616 }617 }618 619 /**620 Returns comment post full URL.621 622 @param rs Invisible parameter623 @return <b>string</b>624 */625 public static function getPostURL($rs)626 {627 return $rs->core->blog->url.$rs->core->getPostPublicURL(628 $rs->post_type,html::sanitizeURL($rs->post_url)629 );630 }631 632 /**633 Returns comment author name in a link to his website if he specified one.634 635 @param rs Invisible parameter636 @return <b>string</b>637 */638 public static function getAuthorLink($rs)639 {640 $res = '%1$s';641 $url = $rs->getAuthorURL();642 if ($url) {643 $res = '<a href="%2$s"%3$s>%1$s</a>';644 }645 646 $nofollow = '';647 if ($rs->core->blog->settings->system->comments_nofollow) {648 $nofollow = ' rel="nofollow"';649 }650 651 return sprintf($res,html::escapeHTML($rs->comment_author),html::escapeHTML($url),$nofollow);652 }653 654 /**655 Returns comment author e-mail address. If <var>$encoded</var> is true,656 "@" sign is replaced by "%40" and "." by "%2e".657 658 @param rs Invisible parameter659 @param encoded <b>boolean</b> Encode address.660 @return <b>string</b>661 */662 public static function getEmail($rs,$encoded=true)663 {664 if ($encoded) {665 return strtr($rs->comment_email,array('@'=>'%40','.'=>'%2e'));666 }667 return $rs->comment_email;668 }669 670 /**671 Returns trackback site title if comment is a trackback.672 673 @param rs Invisible parameter674 @return <b>string</b>675 */676 public static function getTrackbackTitle($rs)677 {678 if ($rs->comment_trackback == 1 &&679 preg_match('|<p><strong>(.*?)</strong></p>|msU',$rs->comment_content,680 $match)) {681 return html::decodeEntities($match[1]);682 }683 }684 685 /**686 Returns trackback content if comment is a trackback.687 688 @param rs Invisible parameter689 @return <b>string</b>690 */691 public static function getTrackbackContent($rs)692 {693 if ($rs->comment_trackback == 1) {694 return preg_replace('|<p><strong>.*?</strong></p>|msU','',695 $rs->comment_content);696 }697 }698 699 /**700 Returns comment feed unique ID.701 702 @param rs Invisible parameter703 @return <b>string</b>704 */705 public static function getFeedID($rs)706 {707 return 'urn:md5:'.md5($rs->core->blog->uid.$rs->comment_id);708 709 $url = parse_url($rs->core->blog->url);710 $date_part = date('Y-m-d',strtotime($rs->comment_dt));711 712 return 'tag:'.$url['host'].','.$date_part.':'.$rs->comment_id;713 }714 715 /**716 Returns whether comment is from the post author.717 718 @param rs Invisible parameter719 @return <b>boolean</b>720 */721 public static function isMe($rs)722 {723 return724 $rs->comment_email && $rs->comment_site &&725 $rs->comment_email == $rs->user_email &&726 $rs->comment_site == $rs->user_url;727 }728 347 } 729 348 -
inc/core/class.dc.workspace.php
r880 r1107 263 263 } 264 264 } 265 266 /** 267 Rename an existing pref in a Workspace 268 269 @param $oldId <b>string</b> Current pref name 270 @param $newId <b>string</b> New pref name 271 @return <b>boolean</b> 272 */ 273 public function rename($oldId,$newId) 274 { 275 if (!$this->ws) { 276 throw new Exception(__('No workspace specified')); 277 } 278 279 if (!array_key_exists($oldId,$this->prefs) || array_key_exists($newId,$this->prefs)) { 280 return false; 281 } 282 283 // Rename the pref in the prefs array 284 $this->prefs[$newId] = $this->prefs[$oldId]; 285 unset($this->prefs[$oldId]); 286 287 // Rename the pref in the database 288 $strReq = 'UPDATE '.$this->table. 289 " SET pref_id = '".$this->con->escape($newId)."' ". 290 " WHERE pref_ws = '".$this->con->escape($this->ws)."' ". 291 " AND pref_id = '".$this->con->escape($oldId)."' "; 292 $this->con->execute($strReq); 293 return true; 294 } 265 295 266 296 /**
Note: See TracChangeset
for help on using the changeset viewer.