1
|
|
|
<?php |
2
|
|
|
// ------------------------------------------------------------------------- // |
3
|
|
|
// mytplsform.php // |
4
|
|
|
// - XOOPS templates admin for each modules - // |
5
|
|
|
// GIJOE <http://www.peak.ne.jp/> // |
6
|
|
|
// ------------------------------------------------------------------------- // |
7
|
|
|
|
8
|
|
|
include_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php'; |
9
|
|
|
include_once dirname(__DIR__) . '/include/gtickets.php'; |
10
|
|
|
include_once XOOPS_ROOT_PATH . '/class/template.php'; |
11
|
|
|
|
12
|
|
|
include_once dirname(__DIR__) . '/class/Text_Diff.php'; |
13
|
|
|
include_once dirname(__DIR__) . '/class/Text_Diff_Renderer.php'; |
14
|
|
|
include_once dirname(__DIR__) . '/class/Text_Diff_Renderer_unified.php'; |
15
|
|
|
|
16
|
|
|
$xoops_system_path = XOOPS_ROOT_PATH . '/modules/system'; |
17
|
|
|
|
18
|
|
|
// initials |
19
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
20
|
|
|
$myts = MyTextSanitizer::getInstance(); |
21
|
|
|
|
22
|
|
|
// determine language |
23
|
|
|
$language = $xoopsConfig['language']; |
24
|
|
|
if (!file_exists("{$xoops_system_path}/language/{$language}/admin/tplsets.php")) { |
25
|
|
|
$language = 'english'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
// load language constants |
29
|
|
|
// to prevent from notice that constants already defined |
30
|
|
|
$error_reporting_level = error_reporting(0); |
31
|
|
|
include_once "{$xoops_system_path}/constants.php"; |
32
|
|
|
include_once "{$xoops_system_path}/language/$language/admin.php"; |
33
|
|
|
include_once "{$xoops_system_path}/language/$language/admin/tplsets.php"; |
34
|
|
|
error_reporting($error_reporting_level); |
35
|
|
|
|
36
|
|
|
// check $xoopsModule |
37
|
|
|
if (!is_object($xoopsModule)) { |
38
|
|
|
redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
// check access right (needs system_admin of tplset) |
42
|
|
|
$syspermHandler = xoops_getHandler('groupperm'); |
43
|
|
View Code Duplication |
if (!$syspermHandler->checkRight('system_admin', XOOPS_SYSTEM_TPLSET, $xoopsUser->getGroups())) { |
|
|
|
|
44
|
|
|
redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// tpl_file from $_GET |
48
|
|
|
$tpl_file = $myts->stripSlashesGPC(@$_GET['tpl_file']); |
49
|
|
|
$tpl_file4sql = addslashes($tpl_file); |
50
|
|
|
|
51
|
|
|
// tpl_file from $_GET |
52
|
|
|
$tpl_tplset = $myts->stripSlashesGPC(@$_GET['tpl_tplset']); |
53
|
|
|
$tpl_tplset4sql = addslashes($tpl_tplset); |
54
|
|
|
|
55
|
|
|
// get information from tplfile table |
56
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('tplfile') . ' f NATURAL LEFT JOIN ' . $db->prefix('tplsource') . " s WHERE f.tpl_file='{$tpl_file4sql}' AND f.tpl_tplset='{$tpl_tplset4sql}'"; |
57
|
|
|
$tpl = $db->fetchArray($db->query($sql)); |
58
|
|
|
if (empty($tpl)) { |
59
|
|
|
die('Invalid tpl_file or tpl_tplset.'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
//************// |
63
|
|
|
// POST stage // |
64
|
|
|
//************// |
65
|
|
|
if (!empty($_POST['do_modify'])) { |
66
|
|
|
// Ticket Check |
67
|
|
|
if (!$xoopsGTicket->check()) { |
68
|
|
|
redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$result = $db->query('SELECT tpl_id FROM ' . $db->prefix('tplfile') . " WHERE tpl_file='{$tpl_file4sql}' AND tpl_tplset='{$tpl_tplset4sql}'"); |
72
|
|
|
while (list($tpl_id) = $db->fetchRow($result)) { |
73
|
|
|
$sql = 'UPDATE ' . $db->prefix('tplsource') . " SET tpl_source='" . addslashes($myts->stripSlashesGPC($_POST['tpl_source'])) . "' WHERE tpl_id=$tpl_id"; |
74
|
|
|
if (!$db->query($sql)) { |
75
|
|
|
die('SQL Error'); |
76
|
|
|
} |
77
|
|
|
$db->query('UPDATE ' . $db->prefix('tplfile') . " SET tpl_lastmodified=UNIX_TIMESTAMP() WHERE tpl_id={$tpl_id}"); |
78
|
|
|
xoops_template_touch($tpl_id); |
79
|
|
|
} |
80
|
|
|
redirect_header('mytplsadmin.php?dirname=' . $tpl['tpl_module'], 1, _MD_MYLINKS_DBUPDATED); |
81
|
|
|
exit; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
xoops_cp_header(); |
85
|
|
|
$mymenu_fake_uri = "/admin/mytplsadmin.php?dirname={$tpl['tpl_module']}"; |
86
|
|
|
|
87
|
|
|
if (file_exists('./mymenu.php')) { |
88
|
|
|
include './mymenu.php'; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
echo "<h3 style='text-align:left;'>" . _AM_MYLINKS_TPLSETS . ' : ' . htmlspecialchars($tpl['tpl_type'], ENT_QUOTES) . ' : ' . htmlspecialchars($tpl['tpl_file'], ENT_QUOTES) . ' (' . htmlspecialchars($tpl['tpl_tplset'], ENT_QUOTES) . ")</h3>\n"; |
92
|
|
|
|
93
|
|
|
// diff from file to selected DB template |
94
|
|
|
$basefilepath = XOOPS_ROOT_PATH . '/modules/' . $tpl['tpl_module'] . '/templates/' . ($tpl['tpl_type'] == 'block' ? 'blocks/' : '') . $tpl['tpl_file']; |
95
|
|
|
$diff_from_file4disp = ''; |
96
|
|
|
if (file_exists($basefilepath)) { |
97
|
|
|
$diff = new Text_Diff(file($basefilepath), explode("\n", $tpl['tpl_source'])); |
98
|
|
|
$renderer = new Text_Diff_Renderer_unified(); |
99
|
|
|
$diff_str = htmlspecialchars($renderer->render($diff), ENT_QUOTES); |
100
|
|
View Code Duplication |
foreach (explode("\n", $diff_str) as $line) { |
|
|
|
|
101
|
|
|
if (ord($line) == 0x2d) { |
102
|
|
|
$diff_from_file4disp .= "<span style='color:red;'>{$line}</span>\n"; |
103
|
|
|
} elseif (ord($line) == 0x2b) { |
104
|
|
|
$diff_from_file4disp .= "<span style='color:blue;'>{$line}</span>\n"; |
105
|
|
|
} else { |
106
|
|
|
$diff_from_file4disp .= "{$line}\n"; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
// diff from DB-default to selected DB template |
112
|
|
|
$diff_from_default4disp = ''; |
113
|
|
|
if ($tpl['tpl_tplset'] != 'default') { |
114
|
|
|
list($default_source) = $db->fetchRow($db->query('SELECT tpl_source FROM ' . $db->prefix('tplfile') . ' NATURAL LEFT JOIN ' . $db->prefix('tplsource') . " WHERE tpl_tplset='default' AND tpl_file='" . addslashes($tpl['tpl_file']) . "' AND tpl_module='" . addslashes($tpl['tpl_module']) . "'")); |
115
|
|
|
$diff = new Text_Diff(explode("\n", $default_source), explode("\n", $tpl['tpl_source'])); |
116
|
|
|
$renderer = new Text_Diff_Renderer_unified(); |
117
|
|
|
$diff_str = htmlspecialchars($renderer->render($diff), ENT_QUOTES); |
118
|
|
View Code Duplication |
foreach (explode("\n", $diff_str) as $line) { |
|
|
|
|
119
|
|
|
if (ord($line) == 0x2d) { |
120
|
|
|
$diff_from_default4disp .= "<span style='color:red;'>{$line}</span>\n"; |
121
|
|
|
} elseif (ord($line) == 0x2b) { |
122
|
|
|
$diff_from_default4disp .= "<span style='color:blue;'>{$line}</span>\n"; |
123
|
|
|
} else { |
124
|
|
|
$diff_from_default4disp .= "{$line}\n"; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
echo "<form name='diff_form' id='diff_form' action='' method='get'>\n" |
130
|
|
|
. " <input type='checkbox' name='display_diff2file' value='1' onClick=\"if(this.checked){document.getElementById('diff2file').style.display='block'}else{document.getElementById('diff2file').style.display='none'};\" id='display_diff2file' checked='checked'> <label for='display_diff2file'>diff from file</label>\n" |
131
|
|
|
. " <pre id='diff2file' style='display:block;border:1px solid black;'>{$diff_from_file4disp}</pre>\n" |
132
|
|
|
. " <input type='checkbox' name='display_diff2default' value='1' onClick=\"if(this.checked){document.getElementById('diff2default').style.display='block'}else{document.getElementById('diff2default').style.display='none'};\" id='display_diff2default'> <label for='display_diff2default'>diff from default</label>\n" |
133
|
|
|
. " <pre id='diff2default' style='display:none;border:1px solid black;'>{$diff_from_default4disp}</pre>\n" . "</form>\n" . "<form name='MainForm' action='?tpl_file=" . htmlspecialchars($tpl['tpl_file'], ENT_QUOTES) . '&tpl_tplset=' . htmlspecialchars($tpl['tpl_tplset'], ENT_QUOTES) |
134
|
|
|
. "' method='post'>\n" . ' ' . $xoopsGTicket->getTicketHtml(__LINE__) . "\n" . " <textarea name='tpl_source' wrap='off' style='width: 600px; height: 400px;'>" . htmlspecialchars($tpl['tpl_source'], ENT_QUOTES) . "</textarea>\n" . " <br>\n" . " <input type='submit' name='do_modify' value='" |
135
|
|
|
. _SUBMIT . "'>\n" . " <input type='reset' name='reset' value='" . _RESET . "'>\n" . "</form>\n"; |
136
|
|
|
|
137
|
|
|
xoops_cp_footer(); |
138
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.