]> git.mxchange.org Git - mailer.git/blobdiff - inc/extensions.php
More variables renamed to , install/admin_WriteData() is now generic (with open TODO)
[mailer.git] / inc / extensions.php
index c98644a484be119a8a914a01e98b84d38df64b41..608cb3234fa92c51de596fb65019fec9637a045e 100644 (file)
@@ -55,10 +55,13 @@ function LOAD_EXTENSION ($ext_name, $EXT_LOAD_MODE = "", $EXT_VER = "", $dry_run
        } // END - if
 
        // Construct FQFN for extension file
-       $extInclude = sprintf("%sinc/extensions/ext-%s.php", PATH, $ext_name);
+       $FQFN = sprintf("%sinc/extensions/ext-%s.php",
+               constant('PATH'),
+               $ext_name
+       );
 
        // Is the extension file NOT there?
-       if (!FILE_READABLE($extInclude)) {
+       if (!FILE_READABLE($FQFN)) {
                // Debug message
                DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Extension %s not found.", $ext_name));
 
@@ -67,25 +70,25 @@ function LOAD_EXTENSION ($ext_name, $EXT_LOAD_MODE = "", $EXT_VER = "", $dry_run
        } // END - if
 
        // Construct FQFN for language file
-       $langInclude = sprintf("%sinc/language/%s_%s.php", PATH, $ext_name, GET_LANGUAGE());
+       $langInclude = sprintf("inc/language/%s_%s.php", $ext_name, GET_LANGUAGE());
 
        // Is this include there?
        if ((FILE_READABLE($langInclude)) && (!isset($EXT_LOADED['lang'][$ext_name]))) {
                // Then load it
                //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "--- Language loaded.");
                $EXT_LOADED['lang'][$ext_name] = true;
-               require($langInclude);
+               LOAD_INC_ONCE($langInclude);
        } // END - if
 
        // Construct FQFN for functions file
-       $funcsInclude = sprintf("%sinc/libs/%s_functions.php", PATH, $ext_name);
+       $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
 
        // Is this include there?
        if ((FILE_READABLE($funcsInclude)) && (!isset($EXT_LOADED['funcs'][$ext_name]))) {
                // Then load it
                //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "--- Functions loaded.");
                $EXT_LOADED['funcs'][$ext_name] = true;
-               require($funcsInclude);
+               LOAD_INC_ONCE($funcsInclude);
        } // END - if
 
        // Extensions are not deprecated by default
@@ -102,7 +105,7 @@ function LOAD_EXTENSION ($ext_name, $EXT_LOAD_MODE = "", $EXT_VER = "", $dry_run
 
        // Include the extension file
        //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "Extension loaded.");
-       require($extInclude);
+       require($FQFN);
 
        // Is this extension deprecated?
        if ($EXT_DEPRECATED == "Y") {
@@ -216,7 +219,7 @@ function EXTENSION_REGISTER ($ext_name, $task_id, $dry_run = false, $logout = tr
                                RUN_FILTER('pre_extension_installed', array('dry_run' => $dry_run, 'sqls' => $SQLs));
 
                                // Register extension
-                               SQL_QUERY_ESC("INSERT INTO `{!MYSQL_PREFIX!}_extensions` (ext_name, ext_active, ext_version) VALUES ('%s','%s','%s')",
+                               SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_extensions` (ext_name, ext_active, ext_version) VALUES ('%s','%s','%s')",
                                        array($ext_name, $EXT_ALWAYS_ACTIVE, $EXT_VERSION), __FILE__, __LINE__);
 
                                // Remove cache file(s) if extension is active
@@ -243,7 +246,7 @@ function EXTENSION_REGISTER ($ext_name, $task_id, $dry_run = false, $logout = tr
                }
        } elseif (($task_id > 0) && (!empty($ext_name))) {
                // Remove task from system when id and extension's name is valid
-               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!MYSQL_PREFIX!}_task_system` WHERE id=%s AND status='NEW' LIMIT 1",
+               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_task_system` WHERE id=%s AND `status`='NEW' LIMIT 1",
                        array(bigintval($task_id)), __FILE__, __LINE__);
        }
 
@@ -296,7 +299,7 @@ function EXTENSION_RUN_SQLS ($ext_id, $load_mode) {
                // Removal mode?
                if ($load_mode == "remove") {
                        // Delete this extension (remember to remove it from your server *before* you click on welcome!
-                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
+                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
                                array($ext_name), __FILE__, __LINE__);
                } // END - if
        } // END - if
@@ -337,7 +340,7 @@ function EXT_IS_ACTIVE ($ext_name) {
        } elseif (($ext_name == "cache") || (GET_EXT_VERSION("cache") == "")) {
                //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "DB! ext_name={$ext_name}");
                // Load from database
-               $result = SQL_QUERY_ESC("SELECT ext_active FROM `{!MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
+               $result = SQL_QUERY_ESC("SELECT ext_active FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
                        array($ext_name), __FILE__, __LINE__);
 
                // Entry found?
@@ -383,7 +386,7 @@ function GET_EXT_VERSION ($ext_name) {
                incrementConfigEntry('cache_hits');
        } elseif (!is_object($cacheInstance)) {
                // Load from database
-               $result = SQL_QUERY_ESC("SELECT ext_version FROM `{!MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
+               $result = SQL_QUERY_ESC("SELECT ext_version FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
                        array($ext_name), __FILE__, __LINE__);
 
                // Is the extension there?
@@ -476,10 +479,10 @@ 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",
+                       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_version='%s' WHERE ext_name='%s' LIMIT 1",
                                array($cacheArray['update_ver'][$ext_name], $ext_name), __FILE__, __LINE__);
 
                        // Remove arrays
@@ -496,9 +499,15 @@ function EXTENSION_UPDATE ($ext_name, $ext_ver, $dry_run = false) {
 }
 
 // Output verbose SQL table for extension
-function EXTENSION_VERBOSE_TABLE ($queries = array(), $title = ADMIN_SQLS_EXECUTED_ON_REMOVAL, $dashed = "", $switch = false, $width = "100%") {
+function EXTENSION_VERBOSE_TABLE ($queries = array(), $title = "", $dashed = "", $switch = false, $width = "100%") {
        global $SQLs;
 
+       // Empty title?
+       if (empty($title)) {
+               // Then fix it to default
+               $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REMOVAL');
+       } // END - if
+
        // Are there some queries in $queries?
        if (count($queries) > 0) {
                // Then use them instead!
@@ -545,7 +554,7 @@ function EXTENSION_VERBOSE_TABLE ($queries = array(), $title = ADMIN_SQLS_EXECUT
                $OUT = LOAD_TEMPLATE("admin_ext_sql_table", true, $content);
        } elseif ((GET_EXT_VERSION("sql_patches") >= "0.0.7") && (getConfig('verbose_sql') == "Y")) {
                // No addional SQL commands to run
-               $OUT = LOAD_TEMPLATE("admin_settings_saved", true, ADMIN_NO_ADDITIONAL_SQLS);
+               $OUT = LOAD_TEMPLATE("admin_settings_saved", true, getMessage('ADMIN_NO_ADDITIONAL_SQLS'));
        } // END - if
 
        // Return output
@@ -568,7 +577,7 @@ function GET_EXT_NAME ($ext_id) {
                incrementConfigEntry('cache_hits');
        } elseif (!EXT_IS_ACTIVE("cache")) {
                // Load from database
-               $result = SQL_QUERY_ESC("SELECT ext_name FROM `{!MYSQL_PREFIX!}_extensions` WHERE id=%s LIMIT 1",
+               $result = SQL_QUERY_ESC("SELECT ext_name FROM `{!_MYSQL_PREFIX!}_extensions` WHERE id=%s LIMIT 1",
                        array(bigintval($ext_id)), __FILE__, __LINE__);
                list($ret) = SQL_FETCHROW($result);
                SQL_FREERESULT($result);
@@ -590,7 +599,7 @@ function GET_EXT_ID ($ext_name) {
                incrementConfigEntry('cache_hits');
        } elseif (!EXT_IS_ACTIVE("cache")) {
                // Load from database
-               $result = SQL_QUERY_ESC("SELECT id FROM `{!MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
+               $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
                        array($ext_name), __FILE__, __LINE__);
                list($ret) = SQL_FETCHROW($result);
                SQL_FREERESULT($result);
@@ -603,7 +612,7 @@ function GET_EXT_ID ($ext_name) {
 // Activate given extension
 function ACTIVATE_EXTENSION ($ext_name) {
        // Activate the extension
-       SQL_QUERY_ESC("UPDATE `{!MYSQL_PREFIX!}_extensions` SET ext_active='Y' WHERE ext_name='%s' LIMIT 1",
+       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_active='Y' WHERE ext_name='%s' LIMIT 1",
                array($ext_name), __FILE__, __LINE__);
 
        // Extension has been activated?
@@ -616,7 +625,7 @@ function ACTIVATE_EXTENSION ($ext_name) {
 // Deactivate given extension
 function DEACTIVATE_EXTENSION($ext_name) {
        // Activate the extension
-       SQL_QUERY_ESC("UPDATE `{!MYSQL_PREFIX!}_extensions` SET ext_active='N' WHERE ext_name='%s' LIMIT 1",
+       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_active='N' WHERE ext_name='%s' LIMIT 1",
                array($ext_name), __FILE__, __LINE__);
 
        // Extension has been activated?
@@ -628,7 +637,11 @@ function DEACTIVATE_EXTENSION($ext_name) {
                CREATE_EXTENSION_DEACTIVATION_TASK($ext_name);
 
                // Notify the admin
-               SEND_ADMIN_NOTIFICATION(ADMIN_SUBJECT_EXTENSION_DEACTIVATED, "admin_ext_deactivated", array('ext_name' => $ext_name));
+               SEND_ADMIN_NOTIFICATION(
+                       getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
+                       "admin_ext_deactivated",
+                       array('ext_name' => $ext_name)
+               );
        } // END - if
 }
 
@@ -648,14 +661,14 @@ function EXT_VERSION_IS_OLDER ($ext_name, $ext_ver) {
 // Creates a new task for updated extension
 function CREATE_EXTENSION_UPDATE_TASK ($admin_id, $ext_name, $ext_ver, $notes) {
        // Create subject line
-       $subject = "[UPDATE-".$ext_name."-".$ext_ver.":] {!ADMIN_UPDATE_EXT_SUBJ!}";
+       $subject = "[UPDATE-".$ext_name."-".$ext_ver.":] {--ADMIN_UPDATE_EXT_SUBJ--}";
 
        // Is the extension there?
        if (GET_EXT_VERSION($ext_name) != "") {
                // Check if task is not there
                if (DETERMINE_TASK_ID_BY_SUBJECT($subject) == 0) {
                        // Task not created so it's a brand-new extension which we need to register and create a task for!
-                       SQL_QUERY_ESC("INSERT INTO `{!MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created) VALUES ('%s','0','NEW','EXTENSION_UPDATE','%s','%s', UNIX_TIMESTAMP())",
+                       SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created) VALUES ('%s','0','NEW','EXTENSION_UPDATE','%s','%s', UNIX_TIMESTAMP())",
                                array($admin_id, $subject, $notes), __FILE__, __LINE__);
                } // END - if
        } // END - if
@@ -667,7 +680,7 @@ function CREATE_NEW_EXTENSION_TASK ($admin_id, $subject, $ext) {
        if ((DETERMINE_TASK_ID_BY_SUBJECT($subject) == 0) && (GET_EXT_VERSION($ext) == "")) {
                // Template file
                $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
-                       PATH,
+                       constant('PATH'),
                        GET_LANGUAGE(),
                        $ext
                );
@@ -682,12 +695,12 @@ function CREATE_NEW_EXTENSION_TASK ($admin_id, $subject, $ext) {
                }
 
                // Task not created so it's a brand-new extension which we need to register and create a task for!
-               SQL_QUERY_ESC("INSERT INTO `{!MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created)
+               SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created)
 VALUES (%s,0,'NEW','EXTENSION','%s','%s',UNIX_TIMESTAMP())",
                        array(
                                $admin_id,
                                $subject,
-                               addslashes($msg),
+                               SQL_ESCAPE($msg),
                        ),  __FILE__, __LINE__, true, false
                );
        } // END - if
@@ -696,16 +709,16 @@ VALUES (%s,0,'NEW','EXTENSION','%s','%s',UNIX_TIMESTAMP())",
 // Creates a task for automatically deactivated (deprecated) extension
 function CREATE_EXTENSION_DEACTIVATION_TASK ($ext) {
        // Create subject line
-       $subject = sprintf("[%s:] %s", $ext, TASK_SUBJ_EXTENSION_DEACTIVATED);
+       $subject = sprintf("[%s:] %s", $ext, getMessage('TASK_SUBJ_EXTENSION_DEACTIVATED'));
 
        // Not installed and do we have created a task for the admin?
        if ((DETERMINE_TASK_ID_BY_SUBJECT($subject) == 0) && (GET_EXT_VERSION($ext) != "")) {
                // Task not created so add it
-               SQL_QUERY_ESC("INSERT INTO `{!MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created)
+               SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (assigned_admin, userid, status, task_type, subject, text, task_created)
 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
@@ -734,7 +747,7 @@ function MODULE_HAS_MENU ($mod, $forceDb = false) {
                }
        } elseif ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && ((!EXT_IS_ACTIVE("cache")) || ($forceDb === true))) {
                // Check database for entry
-               $result = SQL_QUERY_ESC("SELECT has_menu FROM `{!MYSQL_PREFIX!}_mod_reg` WHERE module='%s' LIMIT 1",
+               $result = SQL_QUERY_ESC("SELECT has_menu FROM `{!_MYSQL_PREFIX!}_mod_reg` WHERE module='%s' LIMIT 1",
                        array($mod), __FILE__, __LINE__);
 
                // Entry found?
@@ -767,7 +780,7 @@ function DETERMINE_EXTENSION_TASK_ID ($ext_name) {
        $task_id = 0;
 
        // Search for extension task's id
-       $result = SQL_QUERY_ESC("SELECT id FROM `{!MYSQL_PREFIX!}_task_system` WHERE task_type='EXTENSION' AND subject='[%s:]' LIMIT 1",
+       $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_task_system` WHERE task_type='EXTENSION' AND subject='[%s:]' LIMIT 1",
                array($ext_name), __FILE__, __LINE__);
 
        // Entry found?
@@ -789,7 +802,7 @@ function DETERMINE_TASK_ID_BY_SUBJECT ($subject) {
        $task_id = 0;
 
        // Search for task id
-       $result = SQL_QUERY_ESC("SELECT id FROM `{!MYSQL_PREFIX!}_task_system` WHERE subject LIKE '%s%%' LIMIT 1",
+       $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_task_system` WHERE subject LIKE '%s%%' LIMIT 1",
                array($subject), __FILE__, __LINE__);
 
        // Entry found?
@@ -825,13 +838,13 @@ function ADD_EXTENSION_NOTES ($ver, &$UPDATE_NOTES) {
                        // Initial release
                        $content = array(
                                'ver'   => $ver,
-                               'notes' => INITIAL_RELEASE
+                               'notes' => getMessage('INITIAL_RELEASE')
                        );
                } else {
                        // No update notes found!
                        $content = array(
                                'ver'   => $ver,
-                               'notes' => NO_UPDATE_NOTES
+                               'notes' => getMessage('NO_UPDATE_NOTES')
                        );
                }