1: <?php
2: /**
3: * Common functionality for the remote provider.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_FreeBusy
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Kolab_FreeBusy
12: */
13:
14: /**
15: * Common functionality for the remote provider.
16: *
17: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If
20: * you did not receive this file, see
21: * http://www.horde.org/licenses/lgpl21.
22: *
23: * @category Kolab
24: * @package Kolab_FreeBusy
25: * @author Gunnar Wrobel <wrobel@pardus.de>
26: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
27: * @link http://pear.horde.org/index.php?package=Kolab_FreeBusy
28: */
29: abstract class Horde_Kolab_FreeBusy_Provider_Remote
30: implements Horde_Kolab_FreeBusy_Provider
31: {
32: /**
33: * The owner of the data.
34: *
35: * @var Horde_Kolab_FreeBusy_Owner
36: */
37: private $_owner;
38:
39: /**
40: * The current request.
41: *
42: * @var Horde_Controller_Request
43: */
44: private $_request;
45:
46: /**
47: * Constructor
48: *
49: * @param Horde_Kolab_FreeBusy_Owner $owner The owner of the data.
50: * @param Horde_Controller_Request $request The current request.
51: */
52: public function __construct(
53: Horde_Kolab_FreeBusy_Owner $owner,
54: Horde_Controller_Request $request
55: )
56: {
57: $this->_owner = $owner;
58: $this->_request = $request;
59: }
60:
61: /**
62: * Generate the remote URL.
63: *
64: * @return string The URL
65: */
66: protected function getUrl()
67: {
68: return $this->_getUrl(
69: $this->_owner->getRemoteServer(),
70: $this->_request->getPath()
71: );
72: }
73:
74: /**
75: * Generate the URL for triggering data on a remote system.
76: *
77: * @param string $username The user accessing the data.
78: * @param string $password The user password.
79: *
80: * @return string The URL
81: */
82: protected function getUrlWithCredentials(
83: $username, $password
84: )
85: {
86: return $this->_getUrl(
87: preg_replace(
88: '#(http[s]://)(.*)#',
89: '\1' . urlencode($username) .
90: ':' .urlencode($password) . '@\2',
91: $this->_owner->getRemoteServer()
92: ),
93: $this->_request->getPath()
94: );
95: }
96:
97: /**
98: * Construct the final URL.
99: *
100: * @param string $server The server URL.
101: * @param string $path The path on the server.
102: *
103: * @return string The URL
104: */
105: private function _getUrl($server, $path)
106: {
107: return sprintf('%s/%s', $server, $path);
108: }
109: }