Changeset 702 for trunk/forum/includes/functions_admin.php
- Timestamp:
- Mar 31, 2010, 6:32:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/forum/includes/functions_admin.php
r400 r702 3 3 * 4 4 * @package acp 5 * @version $Id : functions_admin.php 9065 2008-11-13 17:32:55Z toonarmy$5 * @version $Id$ 6 6 * @copyright (c) 2005 phpBB Group 7 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License … … 18 18 19 19 /** 20 * Recalculate Binary Tree 21 function recalc_btree($sql_id, $sql_table, $module_class = '') 20 * Recalculate Nested Sets 21 * 22 * @param int $new_id first left_id (should start with 1) 23 * @param string $pkey primary key-column (containing the id for the parent_id of the children) 24 * @param string $table constant or fullname of the table 25 * @param int $parent_id parent_id of the current set (default = 0) 26 * @param array $where contains strings to compare closer on the where statement (additional) 27 * 28 * @author EXreaction 29 */ 30 function recalc_nested_sets(&$new_id, $pkey, $table, $parent_id = 0, $where = array()) 22 31 { 23 32 global $db; 24 33 25 if (!$sql_id || !$sql_table) 26 { 27 return; 28 } 29 30 $sql_where = ($module_class) ? " WHERE module_class = '" . $db->sql_escape($module_class) . "'" : ''; 31 32 // Reset to minimum possible left and right id 33 $sql = "SELECT MIN(left_id) as min_left_id, MIN(right_id) as min_right_id 34 FROM $sql_table 35 $sql_where"; 34 $sql = 'SELECT * 35 FROM ' . $table . ' 36 WHERE parent_id = ' . (int) $parent_id . 37 ((!empty($where)) ? ' AND ' . implode(' AND ', $where) : '') . ' 38 ORDER BY left_id ASC'; 36 39 $result = $db->sql_query($sql); 37 $row = $db->sql_fetchrow($result); 40 while ($row = $db->sql_fetchrow($result)) 41 { 42 // First we update the left_id for this module 43 if ($row['left_id'] != $new_id) 44 { 45 $db->sql_query('UPDATE ' . $table . ' SET ' . $db->sql_build_array('UPDATE', array('left_id' => $new_id)) . " WHERE $pkey = {$row[$pkey]}"); 46 } 47 $new_id++; 48 49 // Then we go through any children and update their left/right id's 50 recalc_nested_sets($new_id, $pkey, $table, $row[$pkey], $where); 51 52 // Then we come back and update the right_id for this module 53 if ($row['right_id'] != $new_id) 54 { 55 $db->sql_query('UPDATE ' . $table . ' SET ' . $db->sql_build_array('UPDATE', array('right_id' => $new_id)) . " WHERE $pkey = {$row[$pkey]}"); 56 } 57 $new_id++; 58 } 38 59 $db->sql_freeresult($result); 39 40 $substract = (int) (min($row['min_left_id'], $row['min_right_id']) - 1);41 42 if ($substract > 0)43 {44 $sql = "UPDATE $sql_table45 SET left_id = left_id - $substract, right_id = right_id - $substract46 $sql_where";47 $db->sql_query($sql);48 }49 50 $sql = "SELECT $sql_id, parent_id, left_id, right_id51 FROM $sql_table52 $sql_where53 ORDER BY left_id ASC, parent_id ASC, $sql_id ASC";54 $f_result = $db->sql_query($sql);55 56 while ($item_data = $db->sql_fetchrow($f_result))57 {58 if ($item_data['parent_id'])59 {60 $sql = "SELECT left_id, right_id61 FROM $sql_table62 $sql_where " . (($sql_where) ? 'AND' : 'WHERE') . "63 $sql_id = {$item_data['parent_id']}";64 $result = $db->sql_query($sql);65 66 if (!$row = $db->sql_fetchrow($result))67 {68 $sql = "UPDATE $sql_table SET parent_id = 0 WHERE $sql_id = " . $item_data[$sql_id];69 $db->sql_query($sql);70 }71 $db->sql_freeresult($result);72 73 $sql = "UPDATE $sql_table74 SET left_id = left_id + 2, right_id = right_id + 275 $sql_where " . (($sql_where) ? 'AND' : 'WHERE') . "76 left_id > {$row['right_id']}";77 $db->sql_query($sql);78 79 $sql = "UPDATE $sql_table80 SET right_id = right_id + 281 $sql_where " . (($sql_where) ? 'AND' : 'WHERE') . "82 {$row['left_id']} BETWEEN left_id AND right_id";83 $db->sql_query($sql);84 85 $item_data['left_id'] = $row['right_id'];86 $item_data['right_id'] = $row['right_id'] + 1;87 }88 else89 {90 $sql = "SELECT MAX(right_id) AS right_id91 FROM $sql_table92 $sql_where";93 $result = $db->sql_query($sql);94 $row = $db->sql_fetchrow($result);95 $db->sql_freeresult($result);96 97 $item_data['left_id'] = $row['right_id'] + 1;98 $item_data['right_id'] = $row['right_id'] + 2;99 }100 101 $sql = "UPDATE $sql_table102 SET left_id = {$item_data['left_id']}, right_id = {$item_data['right_id']}103 WHERE $sql_id = " . $item_data[$sql_id];104 $db->sql_query($sql);105 }106 $db->sql_freeresult($f_result);107 60 } 108 */109 61 110 62 /** … … 115 67 global $db, $user, $auth; 116 68 117 $acl = ($ignore_acl) ? '' : (($only_acl_post) ? 'f_post' : array('f_list', 'a_forum', 'a_forumadd', 'a_forumdel'));118 119 69 // This query is identical to the jumpbox one 120 $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id70 $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, forum_flags, forum_options, left_id, right_id 121 71 FROM ' . FORUMS_TABLE . ' 122 72 ORDER BY left_id ASC'; … … 147 97 $disabled = false; 148 98 149 if ($acl && !$auth->acl_gets($acl, $row['forum_id'])) 150 { 151 // List permission? 152 if ($auth->acl_get('f_list', $row['forum_id'])) 99 if (!$ignore_acl && $auth->acl_get('f_list', $row['forum_id'])) 100 { 101 if ($only_acl_post && !$auth->acl_get('f_post', $row['forum_id']) || (!$auth->acl_get('m_approve', $row['forum_id']) && !$auth->acl_get('f_noapprove', $row['forum_id']))) 153 102 { 154 103 $disabled = true; 155 104 } 156 else 157 { 158 continue; 159 } 105 else if (!$only_acl_post && !$auth->acl_gets(array('f_list', 'a_forum', 'a_forumadd', 'a_forumdel'), $row['forum_id'])) 106 { 107 $disabled = true; 108 } 109 } 110 else if (!$ignore_acl) 111 { 112 continue; 160 113 } 161 114 … … 303 256 if ($acl_list == '' || ($acl_list != '' && $auth->acl_gets($acl_list, $row['forum_id']))) 304 257 { 305 $rowset[] = ($id_only) ? $row['forum_id'] : $row;258 $rowset[] = ($id_only) ? (int) $row['forum_id'] : $row; 306 259 } 307 260 } … … 356 309 357 310 /** 311 * Copies permissions from one forum to others 312 * 313 * @param int $src_forum_id The source forum we want to copy permissions from 314 * @param array $dest_forum_ids The destination forum(s) we want to copy to 315 * @param bool $clear_dest_perms True if destination permissions should be deleted 316 * @param bool $add_log True if log entry should be added 317 * 318 * @return bool False on error 319 * 320 * @author bantu 321 */ 322 function copy_forum_permissions($src_forum_id, $dest_forum_ids, $clear_dest_perms = true, $add_log = true) 323 { 324 global $db; 325 326 // Only one forum id specified 327 if (!is_array($dest_forum_ids)) 328 { 329 $dest_forum_ids = array($dest_forum_ids); 330 } 331 332 // Make sure forum ids are integers 333 $src_forum_id = (int) $src_forum_id; 334 $dest_forum_ids = array_map('intval', $dest_forum_ids); 335 336 // No source forum or no destination forums specified 337 if (empty($src_forum_id) || empty($dest_forum_ids)) 338 { 339 return false; 340 } 341 342 // Check if source forum exists 343 $sql = 'SELECT forum_name 344 FROM ' . FORUMS_TABLE . ' 345 WHERE forum_id = ' . $src_forum_id; 346 $result = $db->sql_query($sql); 347 $src_forum_name = $db->sql_fetchfield('forum_name'); 348 $db->sql_freeresult($result); 349 350 // Source forum doesn't exist 351 if (empty($src_forum_name)) 352 { 353 return false; 354 } 355 356 // Check if destination forums exists 357 $sql = 'SELECT forum_id, forum_name 358 FROM ' . FORUMS_TABLE . ' 359 WHERE ' . $db->sql_in_set('forum_id', $dest_forum_ids); 360 $result = $db->sql_query($sql); 361 362 $dest_forum_ids = $dest_forum_names = array(); 363 while ($row = $db->sql_fetchrow($result)) 364 { 365 $dest_forum_ids[] = (int) $row['forum_id']; 366 $dest_forum_names[] = $row['forum_name']; 367 } 368 $db->sql_freeresult($result); 369 370 // No destination forum exists 371 if (empty($dest_forum_ids)) 372 { 373 return false; 374 } 375 376 // From the mysql documentation: 377 // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear 378 // in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14. 379 // Due to this we stay on the safe side if we do the insertion "the manual way" 380 381 // Rowsets we're going to insert 382 $users_sql_ary = $groups_sql_ary = array(); 383 384 // Query acl users table for source forum data 385 $sql = 'SELECT user_id, auth_option_id, auth_role_id, auth_setting 386 FROM ' . ACL_USERS_TABLE . ' 387 WHERE forum_id = ' . $src_forum_id; 388 $result = $db->sql_query($sql); 389 390 while ($row = $db->sql_fetchrow($result)) 391 { 392 $row = array( 393 'user_id' => (int) $row['user_id'], 394 'auth_option_id' => (int) $row['auth_option_id'], 395 'auth_role_id' => (int) $row['auth_role_id'], 396 'auth_setting' => (int) $row['auth_setting'], 397 ); 398 399 foreach ($dest_forum_ids as $dest_forum_id) 400 { 401 $users_sql_ary[] = $row + array('forum_id' => $dest_forum_id); 402 } 403 } 404 $db->sql_freeresult($result); 405 406 // Query acl groups table for source forum data 407 $sql = 'SELECT group_id, auth_option_id, auth_role_id, auth_setting 408 FROM ' . ACL_GROUPS_TABLE . ' 409 WHERE forum_id = ' . $src_forum_id; 410 $result = $db->sql_query($sql); 411 412 while ($row = $db->sql_fetchrow($result)) 413 { 414 $row = array( 415 'group_id' => (int) $row['group_id'], 416 'auth_option_id' => (int) $row['auth_option_id'], 417 'auth_role_id' => (int) $row['auth_role_id'], 418 'auth_setting' => (int) $row['auth_setting'], 419 ); 420 421 foreach ($dest_forum_ids as $dest_forum_id) 422 { 423 $groups_sql_ary[] = $row + array('forum_id' => $dest_forum_id); 424 } 425 } 426 $db->sql_freeresult($result); 427 428 $db->sql_transaction('begin'); 429 430 // Clear current permissions of destination forums 431 if ($clear_dest_perms) 432 { 433 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . ' 434 WHERE ' . $db->sql_in_set('forum_id', $dest_forum_ids); 435 $db->sql_query($sql); 436 437 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' 438 WHERE ' . $db->sql_in_set('forum_id', $dest_forum_ids); 439 $db->sql_query($sql); 440 } 441 442 $db->sql_multi_insert(ACL_USERS_TABLE, $users_sql_ary); 443 $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary); 444 445 if ($add_log) 446 { 447 add_log('admin', 'LOG_FORUM_COPIED_PERMISSIONS', $src_forum_name, implode(', ', $dest_forum_names)); 448 } 449 450 $db->sql_transaction('commit'); 451 452 return true; 453 } 454 455 /** 358 456 * Get physical file listing 359 457 */ 360 458 function filelist($rootdir, $dir = '', $type = 'gif|jpg|jpeg|png') 361 459 { 362 $matches = array( );460 $matches = array($dir => array()); 363 461 364 462 // Remove initial / if present … … 620 718 if ($approved_topics) 621 719 { 622 set_config ('num_topics', $config['num_topics'] - $approved_topics, true);720 set_config_count('num_topics', $approved_topics * (-1), true); 623 721 } 624 722 … … 653 751 } 654 752 655 $where_clause = $db->sql_in_set($where_type, array_map('intval', $where_ids)); 753 $where_ids = array_map('intval', $where_ids); 754 755 /* Possible code for splitting post deletion 756 if (sizeof($where_ids) >= 1001) 757 { 758 // Split into chunks of 1000 759 $chunks = array_chunk($where_ids, 1000); 760 761 foreach ($chunks as $_where_ids) 762 { 763 delete_posts($where_type, $_where_ids, $auto_sync, $posted_sync, $post_count_sync, $call_delete_topics); 764 } 765 766 return; 767 }*/ 768 769 $where_clause = $db->sql_in_set($where_type, $where_ids); 656 770 } 657 771 … … 666 780 while ($row = $db->sql_fetchrow($result)) 667 781 { 668 $post_ids[] = $row['post_id'];669 $poster_ids[] = $row['poster_id'];670 $topic_ids[] = $row['topic_id'];671 $forum_ids[] = $row['forum_id'];782 $post_ids[] = (int) $row['post_id']; 783 $poster_ids[] = (int) $row['poster_id']; 784 $topic_ids[] = (int) $row['topic_id']; 785 $forum_ids[] = (int) $row['forum_id']; 672 786 673 787 if ($row['post_postcount'] && $post_count_sync && $row['post_approved']) … … 777 891 if ($approved_posts) 778 892 { 779 set_config ('num_posts', $config['num_posts'] - $approved_posts, true);893 set_config_count('num_posts', $approved_posts * (-1), true); 780 894 } 781 895 … … 800 914 global $db, $config; 801 915 802 if (is_array($ids) && sizeof($ids)) 916 // 0 is as bad as an empty array 917 if (empty($ids)) 918 { 919 return false; 920 } 921 922 if (is_array($ids)) 803 923 { 804 924 $ids = array_unique($ids); … … 810 930 } 811 931 812 if (!sizeof($ids)) 813 { 814 return false; 815 } 932 $sql_where = ''; 816 933 817 934 switch ($mode) … … 820 937 case 'message': 821 938 $sql_id = 'post_msg_id'; 939 $sql_where = ' AND in_message = ' . ($mode == 'message' ? 1 : 0); 822 940 break; 823 941 … … 843 961 FROM ' . ATTACHMENTS_TABLE . ' 844 962 WHERE ' . $db->sql_in_set($sql_id, $ids); 963 964 $sql .= $sql_where; 965 845 966 $result = $db->sql_query($sql); 846 967 … … 868 989 $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . ' 869 990 WHERE ' . $db->sql_in_set($sql_id, $ids); 991 992 $sql .= $sql_where; 993 870 994 $db->sql_query($sql); 871 995 $num_deleted = $db->sql_affectedrows(); … … 895 1019 if ($space_removed || $files_removed) 896 1020 { 897 set_config ('upload_dir_size', $config['upload_dir_size'] - $space_removed, true);898 set_config ('num_files', $config['num_files'] - $files_removed, true);1021 set_config_count('upload_dir_size', $space_removed * (-1), true); 1022 set_config_count('num_files', $files_removed * (-1), true); 899 1023 } 900 1024 … … 916 1040 if (sizeof($post_ids)) 917 1041 { 918 $sql = 'UPDATE ' . POSTS_TABLE . ' 919 SET post_attachment = 0 920 WHERE ' . $db->sql_in_set('post_id', $post_ids); 921 $db->sql_query($sql); 1042 // Just check which posts are still having an assigned attachment not orphaned by querying the attachments table 1043 $sql = 'SELECT post_msg_id 1044 FROM ' . ATTACHMENTS_TABLE . ' 1045 WHERE ' . $db->sql_in_set('post_msg_id', $post_ids) . ' 1046 AND in_message = 0 1047 AND is_orphan = 0'; 1048 $result = $db->sql_query($sql); 1049 1050 $remaining_ids = array(); 1051 while ($row = $db->sql_fetchrow($result)) 1052 { 1053 $remaining_ids[] = $row['post_msg_id']; 1054 } 1055 $db->sql_freeresult($result); 1056 1057 // Now only unset those ids remaining 1058 $post_ids = array_diff($post_ids, $remaining_ids); 1059 1060 if (sizeof($post_ids)) 1061 { 1062 $sql = 'UPDATE ' . POSTS_TABLE . ' 1063 SET post_attachment = 0 1064 WHERE ' . $db->sql_in_set('post_id', $post_ids); 1065 $db->sql_query($sql); 1066 } 922 1067 } 923 1068 … … 925 1070 if (sizeof($message_ids)) 926 1071 { 927 $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' 928 SET message_attachment = 0 929 WHERE ' . $db->sql_in_set('msg_id', $message_ids); 930 $db->sql_query($sql); 1072 // Just check which messages are still having an assigned attachment not orphaned by querying the attachments table 1073 $sql = 'SELECT post_msg_id 1074 FROM ' . ATTACHMENTS_TABLE . ' 1075 WHERE ' . $db->sql_in_set('post_msg_id', $message_ids) . ' 1076 AND in_message = 1 1077 AND is_orphan = 0'; 1078 $result = $db->sql_query($sql); 1079 1080 $remaining_ids = array(); 1081 while ($row = $db->sql_fetchrow($result)) 1082 { 1083 $remaining_ids[] = $row['post_msg_id']; 1084 } 1085 $db->sql_freeresult($result); 1086 1087 // Now only unset those ids remaining 1088 $message_ids = array_diff($message_ids, $remaining_ids); 1089 1090 if (sizeof($message_ids)) 1091 { 1092 $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' 1093 SET message_attachment = 0 1094 WHERE ' . $db->sql_in_set('msg_id', $message_ids); 1095 $db->sql_query($sql); 1096 } 931 1097 } 932 1098 … … 1074 1240 $sql = 'SELECT COUNT(attach_id) AS num_entries 1075 1241 FROM ' . ATTACHMENTS_TABLE . " 1076 WHERE physical_filename = '" . $db->sql_escape( basename($filename)) . "'";1242 WHERE physical_filename = '" . $db->sql_escape(utf8_basename($filename)) . "'"; 1077 1243 $result = $db->sql_query($sql); 1078 1244 $num_entries = (int) $db->sql_fetchfield('num_entries'); … … 1085 1251 } 1086 1252 1087 $filename = ($mode == 'thumbnail') ? 'thumb_' . basename($filename) :basename($filename);1253 $filename = ($mode == 'thumbnail') ? 'thumb_' . utf8_basename($filename) : utf8_basename($filename); 1088 1254 return @unlink($phpbb_root_path . $config['upload_path'] . '/' . $filename); 1089 1255 } … … 1169 1335 { 1170 1336 case 'topic_moved': 1337 $db->sql_transaction('begin'); 1171 1338 switch ($db->sql_layer) 1172 1339 { … … 1205 1372 break; 1206 1373 } 1207 break; 1374 1375 $db->sql_transaction('commit'); 1376 break; 1208 1377 1209 1378 case 'topic_approved': 1379 1380 $db->sql_transaction('begin'); 1210 1381 switch ($db->sql_layer) 1211 1382 { … … 1243 1414 break; 1244 1415 } 1245 break; 1416 1417 $db->sql_transaction('commit'); 1418 break; 1246 1419 1247 1420 case 'post_reported': 1248 1421 $post_ids = $post_reported = array(); 1422 1423 $db->sql_transaction('begin'); 1249 1424 1250 1425 $sql = 'SELECT p.post_id, p.post_reported … … 1298 1473 $db->sql_query($sql); 1299 1474 } 1300 break; 1475 1476 $db->sql_transaction('commit'); 1477 break; 1301 1478 1302 1479 case 'topic_reported': … … 1307 1484 1308 1485 $topic_ids = $topic_reported = array(); 1486 1487 $db->sql_transaction('begin'); 1309 1488 1310 1489 $sql = 'SELECT DISTINCT(t.topic_id) … … 1340 1519 $db->sql_query($sql); 1341 1520 } 1342 break; 1521 1522 $db->sql_transaction('commit'); 1523 break; 1343 1524 1344 1525 case 'post_attachment': 1345 1526 $post_ids = $post_attachment = array(); 1527 1528 $db->sql_transaction('begin'); 1346 1529 1347 1530 $sql = 'SELECT p.post_id, p.post_attachment … … 1395 1578 $db->sql_query($sql); 1396 1579 } 1397 break; 1580 1581 $db->sql_transaction('commit'); 1582 break; 1398 1583 1399 1584 case 'topic_attachment': … … 1404 1589 1405 1590 $topic_ids = $topic_attachment = array(); 1591 1592 $db->sql_transaction('begin'); 1406 1593 1407 1594 $sql = 'SELECT DISTINCT(t.topic_id) … … 1437 1624 $db->sql_query($sql); 1438 1625 } 1439 break; 1626 1627 $db->sql_transaction('commit'); 1628 1629 break; 1440 1630 1441 1631 case 'forum': 1632 1633 $db->sql_transaction('begin'); 1442 1634 1443 1635 // 1: Get the list of all forums … … 1641 1833 } 1642 1834 } 1643 break; 1835 1836 $db->sql_transaction('commit'); 1837 break; 1644 1838 1645 1839 case 'topic': 1646 1840 $topic_data = $post_ids = $approved_unapproved_ids = $resync_forums = $delete_topics = $delete_posts = $moved_topics = array(); 1841 1842 $db->sql_transaction('begin'); 1647 1843 1648 1844 $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_approved, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_replies, t.topic_replies_real, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time … … 1968 2164 unset($topic_data); 1969 2165 2166 $db->sql_transaction('commit'); 2167 1970 2168 // if some topics have been resync'ed then resync parent forums 1971 2169 // except when we're only syncing a range, we don't want to sync forums during … … 1975 2173 sync('forum', 'forum_id', array_values($resync_forums), true, true); 1976 2174 } 1977 break;2175 break; 1978 2176 } 1979 2177 … … 2161 2359 // Remove users who have group memberships with DENY moderator permissions 2162 2360 $sql = $db->sql_build_query('SELECT', array( 2163 'SELECT' => 'a.forum_id, ug.user_id ',2361 'SELECT' => 'a.forum_id, ug.user_id, g.group_id', 2164 2362 2165 2363 'FROM' => array( 2166 2364 ACL_OPTIONS_TABLE => 'o', 2167 2365 USER_GROUP_TABLE => 'ug', 2168 ACL_GROUPS_TABLE => 'a' 2366 GROUPS_TABLE => 'g', 2367 ACL_GROUPS_TABLE => 'a', 2169 2368 ), 2170 2369 … … 2180 2379 OR r.auth_setting = ' . ACL_NEVER . ') 2181 2380 AND a.group_id = ug.group_id 2381 AND g.group_id = ug.group_id 2382 AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1) 2182 2383 AND ' . $db->sql_in_set('ug.user_id', $ug_id_ary) . " 2183 2384 AND ug.user_pending = 0 … … 2299 2500 * View log 2300 2501 */ 2301 function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_time DESC' )2502 function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_time DESC', $keywords = '') 2302 2503 { 2303 2504 global $db, $user, $auth, $phpEx, $phpbb_root_path, $phpbb_admin_path; … … 2316 2517 case 'mod': 2317 2518 $log_type = LOG_MOD; 2519 $sql_forum = ''; 2318 2520 2319 2521 if ($topic_id) 2320 2522 { 2321 $sql_forum = 'AND l.topic_id = ' . intval($topic_id);2523 $sql_forum = 'AND l.topic_id = ' . (int) $topic_id; 2322 2524 } 2323 2525 else if (is_array($forum_id)) … … 2325 2527 $sql_forum = 'AND ' . $db->sql_in_set('l.forum_id', array_map('intval', $forum_id)); 2326 2528 } 2327 else 2328 { 2329 $sql_forum = ($forum_id) ? 'AND l.forum_id = ' . intval($forum_id) : '';2529 else if ($forum_id) 2530 { 2531 $sql_forum = 'AND l.forum_id = ' . (int) $forum_id; 2330 2532 } 2331 2533 break; … … 2348 2550 default: 2349 2551 return; 2552 } 2553 2554 // Use no preg_quote for $keywords because this would lead to sole backslashes being added 2555 // We also use an OR connection here for spaces and the | string. Currently, regex is not supported for searching (but may come later). 2556 $keywords = preg_split('#[\s|]+#u', utf8_strtolower($keywords), 0, PREG_SPLIT_NO_EMPTY); 2557 $sql_keywords = ''; 2558 2559 if (!empty($keywords)) 2560 { 2561 $keywords_pattern = array(); 2562 2563 // Build pattern and keywords... 2564 for ($i = 0, $num_keywords = sizeof($keywords); $i < $num_keywords; $i++) 2565 { 2566 $keywords_pattern[] = preg_quote($keywords[$i], '#'); 2567 $keywords[$i] = $db->sql_like_expression($db->any_char . $keywords[$i] . $db->any_char); 2568 } 2569 2570 $keywords_pattern = '#' . implode('|', $keywords_pattern) . '#ui'; 2571 2572 $operations = array(); 2573 foreach ($user->lang as $key => $value) 2574 { 2575 if (substr($key, 0, 4) == 'LOG_' && preg_match($keywords_pattern, $value)) 2576 { 2577 $operations[] = $key; 2578 } 2579 } 2580 2581 $sql_keywords = 'AND ('; 2582 if (!empty($operations)) 2583 { 2584 $sql_keywords .= $db->sql_in_set('l.log_operation', $operations) . ' OR '; 2585 } 2586 $sql_keywords .= 'LOWER(l.log_data) ' . implode(' OR LOWER(l.log_data) ', $keywords) . ')'; 2350 2587 } 2351 2588 … … 2355 2592 AND u.user_id = l.user_id 2356 2593 " . (($limit_days) ? "AND l.log_time >= $limit_days" : '') . " 2594 $sql_keywords 2357 2595 $sql_forum 2358 2596 ORDER BY $sort_by"; … … 2395 2633 if (!empty($row['log_data'])) 2396 2634 { 2397 $log_data_ary = unserialize($row['log_data']); 2635 $log_data_ary = @unserialize($row['log_data']); 2636 $log_data_ary = ($log_data_ary === false) ? array() : $log_data_ary; 2398 2637 2399 2638 if (isset($user->lang[$row['log_operation']])) … … 2418 2657 } 2419 2658 } 2420 else 2659 else if (!empty($log_data_ary)) 2421 2660 { 2422 2661 $log[$i]['action'] .= '<br />' . implode('', $log_data_ary); … … 2516 2755 2517 2756 $sql = 'SELECT COUNT(l.log_id) AS total_entries 2518 FROM ' . LOG_TABLE . " l2757 FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . " u 2519 2758 WHERE l.log_type = $log_type 2759 AND l.user_id = u.user_id 2520 2760 AND l.log_time >= $limit_days 2761 $sql_keywords 2521 2762 $sql_forum"; 2522 2763 $result = $db->sql_query($sql); … … 2661 2902 } 2662 2903 2663 $sql = 'SELECT user_id, username, user_regdate, user_lastvisit, user_inactive_time, user_inactive_reason2904 $sql = 'SELECT * 2664 2905 FROM ' . USERS_TABLE . ' 2665 2906 WHERE user_type = ' . USER_INACTIVE . … … 3030 3271 } 3031 3272 3273 /** 3274 * Obtains the latest version information 3275 * 3276 * @param bool $force_update Ignores cached data. Defaults to false. 3277 * @param bool $warn_fail Trigger a warning if obtaining the latest version information fails. Defaults to false. 3278 * @param int $ttl Cache version information for $ttl seconds. Defaults to 86400 (24 hours). 3279 * 3280 * @return string | false Version info on success, false on failure. 3281 */ 3282 function obtain_latest_version_info($force_update = false, $warn_fail = false, $ttl = 86400) 3283 { 3284 global $cache; 3285 3286 $info = $cache->get('versioncheck'); 3287 3288 if ($info === false || $force_update) 3289 { 3290 $errstr = ''; 3291 $errno = 0; 3292 3293 $info = get_remote_file('www.phpbb.com', '/updatecheck', 3294 ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno); 3295 3296 if ($info === false) 3297 { 3298 $cache->destroy('versioncheck'); 3299 if ($warn_fail) 3300 { 3301 trigger_error($errstr, E_USER_WARNING); 3302 } 3303 return false; 3304 } 3305 3306 $cache->put('versioncheck', $info, $ttl); 3307 } 3308 3309 return $info; 3310 } 3311 3312 /** 3313 * Enables a particular flag in a bitfield column of a given table. 3314 * 3315 * @param string $table_name The table to update 3316 * @param string $column_name The column containing a bitfield to update 3317 * @param int $flag The binary flag which is OR-ed with the current column value 3318 * @param string $sql_more This string is attached to the sql query generated to update the table. 3319 * 3320 * @return void 3321 */ 3322 function enable_bitfield_column_flag($table_name, $column_name, $flag, $sql_more = '') 3323 { 3324 global $db; 3325 3326 $sql = 'UPDATE ' . $table_name . ' 3327 SET ' . $column_name . ' = ' . $db->sql_bit_or($column_name, $flag) . ' 3328 ' . $sql_more; 3329 $db->sql_query($sql); 3330 } 3331 3032 3332 ?>
Note:
See TracChangeset
for help on using the changeset viewer.