PluginProbe
WP Coder – Insert & Manage Code Snippets / 3.5.1
WP Coder – Insert & Manage Code Snippets v3.5.1
4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 3.5.1 All 39 releases
wp-coder / includes / class-wowp-public.php

class-wowp-public.php in WP Coder – Insert & Manage Code Snippets 3.5.1, at includes/class-wowp-public.php

128 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPCoder;
4
5 defined( 'ABSPATH' ) || exit;
6
7 use WPCoder\Dashboard\DBManager;
8 use WPCoder\Dashboard\FolderManager;
9 use WPCoder\Optimization\HTMLMinifier;
10 use WPCoder\Publisher\Conditions;
11 use WPCoder\Publisher\EnqueueScript;
12 use WPCoder\Publisher\EnqueueStyle;
13 use WPCoder\Publisher\Singleton;
14
15 class WOWP_Public {
16
17 public function __construct() {
18 $this->include_global_php();
19
20 add_shortcode( 'WP-Coder', [ $this, 'shortcode' ] );
21 add_shortcode( WPCoder::SHORTCODE, [ $this, 'shortcode' ] );
22
23 add_action( 'wp_footer', [ $this, 'print_footer' ], 50 );
24 }
25
26 public function include_global_php() {
27 $page_path = FolderManager::path_upload_dir() . 'global-php.php';
28 $save_mode = isset( $_GET['wpcoder-safe-mode'] ) ? absint( $_GET['wpcoder-safe-mode'] ) : 0;
29
30 if ( $save_mode === 1 ) {
31 return false;
32 }
33 if ( file_exists( $page_path ) && get_option( '_wpcoder_enable_php' ) ) {
34 require_once $page_path;
35 }
36 }
37
38
39
40
41 public function shortcode( $atts, $shortcode_content = null ) {
42 if ( ! empty( $atts['id'] ) ) {
43 $result = DBManager::get_data_by_id( $atts['id'] );
44 } elseif ( ! empty( $atts['title'] ) ) {
45 $result = DBManager::get_data_by_title( $atts['title'] );
46 } else {
47 return false;
48 }
49
50 if ( empty( $result ) ) {
51 return false;
52 }
53
54 $default_atts = [ 'id' => "", 'title' => '' ];
55 $add_atts = $this->get_shortcode_atts( $result );
56 $filtered_new_atts = array_diff_key( $add_atts, $default_atts );
57 $result_atts = array_merge( $default_atts, $filtered_new_atts );
58
59 $attrs = shortcode_atts( $result_atts, $atts, WPCoder::SHORTCODE );
60
61 if ( Conditions::init( $result ) === false ) {
62 return false;
63 }
64
65
66 $wp_coder_content_out = $this->get_content( $result, $shortcode_content, $attrs );
67
68 $singleton = Singleton::getInstance();
69 $singleton->setValue( $result->id, $result );
70
71 EnqueueStyle::init( $result );
72 EnqueueScript::init( $result );
73
74 return $wp_coder_content_out;
75 }
76
77 private function get_shortcode_atts( $result ): array {
78 $param = maybe_unserialize( $result->param );
79 if ( empty( $param['shortcode_attribute'] ) || ! is_array( $param['shortcode_attribute'] ) ) {
80 return array();
81 }
82
83 return array_fill_keys( $param['shortcode_attribute'], '' );
84 }
85
86
87 public function print_footer() {
88 $singleton = Singleton::getInstance();
89 $shortcodes = $singleton->getValue();
90
91 foreach ( $shortcodes as $id => $result ) {
92 EnqueueStyle::inline( $result );
93 EnqueueScript::inline( $result );
94 }
95 }
96
97 private function get_content( $result, $shortcode_content = null, $attrs = null ) {
98 $shortcode_content = !empty($shortcode_content) ? do_shortcode( $shortcode_content ) : '';
99 $wp_coder_content = !empty($result->html_code) ? do_shortcode( $result->html_code ) : '';
100
101 if ( ! empty( $attrs ) ) {
102 extract( $attrs, EXTR_PREFIX_SAME, "wpcp" );
103 }
104
105 if ( ! empty( $result->php_code ) ) {
106 $path = FolderManager::code_path( $result );
107 include $path;
108 }
109
110 if ( preg_match_all( '/\{\{(.*?)\}\}/', $wp_coder_content, $matches ) && is_array( $matches[1] ) ) {
111 foreach ( $matches[1] as $match ) {
112 $wpcoder_variable = str_replace( '$', '', $match );
113 if ( isset( $$wpcoder_variable ) ) {
114 $wp_coder_content = str_replace( '{{' . $match . '}}', $$wpcoder_variable, $wp_coder_content );
115 }
116 }
117 }
118
119 $param = ! empty( $result->param ) ? maybe_unserialize( $result->param ) : [];
120 if ( ! empty( $param['minified_html'] ) ) {
121 return HTMLMinifier::minify( $wp_coder_content );
122 }
123
124
125 return $wp_coder_content;
126 }
127
128 }