1: <?php
2: /**
3: * The Horde_Kolab_Storage_Folder_Namespace_Element_Other:: class represents the
4: * namespace for folders of other users.
5: *
6: * PHP version 5
7: *
8: * @category Kolab
9: * @package Kolab_Storage
10: * @author Gunnar Wrobel <wrobel@pardus.de>
11: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
12: * @link http://pear.horde.org/index.php?package=Kolab_Storage
13: */
14:
15: /**
16: * The Horde_Kolab_Storage_Folder_Namespace_Element_Other:: class represents the
17: * namespace for folders of other users.
18: *
19: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
20: *
21: * See the enclosed file COPYING for license information (LGPL). If you
22: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
23: *
24: * @category Kolab
25: * @package Kolab_Storage
26: * @author Gunnar Wrobel <wrobel@pardus.de>
27: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
28: * @link http://pear.horde.org/index.php?package=Kolab_Storage
29: */
30: class Horde_Kolab_Storage_Folder_Namespace_Element_Other
31: extends Horde_Kolab_Storage_Folder_Namespace_Element
32: {
33: /**
34: * Return the type of this namespace (personal, other, or shared).
35: *
36: * @return string The type.
37: */
38: public function getType()
39: {
40: return Horde_Kolab_Storage_Folder_Namespace::OTHER;
41: }
42:
43: /**
44: * Return the owner of a folder.
45: *
46: * @param string $name The name of the folder.
47: *
48: * @return string|boolean The owner of the folder.
49: */
50: public function getOwner($name)
51: {
52: $path = explode($this->_delimiter, $name);
53: $user = $path[1];
54: if (strpos($user, '@') === false) {
55: $domain = strstr(array_pop($path), '@');
56: if (!empty($domain)) {
57: $user .= $domain;
58: } else {
59: $domain = strstr($this->_user, '@');
60: if (!empty($domain)) {
61: $user .= $domain;
62: }
63: }
64: }
65: return $user;
66: }
67:
68: /**
69: * Generate a folder path for the given subpath and owner.
70: *
71: * @since Horde_Kolab_Storage 1.1.0
72: *
73: * @param string $subpath The subpath of the folder.
74: * @param string $owner The folder owner.
75: *
76: * @return string The name of the folder.
77: */
78: public function generatePath($subpath, $owner)
79: {
80: if (strpos($owner, '@') !== false) {
81: $local = strstr($owner, '@', true);
82: } else {
83: $local = $owner;
84: }
85: $start = join(
86: array($this->_name, $local, $subpath),
87: $this->_delimiter
88: );
89: if (strstr($this->_user, '@') !== strstr($owner, '@')) {
90: return $start . strstr($owner, '@');
91: } else {
92: return $start;
93: }
94: }
95:
96: /**
97: * Return an array describing the path elements of the folder.
98: *
99: * @param string $name The name of the folder.
100: *
101: * @return array The path elements.
102: */
103: protected function _subpath($name)
104: {
105: $path = parent::_subpath($name);
106: array_shift($path);
107: return $path;
108: }
109: }