/** * 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); }
/** * Used to render the HTML for the install pages. * * @param string $template * @param array $page_vars */ function ft_install_display_page($template, $page_vars) { global $LANG, $g_smarty, $g_success, $g_message, $g_ft_installation_folder, $g_current_version, $g_release_type, $g_release_date; clearstatcache(); $theme_folder = realpath("{$g_ft_installation_folder}/../themes/default/"); $cache_folder = "{$theme_folder}/cache/"; // always try to set the cache folder to 777 @chmod($cache_folder, 0777); $version_string = $g_current_version; if ($g_release_type == "alpha") { $version_string .= "-alpha-{$g_release_date}"; } else { if ($g_release_type == "beta") { $version_string .= "-beta-{$g_release_date}"; } } // run a preliminary permissions check on the default theme's cache folder if (!is_readable("{$cache_folder}/") || !is_writable("{$cache_folder}/")) { echo <<<EOF <html> <head> <link rel="stylesheet" type="text/css" href="files/main.css"> </head> <body> <div id="container"> <div id="header"> <div style="float:right"> <table cellspacing="0" cellpadding="0" height="25"> <tr> <td><img src="images/account_section_left.jpg" border="0" /></td> <td id="account_section"> <b>{$version_string}</b> </td> <td><img src="images/account_section_right.jpg" border="0" /></td> </tr> </table> </div> <span style="float:left; padding-top: 8px; padding-right: 10px"> <a href="http://www.formtools.org" class="no_border"><img src="../themes/default/images/logo_green.jpg" border="0" height="61" /></a> </span> </div> <div id="content"> <div class="notify"> {$LANG["text_default_theme_cache_folder_not_writable"]} </div> </div> </div> </body> </html> EOF; exit; } $g_smarty = new Smarty(); $g_smarty->template_dir = $theme_folder; $g_smarty->compile_dir = $cache_folder; $g_smarty->use_sub_dirs = false; $g_smarty->assign("LANG", $LANG); $g_smarty->assign("SESSION", $_SESSION["ft_install"]); $g_smarty->assign("same_page", $_SERVER["PHP_SELF"]); $g_smarty->assign("dir", $LANG["special_text_direction"]); $g_smarty->assign("g_success", $g_success); $g_smarty->assign("g_message", $g_message); $g_smarty->assign("g_default_theme", "default"); $g_smarty->assign("version_string", $version_string); // check the "required" vars are at least set so they don't produce warnings when smarty debug is enabled if (!isset($page_vars["head_string"])) { $page_vars["head_string"] = ""; } if (!isset($page_vars["head_title"])) { $page_vars["head_title"] = ""; } 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. $js_messages = isset($page_vars["js_messages"]) ? ft_generate_js_messages($page_vars["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>"; } } // now add the custom variables for this template, as defined in $page_vars foreach ($page_vars as $key => $value) { $g_smarty->assign($key, $value); } $g_smarty->display("{$g_ft_installation_folder}/{$template}"); }