code/control/KapostService.php
public function preview() {
        $auth=$this->request->getVar('auth');
        $token=KapostPreviewToken::get()->filter('Code', Convert::raw2sql($auth))->first();
        
        //Verify the token exists and hasn't expired yet
        if(!empty($token) && $token!==false && $token->exists() && time()-strtotime($token->Created)<self::config()->preview_token_expiry*60 && $token->KapostRefID==$this->urlParams['ID']) {
            $kapostObj=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($this->urlParams['ID']))->sort('"Created" DESC')->first();
            if(!empty($kapostObj) && $kapostObj!==false && $kapostObj->exists()) {
                $previewController=$kapostObj->renderPreview();
                
                $this->extend('updatePreviewDisplay', $kapostObj, $previewController);
                
                return $previewController;
            }
        }
        
        
        //Token expired or object not found
        if(class_exists('ErrorPage')) {
            $response=ErrorPage::response_for(404);
            if(!empty($response)) {
                return parent::httpError(404, $response);
            }
        }
        
        return parent::httpError(404);
    }
public function preview() {
        $auth=$this->request->getVar('auth');
        $token=KapostPreviewToken::get()->filter('Code', Convert::raw2sql($auth))->first();
        
        //Verify the token exists and hasn't expired yet
        if(!empty($token) && $token!==false && $token->exists() && time()-strtotime($token->Created)<self::config()->preview_token_expiry*60 && $token->KapostRefID==$this->urlParams['ID']) {
            $kapostObj=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($this->urlParams['ID']))->sort('"Created" DESC')->first();
            if(!empty($kapostObj) && $kapostObj!==false && $kapostObj->exists()) {
                $previewController=$kapostObj->renderPreview();
                
                $this->extend('updatePreviewDisplay', $kapostObj, $previewController);
                
                return $previewController;
            }
        }
        
        
        //Token expired or object not found
        if(class_exists('ErrorPage')) {
            $response=ErrorPage::response_for(404);
            if(!empty($response)) {
                return parent::httpError(404, $response);
            }
        }
        
        return parent::httpError(404);
    }
public function preview ( ) { $ auth = $ this -> request -> getVar ( 'auth' ) ; $ token = KapostPreviewToken :: get ( ) -> filter ( 'Code' , Convert :: raw2sql ( $ auth ) ) -> first ( ) ; //Verify the token exists and hasn't expired yet if ( ! empty ( $ token ) && $ token !== false && $ token -> exists ( ) && time ( ) - strtotime ( $ token -> Created ) < self :: config ( ) -> preview_token_expiry * 60 && $ token -> KapostRefID == $ this -> urlParams [ 'ID' ] ) { $ kapostObj = KapostObject :: get ( ) -> filter ( 'KapostRefID' , Convert :: raw2sql ( $ this -> urlParams [ 'ID' ] ) ) -> sort ( '"Created" DESC' ) -> first ( ) ; if ( ! empty ( $ kapostObj ) && $ kapostObj !== false && $ kapostObj -> exists ( ) ) { $ previewController = $ kapostObj -> renderPreview ( ) ; $ this -> extend ( 'updatePreviewDisplay' , $ kapostObj , $ previewController ) ; return $ previewController ; } } //Token expired or object not found if ( class_exists ( 'ErrorPage' ) ) { $ response = ErrorPage :: response_for ( 404 ) ; if ( ! empty ( $ response ) ) { return parent :: httpError ( 404 , $ response ) ; } } return parent :: httpError ( 404 ) ; }
Handles rendering of the preview for an object
@return string Response to send to the object
Handles rendering of the preview for an object