Example #1
0
/**
 * Added to detect the presence of Premium module and to allow the user to install them (i.e. enter their license
 * keys during the installation step).
 */
function ft_install_get_premium_modules()
{
    global $g_root_dir;
    $modules_folder = realpath(dirname(__FILE__) . "/../../modules");
    // loop through all modules in this folder and, if the module contains the appropriate files, add it to the database
    $module_info = array();
    $dh = opendir($modules_folder);
    // if we couldn't open the modules folder, it doesn't exist or something went wrong
    if (!$dh) {
        return array(false, $message);
    }
    $premium_modules = array();
    while (($folder = readdir($dh)) !== false) {
        if (is_dir("{$modules_folder}/{$folder}") && $folder != "." && $folder != "..") {
            $info = ft_get_module_info_file_contents($folder);
            if (empty($info)) {
                continue;
            }
            if ($info["is_premium"] == "no") {
                continue;
            }
            $lang_file = "{$modules_folder}/{$folder}/lang/{$info["origin_language"]}.php";
            $lang_info = _ft_get_module_lang_file_contents($lang_file);
            $info["module_name"] = isset($lang_info["module_name"]) ? $lang_info["module_name"] : "";
            $info["module_folder"] = $folder;
            $premium_modules[] = $info;
        }
    }
    return $premium_modules;
}
Example #2
0
/**
 * This function is called from the main Modules page. It upgrades an individual
 * module.
 */
function ft_upgrade_module($module_id)
{
    global $LANG, $g_root_url, $g_root_dir, $g_table_prefix;
    $module_info = ft_get_module($module_id);
    $module_folder = $module_info["module_folder"];
    $module_name = $module_info["module_name"];
    $old_module_version_date = $module_info["module_date"];
    $current_db_version = $module_info["version"];
    $info = ft_get_module_info_file_contents($module_folder);
    $new_version = $info["version"];
    if ($current_db_version == $new_version) {
        return array(false, "");
    }
    // if the module has its own upgrade function, call it. In Oct 2011, a BIG problem was identified
    // in the way modules were being updated. For backward compatibility, the new upgrade function
    // must be named [module folder]__update (not ...__upgrade). if the __update function is defined,
    // it will be called instead of the older __upgrade one.
    @(include_once "{$g_root_dir}/modules/{$module_folder}/library.php");
    // NEW "update" function
    $update_function_name = "{$module_folder}__update";
    if (function_exists($update_function_name)) {
        list($success, $message) = $update_function_name($module_info, $info);
        if (!$success) {
            return array($success, $message);
        }
    } else {
        // OLD "upgrade" function
        $upgrade_function_name = "{$module_folder}__upgrade";
        if (function_exists($upgrade_function_name)) {
            $upgrade_function_name($current_db_version, $new_version);
        }
    }
    // now, update the main module record
    $info = ft_sanitize($info);
    // we're assuming the module developer hasn't removed any of the required fields...
    // now check the language file contains the two required fields: module_name and module_description
    $lang_file = "{$g_root_dir}/modules/{$module_folder}/lang/{$info["origin_language"]}.php";
    $lang_info = _ft_get_module_lang_file_contents($lang_file);
    $lang_info = ft_sanitize($lang_info);
    // check the required language file fields
    if (!isset($lang_info["module_name"]) || empty($lang_info["module_name"]) || (!isset($lang_info["module_description"]) || empty($lang_info["module_description"]))) {
        return;
    }
    $author = $info["author"];
    $author_email = $info["author_email"];
    $author_link = $info["author_link"];
    $module_version = $info["version"];
    $module_date = $info["date"];
    $origin_language = $info["origin_language"];
    $nav = $info["nav"];
    $module_name = $lang_info["module_name"];
    $module_description = $lang_info["module_description"];
    // convert the date into a MySQL datetime
    list($year, $month, $day) = explode("-", $module_date);
    $timestamp = mktime(null, null, null, $month, $day, $year);
    $module_datetime = ft_get_current_datetime($timestamp);
    @mysql_query("\n    UPDATE {$g_table_prefix}modules\n    SET    origin_language = '{$origin_language}',\n           module_name = '{$module_name}',\n           version = '{$module_version}',\n           author = '{$author}',\n           author_email = '{$author_email}',\n           author_link = '{$author_link}',\n           description = '{$module_description}',\n           module_date = '{$module_datetime}'\n    WHERE  module_id = {$module_id}\n      ") or die(mysql_error());
    // remove and update the navigation links for this module
    @mysql_query("DELETE FROM {$g_table_prefix}module_menu_items WHERE module_id = {$module_id}");
    $order = 1;
    while (list($lang_file_key, $info) = each($nav)) {
        $url = $info[0];
        $is_submenu = $info[1] ? "yes" : "no";
        if (empty($lang_file_key) || empty($url)) {
            continue;
        }
        $display_text = isset($lang_info[$lang_file_key]) ? $lang_info[$lang_file_key] : $LANG[$lang_file_key];
        mysql_query("\n      INSERT INTO {$g_table_prefix}module_menu_items (module_id, display_text, url, is_submenu, list_order)\n      VALUES ({$module_id}, '{$display_text}', '{$url}', '{$is_submenu}', {$order})\n        ") or die(mysql_error());
        $order++;
    }
    // And we're done! inform the user that it's been upgraded
    $placeholders = array("module" => $module_name, "version" => $new_version, "link" => "{$g_root_url}/modules/{$module_folder}");
    $message = ft_eval_smarty_string($LANG["notify_module_updated"], $placeholders);
    return array(true, $message);
}