~ubuntu-branches/ubuntu/lucid/gallery2/lucid

« back to all changes in this revision

Viewing changes to modules/webdav/classes/WebDavHelper.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2007-09-10 20:22:19 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070910202219-0jsuntvqge4ade6b
Tags: 2.2.3-2
Add Slovak translation of Debconf templates.  (Thanks to 
Ivan Masá.  Closes: #441671)

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 * @package WebDav
42
42
 * @subpackage Classes
43
43
 * @author Jack Bates <ms419@freezone.co.uk>
44
 
 * @version $Revision: 16012 $
 
44
 * @version $Revision: 16994 $
45
45
 * @static
46
46
 */
47
47
class WebDavHelper {
322
322
    }
323
323
 
324
324
    /**
 
325
     * Take two entities of possibly different classes and make the second entity as close a copy of
 
326
     * the first entity as possible.  Copy the id but not the entity type because the entity type
 
327
     * must always match the class name.
 
328
     * @param object GalleryEntity $sourceEntity entity to copy from
 
329
     * @param object GalleryEntity $mirrorEntity entity to copy to
 
330
     * @return array object GalleryStatus a status code
 
331
     *               object GalleryEntity the mirror entity
 
332
     */
 
333
    function mirrorEntity($sourceEntity, $mirrorEntity) {
 
334
        $className = $mirrorClassName = $mirrorEntity->getClassName();
 
335
        list ($ret, $entityInfo) = GalleryCoreApi::describeEntity($className);
 
336
        if ($ret) {
 
337
            return array($ret, null);
 
338
        }
 
339
 
 
340
        list ($ret, $memberAccessInfo) =
 
341
            GalleryCoreApi::getExternalAccessMemberList($className);
 
342
        if ($ret) {
 
343
            return array($ret, null);
 
344
        }
 
345
        /* We need to override id and pathComponent */
 
346
        $override = array('id', 'pathComponent');
 
347
 
 
348
        /*
 
349
         * Walk down the mirror entity's class hierarchy copying class members from the source
 
350
         * entity if they are defined
 
351
         */
 
352
        while (!empty($className)) {
 
353
            foreach ($entityInfo[$className]['members'] as $memberName => $memberInfo) {
 
354
                if (isset($sourceEntity->$memberName)
 
355
                        && (!empty($memberAccessInfo[$memberName]['write'])
 
356
                            || in_array($memberName, $override))) {
 
357
                    $mirrorEntity->$memberName = $sourceEntity->$memberName;
 
358
                }
 
359
            }
 
360
 
 
361
            $className = $entityInfo[$className]['parent'];
 
362
        }
 
363
 
 
364
        /*
 
365
         * Reset the entity type to the mirror entity's class name because the entity type must
 
366
         * always match the class name
 
367
         */
 
368
        $mirrorEntity->entityType = $mirrorClassName;
 
369
 
 
370
        return array(null, $mirrorEntity);
 
371
    }
 
372
 
 
373
    /**
325
374
     * Get singleton WebDAV server library instance.
326
375
     *
327
376
     * If it didn't need path and baseUrl, we could eliminate and call library methods staticly.
525
574
        if ($ret) {
526
575
            return $ret;
527
576
        }
 
577
        $depth = trim(GalleryUtilities::strToLower($depth));
528
578
 
529
579
        $path = GalleryUtilities::getRequestVariables('path');
530
580
        $path = trim($path, '/');
546
596
            return $ret;
547
597
        }
548
598
 
 
599
        $ret = GalleryCoreApi::assertHasItemPermission($itemId, 'core.view');
 
600
        if ($ret) {
 
601
            return $ret;
 
602
        }
 
603
 
549
604
        $files = array();
550
605
        $ret = WebDavHelper::_propfindFiles($item, $path, $depth, $files);
551
606
        if ($ret) {
669
724
 
670
725
        $files[] = $file;
671
726
 
672
 
        if ($depth <= 0) {
 
727
        if (!$item->getCanContainChildren() || $depth != 'infinity' && $depth <= 0) {
673
728
            return null;
674
729
        }
675
730
 
694
749
                $childPath = "$path/" . $childPath;
695
750
            }
696
751
 
697
 
            $ret = WebDavHelper::_propfindFiles($childItem, $childPath, $depth - 1, $files);
 
752
            $ret = WebDavHelper::_propfindFiles($childItem, $childPath,
 
753
                $depth == 'infinity' ? $depth : $depth - 1,
 
754
                $files);
698
755
            if ($ret) {
699
756
                return $ret;
700
757
            }
779
836
            return $ret;
780
837
        }
781
838
 
 
839
        $ret = GalleryCoreApi::assertHasItemPermission($itemId, 'core.edit');
 
840
        if ($ret) {
 
841
            return $ret;
 
842
        }
 
843
 
782
844
        /* Prepare data-structure from PROPPATCH request */
783
845
        list ($ret, $webDavOptions, $props) = WebDavHelper::proppatchRequestHelper();
784
846
        if ($ret) {
1264
1326
            $error[] = 'form[error][destination][empty]';
1265
1327
        }
1266
1328
 
1267
 
        if (!empty($newParent)) {
 
1329
        if (empty($error)) {
1268
1330
            $newParentId = $newParent->getId();
1269
1331
 
1270
1332
            list ($ret, $permissions) = GalleryCoreApi::getPermissions($newParentId);
1277
1339
            if (!$canAddAlbum && !$canAddItem) {
1278
1340
                $error[] = 'form[error][destination][permission]';
1279
1341
            }
 
1342
        }
1280
1343
 
 
1344
        if (empty($error)) {
1281
1345
            if (!GalleryUtilities::isA($newParent, 'GalleryAlbumItem')) {
1282
1346
                /* The view should never let this happen */
1283
1347
                return array(GalleryCoreApi::error(ERROR_BAD_DATA_TYPE), null);
1430
1494
                /* If all errors were permission denied return more specific error */
1431
1495
                return GalleryCoreApi::error(ERROR_PERMISSION_DENIED);
1432
1496
            }
 
1497
        } else {
 
1498
            $ret = GalleryCoreApi::assertHasItemPermission($item->getId(), 'core.edit');
 
1499
            if ($ret) {
 
1500
                return $ret;
 
1501
            }
1433
1502
        }
1434
1503
 
1435
1504
        list ($ret, $conflictingItemId) = GalleryCoreApi::fetchItemIdByPath($newPath);
1692
1761
            }
1693
1762
        }
1694
1763
 
 
1764
        list ($ret, $permissions) = GalleryCoreApi::fetchPermissionsForItems(array($itemId));
 
1765
        if ($ret) {
 
1766
            return $ret;
 
1767
        }
 
1768
        if (empty($permissions[$itemId]['core.edit'])
 
1769
                && empty($permissions[$itemId]['core.delete'])) {
 
1770
            return GalleryCoreApi::error(ERROR_PERMISSION_DENIED);
 
1771
        }
 
1772
 
1695
1773
        /* Refresh lock */
1696
1774
        if (!empty($update)) {
1697
1775
            /* Don't join with the Gallery lock table since we might be using flock system */