|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @author Sylver35 <[email protected]> |
|
5
|
|
|
* @package Breizh Smilie Creator Extension |
|
6
|
|
|
* @copyright (c) 2018-2019 Sylver35 https://breizhcode.com |
|
7
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace sylver35\smilecreator\migrations; |
|
11
|
|
|
|
|
12
|
|
|
class release_1_0_0_add_bbcode extends \phpbb\db\migration\migration |
|
13
|
|
|
{ |
|
14
|
|
|
public function update_data() |
|
15
|
|
|
{ |
|
16
|
|
|
return [ |
|
17
|
|
|
// custom function |
|
18
|
|
|
['custom', [[&$this, 'install_bbcode']]], |
|
19
|
|
|
]; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function revert_data() |
|
23
|
|
|
{ |
|
24
|
|
|
return [ |
|
25
|
|
|
['custom', [[&$this, 'remove_bbcode']]], |
|
26
|
|
|
]; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function install_bbcode() |
|
30
|
|
|
{ |
|
31
|
|
|
$sql = 'SELECT bbcode_id FROM ' . $this->table_prefix . "bbcodes WHERE LOWER(bbcode_tag) = 'creator'"; |
|
32
|
|
|
$result = $this->db->sql_query($sql); |
|
33
|
|
|
$row = $this->db->sql_fetchrow($result); |
|
34
|
|
|
$this->db->sql_freeresult($result); |
|
35
|
|
|
|
|
36
|
|
|
if (!$row) |
|
37
|
|
|
{ |
|
38
|
|
|
// Create new BBCode |
|
39
|
|
|
$sql = 'SELECT MAX(bbcode_id) AS max_bbcode_id FROM ' . $this->table_prefix . 'bbcodes'; |
|
40
|
|
|
$result = $this->db->sql_query($sql); |
|
41
|
|
|
$row = $this->db->sql_fetchrow($result); |
|
42
|
|
|
$this->db->sql_freeresult($result); |
|
43
|
|
|
|
|
44
|
|
|
if ($row) |
|
45
|
|
|
{ |
|
46
|
|
|
$bbcode_id = $row['max_bbcode_id'] + 1; |
|
47
|
|
|
// Make sure it is greater than the core BBCode ids... |
|
48
|
|
|
if ($bbcode_id <= NUM_CORE_BBCODES) |
|
49
|
|
|
{ |
|
50
|
|
|
$bbcode_id = NUM_CORE_BBCODES + 1; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
else |
|
54
|
|
|
{ |
|
55
|
|
|
$bbcode_id = NUM_CORE_BBCODES + 1; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if ($bbcode_id <= BBCODE_LIMIT) |
|
59
|
|
|
{ |
|
60
|
|
|
$sql_data = [ |
|
61
|
|
|
'bbcode_tag' => 'creator', |
|
62
|
|
|
'bbcode_id' => (int) $bbcode_id, |
|
63
|
|
|
'bbcode_helpline' => '', |
|
64
|
|
|
'display_on_posting' => 0, |
|
65
|
|
|
'bbcode_match' => '[creator={SIMPLETEXT1},{NUMBER},{SIMPLETEXT2},{SIMPLETEXT3}]{TEXT}[/creator]', |
|
66
|
|
|
'bbcode_tpl' => '<img src="|S_CREATOR_BBCODE|app.php/smilecreate/display?smiley={SIMPLETEXT1}&shieldshadow={NUMBER}&fontcolor={SIMPLETEXT2}&shadowcolor={SIMPLETEXT3}&text={TEXT}" alt="{L_IMAGE}" title="{TEXT}">', |
|
67
|
|
|
'first_pass_match' => '!\[creator\=([a-zA-Z0-9-+.,_ ]+),([0-9]+),([a-zA-Z0-9-+.,_ ]+),([a-zA-Z0-9-+.,_ ]+)\](.*?)\[/creator\]!iu', |
|
68
|
|
|
'first_pass_replace' => '\'[creator=${1},${2},${3},${4}:$uid]\' . str_replace([" ", \'"\', "\'", "&", "&", "$", "!", ",", ";"], [" ", "", "", "", "", "", "", "", ""], ${5}) . \'[/creator:$uid]\'', |
|
69
|
|
|
'second_pass_match' => '!\[creator\=([a-zA-Z0-9-+.,_ ]+),([0-9]+),([a-zA-Z0-9-+.,_ ]+),([a-zA-Z0-9-+.,_ ]+):$uid\](.*?)\[/creator:$uid\]!su', |
|
70
|
|
|
'second_pass_replace' => '<img src="|S_CREATOR_BBCODE|app.php/smilecreate/display?smiley=${1}&shieldshadow=${2}&fontcolor=${3}&shadowcolor=${4}&text=${5}" alt="{L_IMAGE}" title="${5}">', |
|
71
|
|
|
]; |
|
72
|
|
|
$sql = 'INSERT INTO ' . $this->table_prefix . 'bbcodes ' . $this->db->sql_build_array('INSERT', $sql_data); |
|
73
|
|
|
$this->db->sql_query($sql); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function remove_bbcode() |
|
79
|
|
|
{ |
|
80
|
|
|
$sql = 'DELETE FROM ' . BBCODES_TABLE . " WHERE bbcode_tag = 'creator'"; |
|
81
|
|
|
$this->db->sql_query($sql); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|