1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-01-18 22:58:10 +01:00

[ticket/16338] Add DuckDuckGo bot

PHPBB3-16338
This commit is contained in:
Alfredo Ramos 2020-04-06 16:02:20 -05:00
parent c7be5d25d0
commit 99dbea1469
3 changed files with 93 additions and 0 deletions

View File

@ -1840,6 +1840,7 @@ function add_bots()
'Ask Jeeves [Bot]' => array('Ask Jeeves', ''),
'Baidu [Spider]' => array('Baiduspider+(', ''),
'Bing [Bot]' => array('bingbot/', ''),
'DuckDuckGo [Bot]' => array('DuckDuckBot/', ''),
'Exabot [Bot]' => array('Exabot/', ''),
'FAST Enterprise [Crawler]' => array('FAST Enterprise Crawler', ''),
'FAST WebCrawler [Crawler]' => array('FAST-WebCrawler/', ''),

View File

@ -0,0 +1,91 @@
<?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.
*
*/
namespace phpbb\db\migration\data\v33x;
class bot_update extends \phpbb\db\migration\migration
{
static public function depends_on()
{
return ['\phpbb\db\migration\data\v330\v330'];
}
public function update_data()
{
return [
['custom', [[$this, 'add_duckduckgo_bot']]],
];
}
public function add_duckduckgo_bot()
{
$bot_name = 'DuckDuckGo [Bot]';
$bot_name_clean = utf8_clean_string($bot_name);
$sql = 'SELECT user_id
FROM ' . $this->table_prefix . 'users
WHERE ' . $this->db->sql_build_array('SELECT', ['username_clean' => $bot_name_clean]);
$result = $this->db->sql_query($sql);
$bot_exists = (bool) $this->db->sql_fetchfield('user_id');
$this->db->sql_freeresult($result);
if (!$bot_exists)
{
$bot_agent = 'DuckDuckBot/';
$bot_ip = '';
$sql = 'SELECT group_id, group_colour
FROM ' . $this->table_prefix . 'groups
WHERE ' . $this->db->sql_build_array('SELECT', ['group_name' => 'BOTS']);
$result = $this->db->sql_query($sql);
$group_row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
// Default fallback, should never get here
if (!$group_row)
{
$group_row['group_id'] = 6;
$group_row['group_colour'] = '9E8DA7';
}
if (!function_exists('user_add'))
{
include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
}
$user_row = [
'user_type' => USER_IGNORE,
'group_id' => $group_row['group_id'],
'username' => $bot_name,
'user_regdate' => time(),
'user_password' => '',
'user_colour' => $group_row['group_colour'],
'user_email' => '',
'user_lang' => $this->config['default_lang'],
'user_style' => $this->config['default_style'],
'user_timezone' => 0,
'user_dateformat' => $this->config['default_dateformat'],
'user_allow_massemail' => 0,
];
$user_id = user_add($user_row);
$sql = 'INSERT INTO ' . $this->table_prefix . 'bots ' . $this->db->sql_build_array('INSERT', [
'bot_active' => 1,
'bot_name' => (string) $bot_name,
'user_id' => (int) $user_id,
'bot_agent' => (string) $bot_agent,
'bot_ip' => (string) $bot_ip,
]);
$this->db->sql_query($sql);
}
}
}

View File

@ -63,6 +63,7 @@ class add_bots extends \phpbb\install\task_base
'Ask Jeeves [Bot]' => array('Ask Jeeves', ''),
'Baidu [Spider]' => array('Baiduspider', ''),
'Bing [Bot]' => array('bingbot/', ''),
'DuckDuckGo [Bot]' => array('DuckDuckBot/', ''),
'Exabot [Bot]' => array('Exabot', ''),
'FAST Enterprise [Crawler]' => array('FAST Enterprise Crawler', ''),
'FAST WebCrawler [Crawler]' => array('FAST-WebCrawler/', ''),