Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

bot_update_v2.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 2.59 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  namespace phpbb\db\migration\data\v33x;
015   
016  class bot_update_v2 extends \phpbb\db\migration\migration
017  {
018      public static function depends_on()
019      {
020          return ['\phpbb\db\migration\data\v33x\v334'];
021      }
022   
023      public function update_data()
024      {
025          return [
026              ['custom', [[$this, 'add_bots']]],
027          ];
028      }
029   
030      public function add_bots()
031      {
032          $bots = [
033              'Ahrefs [Bot]' => 'AhrefsBot/',
034              'Amazon [Bot]' => 'Amazonbot/',
035              'Semrush [Bot]' => 'SemrushBot/',
036          ];
037   
038          $group_row = [];
039   
040          foreach ($bots as $bot_name => $bot_agent)
041          {
042              $bot_name_clean = utf8_clean_string($bot_name);
043   
044              $sql = 'SELECT user_id
045                  FROM ' . $this->table_prefix . 'users
046                  WHERE ' . $this->db->sql_build_array('SELECT', ['username_clean' => $bot_name_clean]);
047              $result = $this->db->sql_query($sql);
048              $bot_exists = (bool) $this->db->sql_fetchfield('user_id');
049              $this->db->sql_freeresult($result);
050   
051              if ($bot_exists)
052              {
053                  continue;
054              }
055   
056              if (!count($group_row))
057              {
058                  $sql = 'SELECT group_id, group_colour
059                      FROM ' . $this->table_prefix . 'groups
060                      WHERE ' . $this->db->sql_build_array('SELECT', ['group_name' => 'BOTS']);
061                  $result = $this->db->sql_query($sql);
062                  $group_row = $this->db->sql_fetchrow($result);
063                  $this->db->sql_freeresult($result);
064   
065                  // Default fallback, should never get here
066                  if (!count($group_row))
067                  {
068                      $group_row['group_id'] = 6;
069                      $group_row['group_colour'] = '9E8DA7';
070                  }
071              }
072   
073              if (!function_exists('user_add'))
074              {
075                  include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
076              }
077   
078              $user_row = [
079                  'user_type'                => USER_IGNORE,
080                  'group_id'                => $group_row['group_id'],
081                  'username'                => $bot_name,
082                  'user_regdate'            => time(),
083                  'user_password'            => '',
084                  'user_colour'            => $group_row['group_colour'],
085                  'user_email'            => '',
086                  'user_lang'                => $this->config['default_lang'],
087                  'user_style'            => $this->config['default_style'],
088                  'user_timezone'            => 0,
089                  'user_dateformat'        => $this->config['default_dateformat'],
090                  'user_allow_massemail'    => 0,
091              ];
092   
093              $user_id = user_add($user_row);
094              $sql = 'INSERT INTO ' . $this->table_prefix . 'bots ' . $this->db->sql_build_array('INSERT', [
095                  'bot_active'    => 1,
096                  'bot_name'        => $bot_name,
097                  'user_id'        => (int) $user_id,
098                  'bot_agent'        => $bot_agent,
099                  'bot_ip'        => '',
100              ]);
101              $this->db->sql_query($sql);
102          }
103      }
104  }
105