richdocuments/lib/helper.php

55 lines
1.1 KiB
PHP
Raw Normal View History

2013-08-18 19:02:48 +03:00
<?php
/**
2015-12-16 17:57:44 +03:00
* ownCloud - Richdocuments App
2013-08-18 19:02:48 +03:00
*
* @author Victor Dubiniuk
* @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
2015-12-16 17:57:44 +03:00
namespace OCA\Richdocuments;
2013-08-18 19:02:48 +03:00
2014-02-12 15:46:53 +03:00
class Helper {
2015-12-16 17:57:44 +03:00
const APP_ID = 'richdocuments';
2014-02-12 15:46:53 +03:00
2017-05-11 21:01:40 +05:30
/**
* @param string $fileId
* @return array
* @throws \Exception
*/
public static function parseFileId($fileId) {
$arr = explode('_', $fileId);
if (count($arr) === 1) {
$fileId = $arr[0];
$version = '0';
} else if (count($arr) === 2) {
list($fileId, $instanceId) = $arr;
$version = '0';
} else if (count($arr) === 3) {
list($fileId, $instanceId, $version) = $arr;
} else {
throw new \Exception('$fileId has not the expected format');
}
return [
$fileId,
$instanceId,
$version,
];
}
public static function getNewFileName($view, $path, $prepend = ' '){
$fileNum = 1;
2014-02-12 15:46:53 +03:00
while ($view->file_exists($path)){
$fileNum += 1;
$path = preg_replace('/(\.|' . $prepend . '\(\d+\)\.)([^.]*)$/', $prepend . '(' . $fileNum . ').$2', $path);
};
2014-02-12 15:46:53 +03:00
return $path;
}
2014-02-12 15:46:53 +03:00
}