Skip to content

Instantly share code, notes, and snippets.

@FernandoGarcia
Last active February 19, 2022 09:18
Show Gist options
  • Save FernandoGarcia/4219f0530986fbbfcfb39c9ed1695489 to your computer and use it in GitHub Desktop.
Save FernandoGarcia/4219f0530986fbbfcfb39c9ed1695489 to your computer and use it in GitHub Desktop.
Make ABBC3 compatible with PHBB 3.14 and PHP 7
diff -ur orig/includes/bbcode.php phpBB3.14/includes/bbcode.php
--- orig/includes/bbcode.php 2019-12-06 21:27:48.073460091 -0300
+++ phpBB3.14/includes/bbcode.php 2019-12-06 20:51:26.565100654 -0300
@@ -125,6 +127,406 @@
}
$message = preg_replace($preg['search'], $preg['replace'], $message);
+
+ // Start Text_effect_pass
+ $regex = "/(\\$)(this->Text_effect_pass)(\().*?(\')(,)( )(\').*?(\')(,)( )(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = preg_split("/(\\$)(this->Text_effect_pass)/", $func);
+ $param = explode("', '", $bracket[1]);
+ $param[0] = substr($param[0], 2);
+ $param[2] = substr($param[2], 0, strrpos($param[2], "')"));
+ $effect = $this->Text_effect_pass($param[0], $param[1], $param[2]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End Text_effect_pass
+
+ // Start moderator_pass
+ $regex = "/(\\$)(this->moderator_pass)(\().*?(\')(,).*?(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = "/(\\$)(this->moderator_pass)/";
+ $bracket = preg_split($bracket, $func);
+ $param = explode("', '", $bracket[1]);
+ $param[0] = substr($param[0], 2);
+ $param[1] = substr($param[1], 0, strrpos($param[1], "')"));
+
+ $effect = $this->moderator_pass($param[0], $param[1]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End moderator_pass
+
+ // Start table_pass
+ $regex = "/(\\$)(this->table_pass)(\().*?(\')(,).*?(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = "/(\\$)(this->table_pass)/";
+ $bracket = preg_split($bracket, $func);
+ $param = explode("', '", $bracket[1]);
+ $param[0] = substr($param[0], 2);
+ $param[1] = substr($param[1], 0, strrpos($param[1], "')"));
+
+ $effect = $this->table_pass($param[0], $param[1]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End table_pass
+
+ // Start BBvideo_pass
+ $regex = "/(\\$)(this->BBvideo_pass)(\().*?(\')(,)( )(\').*?(\')(,)( )(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = preg_split("/(\\$)(this->BBvideo_pass)/", $func);
+ $param = explode("', '", $bracket[1]);
+ $param[0] = substr($param[0], 2);
+ $param[2] = substr($param[2], 0, strrpos($param[2], "')"));
+ $effect = $this->BBvideo_pass($param[0], $param[1], $param[2]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End BBvideo_pass
+
+ // Start anchor_pass
+ $regex = "/(\\$)(this->anchor_pass)(\().*?(\')(,)( )(\').*?(\')(,)( )(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = preg_split("/(\\$)(this->anchor_pass)/", $func);
+ $param = explode("', '", $bracket[1]);
+ $param[0] = substr($param[0], 2);
+ $param[2] = substr($param[2], 0, strrpos($param[2], "')"));
+ $effect = $this->anchor_pass($param[0], $param[1], $param[2]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End anchor_pass
+
+ // Start ed2k_pass
+ $regex = "/(\\$)(t)(h)(i)(s)(-)(>)(e)(d)(2)(k)(_)(p)(a)(s)(s)(\()( ).*?(,)( )(\').*?(\')(,)( )(\').*?(\')( )(\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = preg_split("/(\\$)(this->ed2k_pass)/", $func);
+ $param = explode("', '", $bracket[1]);
+ $param[0] = explode(", 'ed2k:", $param[0]);
+ $param[0][0] = substr($param[0][0], 2);
+ $param[1] = substr($param[1], 0, strrpos($param[1], "' )"));
+ $effect = $this->ed2k_pass($param[0][0], "ed2k:" . $param[0][1], $param[1]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End ed2k_pass
+
+ // Start search_pass
+ $regex = "/(\\$)(this->search_pass)(\().*?(\')(,)( )(\').*?(\')(,)( )(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = preg_split("/(\\$)(this->search_pass)/", $func);
+ $param = explode("', '", $bracket[1]);
+ $param[0] = substr($param[0], 2);
+ $param[2] = substr($param[2], 0, strrpos($param[2], "')"));
+ $effect = $this->search_pass($param[0], $param[1], $param[2]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End search_pass
+ // Start thumb_pass
+ $regex = "/(\\$)(this->thumb_pass)(\().*?(\')(,).*?(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = "/(\\$)(this->thumb_pass)/";
+ $bracket = preg_split($bracket, $func);
+ $param = explode("', '", $bracket[1]);
+ $param[0] = substr($param[0], 2);
+ $param[1] = substr($param[1], 0, strrpos($param[1], "')"));
+
+ $effect = $this->thumb_pass($param[0], $param[1]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End thumb_pass
+
+ // Start img_pass
+ $regex = "/(\\$)(this->img_pass)(\().*?(\')(,).*?(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = "/(\\$)(this->img_pass)/";
+ $bracket = preg_split($bracket, $func);
+ $param = explode("', '", $bracket[1]);
+ $param[0] = substr($param[0], 2);
+ $param[1] = substr($param[1], 0, strrpos($param[1], "')"));
+
+ $effect = $this->img_pass($param[0], $param[1]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End img_pass
+
+ // Start offtopic_pass
+ $regex = "/(\\$)(this->offtopic_pass)(\(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = "/(\\$)(this->offtopic_pass)/";
+ $param = preg_split($bracket, $func);
+ $param[1] = substr($param[1], 2);
+ $param[1] = substr($param[1], 0, strrpos($param[1], "')"));
+
+ $effect = $this->offtopic_pass($param[1]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End offtopic_pass
+
+ // Start spoil_pass
+ $regex = "/(\\$)(this->spoil_pass)(\(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = "/(\\$)(this->spoil_pass)/";
+ $param = preg_split($bracket, $func);
+ $param[1] = substr($param[1], 2);
+ $param[1] = substr($param[1], 0, strrpos($param[1], "')"));
+
+ $effect = $this->spoil_pass($param[1]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End spoil_pass
+
+ // Start hidden_pass
+ $regex = "/(\\$)(this->hidden_pass)(\(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = "/(\\$)(this->hidden_pass)/";
+ $param = preg_split($bracket, $func);
+ $param[1] = substr($param[1], 2);
+ $param[1] = substr($param[1], 0, strrpos($param[1], "')"));
+
+ $effect = $this->hidden_pass($param[1]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End hidden_pass
+
+ // Start nfo_pass
+ $regex = "/(\\$)(this->nfo_pass)(\(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = "/(\\$)(this->nfo_pass)/";
+ $param = preg_split($bracket, $func);
+ $param[1] = substr($param[1], 2);
+ $param[1] = substr($param[1], 0, strrpos($param[1], "')"));
+
+ $effect = $this->nfo_pass($param[1]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End nfo_pass
+
+ // Start scrippets_pass
+ $regex = "/(\\$)(this->scrippets_pass)(\(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = "/(\\$)(this->scrippets_pass)/";
+ $param = preg_split($bracket, $func);
+ $param[1] = substr($param[1], 2);
+ $param[1] = substr($param[1], 0, strrpos($param[1], "')"));
+
+ $effect = $this->scrippets_pass($param[1]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End scrippets_pass
+
+ // Start testlink_pass
+ $regex = "/(\\$)(this->testlink_pass)(\(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = "/(\\$)(this->testlink_pass)/";
+ $param = preg_split($bracket, $func);
+ $param[1] = substr($param[1], 2);
+ $param[1] = substr($param[1], 0, strrpos($param[1], "')"));
+
+ $effect = $this->testlink_pass($param[1]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End testlink_pass
+
+ // Start rapidshare_pass
+ $regex = "/(\\$)(this->rapidshare_pass)(\(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = "/(\\$)(this->rapidshare_pass)/";
+ $param = preg_split($bracket, $func);
+ $param[1] = substr($param[1], 2);
+ $param[1] = substr($param[1], 0, strrpos($param[1], "')"));
+
+ $effect = $this->rapidshare_pass($param[1]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End rapidshare_pass
+
+ // Start click_pass
+ $regex = "/(\\$)(this->click_pass)(\().*?(\')(,).*?(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = "/(\\$)(this->click_pass)/";
+ $bracket = preg_split($bracket, $func);
+ $param = explode("', '", $bracket[1]);
+ $param[0] = substr($param[0], 2);
+ $param[1] = substr($param[1], 0, strrpos($param[1], "')"));
+
+ $effect = $this->click_pass($param[0], $param[1]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End click_pass
+
+ // Start simpleTabs_pass
+ $regex = "/(\\$)(this->simpleTabs_pass)(\(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = "/(\\$)(this->simpleTabs_pass)/";
+ $param = preg_split($bracket, $func);
+ $param[1] = substr($param[1], 2);
+ $param[1] = substr($param[1], 0, strrpos($param[1], "')"));
+
+ $effect = $this->simpleTabs_pass($param[1]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End simpleTabs_pass
+
+ // Start flash_pass
+ $regex = "/(\\$)(this->flash_pass)(\().*?(\')(,)( )(\').*?(\')(,)( )(\').*?(\'\))/is";
+
+ if (preg_match_all($regex, $message, $matches)) {
+ foreach ($matches[0] as $key => $func) {
+ $bracket = preg_split("/(\\$)(this->flash_pass)/", $func);
+ $param = explode("', '", $bracket[1]);
+ $param[0] = substr($param[0], 2);
+ $param[2] = substr($param[2], 0, strrpos($param[2], "')"));
+ $effect = $this->flash_pass($param[0], $param[1], $param[2]);
+ if ($key == 0) {
+ $init = $message;
+ } else {
+ $init = $mess;
+ }
+ $mess = str_replace($matches[0][$key], $effect, $init);
+ }
+ $message = $mess;
+ } // End flash_pass
+
+ // Add new preg_match_all() above
$preg = array('search' => array(), 'replace' => array());
}
$cb = sizeof($callback['search']);
@@ -293,8 +695,8 @@
'preg' => array(
// MOD : MSSTI ABBC3 - Start
- '#\[url:$uid\](ed2k://\|(file|server|serverlist|friend)(|\|[^\\/\|:<>\*\?\"]+?)\|(.*?)\|/?)\[/url:$uid\]#sie' => "\$this->ed2k_pass( \$bbcode_id, '\$1', '' )",
- '#\[url=(ed2k://\|(file|server|serverlist|friend)(|\|[^\\/\|:<>\*\?\"]+?)\|(.*?)\|/?):$uid\](.*?)\[/url:$uid\]#sie' => "\$this->ed2k_pass( \$bbcode_id, '\$1', '\$5' )",
+ '#\[url:$uid\](ed2k://\|(file|server|serverlist|friend)(|\|[^\\/\|:<>\*\?\"]+?)\|(.*?)\|/?)\[/url:$uid\]#si' => "\$this->ed2k_pass( \$bbcode_id, '\$1', '' )",
+ '#\[url=(ed2k://\|(file|server|serverlist|friend)(|\|[^\\/\|:<>\*\?\"]+?)\|(.*?)\|/?):$uid\](.*?)\[/url:$uid\]#si' => "\$this->ed2k_pass( \$bbcode_id, '\$1', '\$5' )",
// MOD : MSSTI ABBC3 - End
'#\[url:$uid\]((.*?))\[/url:$uid\]#s' => $this->bbcode_tpl('url', $bbcode_id),
'#\[url=([^\[]+?):$uid\](.*?)\[/url:$uid\]#s' => $this->bbcode_tpl('url', $bbcode_id),
@@ -449,7 +851,6 @@
$user->add_lang('mods/abbcode');
// MOD : MSSTI ABBC3 - End
$bbcode_tpl = preg_replace_callback('/{L_([A-Z0-9_]+)}/', function($matches){global $user; return (!empty($user->lang[$matches[1]])) ? $user->lang[$matches[1]] : ucwords(strtolower(str_replace('_', ' ', $matches[1])));}, $bbcode_tpl);
-
if (!empty($rowset[$bbcode_id]['second_pass_replace']))
{
// The custom BBCode requires second-pass pattern replacements
diff -ur orig/includes/message_parser.php phpBB3.14/includes/message_parser.php
--- orig/includes/message_parser.php 2019-12-06 21:24:25.200764082 -0300
+++ phpBB3.14/includes/message_parser.php 2019-12-06 18:13:52.637866237 -0300
@@ -73,7 +73,22 @@
{
// eval() sucks, but we must use preg_replace_callback() to support
// PHP 7.0, and custom BBcode replacement function is stored as a string
- $this->message = preg_replace_callback($regexp, function($matches) use($replacement) {eval('$str=' . $replacement[1]); return $str;}, $this->message);
+ $this->message = preg_replace_callback($regexp, function ($matches) use ($replacement) {
+
+ for ($i = 1; $i <= count($matches); $i++) {
+ if (isset($matches[$i])) {
+ $replacement[1] = preg_replace('/\$\{' . $i . '\}/',
+ str_replace(array("\r\n", "'", "\"", "(", ")", "$"),
+ array("\n", "&#39;", "&#34;", "&#40;", "&#41;", "&#36;"), trim($matches[$i])), $replacement[1]);
+ }
+ }
+ try
+ {
+ eval('$str=' . $replacement[1]);
+ } catch (ParseError $e) {
+ //echo 'Caught exception: '.$e->getMessage()."\n";
+ }
+ return $str;}, $this->message);
}
else
{
<?php
# Download and install PHBB 3.14 from here: https://download.phpbb.com/pub/release/3.0/3.0.14/phpBB-3.0.14.zip
# Appply Dion's patch available here: https://forum.dion-designs.com/viewtopic.php?f=27&t=9154
# Tipically you can apply the patch usint the steps bellow but Dion's readme file has more information.
## 1 - Copy email.diff and php7.diff to your forum root
## 2 - open the root of your forum on terminal and run
### 2a - patch -p1 -b --suffix=.bak -i email.diff --dry-run
### 2b - patch -p1 -b --suffix=.bak -i php7.diff --dry-run
### 2c - If everything looks good then remove --dry-run flag and run commands again
#### 2c.1 - If the patch can't find some piece of code you should look for .rej file and apply patches manually.
# 3 - Save abbc3_update_db.php and abbc3.diff in the root of your forum and run patch command according to instructions above.
## 3a - patch -p1 -b --suffix=.bak -i abbc3.diff --dry-run
#4 - The last step: Open abbc3_update_db.php in your browser and verify all changes.
# Basically the script will remove the e modifier from line end.
# If everything looks good click on update button.
global $connect;
$update = "false";
$info = "false";
$info2 = "false";
if (file_exists("config.php")) {
require "config.php";
$GLOBALS['dbname'] = $dbname;
$GLOBALS['dbuser'] = $dbuser;
$GLOBALS['pass'] = $dbpasswd;
$GLOBALS['host'] = $dbhost;
} else {
echo "config.php not found";
exit();
}
$search = select($table_prefix . "bbcodes", "bbcode_id, first_pass_match, second_pass_match", "WHERE 1");
if ($search == true) {
for ($i = 0; $i < count($search); $i++) {
$id[$i] = $search[$i]['bbcode_id'];
$first_pass_match[$i] = $search[$i]['first_pass_match'];
$first_pass_match[$i] = preg_replace('/\/ie/', '/i', $first_pass_match[$i]);
$first_pass_match[$i] = preg_replace('/!ies/', '!is', $first_pass_match[$i]);
$first_pass_match[$i] = preg_replace('/\/e/', '/', $first_pass_match[$i]);
$first_pass_match[$i] = preg_replace('/\/uise/', '/uis', $first_pass_match[$i]);
$first_pass_match[$i] = preg_replace('/#ise/', '#is', $first_pass_match[$i]);
$first_pass_match[$i] = preg_replace('/#ie/', '#i', $first_pass_match[$i]);
$first_pass_match[$i] = preg_replace('/!iues/', '!ius', $first_pass_match[$i]);
$first_pass_match[$i] = preg_replace('/!sie/', '!si', $first_pass_match[$i]);
$first_pass_match[$i] = preg_replace('/!ie/', '!i', $first_pass_match[$i]);
$second_pass_match[$i] = $search[$i]['second_pass_match'];
$second_pass_match[$i] = preg_replace('/\/ie/', '/i', $second_pass_match[$i]);
$second_pass_match[$i] = preg_replace('/!ies/', '!is', $second_pass_match[$i]);
$second_pass_match[$i] = preg_replace('/\/e/', '/', $second_pass_match[$i]);
$second_pass_match[$i] = preg_replace('/\/uise/', '/uis', $second_pass_match[$i]);
$second_pass_match[$i] = preg_replace('/#ise/', '#is', $second_pass_match[$i]);
$second_pass_match[$i] = preg_replace('/#ie/', '#i', $second_pass_match[$i]);
$second_pass_match[$i] = preg_replace('/!iues/', '!ius', $second_pass_match[$i]);
$second_pass_match[$i] = preg_replace('/!sie/', '!si', $second_pass_match[$i]);
$second_pass_match[$i] = preg_replace('/!ie/', '!i', $second_pass_match[$i]);
}
}
else{
echo "Not found";
}
if(!empty($_POST))
{
if (isset($_REQUEST['update']))
{
if ($_REQUEST['update'] == "true")
{
for ($i = 0; $i < count($search); $i++)
{
$first_pass_match[$i] = mysql_escape_mimic($first_pass_match[$i]);
$second_pass_match[$i] = mysql_escape_mimic($second_pass_match[$i]);
$result = update(array("first_pass_match", "second_pass_match"), array($first_pass_match[$i], $second_pass_match[$i]), $table_prefix . "bbcodes", "Where bbcode_id = '$id[$i]'");
if ($result == true)
{
$update = "true";
$search = select($table_prefix . "bbcodes", "bbcode_id, first_pass_match, second_pass_match", "WHERE 1");
if($search == false)
{
$info2 = "An error ocurred refreshing values!";
}
else
{
$info = "Values successfully updated!";
}
}
else
{
$update = "false";
$info = "An error ocurred while updating values!";
}
}
}
else
{
$info = "Invalid option!";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
if($update == "true")
{
echo
"<div class=\"alert success\">
<span class=\"closebtn\">&times;</span>
<strong>Success! </strong>".$info.
"</div>";
}
if(($info != "false") && ($update != "true"))
{
echo
"<div class=\"alert\">
<span class=\"closebtn\">&times;</span>
<strong>Error! </strong>".$info.
"</div>";
}
if(($info2 != "false") && ($update == "true"))
{
echo
"<div class=\"alert warning\">
<span class=\"closebtn\">&times;</span>
<strong>Error! </strong>".$info2.
"</div>";
}
?>
<table id="FirstPassMatch">
<?php
if($update == "false")
{
echo
"<tr>
<th colspan=\"3\" style=\"text-align: center\">First Pass Match</th>
</tr>
<tr>
<td style=\"text-align: center\">ID</td>
<td style=\"text-align: center\">Current value</td>
<td style=\"text-align: center\">New value</td>
</tr>";
}
else
{
echo
"<tr>
<th colspan=\"3\" style=\"text-align: center\">First Pass Match</th>
</tr>
<tr>
<td style=\"text-align: left\">ID</td>
<td style=\"text-align: left\">Current value</td>
</tr>";
}
for ($i = 0; $i < count($search); $i++)
{
if($update == "false")
{
if($search[$i]['first_pass_match'] != ".")
{
echo
"<tr>
<td>" . $id[$i] ."</td>
<td>" . $search[$i]['first_pass_match'] ."</td>
<td>" . $first_pass_match[$i] ."</td>
</tr>";
}
}
else
{
if($search[$i]['first_pass_match'] != ".")
{
echo
"<tr>
<td>" . $id[$i] ."</td>
<td>" . $search[$i]['first_pass_match'] ."</td>
</tr>";
}
}
}
?>
</table>
<table id="SecondPassMatch">
<?php
if($update == "false")
{
echo
"<tr>
<th colspan=\"3\" style=\"text-align: center\">Second Pass Match</th>
</tr>
<tr>
<td style=\"text-align: center\">ID</td>
<td style=\"text-align: center\">Current value</td>
<td style=\"text-align: center\">New value</td>
</tr>";
}
else
{
echo
"<tr>
<th colspan=\"3\" style=\"text-align: center\">Second Pass Match</th>
</tr>
<tr>
<td style=\"text-align: left\">ID</td>
<td style=\"text-align: left\">Current value</td>
</tr>";
}
echo "<br><br><br><br>";
for ($i = 0; $i < count($search); $i++)
{
if($update == "false")
{
if($search[$i]['second_pass_match'] != ".")
{
echo
"<tr>
<td>" . $id[$i] ."</td>
<td>" . $search[$i]['second_pass_match'] ."</td>
<td>" . $second_pass_match[$i] ."</td>
</tr>";
}
}
else
{
if($search[$i]['second_pass_match'] != ".")
{
echo
"<tr>
<td>" . $id[$i] ."</td>
<td>" . $search[$i]['second_pass_match'] ."</td>
</tr>";
}
}
}
?>
</table>
<br>
<br>
<h2>If everything looks good click here!</h2>
<div class="wrapper">
<?php
if($update == "true")
{
?>
<button class="button" onClick="window.location.href=window.location.href">Refresh Page</button>
<?php
}
else
{
?>
<form action="abbc3_update_db.php" method="post">
<button class="button">Update database!</button>
<input type="hidden" name="update" value="true">
</form>
<?php
}
?>
</div>
<br>
<br>
<br>
<br>
<script>
var close = document.getElementsByClassName("closebtn");
var i;
for (i = 0; i < close.length; i++) {
close[i].onclick = function () {
var div = this.parentElement;
div.style.opacity = "0";
setTimeout(function () {
div.style.display = "none";
}, 600);
}
}
</script>
<style>
h2 {
text-align: center;
}
.alert {
padding: 20px;
background-color: #f44336;
color: white;
opacity: 1;
transition: opacity 0.6s;
margin-bottom: 15px;
text-align: center;
}
.alert.success {
background-color: #4CAF50;
}
.alert.info {
background-color: #2196F3;
}
.alert.warning {
background-color: #ff9800;
}
.closebtn {
margin-left: 15px;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
}
.closebtn:hover {
color: black;
}
#FirstPassMatch {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#FirstPassMatch td,
#FirstPassMatch th {
border: 1px solid #ddd;
padding: 8px;
}
#FirstPassMatch tr:nth-child(even) {
background-color: #f2f2f2;
}
#FirstPassMatch tr:hover {
background-color: #ddd;
}
#FirstPassMatch th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #46A5F2;
color: white;
}
#SecondPassMatch {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#SecondPassMatch td,
#SecondPassMatch th {
border: 1px solid #ddd;
padding: 8px;
}
#SecondPassMatch tr:nth-child(even) {
background-color: #f2f2f2;
}
#SecondPassMatch tr:hover {
background-color: #ddd;
}
#SecondPassMatch th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #FF7F1F;
color: white;
}
.wrapper {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
</body>
</html>
<?php
function connect()
{
global $connect;
$dbname = $GLOBALS['dbname'];
$dbuser = $GLOBALS['dbuser'];
$dbpasswd = $GLOBALS['pass'];
$dbhost = $GLOBALS['host'];
$connect = mysqli_connect($dbhost, $dbuser, $dbpasswd);
if (!$connect) {
die(trigger_error("Can't connect"));
return false;
} else {
$db = mysqli_select_db($connect, $dbname);
if (!$db) {
die(trigger_error("Can't select the database"));
return false;
} else {
return $connect;
}
}
}
function close($connect)
{
$dbclose = mysqli_close($connect);
if (!$dbclose) {
echo "Can't close the connection!";
return false;
} else {
return true;
}
}
function select($table, $column = "*", $where = null, $order = null, $limit = null)
{
$sql = "SELECT {$column} FROM {$table} {$where} {$order} {$limit}";
if ($connection = connect()) {
if ($query = mysqli_query($connection, $sql)) {
if (mysqli_num_rows($query) > 0) {
$resultados_totais = array();
while ($resultado = mysqli_fetch_assoc($query)) {
$resultados_totais[] = $resultado;
}
close($connection);
return $resultados_totais;
} else {
return false;
}
} else {
return false;
}
}
}
function update($column, $value, $table, $where)
{
if ((is_array($column)) and (is_array($value))) {
if (count($column) == count($value)) {
$value_column = null;
for ($i = 0; $i < count($column); $i++) {
$value_column .= "{$column[$i]} = '{$value[$i]}',";
}
$value_column = substr($value_column, 0, -1);
$update = "UPDATE {$table} SET {$value_column} {$where}";
} else {
return false;
}
} else {
$update = "UPDATE {$table} SET {$column} = '{$value}' {$where}";
}
if ($connection = connect()) {
$status = mysqli_query($connection, $update) or die(mysqli_error($connect));
if (mysqli_query($connection, $update)) {
close($connection);
return true;
} else {
echo "Invalid query!<br>";
return false;
}
} else {
return false;
}
}
function mysql_escape_mimic($inp)
{
if (is_array($inp)) {
return array_map(__METHOD__, $inp);
}
if (!empty($inp) && is_string($inp)) {
return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $inp);
}
return $inp;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment