Example #1
0
 private static function goNext(Context $ctx)
 {
     if ($ctx->method('post')) {
         foreach ($ctx->post('next', array()) as $k => $v) {
             if (!empty($v) and null !== $ctx->post($k)) {
                 return new Redirect($v);
             }
         }
     }
     return $ctx->getRedirect();
 }
Example #2
0
 public static function hookRemoteCall(Context $ctx, $className)
 {
     $default = 'default';
     if ($ctx->method('post')) {
         $default = $ctx->post('action', $default);
     }
     $action = $ctx->get('action', $default);
     $call = array(array($className, 'rpc_' . strtolower($ctx->method()) . '_' . $action), array($className, 'rpc_' . $action));
     foreach ($call as $args) {
         if (method_exists($args[0], $args[1])) {
             if (null === ($result = call_user_func(array($args[0], $args[1]), $ctx))) {
                 $result = $ctx->getRedirect();
             }
             return $result;
         }
     }
     if (null !== ($next = $ctx->getRedirect())) {
         return $next;
     }
     return false;
 }
Example #3
0
 public static function hookRemoteCall(Context $ctx)
 {
     switch ($ctx->get('action')) {
         case 'add':
             $ctx->user->checkAccess(ACL::CREATE, 'todo');
             $node = Node::create('todo', array('name' => $ctx->post('name'), 'uid' => $ctx->user->id, 'to' => $ctx->post('user', $ctx->user->id), 'published' => 1, 'rel' => $ctx->post('rel')));
             if (empty($node->name)) {
                 $msg = t('не указан текст задачи.');
                 bebop_on_json(array('status' => 'error', 'message' => $msg));
                 throw new InvalidArgumentException($msg);
             }
             $node->save();
             bebop_on_json(array('status' => 'created', 'id' => $node->id, 'html' => $node->render()));
             break;
         case 'toggle':
             try {
                 $node = Node::load(array('class' => 'todo', 'id' => $ctx->get('id')));
             } catch (ObjectNotFoundException $e) {
                 bebop_on_json(array('status' => 'error', 'message' => 'todo ' . $ctx->get('id') . ' not found'));
                 throw new PageNotFoundException();
             }
             if (empty($node->closed)) {
                 $node->closed = date('Y-m-d H:i:s', time() - date('Z', time()));
             } else {
                 $node->closed = null;
             }
             $node->save();
             if ($ctx->method('POST') and null !== ($comment = $ctx->post('comment'))) {
                 $tmp = Node::create('comment', array('uid' => $ctx->user->id, 'author' => $ctx->user->name, 'name' => t('Комментарий к напоминанию'), 'text' => $comment));
                 $tmp->save();
                 $tmp->linkAddParent($node->id);
             }
             $state = $node->closed ? 'closed' : 'open';
             bebop_on_json(array('status' => 'ok', 'state' => $state));
             break;
     }
 }
 /**
  * Возвращает обрабатываемые ноды.
  * Для запросов методом POST использует массив selected[],
  * для запросов методом GET — параметр node.
  */
 private static function getNodes(Context $ctx)
 {
     if ($ctx->method('post')) {
         $ids = $ctx->post('selected', array());
     } else {
         $ids = explode(' ', $ctx->get('node'));
     }
     if (empty($ids)) {
         throw new BadRequestException(t('Не указаны идентификаторы документов (POST-массив selected[] или GET-параметр node)'));
     }
     return Node::find(array('id' => $ids), $ctx->db);
 }
Example #5
0
 public function find(Context $ctx, $realQuery)
 {
     $args = array();
     $query = '/' . $realQuery;
     $prefix = strtoupper($ctx->method()) . '/';
     $q = array($prefix . $query, $prefix . $ctx->host() . $query, $prefix . 'localhost' . $query);
     foreach ($q as $mask) {
         if (array_key_exists($mask, $this->static)) {
             return array($this->static[$mask], array());
         }
         if (false !== ($tmp = $this->findre($mask))) {
             return $tmp;
         }
     }
     return false;
 }