]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
All, except security block, include()/require() rewritten to own LOAD_INC()/LOAD_INC_...
[mailer.git] / inc / functions.php
index e545aa0d6e731f2e2007ac7927149bf1059aad45..f071322d043c171fd85417d3dd4f23f0885ee8b3 100644 (file)
@@ -40,7 +40,7 @@ if (!defined('__SECURITY')) {
 // Check if our config file is writeable or not
 function IS_INC_WRITEABLE($inc) {
        // Generate FQFN
-       $fqfn = sprintf("%sinc/%s.php", PATH, $inc);
+       $fqfn = sprintf("%sinc/%s.php", constant('PATH'), $inc);
 
        // Abort by simple test
        if ((FILE_READABLE($fqfn)) && (!is_writeable($fqfn))) {
@@ -265,7 +265,7 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
        $date_time = MAKE_DATETIME(time(), "1");
 
        // Base directory
-       $BASE = sprintf("%stemplates/%s/html/", PATH, GET_LANGUAGE());
+       $BASE = sprintf("%stemplates/%s/html/", constant('PATH'), GET_LANGUAGE());
        $MODE = "";
 
        // Check for admin/guest/member templates
@@ -476,12 +476,12 @@ function SEND_RAW_EMAIL ($to, $subject, $msg, $from) {
        // Shall we use PHPMailer class or legacy mode?
        if (CHECK_PHPMAILER_USAGE()) {
                // Use PHPMailer class with SMTP enabled
-               require_once(PATH."inc/phpmailer/class.phpmailer.php");
-               require_once(PATH."inc/phpmailer/class.smtp.php");
+               LOAD_INC_ONCE("inc/phpmailer/class.phpmailer.php");
+               LOAD_INC_ONCE("inc/phpmailer/class.smtp.php");
 
                // get new instance
                $mail = new PHPMailer();
-               $mail->PluginDir  = sprintf("%sinc/phpmailer/", PATH);
+               $mail->PluginDir  = sprintf("%sinc/phpmailer/", constant('PATH'));
 
                $mail->IsSMTP();
                $mail->SMTPAuth   = true;
@@ -701,7 +701,7 @@ function GET_LANGUAGE() {
        global $cacheArray;
 
        // Set default return value to default language from config
-       $ret = DEFAULT_LANG;
+       $ret = constant('DEFAULT_LANG');
 
        // Init variable
        $lang = "";
@@ -724,7 +724,7 @@ function GET_LANGUAGE() {
                $ret = get_session('mx_lang');
 
                // Fixes a warning before the session has the mx_lang constant
-               if (empty($ret)) $ret = DEFAULT_LANG;
+               if (empty($ret)) $ret = constant('DEFAULT_LANG');
        }
 
        // Cache entry
@@ -823,7 +823,7 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
        $DATA['email'] = $email;
 
        // Base directory
-       $BASE = sprintf("%stemplates/%s/emails/", PATH, GET_LANGUAGE());
+       $BASE = sprintf("%stemplates/%s/emails/", constant('PATH'), GET_LANGUAGE());
 
        // Check for admin/guest/member templates
        if (strpos($template, "admin_") > -1) {
@@ -950,9 +950,9 @@ function LOAD_URL($URL, $addUrlData=true) {
                header ("Location: ".str_replace("&", "&", $URL));
        } else {
                // Output error message
-               require(PATH."inc/header.php");
+               LOAD_INC("inc/header.php");
                LOAD_TEMPLATE("redirect_url", false, str_replace("&", "&", $URL));
-               require(PATH."inc/footer.php");
+               LOAD_INC("inc/footer.php");
        }
        exit();
 }
@@ -1319,7 +1319,7 @@ function GENERATE_IMAGE($img_code, $header=true) {
        }
 
        // Load image
-       $img = sprintf("%s/theme/%s/images/code_bg.%s", PATH, GET_CURR_THEME(), getConfig('img_type'));
+       $img = sprintf("%s/theme/%s/images/code_bg.%s", constant('PATH'), GET_CURR_THEME(), getConfig('img_type'));
        if (FILE_READABLE($img)) {
                // Switch image type
                switch (getConfig('img_type'))
@@ -2240,13 +2240,13 @@ function FIX_DELETED_COOKIES ($cookies) {
 // Output error messages in a fasioned way and die...
 function mxchange_die ($msg) {
        // Load header
-       require_once(PATH."inc/header.php");
+       LOAD_INC_ONCE("inc/header.php");
 
        // Load the message template
        LOAD_TEMPLATE("admin_settings_saved", false, $msg);
 
        // Load footer
-       require(PATH."inc/footer.php");
+       LOAD_INC("inc/footer.php");
 
        // Exit explicitly
        exit;
@@ -2639,13 +2639,13 @@ function REBUILD_CACHE ($cache, $inc="") {
                // Include file given?
                if (!empty($inc)) {
                        // Construct FQFN
-                       $fqfn = sprintf("%sinc/loader/load_cache-%s.php", PATH, $inc);
+                       $INC = sprintf("inc/loader/load_cache-%s.php", $inc);
 
                        // Is the include there?
-                       if (FILE_READABLE($fqfn)) {
+                       if (FILE_READABLE($INC)) {
                                // And rebuild it from scratch
                                //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): inc={$inc} - LOADED!<br />\n";
-                               require($fqfn);
+                               LOAD_INC($INC);
                        } else {
                                // Include not found!
                                DEBUG_LOG(__FUNCTION__, __LINE__, "Include {$inc} not found. cache={$cache}");
@@ -2915,13 +2915,13 @@ function GET_CURR_THEME() {
                } // END - if
        } elseif ((!isBooleanConstantAndTrue('mxchange_installed')) && ((isBooleanConstantAndTrue('mxchange_installing')) || ($CSS == true)) && ((!empty($_GET['theme'])) || (!empty($_POST['theme'])))) {
                // Prepare FQFN for checking
-               $theme = sprintf("%stheme/%s/theme.php", PATH, SQL_ESCAPE($_GET['theme']));
+               $theme = sprintf("%stheme/%s/theme.php", constant('PATH'), SQL_ESCAPE($_GET['theme']));
 
                // Installation mode active
                if ((!empty($_GET['theme'])) && (FILE_READABLE($theme))) {
                        // Set cookie from URL data
                        set_session('mxchange_theme', SQL_ESCAPE($_GET['theme']));
-               } elseif (FILE_READABLE(sprintf("%stheme/%s/theme.php", PATH, SQL_ESCAPE($_POST['theme'])))) {
+               } elseif (FILE_READABLE(sprintf("%stheme/%s/theme.php", constant('PATH'), SQL_ESCAPE($_POST['theme'])))) {
                        // Set cookie from posted data
                        set_session('mxchange_theme', SQL_ESCAPE($_POST['theme']));
                }
@@ -2934,7 +2934,7 @@ function GET_CURR_THEME() {
        }
 
        // Add (maybe) found theme.php file to inclusion list
-       $theme = sprintf("%stheme/%s/theme.php", PATH, SQL_ESCAPE($ret));
+       $theme = sprintf("%stheme/%s/theme.php", constant('PATH'), SQL_ESCAPE($ret));
 
        // Try to load the requested include file
        if (FILE_READABLE($theme)) $INC_POOL[] = $theme;
@@ -3069,7 +3069,7 @@ function getActualVersion ($type = 0) {
        $new = false;
 
        // FQFN of revision file
-       $FQFN = sprintf("%sinc/cache/.revision", PATH);
+       $FQFN = sprintf("%sinc/cache/.revision", constant('PATH'));
 
        // Check for revision file
        if (!FILE_READABLE($FQFN)) {
@@ -3105,6 +3105,48 @@ function getActualVersion ($type = 0) {
                return trim($akt_vers[$type]);
        }
 }
+
+// Loads an include file and logs any missing files for debug purposes
+function LOAD_INC ($INC) {
+       // Get constant path
+       $PATH = constant('PATH');
+
+       // Use the include file name directly
+       // @TODO Try to find all locations where an FQFN is given to these two
+       // @TODO functions and avoid it.
+       $FQFN = $INC;
+
+       // Check if PATH is in $INC
+       if (substr($INC, 0, $PATH) != $PATH) {
+               // Add it. This is why we need a trailing slash in config.php
+               $FQFN = $PATH . $INC;
+       } // END - if
+
+       // Is the include file there?
+       if (!FILE_READABLE($FQFN)) {
+               // Not there so log it
+               DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Include file %s not found.", basename($INC)));
+               return false;
+       } // END - if
+
+       // Try to load it
+       require($FQFN);
+}
+
+// Loads an include file once
+function LOAD_INC_ONCE ($INC) {
+       global $cacheArray;
+
+       // Is it not loaded?
+       if (!isset($cacheArray['load_once'][$INC])) {
+               // Then try to load it
+               LOAD_INC($INC);
+
+               // And mark it as loaded
+               $cacheArray['load_once'][$INC] = true;
+       } // END - if
+}
+
 //////////////////////////////////////////////////
 // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
 //////////////////////////////////////////////////