public function publish($message) { foreach ($message as $key => $params) { if (null !== $this->_mapReference[$key] && strlen($params) > $this->_mapReference[$key]) { $message[$key] = Centurion_Inflector::cuttext($params, $this->_mapReference[$key]); } } if (!$this->getTokenHandler()->getToken()) { throw new Centurion_Social_NoTokenException('No access token'); } $target = $this->getTargetObject(); if (null === $target || '' == trim($target)) { throw new Centurion_Social_Exception('No target for publishing has been defined'); } // if targetobject is a person id (other than "me"), it will not work if ($this->getTargetObject() != self::DEFAULT_TARGET) { $client = new Zend_Http_Client(); $client->setParameterGet(array('access_token' => $this->getTokenHandler()->getToken()))->setUri(self::ACCOUNTS_URI); $response = $client->request(Zend_Http_Client::GET); $data = Zend_Json::decode($response->getBody()); $pageAccessToken = null; echo '<pre>'; foreach ($data['data'] as $page) { if (in_array($this->getTargetObject(), $page)) { $pageAccessToken = $page['access_token']; break; } } } $message = array_merge(array('access_token' => $pageAccessToken ? $pageAccessToken : $this->getTokenHandler()->getToken()), $message); $client = new Zend_Http_Client(); $client->setParameterPost($message)->setUri(sprintf(self::PUBLISH_URI_PATTERN, $this->getTargetObject())); $response = $client->request(Zend_Http_Client::POST); $data = Zend_Json::decode($response->getBody()); if (isset($data['error'])) { if ($data['error']['type'] == 'Exception') { if (strpos($data['error']['message'], '#200')) { throw new Centurion_Social_NoTokenException($data['error']['message']); } if (strpos($data['error']['message'], '#210')) { throw new Centurion_Social_NoTokenException($data['error']['message']); } throw new Centurion_Social_Exception($data['error']['message']); // elseif (strpos($data['error']['message'],'#506')) { // throw new Centurion_Social_Exception($data['error']['message']); // } } elseif ($data['error']['type'] == 'OAuthException') { throw new Centurion_Social_NoTokenException($data['error']['message']); } } return $data->id; }
public function cuttext($value, $length, $separator = '...') { return Centurion_Inflector::cuttext($value, $length, $separator); }