Browse Source

php compatibility tweaks for mysql

Andrew Dolgov 7 years ago
parent
commit
51ba070346
2 changed files with 13 additions and 7 deletions
  1. 8 2
      functions.php
  2. 5 5
      snippet.php

+ 8 - 2
functions.php

@@ -15,6 +15,12 @@
 
 	define('SINGLE_USER_MODE', false);
 
+	if (DB_TYPE == 'mysql') {
+		define('DB_KEY_FIELD', 'param');
+	} else {
+		define('DB_KEY_FIELD', 'key');
+	}
+
 	$url_regex = "((((new|(ht|f)tp)s?://)?([a-zA-Z+0-9_-]+:[a-zA-Z+0-9_-]+\\@)?((www|ftp|[a-zA-Z+0-9]+(-\\+[a-zA-Z+0-9])*)\\.)?)([a-zA-Z+0-9]+(\\-+[a-zA-Z+0-9]+)*\\.)+[a-zA-Z+]{2,7}(:\\d+)?(/~[a-zA-Z+0-9_%\\-]+)?(/[a-zA-Z+0-9_%.-]+(?=/))*(/[a-zA-Z+0-9_%-]+(\\.[a-zA-Z+0-9]+)?(\\#[a-zA-Z+0-9_.]+)?)*(\\?([a-zA-Z+0-9_.%-]+)=[a-zA-Z+0-9_.%/-]*)?(&([a-zA-Z+0-9_.%-]+)=[a-zA-Z+0-9_.%/-]*)*/?)";
 
 
@@ -740,7 +746,7 @@
 		}
 
 		$result = db_query($link, "SELECT value FROM ttirc_system WHERE
-			key = 'MASTER_RUNNING'");
+			".DB_KEY_FIELD." = 'MASTER_RUNNING'");
 
 		$master_running = db_fetch_result($result, 0, "value") == "true";
 
@@ -975,7 +981,7 @@
 
 		$key = db_escape_string(sha1(uniqid(rand(), true)));
 
-		$result = db_query($link, "INSERT INTO ttirc_snippets (snippet, owner_uid, created, key)
+		$result = db_query($link, "INSERT INTO ttirc_snippets (snippet, owner_uid, created, ".DB_KEY_FIELD.")
 			VALUES ('$text', '".$_SESSION['uid']."', NOW(), '$key')");
 
 		return $key;

+ 5 - 5
snippet.php

@@ -3,7 +3,7 @@
 
 	if (get_magic_quotes_gpc()) {
 		function stripslashes_deep($value) {
-			$value = is_array($value) ? 
+			$value = is_array($value) ?
 				array_map('stripslashes_deep', $value) : stripslashes($value);
 				return $value;
 		}
@@ -14,20 +14,20 @@
 		$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
 	}
 
-	require_once "functions.php"; 
+	require_once "functions.php";
 	require_once "sessions.php";
 	require_once "db-prefs.php";
 	require_once "sanity_check.php";
-	require_once "version.php"; 
+	require_once "version.php";
 	require_once "config.php";
 	require_once "prefs.php";
 	require_once "users.php";
 
-	$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);	
+	$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
 
 	$key = db_escape_string($_REQUEST['key']);
 
-	$result = db_query($link, "SELECT snippet FROM ttirc_snippets WHERE key = '$key'");
+	$result = db_query($link, "SELECT snippet FROM ttirc_snippets WHERE ".DB_KEY_FIELD." = '$key'");
 
 	header("Content-Type: text/plain; charset=utf-8");