public function run()
    {
        $response = null;
        $action = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';

        switch ($action) {
            case '/login':
                $password = isset($_GET['password']) ? $_GET['password'] : null;

                if ($password && sha1($password) == $this->config['password']) {
                    $this->status['admin'] = true;
                }
                break;
            case '/follow':
                $this->status['follower'] = true;
                break;
            case '/update':
                $current = array();

                foreach (array('page', 'slide', 'discover') as $key) {
                    $current[$key] = isset($_GET[$key]) ? $_GET[$key] : null;
                    if ($current[$key] == 'null') {
                        $current[$key] = null;
                    }
                }

                $this->state->current = $current;
                $this->state->persist();

                break;
            case '/current':
                $response = $this->state->current;
                $response['status'] = $this->status;
                break;
            case '/logout':
                $this->status = array();
                break;
            case '/startPoll':
                if (isset($_GET['id']) && isset($_GET['size']) && isset($this->status['admin'])) {
                    $this->startPoll($_GET['id'], (int)$_GET['size']);
                }
                break;
            case '/votePoll':
                if (isset($_GET['answer'])) {
                    $this->votePoll((int)$_GET['answer']);
                }
                break;
            case '/endPoll':
                if (isset($this->status['admin'])) {
                    $this->endPoll();
                }
                break;
            case '/infoPoll':
                $response = $this->infoPoll();
                break;
        }

        if ($response === null) {
            $response = $this->status;
        }

        $_SESSION[$this->key] = $this->status;
        return $response;
    }
public function run()
    {
        $response = null;
        $action = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';

        switch ($action) {
            case '/login':
                $password = isset($_GET['password']) ? $_GET['password'] : null;

                if ($password && sha1($password) == $this->config['password']) {
                    $this->status['admin'] = true;
                }
                break;
            case '/follow':
                $this->status['follower'] = true;
                break;
            case '/update':
                $current = array();

                foreach (array('page', 'slide', 'discover') as $key) {
                    $current[$key] = isset($_GET[$key]) ? $_GET[$key] : null;
                    if ($current[$key] == 'null') {
                        $current[$key] = null;
                    }
                }

                $this->state->current = $current;
                $this->state->persist();

                break;
            case '/current':
                $response = $this->state->current;
                $response['status'] = $this->status;
                break;
            case '/logout':
                $this->status = array();
                break;
            case '/startPoll':
                if (isset($_GET['id']) && isset($_GET['size']) && isset($this->status['admin'])) {
                    $this->startPoll($_GET['id'], (int)$_GET['size']);
                }
                break;
            case '/votePoll':
                if (isset($_GET['answer'])) {
                    $this->votePoll((int)$_GET['answer']);
                }
                break;
            case '/endPoll':
                if (isset($this->status['admin'])) {
                    $this->endPoll();
                }
                break;
            case '/infoPoll':
                $response = $this->infoPoll();
                break;
        }

        if ($response === null) {
            $response = $this->status;
        }

        $_SESSION[$this->key] = $this->status;
        return $response;
    }
public function run ( ) { $ response = null ; $ action = isset ( $ _SERVER [ 'PATH_INFO' ] ) ? $ _SERVER [ 'PATH_INFO' ] : '' ; switch ( $ action ) { case '/login' : $ password = isset ( $ _GET [ 'password' ] ) ? $ _GET [ 'password' ] : null ; if ( $ password && sha1 ( $ password ) == $ this -> config [ 'password' ] ) { $ this -> status [ 'admin' ] = true ; } break ; case '/follow' : $ this -> status [ 'follower' ] = true ; break ; case '/update' : $ current = array ( ) ; foreach ( array ( 'page' , 'slide' , 'discover' ) as $ key ) { $ current [ $ key ] = isset ( $ _GET [ $ key ] ) ? $ _GET [ $ key ] : null ; if ( $ current [ $ key ] == 'null' ) { $ current [ $ key ] = null ; } } $ this -> state -> current = $ current ; $ this -> state -> persist ( ) ; break ; case '/current' : $ response = $ this -> state -> current ; $ response [ 'status' ] = $ this -> status ; break ; case '/logout' : $ this -> status = array ( ) ; break ; case '/startPoll' : if ( isset ( $ _GET [ 'id' ] ) && isset ( $ _GET [ 'size' ] ) && isset ( $ this -> status [ 'admin' ] ) ) { $ this -> startPoll ( $ _GET [ 'id' ] , ( int ) $ _GET [ 'size' ] ) ; } break ; case '/votePoll' : if ( isset ( $ _GET [ 'answer' ] ) ) { $ this -> votePoll ( ( int ) $ _GET [ 'answer' ] ) ; } break ; case '/endPoll' : if ( isset ( $ this -> status [ 'admin' ] ) ) { $ this -> endPoll ( ) ; } break ; case '/infoPoll' : $ response = $ this -> infoPoll ( ) ; break ; } if ( $ response === null ) { $ response = $ this -> status ; } $ _SESSION [ $ this -> key ] = $ this -> status ; return $ response ; }
Process the interactive request
Process the interactive request