File dav/method/GET.class.php
Last commit: Thu Nov 7 01:07:03 2019 +0100 Jan Dankert No direct calls any more. All data of the CMS is transferred via the API within an array.
1 <?php 2 3 class DAV_GET extends DAV 4 { 5 6 /** 7 * WebDav-GET-Methode. 8 * Die gew�nschte Datei wird geladen und im HTTP-Body mitgeliefert. 9 */ 10 public function execute() 11 { 12 switch( $this->request->type ) 13 { 14 case 'root': 15 case 'folder': 16 $this->getDirectoryIndex(); 17 break; 18 19 case 'page': 20 $this->httpStatus( '200 OK' ); 21 header('Content-Type: text/html'); 22 23 echo '<html><head><title>OpenRat WEBDAV Access</title></head>'; 24 echo '<body>'; 25 echo '<h1>'.$this->request->type.'</h1>'; 26 echo '<pre>'; 27 echo 'No Content available'; 28 echo '</pre>'; 29 echo '</body>'; 30 echo '</html>'; 31 break; 32 33 case 'link': 34 $this->httpStatus( '200 OK' ); 35 36 header('Content-Type: text/plain'); 37 38 $link = $this->client->link( $this->request->objectid ); 39 echo 'url: ' .$link['url'] ."\n"; 40 echo 'target-id: '.$link['linkedObjectId']."\n"; 41 42 break; 43 44 case 'file': 45 case 'image': 46 case 'text': 47 $this->httpStatus( '200 OK' ); 48 49 $file = $this->client->file ( $this->request->objectid ); 50 $filevalue = $this->client->filevalue( $this->request->objectid ); 51 52 header('Content-Type: '.$file['mimetype']); 53 header('X-File-Id: ' .$this->request->objectid ); 54 55 // Angabe Content-Disposition 56 // - Bild soll "inline" gezeigt werden 57 // - Dateiname wird benutzt, wenn der Browser das Bild speichern moechte 58 header('Content-Disposition: inline; filename='.$file['filename'].'.'.$file['extension'] ); 59 header('Content-Transfer-Encoding: binary' ); 60 header('Content-Description: '.$file['filename'].'.'.$file['extension'] ); 61 62 // Groesse des Bildes in Bytes 63 // Der Browser hat so die Moeglichkeit, einen Fortschrittsbalken zu zeigen 64 header('Content-Length: '.$file['size'] ); 65 66 echo $filevalue['value']; 67 68 break; 69 70 default: 71 $this->httpStatus( '200 OK' ); 72 header('Content-Type: text/html'); 73 74 echo '<html><head><title>OpenRat WEBDAV Access</title></head>'; 75 echo '<body>'; 76 echo '<h1>'.$this->request->type.'</h1>'; 77 echo '<pre>'; 78 echo 'Unknown node type: '.$this->request->type; 79 echo '</pre>'; 80 echo '</body>'; 81 echo '</html>'; 82 break; 83 84 85 } 86 } 87 88 89 90 91 /** 92 * Erzeugt ein Unix-�hnliche Ausgabe des Verzeichnisses als HTML. 93 */ 94 protected function getDirectoryIndex() 95 { 96 $this->httpStatus( '200 OK' ); 97 98 // Verzeichnis ausgeben 99 header('Content-Type: text/html'); 100 $nl = "\n"; 101 102 103 104 105 $titel = 'Index of '.htmlspecialchars($this->sitePath); 106 $format = "%15s %-19s %-s\n"; 107 108 echo '<html><head><title>'.$titel.'</title></head>'; 109 echo '<body>'; 110 echo '<h1>'.$titel.'</h1>'.$nl; 111 echo '<pre>'; 112 113 printf($format, "Size", "Last modified", "Filename"); 114 115 116 switch( $this->request->type ) 117 { 118 case 'root': // Projektliste 119 120 $result = $this->client->projectlist(); 121 $projects = $result['projects']; 122 foreach( $projects as $projectid=>$p ) 123 { 124 echo '<a href="'.$p['name'].'">'.$p['name'].'</a>'.$nl; 125 } 126 break; 127 128 case 'folder': // Verzeichnisinhalt 129 130 $folder = $this->client->folder( $this->request->objectid ); 131 132 foreach( $folder['content']['object'] as $object ) 133 { 134 135 printf($format, 136 number_format(1), 137 strftime("%Y-%m-%d %H:%M:%S",$object['date'] ), 138 '<a href="./'.$object['filename'].'">'.$object['filename'].'</a>'); 139 echo $nl; 140 141 } 142 } 143 144 echo '</pre>'; 145 echo '</body>'; 146 echo '</html>'; 147 } 148 149 150 151 152 }
Downloaddav/method/GET.class.php
History Thu, 7 Nov 2019 01:07:03 +0100 Jan Dankert No direct calls any more. All data of the CMS is transferred via the API within an array. Mon, 4 Nov 2019 23:56:38 +0100 Jan Dankert Refactoring: Renaming WebDAV to DAV base class. Mon, 4 Nov 2019 23:54:13 +0100 Jan Dankert Refactoring: Splitting DAV methods into single files.