function LoadTemplate($s_name, $s_dir, $s_url, $b_ret_lines = false)
{
    global $php_errormsg;
    $s_buf = "";
    $a_lines = array();
    if (!empty($s_dir)) {
        $s_name = "{$s_dir}/" . basename($s_name);
        @($fp = fopen($s_name, "r"));
        if ($fp === false) {
            SendAlert(GetMessage(MSG_OPEN_TEMPLATE, array("NAME" => $s_name, "ERROR" => CheckString($php_errormsg))));
            return false;
        }
        if ($b_ret_lines) {
            $a_lines = ReadLines($fp);
        } else {
            //
            // load the whole template into a string
            //
            $s_buf = fread($fp, filesize($s_name));
        }
        fclose($fp);
    } else {
        if (substr($s_url, -1) == '/') {
            $s_name = "{$s_url}" . basename($s_name);
        } else {
            $s_name = "{$s_url}/" . basename($s_name);
        }
        if (($m_data = GetURL($s_name, $s_error, $b_ret_lines)) === false) {
            SendAlert($s_error);
            return false;
        }
        if ($b_ret_lines) {
            $a_lines = $m_data;
            //
            // strip line terminations from each line
            //
            for ($ii = count($a_lines); --$ii >= 0;) {
                $s_line = $a_lines[$ii];
                $s_line = str_replace("\r", "", $s_line);
                $s_line = str_replace("\n", "", $s_line);
                $a_lines[$ii] = $s_line;
            }
        } else {
            $s_buf = $m_data;
        }
    }
    return $b_ret_lines ? $a_lines : $s_buf;
}
예제 #2
0
function LoadTemplate($s_name, $s_dir, $s_url, $b_ret_lines = false)
{
    global $php_errormsg;
    $s_buf = "";
    $a_lines = array();
    if (!empty($s_dir)) {
        $s_name = "{$s_dir}/" . basename($s_name);
        @($fp = fopen($s_name, "r"));
        if ($fp === false) {
            SendAlert(GetMessage(MSG_OPEN_TEMPLATE, array("NAME" => $s_name, "ERROR" => CheckString($php_errormsg))));
            return false;
        }
        if ($b_ret_lines) {
            $a_lines = ReadLines($fp);
        } else {
            //
            // load the whole template into a string
            //
            $s_buf = fread($fp, filesize($s_name));
        }
        fclose($fp);
    } else {
        global $aServerVars;
        if (substr($s_url, -1) == '/') {
            $s_name = "{$s_url}" . basename($s_name);
        } else {
            $s_name = "{$s_url}/" . basename($s_name);
        }
        $s_name = AddUserAgent($s_name);
        //
        // open the URL with the same session as we have
        //
        if (session_id() !== "") {
            $s_name = AddURLParams($s_name, session_name() . "=" . urlencode(session_id()));
        } elseif (defined("SID")) {
            $s_name = AddURLParams($s_name, SID);
        }
        $http_get = new HTTPGet($s_name);
        //
        // resolve the name now so the DNS cache can be written to the session
        //
        $http_get->Resolve();
        //
        // Since we might be opening a URL within the same session, we can
        // get locks.  So, close the session for writing to prevent this.
        //
        if (function_exists('session_write_close')) {
            session_write_close();
            //ob_flush();             // this prevents automatic redirects if $TEMPLATEURL
            // is in use and JavaScript is switched off
        }
        FMDebug("Begin read");
        $php_errormsg = "";
        // clear this out in case we get an error that doesn't set it
        if (($a_lines = $http_get->Read()) === FALSE) {
            //
            // get the error code and send the appropriate alert
            //
            list($i_error, $i_sys_err, $s_sys_msg) = $http_get->GetError();
            switch ($i_error) {
                case $http_get->nErrParse:
                    $s_error = GetMessage(MSG_URL_PARSE);
                    break;
                case $http_get->nErrScheme:
                    $a_parts = $http_get->GetURLSplit();
                    $s_error = GetMessage(MSG_URL_SCHEME, array("SCHEME" => $a_parts["scheme"]));
                    break;
                default:
                    $s_error = GetMessage(MSG_SOCKET, array("ERRNO" => $i_sys_err, "ERRSTR" => $s_sys_msg, "PHPERR" => CheckString($php_errormsg)));
                    break;
            }
            SendAlert($s_error);
            return false;
        }
        FMDebug("Read " . count($a_lines) . " lines");
        if ($b_ret_lines) {
            //
            // strip line terminations from each line
            //
            for ($ii = count($a_lines); --$ii >= 0;) {
                $s_line = $a_lines[$ii];
                $s_line = str_replace("\r", "", $s_line);
                $s_line = str_replace("\n", "", $s_line);
                $a_lines[$ii] = $s_line;
            }
        } else {
            $s_buf = implode("", $a_lines);
        }
        //
        // now re-open our session
        //
        session_start();
    }
    return $b_ret_lines ? $a_lines : $s_buf;
}
예제 #3
0
function LoadTemplate($s_name, $b_ret_lines = false)
{
    global $TEMPLATEURL, $TEMPLATEDIR;
    if (empty($TEMPLATEDIR) && empty($TEMPLATEURL)) {
        SendAlert("You must set either TEMPLATEDIR or TEMPLATEURL in formmail.php before you can specify templates in your forms.");
        return false;
    }
    $s_buf = "";
    $a_lines = array();
    if (!empty($TEMPLATEDIR)) {
        $s_name = "{$TEMPLATEDIR}/" . basename($s_name);
        @($fp = fopen($s_name, "r"));
        if ($fp === false) {
            SendAlert("Failed to open template '{$s_name}'");
            return false;
        }
        if ($b_ret_lines) {
            $a_lines = ReadLines($fp);
        } else {
            //
            // load the whole template into a string
            //
            $s_buf = fread($fp, filesize($s_name));
        }
        fclose($fp);
    } else {
        global $HTTP_SERVER_VARS;
        $s_name = "{$TEMPLATEURL}/" . basename($s_name);
        unset($s_agent);
        if (isset($_SERVER['HTTP_USER_AGENT'])) {
            $s_agent = $_SERVER['HTTP_USER_AGENT'];
        } elseif (isset($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) {
            $s_agent = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
        }
        if (isset($s_agent)) {
            $s_name = AddURLParams($s_name, "USER_AGENT={$s_agent}");
        }
        @($fp = fopen($s_name, "r"));
        if ($fp === false) {
            SendAlert("Failed to open template '{$s_name}'");
            return false;
        }
        if ($b_ret_lines) {
            $a_lines = ReadLines($fp);
        } else {
            //
            // load the whole template into a string
            //
            while (!feof($fp)) {
                $s_buf .= fread($fp, 4096);
            }
        }
        fclose($fp);
    }
    return $b_ret_lines ? $a_lines : $s_buf;
}
예제 #4
0
function LoadTemplate($s_name, $b_ret_lines = false)
{
    global $TEMPLATEURL, $TEMPLATEDIR, $php_errormsg;
    if (empty($TEMPLATEDIR) && empty($TEMPLATEURL)) {
        SendAlert(GetMessage(MSG_TEMPLATES));
        return false;
    }
    $s_buf = "";
    $a_lines = array();
    if (!empty($TEMPLATEDIR)) {
        $s_name = "{$TEMPLATEDIR}/" . basename($s_name);
        @($fp = fopen($s_name, "r"));
        if ($fp === false) {
            SendAlert(GetMessage(MSG_OPEN_TEMPLATE, array("NAME" => $s_name, "ERROR" => CheckString($php_errormsg))));
            return false;
        }
        if ($b_ret_lines) {
            $a_lines = ReadLines($fp);
        } else {
            //
            // load the whole template into a string
            //
            $s_buf = fread($fp, filesize($s_name));
        }
        fclose($fp);
    } else {
        global $HTTP_SERVER_VARS;
        $s_name = "{$TEMPLATEURL}/" . basename($s_name);
        unset($s_agent);
        if (isset($_SERVER['HTTP_USER_AGENT'])) {
            $s_agent = $_SERVER['HTTP_USER_AGENT'];
        } elseif (isset($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) {
            $s_agent = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
        }
        if (isset($s_agent)) {
            $s_name = AddURLParams($s_name, "USER_AGENT={$s_agent}");
        }
        @($fp = fopen($s_name, "r"));
        if ($fp === false) {
            SendAlert(GetMessage(MSG_OPEN_TEMPLATE, array("NAME" => $s_name, "ERROR" => CheckString($php_errormsg))));
            return false;
        }
        if ($b_ret_lines) {
            $a_lines = ReadLines($fp);
        } else {
            //
            // load the whole template into a string
            //
            while (!feof($fp)) {
                $s_buf .= fread($fp, 4096);
            }
        }
        fclose($fp);
    }
    return $b_ret_lines ? $a_lines : $s_buf;
}
예제 #5
0
function LoadTemplate($s_name, $s_dir, $s_url, $b_ret_lines = false)
{
    global $php_errormsg;
    $s_buf = "";
    $a_lines = array();
    if (!empty($s_dir)) {
        $s_name = "{$s_dir}/" . basename($s_name);
        @($fp = fopen($s_name, "r"));
        if ($fp === false) {
            SendAlert(GetMessage(MSG_OPEN_TEMPLATE, array("NAME" => $s_name, "ERROR" => CheckString($php_errormsg))));
            return false;
        }
        if ($b_ret_lines) {
            $a_lines = ReadLines($fp);
        } else {
            //
            // load the whole template into a string
            //
            $s_buf = fread($fp, filesize($s_name));
        }
        fclose($fp);
    } else {
        global $aServerVars;
        $s_name = "{$s_url}/" . basename($s_name);
        if (isset($aServerVars['HTTP_USER_AGENT'])) {
            $s_name = AddURLParams($s_name, "USER_AGENT=" . $aServerVars['HTTP_USER_AGENT']);
        }
        //
        // open the URL with the same session as we have
        //
        if (session_id() !== "") {
            $s_name = AddURLParams($s_name, session_name() . "=" . urlencode(session_id()));
        }
        if (defined("SID")) {
            $s_name = AddURLParams($s_name, SID);
        }
        //
        // Since we might be opening a URL within the same session, we can
        // get locks.  So, close the session for writing to prevent this.
        //
        if (function_exists('session_write_close')) {
            session_write_close();
            ob_flush();
            // probably a good idea
        }
        @($fp = fopen($s_name, "r"));
        if ($fp === false) {
            SendAlert(GetMessage(MSG_OPEN_TEMPLATE, array("NAME" => $s_name, "ERROR" => CheckString($php_errormsg))));
            return false;
        }
        if ($b_ret_lines) {
            $a_lines = ReadLines($fp);
        } else {
            //
            // load the whole template into a string
            //
            while (!feof($fp)) {
                $s_buf .= fread($fp, 4096);
            }
        }
        fclose($fp);
        //
        // now re-open our session
        //
        session_start();
    }
    return $b_ret_lines ? $a_lines : $s_buf;
}