コード例 #1
0
ファイル: abstract.php プロジェクト: NicholasJohn16/anahita
 /**
  * Browse Action.
  *
  * @param KCommandContext $context Context parameter
  *
  * @return AnDomainEntitysetDefault
  */
 protected function _actionBrowse(KCommandContext $context)
 {
     $context->append(array('query' => $this->getRepository()->getQuery()));
     $query = $context->query;
     if ($this->q) {
         $query->keyword($this->getService('anahita:filter.term')->sanitize($this->q));
     }
     if ($this->ids) {
         $ids = KConfig::unbox($this->ids);
         $query->id($ids);
     } else {
         $query->limit($this->limit, $this->start);
     }
     $entities = $query->toEntitySet();
     if ($this->isOwnable() && $this->actor) {
         $this->_state->append(array('filter' => 'following'));
         if ($this->filter == 'administering' && $this->getRepository()->hasBehavior('administrable')) {
             $entities->where('administrators.id', 'IN', array($this->actor->id));
         } elseif ($this->actor->isFollowable()) {
             $entities->where('followers.id', 'IN', array($this->actor->id));
         }
     }
     $entities->order('created_on', 'desc');
     return $this->setList($entities)->getList();
 }
コード例 #2
0
ファイル: configuration.php プロジェクト: walteraries/anahita
 /**
  * Saves a configuration
  * 
  * @param KCommandContext $context
  * 
  * @return 
  */
 protected function _actionSave(KCommandContext $context)
 {
     $context->append(array('data' => array('params' => array())));
     //find or create a new component
     $component = $this->getService('repos://admin/components.component')->findOrAddNew(array('option' => 'com_' . $this->getIdentifier()->package), array('data' => array('name' => ucfirst($this->getIdentifier()->package))));
     $params = new JParameter('');
     $params->loadArray((array) $context->data['params']);
     $component->params = $params->toString();
     $component->save();
 }
コード例 #3
0
ファイル: oauthorizable.php プロジェクト: walteraries/anahita
 /**
  * Handles callback 
  * 
  * @param KCommandContext $context
  * @return void
  */
 protected function _actionGetaccesstoken($context)
 {
     $this->getAPI()->requestAccessToken($this->getRequest());
     $token = (array) $this->getAPI()->getToken();
     $consumer = (array) $this->_consumer;
     KRequest::set('session.oauth', array('api' => $this->getAPI()->getName(), 'token' => $token, 'consumer' => $consumer));
     $return = KRequest::get('session.return', 'raw', null);
     if ($return) {
         $context->append(array('data' => array('return' => $return)));
     }
 }
コード例 #4
0
ファイル: serviceable.php プロジェクト: stonyyi/anahita
 /**
  * Return a set of entities.
  *
  * @param KCommandContext $context Context parameter
  *
  * @return AnDomainEntitysetAbstract
  */
 protected function _actionBrowse(KCommandContext $context)
 {
     $data = $context->data;
     $context->append(array('query' => $this->getRepository()->getQuery()));
     $query = $context->query;
     $query->order($this->sort, $this->direction)->limit($this->limit, $this->limitstart);
     $query->keyword = $this->search;
     if ($this->getRepository()->hasBehavior('parentable')) {
         if ($this->getState()->parent) {
             $query->parent($this->getState()->parent);
         } elseif ($this->pid == -1) {
             $query->parent(null);
         }
     }
     return $this->getState()->setList($query->toEntitySet())->getList();
 }
コード例 #5
0
 /**
  * Command handler
  * 
  * @param string  The command name
  * @param object  The command context
  *
  * @return boolean
  */
 public final function execute($name, KCommandContext $context)
 {
     $result = true;
     if (isset($this->_callbacks[$name])) {
         $callbacks = $this->_callbacks[$name];
         $params = $this->_params[$name];
         foreach ($callbacks as $key => $callback) {
             //Append the config to the context
             $context->append($params[$key]);
             //Call the callback
             $result = call_user_func($callback, $context);
             if ($result === false) {
                 break;
             }
         }
     }
     return $result === false ? false : true;
 }
コード例 #6
0
ファイル: callback.php プロジェクト: raeldc/nooku-server
 /**
  * Command handler
  * 
  * @param string  The command name
  * @param object  The command context
  *
  * @return boolean
  */
 public function execute($name, KCommandContext $context)
 {
     $result = true;
     if (isset($this->_callbacks[$name])) {
         $callbacks = $this->_callbacks[$name];
         $params = $this->_params[$name];
         foreach ($callbacks as $key => $callback) {
             $param = $params[$key];
             if (is_array($param) && is_numeric(key($param))) {
                 $result = call_user_func_array($callback, $params);
             } else {
                 $result = call_user_func($callback, $context->append($param));
             }
             //Call the callback
             if ($result === false) {
                 break;
             }
         }
     }
     return $result === false ? false : true;
 }
コード例 #7
0
ファイル: component.php プロジェクト: stonyyi/anahita
 /**
  * Get action.
  *
  * @param KCommandContext $context
  */
 protected function _actionPost(KCommandContext $context)
 {
     $context->append(array('data' => KRequest::get('post', 'raw', array())));
     //backward compatiblity
     if ($context->data['action']) {
         $context->data['_action'] = $context->data['action'];
     }
     $action = 'post';
     if ($context->data['_action']) {
         $action = $context->data['_action'];
         if (in_array($action, array('browse', 'read', 'display'))) {
             throw new LibBaseControllerExceptionMethodNotAllowed('Action: ' . $action . ' not allowed');
         }
     }
     if ($context->request->getFormat() == 'json' || $context->request->isAjax()) {
         $this->registerCallback('after.post', array($this, 'forward'));
     } else {
         $context->response->setRedirect(KRequest::get('server.HTTP_REFERER', 'url'));
     }
     return $this->getController()->execute($action, $context);
 }
コード例 #8
0
ファイル: abstract.php プロジェクト: e-tyatte/anahita
 /**
  * Can be used as a cabllack to automatically create a story.
  *
  * @param KCommandContext $context
  *
  * @return ComStoriesDomainEntityStory
  */
 public function createStoryCallback(KCommandContext $context)
 {
     if ($context->result !== false) {
         $data = $context->data;
         $name = $this->getIdentifier()->name . '_' . $context->action;
         $context->append(array('story' => array('component' => 'com_' . $this->getIdentifier()->package, 'name' => $name, 'owner' => $this->actor, 'object' => $this->getItem(), 'target' => $this->actor, 'comment' => $this->isCommentable() ? $data->comment : null)));
         $story = $this->createStory(KConfig::unbox($context->story));
         $data->story = $story;
         return $story;
     }
     return $context->result;
 }
コード例 #9
0
ファイル: identifiable.php プロジェクト: stonyyi/anahita
 /**
  * Fetches an entity.
  *
  * @param KCommandContext $context
  */
 public function fetchEntity(KCommandContext $context)
 {
     $context->append(array('identity_scope' => array()));
     $identifiable_key = $this->getIdentifiableKey();
     if ($values = $this->{$identifiable_key}) {
         $scope = KConfig::unbox($context->identity_scope);
         $values = KConfig::unbox($values);
         $scope[$identifiable_key] = $values;
         if (is_array($values)) {
             $mode = AnDomain::FETCH_ENTITY_SET;
         } else {
             $mode = AnDomain::FETCH_ENTITY;
         }
         $query = $this->getRepository()->getQuery();
         $query->where($scope);
         $entity = $this->getRepository()->fetch($query, $mode);
         if (empty($entity) || !count($entity)) {
             $exception = new LibBaseControllerExceptionNotFound('Resource Not Found');
             //see if the entity exits or not
             if ($query->disableChain()->fetch()) {
                 if ($this->viewer && !$this->viewer->guest()) {
                     $exception = new LibBaseControllerExceptionForbidden('Forbidden');
                 } else {
                     $exception = new LibBaseControllerExceptionNotFound('Not Found');
                 }
             }
             throw $exception;
         }
         $this->setItem($entity);
         return $entity;
     }
 }
コード例 #10
0
ファイル: default.php プロジェクト: stonyyi/anahita
 /**
  * Authorizes an action on resources owned by the actor.
  * 
  * @param KCommandContext $context Context parameter
  * 
  * @return bool
  */
 protected function _authorizeAction(KCommandContext $context)
 {
     //if entity is not privatable then it doesn't have access to allow method
     if (!$this->_entity->isPrivatable()) {
         return true;
     }
     //if viewer is admin then return true on the action
     if (is_person($this->_viewer) && $this->_viewer->admin()) {
         return true;
     }
     $action = $context->action;
     //any action on the actor requires being a follower by default
     $context->append(array('default' => LibBaseDomainBehaviorPrivatable::FOLLOWER));
     //not access to the entiy
     if ($this->_entity->authorize('access') === false) {
         return false;
     }
     $parts = explode(':', $action);
     $component = array_shift($parts);
     //check if it's a social app then if it's enabled
     if ($component) {
         $component = $this->getService('repos://site/components.component')->find(array('component' => $component));
         if ($component && $component->authorize('action', array('actor' => $this->_entity, 'action' => $parts[1], 'resource' => $parts[0])) === false) {
             return false;
         }
     }
     return $this->_entity->allows($this->_viewer, $action, $context->default);
 }
コード例 #11
0
ファイル: photo.php プロジェクト: walteraries/anahita
 /**
  * Method to upload and Add a photo
  *
  * @param  KCommandContext $context
  * @return void
  */
 protected function _actionAdd($context)
 {
     $data = $context->data;
     $file = KRequest::get('files.file', 'raw');
     $content = @file_get_contents($file['tmp_name']);
     $filesize = strlen($content);
     $uploadlimit = $this->_max_upload_limit * 1024 * 1024;
     $exif = function_exists('exif_read_data') ? @exif_read_data($file['tmp_name']) : array();
     if ($filesize == 0) {
         throw new LibBaseControllerExceptionBadRequest('File is missing');
         return;
     }
     if ($filesize > $uploadlimit) {
         throw new LibBaseControllerExceptionBadRequest('Exceed maximum size');
         return;
     }
     $orientation = 0;
     if (!empty($exif) && isset($exif['Orientation'])) {
         $orientation = $exif['Orientation'];
     }
     $data['portrait'] = array('data' => $content, 'rotation' => $orientation, 'mimetype' => isset($file['type']) ? $file['type'] : null);
     $photo = $this->actor->photos->addNew($data);
     $photo->setExifData($exif);
     $photo->save();
     $this->setItem($photo);
     $this->getResponse()->status = KHttpResponse::CREATED;
     if ($photo->body && preg_match('/\\S/', $photo->body)) {
         $context->append(array('story' => array('body' => $photo->body)));
     }
     return $photo;
 }