GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Midgard Components Framework 3rd generation
Homepage: http://www.midgard-project.org
Clone URL: git://github.com/bergie/midcom.git
MOVE, PUT, MKCOL for snippets and snippetdirs. Removed locking until it is 
made operational again
bergie (author)
Fri Jun 27 07:30:51 -0700 2008
commit  679f4ee56bfd105a58436f700f87d183011bbddf
tree    4db4e3f844866027edec21cd40a14c888fb48d12
parent  8fd4b90c07403ad958bdc474f22df5251df05930
...
55
56
57
 
 
 
58
59
60
...
55
56
57
58
59
60
61
62
63
0
@@ -55,6 +55,9 @@ routes:
0
             - PROPFIND
0
             - OPTIONS
0
             - GET
0
+ - PUT
0
+ - MOVE
0
+ webdav_only: true
0
     page_edit:
0
         controller: midcom_core_controllers_page
0
         action: edit
...
13
14
15
 
 
 
 
16
17
18
19
20
21
 
22
23
24
...
30
31
32
33
 
34
35
 
36
37
 
 
 
 
 
 
 
 
 
 
 
38
39
40
41
42
43
44
45
46
47
48
...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
65
66
67
68
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
71
72
73
 
 
74
75
 
 
76
77
78
79
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
82
83
 
84
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
89
90
91
 
 
 
 
92
93
 
94
95
 
 
 
 
96
97
98
99
100
101
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
105
106
107
...
13
14
15
16
17
18
19
20
21
22
23
24
 
25
26
27
28
...
34
35
36
 
37
38
 
39
40
 
41
42
43
44
45
46
47
48
49
50
51
52
 
 
 
 
 
 
 
53
54
55
...
57
58
59
 
 
 
 
 
 
 
 
 
 
 
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
 
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
 
114
115
116
 
117
118
119
 
 
 
 
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
 
 
139
140
 
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
 
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
 
 
 
240
241
242
243
244
 
245
246
 
247
248
249
250
251
 
 
 
 
 
 
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
0
@@ -13,12 +13,16 @@
0
  */
0
 class midcom_core_controllers_snippets
0
 {
0
+ private $snippetdir = null;
0
+ private $snippet = null;
0
+ private $object_path = '';
0
+
0
     public function __construct($instance)
0
     {
0
         $this->configuration = $_MIDCOM->configuration;
0
     }
0
     
0
- private function get_snippetdir_children($snippetdir_id, $uri_prefix)
0
+ private function get_snippetdir_children($snippetdir_id)
0
     {
0
         // Load children for PROPFIND purposes
0
         $children = array();
0
@@ -30,19 +34,22 @@ class midcom_core_controllers_snippets
0
         $mc->add_value_property('description');
0
         $mc->execute();
0
         $snippetdirs = $mc->list_keys();
0
- foreach ($snippetdirs as $name => $array)
0
+ if (is_array($snippetdirs))
0
         {
0
- if (empty($name))
0
+ foreach ($snippetdirs as $name => $array)
0
             {
0
- continue;
0
+ if (empty($name))
0
+ {
0
+ continue;
0
+ }
0
+ $children[] = array
0
+ (
0
+ 'uri' => "{$_MIDCOM->context->prefix}__snippets{$this->object_path}/{$name}/", // FIXME: dispatcher::generate_url
0
+ 'title' => $name,
0
+ 'mimetype' => 'httpd/unix-directory',
0
+ 'resource' => 'collection',
0
+ );
0
             }
0
- $children[] = array
0
- (
0
- 'uri' => "{$uri_prefix}{$name}/", // FIXME: dispatcher::generate_url
0
- 'title' => $name,
0
- 'mimetype' => 'httpd/unix-directory',
0
- 'resource' => 'collection',
0
- );
0
         }
0
         
0
         // Snippets
0
@@ -50,57 +57,214 @@ class midcom_core_controllers_snippets
0
         $qb->add_constraint('up', '=', $snippetdir_id);
0
         $qb->add_constraint('sitegroup', '=', $_MIDGARD['sitegroup']);
0
         $qb->add_constraint('name', '<>', '');
0
- $snippets = $qb->execute();
0
- foreach ($snippets as $snippet)
0
- {
0
- $children[] = array
0
- (
0
- 'uri' => "{$uri_prefix}{$snippet->name}/", // FIXME: dispatcher::generate_url
0
- 'title' => $snippet->name,
0
- 'mimetype' => 'text/plain',
0
- 'size' => $snippet->metadata->size,
0
- 'revised' => $snippet->metadata->revised,
0
- );
0
+ $snippets = $qb->execute();
0
+ if (is_array($snippets))
0
+ {
0
+ foreach ($snippets as $snippet)
0
+ {
0
+ $children[] = array
0
+ (
0
+ 'uri' => "{$_MIDCOM->context->prefix}__snippets{$this->object_path}/{$snippet->name}.php", // FIXME: dispatcher::generate_url
0
+ 'title' => $snippet->name,
0
+ 'mimetype' => 'text/plain',
0
+ 'size' => $snippet->metadata->size,
0
+ 'revised' => $snippet->metadata->revised,
0
+ );
0
+ }
0
         }
0
         
0
         return $children;
0
     }
0
     
0
- public function action_webdav($route_id, &$data, $args)
0
+ private function get_snippetdir($object_path)
0
+ {
0
+ try
0
+ {
0
+ $snippetdir = new midgard_snippetdir();
0
+ $snippetdir->get_by_path($object_path);
0
+ }
0
+ catch (midgard_error_exception $e)
0
+ {
0
+ return false;
0
+ }
0
+ $this->snippetdir = $snippetdir;
0
+ return true;
0
+ }
0
+
0
+ private function get_snippet($object_path)
0
+ {
0
+ try
0
+ {
0
+ $snippet = new midgard_snippet();
0
+ $snippet->get_by_path(str_replace('.php', '', $object_path));
0
+ }
0
+ catch (midgard_error_exception $e)
0
+ {
0
+ return false;
0
+ }
0
+
0
+ $this->snippet = $snippet;
0
+ return true;
0
+ }
0
+
0
+ private function handle_propfind($route_id, &$data)
0
     {
0
         if ($route_id == 'snippets_root')
0
         {
0
- $data['children'] = $this->get_snippetdir_children(0, "{$_MIDCOM->context->prefix}__snippets/");
0
+ $data['children'] = $this->get_snippetdir_children(0);
0
+ return;
0
         }
0
- else
0
+
0
+ if (!$this->get_snippetdir($this->object_path))
0
         {
0
- // First we need to load the object
0
- $object_path = '/' . implode('/', $args['variable_arguments']);
0
-
0
- try
0
+ throw new midcom_exception_notfound("Snippetdir {$this->object_path} not found");
0
+ }
0
+
0
+ $data['children'] = $this->get_snippetdir_children($this->snippetdir->id);
0
+ }
0
+
0
+ private function handle_put($route_id, &$data)
0
+ {
0
+ if ( $route_id == 'snippets_root'
0
+ || $this->get_snippetdir($this->object_path))
0
+ {
0
+ throw new midcom_exception_httperror("PUT to snippetdir not allowed", 405);
0
+ }
0
+
0
+ if (!$this->get_snippet($this->object_path))
0
+ {
0
+ $parent_path = dirname($this->object_path);
0
+ if (!$this->get_snippetdir($parent_path))
0
             {
0
- $snippetdir = new midgard_snippetdir();
0
- $snippetdir->get_by_path($object_path);
0
+ throw new midcom_exception_notfound("Snippetdir {$parent_path} not found");
0
             }
0
- catch (midgard_error_exception $e)
0
+ $_MIDCOM->authorization->require_do('midgard:create', $this->snippetdir);
0
+
0
+ $new_snippet = new midgard_snippet();
0
+ $new_snippet->up = $this->snippetdir->id;
0
+ $new_snippet->name = basename(str_replace('.php', '', $this->object_path));
0
+ $new_snippet->create();
0
+ }
0
+ else
0
+ {
0
+ $new_snippet = $this->snippet;
0
+ }
0
+
0
+ $new_snippet->code = file_get_contents('php://input');
0
+ $new_snippet->update();
0
+ }
0
+
0
+ private function handle_mkcol($route_id, &$data)
0
+ {
0
+ if ( $this->get_snippet
0
+ || $this->snippetdir)
0
+ {
0
+ throw new midcom_exception_httperror("MKCOL not allowed", 405);
0
+ }
0
+
0
+ $parent_path = dirname($this->object_path);
0
+ if ( $parent_path != '/'
0
+ && !$this->get_snippetdir($parent_path))
0
+ {
0
+ throw new midcom_exception_notfound("Snippetdir {$parent_path} not found");
0
+ }
0
+
0
+ $new_snippetdir = new midgard_snippetdir();
0
+ $new_snippetdir->name = basename($this->object_path);
0
+
0
+ if ($parent_path != '/')
0
+ {
0
+ $_MIDCOM->authorization->require_do('midgard:create', $this->snippetdir);
0
+ $new_snippetdir->up = $this->snippetdir->id;
0
+ }
0
+
0
+ $new_snippetdir->create();
0
+ }
0
+
0
+ private function handle_move($route_id, &$data)
0
+ {
0
+ if (!isset($data['dest']))
0
+ {
0
+ throw new Exception("No destination defined");
0
+ }
0
+
0
+ $snippets_prefix = '__snippets';
0
+ if (substr($data['dest'], 0, strlen($snippets_prefix)) != $snippets_prefix)
0
+ {
0
+ throw new Exception("Invalid destination {$data['dest']}");
0
+ }
0
+
0
+ $destination_object_path = dirname(substr($data['dest'], strlen($snippets_prefix)));
0
+ if (!$this->get_snippetdir($destination_object_path))
0
+ {
0
+ throw new Exception("No snippetdir {$destination_object_path} found");
0
+ }
0
+
0
+ $destination_snippetdir = $this->snippetdir;
0
+
0
+ if (!$this->get_snippetdir($this->object_path))
0
+ {
0
+ // Possibly moving snippets instead
0
+ if (!$this->get_snippet($this->object_path))
0
             {
0
- try
0
+ throw new midcom_exception_notfound("Snippetdir {$this->object_path} not found");
0
+ }
0
+
0
+ $this->snippet->up = $destination_snippetdir->id;
0
+ $this->snippet->name = str_replace('.php', '', basename($data['dest']));
0
+ $this->snippet->update();
0
+ return;
0
+ }
0
+
0
+ $this->snippetdir->up = $destination_snippetdir->id;
0
+ $this->snippetdir->name = basename($data['dest']);
0
+ $this->snippetdir->update();
0
+ }
0
+
0
+ public function action_webdav($route_id, &$data, $args)
0
+ {
0
+ if ($route_id == 'snippets')
0
+ {
0
+ $this->object_path = '/' . implode('/', $args['variable_arguments']);
0
+ }
0
+
0
+ switch ($this->dispatcher->request_method)
0
+ {
0
+ case 'PROPFIND':
0
+ $this->handle_propfind($route_id, &$data);
0
+ return;
0
+
0
+ case 'GET':
0
+ if ($this->get_snippet($this->object_path))
0
                 {
0
- // This is possibly snippet instead
0
- $snippet = new midgard_snippet();
0
- $snippet->get_by_path($object_path);
0
+ $data['data'] = $this->snippet->code;
0
+ $data['mimetype'] = 'text/plain';
0
+ $data['mtime'] = strtotime($this->snippet->metadata->revised);
0
+ return;
0
                 }
0
- catch (midgard_error_exception $e)
0
+ elseif ($this->get_snippetdir($this->object_path))
0
                 {
0
- throw new midcom_exception_notfound("Code Snippet {$object_path} not found");
0
+ $data['mimetype'] = 'httpd/unix-directory';
0
+ $data['size'] = 0;
0
+ $data['mtime'] = strtotime($this->snippetdir->metadata->revised);
0
+ return;
0
                 }
0
- }
0
-
0
- if ($snippetdir->id)
0
- {
0
- $data['children'] = $this->get_snippetdir_children($snippetdir->id, "{$_MIDCOM->context->prefix}__snippets{$object_path}/");
0
- }
0
+
0
+ throw new midcom_exception_notfound("Snippetdir {$this->object_path} not found");
0
+
0
+ case 'PUT':
0
+ $this->handle_put($route_id, &$data);
0
+ return;
0
+
0
+ case 'MKCOL':
0
+ $this->handle_mkcol($route_id, &$data);
0
+ return;
0
+
0
+ case 'MOVE':
0
+ $this->handle_move($route_id, &$data);
0
+ return;
0
         }
0
+
0
     }
0
 }
0
 ?>
0
\ No newline at end of file
...
11
12
13
 
14
15
16
...
87
88
89
90
 
 
91
92
93
...
116
117
118
119
120
121
122
123
 
 
124
125
126
127
128
129
 
 
130
131
132
...
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
 
 
 
 
 
227
228
 
229
230
231
...
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
 
 
 
 
 
 
267
268
269
270
271
272
273
274
275
276
277
278
 
279
280
281
...
296
297
298
299
 
300
301
302
303
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
305
306
...
334
335
336
337
338
339
340
...
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
...
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
 
512
513
514
 
 
 
 
 
 
 
515
516
 
517
518
519
520
521
522
523
524
 
525
526
 
 
 
 
527
528
529
530
 
531
532
533
534
...
11
12
13
14
15
16
17
...
88
89
90
 
91
92
93
94
95
...
118
119
120
 
 
 
 
 
121
122
123
124
125
126
127
128
129
130
131
132
133
...
202
203
204
 
 
 
 
 
 
 
205
206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
208
209
210
211
212
 
213
214
215
216
...
221
222
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
225
226
227
228
229
230
231
 
 
 
 
 
 
 
 
 
 
 
232
233
234
235
...
250
251
252
 
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
...
304
305
306
 
307
308
309
...
326
327
328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
330
331
332
 
333
334
335
...
372
373
374
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375
376
377
 
378
379
380
381
382
383
384
385
 
386
387
 
 
 
 
 
 
 
388
389
 
390
391
392
393
394
 
 
 
395
396
397
398
399
0
@@ -11,6 +11,7 @@ require 'HTTP/WebDAV/Server.php';
0
 
0
 // The PATH_INFO needs to be provided so that creates will work
0
 $_SERVER['PATH_INFO'] = $_MIDCOM->context->uri;
0
+$_SERVER['SCRIPT_NAME'] = $_MIDCOM->context->prefix;
0
 
0
 /**
0
  * WebDAV server for MidCOM 3
0
@@ -87,7 +88,8 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
         $this->http_status("200 OK");
0
         
0
         // We support DAV levels 1 & 2
0
- header("DAV: 1, 2");
0
+ // header("DAV: 1, 2"); TODO: Re-enable when we support locks
0
+ header("DAV: 1");
0
         
0
         header("Content-length: 0");
0
     }
0
@@ -116,17 +118,16 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
             $data['children'] = $this->get_node_children($page);
0
         }
0
         
0
- if (!empty($data['children']))
0
- {
0
- // Convert children to PROPFIND elements
0
- $this->children_to_files($data['children'], &$files);
0
- }
0
+ // Convert children to PROPFIND elements
0
+ $this->children_to_files($data['children'], &$files);
0
         
0
         return true;
0
     }
0
 
0
     private function children_to_files($children, &$files)
0
     {
0
+ $files['files'] = array();
0
+
0
         foreach ($children as $child)
0
         {
0
             $child_props = array
0
@@ -201,31 +202,15 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
      */
0
     function GET(&$options)
0
     {
0
- $info = $this->get_path_info();
0
-
0
- if (is_null($info['object']))
0
- {
0
- throw new midcom_exception_notfound("Not found");
0
- }
0
-
0
         $_MIDCOM->authorization->require_user();
0
 
0
- switch ($info['variant'])
0
- {
0
- case 'content_html':
0
- $options['data'] = $info['object']->content;
0
- $options['mimetype'] = 'text/html';
0
- $options['mtime'] = $info['object']->metadata->revised;
0
- return true;
0
- /*case 'object_xml':
0
- $options['data'] = $info['object']->serialize();
0
- $options['mimetype'] = 'text/xml';
0
- $options['mtime'] = $info['object']->metadata->revised;*/
0
- default:
0
- throw new midcom_exception_notfound("Not found");
0
- }
0
+ // Run the controller
0
+ $controller = $this->controller;
0
+ $action_method = $this->action_method;
0
+ $data =& $options;
0
+ $controller->$action_method($this->route_id, $data, $this->action_arguments);
0
         
0
- throw new midcom_exception_notfound('No route matches current URL');
0
+ return true;
0
     }
0
 
0
     /**
0
@@ -236,46 +221,15 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
      */
0
     function PUT(&$options)
0
     {
0
- $info = $this->get_path_info($options['path']);
0
-
0
- if (is_null($info['object']))
0
- {
0
- // Creation support
0
- if (is_null($info['parent']))
0
- {
0
- $this->logger->log("No parent known");
0
- throw new midcom_exception_notfound("Not found");
0
- }
0
-
0
- $_MIDCOM->authorization->require_do('midgard:create', $info['parent']);
0
-
0
- $this->logger->log("Trying to create {$options['path']}.");
0
-
0
- $file_type = pathinfo($options['path'], PATHINFO_EXTENSION);
0
- switch ($file_type)
0
- {
0
- case 'html':
0
- $info['object'] = $info['parent'];
0
- $info['variant'] = 'content_html';
0
- break;
0
- default:
0
- return "415 Unsupported media type";
0
- }
0
- }
0
-
0
         $_MIDCOM->authorization->require_user();
0
+
0
+ // Run the controller
0
+ $controller = $this->controller;
0
+ $action_method = $this->action_method;
0
+ $data =& $options;
0
+ $controller->$action_method($this->route_id, $data, $this->action_arguments);
0
         
0
- $_MIDCOM->authorization->require_do('midgard:update', $info['object']);
0
-
0
- switch ($info['variant'])
0
- {
0
- case 'content_html':
0
- $info['object']->content = file_get_contents('php://input');
0
- $info['object']->update();
0
- return true;
0
- default:
0
- return '405 Method Not Allowed';
0
- }
0
+ return true;
0
     }
0
 
0
     /**
0
@@ -296,11 +250,27 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
     }
0
 
0
     /**
0
- * LOCK method handler
0
+ * MOVE method handler
0
      *
0
      * @param array general parameter passing array
0
      * @return bool true on success
0
      */
0
+ function MOVE($options)
0
+ {
0
+ // Run the controller
0
+ $controller = $this->controller;
0
+ $action_method = $this->action_method;
0
+ $data =& $options;
0
+ $controller->$action_method($this->route_id, $data, $this->action_arguments);
0
+
0
+ return true;
0
+ }
0
+
0
+ /**
0
+ * LOCK method handler
0
+ *
0
+ * @param array general parameter passing array
0
+ * @return bool true on success
0
     function LOCK(&$options)
0
     {
0
         $this->logger->log("Options: " . serialize($options));
0
@@ -334,7 +304,6 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
      *
0
      * @param array general parameter passing array
0
      * @return bool true on success
0
- */
0
     function UNLOCK(&$options)
0
     {
0
         $info = $this->get_path_info();
0
@@ -357,32 +326,10 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
     }
0
 
0
     /**
0
- * No authentication is needed here
0
- *
0
- * @access private
0
- * @param string HTTP Authentication type (Basic, Digest, ...)
0
- * @param string Username
0
- * @param string Password
0
- * @return bool true on successful authentication
0
- */
0
- function checkAuth($type, $user, $pass)
0
- {
0
- if (!$_MIDCOM->authentication->is_user())
0
- {
0
- if (!$_MIDCOM->authentication->login($username, $password))
0
- {
0
- return false;
0
- }
0
- }
0
- return true;
0
- }
0
-
0
- /**
0
      * checkLock() helper
0
      *
0
      * @param string resource path to check for locks
0
      * @return bool true on success
0
- */
0
     function checkLock($path)
0
     {
0
         $this->logger->log("checkLock {$path}");
0
@@ -425,109 +372,27 @@ class midcom_core_helpers_webdav extends HTTP_WebDAV_Server
0
         $this->logger->log(serialize($lock));
0
         return $lock;
0
     }
0
-
0
- private function get_path_info($path = null)
0
- {
0
- if (is_null($path))
0
- {
0
- $local_path = implode('/', $_MIDCOM->dispatcher->argv);
0
- $this->logger->log("Get path info \"{$local_path}\" from ARGV");
0
- }
0
- else
0
- {
0
- $local_path = substr($path, strlen($_MIDCOM->context->prefix));
0
- $this->logger->log("Get path info \"{$local_path}\" from OPTIONS");
0
- }
0
- $path = $local_path;
0
-
0
- static $info = array();
0
- if (isset($info[$path]))
0
- {
0
- return $info[$path];
0
- }
0
-
0
- $current_page = new midgard_page($_MIDCOM->context->page['guid']);
0
-
0
- $argv = array();
0
- $args = explode('/', $path);
0
- foreach ($args as $arg)
0
- {
0
- if (empty($arg))
0
- {
0
- continue;
0
- }
0
- $argv[] = $arg;
0
- }
0
-
0
- $info[$path] = array
0
- (
0
- 'object' => null,
0
- 'parent' => null,
0
- 'variant' => 'default',
0
- );
0
-
0
- /*if ($_MIDCOM->context->page['id'] == $_MIDCOM->context->host->root)
0
- {
0
- // We're at MidCOM host root page, handle special URL cases
0
- }*/
0
-
0
- if (count($argv) == 0)
0
- {
0
- $info[$path]['object'] = $current_page;
0
- $info[$path]['variant'] = 'collection';
0
- return $info[$path];
0
- }
0
-
0
- if (count($argv) == 1)
0
- {
0
- // Only one argument, check it
0
- switch ($argv[0])
0
- {
0
- case '__content.html':
0
- $info[$path]['object'] = $current_page;
0
- $info[$path]['variant'] = 'content_html';
0
- return $info[$path];
0
- /*case '__midgard_page.xml':
0
- $info[$path]['object'] = $current_page;
0
- $info[$path]['variant'] = 'object_xml';
0
- return $info[$path];*/
0
- default:
0
- $info[$path]['parent'] = $current_page;
0
- $qb = midgard_page::new_query_builder();
0
- $qb->add_constraint('up', '=', $current_page->id);
0
- $qb->add_constraint('name', '=', $argv[0]);
0
- $pages = $qb->execute();
0
- if (count($pages) > 0)
0
- {
0
- $info[$path]['object'] = $pages[0];
0
- $info[$path]['variant'] = 'collection';
0
- return $info[$path];
0
- }
0
- break;
0
- }
0
- }
0
-
0
- return $info[$path];
0
- }
0
+ */
0
 
0
     /**
0
- * Logging method for WebDAV debugging
0
+ * No authentication is needed here
0
+ *
0
+ * @access private
0
+ * @param string HTTP Authentication type (Basic, Digest, ...)
0
+ * @param string Username
0
+ * @param string Password
0
+ * @return bool true on successful authentication
0
      */
0
- private function add_to_log($string, $addtime = true)
0
+ function checkAuth($type, $user, $pass)
0
     {
0
- $log_file = fopen('/tmp/midcom-webdav.log', 'a');
0
- if (!$log_file)
0
- {
0
- return;
0
- }
0
-
0
- if ($addtime)
0
+ if (!$_MIDCOM->authentication->is_user())
0
         {
0
- $string = date('r') . ": {$string}";
0
+ if (!$_MIDCOM->authentication->login($username, $password))
0
+ {
0
+ return false;
0
+ }
0
         }
0
-
0
- fwrite($log_file, "{$string}\n");
0
- fclose($log_file);
0
+ return true;
0
     }
0
 }
0
 ?>
0
\ No newline at end of file
...
237
238
239
240
 
 
 
 
 
241
242
243
244
245
246
247
248
249
250
 
 
 
 
251
252
253
...
237
238
239
 
240
241
242
243
244
245
 
 
 
 
 
 
 
 
 
246
247
248
249
250
251
252
0
@@ -237,17 +237,16 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
         $action_method = "action_{$selected_route_configuration['action']}";
0
         
0
         // Handle HTTP request
0
- switch ($this->request_method)
0
+ if ( isset($selected_route_configuration['webdav_only'])
0
+ && $selected_route_configuration['webdav_only']
0
+ || ( $this->request_method != 'GET'
0
+ && $this->request_method != 'POST')
0
+ )
0
         {
0
- case 'GET':
0
- case 'POST':
0
- // Short-cut these types directly to the controller
0
- break;
0
- default:
0
- // For others, start the full WebDAV server instance
0
- $webdav_server = new midcom_core_helpers_webdav($controller);
0
- $webdav_server->serve($this->route_id, $action_method, $this->action_arguments);
0
- // This will exit
0
+ // Start the full WebDAV server instance
0
+ $webdav_server = new midcom_core_helpers_webdav($controller);
0
+ $webdav_server->serve($this->route_id, $action_method, $this->action_arguments);
0
+ // This will exit
0
         }
0
 
0
         // TODO: store this array somewhere where it can be accessed via get_context_item

Comments

    No one has commented yet.