From b075fa29c59f970bea31bbe8be1bd6560a8778b6 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Wed, 19 Sep 2012 16:10:33 +1200 Subject: [PATCH] Have tiny_mce_gzip.php use local silverstripe-cache folder if available This is a fix for ticket #7670. Some hosting situations don't allow write access to the system temp path. tiny_mce_gzip.php is currently using sys_get_temp_dir() by default, and not using a local silverstripe-cache folder that may exist in the SilverStripe project. This change moves the getTempFolder() function into a common file, and includes that in core/Core.php, as well as thirdparty/tinymce/tiny_mce_gzip.php so both locations share the same code to work out the temp path. --- core/Core.php | 85 +++++++--------------------- core/TempPath.php | 46 +++++++++++++++ tests/core/CoreTest.php | 2 +- thirdparty/tinymce/tiny_mce_gzip.php | 7 ++- 4 files changed, 74 insertions(+), 66 deletions(-) create mode 100644 core/TempPath.php diff --git a/core/Core.php b/core/Core.php index e2ee89321..415604a57 100644 --- a/core/Core.php +++ b/core/Core.php @@ -176,11 +176,31 @@ define('THIRDPARTY_PATH', BASE_PATH . '/' . THIRDPARTY_DIR); define('ASSETS_DIR', 'assets'); define('ASSETS_PATH', BASE_PATH . '/' . ASSETS_DIR); +/////////////////////////////////////////////////////////////////////////////// +// INCLUDES + +if(defined('CUSTOM_INCLUDE_PATH')) { + $includePath = CUSTOM_INCLUDE_PATH . PATH_SEPARATOR + . FRAMEWORK_PATH . PATH_SEPARATOR + . FRAMEWORK_PATH . '/parsers' . PATH_SEPARATOR + . THIRDPARTY_PATH . PATH_SEPARATOR + . get_include_path(); +} else { + $includePath = FRAMEWORK_PATH . PATH_SEPARATOR + . FRAMEWORK_PATH . '/parsers' . PATH_SEPARATOR + . THIRDPARTY_PATH . PATH_SEPARATOR + . get_include_path(); +} + +set_include_path($includePath); + /** * Define the temporary folder if it wasn't defined yet */ +require_once 'core/TempPath.php'; + if(!defined('TEMP_FOLDER')) { - define('TEMP_FOLDER', getTempFolder()); + define('TEMP_FOLDER', getTempFolder(BASE_PATH)); } /** @@ -212,24 +232,6 @@ mb_regex_encoding('UTF-8'); */ gc_enable(); -/////////////////////////////////////////////////////////////////////////////// -// INCLUDES - -if(defined('CUSTOM_INCLUDE_PATH')) { - $includePath = CUSTOM_INCLUDE_PATH . PATH_SEPARATOR - . FRAMEWORK_PATH . PATH_SEPARATOR - . FRAMEWORK_PATH . '/parsers' . PATH_SEPARATOR - . THIRDPARTY_PATH . PATH_SEPARATOR - . get_include_path(); -} else { - $includePath = FRAMEWORK_PATH . PATH_SEPARATOR - . FRAMEWORK_PATH . '/parsers' . PATH_SEPARATOR - . THIRDPARTY_PATH . PATH_SEPARATOR - . get_include_path(); -} - -set_include_path($includePath); - // Include the files needed the initial manifest building, as well as any files // that are needed for the boostrap process on every request. require_once 'cache/Cache.php'; @@ -301,51 +303,6 @@ function getSysTempDir() { return sys_get_temp_dir(); } -/** - * Returns the temporary folder that silverstripe should use for its cache files - * This is loaded into the TEMP_FOLDER define on start up - * - * @param $base The base path to use as the basis for the temp folder name. Defaults to BASE_PATH, - * which is usually fine; however, the $base argument can be used to help test. - */ -function getTempFolder($base = null) { - if(!$base) $base = BASE_PATH; - $tempPath = ''; - $worked = true; - - // first, try finding a silverstripe-cache dir built off the base path - $tempPath = $base . '/silverstripe-cache'; - if(@file_exists($tempPath)) { - return $tempPath; - } - - // failing the above, try finding a namespaced silverstripe-cache dir in the system temp - $cacheFolder = '/silverstripe-cache' . str_replace(array(' ', '/', ':', '\\'), '-', $base); - $tempPath = sys_get_temp_dir() . $cacheFolder; - if(!@file_exists($tempPath)) { - $worked = @mkdir($tempPath); - } - - // failing to use the system path, attempt to create a local silverstripe-cache dir - if(!$worked) { - $worked = true; - $tempPath = $base . '/silverstripe-cache'; - if(!@file_exists($tempPath)) { - $worked = @mkdir($tempPath); - } - } - - if(!$worked) { - throw new Exception( - 'Permission problem gaining access to a temp folder. ' . - 'Please create a folder named silverstripe-cache in the base folder ' . - 'of the installation and ensure it has the correct permissions' - ); - } - - return $tempPath; -} - /** * @deprecated 3.0 Please use {@link SS_ClassManifest::getItemPath()}. */ diff --git a/core/TempPath.php b/core/TempPath.php new file mode 100644 index 000000000..13b48d324 --- /dev/null +++ b/core/TempPath.php @@ -0,0 +1,46 @@ +tempPath)) { - $this->assertEquals(getTempFolder(), $this->tempPath); + $this->assertEquals(getTempFolder(BASE_PATH), $this->tempPath); } else { // A typical Windows location for where sites are stored on IIS $this->assertEquals(getTempFolder('C:\\inetpub\\wwwroot\\silverstripe-test-project'), sys_get_temp_dir() . '/silverstripe-cacheC--inetpub-wwwroot-silverstripe-test-project'); diff --git a/thirdparty/tinymce/tiny_mce_gzip.php b/thirdparty/tinymce/tiny_mce_gzip.php index 21adf61ff..8c571689c 100755 --- a/thirdparty/tinymce/tiny_mce_gzip.php +++ b/thirdparty/tinymce/tiny_mce_gzip.php @@ -9,12 +9,17 @@ * Contributing: http://tinymce.moxiecode.com/contributing */ +$frameworkPath = rtrim(dirname(dirname(dirname(__FILE__))), DIRECTORY_SEPARATOR); +$basePath = rtrim(dirname($frameworkPath), DIRECTORY_SEPARATOR); + +require_once $frameworkPath . '/core/TempPath.php'; + // Handle incoming request if it's a script call if (TinyMCE_Compressor::getParam("js")) { // Default settings $tinyMCECompressor = new TinyMCE_Compressor(array( // CUSTOM SilverStripe - 'cache_dir' => sys_get_temp_dir() + 'cache_dir' => getTempFolder($basePath) // CUSTOM END ));