move to OC namespace

This commit is contained in:
Georg Ehrke 2013-05-29 12:33:24 +02:00
parent eebc15dce0
commit fa6b96090a
11 changed files with 80 additions and 56 deletions

View File

@ -43,9 +43,9 @@ $this->create('js_config', '/core/js/config.js')
$this->create('core_ajax_routes', '/core/routes.json')
->action('OC_Router', 'JSRoutes');
$this->create('core_ajax_preview', '/core/preview.png')
->action('OC_Preview', 'previewRouter');
->action('OC\Preview', 'previewRouter');
$this->create('core_ajax_public_preview', '/core/publicpreview.png')
->action('OC_Preview', 'publicPreviewRouter');
->action('OC\Preview', 'publicPreviewRouter');
OC::$CLASSPATH['OC_Core_LostPassword_Controller'] = 'core/lostpassword/controller.php';
$this->create('core_lostpassword_index', '/lostpassword/')
->get()

View File

@ -544,8 +544,8 @@ class OC {
* register hooks for previews
*/
public static function registerPreviewHooks() {
OC_Hook::connect('OC_Filesystem', 'post_write', 'OC_Preview', 'post_write');
OC_Hook::connect('OC_Filesystem', 'delete', 'OC_Preview', 'post_delete');
OC_Hook::connect('OC_Filesystem', 'post_write', 'OC\Preview', 'post_write');
OC_Hook::connect('OC_Filesystem', 'delete', 'OC\Preview', 'post_delete');
}
/**

View File

@ -11,6 +11,8 @@
* /data/user/thumbnails/pathhash/x-y.png
*
*/
namespace OC;
require_once('preview/images.php');
require_once('preview/movies.php');
require_once('preview/mp3.php');
@ -19,7 +21,7 @@ require_once('preview/svg.php');
require_once('preview/txt.php');
require_once('preview/unknown.php');
class OC_Preview {
class Preview {
//the thumbnail folder
const THUMBNAILS_FOLDER = 'thumbnails';
@ -57,9 +59,9 @@ class OC_Preview {
*/
public function __construct($user = null, $root = '', $file = '', $maxX = 0, $maxY = 0, $scalingup = true, $force = false){
//set config
$this->max_x = OC_Config::getValue('preview_max_x', null);
$this->max_y = OC_Config::getValue('preview_max_y', null);
$this->max_scale_factor = OC_Config::getValue('preview_max_scale_factor', 10);
$this->max_x = \OC_Config::getValue('preview_max_x', null);
$this->max_y = \OC_Config::getValue('preview_max_y', null);
$this->max_scale_factor = \OC_Config::getValue('preview_max_scale_factor', 10);
//save parameters
$this->file = $file;
@ -74,14 +76,14 @@ class OC_Preview {
if($force !== true){
if(!is_null($this->max_x)){
if($this->maxX > $this->max_x){
OC_Log::write('core', 'maxX reduced from ' . $this->maxX . ' to ' . $this->max_x, OC_Log::DEBUG);
\OC_Log::write('core', 'maxX reduced from ' . $this->maxX . ' to ' . $this->max_x, \OC_Log::DEBUG);
$this->maxX = $this->max_x;
}
}
if(!is_null($this->max_y)){
if($this->maxY > $this->max_y){
OC_Log::write('core', 'maxY reduced from ' . $this->maxY . ' to ' . $this->max_y, OC_Log::DEBUG);
\OC_Log::write('core', 'maxY reduced from ' . $this->maxY . ' to ' . $this->max_y, \OC_Log::DEBUG);
$this->maxY = $this->max_y;
}
}
@ -93,26 +95,26 @@ class OC_Preview {
//check if there are any providers at all
if(empty(self::$providers)){
OC_Log::write('core', 'No preview providers exist', OC_Log::ERROR);
throw new Exception('No providers');
\OC_Log::write('core', 'No preview providers exist', \OC_Log::ERROR);
throw new \Exception('No providers');
}
//validate parameters
if($file === ''){
OC_Log::write('core', 'No filename passed', OC_Log::ERROR);
throw new Exception('File not found');
\OC_Log::write('core', 'No filename passed', \OC_Log::ERROR);
throw new \Exception('File not found');
}
//check if file exists
if(!$this->fileview->file_exists($file)){
OC_Log::write('core', 'File:"' . $file . '" not found', OC_Log::ERROR);
throw new Exception('File not found');
\OC_Log::write('core', 'File:"' . $file . '" not found', \OC_Log::ERROR);
throw new \Exception('File not found');
}
//check if given size makes sense
if($maxX === 0 || $maxY === 0){
OC_Log::write('core', 'Can not create preview with 0px width or 0px height', OC_Log::ERROR);
throw new Exception('Height and/or width set to 0');
\OC_Log::write('core', 'Can not create preview with 0px width or 0px height', \OC_Log::ERROR);
throw new \Exception('Height and/or width set to 0');
}
}
}
@ -353,7 +355,7 @@ class OC_Preview {
* @return void
*/
public function showPreview(){
OCP\Response::enableCaching(3600 * 24); // 24 hour
\OCP\Response::enableCaching(3600 * 24); // 24 hour
$preview = $this->getPreview();
if($preview){
$preview->show();
@ -373,7 +375,7 @@ class OC_Preview {
$scalingup = $this->scalingup;
if(!($image instanceof \OC_Image)){
OC_Log::write('core', 'Object passed to resizeAndCrop is not an instance of OC_Image', OC_Log::DEBUG);
OC_Log::write('core', 'Object passed to resizeAndCrop is not an instance of OC_Image', \OC_Log::DEBUG);
return;
}
@ -399,7 +401,7 @@ class OC_Preview {
}
if(!is_null($this->max_scale_factor)){
if($factor > $this->max_scale_factor){
OC_Log::write('core', 'scalefactor reduced from ' . $factor . ' to ' . $this->max_scale_factor, OC_Log::DEBUG);
\OC_Log::write('core', 'scalefactor reduced from ' . $factor . ' to ' . $this->max_scale_factor, \OC_Log::DEBUG);
$factor = $this->max_scale_factor;
}
}
@ -462,7 +464,7 @@ class OC_Preview {
/**
* @brief register a new preview provider to be used
* @param string $provider class name of a OC_Preview_Provider
* @param string $provider class name of a Preview_Provider
* @return void
*/
public static function registerProvider($class, $options=array()){
@ -496,7 +498,7 @@ class OC_Preview {
* @return void
*/
public static function previewRouter($params){
OC_Util::checkLoggedIn();
\OC_Util::checkLoggedIn();
$file = '';
$maxX = 0;
@ -514,15 +516,15 @@ class OC_Preview {
if($file !== '' && $maxX !== 0 && $maxY !== 0){
try{
$preview = new OC_Preview(OC_User::getUser(), 'files', $file, $maxX, $maxY, $scalingup);
$preview = new Preview(\OC_User::getUser(), 'files', $file, $maxX, $maxY, $scalingup);
$preview->showPreview();
}catch(Exception $e){
OC_Response::setStatus(404);
OC_Log::write('core', $e->getmessage(), OC_Log::ERROR);
\OC_Response::setStatus(404);
\OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
exit;
}
}else{
OC_Response::setStatus(404);
\OC_Response::setStatus(404);
exit;
}
}
@ -547,11 +549,11 @@ class OC_Preview {
if(array_key_exists('scalingup', $_GET)) $scalingup = (bool) $_GET['scalingup'];
if(array_key_exists('t', $_GET)) $token = (string) $_GET['t'];
$linkItem = OCP\Share::getShareByToken($token);
$linkItem = \OCP\Share::getShareByToken($token);
if (is_array($linkItem) && isset($linkItem['uid_owner']) && isset($linkItem['file_source'])) {
$userid = $linkItem['uid_owner'];
OC_Util::setupFS($userid);
\OC_Util::setupFS($userid);
$pathid = $linkItem['file_source'];
$path = \OC\Files\Filesystem::getPath($pathid);
}
@ -559,7 +561,7 @@ class OC_Preview {
//clean up file parameter
$file = \OC\Files\Filesystem::normalizePath($file);
if(!\OC\Files\Filesystem::isValidPath($file)){
OC_Response::setStatus(403);
\OC_Response::setStatus(403);
exit;
}
@ -570,15 +572,15 @@ class OC_Preview {
if($userid !== null && $path !== null){
try{
$preview = new OC_Preview($userid, 'files/' . $path, $file, $maxX, $maxY, $scalingup);
$preview = new Preview($userid, 'files/' . $path, $file, $maxX, $maxY, $scalingup);
$preview->showPreview();
}catch(Exception $e){
OC_Response::setStatus(404);
OC_Log::write('core', $e->getmessage(), OC_Log::ERROR);
\OC_Response::setStatus(404);
\OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
exit;
}
}else{
OC_Response::setStatus(404);
\OC_Response::setStatus(404);
exit;
}
}
@ -592,7 +594,7 @@ class OC_Preview {
if(substr($path, 0, 1) == '/'){
$path = substr($path, 1);
}
$preview = new OC_Preview(OC_User::getUser(), 'files/', $path, 0, 0, false, true);
$preview = new Preview(\OC_User::getUser(), 'files/', $path, 0, 0, false, true);
$preview->deleteAllPreviews();
}
}

View File

@ -6,7 +6,9 @@
* later.
* See the COPYING-README file.
*/
class OC_Preview_Image extends OC_Preview_Provider{
namespace OC\Preview;
class Image extends Provider{
public function getMimeType(){
return '/image\/.*/';
@ -31,4 +33,4 @@ class OC_Preview_Image extends OC_Preview_Provider{
}
}
OC_Preview::registerProvider('OC_Preview_Image');
\OC\Preview::registerProvider('OC\Preview\Image');

View File

@ -6,8 +6,10 @@
* later.
* See the COPYING-README file.
*/
namespace OC\Preview;
if(!is_null(shell_exec('ffmpeg -version'))){
class OC_Preview_Movie extends OC_Preview_Provider{
class Movie extends Provider{
public function getMimeType(){
return '/video\/.*/';
@ -18,7 +20,7 @@ if(!is_null(shell_exec('ffmpeg -version'))){
$fileinfo = $fileview->getFileInfo($path);
$abspath = $fileview->toTmpFile($path);
$tmppath = OC_Helper::tmpFile();
$tmppath = \OC_Helper::tmpFile();
//$cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmppath;
$cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 ' . $tmppath;
@ -35,5 +37,5 @@ if(!is_null(shell_exec('ffmpeg -version'))){
}
}
OC_Preview::registerProvider('OC_Preview_Movie');
\OC\Preview::registerProvider('OC\Preview\Movie');
}

View File

@ -5,22 +5,24 @@
* later.
* See the COPYING-README file.
*/
namespace OC\Preview;
require_once('getid3/getid3.php');
class OC_Preview_MP3 extends OC_Preview_Provider{
class MP3 extends Provider{
public function getMimeType(){
return '/audio\/mpeg/';
}
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
$getID3 = new getID3();
$getID3 = new \getID3();
$tmppath = $fileview->toTmpFile($path);
//Todo - add stream support
$tags = $getID3->analyze($tmppath);
getid3_lib::CopyTagsToComments($tags);
\getid3_lib::CopyTagsToComments($tags);
$picture = @$tags['id3v2']['APIC'][0]['data'];
unlink($tmppath);
@ -38,4 +40,4 @@ class OC_Preview_MP3 extends OC_Preview_Provider{
}
OC_Preview::registerProvider('OC_Preview_MP3');
\OC\Preview::registerProvider('OC\Preview\MP3');

View File

@ -5,9 +5,11 @@
* later.
* See the COPYING-README file.
*/
namespace OC\Preview;
if (extension_loaded('imagick')){
class OC_Preview_PDF extends OC_Preview_Provider{
class PDF extends Provider{
public function getMimeType(){
return '/application\/pdf/';
@ -17,7 +19,7 @@ if (extension_loaded('imagick')){
$tmppath = $fileview->toTmpFile($path);
//create imagick object from pdf
$pdf = new imagick($tmppath . '[0]');
$pdf = new \imagick($tmppath . '[0]');
$pdf->setImageFormat('jpg');
unlink($tmppath);
@ -31,5 +33,5 @@ if (extension_loaded('imagick')){
}
}
OC_Preview::registerProvider('OC_Preview_PDF');
\OC\Preview::registerProvider('OC\Preview\PDF');
}

View File

@ -2,7 +2,9 @@
/**
* provides search functionalty
*/
abstract class OC_Preview_Provider{
namespace OC\Preview;
abstract class Provider{
private $options;
public function __construct($options) {

View File

@ -5,18 +5,26 @@
* later.
* See the COPYING-README file.
*/
namespace OC\Preview;
if (extension_loaded('imagick')){
class OC_Preview_SVG extends OC_Preview_Provider{
class SVG extends Provider{
public function getMimeType(){
return '/image\/svg\+xml/';
}
public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) {
$svg = new Imagick();
$svg = new \Imagick();
$svg->setResolution($maxX, $maxY);
$svg->readImageBlob('<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $fileview->file_get_contents($path));
$content = stream_get_contents($fileview->fopen($path, 'r'));
if(substr($content, 0, 5) !== '<?xml'){
$content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
}
$svg->readImageBlob($content);
$svg->setImageFormat('jpg');
//new image object
@ -28,6 +36,6 @@ if (extension_loaded('imagick')){
}
}
OC_Preview::registerProvider('OC_Preview_SVG');
\OC\Preview::registerProvider('OC\Preview\SVG');
}

View File

@ -5,7 +5,9 @@
* later.
* See the COPYING-README file.
*/
class OC_Preview_TXT extends OC_Preview_Provider{
namespace OC\Preview;
class TXT extends Provider{
public function getMimeType(){
return '/text\/.*/';
@ -46,4 +48,4 @@ class OC_Preview_TXT extends OC_Preview_Provider{
}
}
OC_Preview::registerProvider('OC_Preview_TXT');
\OC\Preview::registerProvider('OC\Preview\TXT');

View File

@ -6,7 +6,9 @@
* later.
* See the COPYING-README file.
*/
class OC_Preview_Unknown extends OC_Preview_Provider{
namespace OC\Preview;
class Unknown extends Provider{
public function getMimeType(){
return '/.*/';
@ -22,4 +24,4 @@ class OC_Preview_Unknown extends OC_Preview_Provider{
}
}
OC_Preview::registerProvider('OC_Preview_Unknown');
\OC\Preview::registerProvider('OC\Preview\Unknown');