|
@@ -34,7 +34,7 @@ function searchNewFiles($scanDir) {
|
|
|
global $db;
|
|
global $db;
|
|
|
global $CONFIG;
|
|
global $CONFIG;
|
|
|
|
|
|
|
|
- $oldDocuments = Document::getDocumentsByPath($scanDir);
|
|
|
|
|
|
|
+ $oldDocuments = Document::getDocumentsByLabelPath($scanDir);
|
|
|
$files = scandir($CONFIG['documentPath'] . $scanDir);
|
|
$files = scandir($CONFIG['documentPath'] . $scanDir);
|
|
|
|
|
|
|
|
foreach($files as $file) {
|
|
foreach($files as $file) {
|
|
@@ -60,6 +60,49 @@ function searchNewFiles($scanDir) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function handleFile($filename, &$allDocuments) {
|
|
|
|
|
+ global $db;
|
|
|
|
|
+ global $CONFIG;
|
|
|
|
|
+
|
|
|
|
|
+ if(is_array($filename)) {
|
|
|
|
|
+ foreach($filename as $dir) {
|
|
|
|
|
+ handleFile($dir, $allDocuments);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $found = false;
|
|
|
|
|
+ foreach($allDocuments as $key => $document) {
|
|
|
|
|
+ if($document['fileName'] == explode('/', $filename)[sizeof(explode('/', $filename)) - 1]) {
|
|
|
|
|
+ $labelPath = Label::getLabelById($document['labelId'])->getPath();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if(str_replace($CONFIG['documentPath'], "", $filename) == $labelPath . "/" . $document['path'] . $document['fileName']) {
|
|
|
|
|
+ // found
|
|
|
|
|
+ // update stuff
|
|
|
|
|
+ unset($allDocuments[$key]); // remove from array
|
|
|
|
|
+ $found = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // same filename, path unknown
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(!$found) {
|
|
|
|
|
+ $fileTime = date("Y-m-d H:i:s", filemtime($filename));
|
|
|
|
|
+
|
|
|
|
|
+ $path = explode('/', str_replace($CONFIG['documentPath'], "", $filename));
|
|
|
|
|
+ $labelPath = $path[0];
|
|
|
|
|
+ unset($path[0]);
|
|
|
|
|
+ unset($path[sizeof($path)]);
|
|
|
|
|
+ $path = implode('/', $path) . '/';
|
|
|
|
|
+
|
|
|
|
|
+ Document::addDocument('file', explode('/', $filename)[sizeof(explode('/', $filename)) - 1], $path, Label::getLabelByPath($labelPath)->getId(), '', $fileTime, $fileTime);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function searchMails() {
|
|
function searchMails() {
|
|
|
global $user;
|
|
global $user;
|
|
|
$mailboxes = Mailbox::getAllMailBoxes();
|
|
$mailboxes = Mailbox::getAllMailBoxes();
|
|
@@ -132,4 +175,47 @@ function getExcerptFromString($string, $count = 50) {
|
|
|
return $string;
|
|
return $string;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function startsWith($haystack, $needle)
|
|
|
|
|
+{
|
|
|
|
|
+ $length = strlen($needle);
|
|
|
|
|
+ return (substr($haystack, 0, $length) === $needle);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function endsWith($haystack, $needle)
|
|
|
|
|
+{
|
|
|
|
|
+ $length = strlen($needle);
|
|
|
|
|
+ if ($length == 0) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return (substr($haystack, -$length) === $needle);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function recursiveScanDir($dir, &$results = array()){
|
|
|
|
|
+ $files = scandir($dir);
|
|
|
|
|
+
|
|
|
|
|
+ foreach($files as $key => $value){
|
|
|
|
|
+ $path = realpath($dir . DIRECTORY_SEPARATOR . $value);
|
|
|
|
|
+ if(!is_dir($path)) {
|
|
|
|
|
+ $results[] = $path;
|
|
|
|
|
+ } else if(is_dir($path) && $value != "." && $value != "..") {
|
|
|
|
|
+ $results[$path] = array();
|
|
|
|
|
+ recursiveScanDir($path, $results[$path]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $results;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function in_array_r($needle, &$haystack, $strict = false) {
|
|
|
|
|
+ foreach ($haystack as $item) {
|
|
|
|
|
+ if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
|
|
|
|
|
+ echo $item;
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
?>
|
|
?>
|