/** * Send a POST request * * @param string $method The method to call. * @param array $params The method parameters. * * @return string The request results * @throws Horde_Service_Facebook_Exception */ protected function _postRequest($method, &$params) { $this->_finalizeParams($params); try { $url = new Horde_Url(Horde_Service_Facebook::REST_SERVER_ADDR . $method); $result = $this->_http->request('POST', $url->toString(), $this->_createPostString($params)); } catch (Exception $e) { $this->_facebook->logger->err($e->getMessage()); throw new Horde_Service_Facebook_Exception(Horde_Service_Facebook_Translation::t("Facebook service is unavailable. Please try again later.")); } return $result->getBody(); }
/** * Returns the plural translation of a message. * * @param string $singular The singular version to translate. * @param string $plural The plural version to translate. * @param integer $number The number that determines singular vs. plural. * * @return string The string translation, or the original string if no * translation exists. */ public static function ngettext($singular, $plural, $number) { self::$_domain = 'Horde_Service_Facebook'; self::$_directory = '@data_dir@' == '@' . 'data_dir' . '@' ? __DIR__ . '/../../../../locale' : '@data_dir@/Horde_Service_Facebook/locale'; return parent::ngettext($singular, $plural, $number); }
/** * Perform a multipart/form-data upload. * * @param array $options An options array: * - params: (array) Form parameters to pass * - file: (string) Local path to the file */ public function upload(array $options = array()) { // the format of this message is specified in RFC1867/RFC1341. // we add twenty pseudo-random digits to the end of the boundary string. $boundary = '--------------------------FbMuLtIpArT' . sprintf("%010d", mt_rand()) . sprintf("%010d", mt_rand()); $content_type = 'multipart/form-data; boundary=' . $boundary; // within the message, we prepend two extra hyphens. $delimiter = '--' . $boundary; $close_delimiter = $delimiter . '--'; $content_lines = array(); $params = array_merge($options['params'], $this->_params); foreach ($params as $key => $val) { $content_lines[] = $delimiter; $content_lines[] = 'Content-Disposition: form-data; name="' . $key . '"'; $content_lines[] = ''; $content_lines[] = $val; } // now add the file data $content_lines[] = $delimiter; $content_lines[] = 'Content-Disposition: form-data; filename="' . basename($options['file']) . '"'; $content_lines[] = 'Content-Type: application/octet-stream'; $content_lines[] = ''; $content_lines[] = file_get_contents($options['file']); $content_lines[] = $close_delimiter; $content_lines[] = ''; $content = implode("\r\n", $content_lines); try { $result = $this->_http->request('POST', $this->_endpoint->toString(true), $content, array('Content-Type' => $content_type, 'Content-Length' => strlen($content))); } catch (Horde_Http_Exception $e) { throw new Horde_Service_Facebook_Exception(sprintf(Horde_Service_Facebook_Translation::t("Upload failed: %s"), $e->getMessage())); } if ($result->code != '200') { throw new Horde_Service_Facebook_Exception($result->getBody()); } return json_decode($result->getBody()); }