PluginProbe
Depicter — Popup & Slider Builder / 1.9.2
Depicter — Popup & Slider Builder v1.9.2
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 1.9.2, at app/src/Editor/Editor.php

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