* Dummy extension "yoomedia" added for Yoo! Media's API (Interface 2.0 supported)
[mailer.git] / inc / functions.php
index f2806f6b648279ee09bbe01fa3165063fd4b8e6b..7462021a9d7bae989751a6eaee7f8b8ec45c0d61 100644 (file)
@@ -138,8 +138,16 @@ function OUTPUT_HTML($HTML, $NEW_LINE = true) {
 
                // Compile and run finished rendered HTML code
                while (strpos($OUTPUT, '{!') > 0) {
-                       $eval = "\$OUTPUT = \"" . COMPILE_CODE(addslashes($OUTPUT)) . "\";";
-                       eval($eval);
+                       // Prepare the content and eval() it...
+                       $newContent = "";
+                       $eval = "\$newContent = \"" . COMPILE_CODE(addslashes($OUTPUT)) . "\";";
+                       @eval($eval);
+
+                       if (empty($newContent)) {
+                               // Something went wrong!
+                               die("Evaluation error:<pre>".htmlentities($eval)."</pre>");
+                       }
+                       $OUTPUT = $newContent;
                }
 
                // Output code here, DO NOT REMOVE! ;-)
@@ -1650,6 +1658,16 @@ function ADD_EMAIL_NAV($PAGES, $offset, $show_form, $colspan, $return=false) {
 
 //
 function MXCHANGE_OPEN ($script) {
+       global $_CONFIG;
+       // Default is not to use proxy
+       $useProxy = true;
+
+       // Are proxy settins set?
+       if ((!empty($_CONFIG['proxy_host'])) && ($_CONFIG['proxy_port'] > 0)) {
+               // Then use it
+               $useProxy = true;
+       }
+
        //* DEBUG */ print("SCRIPT=".$script."<br />\n");
        // Compile the script name
        $script = COMPILE_CODE($script);
@@ -1663,7 +1681,7 @@ function MXCHANGE_OPEN ($script) {
                $extract = explode("/", $url);
                $url = $extract[0];
                // Done extracting the URL :)
-       }
+       } // END - if
 
        // Extract host name
        $host = str_replace("http://", "", $url);
@@ -1684,17 +1702,62 @@ function MXCHANGE_OPEN ($script) {
 
        // Open connection
        //* DEBUG */ die("SCRIPT=".$script."<br />\n");
-       $fp = @fsockopen($host, 80, $errno, $errdesc, 30);
-       if (!$fp) {
-               // Failed!
-               return array("", "", "");
+       if ($useProxy) {
+               $fp = @fsockopen(COMPILE_CODE($_CONFIG['proxy_host']), $_CONFIG['proxy_port'], $errno, $errdesc, 30);
+       } else {
+               $fp = @fsockopen($host, 80, $errno, $errdesc, 30);
        }
 
-       // Generate request header
-       $request  = "GET /".trim($script)." HTTP/1.0\r\n";
+       // Is there a link?
+       if (!is_resource($fp)) {
+               // Failed!
+               return array("", "", "");
+       } // END - if
+
+       // Do we use proxy?
+       if ($useProxy) {
+               // Generate CONNECT request header
+               $request  = "CONNECT ".$host.":80 HTTP/1.1\r\n";
+               $request .= "Host: ".$host."\r\n";
+
+               // Use login data to proxy? (username at least!)
+               if (!empty($_CONFIG['proxy_username'])) {
+                       // Add it as well
+                       $encodedAuth = base64_encode(COMPILE_CODE($_CONFIG['proxy_username']).":".COMPILE_CODE($_CONFIG['proxy_password']));
+                       $request .= "Proxy-Authorization: Basic ".$encodedAuth."\r\n";
+               } // END - if
+
+               // Add last new-line
+               $request .= "\r\n";
+               //* DEBUG: */ print("<strong>Request:</strong><pre>".$request."</pre>");
+
+               // Write request
+               fputs($fp, $request);
+
+               // Got response?
+               if (feof($fp)) {
+                       // No response received
+                       return array("", "", "");
+               } // END - if
+
+               // Read the first line
+               $resp = trim(fgets($fp, 10240));
+               $respArray = explode(" ", $resp);
+               if ((strtolower($respArray[0]) !== "http/1.0") || ($respArray[1] != "200")) {
+                       // Invalid response!
+                       return array("", "", "");
+               } // END - if
+       } // END - if
+       
+       // 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\r\n";
+       $request .= "User-Agent: ".TITLE."/".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";
+       //* DEBUG: */ print("<strong>Request:</strong><pre>".$request."</pre>");
 
        // Initialize array
        $response = array();
@@ -1705,16 +1768,25 @@ function MXCHANGE_OPEN ($script) {
        // Read response
        while(!feof($fp)) {
                $response[] = trim(fgets($fp, 1024));
-       }
+       } // END - while
 
        // Close socket
        fclose($fp);
 
+       //* DEBUG: */ print("<strong>Response:</strong><pre>".print_r($response, true)."</pre>");
+
+       // Proxy agent found?
+       if ((substr(strtolower($response[0]), 0, 11) == "proxy-agent") && ($useProxy)) {
+               // Proxy header detected, so remove two lines
+               array_shift($response);
+               array_shift($response);
+       } // END - if
+
        // Was the request successfull?
-       if ((!ereg("200 OK", $response[0])) && (empty($response[0]))) {
+       if ((!ereg("200 OK", $response[0])) || (empty($response[0]))) {
                // Not found / access forbidden
                $response = array("", "", "");
-       }
+       } // END - if
 
        // Return response
        return $response;
@@ -2082,6 +2154,7 @@ function DISPLAY_PARSING_TIME_FOOTER() {
 // Unset/set session variables
 function set_session ($var, $value) {
        global $CSS;
+
        // Abort in CSS mode here
        if ($CSS == 1) return true;
 
@@ -2099,6 +2172,9 @@ function set_session ($var, $value) {
                //* DEBUG: */ echo "SET:".$var."=".$value."<br />\n";
                $_SESSION[$var] =  $value;
                return session_register($var);
+       } elseif (!empty($value)) {
+               // Update session
+               $_SESSION[$var] = $value;
        }
 
        // Return always true if the session variable is already set.
@@ -2121,8 +2197,6 @@ function isSessionVariableSet($var) {
 
 // Returns wether the value of the session variable or NULL if not set
 function get_session($var) {
-       if (!isset($_SESSION)) session_start();
-
        // Default is not found! ;-)
        $value = null;
 
@@ -2137,21 +2211,20 @@ function get_session($var) {
 }
 
 //
-//////////////////////////////////////////////
-//                                          //
-// AUTOMATICALLY RE-GNERATED FUNCTIONS ONLY //
-//                                          //
-//////////////////////////////////////////////
+//////////////////////////////////////////////////
+//                                              //
+// AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
+//                                              //
+//////////////////////////////////////////////////
 //
-if (!function_exists('html_entity_decode'))
-{
+if (!function_exists('html_entity_decode')) {
        // Taken from documentation on www.php.net
-       function html_entity_decode($string)
-       {
+       function html_entity_decode($string) {
                $trans_tbl = get_html_translation_table(HTML_ENTITIES);
                $trans_tbl = array_flip($trans_tbl);
                return strtr($string, $trans_tbl);
        }
 }
+
 //
 ?>