2012-06-02 13:25:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OC\Pictures;
|
|
|
|
|
|
|
|
require_once('lib/base.php');
|
|
|
|
|
|
|
|
class DatabaseManager {
|
|
|
|
private static $instance = null;
|
|
|
|
const TAG = 'DatabaseManager';
|
|
|
|
|
|
|
|
public static function getInstance() {
|
|
|
|
if (self::$instance === null)
|
|
|
|
self::$instance = new DatabaseManager();
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFileData($path) {
|
|
|
|
$gallery_path = \OCP\Config::getSystemValue( 'datadirectory' ).'/'.\OC_User::getUser().'/gallery';
|
|
|
|
$path = $gallery_path.$path;
|
|
|
|
$stmt = \OCP\DB::prepare('SELECT * FROM *PREFIX*pictures_images_cache WHERE uid_owner LIKE ? AND path = ?');
|
|
|
|
$result = $stmt->execute(array(\OCP\USER::getUser(), $path));
|
|
|
|
if (($row = $result->fetchRow()) != false) {
|
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
$image = new \OC_Image();
|
|
|
|
if (!$image->loadFromFile($path)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$stmt = \OCP\DB::prepare('INSERT INTO *PREFIX*pictures_images_cache (uid_owner, path, width, height) VALUES (?, ?, ?, ?)');
|
|
|
|
$stmt->execute(array(\OCP\USER::getUser(), $path, $image->width(), $image->height()));
|
2012-06-08 19:55:28 +00:00
|
|
|
$ret = array('path' => $path, 'width' => $image->width(), 'height' => $image->height());
|
2012-06-06 20:10:09 +00:00
|
|
|
unset($image);
|
2012-06-08 19:55:28 +00:00
|
|
|
return $ret;
|
2012-06-02 13:25:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function __construct() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ThumbnailsManager {
|
|
|
|
|
|
|
|
private static $instance = null;
|
|
|
|
const TAG = 'ThumbnailManager';
|
|
|
|
|
|
|
|
public static function getInstance() {
|
|
|
|
if (self::$instance === null)
|
|
|
|
self::$instance = new ThumbnailsManager();
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getThumbnail($path) {
|
|
|
|
$gallery_path = \OCP\Config::getSystemValue( 'datadirectory' ).'/'.\OC_User::getUser().'/gallery';
|
|
|
|
if (file_exists($gallery_path.$path)) {
|
|
|
|
return new \OC_Image($gallery_path.$path);
|
|
|
|
}
|
|
|
|
if (!\OC_Filesystem::file_exists($path)) {
|
|
|
|
\OC_Log::write(self::TAG, 'File '.$path.' don\'t exists', \OC_Log::WARN);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$image = new \OC_Image();
|
|
|
|
$image->loadFromFile(\OC_Filesystem::getLocalFile($path));
|
|
|
|
if (!$image->valid()) return false;
|
|
|
|
|
|
|
|
$image->fixOrientation();
|
|
|
|
|
2012-06-02 22:29:10 +00:00
|
|
|
$ret = $image->preciseResize(floor((150*$image->width())/$image->height()), 150);
|
2012-06-02 13:25:50 +00:00
|
|
|
|
|
|
|
if (!$ret) {
|
|
|
|
\OC_Log::write(self::TAG, 'Couldn\'t resize image', \OC_Log::ERROR);
|
|
|
|
unset($image);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$image->save($gallery_path.'/'.$path);
|
|
|
|
return $image;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getThumbnailInfo($path) {
|
|
|
|
$arr = DatabaseManager::getInstance()->getFileData($path);
|
2012-06-10 11:04:42 +00:00
|
|
|
if (!$arr) {
|
|
|
|
$thubnail = $this->getThumbnail($path);
|
|
|
|
unset($thubnail);
|
|
|
|
$arr = DatabaseManager::getInstance()->getFileData($path);
|
|
|
|
}
|
2012-06-02 13:25:50 +00:00
|
|
|
$ret = array('filepath' => $arr['path'],
|
2012-06-10 11:04:42 +00:00
|
|
|
'width' => $arr['width'],
|
|
|
|
'height' => $arr['height']);
|
2012-06-02 13:25:50 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete($path) {
|
2012-06-08 18:26:17 +00:00
|
|
|
unlink(\OCP\Config::getSystemValue('datadirectory').'/'.\OC_User::getUser()."/gallery".$path);
|
2012-06-02 13:25:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function __construct() {}
|
|
|
|
|
|
|
|
}
|
2012-06-06 20:10:09 +00:00
|
|
|
?>
|