| [ PHPXref.com ] | [ Generated: Sat Aug 9 15:45:03 2008 ] | [ FluxBB 1.3 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Search index rebuilding script 4 * 5 * Allows administrators to rebuild the index used to search the posts and topics. 6 * 7 * @copyright Copyright (C) 2008 FluxBB.org, based on code copyright (C) 2002-2008 PunBB.org 8 * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher 9 * @package FluxBB 10 */ 11 12 13 if (!defined('FORUM_ROOT')) 14 define('FORUM_ROOT', '../'); 15 16 // Tell common.php that we don't want output buffering 17 define('FORUM_DISABLE_BUFFERING', 1); 18 19 require FORUM_ROOT.'include/common.php'; 20 require FORUM_ROOT.'include/common_admin.php'; 21 22 ($hook = get_hook('ari_start')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; 23 24 if ($forum_user['g_id'] != FORUM_ADMIN) 25 message($lang_common['No permission']); 26 27 // Load the admin.php language file 28 require FORUM_ROOT.'lang/'.$forum_user['language'].'/admin_common.php'; 29 require FORUM_ROOT.'lang/'.$forum_user['language'].'/admin_reindex.php'; 30 31 32 if (isset($_GET['i_per_page']) && isset($_GET['i_start_at'])) 33 { 34 $per_page = intval($_GET['i_per_page']); 35 $start_at = intval($_GET['i_start_at']); 36 if ($per_page < 1 || $start_at < 1) 37 message($lang_common['Bad request']); 38 39 // We validate the CSRF token. If it's set in POST and we're at this point, the token is valid. 40 // If it's in GET, we need to make sure it's valid. 41 if (!isset($_POST['csrf_token']) && (!isset($_GET['csrf_token']) || $_GET['csrf_token'] !== generate_form_token('reindex'.$forum_user['id']))) 42 csrf_confirm_form(); 43 44 ($hook = get_hook('ari_cycle_start')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; 45 46 @set_time_limit(0); 47 48 // If this is the first cycle of posts we empty the search index before we proceed 49 if (isset($_GET['i_empty_index'])) 50 { 51 $query = array( 52 'DELETE' => 'search_matches' 53 ); 54 55 ($hook = get_hook('ari_cycle_qr_empty_search_matches')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; 56 $forum_db->query_build($query) or error(__FILE__, __LINE__); 57 58 $query = array( 59 'DELETE' => 'search_words' 60 ); 61 62 ($hook = get_hook('ari_cycle_qr_empty_search_words')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; 63 $forum_db->query_build($query) or error(__FILE__, __LINE__); 64 65 // Reset the sequence for the search words (not needed for SQLite) 66 switch ($db_type) 67 { 68 case 'mysql': 69 case 'mysqli': 70 $result = $forum_db->query('ALTER TABLE '.$forum_db->prefix.'search_words auto_increment=1') or error(__FILE__, __LINE__); 71 break; 72 73 case 'pgsql'; 74 $result = $forum_db->query('SELECT setval(\''.$forum_db->prefix.'search_words_id_seq\', 1, false)') or error(__FILE__, __LINE__); 75 } 76 } 77 78 // Setup breadcrumbs 79 $forum_page['crumbs'] = array( 80 array($forum_config['o_board_title'], forum_link($forum_url['index'])), 81 $lang_admin_reindex['Rebuilding index title'] 82 ); 83 84 ?> 85 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 86 87 <html lang="<?php $lang_common['lang_identifier'] ?>" dir="<?php echo $lang_common['lang_direction'] ?>"> 88 <head> 89 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 90 91 <title><?php echo generate_crumbs(true) ?></title> 92 <style type="text/css"> 93 body { 94 font: 68.75% Verdana, Arial, Helvetica, sans-serif; 95 color: #333333; 96 background-color: #FFFFFF 97 } 98 </style> 99 </head> 100 <body> 101 102 <p><?php echo $lang_admin_reindex['Rebuilding index'] ?></p> 103 104 <?php 105 106 if (!defined('FORUM_SEARCH_IDX_FUNCTIONS_LOADED')) 107 require FORUM_ROOT.'include/search_idx.php'; 108 109 // Fetch posts to process 110 $query = array( 111 'SELECT' => 'p.id, p.message, t.id, t.subject, t.first_post_id', 112 'FROM' => 'posts AS p', 113 'JOINS' => array( 114 array( 115 'INNER JOIN' => 'topics AS t', 116 'ON' => 't.id=p.topic_id' 117 ) 118 ), 119 'WHERE' => 'p.id>='.$start_at, 120 'ORDER BY' => 'p.id', 121 'LIMIT' => $per_page 122 ); 123 124 ($hook = get_hook('ari_cycle_qr_fetch_posts')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; 125 $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); 126 127 $post_id = 0; 128 echo '<p>'; 129 while ($cur_post = $forum_db->fetch_row($result)) 130 { 131 echo sprintf($lang_admin_reindex['Processing post'], $cur_post[0], $cur_post[2]).'<br />'."\n"; 132 133 if ($cur_post[0] == $cur_post[4]) // This is the "topic post" so we have to index the subject as well 134 update_search_index('post', $cur_post[0], $cur_post[1], $cur_post[3]); 135 else 136 update_search_index('post', $cur_post[0], $cur_post[1]); 137 138 $post_id = $cur_post[0]; 139 } 140 echo '</p>'; 141 142 // Check if there is more work to do 143 $query = array( 144 'SELECT' => 'p.id', 145 'FROM' => 'posts AS p', 146 'WHERE' => 'p.id>'.$post_id, 147 'ORDER BY' => 'p.id', 148 'LIMIT' => '1' 149 ); 150 151 ($hook = get_hook('ari_cycle_qr_find_next_post')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; 152 $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); 153 154 $query_str = ($forum_db->num_rows($result)) ? '?i_per_page='.$per_page.'&i_start_at='.$forum_db->result($result).'&csrf_token='.generate_form_token('reindex'.$forum_user['id']) : ''; 155 156 ($hook = get_hook('ari_cycle_end')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; 157 158 $forum_db->end_transaction(); 159 $forum_db->close(); 160 161 exit('<script type="text/javascript">window.location="'.forum_link($forum_url['admin_reindex']).$query_str.'"</script><br />'.$lang_admin_reindex['Javascript redirect'].' <a href="'.forum_link($forum_url['admin_reindex']).$query_str.'">'.$lang_admin_reindex['Click to continue'].'</a>.'); 162 } 163 164 165 // Get the first post ID from the db 166 $query = array( 167 'SELECT' => 'p.id', 168 'FROM' => 'posts AS p', 169 'ORDER BY' => 'p.id', 170 'LIMIT' => '1' 171 ); 172 173 ($hook = get_hook('ari_qr_find_lowest_post_id')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; 174 $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); 175 if ($forum_db->num_rows($result)) 176 $first_id = $forum_db->result($result); 177 178 // Setup form 179 $forum_page['group_count'] = $forum_page['item_count'] = $forum_page['fld_count'] = 0; 180 181 // Setup breadcrumbs 182 $forum_page['crumbs'] = array( 183 array($forum_config['o_board_title'], forum_link($forum_url['index'])), 184 array($lang_admin_common['Forum administration'], forum_link($forum_url['admin_index'])), 185 $lang_admin_common['Rebuild index'] 186 ); 187 188 ($hook = get_hook('ari_pre_header_load')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; 189 190 define('FORUM_PAGE_SECTION', 'management'); 191 define('FORUM_PAGE_TYPE', 'sectioned'); 192 define('FORUM_PAGE', 'admin-reindex'); 193 require FORUM_ROOT.'header.php'; 194 195 // START SUBST - <!-- forum_main --> 196 ob_start(); 197 198 ($hook = get_hook('ari_main_output_start')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; 199 200 ?> 201 <div class="frm-head"> 202 <h2><span><?php echo $lang_admin_reindex['Reindex heading'] ?></span></h2> 203 </div> 204 <div class="main-content main-frm"> 205 <div class="ct-box"> 206 <p><?php echo $lang_admin_reindex['Reindex info'] ?></p> 207 </div> 208 <form class="frm-form" method="get" accept-charset="utf-8" action="<?php echo forum_link($forum_url['admin_reindex']) ?>"> 209 <div class="hidden"> 210 <input type="hidden" name="csrf_token" value="<?php echo generate_form_token('reindex'.$forum_user['id']) ?>" /> 211 </div> 212 <?php ($hook = get_hook('ari_pre_rebuild_fieldset')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; ?> 213 <fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>"> 214 <legend class="group-legend"><span><?php echo $lang_admin_reindex['Rebuild index legend'] ?></span></legend> 215 <?php ($hook = get_hook('ari_pre_rebuild_per_page')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; ?> 216 <div class="sf-set group-item<?php echo ++$forum_page['item_count'] ?>"> 217 <div class="sf-box text"> 218 <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_admin_reindex['Posts per cycle'] ?></span> <small><?php echo $lang_admin_reindex['Posts per cycle info'] ?></small></label><br /> 219 <span class="fld-input"><input type="text" id="fld<?php echo $forum_page['fld_count'] ?>" name="i_per_page" size="7" maxlength="7" value="100" /></span> 220 </div> 221 </div> 222 <?php ($hook = get_hook('ari_pre_rebuild_start_post')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; ?> 223 <div class="sf-set group-item<?php echo ++$forum_page['item_count'] ?>"> 224 <div class="sf-box text"> 225 <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span class="fld-label"><?php echo $lang_admin_reindex['Starting post'] ?></span> <small><?php echo $lang_admin_reindex['Starting post info'] ?></small></label><br /> 226 <span class="fld-input"><input type="text" id="fld<?php echo $forum_page['fld_count'] ?>" name="i_start_at" size="7" maxlength="7" value="<?php echo (isset($first_id)) ? $first_id : 0 ?>" /></span> 227 </div> 228 </div> 229 <?php ($hook = get_hook('ari_pre_rebuild_empty_index')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; ?> 230 <div class="sf-set group-item<?php echo ++$forum_page['item_count'] ?>"> 231 <div class="sf-box checkbox"> 232 <span class="fld-input"><input type="checkbox" id="fld<?php echo ++$forum_page['fld_count'] ?>" name="i_empty_index" value="1" checked="checked" /></span> 233 <label for="fld<?php echo $forum_page['fld_count'] ?>"><span><?php echo $lang_admin_reindex['Empty index'] ?></span> <?php echo $lang_admin_reindex['Empty index info'] ?></label> 234 </div> 235 </div> 236 <?php ($hook = get_hook('ari_pre_rebuild_fieldset_end')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; ?> 237 </fieldset> 238 <?php ($hook = get_hook('ari_rebuild_fieldset_end')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; ?> 239 <div class="ct-box warn-box"> 240 <p class="important"><?php echo $lang_admin_reindex['Reindex warning'] ?></p> 241 <p class="warn"><?php echo $lang_admin_reindex['Empty index warning'] ?></p> 242 </div> 243 <div class="frm-buttons"> 244 <span class="submit"><input type="submit" name="rebuild_index" value="<?php echo $lang_admin_reindex['Rebuild index'] ?>" /></span> 245 </div> 246 </form> 247 </div> 248 <?php 249 250 ($hook = get_hook('ari_end')) ? (defined('FORUM_USE_INCLUDE') ? include $hook : eval($hook)) : null; 251 252 $tpl_temp = forum_trim(ob_get_contents()); 253 $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main); 254 ob_end_clean(); 255 // END SUBST - <!-- forum_main --> 256 257 require FORUM_ROOT.'footer.php';
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |