|
| 1 | +<?php |
| 2 | + |
| 3 | +$FOLDER = "Notes"; |
| 4 | + |
| 5 | +\OCP\User::checkLoggedIn(); |
| 6 | +\OCP\App::checkAppEnabled('ownnote'); |
| 7 | + |
| 8 | +// Create directory if it doesn't exist |
| 9 | +if (!\OC\Files\Filesystem::is_dir($FOLDER)) { |
| 10 | + if (!\OC\Files\Filesystem::mkdir($FOLDER)) { |
| 11 | + echo "ERROR: Could not create ownNote directory."; |
| 12 | + exit; |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +function endswith($string, $test) { |
| 17 | + $strlen = strlen($string); |
| 18 | + $testlen = strlen($test); |
| 19 | + if ($testlen > $strlen) return false; |
| 20 | + return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0; |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +// Loop through and list files |
| 25 | +if ($listing = \OC\Files\Filesystem::opendir($FOLDER)) { |
| 26 | + if (!listing) { |
| 27 | + echo "ERROR: Error listing directory."; |
| 28 | + exit; |
| 29 | + } |
| 30 | + $now = new DateTime(); |
| 31 | + $filetime = new DateTime(); |
| 32 | + $delete = OCP\Util::imagePath('ownnote','delete.png'); |
| 33 | + $farray = array(); |
| 34 | + $count = 0; |
| 35 | + while (($file = readdir($listing)) !== false) { |
| 36 | + if ($file == "." || $file == "..") continue; |
| 37 | + if (!endswith($file, ".htm")) continue; |
| 38 | + if ($info = \OC\Files\Filesystem::getFileInfo($FOLDER."/".$file)) { |
| 39 | + $filetime->setTimestamp($info['mtime']); |
| 40 | + $difftime = $filetime->diff($now); |
| 41 | + $years = $difftime->y; |
| 42 | + $months = $difftime->m; |
| 43 | + $days = $difftime->d; |
| 44 | + $hours = $difftime->h; |
| 45 | + $minutes = $difftime->i; |
| 46 | + $seconds = $difftime->s; |
| 47 | + $timestring = ""; |
| 48 | + if ($timestring == "" && $years == 1) $timestring = "$years year"; |
| 49 | + if ($timestring == "" && $years > 0) $timestring = "$years years"; |
| 50 | + if ($timestring == "" && $months == 1) $timestring = "$months month"; |
| 51 | + if ($timestring == "" && $months > 0) $timestring = "$months months"; |
| 52 | + if ($timestring == "" && $days == 1) $timestring = "$days day"; |
| 53 | + if ($timestring == "" && $days > 0) $timestring = "$days days"; |
| 54 | + if ($timestring == "" && $hours == 1) $timestring = "$hours hour"; |
| 55 | + if ($timestring == "" && $hours > 0) $timestring = "$hours hours"; |
| 56 | + if ($timestring == "" && $minutes == 1) $timestring = "$minutes minute"; |
| 57 | + if ($timestring == "" && $minutes > 0) $timestring = "$minutes minutes"; |
| 58 | + if ($timestring == "" && $seconds == 1) $timestring = "$seconds second"; |
| 59 | + if ($timestring == "" && $seconds > 0) $timestring = "$seconds seconds"; |
| 60 | + $filename = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file); |
| 61 | + $group = ""; |
| 62 | + if (substr($filename,0,1) == "[") { |
| 63 | + $end = strpos($filename, ']'); |
| 64 | + $group = substr($filename, 1, $end-1); |
| 65 | + $filename = substr($filename, $end+1, strlen($filename)-$end+1); |
| 66 | + $filename = trim($filename); |
| 67 | + } |
| 68 | + $f = array(); |
| 69 | + $f['file'] = $file; |
| 70 | + $f['filename'] = $filename; |
| 71 | + $f['group'] = $group; |
| 72 | + $f['timestring'] = $timestring; |
| 73 | + $f['mtime'] = $info['mtime']; |
| 74 | + $f['timediff'] = $now->getTimestamp()-$info['mtime']; |
| 75 | + $farray[$count] = $f; |
| 76 | + $count++; |
| 77 | + } else { |
| 78 | + echo "ERROR: Error retrieving file information."; |
| 79 | + exit; |
| 80 | + } |
| 81 | + } |
| 82 | + echo json_encode($farray); |
| 83 | +} |
| 84 | + |
| 85 | +?> |
0 commit comments