|
From: Jon O. <jon...@us...> - 2008-03-11 21:05:41
|
Update of /cvsroot/mxbb/core/includes In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv32144 Modified Files: mx_functions_style.php Log Message: Reduced code with a help method for doing all ifs in make_filename() Index: mx_functions_style.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_functions_style.php,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** mx_functions_style.php 11 Mar 2008 19:57:47 -0000 1.64 --- mx_functions_style.php 11 Mar 2008 21:05:36 -0000 1.65 *************** *** 195,198 **** --- 195,199 ---- // $filename2 = substr_count($filename, 'html') ? str_replace(".html", ".tpl", $filename) : str_replace(".tpl", ".html", $filename); + // // Look at MX-Publisher-Module folder.........................................................................MX-Publisher-module *************** *** 203,274 **** $moduleDefault = !empty($mx_user->loaded_default_styles[$mx_block->module_root_path]) ? $mx_user->loaded_default_styles[$mx_block->module_root_path] : $mx_user->default_template_name; ! if( file_exists($module_root_path . 'templates/' . $style_path . '/' . $filename) ) ! { ! // ! // First check current template ! // ! $filename = $module_root_path . 'templates/' . $style_path . '/' . $filename; ! $this->module_template_path = 'templates/' . $style_path . '/'; ! } ! else if( file_exists($module_root_path . 'templates/' . $style_path . '/' . $filename2) ) ! { ! // ! // tpl - html ! // ! $filename = $module_root_path . 'templates/' . $style_path . '/' . $filename2; ! $this->module_template_path = 'templates/' . $style_path . '/'; ! } ! else if( file_exists($module_root_path . 'templates/' . $mx_user->cloned_template_name . '/' . $filename) && !empty($mx_user->cloned_template_name)) ! { ! // ! // Then check Cloned template ! // ! $filename = $module_root_path . 'templates/' . $mx_user->cloned_template_name . '/' . $filename; ! $this->module_template_path = 'templates/' . $mx_user->cloned_template_name . '/'; ! } ! else if( file_exists($module_root_path . 'templates/' . $mx_user->cloned_template_name . '/' . $filename2) && !empty($mx_user->cloned_template_name)) ! { ! // ! // tpl - html ! // ! $filename = $module_root_path . 'templates/' . $mx_user->cloned_template_name . '/' . $filename2; ! $this->module_template_path = 'templates/' . $mx_user->cloned_template_name . '/'; ! } ! else if( file_exists($module_root_path . 'templates/' . $moduleDefault . '/' . $filename) ) ! { ! // ! // Then check default template ! // ! $filename = $module_root_path . 'templates/' . $moduleDefault . '/' . $filename; ! $this->module_template_path = 'templates/' . $moduleDefault . '/'; ! } ! else if( file_exists($module_root_path . 'templates/' . $moduleDefault . '/' . $filename2) ) ! { ! // ! // tpl - html ! // ! $filename = $module_root_path . 'templates/' . $moduleDefault . '/' . $filename2; ! $this->module_template_path = 'templates/' . $moduleDefault . '/'; ! } ! else if( file_exists($module_root_path . 'templates/' . $filename) ) ! { ! // ! // Finally check the template root (for compatibility with some old modules) ! // ! $filename = $module_root_path . 'templates/' . $filename; ! $this->module_template_path = 'templates/'; ! } ! else if( file_exists($module_root_path . 'templates/' . $filename2) ) ! { ! // ! // tpl - html ! // ! $filename = $module_root_path . 'templates/' . $filename2; ! $this->module_template_path = 'templates/'; ! } if (!empty($this->module_template_path)) { ! return $filename; } } --- 204,217 ---- $moduleDefault = !empty($mx_user->loaded_default_styles[$mx_block->module_root_path]) ? $mx_user->loaded_default_styles[$mx_block->module_root_path] : $mx_user->default_template_name; ! $fileSearch = array(); ! $fileSearch[] = $style_path; // First check current template ! $fileSearch[] = $mx_user->cloned_template_name; // Then check Cloned template ! $fileSearch[] = $moduleDefault; // Finally check Default template ! $fileSearch[] = './'; // Compatibility with primitive modules + $temppath = $this->doFileSearch($fileSearch, $filename, $filename2, 'templates/', $module_root_path); if (!empty($this->module_template_path)) { ! return $temppath; } } *************** *** 277,458 **** // Look at MX-Publisher-Root folder.........................................................................MX-Publisher-Root // ! if( file_exists($mx_root_path . 'templates/' . $style_path . '/' . $filename) ) ! { ! // ! // First check current template ! // ! $filename = $mx_root_path . 'templates/' . $style_path . '/' . $filename; ! } ! else if( file_exists($mx_root_path . 'templates/' . $style_path . '/' . $filename2) ) ! { ! // ! // tpl - html ! // ! $filename = $mx_root_path . 'templates/' . $style_path . '/' . $filename2; ! } ! else if( file_exists($mx_root_path . 'templates/' . $mx_user->cloned_template_name . '/' . $filename) && !empty($mx_user->cloned_template_name)) ! { ! // ! // Then check Cloned template ! // ! $filename = $mx_root_path . 'templates/' . $mx_user->cloned_template_name . '/' . $filename; ! } ! else if( file_exists($mx_root_path . 'templates/' . $mx_user->cloned_template_name . '/' . $filename2) && !empty($mx_user->cloned_template_name)) ! { ! // ! // tpl - html ! // ! $filename = $mx_root_path . 'templates/' . $mx_user->cloned_template_name . '/' . $filename2; ! } ! else if( file_exists($mx_root_path . 'templates/' . $mx_user->default_template_name . '/' . $filename) ) ! { ! // ! // Then check Default template ! // ! $filename = $mx_root_path . 'templates/' . $mx_user->default_template_name . '/' . $filename; ! } ! else if( file_exists($mx_root_path . 'templates/' . $mx_user->default_template_name . '/' . $filename2) ) { ! // ! // tpl - html ! // ! $filename = $mx_root_path . 'templates/' . $mx_user->default_template_name . '/' . $filename2; } // // Look at Custom Root folder..............this is used my mx_mod installers too.......this does not use standard templates folders wich are set when the template was re-initialized and defined as custom var // ! else if( file_exists( $this->root . '/' . $filename) ) ! { ! $filename = $this->root . '/' . $filename; ! } ! else if( file_exists($this->root . '/' . $style_path . '/' . $filename) ) ! { ! // ! // First check current template ! // ! $filename = $this->root . '/' . $style_path . '/' . $filename; ! } ! else if( file_exists($this->root . '/' . $style_path . '/' . $filename2) ) ! { ! // ! // tpl - html ! // ! $filename = $this->root. '/' . $style_path . '/' . $filename2; ! } ! else if( file_exists($this->root . '/' . $mx_user->default_template_name . '/' . $filename) ) { ! // ! // Then check current template ! // ! $filename = $mx_root_path . '/' . $mx_user->default_template_name . '/' . $filename; } ! else if( file_exists($this->root . '/' . $moduleDefault . '/' . $filename) ) { // ! // Finally check the Custom Root folde(for compatibility with some old modules) // ! $filename = $this->root . '/' . $moduleDefault . '/' . $filename; ! } ! else ! { // ! // phpBB.........................................................................phpBB // ! switch (PORTAL_BACKEND) ! { ! // ! // Look at phpBB2-Root folder... ! // ! case 'internal': ! case 'phpbb2': ! if( file_exists($phpbb_root_path . 'templates/' . $style_path . '/' . $filename) ) ! { ! // ! // First check current template ! // ! $filename = $phpbb_root_path . 'templates/' . $style_path . '/' . $filename; ! } ! else if( file_exists($phpbb_root_path . 'templates/' . $mx_user->cloned_template_name . '/' . $filename) && !empty($mx_user->cloned_template_name)) ! { ! // ! // Then check Cloned ! // ! $filename = $phpbb_root_path . 'templates/' . $mx_user->cloned_template_name . '/' . $filename; ! } ! else if( file_exists($phpbb_root_path . 'templates/' . $mx_user->default_template_name . '/' . $filename) && !empty($mx_user->default_template_name)) ! { ! // ! // Then check Default ! // ! $filename = $phpbb_root_path . 'templates/' . $mx_user->default_template_name . '/' . $filename; ! } ! else if( file_exists($phpbb_root_path . $this->root . '/' . $filename) ) ! { ! $filename = $phpbb_root_path . $this->root . '/' . $filename; ! } ! else if( file_exists($this->root . '/' . $filename) ) ! { ! // ! // Check if it's an absolute or relative path. ! // ! if( substr($filename, 0, 1) != '/' ) ! { ! $filename = ($rp_filename = phpBB2::phpbb_realpath($this->root . '/' . $filename)) ? $rp_filename : $filename; ! } ! } ! break; // ! // Look at phpBB3-Root folder... // ! case 'phpbb3': ! if( file_exists($phpbb_root_path . 'styles/' . $style_path . '/' . 'theme/' . $filename) ) ! { ! // ! // First check current template ! // ! $filename = $phpbb_root_path . 'styles/' . $style_path . '/' . 'theme/' . $filename; ! } ! else if( file_exists($phpbb_root_path . 'styles/' . $mx_user->cloned_template_name . '/' . 'theme/' . $filename) && !empty($mx_user->cloned_template_name)) ! { ! // ! // Then check Cloned Template ! // ! $filename = $phpbb_root_path . 'styles/' . $mx_user->cloned_template_name . '/' . 'theme/' . $filename; ! } ! else if( file_exists($phpbb_root_path . $this->root . '/' . $filename) ) ! { ! $filename = $phpbb_root_path . $this->root . '/' . $filename; ! } ! if( file_exists($phpbb_root_path . 'adm/style/' . $filename) ) ! { ! // ! // First check ACP template ! // ! $filename = $phpbb_root_path . 'adm/style/' . $filename; ! } ! else if( file_exists($this->root . '/' . $filename) ) { ! // ! // Check if it's an absolute or relative path. ! // ! if( substr($filename, 0, 1) != '/' ) ! { ! $filename = ($rp_filename = phpBB2::phpbb_realpath($this->root . '/' . $filename)) ? $rp_filename : $filename; ! } } ! ! break; } ! ! if( !file_exists($filename) ) { ! die("Template->make_filename(): Error - file $filename does not exist. <br />Class-Root: $this->root <br />Module: $module_root_path <br />Current style: $style_path <br />Cloned style: $mx_user->cloned_template_name <br />Default style: $mx_user->default_template_name <br />Custom module default style: $moduleDefault"); } } - - return $filename; } --- 220,361 ---- // Look at MX-Publisher-Root folder.........................................................................MX-Publisher-Root // ! $fileSearch = array(); ! $fileSearch[] = $style_path; // First check current template ! $fileSearch[] = $mx_user->cloned_template_name; // Then check Cloned template ! $fileSearch[] = $mx_user->default_template_name; // Then check Default template ! $fileSearch[] = './'; ! ! $temppath = $this->doFileSearch($fileSearch, $filename, $filename2, 'templates/'); ! if (!empty($this->module_template_path)) { ! return $temppath; } + // // Look at Custom Root folder..............this is used my mx_mod installers too.......this does not use standard templates folders wich are set when the template was re-initialized and defined as custom var // ! $fileSearch = array(); ! $fileSearch[] = './'; ! $fileSearch[] = $style_path; // First check current template ! $fileSearch[] = $mx_user->cloned_template_name; // Then check Cloned template ! $fileSearch[] = $mx_user->default_template_name; // Then check Default template ! ! $temppath = $this->doFileSearch($fileSearch, $filename, $filename2, $this->root); ! if (!empty($this->module_template_path)) { ! return $temppath; } ! ! ! // ! // phpBB.........................................................................phpBB ! // ! switch (PORTAL_BACKEND) { // ! // Look at phpBB2-Root folder... // ! case 'internal': ! case 'phpbb2': ! ! $fileSearch = array(); ! $fileSearch[] = $style_path; // First check current template ! $fileSearch[] = $mx_user->cloned_template_name; // Then check Cloned template ! $fileSearch[] = $mx_user->default_template_name; // Then check Default template ! $fileSearch[] = './'; ! ! $temppath = $this->doFileSearch($fileSearch, $filename, $filename2, 'templates/', $phpbb_root_path, false); ! if (!empty($this->module_template_path)) ! { ! return $temppath; ! } ! ! break; // ! // Look at phpBB3-Root folder... // ! case 'phpbb3': ! $fileSearch = array(); ! $fileSearch[] = $style_path . '/' . 'theme'; // First check current template ! $fileSearch[] = $mx_user->cloned_template_name . '/' . 'theme'; // Then check Cloned template ! $fileSearch[] = $mx_user->default_template_name . '/' . 'theme'; // Then check Default template ! $fileSearch[] = './'; ! $temppath = $this->doFileSearch($fileSearch, $filename, $filename2, 'styles/', $phpbb_root_path, false); ! if (!empty($this->module_template_path)) ! { ! return $temppath; ! } // ! // This doesn't fit in...so left as is. // ! if( file_exists($phpbb_root_path . 'adm/style/' . $filename) ) ! { ! // ! // First check ACP template ! // ! $this->module_template_path = $phpbb_root_path . 'adm/style/'; ! $temppath = $phpbb_root_path . 'adm/style/' . $filename; ! } ! ! if (!empty($this->module_template_path)) ! { ! return $temppath; ! } ! ! break; ! } ! ! die("Template->make_filename(): Error - file $filename does not exist. <br />Class-Root: $this->root <br />Module: $module_root_path <br />Current style: $style_path <br />Cloned style: $mx_user->cloned_template_name <br />Default style: $mx_user->default_template_name <br />Custom module default style: $moduleDefault"); ! } ! ! /** ! * Help function ! * ! * @param unknown_type $fileSearch ! * @param unknown_type $filename ! * @param unknown_type $filename2 ! * @param unknown_type $module_root_path ! * @return unknown ! */ ! function doFileSearch($fileSearch, $filename, $filename2, $root, $module_root_path = '', $check_file2 = true) ! { ! foreach ($fileSearch as $key => $path) ! { ! if (!empty($path)) ! { ! if( file_exists($module_root_path . $root . $path . '/' . $filename) ) ! { ! $this->module_template_path = $root . $path . '/'; ! return $module_root_path . $root . $path . '/' . $filename; ! } ! if ($check_file2) ! { ! if( file_exists($module_root_path . $root . $path . '/' . $filename2) ) { ! $this->module_template_path = $root . $path . '/'; ! return $module_root_path . $root . $path . '/' . $filename2; } ! } } ! else if ($path == './') { ! if( file_exists($module_root_path . $root . $filename) ) ! { ! $this->module_template_path = $root; ! return $module_root_path . $root . $filename; ! } ! if ($check_file2) ! { ! if( file_exists($module_root_path . $root . $filename2) ) ! { ! $this->module_template_path = $root; ! return $module_root_path . $root . $filename2; ! } ! } } } } |