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