1: <?php
2: /**
3: * Facebook as recipient.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Push
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://www.horde.org/libraries/Horde_Push
12: */
13:
14: /**
15: * Facebook as recipient.
16: *
17: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you did not
20: * receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Horde
23: * @package Push
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://www.horde.org/libraries/Horde_Push
27: */
28: class Horde_Push_Recipient_Facebook
29: extends Horde_Push_Recipient_Base
30: {
31: /**
32: * The facebook client.
33: *
34: * @var Horde_Service_Facebook
35: */
36: private $_facebook;
37:
38: /**
39: * The configuration for this recipient.
40: *
41: * @var array
42: */
43: private $_params;
44:
45: /**
46: * Constructor.
47: *
48: * @param Horde_Service_Facebook $facebook The facebook client.
49: * @param array $params The recipient configuration.
50: */
51: public function __construct(Horde_Service_Facebook $facebook, $params = array())
52: {
53: $this->_facebook = $facebook;
54: $this->_params = $params;
55: }
56:
57: /**
58: * Push content to the recipient.
59: *
60: * @param Horde_Push $content The content element.
61: * @param array $options Additional options.
62: *
63: * @return string The result description.
64: */
65: public function push(Horde_Push $content, $options = array())
66: {
67: $text = $content->getSummary();
68: if (empty($options['pretend'])) {
69: $streams = new Horde_Service_Facebook_Streams($this->_facebook);
70: $streams->publish($text, array(), '', '', '', $this->getAcl());
71: return 'Pushed to facebook stream.';
72: } else {
73: return sprintf(
74: 'Would push "%s" to the facebook stream.', $text
75: );
76: }
77: }
78:
79: /**
80: * Retrieve the ACL setting for this recipient.
81: *
82: * @return string The ACL.
83: */
84: protected function getAcl()
85: {
86: $acl = parent::getAcl();
87: if (empty($acl)) {
88: return array();
89: }
90: if (isset($this->_params['acl']['presets'][$acl])) {
91: return $this->_params['acl']['presets'][$acl];
92: }
93: return array('value' => $acl);
94: }
95: }
96: