PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Editor / Editor.php

Editor.php in Depicter — Popup & Slider Builder trunk, at app/src/Editor/Editor.php

162 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Editor;
3
4
5 use Depicter\Editor\Migrations\JobsQueue;
6 use Depicter\Services\UserAPIService;
7
8
9 class Editor
10 {
11 protected $document_id;
12
13 public function __construct(){
14 }
15
16 public function init()
17 {
18 add_action( 'admin_action_depicter', [ $this, 'make' ] );
19 add_action( 'depicter/plugin/updated', [ $this, 'check_migration_tasks' ] );
20 add_action( 'depicter/editor/open', [ $this, 'renewTokens'] );
21 }
22
23 public function make()
24 {
25
26 if ( !current_user_can('access_depicter') ) {
27 wp_die( esc_html__( 'Sorry, you are not allowed to access this page.', 'depicter' ), esc_html__( 'Depicter Error', 'depicter' ), array(
28 'response' => 403,
29 'back_link' => false,
30 ) );
31 }
32
33 if ( empty( $_REQUEST['document'] ) ) {
34 return;
35 }
36
37 define( 'IS_DEPICTER_EDITOR_PREVIEW', true );
38
39 $this->document_id = absint( $_REQUEST['document'] );
40
41 $this->clearEditPage()
42 ->enqueueAssets()
43 ->printEditorPage();
44
45 do_action( 'depicter/editor/open' );
46
47 die();
48 }
49
50 protected function clearEditPage()
51 {
52 // Send MIME Type header like WP admin-header.
53 header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
54
55 add_filter( 'show_admin_bar', '__return_false' );
56
57 // Remove all WordPress actions
58 remove_all_actions( 'wp_head' );
59 remove_all_actions( 'wp_print_styles' );
60 remove_all_actions( 'wp_print_head_scripts' );
61 remove_all_actions( 'wp_footer' );
62
63 // Handle `wp_head`
64 add_action( 'wp_head', 'wp_enqueue_scripts', 1 );
65 add_action( 'wp_head', 'wp_print_styles', 8 );
66 add_action( 'wp_head', 'wp_print_head_scripts', 9 );
67 add_action( 'wp_head', 'wp_site_icon' );
68
69 // Handle `wp_footer`
70 add_action( 'wp_footer', 'wp_print_footer_scripts', 20 );
71
72 // Handle `wp_enqueue_scripts`
73 remove_all_actions( 'wp_enqueue_scripts' );
74
75 // Also remove all scripts hooked into after_wp_tiny_mce.
76 remove_all_actions( 'after_wp_tiny_mce' );
77
78 // Change heartbeat options
79 add_filter( 'heartbeat_settings', function( $settings ) {
80 $settings['interval'] = 15;
81 return $settings;
82 });
83
84 add_filter('wp_title', function( $title ){
85 if( $document = \Depicter::document()->repository()->findOne( $this->document_id ) ){
86 if( $documentTitle = $document->getFieldValue('name') ){
87 $title = __( 'Depicter', 'depicter' ) . ' | ' . $documentTitle;
88 }
89 }
90 return $title;
91 } );
92
93 return $this;
94 }
95
96 /**
97 * @return $this
98 */
99 protected function enqueueAssets(){
100 \Depicter::resolve('depicter.editor.assets')->bootstrap();
101 return $this;
102 }
103
104 /**
105 * @return $this
106 */
107 private function printEditorPage(){
108 echo \Depicter::view('admin/editor/open/content.php')->toString();
109 return $this;
110 }
111
112 /**
113 * Whether we are in the editor preview mode or not.
114 *
115 * @return bool
116 */
117 public function isPreview(){
118 return defined( 'IS_DEPICTER_EDITOR_PREVIEW' ) && IS_DEPICTER_EDITOR_PREVIEW;
119 }
120
121 /**
122 * Retrieves the document edit page
123 *
124 * @param $id
125 *
126 * @return mixed|void
127 */
128 public function getEditUrl( $id ) {
129 $url = add_query_arg(
130 [
131 'document' => $id,
132 'action' => 'depicter'
133 ],
134 self_admin_url( 'post.php' )
135 );
136
137 return apply_filters( 'depicter/document/urls/edit', $url, $this );
138 }
139
140 /**
141 * Check migration tasks after plugin upgraded
142 */
143 public function check_migration_tasks() {
144 ( new JobsQueue() )->migrate();
145 }
146
147 /**
148 * Renew member tokens before expire date
149 *
150 * @return void
151 */
152 public function renewTokens() {
153 if ( false === \Depicter::cache('base')->get( 'access_token' ) ) {
154 UserAPIService::renewTokens();
155 }
156 }
157 }
158
159
160 // http://idev/wp/en/wp-admin/post.php?post=105&action=depicter
161 // http://idev/wp/en/wp-admin/post.php?post&action=depicter
162