/** * This explicitly empties and reloads any module's hook calls. * * @param array $module_ids */ function sc_reset_module_hook_calls($module_ids) { global $g_table_prefix, $L; $problems = false; foreach ($module_ids as $module_id) { if (!is_numeric($module_id)) { continue; } $module_info = ft_get_module($module_id); if (empty($module_info)) { continue; } $module_folder = $module_info["module_folder"]; $module_version = $module_info["version"]; $module_config = sc_get_module_config_file_contents($module_folder); $desired_hooks = isset($module_config["hooks"][$module_version]) ? $module_config["hooks"][$module_version] : $module_config["hooks"]; if (empty($desired_hooks)) { continue; } mysql_query("DELETE FROM {$g_table_prefix}hook_calls WHERE module_folder = '{$module_folder}'"); foreach ($desired_hooks as $hook_info) { $hook_type = $hook_info["hook_type"]; $action_location = $hook_info["action_location"]; $function_name = $hook_info["function_name"]; $hook_function = $hook_info["hook_function"]; $priority = $hook_info["priority"]; $query = mysql_query("\n \t INSERT INTO {$g_table_prefix}hook_calls (hook_type, action_location, module_folder, function_name, hook_function, priority)\n \t VALUES ('{$hook_type}', '{$action_location}', '{$module_folder}', '{$function_name}', '{$hook_function}', {$priority})\n \t"); if (!$query) { $problems = true; } } } if ($problems) { return array(true, $L["notify_problems_resetting_module_hooks"]); } else { return array(true, $L["notify_module_hooks_reset"]); } }
<?php require "../../global/session_start.php"; ft_check_permission("admin"); $request = array_merge($_POST, $_GET); $module_info = ft_get_module($request["module_id"]); // compile header information $page_vars = array(); $page_vars["page"] = "modules_about"; $page_vars["page_url"] = ft_get_page_url("modules_about"); $page_vars["head_title"] = "{$LANG["word_modules"]} - {$LANG["word_about"]}"; $page_vars["module_info"] = $module_info; ft_display_page("admin/modules/about.tpl", $page_vars);
/** * Loads a theme opening page for a module. This should be used loaded for every page in a * module. It serves the same function as ft_display_page, except that it sets the appropriate root * folder for the module and loads the * * @param array $page_vars a hash of information to display / provide to the template. * @param string $theme */ function ft_display_module_page($template, $page_vars = array(), $theme = "", $swatch = "") { global $g_root_dir, $g_root_url, $g_success, $g_message, $g_link, $g_smarty_debug, $g_language, $LANG, $g_smarty, $L, $g_smarty_use_sub_dirs, $g_js_debug, $g_benchmark_start, $g_enable_benchmarking, $g_hide_upgrade_link; $module_folder = _ft_get_current_module_folder(); // $module_id = ft_get_module_id_from_module_folder($module_folder); $default_module_language = "en_us"; if (empty($theme) && isset($_SESSION["ft"]["account"]["theme"])) { $theme = $_SESSION["ft"]["account"]["theme"]; $swatch = isset($_SESSION["ft"]["account"]["swatch"]) ? $_SESSION["ft"]["account"]["swatch"] : ""; } elseif (empty($theme)) { $settings = ft_get_settings(array("default_theme", "default_client_swatch")); $theme = $settings["default_theme"]; $swatch = $settings["default_client_swatch"]; } if (!isset($_SESSION["ft"]["account"]["is_logged_in"])) { $_SESSION["ft"]["account"]["is_logged_in"] = false; } if (!isset($_SESSION["ft"]["account"]["account_type"])) { $_SESSION["ft"]["account"]["account_type"] = ""; } // common variables. These are sent to EVERY template $g_smarty->template_dir = "{$g_root_dir}/themes/{$theme}"; $g_smarty->compile_dir = "{$g_root_dir}/themes/{$theme}/cache/"; $g_smarty->use_sub_dirs = $g_smarty_use_sub_dirs; $g_smarty->assign("LANG", $LANG); // this contains the custom language content of the module, in the language required. It's populated by // ft_init_module_page(), called on every module page $g_smarty->assign("L", $L); $g_smarty->assign("SESSION", $_SESSION["ft"]); $settings = isset($_SESSION["ft"]["settings"]) ? $_SESSION["ft"]["settings"] : array(); $g_smarty->assign("settings", $settings); $g_smarty->assign("account", $_SESSION["ft"]["account"]); $g_smarty->assign("g_root_dir", $g_root_dir); $g_smarty->assign("g_root_url", $g_root_url); $g_smarty->assign("g_js_debug", $g_js_debug ? "true" : "false"); $g_smarty->assign("g_hide_upgrade_link", $g_hide_upgrade_link); $g_smarty->assign("same_page", ft_get_clean_php_self()); $g_smarty->assign("query_string", $_SERVER["QUERY_STRING"]); // TODO FIX $g_smarty->assign("dir", $LANG["special_text_direction"]); $g_smarty->assign("g_enable_benchmarking", $g_enable_benchmarking); $g_smarty->assign("swatch", $swatch); // if this page has been told to dislay a custom message, override g_success and g_message if (isset($_GET["message"])) { list($g_success, $g_message) = ft_display_custom_page_message($_GET["message"]); } $g_smarty->assign("g_success", $g_success); $g_smarty->assign("g_message", $g_message); $module_id = ft_get_module_id_from_module_folder($module_folder); $module_nav = ft_get_module_menu_items($module_id, $module_folder); $g_smarty->assign("module_nav", $module_nav); // if there's no module title, display the module name. TODO not compatible with languages... if (!isset($page_vars["head_title"])) { $module_id = ft_get_module_id_from_module_folder($module_folder); $module_info = ft_get_module($module_id); $page_vars["head_title"] = $module_info["module_name"]; } // check the "required" vars are at least set so they don't produce warnings when smarty debug is enabled if (!isset($page_vars["head_css"])) { $page_vars["head_css"] = ""; } if (!isset($page_vars["head_js"])) { $page_vars["head_js"] = ""; } if (!isset($page_vars["page"])) { $page_vars["page"] = ""; } // if we need to include custom JS messages in the page, add it to the generated JS. Note: even if the js_messages // key is defined but still empty, the ft_generate_js_messages function is called, returning the "base" JS - like // the JS version of g_root_url. Only if it is not defined will that info not be included. This feature was hacked // in 2.1 to support js_messages from a single module file $js_messages = ""; if (isset($page_vars["js_messages"]) || isset($page_vars["module_js_messages"])) { $core_js_messages = isset($page_vars["js_messages"]) ? $page_vars["js_messages"] : ""; $module_js_messages = isset($page_vars["module_js_messages"]) ? $page_vars["module_js_messages"] : ""; $js_messages = ft_generate_js_messages($core_js_messages, $module_js_messages); } if (!empty($page_vars["head_js"]) || !empty($js_messages)) { $page_vars["head_js"] = "<script type=\"text/javascript\">\n//<![CDATA[\n{$page_vars["head_js"]}\n{$js_messages}\n//]]>\n</script>"; } if (!isset($page_vars["head_css"])) { $page_vars["head_css"] = ""; } else { if (!empty($page_vars["head_css"])) { $page_vars["head_css"] = "<style type=\"text/css\">\n{$page_vars["head_css"]}\n</style>"; } } // theme-specific vars $g_smarty->assign("images_url", "{$g_root_url}/themes/{$theme}/images"); $g_smarty->assign("theme_url", "{$g_root_url}/themes/{$theme}"); $g_smarty->assign("theme_dir", "{$g_root_dir}/themes/{$theme}"); // if there's a Smarty folder, import any of its resources if (is_dir("{$g_root_dir}/modules/{$module_folder}/smarty")) { $g_smarty->plugins_dir[] = "{$g_root_dir}/modules/{$module_folder}/smarty"; } // now add the custom variables for this template, as defined in $page_vars foreach ($page_vars as $key => $value) { $g_smarty->assign($key, $value); } // if smarty debug is on, enable Smarty debugging if ($g_smarty_debug) { $g_smarty->debugging = true; } extract(ft_process_hook_calls("main", compact("g_smarty", "template", "page_vars"), array("g_smarty")), EXTR_OVERWRITE); $g_smarty->display("{$g_root_dir}/modules/{$module_folder}/{$template}"); ft_db_disconnect($g_link); }
<?php require "../../global/library.php"; ft_init_module_page(); require_once "library.php"; $request = array_merge($_POST, $_GET); if (isset($request["update"])) { list($g_success, $g_message) = exp_update_settings($request); } $module_settings = ft_get_module_settings(); $module_id = ft_get_module_id_from_module_folder("export_manager"); $module_info = ft_get_module($module_id); // ------------------------------------------------------------------------------------------------ $page_vars = array(); $page_vars["head_title"] = "{$L["module_name"]} - {$LANG["word_settings"]}"; $page_vars["module_settings"] = $module_settings; $page_vars["module_version"] = $module_info["version"]; $page_vars["allow_url_fopen"] = ini_get("allow_url_fopen") == "1"; ft_display_module_page("templates/settings.tpl", $page_vars);
/** * This was added to solve the problem of being able to construct a valid URL for the login * function, to redirect to whatever custom login page the admin/client has selected. The * page identifier is stored in the login_page field (rename to login_page_identifier?). * * There seems to be some cross-over between this function and ft_get_page_url. Think about! * * @param string $page_identifier special strings that have meaning to Form Tools, used to identify * pages within its interface. See the top of /global/code/menus.php for a list. * @param string $custom_options again used by Form Tools * @param array $args an arbitrary hash of key-value pairs to be passed in the query string */ function ft_construct_page_url($page_identifier, $custom_options = "", $args = array()) { global $g_pages; $url = ""; extract(ft_process_hook_calls("start", compact("url", "page_identifier", "custom_options", "args"), array("url")), EXTR_OVERWRITE); if (!empty($url)) { return $url; } switch ($page_identifier) { case "custom_url": $url = $custom_options; break; case "client_form_submissions": case "form_submissions": case "edit_form": case "edit_form_main": case "edit_form_fields": case "edit_form_views": case "edit_form_emails": $joiner = strpos($g_pages[$page_identifier], "?") ? "&" : "?"; $url = $g_pages[$page_identifier] . $joiner . "form_id=" . $custom_options; break; case "edit_client": case "edit_client_main": case "edit_client_permissions": $joiner = strpos($g_pages[$page_identifier], "?") ? "&" : "?"; $url = $g_pages[$page_identifier] . $joiner . "client_id=" . $custom_options; break; default: // modules if (preg_match("/^module_(\\d+)/", $page_identifier, $matches)) { $module_id = $matches[1]; $module_info = ft_get_module($module_id); if (!empty($module_info)) { $module_folder = $module_info["module_folder"]; $url = "/modules/{$module_folder}/"; } } else { if (preg_match("/^page_(\\d+)/", $page_identifier, $matches)) { $page_id = $matches[1]; $url = "/modules/pages/page.php?id={$page_id}"; } else { $url = $g_pages[$page_identifier]; } } break; } if (!empty($args)) { $params = array(); while (list($key, $value) = each($args)) { $params[] = "{$key}={$value}"; } if (strpos("?", $url) === false) { $url .= "?" . implode("&", $params); } else { $url .= "&" . implode("&", $params); } } return $url; }
/** * 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); }