/** * 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); }
/** * Sets one or more module settings. This basically acts as a wrapper function for ft_set_settings, * which ensures that the module field is set appropriately. * * @param array $setting_name a hash of "setting_name" => "setting_value" */ function ft_set_module_settings($settings) { $module_folder = _ft_get_current_module_folder(); ft_set_settings($settings, $module_folder); }