PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.3.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.3.0
6.3.0 6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / ComponentLibrary / index.php
kirki / ComponentLibrary Last commit date
assets 3 weeks ago controller 3 weeks ago index.php 3 days ago
index.php
185 lines
1 <?php
2 namespace KirkiComponentLib;
3
4 use Kirki\HelperFunctions;
5
6 define( 'KIRKI_COMPONENT_LIBRARY_APP_PREFIX', 'KirkiComponentLibrary' );
7 define( 'KIRKI_COMPONENT_LIBRARY_ROOT_URL', plugin_dir_url( __FILE__ ) );
8 define( 'KIRKI_COMPONENT_LIBRARY_ROOT_PATH', plugin_dir_path( __FILE__ ) );
9
10 require_once KIRKI_COMPONENT_LIBRARY_ROOT_PATH . '/controller/CompLibFormHandler.php';
11 require_once KIRKI_COMPONENT_LIBRARY_ROOT_PATH . '/controller/ShowUserMetadata.php';
12 require_once KIRKI_COMPONENT_LIBRARY_ROOT_PATH . '/controller/ElementGenerator.php';
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 class KirkiComponentLibrary {
19
20 private $component_lib_forms = array();
21
22 public function __construct() {
23 $this->init();
24 add_filter( 'kirki_element_generator_' . KIRKI_COMPONENT_LIBRARY_APP_PREFIX, array( $this, 'element_generator' ), 10, 2 );
25 // add_filter( 'kirki_external_collection_options', array( $this, 'modify_external_collection_options' ), 10, 2 ); // Commented because of: getting double comments (post)
26 add_filter( 'kirki_collection_comments', array( $this, 'kirki_collection_comments' ), 10, 2 );
27
28 add_filter( 'kirki_dynamic_content', array( $this, 'kirki_dynamic_content' ), 10, 2 );
29 new ShowUserMetadata();
30 }
31
32 public function init() {
33 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
34 $action = sanitize_text_field( isset( $_GET['action'] ) ? $_GET['action'] : null );
35 if ( 'kirki' === $action ) {
36 $load_for = sanitize_text_field( isset( $_GET['load_for'] ) ? wp_unslash( $_GET['load_for'] ) : null );
37 if ( 'kirki-iframe' !== $load_for ) {
38 add_action( 'wp_enqueue_scripts', array( $this, 'load_editor_assets' ), 1 );
39 }
40 }
41 }
42
43 public function load_editor_assets() {
44 wp_enqueue_script( KIRKI_COMPONENT_LIBRARY_APP_PREFIX . '-editor', KIRKI_COMPONENT_LIBRARY_ROOT_URL . 'assets/js/' . 'editor.min.js', array(), KIRKI_VERSION, array( 'in_footer' => true ) );
45 wp_add_inline_script(
46 KIRKI_COMPONENT_LIBRARY_APP_PREFIX . '-editor',
47 'const ' . KIRKI_COMPONENT_LIBRARY_APP_PREFIX . ' = ' . json_encode(
48 array(
49 'base_url' => KIRKI_COMPONENT_LIBRARY_ROOT_URL,
50 )
51 ),
52 'before'
53 );
54 add_action(
55 'wp_enqueue_scripts',
56 function () {
57 global $kirki_editor_assets;
58 $kirki_editor_assets['scripts'][] = KIRKI_COMPONENT_LIBRARY_APP_PREFIX . '-editor';
59 },
60 50
61 );
62 }
63
64 public function add_component_library_script( $script_tags ) {
65 $value = $this->component_lib_forms;
66 $val = wp_json_encode( $value );
67 $script = 'var ' . KIRKI_COMPONENT_LIBRARY_APP_PREFIX . ' = window.' . KIRKI_COMPONENT_LIBRARY_APP_PREFIX . " === undefined? {form: $val, root_url:'" . KIRKI_COMPONENT_LIBRARY_ROOT_URL . "'} : {..." . KIRKI_COMPONENT_LIBRARY_APP_PREFIX . ', form:{...(' . KIRKI_COMPONENT_LIBRARY_APP_PREFIX . ".form || {}), ...$val}};";
68
69 $script_tags .= "<script data='" . KIRKI_COMPONENT_LIBRARY_APP_PREFIX . "-elements-property-vars'>$script</script>";
70
71 return $script_tags;
72 }
73
74 public function load_element_scripts_and_styles() {
75 add_filter('kirki_add_script_tags', array( $this, 'add_component_library_script' ) );
76 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
77 $action = sanitize_text_field( isset( $_GET['action'] ) ? $_GET['action'] : null );
78 if ( 'kirki' !== $action ) {
79 add_action(
80 'wp_enqueue_scripts',
81 function () {
82 wp_enqueue_style( KIRKI_COMPONENT_LIBRARY_APP_PREFIX, KIRKI_COMPONENT_LIBRARY_ROOT_URL . 'assets/css/' . 'main.min.css', array(), KIRKI_VERSION );
83 wp_enqueue_script( KIRKI_COMPONENT_LIBRARY_APP_PREFIX, KIRKI_COMPONENT_LIBRARY_ROOT_URL . 'assets/js/' . 'preview.min.js', array(), KIRKI_VERSION, array( 'in_footer' => true ) );
84 }
85 );
86 }
87 }
88
89 public function element_generator( $string, $props ) {
90 $this->load_element_scripts_and_styles();
91 $props['component_lib_forms'] = $this->component_lib_forms;
92 $hide = false;
93 if (
94 'kirki-login-error' === $props['element']['name'] ||
95 'kirki-register-error' === $props['element']['name'] ||
96 'kirki-forgot-password-error' === $props['element']['name'] ||
97 'kirki-change-password-error' === $props['element']['name'] ||
98 'kirki-retrieve-username-error' === $props['element']['name']
99 ) {
100 $hide = true;
101 }
102 $eg = new ElementGenerator( $props );
103 $gen = $eg->generate_common_element( $hide );
104 $this->component_lib_forms = $eg->component_lib_forms;
105 return $gen;
106 }
107
108 // public function modify_external_collection_options( $options, $args ) {
109 // $comment_collection = array(
110 // 'title' => 'Comments',
111 // 'value' => 'comments',
112 // 'inherit' => true,
113 // 'pegination' => true,
114 // 'default_select_type' => 'comment',
115 // 'group' => array(
116 // array(
117 // 'title' => 'Post Comments',
118 // 'value' => 'comment',
119 // 'itemType' => 'comment',
120 // ),
121 // // TODO: need to get all comment type and add it as list here.
122 // ),
123 // );
124 // $options[] = array(
125 // 'title' => 'Others',
126 // 'options' => $comment_collection,
127 // );
128
129 // return $options;
130 // }
131
132 public function kirki_collection_comments( $value, $args ) {
133 $all_comments = array();
134 $c_args = array( 'post_id' => $args['post_parent'] );
135 if ( isset( $args['parent_item_type'] ) && $args['parent_item_type'] === 'comment' ) {
136 $c_args['parent'] = $args['context']['comment_ID'];
137 } elseif ( isset( $args['context']['comment_ID'] ) ) {
138 $c_args['parent'] = $args['context']['comment_ID'];
139 }
140
141 $c_args['current_page'] = 1;
142 $c_args['item_per_page'] = 100;
143 $ac = HelperFunctions::get_comments( $c_args );
144
145 foreach ( $ac['data'] as $comment ) {
146 $all_comments[] = array(
147 'id' => $comment->comment_ID,
148 'comment_post_ID' => $comment->comment_post_ID,
149 'comment_author' => $comment->comment_author,
150 'comment_author_email' => $comment->comment_author_email,
151 'comment_author_url' => $comment->comment_author_url,
152 'comment_date' => $comment->comment_date,
153 'comment_date_gmt' => $comment->comment_date_gmt,
154 'comment_content' => $comment->comment_content,
155 'comment_approved' => $comment->comment_approved,
156 'comment_agent' => $comment->comment_agent,
157 'comment_type' => $comment->comment_type,
158 'comment_parent' => $comment->comment_parent,
159 'user_id' => $comment->user_id,
160 );
161 }
162 return array(
163 'data' => $all_comments,
164 'pagination' => array(),
165 'itemType' => 'comment',
166 );
167 }
168
169 public function kirki_dynamic_content( $value, $args ) {
170 if ( isset( $args['dynamicContent'] ) ) {
171 if ( $args['dynamicContent']['type'] === 'comment' ) {
172 if ( isset( $args['options']['comment'], $args['dynamicContent']['value'], $args['options']['comment'][ $args['dynamicContent']['value'] ] ) ) {
173 return $args['options']['comment'][ $args['dynamicContent']['value'] ];
174 } elseif ( isset( $args['dynamicContent']['value'] ) ) {
175 return $args['dynamicContent']['value'];
176 }
177 }
178 }
179 return $value;
180 }
181 }
182
183
184 new KirkiComponentLibrary();
185