|
|
@@ -28,7 +28,7 @@ use Sabre\DAV\Exception\Forbidden; |
|
|
|
use Sabre\DAV\Exception\MethodNotAllowed; |
|
|
|
use Sabre\DAV\Exception\NotFound; |
|
|
|
use Sabre\DAV\ICollection; |
|
|
|
use Sabre\HTTP\URLUtil; |
|
|
|
use Sabre\Uri; |
|
|
|
|
|
|
|
class AvatarHome implements ICollection { |
|
|
|
|
|
|
@@ -41,25 +41,26 @@ class AvatarHome implements ICollection { |
|
|
|
* AvatarHome constructor. |
|
|
|
* |
|
|
|
* @param array $principalInfo |
|
|
|
* @param IAvatarManager $avatarManager |
|
|
|
*/ |
|
|
|
public function __construct($principalInfo, IAvatarManager $avatarManager) { |
|
|
|
$this->principalInfo = $principalInfo; |
|
|
|
$this->avatarManager = $avatarManager; |
|
|
|
} |
|
|
|
|
|
|
|
function createFile($name, $data = null) { |
|
|
|
public function createFile($name, $data = null) { |
|
|
|
throw new Forbidden('Permission denied to create a file'); |
|
|
|
} |
|
|
|
|
|
|
|
function createDirectory($name) { |
|
|
|
public function createDirectory($name) { |
|
|
|
throw new Forbidden('Permission denied to create a folder'); |
|
|
|
} |
|
|
|
|
|
|
|
function getChild($name) { |
|
|
|
public function getChild($name) { |
|
|
|
$elements = pathinfo($name); |
|
|
|
$ext = isset($elements['extension']) ? $elements['extension'] : ''; |
|
|
|
$size = intval(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
|
|
if (!in_array($ext, ['jpeg', 'png'])) { |
|
|
|
$size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
|
|
if (!in_array($ext, ['jpeg', 'png'], true)) { |
|
|
|
throw new MethodNotAllowed('File format not allowed'); |
|
|
|
} |
|
|
|
if ($size <= 0 || $size > 1024) { |
|
|
@@ -72,7 +73,7 @@ class AvatarHome implements ICollection { |
|
|
|
return new AvatarNode($size, $ext, $avatar); |
|
|
|
} |
|
|
|
|
|
|
|
function getChildren() { |
|
|
|
public function getChildren() { |
|
|
|
try { |
|
|
|
return [ |
|
|
|
$this->getChild('96.jpeg') |
|
|
@@ -82,10 +83,10 @@ class AvatarHome implements ICollection { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function childExists($name) { |
|
|
|
public function childExists($name) { |
|
|
|
try { |
|
|
|
$ret = $this->getChild($name); |
|
|
|
return !is_null($ret); |
|
|
|
return $ret !== null; |
|
|
|
} catch (NotFound $ex) { |
|
|
|
return false; |
|
|
|
} catch (MethodNotAllowed $ex) { |
|
|
@@ -93,16 +94,16 @@ class AvatarHome implements ICollection { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function delete() { |
|
|
|
public function delete() { |
|
|
|
throw new Forbidden('Permission denied to delete this folder'); |
|
|
|
} |
|
|
|
|
|
|
|
function getName() { |
|
|
|
list(,$name) = URLUtil::splitPath($this->principalInfo['uri']); |
|
|
|
public function getName() { |
|
|
|
list(,$name) = Uri\split($this->principalInfo['uri']); |
|
|
|
return $name; |
|
|
|
} |
|
|
|
|
|
|
|
function setName($name) { |
|
|
|
public function setName($name) { |
|
|
|
throw new Forbidden('Permission denied to rename this folder'); |
|
|
|
} |
|
|
|
|
|
|
@@ -111,7 +112,7 @@ class AvatarHome implements ICollection { |
|
|
|
* |
|
|
|
* @return int |
|
|
|
*/ |
|
|
|
function getLastModified() { |
|
|
|
public function getLastModified() { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|