PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 1.1.7
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v1.1.7
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
← All changes | core/class-elementor.php +282 -0 1-final1.1.7 View file →
@@ -1,0 +1,282 @@
1 +<?php
2 +
3 +namespace Templately;
4 +
5 +use Elementor\User;
6 +use Templately\Helper;
7 +
8 +class Elementor {
9 + protected static $_instance = null;
10 +
11 + public static function get_instance() {
12 + if ( static::$_instance === null ) {
13 + static::$_instance = new static;
14 + }
15 +
16 + return static::$_instance;
17 + }
18 +
19 + public function __construct() {
20 + API::get_instance();
21 + if ( class_exists( '\Elementor\Plugin' ) ) {
22 + Loader::add_action( 'wp_enqueue_scripts', $this, 'enqueue_styles' );
23 + Loader::add_action( 'elementor/editor/before_enqueue_scripts', $this, 'enqueue_scripts' );
24 + }
25 + Loader::add_action( 'admin_enqueue_scripts', $this, 'admin_scripts', 99 );
26 + Loader::add_action( 'enqueue_block_editor_assets', $this, 'admin_scripts', 99 );
27 + Loader::add_action( 'enqueue_block_editor_assets', $this, 'enqueue_styles', 99 );
28 + }
29 +
30 + public function enqueue_styles() {
31 + \wp_enqueue_style( 'templately-editor', TEMPLATELY_URL . 'assets/css/editor.css', [], TEMPLATELY_VERSION );
32 + }
33 +
34 + public function is_editor() {
35 + return is_admin() && isset( $_GET['action'] ) && 'elementor' === $_GET['action'];
36 + }
37 +
38 + public function is_elementor() {
39 + return isset( $_GET['action'] ) && 'elementor' === $_GET['action'];
40 + }
41 +
42 + private function get_ip() {
43 + if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
44 + $ip = $_SERVER['HTTP_CLIENT_IP'];
45 + } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
46 + $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
47 + } else {
48 + $ip = $_SERVER['REMOTE_ADDR'];
49 + }
50 +
51 + return $ip;
52 + }
53 +
54 + public function admin_scripts( $hook ) {
55 + if ( ! in_array( $hook, array ( 'toplevel_page_templately', 'post-new.php', 'post.php' ) ) ) {
56 + return;
57 + }
58 + $this->enqueue_scripts( 'admin' );
59 + }
60 +
61 + protected function editor_platform() {
62 + global $current_screen;
63 + $editor = 'elementor';
64 + if ( isset( $_GET['action'] ) && 'elementor' === $_GET['action'] ) {
65 + $editor = 'elementor';
66 + }
67 + if ( $current_screen->is_block_editor() && ! ( isset( $_GET['action'] ) && 'elementor' === $_GET['action'] ) ) {
68 + $editor = 'gutenberg';
69 + }
70 + if ( $current_screen->base === 'toplevel_page_templately' ) {
71 + $editor = 'templately';
72 + }
73 +
74 + return $editor;
75 + }
76 +
77 + public function enqueue_scripts( $hook = '' ) {
78 + $categories = API::get_categories();
79 + global $current_screen;
80 + $suffix = ! ( defined( 'TEMPLATELY_SCRIPT_DEBUG' ) && TEMPLATELY_SCRIPT_DEBUG ) ? '.min' : '';
81 + \wp_enqueue_script(
82 + 'templately-editor',
83 + TEMPLATELY_URL . "assets/js/templately{$suffix}.js",
84 + [ 'wp-i18n', 'wp-element', 'wp-components' ],
85 + \filemtime( TEMPLATELY_PATH . "assets/js/templately{$suffix}.js" ), $hook === 'admin'
86 + );
87 +
88 + \wp_set_script_translations( 'templately-editor', 'templately', TEMPLATELY_PATH . 'languages' );
89 + \wp_localize_script( 'templately-editor', 'TemplatelyAdmin', array (
90 + 'url' => \home_url( '/' ),
91 + 'site_url' => \home_url( '/' ),
92 + 'ip_address' => $this->get_ip(),
93 + 'nonce' => \wp_create_nonce( 'templately_nonce' ),
94 + 'platform' => $this->editor_platform(),
95 + 'is_block_editor' => $current_screen->is_block_editor(),
96 + 'is_elementor' => $this->is_elementor(),
97 + 'is_editor' => $this->is_editor(),
98 + 'is_admin' => is_admin(),
99 + 'admin' => DB::get_user_specific_login_meta( '_templately_connect_data', [] ),
100 + 'post_id' => get_the_ID(),
101 + 'default_image' => \TEMPLATELY_ASSETS . 'images/cloud-item.svg',
102 + 'not_found' => \TEMPLATELY_ASSETS . 'images/no-item-found.png',
103 + 'no_items' => \TEMPLATELY_ASSETS . 'images/no-items.png',
104 + 'loadingImage' => \TEMPLATELY_ASSETS . 'images/loading-logo.gif',
105 + 'templates' => self::templates(),
106 + 'reusable_blocks' => $this->reusable_blocks(),
107 + 'is_logged_in' => DB::get_user_specific_login_meta( '_templately_connected' ),
108 + 'user_can_logout' => Login::user_can_logout(),
109 + 'is_global_login' => Login::already_signedin_globally(),
110 + 'is_linked_login' => Login::get_link_my_account(),
111 + 'cloud_map' => DB::get_option( '_templately_cloud_map', [] ),
112 + 'categories' => array (
113 + 'blocks' => isset( $categories['item_categories'] ) ? $categories['item_categories'] : [],
114 + 'packs' => isset( $categories['pack_categories'] ) ? $categories['pack_categories'] : [],
115 + 'pages' => isset( $categories['page_categories'] ) ? $categories['page_categories'] : []
116 + ),
117 + 'cloud_activity' => DB::get_user_specific_login_meta( '_templately_cloud_last_activity', array (
118 + 'labels' => 'My Clouds',
119 + 'value' => 'clouds'
120 + ) ),
121 + 'platform_exists' => array (
122 + 'gutenberg' => $this->platform_exists( 'gutenberg' ),
123 + 'elementor' => $this->platform_exists( 'elementor' ),
124 + ),
125 + 'current_url' => admin_url('admin.php?page=templately'),
126 + 'prettyurl' => $this->prettyurl(),
127 + ) );
128 +
129 + if ( $hook !== 'admin' ) {
130 + \wp_enqueue_script(
131 + 'templately-frontend-editor',
132 + TEMPLATELY_URL . "assets/js/editor{$suffix}.js",
133 + [ 'jquery', 'wp-i18n' ],
134 + \filemtime( TEMPLATELY_PATH . "assets/js/editor{$suffix}.js" ),
135 + true
136 + );
137 + \wp_set_script_translations( 'templately-frontend-editor', 'templately', TEMPLATELY_PATH . 'languages' );
138 + }
139 +
140 + \wp_enqueue_style( 'templately-poppins',
141 + '//fonts.googleapis.com/css?family=Poppins:300,400,500,600,700', [], TEMPLATELY_VERSION
142 + );
143 + if ( ! defined( 'TEMPLATELY_SCRIPT_DEBUG' ) || ( defined( 'TEMPLATELY_SCRIPT_DEBUG' ) && ! TEMPLATELY_SCRIPT_DEBUG ) ) {
144 + \wp_enqueue_style( 'templately-style',
145 + TEMPLATELY_URL . 'assets/css/templately.css', [ 'templately-poppins' ], TEMPLATELY_VERSION
146 + );
147 + }
148 + }
149 +
150 + public function prettyurl(){
151 + if( isset( $_GET['t_route'] ) && ! empty( $_GET['t_route'] ) ) {
152 + $t_route = trim( $_GET['t_route'] );
153 + if( isset( $_GET['preview'] ) && $_GET['preview'] == true ) {
154 + $t_route .= '?preview=true';
155 + }
156 +
157 + return $t_route;
158 + }
159 + return '';
160 + }
161 +
162 + /**
163 + * Platform Exists or Not
164 + *
165 + * @return void
166 + */
167 + protected function platform_exists( $platform = 'elementor' ) {
168 + // $platform = isset( $_POST['platform'] ) ? trim( sanitize_text_field( $_POST['platform'] ) ) : 'elementor';
169 + if ( $platform === 'gutenberg' ) {
170 + $wp_version = get_bloginfo( 'version' );
171 + if ( version_compare( $wp_version, '5.0.0', '>=' ) ) {
172 + return true;
173 + } else {
174 + if ( \is_plugin_active( 'gutenberg/gutenberg.php' ) ) {
175 + return true;
176 + } else {
177 + return false;
178 + }
179 + }
180 + }
181 +
182 + if ( $platform === 'elementor' ) {
183 + if ( \is_plugin_active( 'elementor/elementor.php' ) ) {
184 + return true;
185 + } else {
186 + return false;
187 + }
188 + }
189 +
190 + return false;
191 + }
192 +
193 + /**
194 + * Get all saved templates from elementor library
195 + * @return void
196 + */
197 + public static function templates( $initial = true, $params = [] ) {
198 + $args = array (
199 + 'post_type' => 'elementor_library',
200 + 'numberposts' => 10,
201 + 'paged' => 1,
202 + );
203 + if ( ! $initial ) {
204 + $args['paged'] = isset( $params['page'] ) ? $params['page'] : 1;
205 + }
206 + $templates = new \WP_Query( $args );
207 + $templates_list = $templates->posts;
208 + $templateList = array ();
209 +
210 + if ( count( $templates_list ) > 0 ) :
211 + $date_format = get_option( 'date_format', 'F j, Y' );
212 + foreach ( $templates_list as $post ) {
213 + $templateList[] = array (
214 + 'id' => $post->ID,
215 + 'title' => $post->post_title,
216 + 'date' => date( $date_format, strtotime( $post->post_date ) ),
217 + 'type' => ucwords( \get_post_meta( $post->ID, '_elementor_template_type', true ) ),
218 + 'created_by' => \get_the_author_meta( 'user_nicename', $post->post_author ),
219 + 'preview_url' => \get_permalink( $post->ID ),
220 + 'export_url' => self::get_export_link( $post->ID ),
221 + );
222 + }
223 + endif;
224 + wp_reset_postdata();
225 + wp_reset_query();
226 +
227 + return array (
228 + 'current_page' => $templates->query_vars['paged'],
229 + 'total_page' => $templates->max_num_pages,
230 + 'items' => $templateList,
231 + );
232 + }
233 +
234 + /**
235 + * Get all saved templates from elementor library
236 + * @return void
237 + */
238 + public function reusable_blocks() {
239 + $templates = new \WP_Query( array (
240 + 'post_type' => 'wp_block'
241 + ) );
242 + $templateList = array ();
243 + if ( $templates->have_posts() ) :
244 + $date_format = get_option( 'date_format', 'F j, Y' );
245 + foreach ( $templates->posts as $post ) {
246 + $templateList[] = array (
247 + 'id' => $post->ID,
248 + 'title' => $post->post_title,
249 + 'date' => date( $date_format, strtotime( $post->post_date ) ),
250 + 'type' => '',
251 + 'created_by' => \get_the_author_meta( 'user_nicename', $post->post_author ),
252 + 'preview_url' => '',
253 + 'export_url' => '',
254 + );
255 + }
256 + endif;
257 + wp_reset_postdata();
258 + wp_reset_query();
259 +
260 + return $templateList;
261 + }
262 +
263 + /**
264 + * From Elementor It Self!
265 + *
266 + * @param template id $template_id
267 + *
268 + * @return void
269 + */
270 + private static function get_export_link( $template_id ) {
271 + return \add_query_arg(
272 + [
273 + 'action' => 'elementor_library_direct_actions',
274 + 'library_action' => 'export_template',
275 + 'source' => 'local',
276 + '_nonce' => \wp_create_nonce( 'elementor_ajax' ),
277 + 'template_id' => $template_id,
278 + ],
279 + \admin_url( 'admin-ajax.php' )
280 + );
281 + }
282 +}