Skip to content

Commit d2556fd

Browse files
committed
[improve] added automatic changes to framework files
1 parent 2c607ee commit d2556fd

4 files changed

Lines changed: 346 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ Released under the GPL V3 license: https://opensource.org/licenses/GPL-3.0
1717
2. Create a live account
1818
3. Create an app key for your osCommerce website
1919
4. Upload the files in the `upload` folder to root of your osCommerce store.
20+
21+
NOTE:
22+
23+
To skip steps 5 - 7, upload `oscautochange.php` file to your osCommerce store root.\
24+
Then access `YOUR_WEB_URL/oscautochange.php` in browser address bar.\
25+
Will show log/success messages based on script status and the file `oscautochange.php` will be deleted.\
26+
Then go to step 8.
27+
2028
5. In: `includes/template_top.php` add:
2129
```
2230
<?php if ( basename( $PHP_SELF ) == 'checkout_confirmation.php' ) : ?>

README_Phoenix.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ Released under the GPL V3 license: https://opensource.org/licenses/GPL-3.0
1616
2. Create a live account
1717
3. Create an app key for your osCommerce website
1818
4. Upload the files in the `upload` folder to root of your osCommerce store.
19+
20+
NOTE:
21+
22+
To skip steps 5 - 7, upload `phoenixautochange.php` file to your osCommerce store root.\
23+
Then access `YOUR_WEB_URL/phoenixautochange.php` in browser address bar.\
24+
Will show log/success messages based on script status and the file `phoenixautochange.php` will be deleted.\
25+
Then go to step 8.
26+
1927
5. In: `includes/application_top.php` add:
2028
```
2129
if ( basename( $PHP_SELF ) == 'checkout_confirmation.php' ) {

oscautochange.php

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
3+
/**
4+
* Insert new lines in "includes/template_top.php" file
5+
*/
6+
$templateTop = 'includes/template_top.php';
7+
$templateTopMatch = 'src= "includes/javascript/paylike.js"';
8+
$templateTopFind = '<head>';
9+
$templateTopInsert = '
10+
<head>
11+
<?php if ( basename( $PHP_SELF ) == \'checkout_confirmation.php\' ) : ?>
12+
<script src= "includes/javascript/paylike.js"></script>
13+
<?php endif ?>
14+
';
15+
16+
modifyFileContents($templateTop, $templateTopMatch, $templateTopFind, $templateTopInsert);
17+
18+
/**
19+
* Insert new lines at the end in "includes/.htaccess" file
20+
*/
21+
$htaccess = 'includes/.htaccess';
22+
$htaccessMatch = 'FilesMatch "paylike.php"';
23+
$htaccessFind = '';
24+
$htaccessInsert = '
25+
<FilesMatch "paylike.php">
26+
Allow from all
27+
</FilesMatch>
28+
';
29+
30+
modifyFileContents($htaccess, $htaccessMatch, $htaccessFind, $htaccessInsert, $endOfFile = true);
31+
32+
/**
33+
* Insert (I) new lines in "admin/modules.php" file
34+
*/
35+
$modules_1 = 'admin/modules.php';
36+
$modules_1_Match = 'payment/paylike/errors.php';
37+
$modules_1_Find = 'require(\'includes/application_top.php\');';
38+
$modules_1_Insert = '
39+
require_once(\'includes/modules/payment/paylike/errors.php\');
40+
require(\'includes/application_top.php\');
41+
';
42+
43+
modifyFileContents($modules_1, $modules_1_Match, $modules_1_Find, $modules_1_Insert);
44+
45+
/**
46+
* Insert (II) new lines in "admin/modules.php" file
47+
*/
48+
$modules_2 = 'admin/modules.php';
49+
$modules_2_Match = 'payment/paylike/validate.php';
50+
$modules_2_Find = 'reset($HTTP_POST_VARS[\'configuration\']);';
51+
$modules_2_Insert = '
52+
reset($HTTP_POST_VARS[\'configuration\']);
53+
require_once(\'includes/modules/payment/paylike/validate.php\');
54+
';
55+
56+
modifyFileContents($modules_2, $modules_2_Match, $modules_2_Find, $modules_2_Insert);
57+
58+
/**
59+
* Insert (III) new lines in "admin/modules.php" file
60+
*/
61+
$modules_3 = 'admin/modules.php';
62+
$modules_3_Match = 'if(sizeof($errors) === 0 || array_search($key, $validation_keys) === FALSE)';
63+
$modules_3_Find = 'tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = \'" . $value . "\' where configuration_key = \'" . $key . "\'");';
64+
$modules_3_Insert = '
65+
if(sizeof($errors) === 0 || array_search($key, $validation_keys) === FALSE){
66+
tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = \'" . $value . "\' where configuration_key = \'" . $key . "\'");
67+
}
68+
';
69+
70+
modifyFileContents($modules_3, $modules_3_Match, $modules_3_Find, $modules_3_Insert);
71+
72+
/**
73+
* Insert (IV) new lines in "admin/modules.php" file
74+
*/
75+
$modules_4 = 'admin/modules.php';
76+
$modules_4_Match = 'if(sizeof($errors)){';
77+
$modules_4_Find = 'tep_redirect(tep_href_link(FILENAME_MODULES, \'set=\' . $set . \'&module=\' . $HTTP_GET_VARS[\'module\']));';
78+
$modules_4_Insert = '
79+
if(sizeof($errors)){
80+
tep_redirect(tep_href_link(FILENAME_MODULES, \'set=\' . $set . \'&module=\' . $HTTP_GET_VARS[\'module\'] . \'&action=edit\'));
81+
}
82+
tep_redirect(tep_href_link(FILENAME_MODULES, \'set=\' . $set . \'&module=\' . $HTTP_GET_VARS[\'module\']));
83+
';
84+
85+
modifyFileContents($modules_4, $modules_4_Match, $modules_4_Find, $modules_4_Insert);
86+
87+
/**
88+
* Insert (V) new lines in "admin/modules.php" file
89+
*/
90+
$modules_5 = 'admin/modules.php';
91+
$modules_5_Match = '(isset($errorHandler))$errorHandler->display()';
92+
$modules_5_Find = 'case \'edit\':';
93+
$modules_5_Insert = '
94+
case \'edit\':
95+
if(isset($errorHandler))$errorHandler->display();
96+
';
97+
98+
modifyFileContents($modules_5, $modules_5_Match, $modules_5_Find, $modules_5_Insert);
99+
100+
101+
102+
/** SELF-DELETE this file. */
103+
echo 'Now the script will be deleted';
104+
unlink(__FILE__);
105+
106+
107+
108+
/** ***************************** FUNCTION AREA ****************************************** */
109+
110+
/**
111+
* Modify file contents with desired text to insert
112+
* - search if text to insert is present
113+
* - replace portion of text with another OR insert text to the end of the file
114+
*
115+
* @param string $relativeFilePath - the file relative path as 'folder/anotherFolder/file.ext'
116+
* @param string $matchText - if this text is present the file will be untouched
117+
* @param string $findText - the text where to begin insertion
118+
* @param string $insertText - the text to be inserted
119+
* @param bool $endOfFile - specify if the desired text has to be inserted to the end of the file
120+
*
121+
* @return void
122+
*
123+
*/
124+
125+
function modifyFileContents($relativeFilePath, $matchText, $findText, $insertText, $endOfFile = false) : void
126+
{
127+
try {
128+
/** Check file existence. */
129+
if (file_exists($relativeFilePath)) {
130+
$file = file_get_contents($relativeFilePath);
131+
} else {
132+
echo 'File not exists -> ' . $relativeFilePath . PHP_EOL . '<br>';
133+
}
134+
135+
/** Check if the file NOT contains the text for insertion. */
136+
if (false === strstr($file, $matchText)) {
137+
138+
/** Check if "$endOfFile" is set to false. */
139+
if (false === $endOfFile) {
140+
/** Insert the new code lines. */
141+
$modifiedFileContents =
142+
str_replace(
143+
$search = $findText,
144+
$replace = $insertText,
145+
$subject = $file
146+
);
147+
148+
/** Write modified contents to the file. */
149+
file_put_contents($relativeFilePath, $modifiedFileContents);
150+
151+
} else {
152+
/** Append the new code lines and writes to the file. */
153+
file_put_contents($relativeFilePath, $insertText, FILE_APPEND);
154+
}
155+
156+
echo 'Successfully changed ' . $relativeFilePath . PHP_EOL . '<br>';
157+
158+
} else {
159+
echo 'Changes already applied to ' . $relativeFilePath . PHP_EOL . '<br>';
160+
}
161+
162+
} catch (Exception $e) {
163+
echo $e->getMessage();
164+
}
165+
}

phoenixautochange.php

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
3+
/**
4+
* Insert new lines in "includes/application_top.php" file
5+
*/
6+
$applicationTop = 'includes/application_top.php';
7+
$applicationTopMatch = 'src= "includes/javascript/paylike.js"';
8+
$applicationTopFind = '';
9+
$applicationTopInsert = '
10+
if ( basename( $PHP_SELF ) == \'checkout_confirmation.php\' ) {
11+
echo \'<script src="https://sdk.paylike.io/10.js"></script>\';
12+
echo \'<script src= "includes/javascript/paylike.js"></script>\';
13+
}
14+
';
15+
16+
modifyFileContents($applicationTop, $applicationTopMatch, $applicationTopFind, $applicationTopInsert, $endOfFile = true);
17+
18+
/**
19+
* Insert new lines at the end in "includes/.htaccess" file
20+
*/
21+
$htaccess = 'includes/.htaccess';
22+
$htaccessMatch = 'FilesMatch "paylike.php"';
23+
$htaccessFind = '';
24+
$htaccessInsert = '
25+
<FilesMatch "paylike.php">
26+
Require all granted
27+
</FilesMatch>
28+
';
29+
30+
modifyFileContents($htaccess, $htaccessMatch, $htaccessFind, $htaccessInsert, $endOfFile = true);
31+
32+
/**
33+
* Insert (I) new lines in "admin/modules.php" file
34+
*/
35+
$modules_1 = 'admin/modules.php';
36+
$modules_1_Match = 'payment/paylike/errors.php';
37+
$modules_1_Find = 'require \'includes/application_top.php\';';
38+
$modules_1_Insert = '
39+
require_once(\'includes/modules/payment/paylike/errors.php\');
40+
require \'includes/application_top.php\';
41+
';
42+
43+
modifyFileContents($modules_1, $modules_1_Match, $modules_1_Find, $modules_1_Insert);
44+
45+
/**
46+
* Insert (II) new lines in "admin/modules.php" file
47+
*/
48+
$modules_2 = 'admin/modules.php';
49+
$modules_2_Match = 'payment/paylike/validate.php';
50+
$modules_2_Find = 'case \'save\':';
51+
$modules_2_Insert = '
52+
case \'save\':
53+
require_once(\'includes/modules/payment/paylike/validate.php\');
54+
';
55+
56+
modifyFileContents($modules_2, $modules_2_Match, $modules_2_Find, $modules_2_Insert);
57+
58+
/**
59+
* Insert (III) new lines in "admin/modules.php" file
60+
*/
61+
$modules_3 = 'admin/modules.php';
62+
$modules_3_Match = 'if(sizeof($errors) === 0 || array_search($key, $validation_keys) === FALSE)';
63+
$modules_3_Find = 'tep_db_query("UPDATE configuration SET configuration_value = \'" . tep_db_input($value) . "\' WHERE configuration_key = \'" . tep_db_input($key) . "\'");';
64+
$modules_3_Insert = '
65+
if(sizeof($errors) === 0 || array_search($key, $validation_keys) === FALSE){
66+
tep_db_query("UPDATE configuration SET configuration_value = \'" . tep_db_input($value) . "\' WHERE configuration_key = \'" . tep_db_input($key) . "\'");
67+
}
68+
';
69+
70+
modifyFileContents($modules_3, $modules_3_Match, $modules_3_Find, $modules_3_Insert);
71+
72+
/**
73+
* Insert (IV) new lines in "admin/modules.php" file
74+
*/
75+
$modules_4 = 'admin/modules.php';
76+
$modules_4_Match = 'if(sizeof($errors)){';
77+
$modules_4_Find = 'tep_redirect(tep_href_link(\'modules.php\', \'set=\' . $set . \'&module=\' . $_GET[\'module\']));';
78+
$modules_4_Insert = '
79+
if(sizeof($errors)){
80+
tep_redirect(tep_href_link(\'modules.php\', \'set=\' . $set . \'&module=\' . $_GET[\'module\'] . \'&action=edit\'));
81+
}
82+
tep_redirect(tep_href_link(\'modules.php\', \'set=\' . $set . \'&module=\' . $_GET[\'module\']));
83+
';
84+
85+
modifyFileContents($modules_4, $modules_4_Match, $modules_4_Find, $modules_4_Insert);
86+
87+
/**
88+
* Insert (V) new lines in "admin/modules.php" file
89+
*/
90+
$modules_5 = 'admin/modules.php';
91+
$modules_5_Match = 'isset($errorHandler))$errorHandler->display()';
92+
$modules_5_Find = '<div class="row no-gutters">';
93+
$modules_5_Insert = '
94+
<?php if(isset($errorHandler))$errorHandler->display(); ?>
95+
<div class="row no-gutters">
96+
';
97+
98+
modifyFileContents($modules_5, $modules_5_Match, $modules_5_Find, $modules_5_Insert);
99+
100+
101+
102+
/** SELF-DELETE this file. */
103+
echo 'Now the script will be deleted';
104+
unlink(__FILE__);
105+
106+
107+
108+
/** ***************************** FUNCTION AREA ****************************************** */
109+
110+
/**
111+
* Modify file contents with desired text to insert
112+
* - search if text to insert is present
113+
* - replace portion of text with another OR insert text to the end of the file
114+
*
115+
* @param string $relativeFilePath - the file relative path as 'folder/anotherFolder/file.ext'
116+
* @param string $matchText - if this text is present the file will be untouched
117+
* @param string $findText - the text where to begin insertion
118+
* @param string $insertText - the text to be inserted
119+
* @param bool $endOfFile - specify if the desired text has to be inserted to the end of the file
120+
*
121+
* @return void
122+
*
123+
*/
124+
125+
function modifyFileContents($relativeFilePath, $matchText, $findText, $insertText, $endOfFile = false) : void
126+
{
127+
try {
128+
/** Check file existence. */
129+
if (file_exists($relativeFilePath)) {
130+
$file = file_get_contents($relativeFilePath);
131+
} else {
132+
echo 'File not exists -> ' . $relativeFilePath . PHP_EOL . '<br>';
133+
}
134+
135+
/** Check if the file NOT contains the text for insertion. */
136+
if (false === strstr($file, $matchText)) {
137+
138+
/** Check if "$endOfFile" is set to false. */
139+
if (false === $endOfFile) {
140+
/** Insert the new code lines. */
141+
$modifiedFileContents =
142+
str_replace(
143+
$search = $findText,
144+
$replace = $insertText,
145+
$subject = $file
146+
);
147+
148+
/** Write modified contents to the file. */
149+
file_put_contents($relativeFilePath, $modifiedFileContents);
150+
151+
} else {
152+
/** Append the new code lines and writes to the file. */
153+
file_put_contents($relativeFilePath, $insertText, FILE_APPEND);
154+
}
155+
156+
echo 'Successfully changed ' . $relativeFilePath . PHP_EOL . '<br>';
157+
158+
} else {
159+
echo 'Changes already applied to ' . $relativeFilePath . PHP_EOL . '<br>';
160+
}
161+
162+
} catch (Exception $e) {
163+
echo $e->getMessage();
164+
}
165+
}

0 commit comments

Comments
 (0)