openrat-webdav

git clone http://git.code.weiherhei.de/openrat-webdav.git
Log | Files | Refs | README

PROPFIND.class.php (8552B)


      1 <?php
      2 
      3 class DAV_PROPFIND extends DAV
      4 {
      5 
      6 	/**
      7 	 * WebDav-Methode PROPFIND.
      8 	 * 
      9 	 * Diese Methode wird
     10 	 * - beim Ermitteln von Verzeichnisinhalten und
     11 	 * - beim Ermitteln von Metainformationen zu einer Datei
     12 	 * verwendet.
     13 	 * 
     14 	 * Das Ergebnis wird in einer XML-Zeichenkette geliefert.
     15 	 */	
     16 	public function execute()
     17 	{
     18 		switch( $this->request->type )
     19 		{
     20 			case 'root':  // Projektliste
     21 				
     22 				$inhalte = array();
     23 				
     24 				$objektinhalt = array();
     25 				$z = 30*365.25*24*60*60;
     26 				$objektinhalt['createdate'    ] = $z;
     27 				$objektinhalt['lastchangedate'] = $z;
     28 				$objektinhalt['size'          ] = 1;
     29 				$objektinhalt['name'          ] = $this->sitePath;
     30 				$objektinhalt['displayname'   ] = '';
     31 				$objektinhalt['type']           = 'folder';
     32 
     33 				$inhalte[] = $objektinhalt;
     34 
     35 				try {
     36                     $result = $this->client->projectlist();
     37                 } catch( Exception $e) {
     38 				    Logger::error($e->__toString().$this->client->__toString());
     39 				    throw $e;
     40                 }
     41 				$projects = $result['projects'];
     42 				foreach( $projects as $projectid=>$p )
     43 				{
     44 					$objektinhalt = array();
     45 					$objektinhalt['createdate'    ] = TIME_20000101;
     46 					$objektinhalt['lastchangedate'] = TIME_20000101;
     47 					$objektinhalt['size'          ] = 1;
     48 					$objektinhalt['name'          ] = $this->sitePath.$p['name'].'/';
     49 					$objektinhalt['displayname'   ] = $p['name'];
     50 					$objektinhalt['type']           = 'folder';
     51 					$inhalte[] = $objektinhalt;
     52 				}
     53 					
     54 				$this->multiStatus( $inhalte );
     55 				break;
     56 
     57 			case 'folder':  // Verzeichnisinhalt
     58 
     59 				$folder = $this->client->folder( $this->request->objectid );
     60 
     61 				$inhalte = array();
     62 
     63 				$objektinhalt = array();
     64 				$objektinhalt['createdate'    ] = $folder['properties']['create_date'];
     65 				$objektinhalt['lastchangedate'] = $folder['properties']['lastchange_date'];
     66 				$objektinhalt['name'          ] = $this->sitePath;
     67 				$objektinhalt['displayname'   ] = $folder['properties']['filename'];
     68 				$objektinhalt['type'          ] = 'folder';
     69 				$objektinhalt['size'          ] = 0;
     70 
     71 				$inhalte[] = $objektinhalt;
     72 					
     73 				if	( $this->depth > 0 )
     74 				{
     75 					
     76 					foreach( $folder['content']['object'] as $object )
     77 					{
     78 						$objektinhalt = array();
     79 						$objektinhalt['createdate'    ] = $object['date'];
     80 						$objektinhalt['lastchangedate'] = $object['date'];
     81 						$objektinhalt['displayname'   ] = $object['filename'];
     82 
     83 						switch( $object['type'] )
     84 						{
     85 							case 'folder':
     86 								$objektinhalt['name'] = $this->sitePath.$object['filename'].'/';
     87 								$objektinhalt['type'] = 'folder';
     88 								$objektinhalt['size'] = 0;
     89 								$inhalte[] = $objektinhalt;
     90 								break;
     91 							case 'file':
     92 							case 'image':
     93 							case 'text':
     94 								$objektinhalt['name'] = $this->sitePath.$object['filename'];
     95 								$objektinhalt['type'] = 'file';
     96 								$objektinhalt['size'] = $object['size'];
     97 								$objektinhalt['mime'] = 'application/x-non-readable';
     98 								$inhalte[] = $objektinhalt;
     99 								break;
    100 							case 'link':
    101 								$objektinhalt['name'] = $this->sitePath.$object['filename'];
    102 								$objektinhalt['type'] = 'file';
    103 								$objektinhalt['size'] = 0;
    104 								$objektinhalt['mime'] = 'application/x-non-readable';
    105 								$inhalte[] = $objektinhalt;
    106 								break;
    107 							case 'url':
    108 							case 'alias':
    109 								$objektinhalt['name'] = $this->sitePath.$object['filename'];
    110 								$objektinhalt['type'] = 'file';
    111 								$objektinhalt['size'] = 0;
    112 								$objektinhalt['mime'] = 'application/x-non-readable';
    113 								$inhalte[] = $objektinhalt;
    114 								break;
    115 							case 'page':
    116 								$objektinhalt['name'] = $this->sitePath.$object['filename'];
    117 								$objektinhalt['type'] = 'file';
    118 								$objektinhalt['size'] = 0;
    119 								$inhalte[] = $objektinhalt;
    120 								break;
    121 							default:
    122 						}
    123 					}
    124 				}
    125 				$this->multiStatus( $inhalte );
    126 				break;
    127 				
    128 			case 'page':
    129 				$page = $this->client->page( $this->request->objectid );
    130 				$prop = $page['properties'];
    131 				$objektinhalt = array();
    132 				$objektinhalt['name']           = $this->sitePath;
    133 				$objektinhalt['displayname']    = $prop['filename'];
    134 				$objektinhalt['createdate'    ] = $prop['date'];
    135 				$objektinhalt['lastchangedate'] = $prop['date'];
    136 				
    137 				$objektinhalt['size'          ] = 0;
    138 				$objektinhalt['type'          ] = 'file';
    139 
    140                 $this->multiStatus( array($objektinhalt) );
    141 
    142                 break;
    143 				
    144 			case 'file':
    145 			case 'text':
    146 			case 'image':
    147 				$file = $this->client->file( $this->request->objectid );
    148 				$objektinhalt = array();
    149 				$objektinhalt['name']           = $this->sitePath;
    150 				$objektinhalt['displayname']    = $file['filename'];
    151 				$objektinhalt['createdate'    ] = $file['date'];
    152 				$objektinhalt['lastchangedate'] = $file['date'];
    153 				
    154 				$objektinhalt['size'          ] = $file['size'];
    155 				$objektinhalt['type'          ] = 'file';
    156 
    157                 $this->multiStatus( array($objektinhalt) );
    158 
    159             break;
    160 				
    161 			case 'link':
    162 				
    163 				$link = $this->client->link( $this->request->objectid );
    164 				
    165 				$objektinhalt = array();
    166 				$objektinhalt['name']           = $this->sitePath;
    167 				$objektinhalt['displayname']    = $link['filename'];
    168 				$objektinhalt['createdate'    ] = $link['date'];
    169 				$objektinhalt['lastchangedate'] = $link['date'];
    170 
    171 				$objektinhalt['size'          ] = 0;
    172 				$objektinhalt['type'          ] = 'file';
    173 				
    174 				
    175 				$this->multiStatus( array($objektinhalt) );
    176 				
    177 				break;
    178 				
    179 			case 'url':
    180 
    181 				$link = $this->client->link( $this->request->objectid );
    182 
    183 				$objektinhalt = array();
    184 				$objektinhalt['name']           = $this->sitePath;
    185 				$objektinhalt['displayname']    = $link['filename'];
    186 				$objektinhalt['createdate'    ] = $link['date'];
    187 				$objektinhalt['lastchangedate'] = $link['date'];
    188 
    189 				$objektinhalt['size'          ] = 0;
    190 				$objektinhalt['type'          ] = 'file';
    191 
    192 
    193 				$this->multiStatus( array($objektinhalt) );
    194 
    195 				break;
    196 
    197 			default:
    198 				Logger::warn('Internal Error, unknown request type: '. $this->request->type);
    199 				$this->httpStatus('500 Internal Server Error');
    200 		}
    201 	}
    202 
    203 
    204 
    205 
    206     /**
    207      * Erzeugt einen Multi-Status.
    208      * @access private
    209      */
    210     protected function multiStatus( $files )
    211     {
    212         $this->httpStatus('207 Multi-Status');
    213         header('Content-Type: text/xml; charset=utf-8');
    214 
    215         $response = '';
    216         $response .= '<?xml version="1.0" encoding="utf-8" ?>';
    217         $response .= '<d:multistatus xmlns:d="DAV:">';
    218 
    219         foreach( $files as $file )
    220             $response .= $this->getResponse( $file['name'],$file );
    221 
    222         $response .= '</d:multistatus>';
    223 
    224         $response = utf8_encode($response);
    225 
    226         header('Content-Length: '.strlen($response));
    227         Logger::trace('Sending Multistatus:'."\n".$response);
    228         echo $response;
    229     }
    230 
    231 
    232     /**
    233      * Erzeugt ein "response"-Element, welches in ein "multistatus"-element verwendet werden kann.
    234      */
    235     protected function getResponse( $file,$options )
    236     {
    237         // TODO: Nur angeforderte Elemente erzeugen.
    238         $response = '';
    239         $response .= '<d:response>';
    240         $response .= '<d:href>'.$file.'</d:href>';
    241         $response .= '<d:propstat>';
    242         $response .= '<d:prop>';
    243         //		$response .= '<d:source></d:source>';
    244         $response .= '<d:creationdate>'.date('r',$options['createdate']).'</d:creationdate>';
    245         $response .= '<d:displayname>'.$options['displayname'].'</d:displayname>';
    246         $response .= '<d:getcontentlength>'.$options['size'].'</d:getcontentlength>';
    247         $response .= '<d:getlastmodified xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" b:dt="dateTime.rfc1123">'.date('r',$options['lastchangedate']).'</d:getlastmodified>';
    248 
    249         if	( $options['type'] == 'folder')
    250             $response .= '<d:resourcetype><d:collection/></d:resourcetype>';
    251         else
    252             $response .= '<d:resourcetype />';
    253 
    254         $response .= '<d:categories />';
    255         $response .= '<d:fields></d:fields>';
    256 
    257 
    258 
    259 //		$response .= '<d:getcontenttype>text/html</d:getcontenttype>';
    260 //		$response .= '<d:getcontentlength />';
    261 //		$response .= '<d:getcontentlanguage />';
    262 //		$response .= '<d:executable />';
    263 //		$response .= '<d:resourcetype>';
    264 //		$response .= '<d:collection />';
    265 //		$response .= '</d:resourcetype>';
    266 //		$response .= '<d:getetag />';
    267 
    268         $response .= '</d:prop>';
    269         $response .= '<d:status>HTTP/1.1 200 OK</d:status>';
    270         $response .= '</d:propstat>';
    271         $response .= '</d:response>';
    272 
    273         return $response;
    274     }
    275 
    276 
    277 }