| @@ -72,9 +72,9 @@ | ||
| 72 | 72 | if ( empty( $documentID ) ) { |
| 73 | 73 | return esc_html__( 'Slider ID is required.', 'depicter' ); |
| 74 | 74 | } |
| 75 | 75 | if( $args['useCache'] && ( false !== $cacheOutput = $this->getDocumentCache( $documentID, $args ) ) ){ |
| 76 | - return $cacheOutput . '<span hidden>Depicter cache hit.</span>'; | |
| 76 | + return $cacheOutput; | |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | $output = ''; |
| 80 | 80 | $where = [ 'status' => $args['status'] ]; |
| @@ -84,20 +84,20 @@ | ||
| 84 | 84 | if( ! $documentID = \Depicter::document()->getID( $documentID ) ){ |
| 85 | 85 | return esc_html__( 'Slider alias not found.', 'depicter' ); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if( $args['showUnpublishedNotice'] ){ | |
| 89 | - $output .= $this->getUnPublishedNoticeMarkup( $documentID ); | |
| 90 | - } elseif( \Depicter::document()->repository()->isNotPublished( $documentID, $where ) ) { | |
| 88 | + if( ! $args['showUnpublishedNotice'] && ! \Depicter::document()->repository()->isPublishedBefore( $documentID ) ) { | |
| 91 | 89 | throw new DocumentNotPublished( __( 'Slider is not published yet and saved as "draft"', 'depicter' ), 0, $where ); |
| 92 | 90 | } |
| 93 | 91 | |
| 94 | 92 | if( $documentModel = \Depicter::document()->getModel( $documentID, $where ) ){ |
| 93 | + $documentModel->setUnpublishedNotice( $args['showUnpublishedNotice'] ); | |
| 95 | 94 | |
| 96 | 95 | $output .= $documentModel->prepare()->render(); |
| 96 | + | |
| 97 | 97 | $documentModel->styleGenerator( $styleGeneratorArgs ); |
| 98 | 98 | |
| 99 | - if( $args['isPrivilegedUser'] && \Depicter::document()->getStatus( $documentID ) == 'publish' ){ | |
| 99 | + if( $args['isPrivilegedUser'] && \Depicter::document()->repository()->isPublished( $documentID ) ){ | |
| 100 | 100 | $documentModel->saveCss(); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | if( ( $args['loadStyleMode'] == 'inline' ) ){ |
| @@ -109,8 +109,10 @@ | ||
| 109 | 109 | $output = $documentModel->getInlineCssTag() . $output; |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | + $output = $documentModel->getBeforeInitCssAndTag() . $output; | |
| 114 | + | |
| 113 | 115 | //---------- |
| 114 | 116 | |
| 115 | 117 | $cssLinksToEnqueue = $documentModel->getCustomCssFiles( 'all' ); |
| 116 | 118 | |
| @@ -115,8 +117,13 @@ | ||
| 115 | 117 | $cssLinksToEnqueue = $documentModel->getCustomCssFiles( 'all' ); |
| 116 | 118 | |
| 117 | 119 | $this->cache->set( $documentID . '_css_files', $cssLinksToEnqueue, WEEK_IN_SECONDS ); |
| 118 | 120 | |
| 121 | + if( $firstSection = $documentModel->getSectionNth(1) ){ | |
| 122 | + $preloadTags = $firstSection->getPreloadTags(); | |
| 123 | + $this->cache->set( $documentID . '_preload_tags', $preloadTags, WEEK_IN_SECONDS ); | |
| 124 | + } | |
| 125 | + | |
| 119 | 126 | // sanitize the output before caching |
| 120 | 127 | $output = Sanitize::html( $output, null, 'depicter/output' ); |
| 121 | 128 | |
| 122 | 129 | if( $args['useCache'] ){ |
| @@ -182,30 +189,7 @@ | ||
| 182 | 189 | public function flushDocumentCache( $documentID ){ |
| 183 | 190 | $this->cache->delete( $documentID ."_auto" ); |
| 184 | 191 | $this->cache->delete( $documentID ."_inline" ); |
| 185 | 192 | $this->cache->delete( $documentID ."_file" ); |
| 186 | - } | |
| 187 | - | |
| 188 | - /** | |
| 189 | - * Get unpublished notice markup if document is not published | |
| 190 | - * | |
| 191 | - * @param int $documentID | |
| 192 | - * @param array $args | |
| 193 | - * | |
| 194 | - * @return string | |
| 195 | - */ | |
| 196 | - public function getUnPublishedNoticeMarkup( $documentID, $args = [] ){ | |
| 197 | - if( $document = \Depicter::document()->repository()->findById( $documentID ) ){ | |
| 198 | - $document = $document->toArray(); | |
| 199 | - | |
| 200 | - if ( $document['status'] == 'draft' ) { | |
| 201 | - return \Depicter::view('admin/notices/slider-draft-notice')->with( 'view_args', [ | |
| 202 | - 'isNotPublished' => true, | |
| 203 | - 'editUrl' => \Depicter::editor()->getEditUrl( $documentID ) | |
| 204 | - ])->toString(); | |
| 205 | - } | |
| 206 | - } | |
| 207 | - | |
| 208 | - return ''; | |
| 209 | 193 | } |
| 210 | 194 | |
| 211 | 195 | } |