Merge gitorious.org:owncloud/owncloud into tanghus_contacts

This commit is contained in:
Thomas Tanghus 2012-02-10 16:42:45 +01:00
commit fd9ce6da35
9 changed files with 148 additions and 130 deletions

View File

@ -93,7 +93,6 @@ class OC_Gallery_Scanner {
if ($image && $image->valid()) { if ($image && $image->valid()) {
imagecopyresampled($thumbnail, $image->resource(), $i*200, 0, 0, 0, 200, 200, 200, 200); imagecopyresampled($thumbnail, $image->resource(), $i*200, 0, 0, 0, 200, 200, 200, 200);
} }
unset($image); // unset $image here to control the lifetime of image::$resource
} }
imagepng($thumbnail, OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/' . $albumName.'.png'); imagepng($thumbnail, OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/' . $albumName.'.png');
} }

View File

@ -92,6 +92,19 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
} }
/**
* sets the last modification time of the file (mtime) to the value given
* in the second parameter or to now if the second param is empty.
* Even if the modification time is set to a custom value the access time is set to now.
*/
public function setLastModifiedTime($mtime) {
OC_Filesystem::setFileMtime($this->path, $mtime);
}
public function endsWith( $str, $sub ) {
return ( substr( $str, strlen( $str ) - strlen( $sub ) ) === $sub );
}
/** /**
* Updates properties on this node, * Updates properties on this node,
* *
@ -110,13 +123,16 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
} }
} }
else { else {
if(!array_key_exists( $propertyName, $existing )){ if( $this->endsWith( $propertyName, "modificationTime")) {
$query = OC_DB::prepare( 'INSERT INTO *PREFIX*properties (userid,propertypath,propertyname,propertyvalue) VALUES(?,?,?,?)' ); $this->setLastModifiedTime($propertyValue);
$query->execute( array( OC_User::getUser(), $this->path, $propertyName,$propertyValue )); } else {
} if(!array_key_exists( $propertyName, $existing )){
else{ $query = OC_DB::prepare( 'INSERT INTO *PREFIX*properties (userid,propertypath,propertyname,propertyvalue) VALUES(?,?,?,?)' );
$query = OC_DB::prepare( 'UPDATE *PREFIX*properties SET propertyvalue = ? WHERE userid = ? AND propertypath = ? AND propertyname = ?' ); $query->execute( array( OC_User::getUser(), $this->path, $propertyName,$propertyValue ));
$query->execute( array( $propertyValue,OC_User::getUser(), $this->path, $propertyName )); } else {
$query = OC_DB::prepare( 'UPDATE *PREFIX*properties SET propertyvalue = ? WHERE userid = ? AND propertypath = ? AND propertyname = ?' );
$query->execute( array( $propertyValue,OC_User::getUser(), $this->path, $propertyName ));
}
} }
} }

View File

@ -35,6 +35,7 @@ class OC_DB {
static private $schema=false; static private $schema=false;
static private $affected=0; static private $affected=0;
static private $result=false; static private $result=false;
static private $inTransaction=false;
/** /**
* @brief connects to the database * @brief connects to the database
@ -490,17 +491,19 @@ class OC_DB {
return false; return false;
} }
self::$connection->beginTransaction(); self::$connection->beginTransaction();
self::$inTransaction=true;
} }
/** /**
* Commit the database changes done during a transaction that is in progress * Commit the database changes done during a transaction that is in progress
*/ */
public static function commit($savePoint=''){ public static function commit(){
self::connect(); self::connect();
if(!self::$connection->inTransaction()){ if(!self::$inTransaction){
return false; return false;
} }
self::$connection->commit(); self::$connection->commit();
self::$inTransaction=false;
} }
} }

View File

@ -32,7 +32,6 @@ class OC_EventSource{
private $fallBackId=0; private $fallBackId=0;
public function __construct(){ public function __construct(){
ob_end_clean();
header('Cache-Control: no-cache'); header('Cache-Control: no-cache');
$this->fallback=isset($_GET['fallback']) and $_GET['fallback']=='true'; $this->fallback=isset($_GET['fallback']) and $_GET['fallback']=='true';
if($this->fallback){ if($this->fallback){

View File

@ -62,7 +62,7 @@ class OC_FileCache{
if(is_array($result)){ if(is_array($result)){
return $result; return $result;
}else{ }else{
OC_Log::write('file not found in cache ('.$path.')','core',OC_Log::DEBUG); OC_Log::write('get(): file not found in cache ('.$path.')','core',OC_Log::DEBUG);
return false; return false;
} }
} }
@ -125,7 +125,9 @@ class OC_FileCache{
$queryParts[]='mimepart=?'; $queryParts[]='mimepart=?';
} }
$arguments[]=$id; $arguments[]=$id;
$query=OC_DB::prepare('UPDATE *PREFIX*fscache SET '.implode(' , ',$queryParts).' WHERE id=?');
$sql = 'UPDATE *PREFIX*fscache SET '.implode(' , ',$queryParts).' WHERE id=?';
$query=OC_DB::prepare($sql);
$query->execute($arguments); $query->execute($arguments);
} }
@ -231,7 +233,7 @@ class OC_FileCache{
if(is_array($result)){ if(is_array($result)){
return $result; return $result;
}else{ }else{
OC_Log::write('file not found in cache ('.$path.')','core',OC_Log::DEBUG); OC_Log::write('getFolderContent(): file not found in cache ('.$path.')','core',OC_Log::DEBUG);
return false; return false;
} }
} }
@ -264,7 +266,7 @@ class OC_FileCache{
if(is_array($result)){ if(is_array($result)){
return $result['id']; return $result['id'];
}else{ }else{
OC_Log::write('file not found in cache ('.$path.')','core',OC_Log::DEBUG); OC_Log::write('getFieldId(): file not found in cache ('.$path.')','core',OC_Log::DEBUG);
return -1; return -1;
} }
} }
@ -293,6 +295,7 @@ class OC_FileCache{
}else{ }else{
$view=new OC_FilesystemView(($root=='/')?'':$root); $view=new OC_FilesystemView(($root=='/')?'':$root);
} }
$path=$params['path']; $path=$params['path'];
$fullPath=$view->getRoot().$path; $fullPath=$view->getRoot().$path;
$mimetype=$view->getMimeType($path); $mimetype=$view->getMimeType($path);

View File

@ -65,6 +65,13 @@ class OC_Filestorage_Local extends OC_Filestorage{
public function filemtime($path){ public function filemtime($path){
return filemtime($this->datadir.$path); return filemtime($this->datadir.$path);
} }
public function setFileMtime($path, $mtime){
// sets the modification time of the file to the given value. If mtime is nil the current time is set.
// note that the access time of the file always changes to the current time.
return touch($this->datadir.$path, $mtime);
}
public function file_get_contents($path){ public function file_get_contents($path){
return file_get_contents($this->datadir.$path); return file_get_contents($this->datadir.$path);
} }

View File

@ -345,6 +345,9 @@ class OC_Filesystem{
static public function filemtime($path){ static public function filemtime($path){
return self::$defaultInstance->filemtime($path); return self::$defaultInstance->filemtime($path);
} }
static public function setFileMtime($path, $mtime){
return self::$defaultInstance->setFileMtime($path, $mtime);
}
static public function file_get_contents($path){ static public function file_get_contents($path){
return self::$defaultInstance->file_get_contents($path); return self::$defaultInstance->file_get_contents($path);
} }

View File

@ -156,6 +156,9 @@ class OC_FilesystemView {
public function filemtime($path){ public function filemtime($path){
return $this->basicOperation('filemtime',$path); return $this->basicOperation('filemtime',$path);
} }
public function setFileMtime($path, $mtime){
return $this->basicOperation('setFileMtime',$path, array('write'), $mtime);
}
public function file_get_contents($path){ public function file_get_contents($path){
return $this->basicOperation('file_get_contents',$path,array('read')); return $this->basicOperation('file_get_contents',$path,array('read'));
} }

View File

@ -44,34 +44,24 @@ function ellipsis($str, $maxlen) {
* *
*/ */
class OC_Image { class OC_Image {
static private $resource = false; // tmp resource. protected $resource = false; // tmp resource.
static private $destroy = false; // if the resource is created withing the object. protected $imagetype = IMAGETYPE_PNG; // Default to png if file type isn't evident.
static private $imagetype = IMAGETYPE_PNG; // Default to png if file type isn't evident. protected $filepath = null;
static private $filepath = null;
/** /**
* @brief Constructor. * @brief Constructor.
* @param $imageref The path to a local file, a base64 encoded string or a resource created by an imagecreate* function. * @param $imageref The path to a local file, a base64 encoded string or a resource created by an imagecreate* function.
* If a resource is passed it is the job of the caller to destroy it using imagedestroy($var)
* @returns bool False on error * @returns bool False on error
*/ */
function __construct($imageref = null) { public function __construct($imageref = null) {
//OC_Log::write('core','OC_Image::__construct, start', OC_Log::DEBUG); //OC_Log::write('core',__METHOD__.'(): start', OC_Log::DEBUG);
if(!extension_loaded('gd') || !function_exists('gd_info')) { if(!extension_loaded('gd') || !function_exists('gd_info')) {
//if(!function_exists('imagecreatefromjpeg')) { //if(!function_exists('imagecreatefromjpeg')) {
OC_Log::write('core','OC_Image::__construct, GD module not installed', OC_Log::ERROR); OC_Log::write('core',__METHOD__.'(): GD module not installed', OC_Log::ERROR);
return false; return false;
} }
if(!is_null($imageref)) { if(!is_null($imageref)) {
self::load($imageref); $this->load($imageref);
}
}
/**
* @brief Destructor.
*/
function __destruct() {
if(is_resource(self::$resource) && self::$destroy) {
imagedestroy(self::$resource); // Why does this issue a warning.
} }
} }
@ -80,8 +70,7 @@ class OC_Image {
* @returns bool * @returns bool
*/ */
public function valid() { // apparently you can't name a method 'empty'... public function valid() { // apparently you can't name a method 'empty'...
$ret = is_resource(self::$resource); return is_resource($this->resource);
return $ret;
} }
/** /**
@ -89,7 +78,7 @@ class OC_Image {
* @returns int * @returns int
*/ */
public function mimeType() { public function mimeType() {
return is_resource(self::$resource) ? image_type_to_mime_type(self::$imagetype) : ''; return is_resource($this->resource) ? image_type_to_mime_type($this->imagetype) : '';
} }
/** /**
@ -97,7 +86,7 @@ class OC_Image {
* @returns int * @returns int
*/ */
public function width() { public function width() {
return is_resource(self::$resource) ? imagesx(self::$resource) : -1; return is_resource($this->resource) ? imagesx($this->resource) : -1;
} }
/** /**
@ -105,7 +94,7 @@ class OC_Image {
* @returns int * @returns int
*/ */
public function height() { public function height() {
return is_resource(self::$resource) ? imagesy(self::$resource) : -1; return is_resource($this->resource) ? imagesy($this->resource) : -1;
} }
/** /**
@ -122,8 +111,8 @@ class OC_Image {
*/ */
public function save($filepath=null) { public function save($filepath=null) {
if($filepath === null && self::$filepath === null) { if($filepath === null && $this->filepath === null) {
OC_Log::write('core','OC_Image::save. save() called with no path.', OC_Log::ERROR); OC_Log::write('core',__METHOD__.'(): called with no path.', OC_Log::ERROR);
return false; return false;
} elseif($filepath === null && $this->filepath !== null) { } elseif($filepath === null && $this->filepath !== null) {
$filepath = $this->filepath; $filepath = $this->filepath;
@ -136,14 +125,14 @@ class OC_Image {
*/ */
private function _output($filepath=null, $really=false) { private function _output($filepath=null, $really=false) {
if($really === false) { if($really === false) {
header('Content-Type: '.self::mimeType()); header('Content-Type: '.$this->mimeType());
$filepath = null; // Just being cautious ;-) $filepath = null; // Just being cautious ;-)
} else { } else {
if(!is_writable(dirname($filepath))) { if(!is_writable(dirname($filepath))) {
OC_Log::write('core','OC_Image::_output. Directory \''.dirname($filepath).'\' is not writable.', OC_Log::ERROR); OC_Log::write('core',__METHOD__.'(): Directory \''.dirname($filepath).'\' is not writable.', OC_Log::ERROR);
return false; return false;
} elseif(is_writable(dirname($filepath)) && file_exists($filepath) && !is_writable($filepath)) { } elseif(is_writable(dirname($filepath)) && file_exists($filepath) && !is_writable($filepath)) {
OC_Log::write('core','OC_Image::_output. File \''.$filepath.'\' is not writable.', OC_Log::ERROR); OC_Log::write('core',__METHOD__.'(): File \''.$filepath.'\' is not writable.', OC_Log::ERROR);
return false; return false;
} }
} }
@ -152,25 +141,25 @@ class OC_Image {
} }
$retval = false; $retval = false;
switch(self::$imagetype) { switch($this->imagetype) {
case IMAGETYPE_GIF: case IMAGETYPE_GIF:
$retval = imagegif(self::$resource, $filepath); $retval = imagegif($this->resource, $filepath);
break; break;
case IMAGETYPE_JPEG: case IMAGETYPE_JPEG:
$retval = imagejpeg(self::$resource, $filepath); $retval = imagejpeg($this->resource, $filepath);
break; break;
case IMAGETYPE_PNG: case IMAGETYPE_PNG:
$retval = imagepng(self::$resource, $filepath); $retval = imagepng($this->resource, $filepath);
break; break;
case IMAGETYPE_XBM: case IMAGETYPE_XBM:
$retval = imagexbm(self::$resource, $filepath); $retval = imagexbm($this->resource, $filepath);
break; break;
case IMAGETYPE_WBMP: case IMAGETYPE_WBMP:
case IMAGETYPE_BMP: case IMAGETYPE_BMP:
$retval = imagewbmp(self::$resource, $filepath); $retval = imagewbmp($this->resource, $filepath);
break; break;
default: default:
$retval = imagepng(self::$resource, $filepath); $retval = imagepng($this->resource, $filepath);
} }
return $retval; return $retval;
} }
@ -179,14 +168,14 @@ class OC_Image {
* @brief Prints the image when called as $image(). * @brief Prints the image when called as $image().
*/ */
public function __invoke() { public function __invoke() {
return self::show(); return $this->show();
} }
/** /**
* @returns Returns the image resource in any. * @returns Returns the image resource in any.
*/ */
public function resource() { public function resource() {
return self::$resource; return $this->resource;
} }
/** /**
@ -194,9 +183,9 @@ class OC_Image {
*/ */
function __toString() { function __toString() {
ob_start(); ob_start();
$res = imagepng(self::$resource); $res = imagepng($this->resource);
if (!$res) { if (!$res) {
OC_Log::write('core','OC_Image::_string. Error writing image',OC_Log::ERROR); OC_Log::write('core','OC_Image->__toString. Error writing image',OC_Log::ERROR);
} }
return base64_encode(ob_get_clean()); return base64_encode(ob_get_clean());
} }
@ -208,18 +197,18 @@ class OC_Image {
*/ */
public function fixOrientation() { public function fixOrientation() {
if(!is_callable('exif_read_data')){ if(!is_callable('exif_read_data')){
OC_Log::write('core','OC_Image::fixOrientation() Exif module not enabled.', OC_Log::DEBUG); OC_Log::write('core','OC_Image->fixOrientation() Exif module not enabled.', OC_Log::DEBUG);
return false; return false;
} }
if(!is_resource(self::$resource)) { if(!is_resource($this->resource)) {
OC_Log::write('core','OC_Image::fixOrientation() No image loaded.', OC_Log::DEBUG); OC_Log::write('core','OC_Image->fixOrientation() No image loaded.', OC_Log::DEBUG);
return false; return false;
} }
if(is_null(self::$filepath) || !is_readable(self::$filepath)) { if(is_null($this->filepath) || !is_readable($this->filepath)) {
OC_Log::write('core','OC_Image::fixOrientation() No readable file path set.', OC_Log::DEBUG); OC_Log::write('core','OC_Image->fixOrientation() No readable file path set.', OC_Log::DEBUG);
return false; return false;
} }
$exif = exif_read_data(self::$filepath, 'IFD0'); $exif = exif_read_data($this->filepath, 'IFD0');
if(!$exif) { if(!$exif) {
return false; return false;
} }
@ -227,7 +216,7 @@ class OC_Image {
return true; // Nothing to fix return true; // Nothing to fix
} }
$o = $exif['Orientation']; $o = $exif['Orientation'];
OC_Log::write('core','OC_Image::fixOrientation() Orientation: '.$o, OC_Log::DEBUG); OC_Log::write('core','OC_Image->fixOrientation() Orientation: '.$o, OC_Log::DEBUG);
$rotate = 0; $rotate = 0;
$flip = false; $flip = false;
switch($o) { switch($o) {
@ -266,22 +255,22 @@ class OC_Image {
break; break;
} }
if($rotate) { if($rotate) {
$res = imagerotate(self::$resource, $rotate, -1); $res = imagerotate($this->resource, $rotate, -1);
if($res) { if($res) {
if(imagealphablending($res, true)) { if(imagealphablending($res, true)) {
if(imagesavealpha($res, true)) { if(imagesavealpha($res, true)) {
self::$resource = $res; $this->resource = $res;
return true; return true;
} else { } else {
OC_Log::write('core','OC_Image::fixOrientation() Error during alphasaving.', OC_Log::DEBUG); OC_Log::write('core','OC_Image->fixOrientation() Error during alphasaving.', OC_Log::DEBUG);
return false; return false;
} }
} else { } else {
OC_Log::write('core','OC_Image::fixOrientation() Error during alphablending.', OC_Log::DEBUG); OC_Log::write('core','OC_Image->fixOrientation() Error during alphablending.', OC_Log::DEBUG);
return false; return false;
} }
} else { } else {
OC_Log::write('core','OC_Image::fixOrientation() Error during oriention fixing.', OC_Log::DEBUG); OC_Log::write('core','OC_Image->fixOrientation() Error during oriention fixing.', OC_Log::DEBUG);
return false; return false;
} }
} }
@ -290,20 +279,19 @@ class OC_Image {
/** /**
* @brief Loads an image from a local file, a base64 encoded string or a resource created by an imagecreate* function. * @brief Loads an image from a local file, a base64 encoded string or a resource created by an imagecreate* function.
* @param $imageref The path to a local file, a base64 encoded string or a resource created by an imagecreate* function. * @param $imageref The path to a local file, a base64 encoded string or a resource created by an imagecreate* function.
* If a resource is passed it is the job of the caller to destroy it using imagedestroy($var)
* @returns An image resource or false on error * @returns An image resource or false on error
*/ */
public function load($imageref) { public function load($imageref) {
if(self::loadFromFile($imageref) !== false) { if($this->loadFromFile($imageref) !== false) {
return self::$resource; return $this->resource;
} elseif(self::loadFromBase64($imageref) !== false) { } elseif($this->loadFromBase64($imageref) !== false) {
return self::$resource; return $this->resource;
} elseif(self::loadFromData($imageref) !== false) { } elseif($this->loadFromData($imageref) !== false) {
return self::$resource; return $this->resource;
} elseif(self::loadFromResource($imageref) !== false) { } elseif($this->loadFromResource($imageref) !== false) {
return self::$resource; return $this->resource;
} else { } else {
OC_Log::write('core','OC_Image::load, couldn\'t load anything. Giving up!', OC_Log::DEBUG); OC_Log::write('core',__METHOD__.'(): couldn\'t load anything. Giving up!', OC_Log::DEBUG);
return false; return false;
} }
} }
@ -316,45 +304,45 @@ class OC_Image {
public function loadFromFile($imagepath=false) { public function loadFromFile($imagepath=false) {
if(!is_file($imagepath) || !file_exists($imagepath) || !is_readable($imagepath)) { if(!is_file($imagepath) || !file_exists($imagepath) || !is_readable($imagepath)) {
// Debug output disabled because this method is tried before loadFromBase64? // Debug output disabled because this method is tried before loadFromBase64?
OC_Log::write('core','OC_Image::loadFromFile, couldn\'t load: '.ellipsis($imagepath, 50), OC_Log::DEBUG); OC_Log::write('core','OC_Image->loadFromFile, couldn\'t load: '.ellipsis($imagepath, 50), OC_Log::DEBUG);
return false; return false;
} }
$itype = exif_imagetype($imagepath); $itype = exif_imagetype($imagepath);
switch($itype) { switch($itype) {
case IMAGETYPE_GIF: case IMAGETYPE_GIF:
if (imagetypes() & IMG_GIF) { if (imagetypes() & IMG_GIF) {
self::$resource = imagecreatefromgif($imagepath); $this->resource = imagecreatefromgif($imagepath);
} else { } else {
OC_Log::write('core','OC_Image::loadFromFile, GIF images not supported: '.$imagepath, OC_Log::DEBUG); OC_Log::write('core','OC_Image->loadFromFile, GIF images not supported: '.$imagepath, OC_Log::DEBUG);
} }
break; break;
case IMAGETYPE_JPEG: case IMAGETYPE_JPEG:
if (imagetypes() & IMG_JPG) { if (imagetypes() & IMG_JPG) {
self::$resource = imagecreatefromjpeg($imagepath); $this->resource = imagecreatefromjpeg($imagepath);
} else { } else {
OC_Log::write('core','OC_Image::loadFromFile, JPG images not supported: '.$imagepath, OC_Log::DEBUG); OC_Log::write('core','OC_Image->loadFromFile, JPG images not supported: '.$imagepath, OC_Log::DEBUG);
} }
break; break;
case IMAGETYPE_PNG: case IMAGETYPE_PNG:
if (imagetypes() & IMG_PNG) { if (imagetypes() & IMG_PNG) {
self::$resource = imagecreatefrompng($imagepath); $this->resource = imagecreatefrompng($imagepath);
} else { } else {
OC_Log::write('core','OC_Image::loadFromFile, PNG images not supported: '.$imagepath, OC_Log::DEBUG); OC_Log::write('core','OC_Image->loadFromFile, PNG images not supported: '.$imagepath, OC_Log::DEBUG);
} }
break; break;
case IMAGETYPE_XBM: case IMAGETYPE_XBM:
if (imagetypes() & IMG_XPM) { if (imagetypes() & IMG_XPM) {
self::$resource = imagecreatefromxbm($imagepath); $this->resource = imagecreatefromxbm($imagepath);
} else { } else {
OC_Log::write('core','OC_Image::loadFromFile, XBM/XPM images not supported: '.$imagepath, OC_Log::DEBUG); OC_Log::write('core','OC_Image->loadFromFile, XBM/XPM images not supported: '.$imagepath, OC_Log::DEBUG);
} }
break; break;
case IMAGETYPE_WBMP: case IMAGETYPE_WBMP:
case IMAGETYPE_BMP: case IMAGETYPE_BMP:
if (imagetypes() & IMG_WBMP) { if (imagetypes() & IMG_WBMP) {
self::$resource = imagecreatefromwbmp($imagepath); $this->resource = imagecreatefromwbmp($imagepath);
} else { } else {
OC_Log::write('core','OC_Image::loadFromFile, (W)BMP images not supported: '.$imagepath, OC_Log::DEBUG); OC_Log::write('core','OC_Image->loadFromFile, (W)BMP images not supported: '.$imagepath, OC_Log::DEBUG);
} }
break; break;
/* /*
@ -382,17 +370,16 @@ class OC_Image {
break; break;
*/ */
default: default:
self::$resource = imagecreatefromstring(file_get_contents($imagepath)); $this->resource = imagecreatefromstring(file_get_contents($imagepath));
$itype = IMAGETYPE_PNG; $itype = IMAGETYPE_PNG;
OC_Log::write('core','OC_Image::loadFromFile, Default', OC_Log::DEBUG); OC_Log::write('core','OC_Image->loadFromFile, Default', OC_Log::DEBUG);
break; break;
} }
if($this->valid()) { if($this->valid()) {
self::$imagetype = $itype; $this->imagetype = $itype;
self::$filepath = $imagepath; $this->filepath = $imagepath;
self::$destroy = true;
} }
return self::$resource; return $this->resource;
} }
/** /**
@ -404,13 +391,12 @@ class OC_Image {
if(is_resource($str)) { if(is_resource($str)) {
return false; return false;
} }
self::$resource = imagecreatefromstring($str); $this->resource = imagecreatefromstring($str);
if(!self::$resource) { if(!$this->resource) {
OC_Log::write('core','OC_Image::loadFromData, couldn\'t load', OC_Log::DEBUG); OC_Log::write('core','OC_Image->loadFromData, couldn\'t load', OC_Log::DEBUG);
return false; return false;
} }
self::$destroy = true; return $this->resource;
return self::$resource;
} }
/** /**
@ -424,20 +410,19 @@ class OC_Image {
} }
$data = base64_decode($str); $data = base64_decode($str);
if($data) { // try to load from string data if($data) { // try to load from string data
self::$resource = imagecreatefromstring($data); $this->resource = imagecreatefromstring($data);
if(!self::$resource) { if(!$this->resource) {
OC_Log::write('core','OC_Image::loadFromBase64, couldn\'t load', OC_Log::DEBUG); OC_Log::write('core','OC_Image->loadFromBase64, couldn\'t load', OC_Log::DEBUG);
return false; return false;
} }
self::$destroy = true; return $this->resource;
return self::$resource;
} else { } else {
return false; return false;
} }
} }
/** /**
* @brief Checks if image resource is valid and assigns it to self::$resource. * @brief Checks if image resource is valid and assigns it to $this->resource.
* @param $res An image resource. * @param $res An image resource.
* @returns An image resource or false on error * @returns An image resource or false on error
*/ */
@ -445,7 +430,7 @@ class OC_Image {
if(!is_resource($res)) { if(!is_resource($res)) {
return false; return false;
} }
self::$resource = $res; $this->resource = $res;
} }
/** /**
@ -454,12 +439,12 @@ class OC_Image {
* @returns bool * @returns bool
*/ */
public function resize($maxsize) { public function resize($maxsize) {
if(!self::$resource) { if(!$this->resource) {
OC_Log::write('core','OC_Image::resize, No image loaded', OC_Log::ERROR); OC_Log::write('core',__METHOD__.'(): No image loaded', OC_Log::ERROR);
return false; return false;
} }
$width_orig=imageSX(self::$resource); $width_orig=imageSX($this->resource);
$height_orig=imageSY(self::$resource); $height_orig=imageSY($this->resource);
$ratio_orig = $width_orig/$height_orig; $ratio_orig = $width_orig/$height_orig;
if ($ratio_orig > 1) { if ($ratio_orig > 1) {
@ -472,18 +457,18 @@ class OC_Image {
$process = imagecreatetruecolor(round($new_width), round($new_height)); $process = imagecreatetruecolor(round($new_width), round($new_height));
if ($process == false) { if ($process == false) {
OC_Log::write('core','OC_Image::resize. Error creating true color image',OC_Log::ERROR); OC_Log::write('core',__METHOD__.'(): Error creating true color image',OC_Log::ERROR);
imagedestroy($process); imagedestroy($process);
return false; return false;
} }
imagecopyresampled($process, self::$resource, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig); imagecopyresampled($process, $this->resource, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
if ($process == false) { if ($process == false) {
OC_Log::write('core','OC_Image::resize. Error resampling process image '.$new_width.'x'.$new_height,OC_Log::ERROR); OC_Log::write('core',__METHOD__.'(): Error resampling process image '.$new_width.'x'.$new_height,OC_Log::ERROR);
imagedestroy($process); imagedestroy($process);
return false; return false;
} }
self::$resource = $process; $this->resource = $process;
return true; return true;
} }
@ -492,12 +477,12 @@ class OC_Image {
* @returns bool for success or failure * @returns bool for success or failure
*/ */
public function centerCrop() { public function centerCrop() {
if(!self::$resource) { if(!$this->resource) {
OC_Log::write('core','OC_Image::centerCrop, No image loaded', OC_Log::ERROR); OC_Log::write('core','OC_Image->centerCrop, No image loaded', OC_Log::ERROR);
return false; return false;
} }
$width_orig=imageSX(self::$resource); $width_orig=imageSX($this->resource);
$height_orig=imageSY(self::$resource); $height_orig=imageSY($this->resource);
if($width_orig === $height_orig) { if($width_orig === $height_orig) {
return true; return true;
} }
@ -513,17 +498,17 @@ class OC_Image {
} }
$process = imagecreatetruecolor($width, $height); $process = imagecreatetruecolor($width, $height);
if ($process == false) { if ($process == false) {
OC_Log::write('core','OC_Image::centerCrop. Error creating true color image',OC_Log::ERROR); OC_Log::write('core','OC_Image->centerCrop. Error creating true color image',OC_Log::ERROR);
imagedestroy($process); imagedestroy($process);
return false; return false;
} }
imagecopyresampled($process, self::$resource, 0, 0, $x, $y, $width, $height, $width, $height); imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $width, $height, $width, $height);
if ($process == false) { if ($process == false) {
OC_Log::write('core','OC_Image::centerCrop. Error resampling process image '.$width.'x'.$height,OC_Log::ERROR); OC_Log::write('core','OC_Image->centerCrop. Error resampling process image '.$width.'x'.$height,OC_Log::ERROR);
imagedestroy($process); imagedestroy($process);
return false; return false;
} }
self::$resource = $process; $this->resource = $process;
return true; return true;
} }
@ -536,26 +521,26 @@ class OC_Image {
* @returns bool for success or failure * @returns bool for success or failure
*/ */
public function crop($x, $y, $w, $h) { public function crop($x, $y, $w, $h) {
if(!self::$resource) { if(!$this->resource) {
OC_Log::write('core','OC_Image::crop, No image loaded', OC_Log::ERROR); OC_Log::write('core',__METHOD__.'(): No image loaded', OC_Log::ERROR);
return false; return false;
} }
$width_orig=imageSX(self::$resource); $width_orig=imageSX($this->resource);
$height_orig=imageSY(self::$resource); $height_orig=imageSY($this->resource);
//OC_Log::write('core','OC_Image::crop. Original size: '.$width_orig.'x'.$height_orig, OC_Log::DEBUG); //OC_Log::write('core',__METHOD__.'(): Original size: '.$width_orig.'x'.$height_orig, OC_Log::DEBUG);
$process = imagecreatetruecolor($w, $h); $process = imagecreatetruecolor($w, $h);
if ($process == false) { if ($process == false) {
OC_Log::write('core','OC_Image::crop. Error creating true color image',OC_Log::ERROR); OC_Log::write('core',__METHOD__.'(): Error creating true color image',OC_Log::ERROR);
imagedestroy($process); imagedestroy($process);
return false; return false;
} }
imagecopyresampled($process, self::$resource, 0, 0, $x, $y, $w, $h, $w, $h); imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $w, $h, $w, $h);
if ($process == false) { if ($process == false) {
OC_Log::write('core','OC_Image::crop. Error resampling process image '.$w.'x'.$h,OC_Log::ERROR); OC_Log::write('core',__METHOD__.'(): Error resampling process image '.$w.'x'.$h,OC_Log::ERROR);
imagedestroy($process); imagedestroy($process);
return false; return false;
} }
self::$resource = $process; $this->resource = $process;
return true; return true;
} }
} }