Welcome to mirror list, hosted at ThFree Co, Russian Federation.

NoteUtils.php « Misc « lib - github.com/CarnetApp/CarnetNextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f191bb8ddc4bb81ddafeccd6524c0a99c5ce688 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace OCA\Carnet\Misc;
class NoteUtils{
    public static $defaultCarnetNotePath = "Documents/QuickNote";
    public function getMetadata($carnetFolder, $path){
        $meta = array();
        $tmppath = tempnam(sys_get_temp_dir(), uniqid().".zip");
        $node = $carnetFolder->get($path);
        
        file_put_contents($tmppath, $node->fopen("r"));
            $zipFile = new \PhpZip\ZipFile();
            $zipFile->openFromStream(fopen($tmppath, "r")); //issue with encryption when open directly + unexpectedly faster to copy before Oo'
            $meta['lastmodfile'] = $node->getMTime();
            try{
                $meta['metadata'] = json_decode($zipFile->getEntryContents("metadata.json"));
            } catch(\PhpZip\Exception\ZipNotFoundEntry $e){
            
            }
            try{
            
            $meta['shorttext'] = mb_substr(trim(preg_replace('#<[^>]+>#', ' ', $zipFile->getEntryContents("index.html"))),0, 150);
            $i=0;
            try{
                foreach($zipFile->getListFiles() as $f){
                    if(substr($f, 0, strlen("data/preview")) === "data/preview"){

                        $meta['previews'][$i] = "./note/getmedia?note=".$path."&media=".$f;
                        $i++;
                        if($i>2)
                            break;
                    }
                    
                }
            }
            catch(\PhpZip\Exception\ZipNotFoundEntry $e){
                
            }
        } catch(\PhpZip\Exception\ZipNotFoundEntry $e){
            $meta['shorttext'] = "";
            
        }
        unlink($tmppath);
        return $meta;
        
    }
}
?>