original_string: public function Sort($Target = '') {
        if (!Gdn::Session()->IsValid())
           throw PermissionException();
           
        if (!$this->Request->IsAuthenticatedPostBack())
           throw ForbiddenException('GET');
        
        // Get param
        $SortField = Gdn::Request()->Post('DiscussionSort');
        $SortField = 'd.'.StringBeginsWith($SortField, 'd.', TRUE, TRUE);
        
        // Use whitelist here too to keep database clean
        if (!in_array($SortField, DiscussionModel::AllowedSortFields())) {
           throw new Gdn_UserException("Unknown sort $SortField.");
        }
        
        // Set user pref
        Gdn::UserModel()->SavePreference(Gdn::Session()->UserID, 'Discussions.SortField', $SortField);
        
        if ($Target)
           Redirect($Target);
        
        // Send sorted discussions.
        $this->DeliveryMethod(DELIVERY_METHOD_JSON);
        $this->Render();
     }
code: public function Sort($Target = '') {
        if (!Gdn::Session()->IsValid())
           throw PermissionException();
           
        if (!$this->Request->IsAuthenticatedPostBack())
           throw ForbiddenException('GET');
        
        // Get param
        $SortField = Gdn::Request()->Post('DiscussionSort');
        $SortField = 'd.'.StringBeginsWith($SortField, 'd.', TRUE, TRUE);
        
        // Use whitelist here too to keep database clean
        if (!in_array($SortField, DiscussionModel::AllowedSortFields())) {
           throw new Gdn_UserException("Unknown sort $SortField.");
        }
        
        // Set user pref
        Gdn::UserModel()->SavePreference(Gdn::Session()->UserID, 'Discussions.SortField', $SortField);
        
        if ($Target)
           Redirect($Target);
        
        // Send sorted discussions.
        $this->DeliveryMethod(DELIVERY_METHOD_JSON);
        $this->Render();
     }
code_tokens: public function Sort ( $ Target = '' ) { if ( ! Gdn :: Session ( ) -> IsValid ( ) ) throw PermissionException ( ) ; if ( ! $ this -> Request -> IsAuthenticatedPostBack ( ) ) throw ForbiddenException ( 'GET' ) ; // Get param $ SortField = Gdn :: Request ( ) -> Post ( 'DiscussionSort' ) ; $ SortField = 'd.' . StringBeginsWith ( $ SortField , 'd.' , TRUE , TRUE ) ; // Use whitelist here too to keep database clean if ( ! in_array ( $ SortField , DiscussionModel :: AllowedSortFields ( ) ) ) { throw new Gdn_UserException ( "Unknown sort $SortField." ) ; } // Set user pref Gdn :: UserModel ( ) -> SavePreference ( Gdn :: Session ( ) -> UserID , 'Discussions.SortField' , $ SortField ) ; if ( $ Target ) Redirect ( $ Target ) ; // Send sorted discussions. $ this -> DeliveryMethod ( DELIVERY_METHOD_JSON ) ; $ this -> Render ( ) ; }
docstring: Set user preference for sorting discussions.
docstring_tokens: Set user preference for sorting discussions .