1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package sitemaker |
5
|
|
|
* @copyright (c) 2013 Daniel A. (blitze) |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace blitze\content\migrations\v20x; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Initial schema changes needed for Extension installation |
14
|
|
|
*/ |
15
|
|
|
class m2_initial_data extends \phpbb\db\migration\container_aware_migration |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @inheritdoc |
19
|
|
|
*/ |
20
|
|
|
static public function depends_on() |
21
|
|
|
{ |
22
|
|
|
return array( |
23
|
|
|
'\blitze\content\migrations\v20x\m1_initial_schema', |
24
|
|
|
'\blitze\content\migrations\converter\c1_update_config', |
25
|
|
|
); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @inheritdoc |
30
|
|
|
*/ |
31
|
|
|
public function update_data() |
32
|
|
|
{ |
33
|
|
|
return array( |
34
|
|
|
array('custom', array(array($this, 'create_forum'))), |
35
|
|
|
array('custom', array(array($this, 'create_bbcodes'))), |
36
|
|
|
array('config.add', array('blitze_content_forum_id', 0)), |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* |
42
|
|
|
*/ |
43
|
|
|
public function create_forum() |
44
|
|
|
{ |
45
|
|
|
$forum = $this->container->get('blitze.sitemaker.forum.manager'); |
46
|
|
|
|
47
|
|
|
$forum_data = array( |
48
|
|
|
'forum_type' => FORUM_CAT, |
49
|
|
|
'forum_name' => 'Sitemaker Content', |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
if (!empty($this->config['blitze_content_forum_id'])) |
53
|
|
|
{ |
54
|
|
|
$forum_data['forum_id'] = (int) $this->config['blitze_content_forum_id']; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$errors = $forum->add($forum_data); |
58
|
|
|
|
59
|
|
|
if (!sizeof($errors)) |
60
|
|
|
{ |
61
|
|
|
$forum_id = (int) $forum_data['forum_id']; |
62
|
|
|
$this->config->set('blitze_content_forum_id', $forum_id); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* |
68
|
|
|
*/ |
69
|
|
|
public function create_bbcodes() |
70
|
|
|
{ |
71
|
|
|
if (!class_exists('acp_bbcodes')) |
72
|
|
|
{ |
73
|
|
|
include($this->phpbb_root_path . 'includes/acp/acp_bbcodes.' . $this->php_ext); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$bbcodes_ary = array( |
77
|
|
|
array( |
78
|
|
|
'match' => '[tag={IDENTIFIER}]{TEXT}[/tag]', |
79
|
|
|
'template' => "<!-- begin field -->\n" . |
80
|
|
|
"<h4>{IDENTIFIER}</h4><br />\n" . |
81
|
|
|
"<div data-field=\"{IDENTIFIER}\">{TEXT}</div><br />\n" . |
82
|
|
|
"<!-- end field -->\n", |
83
|
|
|
), |
84
|
|
|
array( |
85
|
|
|
'match' => '[page={SIMPLETEXT}]{TEXT}[/page]', |
86
|
|
|
'template' => "<!-- begin page -->\n" . |
87
|
|
|
"<i>{SIMPLETEXT}</i>\n" . |
88
|
|
|
"<div data-page=\"{SIMPLETEXT}\">{TEXT}</div><br />\n" . |
89
|
|
|
"<!-- end page -->\n", |
90
|
|
|
), |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$sql = 'SELECT bbcode_id, bbcode_tag |
94
|
|
|
FROM ' . BBCODES_TABLE . ' |
95
|
|
|
ORDER BY bbcode_id ASC'; |
96
|
|
|
$result = $this->db->sql_query($sql); |
97
|
|
|
|
98
|
|
|
$max_bbcode_id = NUM_CORE_BBCODES; |
99
|
|
|
$current_bbcodes = array(); |
100
|
|
|
|
101
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
102
|
|
|
{ |
103
|
|
|
$max_bbcode_id = (int) $row['bbcode_id']; |
104
|
|
|
$current_bbcodes[$row['bbcode_tag']] = $row['bbcode_id']; |
105
|
|
|
} |
106
|
|
|
$this->db->sql_freeresult($result); |
107
|
|
|
|
108
|
|
|
// Make sure max_bbcode_id is not less than the core bbcode ids... |
109
|
|
|
if ($max_bbcode_id < NUM_CORE_BBCODES) |
110
|
|
|
{ |
111
|
|
|
$max_bbcode_id = NUM_CORE_BBCODES; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$bbcode_manager = new \acp_bbcodes(); |
115
|
|
|
|
116
|
|
|
foreach ($bbcodes_ary as $bbcode) |
117
|
|
|
{ |
118
|
|
|
$data = $bbcode_manager->build_regexp($bbcode['match'], $bbcode['template']); |
119
|
|
|
|
120
|
|
|
$sql_ary = array( |
121
|
|
|
'bbcode_tag' => $data['bbcode_tag'], |
122
|
|
|
'bbcode_match' => $bbcode['match'], |
123
|
|
|
'bbcode_tpl' => $bbcode['template'], |
124
|
|
|
'display_on_posting' => false, |
125
|
|
|
'bbcode_helpline' => '', |
126
|
|
|
'first_pass_match' => $data['first_pass_match'], |
127
|
|
|
'first_pass_replace' => $data['first_pass_replace'], |
128
|
|
|
'second_pass_match' => $data['second_pass_match'], |
129
|
|
|
'second_pass_replace' => $data['second_pass_replace'] |
130
|
|
|
); |
131
|
|
|
|
132
|
|
|
// Does this bbcode already exist? |
133
|
|
|
if (isset($current_bbcodes[$sql_ary['bbcode_tag']])) |
134
|
|
|
{ |
135
|
|
|
$this->db->sql_query('UPDATE ' . BBCODES_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE bbcode_id = ' . (int) $current_bbcodes[$sql_ary['bbcode_tag']]); |
136
|
|
|
} |
137
|
|
|
else |
138
|
|
|
{ |
139
|
|
|
$sql_ary['bbcode_id'] = ++$max_bbcode_id; |
140
|
|
|
|
141
|
|
|
$this->db->sql_query('INSERT INTO ' . BBCODES_TABLE . $this->db->sql_build_array('INSERT', $sql_ary)); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$this->container->get('cache.driver')->destroy('sql', BBCODES_TABLE); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|