mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 05:18:52 +00:00
[ticket/13859] Allow up-to-date format for Youtube profile field URLs
Per the tracker issue: > In 3.1 a youtube profilefield was added in which we can insert our youtube > username to link to it.... There is just one major problem though... > > New youtube members no longer get an username. So I think we should decide on > providing different ways to access their profile. This PR will allow users to use any valid YouTube-domain URL, which allows for all 3 formats (`/channel/...`, `/c/...`, and the now-legacy `/user/...`). Per [YouTube's docs](https://support.google.com/youtube/answer/6180214?hl=en): > ## Channel URL (ID-based) > Example: youtube.com/channel/UCUZHFZ9jIKrLroW8LcyJEQQ > > This is the standard URL that YouTube channels use. > > ... > > ## Custom URL > Example: youtube.com/c/YouTubeCreators > > A custom URL is a shorter, easy-to-remember URL that you can share with your > audience. > > ... > > ## Legacy username URL > Example: youtube.com/user/YouTube > > Depending on when your channel was created, it may have a username. Usernames > are no longer required for channels today, but you can still use this URL to > direct to your channel — even if your channel name has changed since you chose > your username. Existing usernames can't be changed. PHPBB3-13859
This commit is contained in:
parent
a12a6f52ae
commit
dd6e110210
1 changed files with 82 additions and 0 deletions
|
@ -0,0 +1,82 @@
|
|||
<?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 profilefield_youtube_update extends \phpbb\db\migration\migration
|
||||
{
|
||||
protected $youtube_url_matcher = 'https:\\/\\/(www\\.)?youtube\\.com\\/.+';
|
||||
|
||||
public function effectively_installed()
|
||||
{
|
||||
$profile_fields = $this->table_prefix . 'profile_fields';
|
||||
|
||||
$result = $this->db->sql_query(
|
||||
"SELECT field_validation
|
||||
FROM $profile_fields
|
||||
WHERE field_name = 'phpbb_youtube'"
|
||||
);
|
||||
|
||||
$row = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
return $row['field_validation'] === $this->youtube_url_matcher;
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return ['\phpbb\db\migration\data\v33x\v337'];
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return [['custom', [[$this, 'update_youtube_profile_field']]]];
|
||||
}
|
||||
|
||||
public function update_youtube_profile_field()
|
||||
{
|
||||
$profile_fields = $this->table_prefix . 'profile_fields';
|
||||
$profile_fields_data = $this->table_prefix . 'profile_fields_data';
|
||||
|
||||
$field_validation = $this->db->sql_escape($this->youtube_url_matcher);
|
||||
|
||||
$min_length = strlen('https://youtube.com/c/') + 1;
|
||||
|
||||
$this->db->sql_query(
|
||||
"UPDATE $profile_fields SET
|
||||
field_length = '40',
|
||||
field_minlen = '$min_length',
|
||||
field_maxlen = '255',
|
||||
field_validation = '$field_validation',
|
||||
field_contact_url = '%s'
|
||||
WHERE field_name = 'phpbb_youtube'"
|
||||
);
|
||||
|
||||
$yt_profile_field = 'pf_phpbb_youtube';
|
||||
$prepend_legacy_youtube_url = $this->db->sql_concatenate(
|
||||
"'https://youtube.com/user/'", $yt_profile_field
|
||||
);
|
||||
$is_not_already_youtube_url = $this->db->sql_not_like_expression(
|
||||
$this->db->get_any_char()
|
||||
. 'youtube.com/'
|
||||
. $this->db->get_any_char()
|
||||
);
|
||||
|
||||
$this->db->sql_query(
|
||||
"UPDATE $profile_fields_data SET
|
||||
$yt_profile_field = $prepend_legacy_youtube_url
|
||||
WHERE $yt_profile_field <> ''
|
||||
AND $yt_profile_field $is_not_already_youtube_url"
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue