- } elseif ($task_found == "0") {
- // No longer assigned or old task
- LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_REG_FAILED_ASSIGED);
- } else {
- // ID is invalid
- LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_REG_FAILED_INVALID);
- }
- break;
-
-case "search": // Search for new extensions on our server
- // Get response from our server
- $response = GET_URL("extensions.php");
-
- // Are extensions found?
- if (($response[sizeof($response) - 1] == "[EOF]") && ($response[0] != "[EOF]"))
- {
- // Ok, mark found and create the array
- $EXT_SEARCH = array(
- 'fname' => array(), // File names
- 'fsize' => array(), // File size
- 'fctime' => array(), // File creation timestamp
- 'infos' => array(), // File informations (maybe loaded!)
- 'ver' => array(), // Version number
- 'cver' => array(), // Current version number
- );
-
- // Get count of extensions for validation
- $count = trim($response[sizeof($response) - 2]);
- foreach ($response as $id=>$value)
- {
- $value = str_replace("\n", "", $value); $ver = "";
- // Leave loop when data is invalid or EOF?
- if ((substr($value, 0, 4) == "ext-") && (substr($value, -4) == ".zip"))
- {
- $name = substr($value, 4, -4);
- $file = sprintf("%sinc/extensions/ext-%s.php", PATH, $name);
- $ver = trim(substr($response[$id + 3], 4));
-
- // Load current extension's version
- $cver = GET_EXT_VERSION($name);
- if (empty($cver)) $cver = "-.-";
-
- // Is the extension already installed or not?
- if (!file_exists($file) || ($ver != $cver))
- {
- // No, it isn't. So let's add this one!
- $EXT_SEARCH['fname'][] = $name;
- $EXT_SEARCH['fsize'][] = $response[$id + 1];
- $EXT_SEARCH['fctime'][] = $response[$id + 2];
- $EXT_SEARCH['ver'][] = $ver;
- $EXT_SEARCH['cver'][] = $cver;
-
- $LANG_DUMMY = explode("[nl]", $response[$id + 4]);
- $LANG = array();
- $INFO = ADMIN_EXT_NO_INFO_FOUND;
-
- // Trim every data line
- foreach ($LANG_DUMMY as $k=>$v)
- {
- $v = trim($v);
- if (substr($v, 3) == "") $v = "---";
- $LANG_DUMMY[$k] = $v;
- if ($v == "xx:xx") break;
- $LANG[] = $v;
- }
-
- // If language is found stop searching on matching line
- foreach($LANG as $search)
- {
- if (substr($search, 0, 3) == (GET_LANGUAGE().":")) { $INFO = substr($search, 3); break; }
+ break;
+
+ case 'register': // Register new extension
+ // Do we have some tasks?
+ $numTasks = countSumTotalData(getCurrentAdminId(), 'task_system', 'id', 'assigned_admin', true, "AND `task_type`='EXTENSION'");
+
+ // Is the id number valid and the task was found?
+ if (($taskId > 0) && ($numTasks > 0)) {
+ // id is valid so begin with registration, we first want to it's real name from task management (subject column)
+ $result = SQL_QUERY_ESC("SELECT `subject` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
+ array(bigintval($taskId)), __FILE__, __LINE__);
+ list($subject) = SQL_FETCHROW($result);
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Disable cache update by default
+ $cache_update = '0';
+ if (!empty($subject)) {
+ // Extract extension's name from subject...
+ $ext_name = trim(substr($subject, 1, strpos($subject, ':') - 1));
+
+ // Test the extension for deprecation
+ loadExtension($ext_name, 'test');
+
+ // Is the extension deprecated?
+ if (!isExtensionDeprecated()) {
+ // ... so we can finally register and load it in registration mode
+ if (registerExtension($ext_name, $taskId)) {
+ // Errors?
+ if (!ifFatalErrorsDetected()) {
+ // Extension was found and successfully registered
+ redirectToUrl('modules.php?module=admin&what=extensions&registered=' . getExtensionId($ext_name));
+ } else {
+ // Errors detected!
+ displayMessage(getMaskedMessage('ADMIN_EXTENSION_NOT_REGISTERED', $ext_name));
+ }
+
+ // Do we need to update cache file?
+ // @TODO Rewrite this to a filter
+ if (isExtensionActive('cache')) {
+ // Remove cache file (will be auto-created again!)
+ if ($GLOBALS['cache_instance']->loadCacheFile('config')) $GLOBALS['cache_instance']->removeCacheFile();
+ if ($GLOBALS['cache_instance']->loadCacheFile('extension')) $GLOBALS['cache_instance']->removeCacheFile();
+ if ($GLOBALS['cache_instance']->loadCacheFile('filter')) $GLOBALS['cache_instance']->removeCacheFile();
+ if ($GLOBALS['cache_instance']->loadCacheFile('modules')) $GLOBALS['cache_instance']->removeCacheFile();
+ } // END - if
+ } elseif (isExtensionInstalled($ext_name)) {
+ // Notify the admin that we have a problem here...
+ displayMessage('{--ADMIN_EXTENSION_REGISTRATION_FAILED_ALREADY--}');
+ } else {
+ // Notify the admin that we have a problem here...
+ displayMessage(getMaskedMessage('ADMIN_EXTENSION_REGISTRATION_FAILED_404', $ext_name));