*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2015
- * $Id: $
- *
*/
/**
* The path name.
* @param bool $abort
* Should we abort or just return an invalid code.
- *
- * @return void
*/
public static function createDir($path, $abort = TRUE) {
if (is_dir($path) || empty($path)) {
* @param bool $verbose
*
* @throws Exception
- * @return void
*/
public static function cleanDir($target, $rmdir = TRUE, $verbose = TRUE) {
static $exceptions = array('.', '..');
*/
public static function addTrailingSlash($path, $slash = NULL) {
if (!$slash) {
- // FIXME: Defaulting to backslash on windows systems can produce unexpected results, esp for URL strings which should always use forward-slashes.
+ // FIXME: Defaulting to backslash on windows systems can produce
+ // unexpected results, esp for URL strings which should always use forward-slashes.
// I think this fn should default to forward-slash instead.
$slash = DIRECTORY_SEPARATOR;
}
$string = $prefix . $fileName;
}
- //get rid of comments starting with # and --
+ // get rid of comments starting with # and --
$string = preg_replace("/^#[^\n]*$/m", "\n", $string);
$string = preg_replace("/^(--[^-]).*/m", "\n", $string);
if (!$extensions) {
$extensions = CRM_Core_OptionGroup::values('safe_file_extension', TRUE);
- //make extensions to lowercase
+ // make extensions to lowercase
$extensions = array_change_key_case($extensions, CASE_LOWER);
// allow html/htm extension ONLY if the user is admin
// and/or has access CiviMail
unset($extensions['htm']);
}
}
- //support lower and uppercase file extensions
+ // support lower and uppercase file extensions
return isset($extensions[strtolower($ext)]) ? TRUE : FALSE;
}
}
/**
- * Remove the 32 bit md5 we add to the fileName
- * also remove the unknown tag if we added it
+ * Remove the 32 bit md5 we add to the fileName also remove the unknown tag if we added it.
+ *
+ * @param $name
+ *
+ * @return mixed
*/
public static function cleanFileName($name) {
// replace the last 33 character before the '.' with null
* Create the base file path from which all our internal directories are
* offset. This is derived from the template compile directory set
*/
- public static function baseFilePath($templateCompileDir = NULL) {
+ public static function baseFilePath() {
static $_path = NULL;
if (!$_path) {
- if ($templateCompileDir == NULL) {
- $config = CRM_Core_Config::singleton();
- $templateCompileDir = $config->templateCompileDir;
+ // Note: Don't rely on $config; that creates a dependency loop.
+ if (!defined('CIVICRM_TEMPLATE_COMPILEDIR')) {
+ throw new RuntimeException("Undefined constant: CIVICRM_TEMPLATE_COMPILEDIR");
}
+ $templateCompileDir = CIVICRM_TEMPLATE_COMPILEDIR;
$path = dirname($templateCompileDir);
/**
* Determine if a path is absolute.
*
+ * @param string $path
+ *
* @return bool
* TRUE if absolute. FALSE if relative.
*/
/**
* @param $directory
+ * @param string|NULL $basePath
+ * The base path when evaluating relative paths. Should include trailing slash.
*
* @return string
*/
- public static function absoluteDirectory($directory) {
+ public static function absoluteDirectory($directory, $basePath = NULL) {
// check if directory is already absolute, if so return immediately
// Note: Windows PHP accepts any mix of "/" or "\", so "C:\htdocs" or "C:/htdocs" would be a valid absolute path
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && preg_match(';^[a-zA-Z]:[/\\\\];', $directory)) {
}
// make everything absolute from the baseFilePath
- $basePath = self::baseFilePath();
+ $basePath = ($basePath === NULL) ? self::baseFilePath() : $basePath;
return $basePath . $directory;
}
/**
* Create a path to a temporary file which can endure for multiple requests.
*
- * TODO: Automatic file cleanup using, eg, TTL policy
+ * @todo Automatic file cleanup using, eg, TTL policy
*
* @param string $prefix
*
* @see tempnam
*/
public static function tempnam($prefix = 'tmp-') {
- //$config = CRM_Core_Config::singleton();
- //$nonce = md5(uniqid() . $config->dsn . $config->userFrameworkResourceURL);
- //$fileName = "{$config->configAndLogDir}" . $prefix . $nonce . $suffix;
+ // $config = CRM_Core_Config::singleton();
+ // $nonce = md5(uniqid() . $config->dsn . $config->userFrameworkResourceURL);
+ // $fileName = "{$config->configAndLogDir}" . $prefix . $nonce . $suffix;
$fileName = tempnam(sys_get_temp_dir(), $prefix);
return $fileName;
}
/**
* Create a path to a temporary directory which can endure for multiple requests.
*
- * TODO: Automatic file cleanup using, eg, TTL policy
+ * @todo Automatic file cleanup using, eg, TTL policy
*
* @param string $prefix
*
}
}
- // return rename($fromDir, $toDir); // CRM-11987, https://bugs.php.net/bug.php?id=54097
+ // return rename($fromDir, $toDir); CRM-11987, https://bugs.php.net/bug.php?id=54097
CRM_Utils_File::copyDir($fromDir, $toDir);
if (!CRM_Utils_File::cleanDir($fromDir, TRUE, FALSE)) {