/
index.php
200 lines (193 loc) · 7.81 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!--
/**
/* Developer : Suraj Jain
/* Email : mail.surajjain@gmail.com
/* Website : http://developersign.com/
/* Blog Website : http://developersurajjain.blogspot.com/
**/
-->
<?php
require 'server/opencart.php';
require 'server/Session.php';
require 'server/Redirect.php';
define('_ROUTE', explode('opencart_url_master', __DIR__)[0]);
$currentUrl = explode('/',$_SERVER['REQUEST_URI']);
$dirUrl = (isset($currentUrl[1]) && $currentUrl[1] != 'opencart_url_master' ? $currentUrl[1] : '');
$localValue = _getOCLocalValue(_ROUTE . 'index.php');
$localValue = ($localValue) ? $localValue : 'route';
$localURL = _getOCLocalUrl(_ROUTE . 'system/library/url.php', $localValue);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="Suraj Jain" />
<title>Opencart - Change URL Pattern | Developersign</title>
<link rel="stylesheet" href="css/devsj.css" media="all" />
</head>
<body>
<div id="main">
<div class="top-menu">
<ul>
<?php
foreach(glob("*.php") as $file) {
echo '<li><a href="'.$file.'">' . _filter($file) . '</a></li>';
}
?>
</ul>
</div>
<h1>Opencart - Change URL Pattern</h1>
<?php
if(isset($_POST['replaceBy'],$_POST['replaceTo'],$_POST['url_pattern'],$_POST['currentTheme']) && !empty($_POST['replaceBy']) && !empty($_POST['replaceTo']) && !empty($_POST['currentTheme'])) {
extract($_POST);
/*
/ This is a new replacement value to change url pattern.
*/
if(!scan($replaceBy)) {
Session::_setSession('status', '<p style="margin-top: 5px;color: red;">Invalid Text.</p>');
Redirect::to('index.php');
}
$replaceTo = trim($replaceTo);
$replaceBy = trim($replaceBy);
$theme = trim($currentTheme);
$urlPattern = (isset($url_pattern) && !empty($url_pattern)? trim($url_pattern) : '');
/*
/ Please do Not Change anything
*/
$totalAffectedfiles = $totalPlaces = 0;
$output = '';
$output = '<ul id="files">';
foreach($opencart as $type => $value) {
foreach($value as $dir) {
if($type === 'DIR' && !empty($dir)) {
if(is_dir(_ROUTE . $dir)) {
if($dh = opendir(_ROUTE . $dir)) {
while(($file = readdir($dh)) !== false) {
if($file == '.' || $file == '..')continue;
if($dh2 = opendir(_ROUTE . $dir . $file)) {
while(($filename = readdir($dh2)) !== false) {
if($filename == '.' || $filename == '..')continue;
$actionFile = _ROUTE . $dir . $file . '/' . $filename;
$totalPlaces += _updateOCFile($replaceTo, $replaceBy, $actionFile, $urlPattern);
$output .= '<li>' . $actionFile . '</li>';
$totalAffectedfiles++;
}
closedir($dh2);
}
}
closedir($dh);
}
}
}
else if($type === 'FILE' && !empty($dir)) {
$actionFile = _ROUTE . $dir;
$totalPlaces += _updateOCFile($replaceTo, $replaceBy, $actionFile, $urlPattern);
$output .= '<li>' . $actionFile . '</li>';
$totalAffectedfiles++;
}
else if($type === 'THEME' && !empty($dir)) {
$dir = $dir . $theme . '/template/';
if(is_dir(_ROUTE . $dir)) {
if($dh = opendir(_ROUTE . $dir)) {
while(($file = readdir($dh)) !== false) {
if($file == '.' || $file == '..')continue;
if($dh2 = opendir(_ROUTE . $dir . $file)) {
while(($filename = readdir($dh2)) !== false) {
if($filename == '.' || $filename == '..')continue;
$actionFile = _ROUTE . $dir . $file . '/' . $filename;
$totalPlaces += _updateOCFile($replaceTo, $replaceBy, $actionFile, $urlPattern);
$output .= '<li>' . $actionFile . '</li>';
$totalAffectedfiles++;
}
closedir($dh2);
}
}
closedir($dh);
}
}
}
}
}
$output .= '</ul>';
Session::_setSession('text_data', $output);
Session::_setSession('total_files', $totalAffectedfiles);
Session::_setSession('total_places', $totalPlaces);
Redirect::to('index.php');
} else {
if(Session::_sessionExists('text_data') && Session::_sessionExists('total_files') && Session::_sessionExists('total_places')) {
echo '<div id="overlay-text"><h2 class="redcolor">Warning!!<h2><p>Do not refresh page.</p></div>';
echo Session::_flashSession('text_data');
echo '<div id="bottom-files" style="display:none">
<div class="row"><div class="total_rows">Total Updated Files : <span style="color:#000">' . Session::_flashSession('total_files') . '</span></div></div>
<div class="row"><div class="total_rows">Total Words Replaced : <span style="color:#000">' . Session::_flashSession('total_places') . '</span></div></div>
<div class="row"><div class="col-6"><a href="index.php" class="btn pull-right">Close</a></div>
</div></div>';
} else {
?>
<form name="ocForm" action="" method="post" onsubmit="return confirm('Are you sure you want to update?');">
<div class="row">
<div class="col-3">
<label for="rto" class="pull-right">Select URL Pattern <span style="color:blue;font-size:11px;">(Optional)</span>: </label>
</div>
<div class="col-9">
<select name="url_pattern" class="select">
<option value="">Want to change?</option>
<option value="<?php echo ($localURL === 'index' ? 'noindex' : 'index'); ?>">http://<?php echo $_SERVER['HTTP_HOST'] . '/' . $dirUrl; ?>/<?php echo ($localURL === 'index' ? '' : 'index.php'); ?>?<?php echo $localValue; ?>=common/home</option>
</select>
</div>
</div>
<div class="row">
<div class="col-3">
<label for="rto" class="pull-right">Select Your Current Theme <span style="color:red;font-size:11px;">(Required)</span>: </label>
</div>
<div class="col-9">
<select name="currentTheme" class="select">
<?php
foreach(glob(_ROUTE . "catalog/view/theme/*") as $theme) {
$themeName = explode(_ROUTE . "catalog/view/theme/",$theme)[1];
echo '<option value="'.$themeName.'">'.$themeName.'</option>';
}
?>
</select>
</div>
</div>
<div class="row">
<div class="col-3">
<label for="rto" class="pull-right">Old Text <span style="color:red;font-size:11px;">(Required)</span>: </label>
</div>
<div class="col-9">
<input type="text" name="replaceTo" id="rto" autocomplete="off" class="text" value="<?php echo $localValue; ?>" readonly="readonly" style="color:#999" />
</div>
</div>
<div class="row">
<div class="col-3">
<label for="rby" class="pull-right">Enter New Text <span style="color:red;font-size:11px;">(Required)</span>: </label>
</div>
<div class="col-9">
<input type="text" name="replaceBy" id="rby" autocomplete="off" class="text" value="" /><br />
<small>Note : <br />
1) Only characters <strong>[a-zA-Z]</strong>, number <strong>[0-9]</strong> and special characters <strong>(_ - | $ @)</strong> are allowed.<br />
2) The text must have one character and one (number or special character).<br />
3) Valid formats = <span style="color:green">_dir, 23-dir, pp-39, |page</span><br />
3) Invalid formats = <span style="color:red">_232, page, |33, _, route</span></small>
</div>
</div>
<div class="row">
<div class="col-3">
<label for="rby"> </label>
</div>
<div class="col-9">
<input type="submit" name="submit-form" value="Replace" class="btn" />
<?php if(Session::_sessionExists('status')) { echo Session::_flashSession('status'); } ?>
</div>
</div>
</form>
<?php
}
}
?>
</div>
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="js/devsj.js"></script>
</body>
</html>