1<?php 2/** 3 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 4 * @author Esther Brunner <wikidesign@gmail.com> 5 */ 6 7// must be run within Dokuwiki 8if (!defined('DOKU_INC')) die(); 9 10if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); 11if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 12if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13 14require_once(DOKU_PLUGIN.'action.php'); 15 16class action_plugin_discussion extends DokuWiki_Action_Plugin{ 17 18 var $avatar = null; 19 var $style = null; 20 var $use_avatar = null; 21 22 function getInfo() { 23 return array( 24 'author' => 'Gina Häußge, Michael Klier, Esther Brunner', 25 'email' => 'dokuwiki@chimeric.de', 26 'date' => @file_get_contents(DOKU_PLUGIN.'discussion/VERSION'), 27 'name' => 'Discussion Plugin (action component)', 28 'desc' => 'Enables discussion features', 29 'url' => 'http://wiki.splitbrain.org/plugin:discussion', 30 ); 31 } 32 33 function register(&$contr) { 34 $contr->register_hook( 35 'ACTION_ACT_PREPROCESS', 36 'BEFORE', 37 $this, 38 'handle_act_preprocess', 39 array() 40 ); 41 $contr->register_hook( 42 'TPL_ACT_RENDER', 43 'AFTER', 44 $this, 45 'comments', 46 array() 47 ); 48 $contr->register_hook( 49 'INDEXER_PAGE_ADD', 50 'AFTER', 51 $this, 52 'idx_add_discussion', 53 array() 54 ); 55 $contr->register_hook( 56 'TPL_METAHEADER_OUTPUT', 57 'BEFORE', 58 $this, 59 'handle_tpl_metaheader_output', 60 array() 61 ); 62 $contr->register_hook( 63 'TOOLBAR_DEFINE', 64 'AFTER', 65 $this, 66 'handle_toolbar_define', 67 array() 68 ); 69 } 70 71 /** 72 * Modify Tollbar for use with discussion plugin 73 * 74 * @author Michael Klier <chi@chimeric.de> 75 */ 76 function handle_toolbar_define(&$event, $param) { 77 global $ACT; 78 if($ACT != 'show') return; 79 80 if($this->_hasDiscussion($title) && $this->getConf('wikisyntaxok')) { 81 $toolbar = array(); 82 foreach($event->data as $btn) { 83 if($btn['type'] == 'mediapopup') continue; 84 if($btn['type'] == 'signature') continue; 85 if(preg_match("/=+?/", $btn['open'])) continue; 86 array_push($toolbar, $btn); 87 } 88 $event->data = $toolbar; 89 } 90 } 91 92 /** 93 * Dirty workaround to add a toolbar to the discussion plugin 94 * 95 * @author Michael Klier <chi@chimeric.de> 96 */ 97 function handle_tpl_metaheader_output(&$event, $param) { 98 global $ACT; 99 global $ID; 100 if($ACT != 'show') return; 101 102 // FIXME check if this works for global discussion/on too 103 if($this->_hasDiscussion($title) && $this->getConf('wikisyntaxok')) { 104 // FIXME ugly workaround, replace this once DW the toolbar code is more flexible 105 array_unshift($event->data['script'], array('type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => DOKU_BASE.'lib/scripts/edit.js')); 106 @require_once(DOKU_INC.'inc/toolbar.php'); 107 ob_start(); 108 print 'NS = "' . getNS($ID) . '";'; // we have to define NS, otherwise we get get JS errors 109 toolbar_JSdefines('toolbar'); 110 $script = ob_get_clean(); 111 array_push($event->data['script'], array('type' => 'text/javascript', 'charset' => "utf-8", '_data' => $script)); 112 } 113 } 114 115 /** 116 * Handles comment actions, dispatches data processing routines 117 */ 118 function handle_act_preprocess(&$event, $param) { 119 global $ID; 120 global $INFO; 121 global $conf; 122 global $lang; 123 124 // handle newthread ACTs 125 if ($event->data == 'newthread') { 126 // we can handle it -> prevent others 127 $event->preventDefault(); 128 $event->data = $this->_newThread(); 129 } 130 131 // enable captchas 132 if ((in_array($_REQUEST['comment'], array('add', 'save'))) 133 && (@file_exists(DOKU_PLUGIN.'captcha/action.php'))) { 134 $this->_captchaCheck(); 135 } 136 137 // if we are not in show mode or someone wants to unsubscribe, that was all for now 138 if ($event->data != 'show' && $event->data != 'unsubscribe' && $event->data != 'confirmsubscribe') return; 139 140 if ($event->data == 'unsubscribe' or $event->data == 'confirmsubscribe') { 141 // ok we can handle it prevent others 142 $event->preventDefault(); 143 144 if (!isset($_REQUEST['hash'])) { 145 return false; 146 } else { 147 $file = metaFN($ID, '.comments'); 148 $data = unserialize(io_readFile($file)); 149 foreach($data['subscribers'] as $mail => $info) { 150 // convert old style subscribers just in case 151 if(!is_array($info)) { 152 $hash = $data['subscribers'][$mail]; 153 $data['subscribers'][$mail]['hash'] = $hash; 154 $data['subscribers'][$mail]['active'] = true; 155 $data['subscribers'][$mail]['confirmsent'] = true; 156 } 157 } 158 159 if($data['subscribers'][$mail]['hash'] == $_REQUEST['hash']) { 160 if($event->data == 'unsubscribe') { 161 unset($data['subscribers'][$mail]); 162 msg(sprintf($lang['unsubscribe_success'], $mail, $ID), 1); 163 } elseif($event->data == 'confirmsubscribe') { 164 $data['subscribers'][$mail]['active'] = true; 165 msg(sprintf($lang['subscribe_success'], $mail, $ID), 1); 166 } 167 io_saveFile($file, serialize($data)); 168 $event->data = 'show'; 169 return true; 170 } else { 171 return false; 172 } 173 } 174 } else { 175 // do the data processing for comments 176 $cid = $_REQUEST['cid']; 177 switch ($_REQUEST['comment']) { 178 case 'add': 179 if(empty($_REQUEST['text'])) return; // don't add empty comments 180 if(isset($_SERVER['REMOTE_USER']) && !$this->getConf('adminimport')) { 181 $comment['user']['id'] = $_SERVER['REMOTE_USER']; 182 $comment['user']['name'] = $INFO['userinfo']['name']; 183 $comment['user']['mail'] = $INFO['userinfo']['mail']; 184 } elseif((isset($_SERVER['REMOTE_USER']) && $this->getConf('adminimport') && auth_ismanager()) || !isset($_SERVER['REMOTE_USER'])) { 185 if(empty($_REQUEST['name']) or empty($_REQUEST['mail'])) return // don't add anonymous comments 186 $comment['user']['id'] = 'test'.hsc($_REQUEST['user']); 187 $comment['user']['name'] = hsc($_REQUEST['name']); 188 $comment['user']['mail'] = hsc($_REQUEST['mail']); 189 } 190 $comment['user']['address'] = ($this->getConf('addressfield')) ? hsc($_REQUEST['address']) : ''; 191 $comment['user']['url'] = ($this->getConf('urlfield')) ? $this->_checkURL($_REQUEST['url']) : ''; 192 $comment['subscribe'] = ($this->getConf('subscribe')) ? $_REQUEST['subscribe'] : ''; 193 $comment['date'] = array('created' => $_REQUEST['date']); 194 $comment['raw'] = cleanText($_REQUEST['text']); 195 $repl = $_REQUEST['reply']; 196 if($this->getConf('moderate') && !auth_ismanager()) { 197 $comment['show'] = false; 198 } else { 199 $comment['show'] = true; 200 } 201 $this->_add($comment, $repl); 202 break; 203 204 case 'save': 205 $raw = cleanText($_REQUEST['text']); 206 $this->_save(array($cid), $raw); 207 break; 208 209 case 'delete': 210 $this->_save(array($cid), ''); 211 break; 212 213 case 'toogle': 214 $this->_save(array($cid), '', 'toogle'); 215 break; 216 } 217 } 218 219 // FIXME use new TPL_TOC_RENDER event in the future 220 if(count($INFO['meta']['description']['tableofcontents']) >= ($conf['maxtoclevel']-1) && $INFO['meta']['internal']['toc']) { 221 222 $TOC = array(); 223 global $TOC; 224 $TOC = $INFO['meta']['description']['tableofcontents']; 225 226 $tocitem = array( 'hid' => 'discussion__section', 227 'title' => $this->getLang('discussion'), 228 'type' => 'ul', 229 'level' => 1 ); 230 231 $file = metaFN($ID, '.comments'); 232 if(@file_exists($file)) { 233 $data = unserialize(io_readFile($file)); 234 if($data['status'] != 0 && !empty($TOC)) { 235 $TOC[] = $tocitem; 236 } 237 } 238 } 239 } 240 241 /** 242 * Main function; dispatches the visual comment actions 243 */ 244 function comments(&$event, $param) { 245 if ($event->data != 'show') return; // nothing to do for us 246 247 $cid = $_REQUEST['cid']; 248 switch ($_REQUEST['comment']) { 249 case 'edit': 250 $this->_show(NULL, $cid); 251 break; 252 default: 253 $this->_show($cid); 254 break; 255 } 256 } 257 258 /** 259 * Redirects browser to given comment anchor 260 */ 261 function _redirect($cid) { 262 global $ID; 263 global $ACT; 264 265 if ($ACT !== 'show') return; 266 267 if($this->getConf('moderate') && !auth_ismanager()) { 268 msg($this->getLang('moderation'), 1); 269 @session_start(); 270 global $MSG; 271 $_SESSION[DOKU_COOKIE]['msg'] = $MSG; 272 session_write_close(); 273 $url = wl($ID); 274 } else { 275 $url = wl($ID) . '#comment_' . $cid; 276 } 277 send_redirect($url); 278 exit(); 279 } 280 281 /** 282 * Shows all comments of the current page 283 */ 284 function _show($reply = NULL, $edit = NULL) { 285 global $ID; 286 global $INFO; 287 global $ACT; 288 289 // get .comments meta file name 290 $file = metaFN($ID, '.comments'); 291 292 if (!$INFO['exists']) return; 293 if (!@file_exists($file) && !$this->getConf('automatic')) return false; 294 295 // load data 296 if (@file_exists($file)) { 297 $data = unserialize(io_readFile($file, false)); 298 if (!$data['status']) return false; // comments are turned off 299 } elseif (!@file_exists($file) && $this->getConf('automatic') && $INFO['exists']) { 300 // set status to show the comment form 301 $data['status'] = 1; 302 $data['number'] = 0; 303 } 304 305 // section title 306 $title = ($data['title'] ? hsc($data['title']) : $this->getLang('discussion')); 307 ptln('<div class="comment_wrapper">'); 308 ptln('<h2><a name="discussion__section" id="discussion__section">', 2); 309 ptln($title, 4); 310 ptln('</a></h2>', 2); 311 ptln('<div class="level2 hfeed">', 2); 312 // now display the comments 313 if (isset($data['comments'])) { 314 if (!$this->getConf('usethreading')) { 315 $data['comments'] = $this->_flattenThreads($data['comments']); 316 uasort($data['comments'], '_sortCallBack'); 317 } 318 if($this->getConf('newestfirst')) { 319 $data['comments'] = array_reverse($data['comments']); 320 } 321 foreach ($data['comments'] as $key => $value) { 322 if ($key == $edit) $this->_form($value['raw'], 'save', $edit); // edit form 323 else $this->_print($key, $data, '', $reply); 324 } 325 } 326 327 // comment form 328 if (($data['status'] == 1) && (!$reply || !$this->getConf('usethreading')) && !$edit) $this->_form(''); 329 330 ptln('</div>', 2); // level2 hfeed 331 ptln('</div>'); // comment_wrapper 332 333 return true; 334 } 335 336 function _flattenThreads($comments, $keys = null) { 337 if (is_null($keys)) 338 $keys = array_keys($comments); 339 340 foreach($keys as $cid) { 341 if (!empty($comments[$cid]['replies'])) { 342 $rids = $comments[$cid]['replies']; 343 $comments = $this->_flattenThreads($comments, $rids); 344 $comments[$cid]['replies'] = array(); 345 } 346 $comments[$cid]['parent'] = ''; 347 } 348 return $comments; 349 } 350 351 /** 352 * Adds a new comment and then displays all comments 353 */ 354 function _add($comment, $parent) { 355 global $lang; 356 global $ID; 357 global $TEXT; 358 359 $otxt = $TEXT; // set $TEXT to comment text for wordblock check 360 $TEXT = $comment['raw']; 361 362 // spamcheck against the DokuWiki blacklist 363 if (checkwordblock()) { 364 msg($this->getLang('wordblock'), -1); 365 return false; 366 } 367 368 if ((!$this->getConf('allowguests')) 369 && ($comment['user']['id'] != $_SERVER['REMOTE_USER'])) 370 return false; // guest comments not allowed 371 372 $TEXT = $otxt; // restore global $TEXT 373 374 // get discussion meta file name 375 $file = metaFN($ID, '.comments'); 376 377 // create comments file if it doesn't exist yet 378 if(!@file_exists($file)) { 379 $data = array('status' => 1, 'number' => 0); 380 io_saveFile($file, serialize($data)); 381 } else { 382 $data = array(); 383 $data = unserialize(io_readFile($file, false)); 384 if ($data['status'] != 1) return false; // comments off or closed 385 } 386 387 if ($comment['date']['created']) { 388 $date = strtotime($comment['date']['created']); 389 } else { 390 $date = time(); 391 } 392 393 if ($date == -1) { 394 $date = time(); 395 } 396 397 $cid = md5($comment['user']['id'].$date); // create a unique id 398 399 if (!is_array($data['comments'][$parent])) { 400 $parent = NULL; // invalid parent comment 401 } 402 403 // render the comment 404 $xhtml = $this->_render($comment['raw']); 405 406 // fill in the new comment 407 $data['comments'][$cid] = array( 408 'user' => $comment['user'], 409 'date' => array('created' => $date), 410 'show' => true, 411 'raw' => $comment['raw'], 412 'xhtml' => $xhtml, 413 'parent' => $parent, 414 'replies' => array(), 415 'show' => $comment['show'] 416 ); 417 418 if($comment['subscribe']) { 419 $mail = $comment['user']['mail']; 420 if($data['subscribers']) { 421 if(!$data['subscribers'][$mail]) { 422 $data['subscribers'][$mail]['hash'] = md5($mail . mt_rand()); 423 $data['subscribers'][$mail]['active'] = false; 424 $data['subscribers'][$mail]['confirmsent'] = false; 425 } else { 426 // convert old style subscribers and set them active 427 if(!is_array($data['subscribers'][$mail])) { 428 $hash = $data['subscribers'][$mail]; 429 $data['subscribers'][$mail]['hash'] = $hash; 430 $data['subscribers'][$mail]['active'] = true; 431 $data['subscribers'][$mail]['confirmsent'] = true; 432 } 433 } 434 } else { 435 $data['subscribers'][$mail]['hash'] = md5($mail . mt_rand()); 436 $data['subscribers'][$mail]['active'] = false; 437 $data['subscribers'][$mail]['confirmsent'] = false; 438 } 439 } 440 441 // update parent comment 442 if ($parent) $data['comments'][$parent]['replies'][] = $cid; 443 444 // update the number of comments 445 $data['number']++; 446 447 // notify subscribers of the page 448 $data['comments'][$cid]['cid'] = $cid; 449 $this->_notify($data['comments'][$cid], $data['subscribers']); 450 451 // save the comment metadata file 452 io_saveFile($file, serialize($data)); 453 $this->_addLogEntry($date, $ID, 'cc', '', $cid); 454 455 $this->_redirect($cid); 456 return true; 457 } 458 459 /** 460 * Saves the comment with the given ID and then displays all comments 461 */ 462 function _save($cids, $raw, $act = NULL) { 463 global $ID; 464 465 if ($raw) { 466 global $TEXT; 467 468 $otxt = $TEXT; // set $TEXT to comment text for wordblock check 469 $TEXT = $raw; 470 471 // spamcheck against the DokuWiki blacklist 472 if (checkwordblock()) { 473 msg($this->getLang('wordblock'), -1); 474 return false; 475 } 476 477 $TEXT = $otxt; // restore global $TEXT 478 } 479 480 // get discussion meta file name 481 $file = metaFN($ID, '.comments'); 482 $data = unserialize(io_readFile($file, false)); 483 484 if (!is_array($cids)) $cids = array($cids); 485 foreach ($cids as $cid) { 486 487 if (is_array($data['comments'][$cid]['user'])) { 488 $user = $data['comments'][$cid]['user']['id']; 489 $convert = false; 490 } else { 491 $user = $data['comments'][$cid]['user']; 492 $convert = true; 493 } 494 495 // someone else was trying to edit our comment -> abort 496 if (($user != $_SERVER['REMOTE_USER']) && (!auth_ismanager())) return false; 497 498 $date = time(); 499 500 // need to convert to new format? 501 if ($convert) { 502 $data['comments'][$cid]['user'] = array( 503 'id' => $user, 504 'name' => $data['comments'][$cid]['name'], 505 'mail' => $data['comments'][$cid]['mail'], 506 'url' => $data['comments'][$cid]['url'], 507 'address' => $data['comments'][$cid]['address'], 508 ); 509 $data['comments'][$cid]['date'] = array( 510 'created' => $data['comments'][$cid]['date'] 511 ); 512 } 513 514 if ($act == 'toogle') { // toogle visibility 515 $now = $data['comments'][$cid]['show']; 516 $data['comments'][$cid]['show'] = !$now; 517 $data['number'] = $this->_count($data); 518 519 $type = ($data['comments'][$cid]['show'] ? 'sc' : 'hc'); 520 521 } elseif ($act == 'show') { // show comment 522 $data['comments'][$cid]['show'] = true; 523 $data['number'] = $this->_count($data); 524 525 $type = 'sc'; // show comment 526 527 } elseif ($act == 'hide') { // hide comment 528 $data['comments'][$cid]['show'] = false; 529 $data['number'] = $this->_count($data); 530 531 $type = 'hc'; // hide comment 532 533 } elseif (!$raw) { // remove the comment 534 $data['comments'] = $this->_removeComment($cid, $data['comments']); 535 $data['number'] = $this->_count($data); 536 537 $type = 'dc'; // delete comment 538 539 } else { // save changed comment 540 $xhtml = $this->_render($raw); 541 542 // now change the comment's content 543 $data['comments'][$cid]['date']['modified'] = $date; 544 $data['comments'][$cid]['raw'] = $raw; 545 $data['comments'][$cid]['xhtml'] = $xhtml; 546 547 $type = 'ec'; // edit comment 548 } 549 } 550 551 // save the comment metadata file 552 io_saveFile($file, serialize($data)); 553 $this->_addLogEntry($date, $ID, $type, '', $cid); 554 555 $this->_redirect($cid); 556 return true; 557 } 558 559 /** 560 * Recursive function to remove a comment 561 */ 562 function _removeComment($cid, $comments) { 563 if (is_array($comments[$cid]['replies'])) { 564 foreach ($comments[$cid]['replies'] as $rid) { 565 $comments = $this->_removeComment($rid, $comments); 566 } 567 } 568 unset($comments[$cid]); 569 return $comments; 570 } 571 572 /** 573 * Prints an individual comment 574 */ 575 function _print($cid, &$data, $parent = '', $reply = '', $visible = true) { 576 577 if (!isset($data['comments'][$cid])) return false; // comment was removed 578 $comment = $data['comments'][$cid]; 579 580 if (!is_array($comment)) return false; // corrupt datatype 581 582 if ($comment['parent'] != $parent) return true; // reply to an other comment 583 584 if (!$comment['show']) { // comment hidden 585 if (auth_ismanager()) $hidden = ' comment_hidden'; 586 else return true; 587 } else { 588 $hidden = ''; 589 } 590 591 if($this->getConf('newestfirst')) { 592 // reply form 593 $this->_print_form($cid, $reply); 594 // replies to this comment entry? 595 $this->_print_replies($cid, $data, $reply, $visible); 596 // print the actual comment 597 $this->_print_comment($cid, $data, $parent, $reply, $visible, $hidden); 598 } else { 599 // print the actual comment 600 $this->_print_comment($cid, $data, $parent, $reply, $visible, $hidden); 601 // replies to this comment entry? 602 $this->_print_replies($cid, $data, $reply, $visible); 603 // reply form 604 $this->_print_form($cid, $reply); 605 } 606 } 607 608 function _print_comment($cid, &$data, $parent, $reply, $visible, $hidden) 609 { 610 global $conf, $lang, $ID, $HIGH; 611 $comment = $data['comments'][$cid]; 612 613 // comment head with date and user data 614 ptln('<div class="hentry'.$hidden.'">', 4); 615 ptln('<div class="comment_head">', 6); 616 ptln('<a name="comment_'.$cid.'" id="comment_'.$cid.'"></a>', 8); 617 $head = '<span class="vcard author">'; 618 619 // prepare variables 620 if (is_array($comment['user'])) { // new format 621 $user = $comment['user']['id']; 622 $name = $comment['user']['name']; 623 $mail = $comment['user']['mail']; 624 $url = $comment['user']['url']; 625 $address = $comment['user']['address']; 626 } else { // old format 627 $user = $comment['user']; 628 $name = $comment['name']; 629 $mail = $comment['mail']; 630 $url = $comment['url']; 631 $address = $comment['address']; 632 } 633 if (is_array($comment['date'])) { // new format 634 $created = $comment['date']['created']; 635 $modified = $comment['date']['modified']; 636 } else { // old format 637 $created = $comment['date']; 638 $modified = $comment['edited']; 639 } 640 641 // show avatar image? 642 if ($this->_use_avatar()) { 643 644 $avatar = ''; 645 646 // check mail first 647 if ($mail) { 648 $avatar = $this->avatar->getXHTML($mail, $name, 'left'); 649 } 650 651 // okay maybe a user avatar? 652 // FIXME make namespace configurable 653 $files = @glob(mediaFN('user') . '/' . $user . '.*'); 654 if(!$avatar && $files) { 655 $avatar = $this->avatar->getXHTML($user, $name, 'left'); 656 } 657 658 // well it's a monster then 659 if(!$avatar) { 660 $avatar = $this->avatar->getXHTML($name, $name, 'left'); 661 } 662 663 $head .= $avatar; 664 665 } 666 667 if ($this->getConf('linkemail') && $mail) { 668 $head .= $this->email($mail, $name, 'email fn'); 669 } elseif ($url) { 670 $head .= $this->external_link($this->_checkURL($url), $name, 'urlextern url fn'); 671 } else { 672 $head .= '<span class="fn">'.$name.'</span>'; 673 } 674 if ($address) $head .= ', <span class="adr">'.$address.'</span>'; 675 $head .= '</span>, '. 676 '<abbr class="published" title="'.strftime('%Y-%m-%dT%H:%M:%SZ', $created).'">'. 677 strftime($conf['dformat'], $created).'</abbr>'; 678 if ($comment['edited']) $head .= ' (<abbr class="updated" title="'. 679 strftime('%Y-%m-%dT%H:%M:%SZ', $modified).'">'.strftime($conf['dformat'], $modified). 680 '</abbr>)'; 681 ptln($head, 8); 682 ptln('</div>', 6); // class="comment_head" 683 684 // main comment content 685 ptln('<div class="comment_body entry-content"'. 686 ($this->getConf('useavatar') ? $this->_get_style() : '').'>', 6); 687 echo ($HIGH?html_hilight($comment['xhtml'],$HIGH):$comment['xhtml']).DOKU_LF; 688 ptln('</div>', 6); // class="comment_body" 689 690 if ($visible) { 691 ptln('<div class="comment_buttons">', 6); 692 693 // show reply button? 694 if (($data['status'] == 1) && !$reply && $comment['show'] 695 && ($this->getConf('allowguests') || $_SERVER['REMOTE_USER']) && $this->getConf('usethreading')) 696 $this->_button($cid, $this->getLang('btn_reply'), 'reply', true); 697 698 // show edit, show/hide and delete button? 699 if ((($user == $_SERVER['REMOTE_USER']) && ($user != '')) || (auth_ismanager())) { 700 $this->_button($cid, $lang['btn_secedit'], 'edit', true); 701 $label = ($comment['show'] ? $this->getLang('btn_hide') : $this->getLang('btn_show')); 702 $this->_button($cid, $label, 'toogle'); 703 $this->_button($cid, $lang['btn_delete'], 'delete'); 704 } 705 ptln('</div>', 6); // class="comment_buttons" 706 } 707 ptln('</div>', 4); // class="hentry" 708 } 709 710 function _print_form($cid, $reply) 711 { 712 if ($this->getConf('usethreading') && $reply == $cid) { 713 ptln('<div class="comment_replies">', 4); 714 $this->_form('', 'add', $cid); 715 ptln('</div>', 4); // class="comment_replies" 716 } 717 } 718 719 function _print_replies($cid, &$data, $reply, &$visible) 720 { 721 $comment = $data['comments'][$cid]; 722 if (!count($comment['replies'])) { 723 return; 724 } 725 ptln('<div class="comment_replies"'.$this->_get_style().'>', 4); 726 $visible = ($comment['show'] && $visible); 727 foreach ($comment['replies'] as $rid) { 728 $this->_print($rid, $data, $cid, $reply, $visible); 729 } 730 ptln('</div>', 4); 731 } 732 733 function _use_avatar() 734 { 735 if (is_null($this->use_avatar)) { 736 $this->use_avatar = $this->getConf('useavatar') 737 && (!plugin_isdisabled('avatar')) 738 && ($this->avatar =& plugin_load('helper', 'avatar')); 739 } 740 return $this->use_avatar; 741 } 742 743 function _get_style() 744 { 745 if (is_null($this->style)){ 746 if ($this->_use_avatar()) { 747 $this->style = ' style="margin-left: '.($this->avatar->getConf('size') + 14).'px;"'; 748 } else { 749 $this->style = ' style="margin-left: 20px;"'; 750 } 751 } 752 return $this->style; 753 } 754 755 /** 756 * Outputs the comment form 757 */ 758 function _form($raw = '', $act = 'add', $cid = NULL) { 759 global $lang; 760 global $conf; 761 global $ID; 762 global $INFO; 763 764 // not for unregistered users when guest comments aren't allowed 765 if (!$_SERVER['REMOTE_USER'] && !$this->getConf('allowguests')) return false; 766 767 // fill $raw with $_REQUEST['text'] if it's empty (for failed CAPTCHA check) 768 if (!$raw && ($_REQUEST['comment'] == 'show')) $raw = $_REQUEST['text']; 769 ?> 770 771 <div class="comment_form"> 772 <form id="discussion__comment_form" method="post" action="<?php echo script() ?>" accept-charset="<?php echo $lang['encoding'] ?>"> 773 <div class="no"> 774 <input type="hidden" name="id" value="<?php echo $ID ?>" /> 775 <input type="hidden" name="do" value="show" /> 776 <input type="hidden" name="comment" value="<?php echo $act ?>" /> 777 <input type="hidden" name="wikisyntaxok" id="discussion__comment_wikisyntaxok" value="<?php echo $this->getConf('wikisyntaxok') ?>" /> 778 <?php 779 // for adding a comment 780 if ($act == 'add') { 781 ?> 782 <input type="hidden" name="reply" value="<?php echo $cid ?>" /> 783 <?php 784 // for guest/adminimport: show name, e-mail and subscribe to comments fields 785 if(!$_SERVER['REMOTE_USER'] or ($this->getConf('adminimport') && auth_ismanager())) { 786 ?> 787 <input type="hidden" name="user" value="<?php echo clientIP() ?>" /> 788 <div class="comment_name"> 789 <label class="block" for="discussion__comment_name"> 790 <span><?php echo $lang['fullname'] ?>:</span> 791 <input type="text" class="edit<?php if($_REQUEST['comment'] == 'add' && empty($_REQUEST['name'])) echo ' error'?>" name="name" id="discussion__comment_name" size="50" tabindex="1" value="<?php echo hsc($_REQUEST['name'])?>" /> 792 </label> 793 </div> 794 <div class="comment_mail"> 795 <label class="block" for="discussion__comment_mail"> 796 <span><?php echo $lang['email'] ?>:</span> 797 <input type="text" class="edit<?php if($_REQUEST['comment'] == 'add' && empty($_REQUEST['mail'])) echo ' error'?>" name="mail" id="discussion__comment_mail" size="50" tabindex="2" value="<?php echo hsc($_REQUEST['mail'])?>" /> 798 </label> 799 </div> 800 <?php 801 } 802 803 // allow entering an URL 804 if ($this->getConf('urlfield')) { 805 ?> 806 <div class="comment_url"> 807 <label class="block" for="discussion__comment_url"> 808 <span><?php echo $this->getLang('url') ?>:</span> 809 <input type="text" class="edit" name="url" id="discussion__comment_url" size="50" tabindex="3" value="<?php echo hsc($_REQUEST['url'])?>" /> 810 </label> 811 </div> 812 <?php 813 } 814 815 // allow entering an address 816 if ($this->getConf('addressfield')) { 817 ?> 818 <div class="comment_address"> 819 <label class="block" for="discussion__comment_address"> 820 <span><?php echo $this->getLang('address') ?>:</span> 821 <input type="text" class="edit" name="address" id="discussion__comment_address" size="50" tabindex="4" value="<?php echo hsc($_REQUEST['address'])?>" /> 822 </label> 823 </div> 824 <?php 825 } 826 827 // allow setting the comment date 828 if ($this->getConf('adminimport') && (auth_ismanager())) { 829 ?> 830 <div class="comment_date"> 831 <label class="block" for="discussion__comment_date"> 832 <span><?php echo $this->getLang('date') ?>:</span> 833 <input type="text" class="edit" name="date" id="discussion__comment_date" size="50" /> 834 </label> 835 </div> 836 <?php 837 } 838 839 // for saving a comment 840 } else { 841 ?> 842 <input type="hidden" name="cid" value="<?php echo $cid ?>" /> 843 <?php 844 } 845 ?> 846 <div class="comment_text"> 847 <div id="discussion__comment_toolbar"> 848 <?php echo $this->getLang('entercomment')?> 849 <?php if($this->getLang('wikisyntaxok')) echo ', ' . $this->getLang('wikisyntax') . ':';?> 850 </div> 851 <textarea class="edit<?php if($_REQUEST['comment'] == 'add' && empty($_REQUEST['text'])) echo ' error'?>" name="text" cols="80" rows="10" id="discussion__comment_text" tabindex="5"><?php 852 if($raw) { 853 echo formText($raw); 854 } else { 855 echo $_REQUEST['text']; 856 } 857 ?></textarea> 858 </div> 859 <?php //bad and dirty event insert hook 860 $evdata = array('writable' => true); 861 trigger_event('HTML_EDITFORM_INJECTION', $evdata); 862 ?> 863 <input class="button comment_submit" id="discussion__btn_submit" type="submit" name="submit" accesskey="s" value="<?php echo $lang['btn_save'] ?>" title="<?php echo $lang['btn_save']?> [S]" tabindex="7" /> 864 <input class="button comment_preview" id="discussion__btn_preview" type="button" name="preview" accesskey="p" value="<?php echo $lang['btn_preview'] ?>" title="<?php echo $lang['btn_preview']?> [P]" /> 865 866 <?php if((!$_SERVER['REMOTE_USER'] || $_SERVER['REMOTE_USER'] && !$conf['subscribers']) && $this->getConf('subscribe')) { ?> 867 <div class="comment_subscribe"> 868 <input type="checkbox" id="discussion__comment_subscribe" name="subscribe" tabindex="6" /> 869 <label class="block" for="discussion__comment_subscribe"> 870 <span><?php echo $this->getLang('subscribe') ?></span> 871 </label> 872 </div> 873 <?php } ?> 874 875 <div class="clearer"></div> 876 <div id="discussion__comment_preview"> </div> 877 </div> 878 </form> 879 </div> 880 <?php 881 if ($this->getConf('usecocomment')) echo $this->_coComment(); 882 } 883 884 /** 885 * Adds a javascript to interact with coComments 886 */ 887 function _coComment() { 888 global $ID; 889 global $conf; 890 global $INFO; 891 892 $user = $_SERVER['REMOTE_USER']; 893 894 ?> 895 <script type="text/javascript"><!--//--><![CDATA[//><!-- 896 var blogTool = "DokuWiki"; 897 var blogURL = "<?php echo DOKU_URL ?>"; 898 var blogTitle = "<?php echo $conf['title'] ?>"; 899 var postURL = "<?php echo wl($ID, '', true) ?>"; 900 var postTitle = "<?php echo tpl_pagetitle($ID, true) ?>"; 901 <?php 902 if ($user) { 903 ?> 904 var commentAuthor = "<?php echo $INFO['userinfo']['name'] ?>"; 905 <?php 906 } else { 907 ?> 908 var commentAuthorFieldName = "name"; 909 <?php 910 } 911 ?> 912 var commentAuthorLoggedIn = <?php echo ($user ? 'true' : 'false') ?>; 913 var commentFormID = "discussion__comment_form"; 914 var commentTextFieldName = "text"; 915 var commentButtonName = "submit"; 916 var cocomment_force = false; 917 //--><!]]></script> 918 <script type="text/javascript" src="http://www.cocomment.com/js/cocomment.js"> 919 </script> 920 <?php 921 } 922 923 /** 924 * General button function 925 */ 926 function _button($cid, $label, $act, $jump = false) { 927 global $ID; 928 929 $anchor = ($jump ? '#discussion__comment_form' : '' ); 930 931 ?> 932 <form class="button discussion__<?php echo $act?>" method="get" action="<?php echo script().$anchor ?>"> 933 <div class="no"> 934 <input type="hidden" name="id" value="<?php echo $ID ?>" /> 935 <input type="hidden" name="do" value="show" /> 936 <input type="hidden" name="comment" value="<?php echo $act ?>" /> 937 <input type="hidden" name="cid" value="<?php echo $cid ?>" /> 938 <input type="submit" value="<?php echo $label ?>" class="button" title="<?php echo $label ?>" /> 939 </div> 940 </form> 941 <?php 942 return true; 943 } 944 945 /** 946 * Adds an entry to the comments changelog 947 * 948 * @author Esther Brunner <wikidesign@gmail.com> 949 * @author Ben Coburn <btcoburn@silicodon.net> 950 */ 951 function _addLogEntry($date, $id, $type = 'cc', $summary = '', $extra = '') { 952 global $conf; 953 954 $changelog = $conf['metadir'].'/_comments.changes'; 955 956 if(!$date) $date = time(); //use current time if none supplied 957 $remote = $_SERVER['REMOTE_ADDR']; 958 $user = $_SERVER['REMOTE_USER']; 959 960 $strip = array("\t", "\n"); 961 $logline = array( 962 'date' => $date, 963 'ip' => $remote, 964 'type' => str_replace($strip, '', $type), 965 'id' => $id, 966 'user' => $user, 967 'sum' => str_replace($strip, '', $summary), 968 'extra' => str_replace($strip, '', $extra) 969 ); 970 971 // add changelog line 972 $logline = implode("\t", $logline)."\n"; 973 io_saveFile($changelog, $logline, true); //global changelog cache 974 $this->_trimRecentCommentsLog($changelog); 975 976 // tell the indexer to re-index the page 977 @unlink(metaFN($id, '.indexed')); 978 } 979 980 /** 981 * Trims the recent comments cache to the last $conf['changes_days'] recent 982 * changes or $conf['recent'] items, which ever is larger. 983 * The trimming is only done once a day. 984 * 985 * @author Ben Coburn <btcoburn@silicodon.net> 986 */ 987 function _trimRecentCommentsLog($changelog) { 988 global $conf; 989 990 if (@file_exists($changelog) && 991 (filectime($changelog) + 86400) < time() && 992 !@file_exists($changelog.'_tmp')) { 993 994 io_lock($changelog); 995 $lines = file($changelog); 996 if (count($lines)<$conf['recent']) { 997 // nothing to trim 998 io_unlock($changelog); 999 return true; 1000 } 1001 1002 io_saveFile($changelog.'_tmp', ''); // presave tmp as 2nd lock 1003 $trim_time = time() - $conf['recent_days']*86400; 1004 $out_lines = array(); 1005 1006 $num = count($lines); 1007 for ($i=0; $i<$num; $i++) { 1008 $log = parseChangelogLine($lines[$i]); 1009 if ($log === false) continue; // discard junk 1010 if ($log['date'] < $trim_time) { 1011 $old_lines[$log['date'].".$i"] = $lines[$i]; // keep old lines for now (append .$i to prevent key collisions) 1012 } else { 1013 $out_lines[$log['date'].".$i"] = $lines[$i]; // definitely keep these lines 1014 } 1015 } 1016 1017 // sort the final result, it shouldn't be necessary, 1018 // however the extra robustness in making the changelog cache self-correcting is worth it 1019 ksort($out_lines); 1020 $extra = $conf['recent'] - count($out_lines); // do we need extra lines do bring us up to minimum 1021 if ($extra > 0) { 1022 ksort($old_lines); 1023 $out_lines = array_merge(array_slice($old_lines,-$extra),$out_lines); 1024 } 1025 1026 // save trimmed changelog 1027 io_saveFile($changelog.'_tmp', implode('', $out_lines)); 1028 @unlink($changelog); 1029 if (!rename($changelog.'_tmp', $changelog)) { 1030 // rename failed so try another way... 1031 io_unlock($changelog); 1032 io_saveFile($changelog, implode('', $out_lines)); 1033 @unlink($changelog.'_tmp'); 1034 } else { 1035 io_unlock($changelog); 1036 } 1037 return true; 1038 } 1039 } 1040 1041 /** 1042 * Sends a notify mail on new comment 1043 * 1044 * @param array $comment data array of the new comment 1045 * 1046 * @author Andreas Gohr <andi@splitbrain.org> 1047 * @author Esther Brunner <wikidesign@gmail.com> 1048 */ 1049 function _notify($comment, &$subscribers) { 1050 global $conf; 1051 global $ID; 1052 1053 $notify_text = io_readfile($this->localfn('subscribermail')); 1054 $confirm_text = io_readfile($this->localfn('confirmsubscribe')); 1055 $subject_notify = '['.$conf['title'].'] '.$this->getLang('mail_newcomment'); 1056 $subject_subscribe = '['.$conf['title'].'] '.$this->getLang('subscribe'); 1057 1058 $search = array( 1059 '@PAGE@', 1060 '@TITLE@', 1061 '@DATE@', 1062 '@NAME@', 1063 '@TEXT@', 1064 '@COMMENTURL@', 1065 '@UNSUBSCRIBE@', 1066 '@DOKUWIKIURL@', 1067 ); 1068 1069 // notify page subscribers 1070 if ($conf['subscribers'] || $conf['notify']) { 1071 $list = explode(',', subscriber_addresslist($ID)); 1072 $to = (!empty($conf['notify'])) ? $conf['notify'] : array_pop($list); 1073 $bcc = implode(',', $list); 1074 1075 $replace = array( 1076 $ID, 1077 $conf['title'], 1078 strftime($conf['dformat'], $comment['date']['created']), 1079 $comment['user']['name'], 1080 $comment['raw'], 1081 wl($ID, '', true) . '#comment_' . $comment['cid'], 1082 wl($ID, 'do=unsubscribe', true, '&'), 1083 DOKU_URL, 1084 ); 1085 1086 $body = str_replace($search, $replace, $notify_text); 1087 mail_send($to, $subject_notify, $body, $conf['mailfrom'], '', $bcc); 1088 } 1089 1090 // notify comment subscribers 1091 if (!empty($subscribers)) { 1092 1093 foreach($subscribers as $mail => $data) { 1094 $to = $mail; 1095 1096 if($data['active']) { 1097 $replace = array( 1098 $ID, 1099 $conf['title'], 1100 strftime($conf['dformat'], $comment['date']['created']), 1101 $comment['user']['name'], 1102 $comment['raw'], 1103 wl($ID, '', true) . '#comment_' . $comment['cid'], 1104 wl($ID, 'do=unsubscribe&hash=' . $data['hash'], true, '&'), 1105 DOKU_URL, 1106 ); 1107 1108 $body = str_replace($search, $replace, $notify_text); 1109 mail_send($to, $subject_notify, $body, $conf['mailfrom']); 1110 } elseif(!$data['active'] && !$data['confirmsent']) { 1111 $search = array( 1112 '@PAGE@', 1113 '@TITLE@', 1114 '@SUBSCRIBE@', 1115 '@DOKUWIKIURL@', 1116 ); 1117 $replace = array( 1118 $ID, 1119 $conf['title'], 1120 wl($ID, 'do=confirmsubscribe&hash=' . $data['hash'], true, '&'), 1121 DOKU_URL, 1122 ); 1123 1124 $body = str_replace($search, $replace, $confirm_text); 1125 mail_send($to, $subject_subscribe, $body, $conf['mailfrom']); 1126 $subscribers[$mail]['confirmsent'] = true; 1127 } 1128 } 1129 } 1130 } 1131 1132 /** 1133 * Counts the number of visible comments 1134 */ 1135 function _count($data) { 1136 $number = 0; 1137 foreach ($data['comments'] as $cid => $comment) { 1138 if ($comment['parent']) continue; 1139 if (!$comment['show']) continue; 1140 $number++; 1141 $rids = $comment['replies']; 1142 if (count($rids)) $number = $number + $this->_countReplies($data, $rids); 1143 } 1144 return $number; 1145 } 1146 1147 function _countReplies(&$data, $rids) { 1148 $number = 0; 1149 foreach ($rids as $rid) { 1150 if (!isset($data['comments'][$rid])) continue; // reply was removed 1151 if (!$data['comments'][$rid]['show']) continue; 1152 $number++; 1153 $rids = $data['comments'][$rid]['replies']; 1154 if (count($rids)) $number = $number + $this->_countReplies($data, $rids); 1155 } 1156 return $number; 1157 } 1158 1159 /** 1160 * Renders the comment text 1161 */ 1162 function _render($raw) { 1163 if ($this->getConf('wikisyntaxok')) { 1164 $xhtml = $this->render($raw); 1165 } else { // wiki syntax not allowed -> just encode special chars 1166 $xhtml = htmlspecialchars(trim($raw)); 1167 } 1168 return $xhtml; 1169 } 1170 1171 /** 1172 * Finds out whether there is a discussion section for the current page 1173 */ 1174 function _hasDiscussion(&$title) { 1175 global $ID; 1176 1177 $cfile = metaFN($ID, '.comments'); 1178 1179 if (!@file_exists($cfile)) { 1180 if ($this->getConf('automatic')) { 1181 return true; 1182 } else { 1183 return false; 1184 } 1185 } 1186 1187 $comments = unserialize(io_readFile($cfile, false)); 1188 1189 if ($comments['title']) $title = hsc($comments['title']); 1190 $num = $comments['number']; 1191 if ((!$comments['status']) || (($comments['status'] == 2) && (!$num))) return false; 1192 else return true; 1193 } 1194 1195 /** 1196 * Creates a new thread page 1197 */ 1198 function _newThread() { 1199 global $ID, $INFO; 1200 1201 $ns = cleanID($_REQUEST['ns']); 1202 $title = str_replace(':', '', $_REQUEST['title']); 1203 $back = $ID; 1204 $ID = ($ns ? $ns.':' : '').cleanID($title); 1205 $INFO = pageinfo(); 1206 1207 // check if we are allowed to create this file 1208 if ($INFO['perm'] >= AUTH_CREATE) { 1209 1210 //check if locked by anyone - if not lock for my self 1211 if ($INFO['locked']) return 'locked'; 1212 else lock($ID); 1213 1214 // prepare the new thread file with default stuff 1215 if (!@file_exists($INFO['filepath'])) { 1216 global $TEXT; 1217 1218 $TEXT = pageTemplate(array(($ns ? $ns.':' : '').$title)); 1219 if (!$TEXT) { 1220 $data = array('id' => $ID, 'ns' => $ns, 'title' => $title, 'back' => $back); 1221 $TEXT = $this->_pageTemplate($data); 1222 } 1223 return 'preview'; 1224 } else { 1225 return 'edit'; 1226 } 1227 } else { 1228 return 'show'; 1229 } 1230 } 1231 1232 /** 1233 * Adapted version of pageTemplate() function 1234 */ 1235 function _pageTemplate($data) { 1236 global $conf, $INFO; 1237 1238 $id = $data['id']; 1239 $user = $_SERVER['REMOTE_USER']; 1240 $tpl = io_readFile(DOKU_PLUGIN.'discussion/_template.txt'); 1241 1242 // standard replacements 1243 $replace = array( 1244 '@NS@' => $data['ns'], 1245 '@PAGE@' => strtr(noNS($id),'_',' '), 1246 '@USER@' => $user, 1247 '@NAME@' => $INFO['userinfo']['name'], 1248 '@MAIL@' => $INFO['userinfo']['mail'], 1249 '@DATE@' => strftime($conf['dformat']), 1250 ); 1251 1252 // additional replacements 1253 $replace['@BACK@'] = $data['back']; 1254 $replace['@TITLE@'] = $data['title']; 1255 1256 // avatar if useavatar and avatar plugin available 1257 if ($this->getConf('useavatar') 1258 && (@file_exists(DOKU_PLUGIN.'avatar/syntax.php')) 1259 && (!plugin_isdisabled('avatar'))) { 1260 $replace['@AVATAR@'] = '{{avatar>'.$user.' }} '; 1261 } else { 1262 $replace['@AVATAR@'] = ''; 1263 } 1264 1265 // tag if tag plugin is available 1266 if ((@file_exists(DOKU_PLUGIN.'tag/syntax/tag.php')) 1267 && (!plugin_isdisabled('tag'))) { 1268 $replace['@TAG@'] = "\n\n{{tag>}}"; 1269 } else { 1270 $replace['@TAG@'] = ''; 1271 } 1272 1273 // do the replace 1274 $tpl = str_replace(array_keys($replace), array_values($replace), $tpl); 1275 return $tpl; 1276 } 1277 1278 /** 1279 * Checks if the CAPTCHA string submitted is valid 1280 * 1281 * @author Andreas Gohr <gohr@cosmocode.de> 1282 * @adaption Esther Brunner <wikidesign@gmail.com> 1283 */ 1284 function _captchaCheck() { 1285 if (plugin_isdisabled('captcha') || (!$captcha = plugin_load('helper', 'captcha'))) 1286 return; // CAPTCHA is disabled or not available 1287 1288 // do nothing if logged in user and no CAPTCHA required 1289 if (!$captcha->getConf('forusers') && $_SERVER['REMOTE_USER']) return; 1290 1291 // compare provided string with decrypted captcha 1292 $rand = PMA_blowfish_decrypt($_REQUEST['plugin__captcha_secret'], auth_cookiesalt()); 1293 $code = $captcha->_generateCAPTCHA($captcha->_fixedIdent(), $rand); 1294 1295 if (!$_REQUEST['plugin__captcha_secret'] || 1296 !$_REQUEST['plugin__captcha'] || 1297 strtoupper($_REQUEST['plugin__captcha']) != $code) { 1298 1299 // CAPTCHA test failed! Continue to edit instead of saving 1300 msg($captcha->getLang('testfailed'), -1); 1301 if ($_REQUEST['comment'] == 'save') $_REQUEST['comment'] = 'edit'; 1302 elseif ($_REQUEST['comment'] == 'add') $_REQUEST['comment'] = 'show'; 1303 } 1304 // if we arrive here it was a valid save 1305 } 1306 1307 /** 1308 * Adds the comments to the index 1309 */ 1310 function idx_add_discussion(&$event, $param) { 1311 1312 // get .comments meta file name 1313 $file = metaFN($event->data[0], '.comments'); 1314 1315 if (@file_exists($file)) $data = unserialize(io_readFile($file, false)); 1316 if ((!$data['status']) || ($data['number'] == 0)) return; // comments are turned off 1317 1318 // now add the comments 1319 if (isset($data['comments'])) { 1320 foreach ($data['comments'] as $key => $value) { 1321 $event->data[1] .= $this->_addCommentWords($key, $data); 1322 } 1323 } 1324 } 1325 1326 /** 1327 * Adds the words of a given comment to the index 1328 */ 1329 function _addCommentWords($cid, &$data, $parent = '') { 1330 1331 if (!isset($data['comments'][$cid])) return ''; // comment was removed 1332 $comment = $data['comments'][$cid]; 1333 1334 if (!is_array($comment)) return ''; // corrupt datatype 1335 if ($comment['parent'] != $parent) return ''; // reply to an other comment 1336 if (!$comment['show']) return ''; // hidden comment 1337 1338 $text = $comment['raw']; // we only add the raw comment text 1339 if (is_array($comment['replies'])) { // and the replies 1340 foreach ($comment['replies'] as $rid) { 1341 $text .= $this->_addCommentWords($rid, $data, $cid); 1342 } 1343 } 1344 return ' '.$text; 1345 } 1346 1347 /** 1348 * Only allow http(s) URLs and append http:// to URLs if needed 1349 */ 1350 function _checkURL($url) { 1351 if(preg_match("#^http://|^https://#", $url)) { 1352 return hsc($url); 1353 } elseif(substr($url, 0, 4) == 'www.') { 1354 return hsc('http://' . $url); 1355 } else { 1356 return ''; 1357 } 1358 } 1359} 1360 1361function _sortCallback($a, $b) { 1362 if (is_array($a['date'])) { // new format 1363 $createdA = $a['date']['created']; 1364 } else { // old format 1365 $createdA = $a['date']; 1366 } 1367 1368 if (is_array($b['date'])) { // new format 1369 $createdB = $b['date']['created']; 1370 } else { // old format 1371 $createdB = $b['date']; 1372 } 1373 1374 if ($createdA == $createdB) 1375 return 0; 1376 else 1377 return ($createdA < $createdB) ? -1 : 1; 1378} 1379 1380// vim:ts=4:sw=4:et:enc=utf-8: 1381