Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

acp_search.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 16.40 KiB


001  <?php
002  /**
003  *
004  * This file is part of the phpBB Forum Software package.
005  *
006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
007  * @license GNU General Public License, version 2 (GPL-2.0)
008  *
009  * For full copyright and license information, please see
010  * the docs/CREDITS.txt file.
011  *
012  */
013   
014  /**
015  * @ignore
016  */
017  if (!defined('IN_PHPBB'))
018  {
019      exit;
020  }
021   
022  class acp_search
023  {
024      var $u_action;
025      var $state;
026      var $search;
027      var $max_post_id;
028      var $batch_size = 100;
029   
030      function main($id, $mode)
031      {
032          global $user;
033   
034          $user->add_lang('acp/search');
035   
036          // For some this may be of help...
037          @ini_set('memory_limit', '128M');
038   
039          switch ($mode)
040          {
041              case 'settings':
042                  $this->settings($id, $mode);
043              break;
044   
045              case 'index':
046                  $this->index($id, $mode);
047              break;
048          }
049      }
050   
051      function settings($id, $mode)
052      {
053          global $db, $user, $auth, $template, $cache;
054          global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
055   
056          $submit = (isset($_POST['submit'])) ? true : false;
057   
058          $search_types = $this->get_search_types();
059   
060          $settings = array(
061              'search_interval'            => 'float',
062              'search_anonymous_interval'    => 'float',
063              'load_search'                => 'bool',
064              'limit_search_load'            => 'float',
065              'min_search_author_chars'    => 'integer',
066              'max_num_search_keywords'    => 'integer',
067              'search_store_results'        => 'integer',
068          );
069   
070          $search = null;
071          $error = false;
072          $search_options = '';
073          foreach ($search_types as $type)
074          {
075              if ($this->init_search($type, $search, $error))
076              {
077                  continue;
078              }
079   
080              $name = $search->get_name();
081   
082              $selected = ($config['search_type'] == $type) ? ' selected="selected"' : '';
083              $identifier = substr($type, strrpos($type, '\\') + 1);
084              $search_options .= "<option value=\"$type\"$selected data-toggle-setting=\"#search_{$identifier}_settings\">$name</option>";
085   
086              if (method_exists($search, 'acp'))
087              {
088                  $vars = $search->acp();
089   
090                  if (!$submit)
091                  {
092                      $template->assign_block_vars('backend', array(
093                          'NAME'            => $name,
094                          'SETTINGS'        => $vars['tpl'],
095                          'IDENTIFIER'    => $identifier,
096                      ));
097                  }
098                  else if (is_array($vars['config']))
099                  {
100                      $settings = array_merge($settings, $vars['config']);
101                  }
102              }
103          }
104          unset($search);
105          unset($error);
106   
107          $cfg_array = (isset($_REQUEST['config'])) ? request_var('config', array('' => ''), true) : array();
108          $updated = request_var('updated', false);
109   
110          foreach ($settings as $config_name => $var_type)
111          {
112              if (!isset($cfg_array[$config_name]))
113              {
114                  continue;
115              }
116   
117              // e.g. integer:4:12 (min 4, max 12)
118              $var_type = explode(':', $var_type);
119   
120              $config_value = $cfg_array[$config_name];
121              settype($config_value, $var_type[0]);
122   
123              if (isset($var_type[1]))
124              {
125                  $config_value = max($var_type[1], $config_value);
126              }
127   
128              if (isset($var_type[2]))
129              {
130                  $config_value = min($var_type[2], $config_value);
131              }
132   
133              // only change config if anything was actually changed
134              if ($submit && ($config[$config_name] != $config_value))
135              {
136                  set_config($config_name, $config_value);
137                  $updated = true;
138              }
139          }
140   
141          if ($submit)
142          {
143              $extra_message = '';
144              if ($updated)
145              {
146                  add_log('admin', 'LOG_CONFIG_SEARCH');
147              }
148   
149              if (isset($cfg_array['search_type']) && in_array($cfg_array['search_type'], $search_types, true) && ($cfg_array['search_type'] != $config['search_type']))
150              {
151                  $search = null;
152                  $error = false;
153   
154                  if (!$this->init_search($cfg_array['search_type'], $search, $error))
155                  {
156                      if (confirm_box(true))
157                      {
158                          if (!method_exists($search, 'init') || !($error = $search->init()))
159                          {
160                              set_config('search_type', $cfg_array['search_type']);
161   
162                              if (!$updated)
163                              {
164                                  add_log('admin', 'LOG_CONFIG_SEARCH');
165                              }
166                              $extra_message = '<br />' . $user->lang['SWITCHED_SEARCH_BACKEND'] . '<br /><a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=search&amp;mode=index') . '">&raquo; ' . $user->lang['GO_TO_SEARCH_INDEX'] . '</a>';
167                          }
168                          else
169                          {
170                              trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
171                          }
172                      }
173                      else
174                      {
175                          confirm_box(false, $user->lang['CONFIRM_SEARCH_BACKEND'], build_hidden_fields(array(
176                              'i'            => $id,
177                              'mode'        => $mode,
178                              'submit'    => true,
179                              'updated'    => $updated,
180                              'config'    => array('search_type' => $cfg_array['search_type']),
181                          )));
182                      }
183                  }
184                  else
185                  {
186                      trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
187                  }
188              }
189   
190              $search = null;
191              $error = false;
192              if (!$this->init_search($config['search_type'], $search, $error))
193              {
194                  if ($updated)
195                  {
196                      if (method_exists($search, 'config_updated'))
197                      {
198                          if ($search->config_updated())
199                          {
200                              trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
201                          }
202                      }
203                  }
204              }
205              else
206              {
207                  trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
208              }
209   
210              trigger_error($user->lang['CONFIG_UPDATED'] . $extra_message . adm_back_link($this->u_action));
211          }
212          unset($cfg_array);
213   
214          $this->tpl_name = 'acp_search';
215          $this->page_title = 'ACP_SEARCH_SETTINGS';
216   
217          $template->assign_vars(array(
218              'LIMIT_SEARCH_LOAD'        => (float) $config['limit_search_load'],
219              'MIN_SEARCH_AUTHOR_CHARS'    => (int) $config['min_search_author_chars'],
220              'SEARCH_INTERVAL'        => (float) $config['search_interval'],
221              'SEARCH_GUEST_INTERVAL'    => (float) $config['search_anonymous_interval'],
222              'SEARCH_STORE_RESULTS'    => (int) $config['search_store_results'],
223              'MAX_NUM_SEARCH_KEYWORDS'    => (int) $config['max_num_search_keywords'],
224   
225              'S_SEARCH_TYPES'        => $search_options,
226              'S_YES_SEARCH'            => (bool) $config['load_search'],
227              'S_SETTINGS'            => true,
228   
229              'U_ACTION'                => $this->u_action)
230          );
231      }
232   
233      function index($id, $mode)
234      {
235          global $db, $user, $auth, $template, $cache;
236          global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
237   
238          $action = request_var('action', '');
239          $this->state = explode(',', $config['search_indexing_state']);
240   
241          if (isset($_POST['cancel']))
242          {
243              $action = '';
244              $this->state = array();
245              $this->save_state();
246          }
247   
248          if ($action)
249          {
250              switch ($action)
251              {
252                  case 'progress_bar':
253                      $type = request_var('type', '');
254                      $this->display_progress_bar($type);
255                  break;
256   
257                  case 'delete':
258                      $this->state[1] = 'delete';
259                  break;
260   
261                  case 'create':
262                      $this->state[1] = 'create';
263                  break;
264   
265                  default:
266                      trigger_error('NO_ACTION', E_USER_ERROR);
267                  break;
268              }
269   
270              if (empty($this->state[0]))
271              {
272                  $this->state[0] = request_var('search_type', '');
273              }
274   
275              $this->search = null;
276              $error = false;
277              if ($this->init_search($this->state[0], $this->search, $error))
278              {
279                  trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
280              }
281              $name = $this->search->get_name();
282   
283              $action = &$this->state[1];
284   
285              $this->max_post_id = $this->get_max_post_id();
286   
287              $post_counter = (isset($this->state[2])) ? $this->state[2] : 0;
288              $this->state[2] = &$post_counter;
289              $this->save_state();
290   
291              switch ($action)
292              {
293                  case 'delete':
294                      if (method_exists($this->search, 'delete_index'))
295                      {
296                          // pass a reference to myself so the $search object can make use of save_state() and attributes
297                          if ($error = $this->search->delete_index($this, append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=delete", false)))
298                          {
299                              $this->state = array('');
300                              $this->save_state();
301                              trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
302                          }
303                      }
304                      else
305                      {
306                          $starttime = explode(' ', microtime());
307                          $starttime = $starttime[1] + $starttime[0];
308                          $row_count = 0;
309                          while (still_on_time() && $post_counter <= $this->max_post_id)
310                          {
311                              $sql = 'SELECT post_id, poster_id, forum_id
312                                  FROM ' . POSTS_TABLE . '
313                                  WHERE post_id >= ' . (int) ($post_counter + 1) . '
314                                      AND post_id <= ' . (int) ($post_counter + $this->batch_size);
315                              $result = $db->sql_query($sql);
316   
317                              $ids = $posters = $forum_ids = array();
318                              while ($row = $db->sql_fetchrow($result))
319                              {
320                                  $ids[] = $row['post_id'];
321                                  $posters[] = $row['poster_id'];
322                                  $forum_ids[] = $row['forum_id'];
323                              }
324                              $db->sql_freeresult($result);
325                              $row_count += sizeof($ids);
326   
327                              if (sizeof($ids))
328                              {
329                                  $this->search->index_remove($ids, $posters, $forum_ids);
330                              }
331   
332                              $post_counter += $this->batch_size;
333                          }
334                          // save the current state
335                          $this->save_state();
336   
337                          if ($post_counter <= $this->max_post_id)
338                          {
339                              $mtime = explode(' ', microtime());
340                              $totaltime = $mtime[0] + $mtime[1] - $starttime;
341                              $rows_per_second = $row_count / $totaltime;
342                              meta_refresh(1, append_sid($this->u_action . '&amp;action=delete&amp;skip_rows=' . $post_counter));
343                              trigger_error($user->lang('SEARCH_INDEX_DELETE_REDIRECT', (int) $row_count, $post_counter, $rows_per_second));
344                          }
345                      }
346   
347                      $this->search->tidy();
348   
349                      $this->state = array('');
350                      $this->save_state();
351   
352                      add_log('admin', 'LOG_SEARCH_INDEX_REMOVED', $name);
353                      trigger_error($user->lang['SEARCH_INDEX_REMOVED'] . adm_back_link($this->u_action) . $this->close_popup_js());
354                  break;
355   
356                  case 'create':
357                      if (method_exists($this->search, 'create_index'))
358                      {
359                          // pass a reference to acp_search so the $search object can make use of save_state() and attributes
360                          if ($error = $this->search->create_index($this, append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=create", false)))
361                          {
362                              $this->state = array('');
363                              $this->save_state();
364                              trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
365                          }
366                      }
367                      else
368                      {
369                          $sql = 'SELECT forum_id, enable_indexing
370                              FROM ' . FORUMS_TABLE;
371                          $result = $db->sql_query($sql, 3600);
372   
373                          while ($row = $db->sql_fetchrow($result))
374                          {
375                              $forums[$row['forum_id']] = (bool) $row['enable_indexing'];
376                          }
377                          $db->sql_freeresult($result);
378   
379                          $starttime = explode(' ', microtime());
380                          $starttime = $starttime[1] + $starttime[0];
381                          $row_count = 0;
382                          while (still_on_time() && $post_counter <= $this->max_post_id)
383                          {
384                              $sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id
385                                  FROM ' . POSTS_TABLE . '
386                                  WHERE post_id >= ' . (int) ($post_counter + 1) . '
387                                      AND post_id <= ' . (int) ($post_counter + $this->batch_size);
388                              $result = $db->sql_query($sql);
389   
390                              $buffer = $db->sql_buffer_nested_transactions();
391   
392                              if ($buffer)
393                              {
394                                  $rows = $db->sql_fetchrowset($result);
395                                  $rows[] = false; // indicate end of array for while loop below
396   
397                                  $db->sql_freeresult($result);
398                              }
399   
400                              $i = 0;
401                              while ($row = ($buffer ? $rows[$i++] : $db->sql_fetchrow($result)))
402                              {
403                                  // Indexing enabled for this forum
404                                  if (isset($forums[$row['forum_id']]) && $forums[$row['forum_id']])
405                                  {
406                                      $this->search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']);
407                                  }
408                                  $row_count++;
409                              }
410                              if (!$buffer)
411                              {
412                                  $db->sql_freeresult($result);
413                              }
414   
415                              $post_counter += $this->batch_size;
416                          }
417                          // save the current state
418                          $this->save_state();
419   
420                          // pretend the number of posts was as big as the number of ids we indexed so far
421                          // just an estimation as it includes deleted posts
422                          $num_posts = $config['num_posts'];
423                          $config['num_posts'] = min($config['num_posts'], $post_counter);
424                          $this->search->tidy();
425                          $config['num_posts'] = $num_posts;
426   
427                          if ($post_counter <= $this->max_post_id)
428                          {
429                              $mtime = explode(' ', microtime());
430                              $totaltime = $mtime[0] + $mtime[1] - $starttime;
431                              $rows_per_second = $row_count / $totaltime;
432                              meta_refresh(1, append_sid($this->u_action . '&amp;action=create&amp;skip_rows=' . $post_counter));
433                              trigger_error($user->lang('SEARCH_INDEX_CREATE_REDIRECT', (int) $row_count, $post_counter) . $user->lang('SEARCH_INDEX_CREATE_REDIRECT_RATE', $rows_per_second));
434                          }
435                      }
436   
437                      $this->search->tidy();
438   
439                      $this->state = array('');
440                      $this->save_state();
441   
442                      add_log('admin', 'LOG_SEARCH_INDEX_CREATED', $name);
443                      trigger_error($user->lang['SEARCH_INDEX_CREATED'] . adm_back_link($this->u_action) . $this->close_popup_js());
444                  break;
445              }
446          }
447   
448          $search_types = $this->get_search_types();
449   
450          $search = null;
451          $error = false;
452          $search_options = '';
453          foreach ($search_types as $type)
454          {
455              if ($this->init_search($type, $search, $error) || !method_exists($search, 'index_created'))
456              {
457                  continue;
458              }
459   
460              $name = $search->get_name();
461   
462              $data = array();
463              if (method_exists($search, 'index_stats'))
464              {
465                  $data = $search->index_stats();
466              }
467   
468              $statistics = array();
469              foreach ($data as $statistic => $value)
470              {
471                  $n = sizeof($statistics);
472                  if ($n && sizeof($statistics[$n - 1]) < 3)
473                  {
474                      $statistics[$n - 1] += array('statistic_2' => $statistic, 'value_2' => $value);
475                  }
476                  else
477                  {
478                      $statistics[] = array('statistic_1' => $statistic, 'value_1' => $value);
479                  }
480              }
481   
482              $template->assign_block_vars('backend', array(
483                  'L_NAME'            => $name,
484                  'NAME'                => $type,
485   
486                  'S_ACTIVE'            => ($type == $config['search_type']) ? true : false,
487                  'S_HIDDEN_FIELDS'    => build_hidden_fields(array('search_type' => $type)),
488                  'S_INDEXED'            => (bool) $search->index_created(),
489                  'S_STATS'            => (bool) sizeof($statistics))
490              );
491   
492              foreach ($statistics as $statistic)
493              {
494                  $template->assign_block_vars('backend.data', array(
495                      'STATISTIC_1'    => $statistic['statistic_1'],
496                      'VALUE_1'        => $statistic['value_1'],
497                      'STATISTIC_2'    => (isset($statistic['statistic_2'])) ? $statistic['statistic_2'] : '',
498                      'VALUE_2'        => (isset($statistic['value_2'])) ? $statistic['value_2'] : '')
499                  );
500              }
501          }
502          unset($search);
503          unset($error);
504          unset($statistics);
505          unset($data);
506   
507          $this->tpl_name = 'acp_search';
508          $this->page_title = 'ACP_SEARCH_INDEX';
509   
510          $template->assign_vars(array(
511              'S_INDEX'                => true,
512              'U_ACTION'                => $this->u_action,
513              'U_PROGRESS_BAR'        => append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;mode=$mode&amp;action=progress_bar"),
514              'UA_PROGRESS_BAR'        => addslashes(append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;mode=$mode&amp;action=progress_bar")),
515          ));
516   
517          if (isset($this->state[1]))
518          {
519              $template->assign_vars(array(
520                  'S_CONTINUE_INDEXING'    => $this->state[1],
521                  'U_CONTINUE_INDEXING'    => $this->u_action . '&amp;action=' . $this->state[1],
522                  'L_CONTINUE'            => ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING'] : $user->lang['CONTINUE_DELETING_INDEX'],
523                  'L_CONTINUE_EXPLAIN'    => ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING_EXPLAIN'] : $user->lang['CONTINUE_DELETING_INDEX_EXPLAIN'])
524              );
525          }
526      }
527   
528      function display_progress_bar($type)
529      {
530          global $template, $user;
531   
532          $l_type = ($type == 'create') ? 'INDEXING_IN_PROGRESS' : 'DELETING_INDEX_IN_PROGRESS';
533   
534          adm_page_header($user->lang[$l_type]);
535   
536          $template->set_filenames(array(
537              'body'    => 'progress_bar.html')
538          );
539   
540          $template->assign_vars(array(
541              'L_PROGRESS'            => $user->lang[$l_type],
542              'L_PROGRESS_EXPLAIN'    => $user->lang[$l_type . '_EXPLAIN'])
543          );
544   
545          adm_page_footer();
546      }
547   
548      function close_popup_js()
549      {
550          return "<script type=\"text/javascript\">\n" .
551              "// <![CDATA[\n" .
552              "    close_waitscreen = 1;\n" .
553              "// ]]>\n" .
554              "</script>\n";
555      }
556   
557      function get_search_types()
558      {
559          global $phpbb_root_path, $phpEx, $phpbb_extension_manager;
560   
561          $finder = $phpbb_extension_manager->get_finder();
562   
563          return $finder
564              ->extension_suffix('_backend')
565              ->extension_directory('/search')
566              ->core_path('phpbb/search/')
567              ->get_classes();
568      }
569   
570      function get_max_post_id()
571      {
572          global $db;
573   
574          $sql = 'SELECT MAX(post_id) as max_post_id
575              FROM '. POSTS_TABLE;
576          $result = $db->sql_query($sql);
577          $max_post_id = (int) $db->sql_fetchfield('max_post_id');
578          $db->sql_freeresult($result);
579   
580          return $max_post_id;
581      }
582   
583      function save_state($state = false)
584      {
585          if ($state)
586          {
587              $this->state = $state;
588          }
589   
590          ksort($this->state);
591   
592          set_config('search_indexing_state', implode(',', $this->state), true);
593      }
594   
595      /**
596      * Initialises a search backend object
597      *
598      * @return false if no error occurred else an error message
599      */
600      function init_search($type, &$search, &$error)
601      {
602          global $phpbb_root_path, $phpEx, $user, $auth, $config, $db;
603   
604          if (!class_exists($type) || !method_exists($type, 'keyword_search'))
605          {
606              $error = $user->lang['NO_SUCH_SEARCH_MODULE'];
607              return $error;
608          }
609   
610          $error = false;
611          $search = new $type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
612   
613          return $error;
614      }
615  }
616