0byt3m1n1
Path:
/
data
/
applications
/
aps
/
gallery
/
2.2-08
/
htdocs
/
modules
/
useralbum
/
classes
/
[
Home
]
File: UserAlbumHelper.class
<?php /* * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2007 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ /** * A helper class for user albums * @package UserAlbum * @subpackage Classes * @author Alan Harder <alan.harder@sun.com> * @version $Revision: 15513 $ * @static */ class UserAlbumHelper { /** * Create a new user album * * @param object GalleryUser $user new user * @return object GalleryStatus a status code */ function createUserAlbum($user) { list ($ret, $core) = GalleryCoreApi::fetchAllPluginParameters('module', 'core'); if ($ret) { return $ret; } list ($ret, $module) = GalleryCoreApi::fetchAllPluginParameters('module', 'useralbum'); if ($ret) { return $ret; } /* Create album.. */ $albumTitle = trim($user->getFullName()); if (empty($albumTitle)) { $albumTitle = $user->getUserName(); } $albumName = $user->getUserName(); while (true) { list ($ret, $album) = GalleryCoreApi::createAlbum( $module['targetLocation'], $albumName, $albumTitle, '', '', ''); if (!$ret) { break; } if ($ret->getErrorCode() & ERROR_COLLISION) { $albumName .= '_'; } else { return $ret; } } list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($album->getId()); if ($ret) { return $ret; } /* Set owner.. */ $album->setOwnerId($user->getId()); $ret = $album->save(); if ($ret) { GalleryCoreApi::releaseLocks($lockId); return $ret; } $albumId = $album->getId(); /* Set permissions.. */ list ($ret, $permissions) = GalleryCoreApi::fetchAllPermissionsForItem($albumId, true); if ($ret) { GalleryCoreApi::releaseLocks($lockId); return $ret; } $visited = array(); foreach ($permissions as $permission) { /* don't bother for administrator group */ if (empty($permission['groupId']) || $permission['groupId'] != $core['id.adminGroup']) { /* remove all view permissions at once */ if (strstr($permission['permission'], 'core.view') || ($permission['permission'] == 'core.all')) { if (!empty($permission['groupId']) && empty($visited[$permission['groupId']])) { $ret = GalleryCoreApi::removeGroupPermission($albumId, $permission['groupId'], 'core.viewAll'); if ($ret) { GalleryCoreApi::releaseLocks($lockId); return $ret; } $visited[$permission['groupId']] = 1; } else if (!empty($permission['userId']) && empty($visited[$permission['userId']])) { $ret = GalleryCoreApi::removeUserPermission($albumId, $permission['userId'], 'core.viewAll'); if ($ret) { GalleryCoreApi::releaseLocks($lockId); return $ret; } $visited[$permission['userId']] = 1; } } } } $ret = GalleryCoreApi::addUserPermission($albumId, $user->getId(), 'core.all'); if ($ret) { GalleryCoreApi::releaseLocks($lockId); return $ret; } $viewPermissions = $module['fullSize'] ? array('core.viewAll') : array('core.view', 'core.viewResizes'); switch ($module['view']) { case 'everybody': $groupId = $core['id.everybodyGroup']; break; case 'allusers': $groupId = $core['id.allUserGroup']; break; } if (isset($groupId)) { foreach ($viewPermissions as $permission) { $ret = GalleryCoreApi::addGroupPermission($albumId, $groupId, $permission); if ($ret) { GalleryCoreApi::releaseLocks($lockId); return $ret; } } } $ret = GalleryCoreApi::releaseLocks($lockId); if ($ret) { return $ret; } /* Record id of album */ $ret = GalleryCoreApi::setPluginParameter( 'module', 'useralbum', 'albumId', $albumId, $user->getId()); if ($ret) { return $ret; } return null; } } ?>