summaryrefslogtreecommitdiffstats
path: root/lib/helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/helper.php')
-rw-r--r--lib/helper.php68
1 files changed, 40 insertions, 28 deletions
diff --git a/lib/helper.php b/lib/helper.php
index 73484ad913f..225e9fd2a9a 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -27,6 +27,7 @@
class OC_Helper {
private static $mimetypes=array();
private static $tmpFiles=array();
+ private static $mimetypeIcons = array();
/**
* @brief Creates an url using a defined route
@@ -159,7 +160,7 @@ class OC_Helper {
*/
public static function imagePath( $app, $image ) {
// Read the selected theme from the config file
- $theme=OC_Config::getValue( "theme" );
+ $theme = OC_Util::getTheme();
// Check if the app is in the app folder
if( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/img/$image" )) {
@@ -187,31 +188,38 @@ class OC_Helper {
*
* Returns the path to the image of this file type.
*/
- public static function mimetypeIcon( $mimetype ) {
- $alias=array('application/xml'=>'code/xml');
- if(isset($alias[$mimetype])) {
- $mimetype=$alias[$mimetype];
+ public static function mimetypeIcon($mimetype) {
+ $alias = array('application/xml' => 'code/xml');
+ if (isset($alias[$mimetype])) {
+ $mimetype = $alias[$mimetype];
+ }
+ if (isset(self::$mimetypeIcons[$mimetype])) {
+ return self::$mimetypeIcons[$mimetype];
}
// Replace slash and backslash with a minus
- $mimetype = str_replace( "/", "-", $mimetype );
- $mimetype = str_replace( "\\", "-", $mimetype );
+ $icon = str_replace('/', '-', $mimetype);
+ $icon = str_replace( '\\', '-', $icon);
// Is it a dir?
- if( $mimetype == "dir" ) {
- return OC::$WEBROOT."/core/img/filetypes/folder.png";
+ if ($mimetype === 'dir') {
+ self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/folder.png';
+ return OC::$WEBROOT.'/core/img/filetypes/folder.png';
}
// Icon exists?
- if( file_exists( OC::$SERVERROOT."/core/img/filetypes/$mimetype.png" )) {
- return OC::$WEBROOT."/core/img/filetypes/$mimetype.png";
- }
- //try only the first part of the filetype
- $mimetype=substr($mimetype, 0, strpos($mimetype, '-'));
- if( file_exists( OC::$SERVERROOT."/core/img/filetypes/$mimetype.png" )) {
- return OC::$WEBROOT."/core/img/filetypes/$mimetype.png";
+ if (file_exists(OC::$SERVERROOT.'/core/img/filetypes/'.$icon.'.png')) {
+ self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/'.$icon.'.png';
+ return OC::$WEBROOT.'/core/img/filetypes/'.$icon.'.png';
}
- else{
- return OC::$WEBROOT."/core/img/filetypes/file.png";
+
+ // Try only the first part of the filetype
+ $mimePart = substr($icon, 0, strpos($icon, '-'));
+ if (file_exists(OC::$SERVERROOT.'/core/img/filetypes/'.$mimePart.'.png')) {
+ self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/'.$mimePart.'.png';
+ return OC::$WEBROOT.'/core/img/filetypes/'.$mimePart.'.png';
+ } else {
+ self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/file.png';
+ return OC::$WEBROOT.'/core/img/filetypes/file.png';
}
}
@@ -541,13 +549,15 @@ class OC_Helper {
}
/**
- * create a temporary file with an unique filename. It will not be deleted
- * automatically
- * @param string $postfix
- * @return string
+ * move a file to oc-noclean temp dir
+ * @param string $filename
+ * @return mixed
*
*/
- public static function tmpFileNoClean($postfix='') {
+ public static function moveToNoClean($filename='') {
+ if ($filename == '') {
+ return false;
+ }
$tmpDirNoClean=get_temp_dir().'/oc-noclean/';
if (!file_exists($tmpDirNoClean) || !is_dir($tmpDirNoClean)) {
if (file_exists($tmpDirNoClean)) {
@@ -555,10 +565,12 @@ class OC_Helper {
}
mkdir($tmpDirNoClean);
}
- $file=$tmpDirNoClean.md5(time().rand()).$postfix;
- $fh=fopen($file, 'w');
- fclose($fh);
- return $file;
+ $newname=$tmpDirNoClean.basename($filename);
+ if (rename($filename, $newname)) {
+ return $newname;
+ } else {
+ return false;
+ }
}
/**
@@ -597,7 +609,7 @@ class OC_Helper {
}
/**
- * remove all files created by self::tmpFileNoClean
+ * remove all files in PHP /oc-noclean temp dir
*/
public static function cleanTmpNoClean() {
$tmpDirNoCleanFile=get_temp_dir().'/oc-noclean/';