Functions imported, some dev-scripts added
authorRoland Häder <roland@mxchange.org>
Mon, 23 Feb 2009 22:15:43 +0000 (22:15 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 23 Feb 2009 22:15:43 +0000 (22:15 +0000)
14 files changed:
inc/db/lib-mysql3.php
inc/extensions.php
inc/functions.php
inc/header.php
inc/libs/wernis_functions.php
inc/libs/yoomedia_functions.php
inc/loader/load_cache-config.php
inc/modules/admin/admin-inc.php
inc/modules/admin/overview-inc.php
inc/modules/admin/what-list_payouts.php
inc/modules/admin/what-list_unconfirmed.php
inc/modules/admin/what-usage.php
inc/modules/frametester.php
inc/modules/loader.php

index b1850f4efa553eb7983d1ed102eefd3cd7a813ed..f90a8f6f9ab8b009b1f8a885b86822a416349cb5 100644 (file)
@@ -47,12 +47,12 @@ function SQL_QUERY ($sql_string, $F, $L) {
        // Remove \t, \n and \r from queries they may confuse some MySQL version I have heard
        $sql_string = str_replace("\t", " ", str_replace("\n", " ", str_replace("\r", " ", $sql_string)));
 
-       // Starting time
-       $querytimeBefore = array_sum(explode(' ', microtime()));
-
        // Replace {!_MYSQL_PREFIX!} with constant, closes #84. Thanks to profi-concept
        $sql_string = str_replace("{!_MYSQL_PREFIX!}", constant('_MYSQL_PREFIX'), $sql_string);
 
+       // Starting time
+       $querytimeBefore = array_sum(explode(' ', microtime()));
+
        // Run SQL command
        //* DEBUG: */ echo $sql_string."<br />\n";
        $result = mysql_query($sql_string, $link)
@@ -164,8 +164,8 @@ function SQL_FETCHARRAY($res, $nr=0, $remove_numerical=true) {
                        for ($idx = 0; $idx < ($max / 2); $idx++) {
                                // Remove entry
                                unset($row[$idx]);
-                       }
-               }
+                       } // END - for
+               } // END - if
 
                // Return row
                return $row;
@@ -180,11 +180,13 @@ function SQL_RESULT ($res, $row, $field) {
        $result = mysql_result($res, $row, $field);
        return $result;
 }
+
 // SQL connect
 function SQL_CONNECT ($host, $login, $password, $F, $L) {
        $connect = mysql_connect($host, $login, $password) or addFatalMessage($F." (".$L."):".mysql_error());
        return $connect;
 }
+
 // SQL select database
 function SQL_SELECT_DB ($dbName, $link, $F, $L) {
        // Is there still a valid link? If not, skip it.
@@ -192,6 +194,7 @@ function SQL_SELECT_DB ($dbName, $link, $F, $L) {
 
        return mysql_select_db($dbName, $link) or addFatalMessage($F." (".$L."):".mysql_error());
 }
+
 // SQL close link
 function SQL_CLOSE (&$link, $F, $L) {
        global $cacheInstance, $cacheArray;
@@ -251,7 +254,7 @@ function SQL_QUERY_ESC ($qstring, $data, $file, $line, $run=true, $strip=true) {
                } else {
                        $eval .= ", ''";
                }
-       }
+       } // END - foreach
        $eval .= ");";
        //
        // Debugging
@@ -266,16 +269,10 @@ function SQL_QUERY_ESC ($qstring, $data, $file, $line, $run=true, $strip=true) {
        // Was the eval() command fine?
        if ($query == "failed") {
                // Something went wrong?
-               printf("eval=%s\n<pre>%s</pre>",
-                       htmlentities($eval),
-                       debug_get_printable_backtrace()
-               );
-
-               // Abort further code executions
-               exit;
+               debug_report_bug("eval={$eval}");
        } // END - if
 
-       if ($run) {
+       if ($run === true) {
                // Run SQL query (default)
                return SQL_QUERY($query, $file, $line);
        } else {
@@ -302,11 +299,9 @@ function SQL_ESCAPE ($str, $secureString=true,$strip=true) {
        } // END - if
 
        if (!is_resource($link)) {
-               // Fall-back to addslashes() when there is no link
-               return addslashes($str);
-       } // END - if
-
-       if (function_exists('mysql_real_escape_string')) {
+               // Fall-back to smartAddSlashes() when there is no link
+               return smartAddSlashes($str);
+       } elseif (function_exists('mysql_real_escape_string')) {
                // The new and improved version
                //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):str={$str}<br />\n";
                return mysql_real_escape_string($str, $link);
@@ -314,8 +309,8 @@ function SQL_ESCAPE ($str, $secureString=true,$strip=true) {
                // The obsolete function
                return mysql_escape_string($str, $link);
        } else {
-               // If nothing else works
-               return addslashes($str);
+               // If nothing else works, fall back to smartAddSlashes()
+               return smartAddSlashes($str);
        }
 }
 
@@ -345,7 +340,8 @@ function SQL_ALTER_TABLE ($sql, $F, $L) {
        $result = false;
 
        // Determine index/fulltext/unique word
-       $noIndex = ((eregi("INDEX", $sql) == false) && (eregi("FULLTEXT", $sql) == false) && (eregi("UNIQUE", $sql) == false);
+       //         12     3             3         2    2     3                3         2    2     3              3         21
+       $noIndex = ((eregi("INDEX", $sql) == false) && (eregi("FULLTEXT", $sql) == false) && (eregi("UNIQUE", $sql) == false));
 
        // Shall we add/drop?
        if (((eregi("ADD", $sql) > 0) || (eregi("DROP", $sql) > 0)) && ($noIndex)) {
@@ -374,5 +370,6 @@ function SQL_ALTER_TABLE ($sql, $F, $L) {
        // Return result
        return $result;
 }
+
 //
 ?>
index 8de47c2d42fa26998f81b12791aae6cd454a62b5..608cb3234fa92c51de596fb65019fec9637a045e 100644 (file)
@@ -479,7 +479,7 @@ function EXTENSION_UPDATE ($ext_name, $ext_ver, $dry_run = false) {
 
                if (!$dry_run) {
                        // Create task
-                       CREATE_EXTENSION_UPDATE_TASK(GET_CURRENT_ADMIN_ID(), $ext_name, $cacheArray['update_ver'][$ext_name], addslashes($NOTES));
+                       CREATE_EXTENSION_UPDATE_TASK(GET_CURRENT_ADMIN_ID(), $ext_name, $cacheArray['update_ver'][$ext_name], SQL_ESCAPE($NOTES));
 
                        // Update extension's version
                        SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_version='%s' WHERE ext_name='%s' LIMIT 1",
@@ -700,7 +700,7 @@ VALUES (%s,0,'NEW','EXTENSION','%s','%s',UNIX_TIMESTAMP())",
                        array(
                                $admin_id,
                                $subject,
-                               addslashes($msg),
+                               SQL_ESCAPE($msg),
                        ),  __FILE__, __LINE__, true, false
                );
        } // END - if
@@ -718,7 +718,7 @@ function CREATE_EXTENSION_DEACTIVATION_TASK ($ext) {
 VALUES (0,0,'NEW','EXTENSION_DEACTIVATION','%s','%s',UNIX_TIMESTAMP())",
                        array(
                                $subject,
-                               addslashes(LOAD_TEMPLATE("task_ext_deactivated", true, $ext)),
+                               SQL_ESCAPE(LOAD_TEMPLATE("task_ext_deactivated", true, $ext)),
                        ),  __FILE__, __LINE__, true, false
                );
        } // END - if
index c5db673515ab429308bea018173048a8f4c41958..ef6cbde5323b40bf5ff838a7513d39983f08896d 100644 (file)
@@ -139,7 +139,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
                while (strpos($OUTPUT, '{!') > 0) {
                        // Prepare the content and eval() it...
                        $newContent = "";
-                       $eval = "\$newContent = \"".COMPILE_CODE(addslashes($OUTPUT))."\";";
+                       $eval = "\$newContent = \"".COMPILE_CODE(SQL_ESCAPE($OUTPUT))."\";";
                        @eval($eval);
 
                        // Was that eval okay?
@@ -160,7 +160,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
 
                // Compile and run finished rendered HTML code
                while (strpos($OUTPUT, '{!') > 0) {
-                       $eval = "\$OUTPUT = \"".COMPILE_CODE(addslashes($OUTPUT))."\";";
+                       $eval = "\$OUTPUT = \"".COMPILE_CODE(SQL_ESCAPE($OUTPUT))."\";";
                        eval($eval);
                } // END - while
 
@@ -251,7 +251,9 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
                        // Translate gender
                        $content['gender'] = TRANSLATE_GENDER($content['gender']);
                } else {
-                       // DEPRECATED: Load data in direct variables
+                       // @DEPRECATED
+                       // @TODO Fine all templates which are using these direct variables and rewrite them.
+                       // @TODO After this step is done, this else-block is history
                        list($gender, $surname, $family, $email) = SQL_FETCHROW($result);
 
                        // Translate gender
@@ -337,7 +339,7 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
                $ret = "";
                if ((strpos($tmpl_file, "\$") !== false) || (strpos($tmpl_file, '{--') !== false) || (strpos($tmpl_file, '--}') > 0)) {
                        // Okay, compile it!
-                       $tmpl_file = "\$ret=\"".COMPILE_CODE(addslashes($tmpl_file))."\";";
+                       $tmpl_file = "\$ret=\"".COMPILE_CODE(SQL_ESCAPE($tmpl_file))."\";";
                        eval($tmpl_file);
                } else {
                        // Simply return loaded code
@@ -383,7 +385,7 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML = "N", $FROM = "") {
        //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):TO={$TO},SUBJECT={$SUBJECT}<br />\n";
 
        // Compile subject line (for POINTS constant etc.)
-       $eval = "\$SUBJECT = html_entity_decode(\"".COMPILE_CODE(addslashes($SUBJECT))."\");";
+       $eval = "\$SUBJECT = decodeEntities(\"".COMPILE_CODE(SQL_ESCAPE($SUBJECT))."\");";
        eval($eval);
 
        // Set from header
@@ -436,11 +438,11 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML = "N", $FROM = "") {
        }
 
        // Compile "TO"
-       $eval = "\$TO = \"".COMPILE_CODE(addslashes($TO))."\";";
+       $eval = "\$TO = \"".COMPILE_CODE(SQL_ESCAPE($TO))."\";";
        eval($eval);
 
        // Compile "MSG"
-       $eval = "\$MSG = \"".COMPILE_CODE(addslashes($MSG))."\";";
+       $eval = "\$MSG = \"".COMPILE_CODE(SQL_ESCAPE($MSG))."\";";
        eval($eval);
 
        // Fix HTML parameter (default is no!)
@@ -504,7 +506,7 @@ function SEND_RAW_EMAIL ($to, $subject, $msg, $from) {
                        $mail->WordWrap   = 70;
                        $mail->IsHTML(true);
                } else {
-                       $mail->Body       = html_entity_decode($msg);
+                       $mail->Body       = decodeEntities($msg);
                }
                $mail->AddAddress($to, "");
                $mail->AddReplyTo(constant('WEBMASTER'), constant('MAIN_TITLE'));
@@ -513,7 +515,7 @@ function SEND_RAW_EMAIL ($to, $subject, $msg, $from) {
                $mail->Send();
        } else {
                // Use legacy mail() command
-               @mail($to, $subject, html_entity_decode($msg), $from);
+               @mail($to, $subject, decodeEntities($msg), $from);
        }
 }
 //
@@ -624,35 +626,45 @@ function DEREFERER ($URL) {
        // Don't de-refer our own links!
        if (substr($URL, 0, strlen(URL)) != URL) {
                // De-refer this link
-               $URL = "modules.php?module=loader&amp;url=".urlencode(base64_encode(gzcompress($URL)));
+               $URL = "modules.php?module=loader&amp;url=".encodeString(compileUriCode($URL));
        } // END - if
 
        // Return link
        return $URL;
 }
 
-//
+// Translate Uni*-like gender to human-readable
 function TRANSLATE_GENDER ($gender) {
-       switch ($gender)
-       {
-               case "M": $ret = GENDER_M; break;
-               case "F": $ret = GENDER_F; break;
-               case "C": $ret = GENDER_C; break;
-               default : $ret = $gender; break;
+       // Default
+       $ret = "!{$gender}!";
+
+       // Male/female or company?
+       switch ($gender) {
+               case "M": $ret = getMessage('GENDER_M'); break;
+               case "F": $ret = getMessage('GENDER_F'); break;
+               case "C": $ret = getMessage('GENDER_C'); break;
+               default:
+                       // Log unknown gender
+                       DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown gender %s detected.", $gender));
+                       break;
        }
+
+       // Return translated gender
        return $ret;
 }
+
 //
-function FRAMETESTER($URL) {
+function FRAMETESTER ($URL) {
        // Prepare frametester URL
        $frametesterUrl = sprintf("%s/modules.php?module=frametester&amp;url=%s",
                URL,
-               urlencode(base64_encode(gzcompress(COMPILE_CODE($URL))))
+               encodeString(compileUriCode($URL))
        );
        return $frametesterUrl;
 }
+
 //
-function SELECTION_COUNT($array) {
+function SELECTION_COUNT ($array) {
        $ret = 0;
        if (is_array($array)) {
                foreach ($array as $key => $sel) {
@@ -666,31 +678,27 @@ function IMG_CODE ($code, $type, $DATA, $uid) {
        return "<IMG border=\"0\" alt=\"Code\" src=\"{!URL!}/mailid_top.php?uid=".$uid."&amp;".$type."=".$DATA."&amp;mode=img&amp;code=".$code."\">";
 }
 //
-function TRANSLATE_STATUS($status) {
+function TRANSLATE_STATUS ($status) {
        switch ($status)
        {
        case "UNCONFIRMED":
-               $ret = ACCOUNT_UNCONFIRMED;
-               break;
-
        case "CONFIRMED":
-               $ret = ACCOUNT_CONFIRMED;
-               break;
-
        case "LOCKED":
-               $ret = ACCOUNT_LOCKED;
+               $ret = getMessage(sprintf("ACCOUNT_%s", $status));
                break;
 
        case "":
        case null:
-               $ret = ACCOUNT_DELETED;
+               $ret = getMessage('ACCOUNT_DELETED');
                break;
 
        default:
                DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown status %s detected.", $status));
-               $ret = UNKNOWN_STATUS_1.$status.UNKNOWN_STATUS_2;
+               $ret = sprintf(getMessage('UNKNOWN_STATUS"'), $status);
                break;
        }
+
+       // Return it
        return $ret;
 }
 //
@@ -770,7 +778,7 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
        // Expiration in a nice output format
        if (getConfig('auto_purge') == 0) {
                // Will never expire!
-               $EXPIRATION = MAIL_WILL_NEVER_EXPIRE;
+               $EXPIRATION = getMessage('MAIL_WILL_NEVER_EXPIRE');
        } else {
                // Create nice date string
                $EXPIRATION = CREATE_FANCY_TIME(getConfig('auto_purge'));
@@ -852,10 +860,10 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
        if (FILE_READABLE($file)) {
                // The local file does exists so we load it. :)
                $tmpl_file = READ_FILE($file);
-               $tmpl_file = addslashes($tmpl_file);
+               $tmpl_file = SQL_ESCAPE($tmpl_file);
 
                // Run code
-               $tmpl_file = "\$newContent = html_entity_decode(\"".COMPILE_CODE($tmpl_file)."\");";
+               $tmpl_file = "\$newContent = decodeEntities(\"".COMPILE_CODE($tmpl_file)."\");";
                @eval($tmpl_file);
        } elseif (!empty($template)) {
                // Template file not found!
@@ -903,7 +911,7 @@ function LOAD_URL($URL, $addUrlData=true) {
        global $CSS, $footer;
 
        // Compile out URI codes
-       $URL = COMPILE_CODE($URL);
+       $URL = compileUriCode($URL);
 
        // Check if http(s):// is there
        if ((substr($URL, 0, 7) != "http://") && (substr($URL, 0, 8) != "https://")) {
@@ -1210,19 +1218,25 @@ function ADD_SELECTION($type, $DEFAULT, $prefix="", $id="0") {
 //
 function TRANSLATE_YESNO($yn)
 {
-       switch ($yn)
-       {
-               case "Y": $yn = YES; break;
-               case "N": $yn = NO; break;
-               default : $yn = "??? (".$yn.")"; break;
+       // Default
+       $yn = "??? (".$yn.")";
+       switch ($yn) {
+               case "Y": $yn = getMessage('YES'); break;
+               case "N": $yn = getMessage('NO'); break;
+               default:
+                       // Log unknown value
+                       DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown value %s. Expected Y/N!", $yn));
+                       break;
        }
+
+       // Return it
        return $yn;
 }
 //
 // Deprecated : $length
 // Optional   : $DATA
 //
-function GEN_RANDOM_CODE($length, $code, $uid, $DATA="") {
+function GEN_RANDOM_CODE ($length, $code, $uid, $DATA="") {
        // Fix missing _MAX constant
        if (!defined('_MAX')) define('_MAX', 15235);
 
@@ -1230,7 +1244,7 @@ function GEN_RANDOM_CODE($length, $code, $uid, $DATA="") {
        $server = $_SERVER['PHP_SELF'].":".GET_USER_AGENT().":".getenv('SERVER_SOFTWARE').":".GET_REMOTE_ADDR().":".":".filemtime(constant('PATH')."inc/databases.php");
 
        // Build key string
-       $keys   = SITE_KEY.":".DATE_KEY;
+       $keys   = constant('SITE_KEY').":".constant('DATE_KEY');
        if (getConfig('secret_key') != null)  $keys .= ":".getConfig('secret_key');
        if (getConfig('file_hash') != null)   $keys .= ":".getConfig('file_hash');
        $keys .= ":".date("d-m-Y (l-F-T)", bigintval(getConfig('patch_ctime')));
@@ -1254,13 +1268,13 @@ function GEN_RANDOM_CODE($length, $code, $uid, $DATA="") {
                $saltedHash = generateHash(($a % constant('_PRIME')).":".$server.":".$keys.":".$data.":".date("d-m-Y (l-F-T)", time()).":".$a, getConfig('master_salt'));
 
                // Create number from hash
-               $rcode = hexdec(substr($saltedHash, strlen(getConfig('master_salt')), 9)) / abs(_MAX - $a + sqrt(_ADD)) / pi();
+               $rcode = hexdec(substr($saltedHash, strlen(getConfig('master_salt')), 9)) / abs(constant('_MAX') - $a + sqrt(constant('_ADD'))) / pi();
        } else {
                // Generate hash with "hash of site key" from modula of number with the prime number and other data
                $saltedHash = generateHash(($a % constant('_PRIME')).":".$server.":".$keys.":".$data.":".date("d-m-Y (l-F-T)", time()).":".$a, substr(sha1(SITE_KEY), 0, 8));
 
                // Create number from hash
-               $rcode = hexdec(substr($saltedHash, 8, 9)) / abs(_MAX - $a + sqrt(_ADD)) / pi();
+               $rcode = hexdec(substr($saltedHash, 8, 9)) / abs(constant('_MAX') - $a + sqrt(constant('_ADD'))) / pi();
        }
 
        // At least 10 numbers shall be secure enought!
@@ -1274,6 +1288,7 @@ function GEN_RANDOM_CODE($length, $code, $uid, $DATA="") {
        // Done building code
        return $return;
 }
+
 // Does only allow numbers
 function bigintval($num, $castValue = true) {
        // Filter all numbers out
@@ -1286,20 +1301,21 @@ function bigintval($num, $castValue = true) {
        // @TODO Remove this if() block if all is working fine
        if ("".$ret."" != "".$num."") {
                // Log the values
-               debug_report_bug();
+               debug_report_bug("{$ret}<>{$num}");
        } // END - if
 
        // Return result
        return $ret;
 }
+
 // Insert the code in $img_code into jpeg or PNG image
-function GENERATE_IMAGE($img_code, $header=true) {
+function GENERATE_IMAGE ($img_code, $header=true) {
        if ((strlen($img_code) > 6) || (empty($img_code)) || (getConfig('code_length') == 0)) {
                // Stop execution of function here because of over-sized code length
                return;
        } elseif (!$header) {
                // Return in an HTML code code
-               return "<IMG src=\"{!URL!}/img.php?code=".$img_code."\">\n";
+               return "<img src=\"{!URL!}/img.php?code=".$img_code."\" alt=\"Image\" />\n";
        }
 
        // Load image
@@ -1320,6 +1336,7 @@ function GENERATE_IMAGE($img_code, $header=true) {
                }
        } else {
                // Exit function here
+               DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("File for image type %s not found.", getConfig('img_type')));
                return;
        }
 
@@ -1635,7 +1652,7 @@ function CREATE_FANCY_TIME ($stamp) {
        foreach($data as $k => $v) {
                if ($v > 0) {
                        // Value is greater than 0 "eval" data to return string
-                       $eval = "\$ret .= \", \".\$v.\" \"._".strtoupper($k).";";
+                       $eval = "\$ret .= \", \".\$v.\" {--_".strtoupper($k)."--}\";";
                        eval($eval);
                        break;
                } // END - if
@@ -1647,7 +1664,7 @@ function CREATE_FANCY_TIME ($stamp) {
                $ret = substr($ret, 2);
        } else {
                // Zero seconds
-               $ret = "0 "._SECONDS;
+               $ret = "0 {--_SECONDS--}";
        }
 
        // Return fancy time string
@@ -1713,7 +1730,7 @@ function ADD_EMAIL_NAV($PAGES, $offset, $show_form, $colspan, $return=false) {
 // Extract host from script name
 function EXTRACT_HOST (&$script) {
        // Use default SERVER_URL by default... ;) So?
-       $url = SERVER_URL;
+       $url = constant('SERVER_URL');
 
        // Is this URL valid?
        if (substr($script, 0, 7) == "http://") {
@@ -1756,8 +1773,8 @@ function GET_URL ($script) {
        // Generate GET request header
        $request  = "GET /" . trim($script) . " HTTP/1.1\r\n";
        $request .= "Host: " . $host . "\r\n";
-       $request .= "Referer: " . URL . "/admin.php\r\n";
-       $request .= "User-Agent: " . TITLE . "/" . FULL_VERSION . "\r\n";
+       $request .= "Referer: " . constant('URL') . "/admin.php\r\n";
+       $request .= "User-Agent: " . constant('TITLE') . "/" . constant('FULL_VERSION') . "\r\n";
        $request .= "Content-Type: text/plain\r\n";
        $request .= "Cache-Control: no-cache\r\n";
        $request .= "Connection: Close\r\n\r\n";
@@ -1790,8 +1807,8 @@ function POST_URL ($script, $postData) {
        // Generate POST request header
        $request  = "POST /" . trim($script) . " HTTP/1.1\r\n";
        $request .= "Host: " . $host . "\r\n";
-       $request .= "Referer: " . URL . "/admin.php\r\n";
-       $request .= "User-Agent: " . TITLE . "/" . FULL_VERSION . "\r\n";
+       $request .= "Referer: " . constant('URL') . "/admin.php\r\n";
+       $request .= "User-Agent: " . constant('TITLE') . "/" . constant('FULL_VERSION') . "\r\n";
        $request .= "Content-type: application/x-www-form-urlencoded\r\n";
        $request .= "Content-length: " . strlen($data) . "\r\n";
        $request .= "Cache-Control: no-cache\r\n";
@@ -1930,6 +1947,7 @@ function VALIDATE_EMAIL($email) {
        // Return check result
        return eregi($regex, $email);
 }
+
 // Function taken from user comments on www.php.net / function eregi()
 function VALIDATE_URL ($URL, $compile=true) {
        // Trim URL a little
@@ -1937,7 +1955,7 @@ function VALIDATE_URL ($URL, $compile=true) {
        //* DEBUG: */ echo $URL."<br />";
 
        // Compile some chars out...
-       if ($compile) $URL = COMPILE_CODE($URL, false, false, false);
+       if ($compile) $URL = compileUriCode($URL, false, false, false);
        //* DEBUG: */ echo $URL."<br />";
 
        // Check for the extension filter
@@ -1948,8 +1966,9 @@ function VALIDATE_URL ($URL, $compile=true) {
 
        // If not installed, perform a simple test. Just make it sure there is always a http:// or
        // https:// in front of the URLs
-       return (((substr($URL, 0, 7) == "http://") || (substr($URL, 0, 8) == "https://")) && (strlen($URL) >= 12));
+       return isUrlValid($URL);
 }
+
 //
 function MEMBER_ACTION_LINKS ($uid, $status = "") {
        // Define all main targets
@@ -1986,11 +2005,14 @@ function MEMBER_ACTION_LINKS ($uid, $status = "") {
        // Return string
        return $OUT;
 }
+
 // Function for backward-compatiblity
-function ADD_CATEGORY_table ($MODE, $return=false) {
+// @TODO Can this function be deprecated?
+function ADD_CATEGORY_TABLE ($MODE, $return=false) {
        // Load it from the register extension
-       return REGISTER_ADD_CATEGORY_table ($MODE, $return);
+       return REGISTER_ADD_CATEGORY_TABLE ($MODE, $return);
 }
+
 // Generate an email link
 function CREATE_EMAIL_LINK ($email, $table = "admins") {
        // Default email link (INSECURE! Spammer can read this by harvester programs)
@@ -3295,6 +3317,124 @@ function INCLUDE_READABLE ($INC) {
        return FILE_READABLE($FQFN);
 }
 
+// Encode strings
+// @TODO Implement $compress
+function encodeString ($str, $compress=true) {
+       $str = urlencode(base64_encode(compileUriCode($str)));
+       return $str;
+}
+
+// Decode strings encoded with encodeString()
+// @TODO Implement $decompress
+function decodeString ($str, $decompress=true) {
+       $str = compileUriCode(base64_decode(urldecode(compileUriCode($str))));
+       return $str;
+}
+
+// Compile characters which are allowed in URLs
+function compileUriCode ($code, $simple=true) {
+       // Compile constants
+       if (!$simple) $code = str_replace("{--", '".', str_replace("--}", '."', $code));
+
+       // Compile QUOT and other non-HTML codes
+       $code = str_replace("{DOT}", ".",
+               str_replace("{SLASH}", "/",
+               str_replace("{QUOT}", "'",
+               str_replace("{DOLLAR}", "$",
+               str_replace("{OPEN_ANCHOR}", "(",
+               str_replace("{CLOSE_ANCHOR}", ")",
+               str_replace("{OPEN_SQR}", "[",
+               str_replace("{CLOSE_SQR}", "]",
+               str_replace("{PER}", "%",
+               $code
+       )))))))));
+
+       // Return compiled code
+       return $code;
+}
+
+// Function taken from user comments on www.php.net / function eregi()
+function isUrlValid ($url) {
+       // Prepare URL
+       $url = strip_tags(str_replace("\\", "", compileUriCode(urldecode($url))));
+
+       // Allows http and https
+       $http      = "(http|https)+(:\/\/)";
+       // Test domain
+       $domain1   = "([[:alnum:]]([-[:alnum:]])*\.)?([[:alnum:]][-[:alnum:]\.]*[[:alnum:]])(\.[[:alpha:]]{2,5})?";
+       // Test double-domains (e.g. .de.vu)
+       $domain2   = "([-[:alnum:]])?(\.[[:alnum:]][-[:alnum:]\.]*[[:alnum:]])(\.[[:alpha:]]{2,5})(\.[[:alpha:]]{2,5})?";
+       // Test IP number
+       $ip        = "([[:digit:]]{1,3})\.([[:digit:]]{1,3})\.([[:digit:]]{1,3})\.([[:digit:]]{1,3})";
+       // ... directory
+       $dir       = "((/)+([-_\.[:alnum:]])+)*";
+       // ... page
+       $page      = "/([-_[:alnum:]][-\._[:alnum:]]*\.[[:alnum:]]{2,5})?";
+       // ... and the string after and including question character
+       $getstring1 = "([\?/]([[:alnum:]][-\._%[:alnum:]]*(=)?([-\@\._:%[:alnum:]])+)(&([[:alnum:]]([-_%[:alnum:]])*(=)?([-\@\[\._:%[:alnum:]])+(\])*))*)?";
+       // Pattern for URLs like http://url/dir/doc.html?var=value
+       $pattern['d1dpg1']  = $http.$domain1.$dir.$page.$getstring1;
+       $pattern['d2dpg1']  = $http.$domain2.$dir.$page.$getstring1;
+       $pattern['ipdpg1']  = $http.$ip.$dir.$page.$getstring1;
+       // Pattern for URLs like http://url/dir/?var=value
+       $pattern['d1dg1']  = $http.$domain1.$dir."/".$getstring1;
+       $pattern['d2dg1']  = $http.$domain2.$dir."/".$getstring1;
+       $pattern['ipdg1']  = $http.$ip.$dir."/".$getstring1;
+       // Pattern for URLs like http://url/dir/page.ext
+       $pattern['d1dp']  = $http.$domain1.$dir.$page;
+       $pattern['d1dp']  = $http.$domain2.$dir.$page;
+       $pattern['ipdp']  = $http.$ip.$dir.$page;
+       // Pattern for URLs like http://url/dir
+       $pattern['d1d']  = $http.$domain1.$dir;
+       $pattern['d2d']  = $http.$domain2.$dir;
+       $pattern['ipd']  = $http.$ip.$dir;
+       // Pattern for URLs like http://url/?var=value
+       $pattern['d1g1']  = $http.$domain1."/".$getstring1;
+       $pattern['d2g1']  = $http.$domain2."/".$getstring1;
+       $pattern['ipg1']  = $http.$ip."/".$getstring1;
+       // Pattern for URLs like http://url?var=value
+       $pattern['d1g12']  = $http.$domain1.$getstring1;
+       $pattern['d2g12']  = $http.$domain2.$getstring1;
+       $pattern['ipg12']  = $http.$ip.$getstring1;
+       // Test all patterns
+       $reg = false;
+       foreach ($pattern as $key=>$pat) {
+               // Debug regex?
+               if (defined('DEBUG_REGEX')) {
+                       $pat = str_replace("[:alnum:]", "0-9a-zA-Z", $pat);
+                       $pat = str_replace("[:alpha:]", "a-zA-Z", $pat);
+                       $pat = str_replace("[:digit:]", "0-9", $pat);
+                       $pat = str_replace(".", "\.", $pat);
+                       $pat = str_replace("@", "\@", $pat);
+                       echo $key."=&nbsp;".$pat."<br />";
+               }
+
+               // Check if expression matches
+               $reg = ($reg || preg_match(("^".$pat."^"), $url));
+
+               // Does it match?
+               if ($reg === true) break;
+       }
+
+       // Return true/false
+       return $reg;
+}
+
+// Smartly adds slashes
+function smartAddSlashes ($unquoted) {
+       $unquoted = str_replace("\\", "", $unquoted);
+       return addslashes($unquoted);
+}
+
+// Decode entities in a nicer way
+function decodeEntities ($str) {
+       // @TODO We may want to switch over to UTF-8 here!
+       $decodedString = html_entity_decode($str, ENT_NOQUOTES, "ISO-8859-15");
+
+       // Return decoded string
+       return $decodedString;
+}
+
 //////////////////////////////////////////////////
 // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
 //////////////////////////////////////////////////
index 5d32484a7ae6fc39a8d5547c85dbabf69586b327..56cafa67ced876624a305e31d833bb9433d23306 100644 (file)
@@ -77,7 +77,7 @@ if (($header != "1") && ($header != "2")) {
                                if ((getConfig('enable_title_deco') == "Y") && (getConfig('title_right') != "")) $TITLE .= " ".trim(getConfig('title_right'));
 
                                // Remember title in constant for the template
-                               define('__PAGE_TITLE', html_entity_decode($TITLE));
+                               define('__PAGE_TITLE', $TITLE);
                        } elseif ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndTrue('admin_registered'))) {
                                // Load language file because it was missing in installation finalizer step... *sigh*
                                $FQFN = sprintf("inc/language/install_%s.php",
index 89adec715d09d743c95ba49ba2e06bb75876a27f..0cb27530e046cbb8c623a0283a358daf1c706524 100644 (file)
@@ -234,7 +234,7 @@ function WERNIS_EXECUTE_WITHDRAW ($wdsId, $userMd5, $amount) {
                't_md5'                 => $userMd5,
                'r_uid'                 => getConfig('wernis_refid'),
                'amount'                => bigintval($amount),
-               'purpose'               => urlencode(base64_encode($purpose))
+               'purpose'               => encodeString($purpose, false)
        );
 
        // Return the result from the lower functions
@@ -275,7 +275,7 @@ function WERNIS_EXECUTE_PAYOUT ($wdsId, $amount) {
                't_md5'                 => getConfig('wernis_pass_md5'),
                'r_uid'                 => bigintval($wdsId),
                'amount'                => bigintval($amount),
-               'purpose'               => urlencode(base64_encode($purpose))
+               'purpose'               => encodeString($purpose, false)
        );
 
        // Return the result from the lower functions
index 9307272432fa2916a294906b7a56ce105dcfb871..e167b07b955f57b6adf5dd951dc2899f3842a700 100644 (file)
@@ -57,7 +57,7 @@ function YOOMEDIA_TEST_CONFIG ($data) {
 
        // Query the API with a test request without couting it
        // If zero reply comes back the data is invalid!
-       $response = YOOMEDIA_QUERY_API("out_textmail.php", true); // TODO Ask Yoo!Media for test script
+       $response = YOOMEDIA_QUERY_API("out_textmail.php", true); // @TODO Ask Yoo!Media for test script
 
        // Log the response if failed
        if (count($response) == 0) {
index 72853a24f68552b65ce91ac42b925985d754df6f..39b032af951642da048e0253eb17dbbf7acc5f77 100644 (file)
@@ -46,7 +46,7 @@ if (($cacheInstance->loadCacheFile("config", true)) && ($cacheInstance->extensio
        global $cacheArray;
        $cacheArray['config'] = $cacheInstance->getArrayFromCache();
 
-       // TODO: Do we really need to cache the config???
+       // @TODO: Do we really need to cache the config???
 } elseif ((getConfig('cache_config') == "Y") && ($CSS != "1") && ($CSS != "-1")) {
        // Create cache file here
        $cacheInstance->init("CONFIG");
index c7ed2575c9acf71e71ce4a33a1d2a2b825c34312..7ab5e1283ab55aa84f147e8d87058e4efb97c780 100644 (file)
@@ -412,25 +412,19 @@ function ADD_ADMIN_MENU($act, $wht, $return=false) {
 
        // Build main menu
        $result_main = SQL_QUERY("SELECT action, title, descr FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE (what='' OR `what` IS NULL) ORDER BY `sort`, id DESC", __FILE__, __LINE__);
-       if (SQL_NUMROWS($result_main) > 0)
-       {
+       if (SQL_NUMROWS($result_main) > 0) {
                $OUT = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"admin_menu_main\">
 <tr><td colspan=\"2\" height=\"7\" class=\"seperator\">&nbsp;</td></tr>\n";
-               while (list($menu, $title, $descr) = SQL_FETCHROW($result_main))
-               {
-                       if ((EXT_IS_ACTIVE("admins")) && (GET_EXT_VERSION("admins") > "0.2"))
-                       {
+               while (list($menu, $title, $descr) = SQL_FETCHROW($result_main)) {
+                       if ((EXT_IS_ACTIVE("admins")) && (GET_EXT_VERSION("admins") > "0.2")) {
                                $ACL = ADMINS_CHECK_ACL($menu, "");
-                       }
-                        else
-                       {
+                       } else {
                                // ACL is "allow"... hmmm
                                $ACL = true;
                        }
-                       if ($ACL)
-                       {
-                               if (!$SUB)
-                               {
+
+                       if ($ACL === true) {
+                               if (!$SUB) {
                                        // Insert compiled menu title and description
                                        $menuTitle[$menu]      = $title;
                                        $menuDesription[$menu] = $descr;
@@ -537,7 +531,7 @@ function ADD_ADMIN_MENU($act, $wht, $return=false) {
 
        // Compile and run the code here. This inserts all constants into the
        // HTML output. Costs me some time to figure this out... *sigh* Quix0r
-       $eval = "\$OUT = \"".COMPILE_CODE(addslashes($OUT))."\";";
+       $eval = "\$OUT = \"".COMPILE_CODE(SQL_ESCAPE($OUT))."\";";
        eval($eval);
 
        // Is there a cache instance again?
index 85d37c9740751a0548e819755567f7d3c44221f8..a9a81337c8330f4e1f3f7ec590b4301548e72758 100644 (file)
@@ -155,14 +155,14 @@ function OUTPUT_SELECTED_TASKS ($POST, $result_tasks) {
                                } // END - if
 
                                // Decode entities of the text
-                               $text = html_entity_decode($text);
+                               $text = decodeEntities($text);
 
                                // Compile and insert text from task into table template
                                $text = LOAD_TEMPLATE("admin_extensions_text", true, $text);
 
                                // Initialize variables (no title for SQL commands by default)
                                $ext_name = "";
-                               $title = TASK_NO_TITLE;
+                               $title = getMessage('TASK_NO_TITLE');
 
                                // Shall I list SQL commands assigned to an extension installation or update task?
                                if (((GET_EXT_VERSION("sql_patches") != '') && (getConfig('verbose_sql') == "Y")) || (!EXT_IS_ACTIVE("sql_patches"))) {
@@ -175,7 +175,7 @@ function OUTPUT_SELECTED_TASKS ($POST, $result_tasks) {
                                                $text .= $NOTES;
 
                                                // Set title
-                                               $title = ADMIN_SQLS_EXECUTED_ON_REGISTER;
+                                               $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REGISTER');
                                        } elseif ($type == "EXTENSION_UPDATE") {
                                                // Prepare extension name and version
                                                $ext_name = substr($ext_name, 7);
@@ -191,7 +191,7 @@ function OUTPUT_SELECTED_TASKS ($POST, $result_tasks) {
                                                $text .= $NOTES;
 
                                                // Set title
-                                               $title = ADMIN_SQLS_EXECUTED_ON_UPDATE;
+                                               $title = getMessage('ADMIN_SQLS_EXECUTED_ON_UPDATE');
                                        } else {
                                                // Remove extension's name
                                                $ext_name = "";
@@ -230,7 +230,7 @@ function OUTPUT_SELECTED_TASKS ($POST, $result_tasks) {
                                case "EXTENSION": // Install new extensions
                                        $ext_name = substr($subj, 1, strpos($subj, ":") - 1);
                                        $result_lines = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
-                                        array($ext_name), __FILE__, __LINE__);
+                                               array($ext_name), __FILE__, __LINE__);
                                        $lines = SQL_NUMROWS($result_lines);
                                        SQL_FREERESULT($result_lines);
                                        if ($lines == "0") {
@@ -263,6 +263,7 @@ function OUTPUT_SELECTED_TASKS ($POST, $result_tasks) {
                                        break;
 
                                case "SUPPORT_MEMBER": // Assign on member's support request
+                                       // @TODO This may also be rewritten to include files
                                        switch ($mode)
                                        {
                                        default: // @TODO Unknown support mode
index d248df10f1497c558e683b616cb645179a339997..35e3bb7215720b12f7cdfe3b15a2d0fdb1c3a7da 100644 (file)
@@ -107,7 +107,7 @@ if (!empty($_GET['pid'])) {
 
                                                // Transfer variables...
                                                $eval = "\$URL = \"".$eurl."\";";
-                                               $reason = urlencode(base64_encode(PAYOUT_REASON_PAYOUT));
+                                               $reason = encodeString(getMessage('PAYOUT_REASON_PAYOUT'), false);
 
                                                // Run code...
                                                eval($eval);
index 0c46cbe3fc47bb2ceec5a710de53d9ce084dbc69..4fbe78833c52645c4b3b0b11c83615b1e107dde3 100644 (file)
@@ -93,7 +93,7 @@ if ($listed === true) {
                define('__LIST_UNCON_SENDER' , $sender);
                define('__LIST_UNCON_SUBJECT', COMPILE_CODE($subj));
                define('__LIST_UNCON_TEXT'   , COMPILE_CODE($text));
-               define('__LIST_UNCON_URL'    , urlencode(base64_encode($url)));
+               define('__LIST_UNCON_URL'    , encodeString($url));
                define('__LIST_UNCON_STAMP'  , MAKE_DATETIME($stamp, "2"));
 
                // Load unconfirmed mail links. Hmmm, this select query is pretty cool
index 1e40c5de2feec4f48b81ac44ab970f904cf4b9cf..09da0a61ee5b991fc1c2a9ca447fe2d6f92f20ea 100644 (file)
@@ -82,7 +82,7 @@ if (!empty($_GET['image'])) {
 if ((!empty($FQFN)) && (FILE_READABLE($FQFN))) {
        // @TODO This code is double, see LOAD_TEMPLATE and LOAD_EMAIL_TEMPLATE in functions.php
        $tmpl_file = READ_FILE($FQFN);
-       $tmpl_file = addslashes($tmpl_file);
+       $tmpl_file = SQL_ESCAPE($tmpl_file);
        $tmpl_file = "\$content=\"".$tmpl_file."\";";
        eval($tmpl_file);
        // Until here...
index 01dbc053d1413d4ac0837780019ccfea4975f420..aae2439303bb903a1ba88d9e109c88c7c38c7780 100644 (file)
@@ -74,7 +74,7 @@ if ((!empty($_POST['url'])) || (!empty($_GET['url'])) || (!empty($_GET['frame'])
        $url = constant('URL');
 
        // Decode URL if set in GET parameters
-       if (!empty($_GET['url']))  $url = gzuncompress(base64_decode(str_replace(" ", "+", COMPILE_CODE(urldecode($_GET['url'])))));
+       if (!empty($_GET['url']))  $url = decodeString(str_replace(" ", "+", compileUriCode(urldecode($_GET['url']))));
 
        // Use URL from POST data if set
        if (!empty($_POST['url'])) $url = $_POST['url'];
index ab8533a79b1382f876e8bcade550e6bd6a1a04df..4b6a8d1d85da7360517b51957ffea5327f1b206b 100644 (file)
@@ -39,7 +39,7 @@ if (!defined('__SECURITY')) {
 
 if (!empty($_GET['url'])) {
        // Decode URL
-       $url = gzuncompress(base64_decode(str_replace(" ", "+", COMPILE_CODE(urldecode($_GET['url'])))));
+       $url = decodeString(str_replace(" ", "+", compileUriCode(urldecode($_GET['url']))));
 
        // Validate the URL
        if (VALIDATE_URL($url)) {