* @license GNU General Public License, version 2 (GPL-2.0) * * For full copyright and license information, please see * the docs/CREDITS.txt file. * */ namespace phpbb\db\driver; /** * SQLite3 Database Abstraction Layer * Minimum Requirement: 3.6.15+ */ class sqlite3 extends \phpbb\db\driver\driver { /** * @var string Stores errors during connection setup in case the driver is not available */ protected $connect_error = ''; /** * @var \SQLite3 The SQLite3 database object to operate against */ protected $dbo = null; /** * {@inheritDoc} */ public function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { $this->persistency = false; $this->user = $sqluser; $this->server = $sqlserver . (($port) ? ':' . $port : ''); $this->dbname = $database; if (!class_exists('SQLite3', false)) { $this->connect_error = 'SQLite3 not found, is the extension installed?'; return $this->sql_error(''); } try { $this->dbo = new \SQLite3($this->server, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE); $this->dbo->busyTimeout(60000); $this->db_connect_id = true; } catch (\Exception $e) { $this->connect_error = $e->getMessage(); return array('message' => $this->connect_error); } return true; } /** * {@inheritDoc} */ public function sql_server_info($raw = false, $use_cache = true) { global $cache; if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('sqlite_version')) === false) { $version = \SQLite3::version(); $this->sql_server_version = $version['versionString']; if (!empty($cache) && $use_cache) { $cache->put('sqlite_version', $this->sql_server_version); } } return ($raw) ? $this->sql_server_version : 'SQLite ' . $this->sql_server_version; } /** * SQL Transaction * * @param string $status Should be one of the following strings: * begin, commit, rollback * @return bool Success/failure of the transaction query */ protected function _sql_transaction($status = 'begin') { switch ($status) { case 'begin': return $this->dbo->exec('BEGIN IMMEDIATE'); break; case 'commit': return $this->dbo->exec('COMMIT'); break; case 'rollback': return @$this->dbo->exec('ROLLBACK'); break; } return true; } /** * {@inheritDoc} */ public function sql_query($query = '', $cache_ttl = 0) { if ($query != '') { global $cache; // EXPLAIN only in extra debug mode if (defined('DEBUG')) { $this->sql_report('start', $query); } else if (defined('PHPBB_DISPLAY_LOAD_TIME')) { $this->curtime = microtime(true); } $this->last_query_text = $query; $this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) { if ($this->transaction === true && strpos($query, 'INSERT') === 0) { $query = preg_replace('/^INSERT INTO/', 'INSERT OR ROLLBACK INTO', $query); } if (($this->query_result = @$this->dbo->query($query)) === false) { // Try to recover a lost database connection if ($this->dbo && !@$this->dbo->lastErrorMsg()) { if ($this->sql_connect($this->server, $this->user, '', $this->dbname)) { $this->query_result = @$this->dbo->query($query); } } if ($this->query_result === false) { $this->sql_error($query); } } if (defined('DEBUG')) { $this->sql_report('stop', $query); } else if (defined('PHPBB_DISPLAY_LOAD_TIME')) { $this->sql_time += microtime(true) - $this->curtime; } if (!$this->query_result) { return false; } if ($cache && $cache_ttl) { $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); } } else if (defined('DEBUG')) { $this->sql_report('fromcache', $query); } } else { return false; } return $this->query_result; } /** * Build LIMIT query * * @param string $query The SQL query to execute * @param int $total The number of rows to select * @param int $offset * @param int $cache_ttl Either 0 to avoid caching or * the time in seconds which the result shall be kept in cache * @return mixed Buffered, seekable result handle, false on error */ protected function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { $this->query_result = false; // if $total is set to 0 we do not want to limit the number of rows if ($total == 0) { $total = -1; } $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); return $this->sql_query($query, $cache_ttl); } /** * {@inheritDoc} */ public function sql_affectedrows() { return ($this->db_connect_id) ? $this->dbo->changes() : false; } /** * {@inheritDoc} */ public function sql_fetchrow($query_id = false) { global $cache; if ($query_id === false) { /** @var \SQLite3Result $query_id */ $query_id = $this->query_result; } if ($cache && !is_object($query_id) && $cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } return is_object($query_id) ? @$query_id->fetchArray(SQLITE3_ASSOC) : false; } /** * {@inheritDoc} */ public function sql_nextid() { return ($this->db_connect_id) ? $this->dbo->lastInsertRowID() : false; } /** * {@inheritDoc} */ public function sql_freeresult($query_id = false) { global $cache; if ($query_id === false) { $query_id = $this->query_result; } if ($cache && !is_object($query_id) && $cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } if ($query_id) { return @$query_id->finalize(); } } /** * {@inheritDoc} */ public function sql_escape($msg) { return \SQLite3::escapeString($msg); } /** * {@inheritDoc} * * For SQLite an underscore is an unknown character. */ public function sql_like_expression($expression) { // Unlike LIKE, GLOB is unfortunately case sensitive. // We only catch * and ? here, not the character map possible on file globbing. $expression = str_replace(array(chr(0) . '_', chr(0) . '%'), array(chr(0) . '?', chr(0) . '*'), $expression); $expression = str_replace(array('?', '*'), array("\?", "\*"), $expression); $expression = str_replace(array(chr(0) . "\?", chr(0) . "\*"), array('?', '*'), $expression); return 'GLOB \'' . $this->sql_escape($expression) . '\''; } /** * {@inheritDoc} * * For SQLite an underscore is an unknown character. */ public function sql_not_like_expression($expression) { // Unlike NOT LIKE, NOT GLOB is unfortunately case sensitive // We only catch * and ? here, not the character map possible on file globbing. $expression = str_replace(array(chr(0) . '_', chr(0) . '%'), array(chr(0) . '?', chr(0) . '*'), $expression); $expression = str_replace(array('?', '*'), array("\?", "\*"), $expression); $expression = str_replace(array(chr(0) . "\?", chr(0) . "\*"), array('?', '*'), $expression); return 'NOT GLOB \'' . $this->sql_escape($expression) . '\''; } /** * return sql error array * * @return array */ protected function _sql_error() { if (class_exists('SQLite3', false) && isset($this->dbo)) { $error = array( 'message' => $this->dbo->lastErrorMsg(), 'code' => $this->dbo->lastErrorCode(), ); } else { $error = array( 'message' => $this->connect_error, 'code' => '', ); } return $error; } /** * Build db-specific query data * * @param string $stage Available stages: FROM, WHERE * @param mixed $data A string containing the CROSS JOIN query or an array of WHERE clauses * * @return string The db-specific query fragment */ protected function _sql_custom_build($stage, $data) { return $data; } /** * Close sql connection * * @return bool False if failure */ protected function _sql_close() { return $this->dbo->close(); } /** * Build db-specific report * * @param string $mode Available modes: display, start, stop, * add_select_row, fromcache, record_fromcache * @param string $query The Query that should be explained * @return mixed Either a full HTML page, boolean or null */ protected function _sql_report($mode, $query = '') { switch ($mode) { case 'start': $explain_query = $query; if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) { $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2]; } else if (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) { $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2]; } if (preg_match('/^SELECT/', $explain_query)) { $html_table = false; if ($result = $this->dbo->query("EXPLAIN QUERY PLAN $explain_query")) { while ($row = $result->fetchArray(SQLITE3_ASSOC)) { $html_table = $this->sql_report('add_select_row', $query, $html_table, $row); } } if ($html_table) { $this->html_hold .= ''; } } break; case 'fromcache': $endtime = explode(' ', microtime()); $endtime = $endtime[0] + $endtime[1]; $result = $this->dbo->query($query); if ($result) { while ($void = $result->fetchArray(SQLITE3_ASSOC)) { // Take the time spent on parsing rows into account } } $splittime = explode(' ', microtime()); $splittime = $splittime[0] + $splittime[1]; $this->sql_report('record_fromcache', $query, $endtime, $splittime); break; } } } id='n207' href='#n207'>207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* ucp_main
* UCP Front Panel
*/
class ucp_main
{
var $p_master;
var $u_action;
function ucp_main(&$p_master)
{
$this->p_master = &$p_master;
}
function main($id, $mode)
{
global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
global $request;
switch ($mode)
{
case 'front':
$user->add_lang('memberlist');
$sql_from = TOPICS_TABLE . ' t ';
$sql_select = '';
if ($config['load_db_track'])
{
$sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.topic_id = t.topic_id
AND tp.user_id = ' . $user->data['user_id'] . ')';
$sql_select .= ', tp.topic_posted';
}
if ($config['load_db_lastread'])
{
$sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id
AND tt.user_id = ' . $user->data['user_id'] . ')';
$sql_select .= ', tt.mark_time';
$sql_from .= ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.forum_id = t.forum_id
AND ft.user_id = ' . $user->data['user_id'] . ')';
$sql_select .= ', ft.mark_time AS forum_mark_time';
}
$topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
$folder = 'global_read';
$folder_new = 'global_unread';
// Get cleaned up list... return only those forums having the f_read permission
$forum_ary = $auth->acl_getf('f_read', true);
$forum_ary = array_unique(array_keys($forum_ary));
$topic_list = $rowset = array();
// If the user can't see any forums, he can't read any posts because fid of 0 is invalid
if (!empty($forum_ary))
{
$sql = "SELECT t.* $sql_select
FROM $sql_from
WHERE t.topic_type = " . POST_GLOBAL . '
AND ' . $db->sql_in_set('t.forum_id', $forum_ary) . '
ORDER BY t.topic_last_post_time DESC, t.topic_last_post_id DESC';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$topic_list[] = $row['topic_id'];
$rowset[$row['topic_id']] = $row;
}
$db->sql_freeresult($result);
}
$topic_forum_list = array();
foreach ($rowset as $t_id => $row)
{
if (isset($forum_tracking_info[$row['forum_id']]))
{
$row['forum_mark_time'] = $forum_tracking_info[$row['forum_id']];
}
$topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread'] && $user->data['is_registered'] && isset($row['forum_mark_time'])) ? $row['forum_mark_time'] : 0;
$topic_forum_list[$row['forum_id']]['topics'][] = (int) $t_id;
}
$topic_tracking_info = $tracking_topics = array();
if ($config['load_db_lastread'])
{
foreach ($topic_forum_list as $f_id => $topic_row)
{
$topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']));
}
}
else
{
foreach ($topic_forum_list as $f_id => $topic_row)
{
$topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics']);
}
}
unset($topic_forum_list);
foreach ($topic_list as $topic_id)
{
$row = &$rowset[$topic_id];
$forum_id = $row['forum_id'];
$topic_id = $row['topic_id'];
$unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
$folder_img = ($unread_topic) ? $folder_new : $folder;
$folder_alt = ($unread_topic) ? 'UNREAD_POSTS' : (($row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_UNREAD_POSTS');
if ($row['topic_status'] == ITEM_LOCKED)
{
$folder_img .= '_locked';
}
// Posted image?
if (!empty($row['topic_posted']) && $row['topic_posted'])
{
$folder_img .= '_mine';
}
$template->assign_block_vars('topicrow', array(
'FORUM_ID' => $forum_id,
'TOPIC_ID' => $topic_id,
'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']),
'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
'TOPIC_TITLE' => censor_text($row['topic_title']),
'TOPIC_TYPE' => $topic_type,
'TOPIC_IMG_STYLE' => $folder_img,
'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', '') : '',
'S_USER_POSTED' => (!empty($row['topic_posted']) && $row['topic_posted']) ? true : false,
'S_UNREAD' => $unread_topic,
'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&p=" . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&view=unread") . '#unread',
'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id"))
);
}
if ($config['load_user_activity'])
{
if (!function_exists('display_user_activity'))
{
include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
}
display_user_activity($user->data);
}
// Do the relevant calculations
$memberdays = max(1, round((time() - $user->data['user_regdate']) / 86400));
$posts_per_day = $user->data['user_posts'] / $memberdays;
$percentage = ($config['num_posts']) ? min(100, ($user->data['user_posts'] / $config['num_posts']) * 100) : 0;
$template->assign_vars(array(
'USER_COLOR' => (!empty($user->data['user_colour'])) ? $user->data['user_colour'] : '',
'JOINED' => $user->format_date($user->data['user_regdate']),
'LAST_ACTIVE' => (empty($last_active)) ? ' - ' : $user->format_date($last_active),
'WARNINGS' => ($user->data['user_warnings']) ? $user->data['user_warnings'] : 0,
'POSTS' => ($user->data['user_posts']) ? $user->data['user_posts'] : 0,
'POSTS_DAY' => $user->lang('POST_DAY', $posts_per_day),
'POSTS_PCT' => $user->lang('POST_PCT', $percentage),
// 'S_GROUP_OPTIONS' => $group_options,
'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user->data['user_id'] . '&sr=posts') : '',
));
break;
case 'subscribed':
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
$user->add_lang('viewforum');
add_form_key('ucp_front_subscribed');
$unwatch = (isset($_POST['unwatch'])) ? true : false;
if ($unwatch)
{
if (check_form_key('ucp_front_subscribed'))
{
$forums = array_keys(request_var('f', array(0 => 0)));
$topics = array_keys(request_var('t', array(0 => 0)));
$msg = '';
if (sizeof($forums) || sizeof($topics))
{
$l_unwatch = '';
if (sizeof($forums))
{
$sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forums) . '
AND user_id = ' . $user->data['user_id'];
$db->sql_query($sql);
$l_unwatch .= '_FORUMS';
}
if (sizeof($topics))
{
$sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
WHERE ' . $db->sql_in_set('topic_id', $topics) . '
AND user_id = ' . $user->data['user_id'];
$db->sql_query($sql);
$l_unwatch .= '_TOPICS';
}
$msg = $user->lang['UNWATCHED' . $l_unwatch];
}
else
{
$msg = $user->lang['NO_WATCHED_SELECTED'];
}
}
else
{
$msg = $user->lang['FORM_INVALID'];
}
$message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=subscribed") . '">', '</a>');
meta_refresh(3, append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=subscribed"));
trigger_error($message);
}
$forbidden_forums = array();
if ($config['allow_forum_notify'])
{
$forbidden_forums = $auth->acl_getf('!f_read', true);
$forbidden_forums = array_unique(array_keys($forbidden_forums));
$sql_array = array(
'SELECT' => 'f.*',
'FROM' => array(
FORUMS_WATCH_TABLE => 'fw',
FORUMS_TABLE => 'f'
),
'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . '
AND f.forum_id = fw.forum_id
AND ' . $db->sql_in_set('f.forum_id', $forbidden_forums, true, true),
'ORDER_BY' => 'left_id'
);
if ($config['load_db_lastread'])
{
$sql_array['LEFT_JOIN'] = array(
array(
'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
)
);
$sql_array['SELECT'] .= ', ft.mark_time ';
}
else
{
$tracking_topics = $request->variable($config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
$tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
}
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$forum_id = $row['forum_id'];
if ($config['load_db_lastread'])
{
$forum_check = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
}
else
{
$forum_check = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
}
$unread_forum = ($row['forum_last_post_time'] > $forum_check) ? true : false;
// Which folder should we display?
if ($row['forum_status'] == ITEM_LOCKED)
{
$folder_image = ($unread_forum) ? 'forum_unread_locked' : 'forum_read_locked';
$folder_alt = 'FORUM_LOCKED';
}
else
{
$folder_image = ($unread_forum) ? 'forum_unread' : 'forum_read';
$folder_alt = ($unread_forum) ? 'UNREAD_POSTS' : 'NO_UNREAD_POSTS';
}
// Create last post link information, if appropriate
if ($row['forum_last_post_id'])
{
$last_post_time = $user->format_date($row['forum_last_post_time']);
$last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&p=" . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
}
else
{
$last_post_time = $last_post_url = '';
}
$template->assign_block_vars('forumrow', array(
'FORUM_ID' => $forum_id,
'FORUM_IMG_STYLE' => $folder_image,
'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt),
'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
'FORUM_NAME' => $row['forum_name'],
'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
'LAST_POST_SUBJECT' => $row['forum_last_post_subject'],
'LAST_POST_TIME' => $last_post_time,
'LAST_POST_AUTHOR' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
'S_UNREAD_FORUM' => $unread_forum,
'U_LAST_POST' => $last_post_url,
'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
);
}
$db->sql_freeresult($result);
}
// Subscribed Topics
if ($config['allow_topic_notify'])
{
if (empty($forbidden_forums))
{
$forbidden_forums = $auth->acl_getf('!f_read', true);
$forbidden_forums = array_unique(array_keys($forbidden_forums));
}
$this->assign_topiclist('subscribed', $forbidden_forums);
}
$template->assign_vars(array(
'S_TOPIC_NOTIFY' => $config['allow_topic_notify'],
'S_FORUM_NOTIFY' => $config['allow_forum_notify'],
));
break;
case 'bookmarks':
if (!$config['allow_bookmarks'])
{
$template->assign_vars(array(
'S_NO_DISPLAY_BOOKMARKS' => true)
);
break;
}
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
$user->add_lang('viewforum');
if (isset($_POST['unbookmark']))
{
$s_hidden_fields = array('unbookmark' => 1);
$topics = (isset($_POST['t'])) ? array_keys(request_var('t', array(0 => 0))) : array();
$url = $this->u_action;
if (!sizeof($topics))
{
trigger_error('NO_BOOKMARKS_SELECTED');
}
foreach ($topics as $topic_id)
{
$s_hidden_fields['t'][$topic_id] = 1;
}
if (confirm_box(true))
{
$sql = 'DELETE FROM ' . BOOKMARKS_TABLE . '
WHERE user_id = ' . $user->data['user_id'] . '
AND ' . $db->sql_in_set('topic_id', $topics);
$db->sql_query($sql);
meta_refresh(3, $url);
$message = $user->lang['BOOKMARKS_REMOVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>');
trigger_error($message);
}
else
{
confirm_box(false, 'REMOVE_SELECTED_BOOKMARKS', build_hidden_fields($s_hidden_fields));
}
}
$forbidden_forums = $auth->acl_getf('!f_read', true);
$forbidden_forums = array_unique(array_keys($forbidden_forums));
$this->assign_topiclist('bookmarks', $forbidden_forums);
break;
case 'drafts':
$pm_drafts = ($this->p_master->p_name == 'pm') ? true : false;
$template->assign_var('S_SHOW_DRAFTS', true);
$user->add_lang('posting');
$edit = (isset($_REQUEST['edit'])) ? true : false;
$submit = (isset($_POST['submit'])) ? true : false;
$draft_id = $request->variable('edit', 0);
$delete = (isset($_POST['delete'])) ? true : false;
$s_hidden_fields = ($edit) ? '<input type="hidden" name="edit" value="' . $draft_id . '" />' : '';
$draft_subject = $draft_message = '';
add_form_key('ucp_draft');
if ($delete)
{
if (check_form_key('ucp_draft'))
{
$drafts = array_keys(request_var('d', array(0 => 0)));
if (sizeof($drafts))
{
$sql = 'DELETE FROM ' . DRAFTS_TABLE . '
WHERE ' . $db->sql_in_set('draft_id', $drafts) . '
AND user_id = ' . $user->data['user_id'];
$db->sql_query($sql);
}
$msg = $user->lang['DRAFTS_DELETED'];
unset($drafts);
}
else
{
$msg = $user->lang['FORM_INVALID'];
}
$message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
meta_refresh(3, $this->u_action);
trigger_error($message);
}
if ($submit && $edit)
{
$draft_subject = utf8_normalize_nfc(request_var('subject', '', true));
$draft_message = utf8_normalize_nfc(request_var('message', '', true));
if (check_form_key('ucp_draft'))
{
if ($draft_message && $draft_subject)
{
$draft_row = array(
'draft_subject' => $draft_subject,
'draft_message' => $draft_message
);
$sql = 'UPDATE ' . DRAFTS_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $draft_row) . "
WHERE draft_id = $draft_id
AND user_id = " . $user->data['user_id'];
$db->sql_query($sql);
$message = $user->lang['DRAFT_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
meta_refresh(3, $this->u_action);
trigger_error($message);
}
else
{
$template->assign_var('ERROR', ($draft_message == '') ? $user->lang['EMPTY_DRAFT'] : (($draft_subject == '') ? $user->lang['EMPTY_DRAFT_TITLE'] : ''));
}
}
else
{
$template->assign_var('ERROR', $user->lang['FORM_INVALID']);
}
}
if (!$pm_drafts)
{
$sql = 'SELECT d.*, f.forum_name
FROM ' . DRAFTS_TABLE . ' d, ' . FORUMS_TABLE . ' f
WHERE d.user_id = ' . $user->data['user_id'] . ' ' .
(($edit) ? "AND d.draft_id = $draft_id" : '') . '