Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
48f0c542
Commit
48f0c542
authored
Aug 19, 2013
by
Georg Ehrke
Browse files
style fixes for preview lib
parent
f2702ff1
Changes
8
Hide whitespace changes
Inline
Side-by-side
apps/files/templates/part.list.php
View file @
48f0c542
...
...
@@ -3,7 +3,8 @@
$totaldirs
=
0
;
$totalsize
=
0
;
?>
<?php
foreach
(
$_
[
'files'
]
as
$file
)
:
$relativePath
=
substr
(
$file
[
'path'
],
6
);
//strlen('files/') => 6
//strlen('files/') => 6
$relativePath
=
substr
(
$file
[
'path'
],
6
);
$totalsize
+=
$file
[
'size'
];
if
(
$file
[
'type'
]
===
'dir'
)
{
$totaldirs
++
;
...
...
config/config.sample.php
View file @
48f0c542
...
...
@@ -199,6 +199,8 @@ $CONFIG = array(
'preview_max_scale_factor'
=>
10
,
/* custom path for libreoffice / openoffice binary */
'preview_libreoffice_path'
=>
'/usr/bin/libreoffice'
,
/* cl parameters for libreoffice / openoffice */
'preview_office_cl_parameters'
=>
''
,
// date format to be used while writing to the owncloud logfile
'logdateformat'
=>
'F d, Y H:i:s'
,
);
core/ajax/preview.php
View file @
48f0c542
...
...
@@ -13,13 +13,15 @@ $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36';
$scalingUp
=
array_key_exists
(
'scalingup'
,
$_GET
)
?
(
bool
)
$_GET
[
'scalingup'
]
:
true
;
if
(
$file
===
''
)
{
\
OC_Response
::
setStatus
(
400
);
//400 Bad Request
//400 Bad Request
\
OC_Response
::
setStatus
(
400
);
\
OC_Log
::
write
(
'core-preview'
,
'No file parameter was passed'
,
\
OC_Log
::
DEBUG
);
exit
;
}
if
(
$maxX
===
0
||
$maxY
===
0
)
{
\
OC_Response
::
setStatus
(
400
);
//400 Bad Request
//400 Bad Request
\
OC_Response
::
setStatus
(
400
);
\
OC_Log
::
write
(
'core-preview'
,
'x and/or y set to 0'
,
\
OC_Log
::
DEBUG
);
exit
;
}
...
...
@@ -34,6 +36,5 @@ try{
$preview
->
show
();
}
catch
(
\
Exception
$e
)
{
\
OC_Response
::
setStatus
(
500
);
\
OC_Log
::
write
(
'core'
,
$e
->
getmessage
(),
\
OC_Log
::
ERROR
);
exit
;
\
OC_Log
::
write
(
'core'
,
$e
->
getmessage
(),
\
OC_Log
::
DEBUG
);
}
\ No newline at end of file
lib/preview.php
View file @
48f0c542
...
...
@@ -13,14 +13,14 @@
*/
namespace
OC
;
require_once
(
'preview/image
s
.php'
)
;
require_once
(
'preview/movies.php'
)
;
require_once
(
'preview/mp3.php'
)
;
require_once
(
'preview/pdf.php'
)
;
require_once
(
'preview/svg.php'
)
;
require_once
(
'preview/txt.php'
)
;
require_once
(
'preview/unknown.php'
)
;
require_once
(
'preview/office.php'
)
;
require_once
'preview/image.php'
;
require_once
'preview/movies.php'
;
require_once
'preview/mp3.php'
;
require_once
'preview/pdf.php'
;
require_once
'preview/svg.php'
;
require_once
'preview/txt.php'
;
require_once
'preview/unknown.php'
;
require_once
'preview/office.php'
;
class
Preview
{
//the thumbnail folder
...
...
@@ -32,8 +32,8 @@ class Preview {
private
$configMaxY
;
//fileview object
private
$file
v
iew
=
null
;
private
$user
v
iew
=
null
;
private
$file
V
iew
=
null
;
private
$user
V
iew
=
null
;
//vars
private
$file
;
...
...
@@ -76,8 +76,8 @@ class Preview {
if
(
$user
===
''
){
$user
=
\
OC_User
::
getUser
();
}
$this
->
file
v
iew
=
new
\
OC\Files\View
(
'/'
.
$user
.
'/'
.
$root
);
$this
->
user
v
iew
=
new
\
OC\Files\View
(
'/'
.
$user
);
$this
->
file
V
iew
=
new
\
OC\Files\View
(
'/'
.
$user
.
'/'
.
$root
);
$this
->
user
V
iew
=
new
\
OC\Files\View
(
'/'
.
$user
);
$this
->
preview
=
null
;
...
...
@@ -226,12 +226,12 @@ class Preview {
public
function
isFileValid
()
{
$file
=
$this
->
getFile
();
if
(
$file
===
''
)
{
\
OC_Log
::
write
(
'core'
,
'No filename passed'
,
\
OC_Log
::
ERROR
);
\
OC_Log
::
write
(
'core'
,
'No filename passed'
,
\
OC_Log
::
DEBUG
);
return
false
;
}
if
(
!
$this
->
file
v
iew
->
file_exists
(
$file
))
{
\
OC_Log
::
write
(
'core'
,
'File:"'
.
$file
.
'" not found'
,
\
OC_Log
::
ERROR
);
if
(
!
$this
->
file
V
iew
->
file_exists
(
$file
))
{
\
OC_Log
::
write
(
'core'
,
'File:"'
.
$file
.
'" not found'
,
\
OC_Log
::
DEBUG
);
return
false
;
}
...
...
@@ -245,12 +245,12 @@ class Preview {
public
function
deletePreview
()
{
$file
=
$this
->
getFile
();
$fileInfo
=
$this
->
file
v
iew
->
getFileInfo
(
$file
);
$fileInfo
=
$this
->
file
V
iew
->
getFileInfo
(
$file
);
$fileId
=
$fileInfo
[
'fileid'
];
$previewPath
=
$this
->
getThumbnailsFolder
()
.
'/'
.
$fileId
.
'/'
.
$this
->
getMaxX
()
.
'-'
.
$this
->
getMaxY
()
.
'.png'
;
$this
->
user
v
iew
->
unlink
(
$previewPath
);
return
!
$this
->
user
v
iew
->
file_exists
(
$previewPath
);
$this
->
user
V
iew
->
unlink
(
$previewPath
);
return
!
$this
->
user
V
iew
->
file_exists
(
$previewPath
);
}
/**
...
...
@@ -260,13 +260,13 @@ class Preview {
public
function
deleteAllPreviews
()
{
$file
=
$this
->
getFile
();
$fileInfo
=
$this
->
file
v
iew
->
getFileInfo
(
$file
);
$fileInfo
=
$this
->
file
V
iew
->
getFileInfo
(
$file
);
$fileId
=
$fileInfo
[
'fileid'
];
$previewPath
=
$this
->
getThumbnailsFolder
()
.
'/'
.
$fileId
.
'/'
;
$this
->
user
v
iew
->
deleteAll
(
$previewPath
);
$this
->
user
v
iew
->
rmdir
(
$previewPath
);
return
!
$this
->
user
v
iew
->
is_dir
(
$previewPath
);
$this
->
user
V
iew
->
deleteAll
(
$previewPath
);
$this
->
user
V
iew
->
rmdir
(
$previewPath
);
return
!
$this
->
user
V
iew
->
is_dir
(
$previewPath
);
}
/**
...
...
@@ -280,9 +280,9 @@ class Preview {
$maxX
=
$this
->
getMaxX
();
$maxY
=
$this
->
getMaxY
();
$scalingUp
=
$this
->
getScalingUp
();
$max
s
cale
f
actor
=
$this
->
getMaxScaleFactor
();
$max
S
cale
F
actor
=
$this
->
getMaxScaleFactor
();
$fileInfo
=
$this
->
file
v
iew
->
getFileInfo
(
$file
);
$fileInfo
=
$this
->
file
V
iew
->
getFileInfo
(
$file
);
$fileId
=
$fileInfo
[
'fileid'
];
if
(
is_null
(
$fileId
))
{
...
...
@@ -290,12 +290,12 @@ class Preview {
}
$previewPath
=
$this
->
getThumbnailsFolder
()
.
'/'
.
$fileId
.
'/'
;
if
(
!
$this
->
user
v
iew
->
is_dir
(
$previewPath
))
{
if
(
!
$this
->
user
V
iew
->
is_dir
(
$previewPath
))
{
return
false
;
}
//does a preview with the wanted height and width already exist?
if
(
$this
->
user
v
iew
->
file_exists
(
$previewPath
.
$maxX
.
'-'
.
$maxY
.
'.png'
))
{
if
(
$this
->
user
V
iew
->
file_exists
(
$previewPath
.
$maxX
.
'-'
.
$maxY
.
'.png'
))
{
return
$previewPath
.
$maxX
.
'-'
.
$maxY
.
'.png'
;
}
...
...
@@ -304,7 +304,7 @@ class Preview {
//array for usable cached thumbnails
$possibleThumbnails
=
array
();
$allThumbnails
=
$this
->
user
v
iew
->
getDirectoryContent
(
$previewPath
);
$allThumbnails
=
$this
->
user
V
iew
->
getDirectoryContent
(
$previewPath
);
foreach
(
$allThumbnails
as
$thumbnail
)
{
$name
=
rtrim
(
$thumbnail
[
'name'
],
'.png'
);
$size
=
explode
(
'-'
,
$name
);
...
...
@@ -319,7 +319,7 @@ class Preview {
if
(
$x
<
$maxX
||
$y
<
$maxY
)
{
if
(
$scalingUp
)
{
$scalefactor
=
$maxX
/
$x
;
if
(
$scalefactor
>
$max
s
cale
f
actor
)
{
if
(
$scalefactor
>
$max
S
cale
F
actor
)
{
continue
;
}
}
else
{
...
...
@@ -371,19 +371,19 @@ class Preview {
$maxY
=
$this
->
getMaxY
();
$scalingUp
=
$this
->
getScalingUp
();
$fileInfo
=
$this
->
file
v
iew
->
getFileInfo
(
$file
);
$fileInfo
=
$this
->
file
V
iew
->
getFileInfo
(
$file
);
$fileId
=
$fileInfo
[
'fileid'
];
$cached
=
$this
->
isCached
();
if
(
$cached
)
{
$image
=
new
\
OC_Image
(
$this
->
user
v
iew
->
file_get_contents
(
$cached
,
'r'
));
$image
=
new
\
OC_Image
(
$this
->
user
V
iew
->
file_get_contents
(
$cached
,
'r'
));
$this
->
preview
=
$image
->
valid
()
?
$image
:
null
;
$this
->
resizeAndCrop
();
}
if
(
is_null
(
$this
->
preview
))
{
$mimetype
=
$this
->
file
v
iew
->
getMimeType
(
$file
);
$mimetype
=
$this
->
file
V
iew
->
getMimeType
(
$file
);
$preview
=
null
;
foreach
(
self
::
$providers
as
$supportedMimetype
=>
$provider
)
{
...
...
@@ -393,7 +393,7 @@ class Preview {
\
OC_Log
::
write
(
'core'
,
'Generating preview for "'
.
$file
.
'" with "'
.
get_class
(
$provider
)
.
'"'
,
\
OC_Log
::
DEBUG
);
$preview
=
$provider
->
getThumbnail
(
$file
,
$maxX
,
$maxY
,
$scalingUp
,
$this
->
file
v
iew
);
$preview
=
$provider
->
getThumbnail
(
$file
,
$maxX
,
$maxY
,
$scalingUp
,
$this
->
file
V
iew
);
if
(
!
(
$preview
instanceof
\
OC_Image
))
{
continue
;
...
...
@@ -405,15 +405,15 @@ class Preview {
$previewPath
=
$this
->
getThumbnailsFolder
()
.
'/'
.
$fileId
.
'/'
;
$cachePath
=
$previewPath
.
$maxX
.
'-'
.
$maxY
.
'.png'
;
if
(
$this
->
user
v
iew
->
is_dir
(
$this
->
getThumbnailsFolder
()
.
'/'
)
===
false
)
{
$this
->
user
v
iew
->
mkdir
(
$this
->
getThumbnailsFolder
()
.
'/'
);
if
(
$this
->
user
V
iew
->
is_dir
(
$this
->
getThumbnailsFolder
()
.
'/'
)
===
false
)
{
$this
->
user
V
iew
->
mkdir
(
$this
->
getThumbnailsFolder
()
.
'/'
);
}
if
(
$this
->
user
v
iew
->
is_dir
(
$previewPath
)
===
false
)
{
$this
->
user
v
iew
->
mkdir
(
$previewPath
);
if
(
$this
->
user
V
iew
->
is_dir
(
$previewPath
)
===
false
)
{
$this
->
user
V
iew
->
mkdir
(
$previewPath
);
}
$this
->
user
v
iew
->
file_put_contents
(
$cachePath
,
$preview
->
data
());
$this
->
user
V
iew
->
file_put_contents
(
$cachePath
,
$preview
->
data
());
break
;
}
...
...
@@ -470,7 +470,7 @@ class Preview {
if
(
$x
===
$realx
&&
$y
===
$realy
)
{
$this
->
preview
=
$image
;
return
true
;
return
;
}
$factorX
=
$x
/
$realx
;
...
...
lib/preview/image
s
.php
→
lib/preview/image.php
View file @
48f0c542
File moved
lib/preview/
libre
office-cl.php
→
lib/preview/office-cl.php
View file @
48f0c542
...
...
@@ -7,7 +7,7 @@
*/
namespace
OC\Preview
;
//we need imagick to convert
//we need imagick to convert
class
Office
extends
Provider
{
private
$cmd
;
...
...
@@ -26,7 +26,10 @@ class Office extends Provider {
$tmpDir
=
get_temp_dir
();
$exec
=
$this
->
cmd
.
' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir '
.
escapeshellarg
(
$tmpDir
)
.
' '
.
escapeshellarg
(
$absPath
);
$defaultParameters
=
' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir '
;
$clParameters
=
\
OCP\Config
::
getSystemValue
(
'preview_office_cl_parameters'
,
$defaultParameters
);
$exec
=
$this
->
cmd
.
$clParameters
.
escapeshellarg
(
$tmpDir
)
.
' '
.
escapeshellarg
(
$absPath
);
$export
=
'export HOME=/'
.
$tmpDir
;
shell_exec
(
$export
.
"
\n
"
.
$exec
);
...
...
@@ -110,7 +113,7 @@ class MSOffice2007 extends Office {
//.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt
class
OpenDocument
extends
Office
{
public
function
getMimeType
()
{
return
'/application\/vnd.oasis.opendocument.*/'
;
}
...
...
lib/preview/
ms
office.php
→
lib/preview/office
-fallback
.php
View file @
48f0c542
File moved
lib/preview/office.php
View file @
48f0c542
...
...
@@ -14,9 +14,9 @@ if (extension_loaded('imagick')) {
$isOpenOfficeAvailable
=
!
empty
(
$whichOpenOffice
);
//let's see if there is libreoffice or openoffice on this machine
if
(
$isShellExecEnabled
&&
(
$isLibreOfficeAvailable
||
$isOpenOfficeAvailable
||
is_string
(
\
OC_Config
::
getValue
(
'preview_libreoffice_path'
,
null
))))
{
require_once
(
'
libre
office-cl.php'
);
require_once
(
'office-cl.php'
);
}
else
{
//in case there isn't, use our fallback
require_once
(
'
ms
office.php'
);
require_once
(
'office
-fallback
.php'
);
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment