1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11: class Folks_Activity_Form extends Horde_Form {
12:
13: 14:
15: function __construct($vars, $title, $name)
16: {
17: parent::__construct($vars, $title, $name);
18:
19: if ($name == 'long') {
20: $this->addVariable(_("Activity"), 'activity', 'longText', true, false, null, array(4));
21: } else {
22: $this->addVariable(_("Activity"), 'activity', 'text', true, false, null, array('', 80));
23: }
24:
25: $this->setButtons(_("Post"));
26: }
27:
28: 29:
30: function execute()
31: {
32: $message = trim(strip_tags($this->_vars->get('activity')));
33:
34: if (empty($message)) {
35: return PEAR::raiseError(_("You cannot post an empty activity message."));
36: }
37:
38: $filters = array('text2html', 'bbcode', 'highlightquotes', 'emoticons');
39: $filters_params = array(array('parselevel' => Horde_Text_Filter_Text2html::MICRO),
40: array(),
41: array(),
42: array());
43:
44: if (($hasBBcode = strpos($message, '[')) !== false &&
45: strpos($message, '[/', $hasBBcode) !== false) {
46: $filters_params[0]['parselevel'] = Horde_Text_Filter_Text2html::NOHTML;
47: }
48:
49: $message = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter(trim($message), $filters, $filters_params);
50:
51: $result = $GLOBALS['folks_driver']->logActivity($message, 'folks:custom');
52: if ($result instanceof PEAR_Error) {
53: return $result;
54: }
55:
56: if ($conf['facebook']['enabled']) {
57: $message = trim(strip_tags($this->_vars->get('activity')));
58: register_shutdown_function(array(&$this, '_facebook'), $message);
59: }
60:
61: return true;
62: }
63:
64: 65:
66: public function _facebook($message)
67: {
68: global $conf, $prefs;
69:
70:
71: if (!$conf['facebook']['enabled']) {
72: return true;
73: }
74:
75:
76: $fbp = unserialize($prefs->getValue('facebook'));
77: if (!$fbp || empty($fbp['uid'])) {
78: return true;
79: }
80:
81:
82: $context = array('http_client' => new Horde_Http_Client(),
83: 'http_request' => $GLOBALS['injector']->getInstance('Horde_Controller_Request'));
84: $facebook = new Horde_Service_Facebook($conf['facebook']['key'],
85: $conf['facebook']['secret'],
86: $context);
87:
88: $facebook->auth->setUser($fbp['uid'], $fbp['sid'], 0);
89:
90: try {
91: $facebook->users->setStatus($message);
92: } catch (Horde_Service_Facebook_Exception $e) {
93:
94: }
95: }
96: }
97: