Changeset 2566:9bf417837888 for inc/core/class.dc.core.php
- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.core.php
r2492 r2566 39 39 public $rest; ///< <b>dcRestServer</b> dcRestServer object 40 40 public $log; ///< <b>dcLog</b> dcLog object 41 41 42 42 private $versions = null; 43 43 private $formaters = array(); 44 44 private $behaviors = array(); 45 45 private $post_types = array(); 46 46 47 47 /** 48 48 dcCore constructor inits everything related to Dotclear. It takes arguments 49 49 to init database connection. 50 50 51 51 @param driver <b>string</b> Database driver name 52 52 @param host <b>string</b> Database hostname … … 60 60 { 61 61 $this->con = dbLayer::init($driver,$host,$db,$user,$password,$persist); 62 62 63 63 # define weak_locks for mysql 64 64 if ($this->con instanceof mysqlConnection) { … … 67 67 mysqliConnection::$weak_locks = true; 68 68 } 69 69 70 70 # define searchpath for postgresql 71 71 if ($this->con instanceof pgsqlConnection) … … 79 79 } 80 80 } 81 81 82 82 $this->prefix = $prefix; 83 83 84 84 $this->error = new dcError(); 85 85 $this->auth = $this->authInstance(); 86 86 $this->session = new sessionDB($this->con,$this->prefix.'session',DC_SESSION_NAME,'',null,DC_ADMIN_SSL); 87 87 $this->url = new dcUrlHandlers(); 88 88 89 89 $this->plugins = new dcPlugins($this); 90 90 91 91 $this->rest = new dcRestServer($this); 92 92 93 93 $this->meta = new dcMeta($this); 94 94 95 95 $this->log = new dcLog($this); 96 96 97 97 $this->addFormater('xhtml', create_function('$s','return $s;')); 98 98 $this->addFormater('wiki', array($this,'wikiTransform')); 99 99 } 100 100 101 101 private function authInstance() 102 102 { … … 108 108 $c = DC_AUTH_CLASS; 109 109 } 110 110 111 111 if (!class_exists($c)) { 112 112 throw new Exception('Authentication class '.$c.' does not exist.'); 113 113 } 114 114 115 115 if ($c != 'dcAuth' && !is_subclass_of($c,'dcAuth')) { 116 116 throw new Exception('Authentication class '.$c.' does not inherit dcAuth.'); 117 117 } 118 118 119 119 return new $c($this); 120 120 } 121 122 121 122 123 123 /// @name Blog init methods 124 124 //@{ 125 125 /** 126 126 Sets a blog to use in <var>blog</var> property. 127 127 128 128 @param id <b>string</b> Blog ID 129 129 */ … … 132 132 $this->blog = new dcBlog($this, $id); 133 133 } 134 134 135 135 /** 136 136 Unsets <var>blog</var> property. … … 141 141 } 142 142 //@} 143 144 143 144 145 145 /// @name Blog status methods 146 146 //@{ 147 147 /** 148 148 Returns an array of available blog status codes and names. 149 149 150 150 @return <b>array</b> Simple array with codes in keys and names in value 151 151 */ … … 158 158 ); 159 159 } 160 160 161 161 /** 162 162 Returns a blog status name given to a code. This is intended to be 163 163 human-readable and will be translated, so never use it for tests. 164 164 If status code does not exist, returns <i>offline</i>. 165 165 166 166 @param s <b>integer</b> Status code 167 167 @return <b>string</b> Blog status name … … 176 176 } 177 177 //@} 178 178 179 179 /// @name Admin nonce secret methods 180 180 //@{ 181 181 182 182 public function getNonce() 183 183 { 184 184 return crypt::hmac(DC_MASTER_KEY,session_id()); 185 185 } 186 186 187 187 public function checkNonce($secret) 188 188 { … … 190 190 return false; 191 191 } 192 192 193 193 return $secret == crypt::hmac(DC_MASTER_KEY,session_id()); 194 194 } 195 195 196 196 public function formNonce() 197 197 { … … 199 199 return; 200 200 } 201 201 202 202 return form::hidden(array('xd_check'),$this->getNonce()); 203 203 } 204 204 //@} 205 206 205 206 207 207 /// @name Text Formatters methods 208 208 //@{ … … 211 211 transform text. The function must be a valid callback and takes one 212 212 argument: the string to transform. It returns the transformed string. 213 213 214 214 @param name <b>string</b> Formater name 215 215 @param func <b>callback</b> Function to use, must be a valid and callable callback … … 221 221 } 222 222 } 223 223 224 224 /** 225 225 Returns formaters list. 226 226 227 227 @return <b>array</b> An array of formaters names in values. 228 228 */ … … 231 231 return array_keys($this->formaters); 232 232 } 233 233 234 234 /** 235 235 If <var>$name</var> is a valid formater, it returns <var>$str</var> 236 236 transformed using that formater. 237 237 238 238 @param name <b>string</b> Formater name 239 239 @param str <b>string</b> String to transform … … 245 245 return call_user_func($this->formaters[$name],$str); 246 246 } 247 247 248 248 return $str; 249 249 } 250 250 //@} 251 252 251 252 253 253 /// @name Behaviors methods 254 254 //@{ … … 256 256 Adds a new behavior to behaviors stack. <var>$func</var> must be a valid 257 257 and callable callback. 258 258 259 259 @param behavior <b>string</b> Behavior name 260 260 @param func <b>callback</b> Function to call … … 266 266 } 267 267 } 268 268 269 269 /** 270 270 Tests if a particular behavior exists in behaviors stack. 271 271 272 272 @param behavior <b>string</b> Behavior name 273 273 @return <b>boolean</b> … … 277 277 return isset($this->behaviors[$behavior]); 278 278 } 279 279 280 280 /** 281 281 Get behaviors stack (or part of). 282 282 283 283 @param behavior <b>string</b> Behavior name 284 284 @return <b>array</b> … … 287 287 { 288 288 if (empty($this->behaviors)) return null; 289 289 290 290 if ($behavior == '') { 291 291 return $this->behaviors; … … 293 293 return $this->behaviors[$behavior]; 294 294 } 295 295 296 296 return array(); 297 297 } 298 298 299 299 /** 300 300 Calls every function in behaviors stack for a given behavior and returns 301 301 concatened result of each function. 302 302 303 303 Every parameters added after <var>$behavior</var> will be pass to 304 304 behavior calls. 305 305 306 306 @param behavior <b>string</b> Behavior name 307 307 @return <b>string</b> Behavior concatened result … … 313 313 $args = func_get_args(); 314 314 array_shift($args); 315 315 316 316 $res = ''; 317 317 318 318 foreach ($this->behaviors[$behavior] as $f) { 319 319 $res .= call_user_func_array($f,$args); 320 320 } 321 321 322 322 return $res; 323 323 } 324 324 } 325 325 //@} 326 326 327 327 /// @name Post types URLs management 328 328 //@{ … … 332 332 $type = 'post'; 333 333 } 334 334 335 335 $url = sprintf($this->post_types[$type]['admin_url'],$post_id); 336 336 return $escaped ? html::escapeURL($url) : $url; 337 337 } 338 338 339 339 public function getPostPublicURL($type,$post_url,$escaped=true) 340 340 { … … 342 342 $type = 'post'; 343 343 } 344 344 345 345 $url = sprintf($this->post_types[$type]['public_url'],$post_url); 346 346 return $escaped ? html::escapeURL($url) : $url; 347 347 } 348 348 349 349 public function setPostType($type,$admin_url,$public_url,$label='') 350 350 { … … 355 355 ); 356 356 } 357 357 358 358 public function getPostTypes() 359 359 { … … 361 361 } 362 362 //@} 363 363 364 364 /// @name Versions management methods 365 365 //@{ 366 366 /** 367 367 Returns a given $module version. 368 368 369 369 @param module <b>string</b> Module name 370 370 @return <b>string</b> Module version … … 377 377 $strReq = 'SELECT module, version FROM '.$this->prefix.'version'; 378 378 $rs = $this->con->select($strReq); 379 379 380 380 while ($rs->fetch()) { 381 381 $this->versions[$rs->module] = $rs->version; 382 382 } 383 383 } 384 384 385 385 if (isset($this->versions[$module])) { 386 386 return $this->versions[$module]; … … 389 389 } 390 390 } 391 391 392 392 /** 393 393 Sets $version to given $module. 394 394 395 395 @param module <b>string</b> Module name 396 396 @param version <b>string</b> Module version … … 399 399 { 400 400 $cur_version = $this->getVersion($module); 401 401 402 402 $cur = $this->con->openCursor($this->prefix.'version'); 403 403 $cur->module = (string) $module; 404 404 $cur->version = (string) $version; 405 405 406 406 if ($cur_version === null) { 407 407 $cur->insert(); … … 409 409 $cur->update("WHERE module='".$this->con->escape($module)."'"); 410 410 } 411 411 412 412 $this->versions[$module] = $version; 413 413 } 414 414 415 415 /** 416 416 Removes given $module version entry. 417 417 418 418 @param module <b>string</b> Module name 419 419 */ … … 423 423 'DELETE FROM '.$this->prefix.'version '. 424 424 "WHERE module = '".$this->con->escape($module)."' "; 425 425 426 426 $this->con->execute($strReq); 427 427 428 428 if (is_array($this->versions)) { 429 429 unset($this->versions[$module]); 430 430 } 431 431 } 432 432 433 433 //@} 434 434 435 435 /// @name Users management methods 436 436 //@{ 437 437 /** 438 438 Returns a user by its ID. 439 439 440 440 @param id <b>string</b> User ID 441 441 @return <b>record</b> … … 444 444 { 445 445 $params['user_id'] = $id; 446 446 447 447 return $this->getUsers($params); 448 448 } 449 449 450 450 /** 451 451 Returns a users list. <b>$params</b> is an array with the following 452 452 optionnal parameters: 453 453 454 454 - <var>q</var>: search string (on user_id, user_name, user_firstname) 455 455 - <var>user_id</var>: user ID 456 456 - <var>order</var>: ORDER BY clause (default: user_id ASC) 457 457 - <var>limit</var>: LIMIT clause (should be an array ![limit,offset]) 458 458 459 459 @param params <b>array</b> Parameters 460 460 @param count_only <b>boolean</b> Only counts results … … 481 481 'WHERE NULL IS NULL '; 482 482 } 483 483 484 484 if (!empty($params['q'])) { 485 485 $q = $this->con->escape(str_replace('*','%',strtolower($params['q']))); … … 490 490 ') '; 491 491 } 492 492 493 493 if (!empty($params['user_id'])) { 494 494 $strReq .= "AND U.user_id = '".$this->con->escape($params['user_id'])."' "; 495 495 } 496 496 497 497 if (!$count_only) { 498 498 $strReq .= 'GROUP BY U.user_id,user_super,user_status,user_pwd,user_change_pwd,'. 499 499 'user_name,user_firstname,user_displayname,user_email,user_url,'. 500 500 'user_desc, user_lang,user_tz,user_post_status,user_options '; 501 501 502 502 if (!empty($params['order']) && !$count_only) { 503 503 $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; … … 506 506 } 507 507 } 508 508 509 509 if (!$count_only && !empty($params['limit'])) { 510 510 $strReq .= $this->con->limit($params['limit']); 511 511 } 512 512 513 513 $rs = $this->con->select($strReq); 514 514 $rs->extend('rsExtUser'); 515 515 return $rs; 516 516 } 517 517 518 518 /** 519 519 Create a new user. Takes a cursor as input and returns the new user ID. 520 520 521 521 @param cur <b>cursor</b> User cursor 522 522 @return <b>string</b> … … 527 527 throw new Exception(__('You are not an administrator')); 528 528 } 529 529 530 530 if ($cur->user_id == '') { 531 531 throw new Exception(__('No user ID given')); 532 532 } 533 533 534 534 if ($cur->user_pwd == '') { 535 535 throw new Exception(__('No password given')); 536 536 } 537 537 538 538 $this->getUserCursor($cur); 539 539 540 540 if ($cur->user_creadt === null) { 541 541 $cur->user_creadt = date('Y-m-d H:i:s'); 542 542 } 543 543 544 544 $cur->insert(); 545 545 546 546 $this->auth->afterAddUser($cur); 547 547 548 548 return $cur->user_id; 549 549 } 550 550 551 551 /** 552 552 Updates an existing user. Returns the user ID. 553 553 554 554 @param id <b>string</b> User ID 555 555 @param cur <b>cursor</b> User cursor … … 559 559 { 560 560 $this->getUserCursor($cur); 561 561 562 562 if (($cur->user_id !== null || $id != $this->auth->userID()) && 563 563 !$this->auth->isSuperAdmin()) { 564 564 throw new Exception(__('You are not an administrator')); 565 565 } 566 566 567 567 $cur->update("WHERE user_id = '".$this->con->escape($id)."' "); 568 568 569 569 $this->auth->afterUpdUser($id,$cur); 570 570 571 571 if ($cur->user_id !== null) { 572 572 $id = $cur->user_id; 573 573 } 574 574 575 575 # Updating all user's blogs 576 576 $rs = $this->con->select( … … 578 578 "WHERE user_id = '".$this->con->escape($id)."' " 579 579 ); 580 580 581 581 while ($rs->fetch()) { 582 582 $b = new dcBlog($this,$rs->blog_id); … … 584 584 unset($b); 585 585 } 586 586 587 587 return $id; 588 588 } 589 589 590 590 /** 591 591 Deletes a user. 592 592 593 593 @param id <b>string</b> User ID 594 594 */ … … 598 598 throw new Exception(__('You are not an administrator')); 599 599 } 600 600 601 601 if ($id == $this->auth->userID()) { 602 602 return; 603 603 } 604 604 605 605 $rs = $this->getUser($id); 606 606 607 607 if ($rs->nb_post > 0) { 608 608 return; 609 609 } 610 610 611 611 $strReq = 'DELETE FROM '.$this->prefix.'user '. 612 612 "WHERE user_id = '".$this->con->escape($id)."' "; 613 613 614 614 $this->con->execute($strReq); 615 615 616 616 $this->auth->afterDelUser($id); 617 617 } 618 618 619 619 /** 620 620 Checks whether a user exists. 621 621 622 622 @param id <b>string</b> User ID 623 623 @return <b>boolean</b> … … 628 628 'FROM '.$this->prefix.'user '. 629 629 "WHERE user_id = '".$this->con->escape($id)."' "; 630 630 631 631 $rs = $this->con->select($strReq); 632 632 633 633 return !$rs->isEmpty(); 634 634 } 635 635 636 636 /** 637 637 Returns all user permissions as an array which looks like: 638 638 639 639 - [blog_id] 640 640 - [name] => Blog name … … 643 643 - [permission] => true 644 644 - ... 645 645 646 646 @param id <b>string</b> User ID 647 647 @return <b>array</b> … … 653 653 'INNER JOIN '.$this->prefix.'blog B ON P.blog_id = B.blog_id '. 654 654 "WHERE user_id = '".$this->con->escape($id)."' "; 655 655 656 656 $rs = $this->con->select($strReq); 657 657 658 658 $res = array(); 659 659 660 660 while ($rs->fetch()) 661 661 { … … 666 666 ); 667 667 } 668 668 669 669 return $res; 670 670 } 671 671 672 672 /** 673 673 Sets user permissions. The <var>$perms</var> array looks like: 674 674 675 675 - [blog_id] => '|perm1|perm2|' 676 676 - ... 677 677 678 678 @param id <b>string</b> User ID 679 679 @param perms <b>array</b> Permissions array … … 684 684 throw new Exception(__('You are not an administrator')); 685 685 } 686 686 687 687 $strReq = 'DELETE FROM '.$this->prefix.'permissions '. 688 688 "WHERE user_id = '".$this->con->escape($id)."' "; 689 689 690 690 $this->con->execute($strReq); 691 691 692 692 foreach ($perms as $blog_id => $p) { 693 693 $this->setUserBlogPermissions($id, $blog_id, $p, false); 694 694 } 695 695 } 696 696 697 697 /** 698 698 Sets user permissions for a given blog. <var>$perms</var> is an array with 699 699 permissions in values 700 700 701 701 @param id <b>string</b> User ID 702 702 @param blog_id <b>string</b> Blog ID … … 709 709 throw new Exception(__('You are not an administrator')); 710 710 } 711 711 712 712 $no_perm = empty($perms); 713 713 714 714 $perms = '|'.implode('|',array_keys($perms)).'|'; 715 715 716 716 $cur = $this->con->openCursor($this->prefix.'permissions'); 717 717 718 718 $cur->user_id = (string) $id; 719 719 $cur->blog_id = (string) $blog_id; 720 720 $cur->permissions = $perms; 721 721 722 722 if ($delete_first || $no_perm) 723 723 { … … 725 725 "WHERE blog_id = '".$this->con->escape($blog_id)."' ". 726 726 "AND user_id = '".$this->con->escape($id)."' "; 727 727 728 728 $this->con->execute($strReq); 729 729 } 730 730 731 731 if (!$no_perm) { 732 732 $cur->insert(); 733 733 } 734 734 } 735 735 736 736 /** 737 737 Sets a user default blog. This blog will be selected when user log in. 738 738 739 739 @param id <b>string</b> User ID 740 740 @param blog_id <b>string</b> Blog ID … … 743 743 { 744 744 $cur = $this->con->openCursor($this->prefix.'user'); 745 745 746 746 $cur->user_default_blog = (string) $blog_id; 747 747 748 748 $cur->update("WHERE user_id = '".$this->con->escape($id)."'"); 749 749 } 750 750 751 751 private function getUserCursor($cur) 752 752 { … … 755 755 throw new Exception(__('User ID must contain at least 2 characters using letters, numbers or symbols.')); 756 756 } 757 757 758 758 if ($cur->user_url !== null && $cur->user_url != '') { 759 759 if (!preg_match('|^http(s?)://|',$cur->user_url)) { … … 761 761 } 762 762 } 763 763 764 764 if ($cur->isField('user_pwd')) { 765 765 if (strlen($cur->user_pwd) < 6) { … … 768 768 $cur->user_pwd = crypt::hmac(DC_MASTER_KEY,$cur->user_pwd); 769 769 } 770 770 771 771 if ($cur->user_lang !== null && !preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$cur->user_lang)) { 772 772 throw new Exception(__('Invalid user language code')); 773 773 } 774 774 775 775 if ($cur->user_upddt === null) { 776 776 $cur->user_upddt = date('Y-m-d H:i:s'); 777 777 } 778 778 779 779 if ($cur->user_options !== null) { 780 780 $cur->user_options = serialize((array) $cur->user_options); 781 781 } 782 782 } 783 783 784 784 /** 785 785 Returns user default settings in an associative array with setting names in 786 786 keys. 787 787 788 788 @return <b>array</b> 789 789 */ … … 797 797 } 798 798 //@} 799 799 800 800 /// @name Blog management methods 801 801 //@{ 802 802 /** 803 803 Returns all blog permissions (users) as an array which looks like: 804 804 805 805 - [user_id] 806 806 - [name] => User name … … 811 811 - [permission] => true 812 812 - ... 813 813 814 814 @param id <b>string</b> Blog ID 815 815 @param with_super <b>boolean</b> Includes super admins in result … … 824 824 'JOIN '.$this->prefix.'permissions P ON U.user_id = P.user_id '. 825 825 "WHERE blog_id = '".$this->con->escape($id)."' "; 826 826 827 827 if ($with_super) { 828 828 $strReq .= … … 833 833 'WHERE user_super = 1 '; 834 834 } 835 835 836 836 $rs = $this->con->select($strReq); 837 837 838 838 $res = array(); 839 839 840 840 while ($rs->fetch()) 841 841 { … … 849 849 ); 850 850 } 851 851 852 852 return $res; 853 853 } 854 854 855 855 /** 856 856 Returns a blog of given ID. 857 857 858 858 @param id <b>string</b> Blog ID 859 859 @return <b>record</b> … … 862 862 { 863 863 $blog = $this->getBlogs(array('blog_id'=>$id)); 864 864 865 865 if ($blog->isEmpty()) { 866 866 return false; 867 867 } 868 868 869 869 return $blog; 870 870 } 871 871 872 872 /** 873 873 Returns a record of blogs. <b>$params</b> is an array with the following 874 874 optionnal parameters: 875 875 876 876 - <var>blog_id</var>: Blog ID 877 877 - <var>q</var>: Search string on blog_id, blog_name and blog_url 878 878 - <var>limit</var>: limit results 879 879 880 880 @param params <b>array</b> Parameters 881 881 @param count_only <b>boolean</b> Count only results … … 886 886 $join = ''; // %1$s 887 887 $where = ''; // %2$s 888 888 889 889 if ($count_only) 890 890 { … … 904 904 'WHERE NULL IS NULL '. 905 905 '%2$s '; 906 906 907 907 if (!empty($params['order'])) { 908 908 $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; … … 910 910 $strReq .= 'ORDER BY B.blog_id ASC '; 911 911 } 912 912 913 913 if (!empty($params['limit'])) { 914 914 $strReq .= $this->con->limit($params['limit']); 915 915 } 916 916 } 917 917 918 918 if ($this->auth->userID() && !$this->auth->isSuperAdmin()) 919 919 { … … 926 926 $where = 'AND blog_status IN (1,0) '; 927 927 } 928 928 929 929 if (!empty($params['blog_id'])) { 930 930 $where .= "AND B.blog_id = '".$this->con->escape($params['blog_id'])."' "; 931 931 } 932 932 933 933 if (!empty($params['q'])) { 934 934 $params['q'] = strtolower(str_replace('*','%',$params['q'])); … … 940 940 ') '; 941 941 } 942 942 943 943 $strReq = sprintf($strReq,$join,$where); 944 944 return $this->con->select($strReq); 945 945 } 946 946 947 947 /** 948 948 Creates a new blog. 949 949 950 950 @param cur <b>cursor</b> Blog cursor 951 951 */ … … 955 955 throw new Exception(__('You are not an administrator')); 956 956 } 957 957 958 958 $this->getBlogCursor($cur); 959 959 960 960 $cur->blog_creadt = date('Y-m-d H:i:s'); 961 961 $cur->blog_upddt = date('Y-m-d H:i:s'); 962 962 $cur->blog_uid = md5(uniqid()); 963 963 964 964 $cur->insert(); 965 965 } 966 966 967 967 /** 968 968 Updates a given blog. 969 969 970 970 @param id <b>string</b> Blog ID 971 971 @param cur <b>cursor</b> Blog cursor … … 974 974 { 975 975 $this->getBlogCursor($cur); 976 976 977 977 $cur->blog_upddt = date('Y-m-d H:i:s'); 978 978 979 979 $cur->update("WHERE blog_id = '".$this->con->escape($id)."'"); 980 980 } 981 981 982 982 private function getBlogCursor($cur) 983 983 { 984 984 if ($cur->blog_id !== null 985 985 && !preg_match('/^[A-Za-z0-9._-]{2,}$/',$cur->blog_id)) { 986 throw new Exception(__('Blog ID must contain at least 2 characters using letters, numbers or symbols.')); 987 } 988 986 throw new Exception(__('Blog ID must contain at least 2 characters using letters, numbers or symbols.')); 987 } 988 989 989 if ($cur->blog_name !== null && $cur->blog_name == '') { 990 990 throw new Exception(__('No blog name')); 991 991 } 992 992 993 993 if ($cur->blog_url !== null && $cur->blog_url == '') { 994 994 throw new Exception(__('No blog URL')); 995 995 } 996 996 997 997 if ($cur->blog_desc !== null) { 998 998 $cur->blog_desc = html::clean($cur->blog_desc); 999 999 } 1000 1000 } 1001 1001 1002 1002 /** 1003 1003 Removes a given blog. 1004 1004 @warning This will remove everything related to the blog (posts, 1005 1005 categories, comments, links...) 1006 1006 1007 1007 @param id <b>string</b> Blog ID 1008 1008 */ … … 1012 1012 throw new Exception(__('You are not an administrator')); 1013 1013 } 1014 1014 1015 1015 $strReq = 'DELETE FROM '.$this->prefix.'blog '. 1016 1016 "WHERE blog_id = '".$this->con->escape($id)."' "; 1017 1017 1018 1018 $this->con->execute($strReq); 1019 1019 } 1020 1020 1021 1021 /** 1022 1022 Checks if a blog exist. 1023 1023 1024 1024 @param id <b>string</b> Blog ID 1025 1025 @return <b>boolean</b> … … 1030 1030 'FROM '.$this->prefix.'blog '. 1031 1031 "WHERE blog_id = '".$this->con->escape($id)."' "; 1032 1032 1033 1033 $rs = $this->con->select($strReq); 1034 1034 1035 1035 return !$rs->isEmpty(); 1036 1036 } 1037 1037 1038 1038 /** 1039 1039 Count posts on a blog 1040 1040 1041 1041 @param id <b>string</b> Blog ID 1042 1042 @param type <b>string</b> Post type … … 1048 1048 'FROM '.$this->prefix.'post '. 1049 1049 "WHERE blog_id = '".$this->con->escape($id)."' "; 1050 1050 1051 1051 if ($type) { 1052 1052 $strReq .= "AND post_type = '".$this->con->escape($type)."' "; 1053 1053 } 1054 1054 1055 1055 return $this->con->select($strReq)->f(0); 1056 1056 } 1057 1057 //@} 1058 1058 1059 1059 /// @name HTML Filter methods 1060 1060 //@{ … … 1063 1063 tidy extension is present). If <b>enable_html_filter</b> blog setting is 1064 1064 false, returns not filtered string. 1065 1065 1066 1066 @param str <b>string</b> String to filter 1067 1067 @return <b>string</b> Filtered string. … … 1072 1072 return $str; 1073 1073 } 1074 1074 1075 1075 $filter = new htmlFilter; 1076 1076 $str = trim($filter->apply($str)); … … 1078 1078 } 1079 1079 //@} 1080 1080 1081 1081 /// @name wiki2xhtml methods 1082 1082 //@{ … … 1085 1085 $this->wiki2xhtml = new wiki2xhtml; 1086 1086 } 1087 1087 1088 1088 /** 1089 1089 Returns a transformed string with wiki2xhtml. 1090 1090 1091 1091 @param str <b>string</b> String to transform 1092 1092 @return <b>string</b> Transformed string … … 1099 1099 return $this->wiki2xhtml->transform($str); 1100 1100 } 1101 1101 1102 1102 /** 1103 1103 Inits <var>wiki2xhtml</var> property for blog post. … … 1106 1106 { 1107 1107 $this->initWiki(); 1108 1108 1109 1109 $this->wiki2xhtml->setOpts(array( 1110 1110 'active_title' => 1, … … 1138 1138 'note_str' => '<div class="footnotes"><h4>Notes</h4>%s</div>' 1139 1139 )); 1140 1140 1141 1141 $this->wiki2xhtml->registerFunction('url:post',array($this,'wikiPostLink')); 1142 1142 1143 1143 # --BEHAVIOR-- coreWikiPostInit 1144 1144 $this->callBehavior('coreInitWikiPost',$this->wiki2xhtml); 1145 1145 } 1146 1146 1147 1147 /** 1148 1148 Inits <var>wiki2xhtml</var> property for simple blog comment (basic syntax). … … 1151 1151 { 1152 1152 $this->initWiki(); 1153 1153 1154 1154 $this->wiki2xhtml->setOpts(array( 1155 1155 'active_title' => 0, … … 1180 1180 'active_fr_syntax' => 0 1181 1181 )); 1182 1182 1183 1183 # --BEHAVIOR-- coreInitWikiSimpleComment 1184 1184 $this->callBehavior('coreInitWikiSimpleComment',$this->wiki2xhtml); 1185 1185 } 1186 1186 1187 1187 /** 1188 1188 Inits <var>wiki2xhtml</var> property for blog comment. … … 1191 1191 { 1192 1192 $this->initWiki(); 1193 1193 1194 1194 $this->wiki2xhtml->setOpts(array( 1195 1195 'active_title' => 0, … … 1220 1220 'active_fr_syntax' => 0 1221 1221 )); 1222 1222 1223 1223 # --BEHAVIOR-- coreInitWikiComment 1224 1224 $this->callBehavior('coreInitWikiComment',$this->wiki2xhtml); 1225 1225 } 1226 1226 1227 1227 public function wikiPostLink($url,$content) 1228 1228 { 1229 if (!($this->blog instanceof dcBlog)) { 1229 if (!($this->blog instanceof dcBlog)) { 1230 1230 return array(); 1231 1231 } 1232 1232 1233 1233 $post_id = abs((integer) substr($url,5)); 1234 1234 if (!$post_id) { 1235 1235 return array(); 1236 1236 } 1237 1237 1238 1238 $post = $this->blog->getPosts(array('post_id'=>$post_id)); 1239 1239 if ($post->isEmpty()) { 1240 1240 return array(); 1241 1241 } 1242 1242 1243 1243 $res = array('url' => $post->getURL()); 1244 1244 $post_title = $post->post_title; 1245 1245 1246 1246 if ($content != $url) { 1247 1247 $res['title'] = html::escapeHTML($post->post_title); 1248 1248 } 1249 1249 1250 1250 if ($content == '' || $content == $url) { 1251 1251 $res['content'] = html::escapeHTML($post->post_title); 1252 1252 } 1253 1253 1254 1254 if ($post->post_lang) { 1255 1255 $res['lang'] = $post->post_lang; 1256 1256 } 1257 1257 1258 1258 return $res; 1259 1259 } 1260 1260 //@} 1261 1261 1262 1262 /// @name Maintenance methods 1263 1263 //@{ … … 1265 1265 Creates default settings for active blog. Optionnal parameter 1266 1266 <var>defaults</var> replaces default params while needed. 1267 1267 1268 1268 @param defaults <b>array</b> Default parameters 1269 1269 */ … … 1348 1348 ); 1349 1349 } 1350 1350 1351 1351 $settings = new dcSettings($this,null); 1352 1352 $settings->addNamespace('system'); 1353 1353 1354 1354 foreach ($defaults as $v) { 1355 1355 $settings->system->put($v[0],$v[2],$v[1],$v[3],false,true); 1356 1356 } 1357 1357 } 1358 1358 1359 1359 /** 1360 1360 Recreates entries search engine index. 1361 1361 1362 1362 @param start <b>integer</b> Start entry index 1363 1363 @param limit <b>integer</b> Number of entry to index 1364 1364 1365 1365 @return <b>integer</b> <var>$start</var> and <var>$limit</var> sum 1366 1366 */ … … 1371 1371 $rs = $this->con->select($strReq); 1372 1372 $count = $rs->f(0); 1373 1373 1374 1374 $strReq = 'SELECT post_id, post_title, post_excerpt_xhtml, post_content_xhtml '. 1375 1375 'FROM '.$this->prefix.'post '; 1376 1376 1377 1377 if ($start !== null && $limit !== null) { 1378 1378 $strReq .= $this->con->limit($start,$limit); 1379 1379 } 1380 1380 1381 1381 $rs = $this->con->select($strReq,true); 1382 1382 1383 1383 $cur = $this->con->openCursor($this->prefix.'post'); 1384 1384 1385 1385 while ($rs->fetch()) 1386 1386 { 1387 1387 $words = $rs->post_title.' '. $rs->post_excerpt_xhtml.' '. 1388 1388 $rs->post_content_xhtml; 1389 1389 1390 1390 $cur->post_words = implode(' ',text::splitWords($words)); 1391 1391 $cur->update('WHERE post_id = '.(integer) $rs->post_id); 1392 1392 $cur->clean(); 1393 1393 } 1394 1394 1395 1395 if ($start+$limit > $count) { 1396 1396 return null; … … 1398 1398 return $start+$limit; 1399 1399 } 1400 1400 1401 1401 /** 1402 1402 Recreates comments search engine index. 1403 1403 1404 1404 @param start <b>integer</b> Start comment index 1405 1405 @param limit <b>integer</b> Number of comments to index 1406 1406 1407 1407 @return <b>integer</b> <var>$start</var> and <var>$limit</var> sum 1408 1408 */ … … 1413 1413 $rs = $this->con->select($strReq); 1414 1414 $count = $rs->f(0); 1415 1415 1416 1416 $strReq = 'SELECT comment_id, comment_content '. 1417 1417 'FROM '.$this->prefix.'comment '; 1418 1418 1419 1419 if ($start !== null && $limit !== null) { 1420 1420 $strReq .= $this->con->limit($start,$limit); 1421 1421 } 1422 1422 1423 1423 $rs = $this->con->select($strReq); 1424 1424 1425 1425 $cur = $this->con->openCursor($this->prefix.'comment'); 1426 1426 1427 1427 while ($rs->fetch()) 1428 1428 { … … 1431 1431 $cur->clean(); 1432 1432 } 1433 1433 1434 1434 if ($start+$limit > $count) { 1435 1435 return null; … … 1437 1437 return $start+$limit; 1438 1438 } 1439 1439 1440 1440 /** 1441 1441 Reinits nb_comment and nb_trackback in post table. … … 1443 1443 public function countAllComments() 1444 1444 { 1445 1445 1446 1446 $updCommentReq = 'UPDATE '.$this->prefix.'post P '. 1447 1447 'SET nb_comment = ('. … … 1459 1459 $this->con->execute($updTrackbackReq); 1460 1460 } 1461 1461 1462 1462 /** 1463 1463 Empty templates cache directory … … 1471 1471 //@} 1472 1472 } 1473 ?>
Note: See TracChangeset
for help on using the changeset viewer.