Exemplo n.º 1
0
 public function onPost()
 {
     if ($this->user->hasRight('user_activity_add')) {
         try {
             $contentType = Base::getRequestHeader('Content-Type');
             switch ($contentType) {
                 case Writer\Atom::$mime:
                     $atom = new Atom();
                     $atom->import($this->getRequest(ReaderInterface::DOM));
                     foreach ($atom as $entry) {
                         try {
                             $this->insertEntry($entry);
                         } catch (\Exception $e) {
                         }
                     }
                     break;
                 default:
                     throw new Exception('Invalid content type');
                     break;
             }
             $msg = new Data\Message('You have successful create a message', true);
             $this->setResponse($msg, WriterInterface::XML);
         } catch (Exception $e) {
             $msg = new Data\Message($e->getMessage(), false);
             $this->setResponse($msg, WriterInterface::XML);
         }
     } else {
         $msg = new Data\Message('Access not allowed', false);
         $this->setResponse($msg, WriterInterface::XML, $this->user->isAnonymous() ? 401 : 403);
     }
 }
Exemplo n.º 2
0
 protected function setWriterConfig(WriterResult $writer)
 {
     switch ($writer->getType()) {
         case WriterInterface::ATOM:
             $updated = $this->getSql()->getField('SELECT `date` FROM ' . $this->registry['table.forum'] . ' ORDER BY `date` DESC LIMIT 1');
             $title = 'Forum';
             $id = 'urn:uuid:' . $this->base->getUUID('forum');
             $updated = new DateTime($updated, $this->registry['core.default_timezone']);
             $writer = $writer->getWriter();
             $writer->setConfig($title, $id, $updated);
             $writer->setGenerator('amun ' . Base::getVersion());
             if (!empty($this->config['amun_hub'])) {
                 $writer->addLink($this->config['amun_hub'], 'hub');
             }
             break;
     }
 }
Exemplo n.º 3
0
 /**
  * @httpMethod GET
  * @path /{service}
  * @nickname getApiDetails
  * @responseClass Declaration
  */
 public function getApiDetails()
 {
     try {
         $basePath = $this->config['psx_url'] . '/' . $this->config['psx_dispatch'] . 'api';
         $serviceName = strtolower($this->getUriFragments('service'));
         $cache = new Cache('swagger-api-detail-' . $serviceName);
         if (($declaration = $cache->load()) === false) {
             $declaration = new Declaration(Base::getVersion(), $basePath, null);
             $this->buildApiDetails($declaration, $serviceName);
             $cache->write(serialize($declaration));
         } else {
             $declaration = unserialize($declaration);
         }
         $this->setResponse($declaration);
     } catch (\Exception $e) {
         $msg = new Message($e->getMessage(), false);
         $this->setResponse($msg);
     }
 }
Exemplo n.º 4
0
 /**
  * @httpMethod GET
  * @path /{userName}
  */
 public function doProfile()
 {
     if ($this->user->hasRight('profile_view')) {
         $account = $this->getAccount();
         if (!$account instanceof Account\Record) {
             throw new Exception('Invalid user');
         }
         $this->template->assign('account', $account);
         // check whether remote profile
         if ($account->status == Account\Record::REMOTE) {
             Base::setResponseCode(301);
             header('Location: ' . $account->profileUrl);
             exit;
         }
         // add path
         $this->path->add($account->name, $this->page->getUrl() . '/' . $account->name);
         // get activities
         $activities = $this->getActivities($account);
         $this->template->assign('activities', $activities);
         // options
         $url = $this->config['psx_url'] . '/' . $this->config['psx_dispatch'] . 'api/user/friend';
         $options = new Option(__CLASS__, $this->registry, $this->user, $this->page);
         if (!$this->user->isAnonymous() && !$this->user->hasFriend($account)) {
             $options->add('profile_view', 'Add as friend', 'javascript:amun.services.profile.friendshipRequest(' . $this->user->getId() . ', ' . $account->id . ', \'' . $url . '\', this)');
         }
         $options->load(array($this->page, $account));
         $this->template->assign('options', $options);
         // template
         $this->htmlCss->add('profile');
         $this->htmlJs->add('amun');
         $this->htmlJs->add('profile');
         $this->htmlContent->add(Html\Content::META, Atom\Writer::link('Activity', $this->config['psx_url'] . '/' . $this->config['psx_dispatch'] . 'api/my/activity/' . $account->id . '?format=atom'));
         $this->htmlContent->add(Html\Content::META, '<link rel="alternate" type="application/stream+json" href="' . $this->config['psx_url'] . '/' . $this->config['psx_dispatch'] . 'api/user/activity/' . $account->id . '?format=jas" />');
         $this->htmlContent->add(Html\Content::META, '<link rel="meta" type="application/rdf+xml" title="FOAF" href="' . $this->config['psx_url'] . '/' . $this->config['psx_dispatch'] . 'api/my/foaf/' . $account->name . '" />');
         $this->htmlContent->add(Html\Content::META, '<link rel="profile" type="html/text" href="' . $account->profileUrl . '" />');
     } else {
         throw new Exception('Access not allowed');
     }
 }
Exemplo n.º 5
0
 /**
  * Outputs the raw media item
  *
  * @httpMethod GET
  * @path /{mediaId}
  * @nickname doServe
  * @responseClass PSX_Data_Message
  */
 public function doServe()
 {
     try {
         // get id
         $mediaId = $this->getUriFragments('mediaId');
         if (strlen($mediaId) == 36) {
             $media = $this->getHandler()->getOneByGlobalId($mediaId);
         } else {
             $media = $this->getHandler()->getOneById($mediaId);
         }
         // get media item
         if (!empty($media)) {
             // remove caching header
             header_remove('Expires');
             header_remove('Last-Modified');
             header_remove('Cache-Control');
             header_remove('Pragma');
             // check right
             if (!empty($media['rightId']) && !$this->user->hasRightId($media['rightId'])) {
                 throw new Exception('Access not allowed');
             }
             // send header
             switch ($media['mimeType']) {
                 case 'application/octet-stream':
                     header('Content-Type: ' . $media['mimeType']);
                     header('Content-Disposition: attachment; filename="' . $media['name'] . '"');
                     break;
                 default:
                     header('Content-Type: ' . $media['mimeType']);
                     break;
             }
             // read content
             if ($media['path'][0] == '/' || $media['path'][1] == ':') {
                 // absolute path
                 $path = $media['path'];
             } else {
                 // relative path
                 $path = $this->registry['media.path'] . '/' . $media['path'];
             }
             if (!is_file($path)) {
                 throw new Exception('File not found', 404);
             }
             $response = file_get_contents($path);
             // caching header
             $etag = md5($response);
             $match = Base::getRequestHeader('If-None-Match');
             $match = $match !== false ? trim($match, '"') : '';
             header('Etag: "' . $etag . '"');
             if ($match != $etag) {
                 echo $response;
             } else {
                 header('HTTP/1.1 304 Not Modified');
             }
             exit;
         } else {
             throw new Exception('Invalid media id');
         }
     } catch (\Exception $e) {
         $msg = new Message($e->getMessage(), false);
         $this->setResponse($msg, null, 404);
     }
 }
Exemplo n.º 6
0
Arquivo: View.php Projeto: visapi/amun
 private function getForum()
 {
     $result = $this->getHandler()->getOneById($this->id, array(), Sql::FETCH_OBJECT);
     if (empty($result)) {
         throw new Exception('Invalid forum id');
     }
     $this->id = $result->id;
     // redirect to correct url
     if (empty($this->title) || strcasecmp($this->title, $result->urlTitle) !== 0) {
         Base::setResponseCode(301);
         header('Location: ' . $this->page->getUrl() . '/view/' . $result->id . '/' . $result->urlTitle);
         exit;
     }
     return $result;
 }
Exemplo n.º 7
0
 private function isMaxVersion($value)
 {
     $a = Base::getVersion();
     $b = $value;
     return version_compare($a, $b, '<=');
 }
Exemplo n.º 8
0
 protected function setWriterConfig(WriterResult $writer)
 {
     switch ($writer->getType()) {
         case WriterInterface::ATOM:
             $account = $this->getHandler('AmunService\\User\\Account')->getOneById($this->userId, array('id', 'globalId', 'name', 'profileUrl', 'thumbnailUrl', 'updated'), Sql::FETCH_OBJECT);
             if ($account instanceof Account\Record) {
                 $writer = $writer->getWriter();
                 $writer->setConfig($account->name . ' activities', 'urn:uuid:' . $account->globalId, $account->getUpdated());
                 $writer->setGenerator('amun ' . Base::getVersion());
                 $writer->addAuthor($account->name, $account->profileUrl);
                 $writer->addLink($account->profileUrl, 'alternate', 'text/html');
                 $writer->addLink($account->thumbnailUrl, 'avatar');
                 $writer->setLogo($account->thumbnailUrl);
                 if (!empty($this->config['amun_hub'])) {
                     $writer->addLink($this->config['amun_hub'], 'hub');
                 }
             } else {
                 throw new Exception('Invalid user account');
             }
             break;
     }
 }