PluginProbe
Gum Addon for Elementor / trunk
Gum Addon for Elementor vtrunk
1.3.18 1.3.17 trunk 1.0.0 1.0.10 1.0.11 1.0.12 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 All 58 releases
gum-elementor-addon / gum-elementor-addon.php

gum-elementor-addon.php in Gum Addon for Elementor trunk, at gum-elementor-addon.php

346 lines 11.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') or die();
3 /*
4 * Plugin Name: Gum Addon for Elementor
5 * Plugin URI: http://themegum.com/
6 * Description: Addon widget for Elementor. Slideshow, pricing table, icon list, recent post, blog term, post term, post share, post meta, post related, post adjacent, blog grid, post slider,navigation menu, image box, popover and to top button
7 * Version: 1.3.18
8 * Author: TemeGUM
9 * Author URI: http://themegum.com
10 * Domain Path: /languages/
11 * Text Domain: gum-elementor-addon
12 * License: GPLv3 or later
13 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
14 * Requires Plugins: elementor
15 * Requires at least: 6.0
16 * Tested up to: 7.1
17 * Requires PHP: 7.0
18 * Elementor tested up to: 4.1.1
19 */
20
21 require_once plugin_dir_path(__FILE__). '/helper.php';
22
23 final class Gum_Elementor_Addon{
24
25 private static $_instance = null;
26
27 public static function instance() {
28
29 if ( is_null( self::$_instance ) ) {
30 self::$_instance = new self();
31 }
32 return self::$_instance;
33
34 }
35
36 public function __construct() {
37
38 define('GUM_ELEMENTOR_URL', trailingslashit(plugin_dir_url( __FILE__ )));
39 define('GUM_ELEMENTOR_DIR',plugin_dir_path(__FILE__));
40
41 load_plugin_textdomain('gum-elementor-addon', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
42
43 if(!function_exists('is_plugin_active')){
44 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
45 }
46
47 if(is_plugin_active('elementor/elementor.php')){
48
49 $this->init();
50 }
51 else{
52 add_action( 'admin_notices', array( $this, 'deactive_notice'), 10 );
53 $this->deactive();
54 }
55
56 }
57
58 public function init(){
59
60 require_once( GUM_ELEMENTOR_DIR."widgets/section.php" );
61 require_once( GUM_ELEMENTOR_DIR."widgets/icon_list.php" );
62 require_once( GUM_ELEMENTOR_DIR."widgets/image_box.php" );
63 require_once( GUM_ELEMENTOR_DIR."widgets/accordion.php" );
64 require_once( GUM_ELEMENTOR_DIR."widgets/counter.php" );
65 require_once( GUM_ELEMENTOR_DIR."widgets/progress.php" );
66 require_once( GUM_ELEMENTOR_DIR."widgets/button.php" );
67
68 add_action( 'elementor/init',array( $this, '_register_elementor_category' ) );
69 add_action( 'elementor/widgets/widgets_registered', array($this, '_elementor_widget_register'), 9999 );
70
71 add_action('wp_head',array($this,'add_count_post_view'));
72 }
73
74 public function _register_elementor_category($manager){
75
76
77 \Elementor\Plugin::$instance->elements_manager->add_category(
78 'temegum',
79 [
80 'title' => 'TemeGUM',
81 'icon' => 'feicon-font',
82 ],
83 1
84 );
85
86 \Elementor\Plugin::$instance->elements_manager->add_category(
87 'temegum_blog',
88 [
89 'title' => 'TemeGUM Blog',
90 'icon' => 'feicon-font',
91 ],
92 1
93 );
94
95 }
96
97 public function _elementor_widget_register($widgets_manager){
98
99
100 if(defined('ELEMENTOR_PATH') && class_exists('Elementor\Widget_Base')){
101
102 require_once( GUM_ELEMENTOR_DIR."widgets/slideshow.php" );
103 require_once( GUM_ELEMENTOR_DIR."widgets/popover_btn.php" );
104 require_once( GUM_ELEMENTOR_DIR."widgets/heading.php" );
105 require_once( GUM_ELEMENTOR_DIR."widgets/blog_lists.php" );
106 require_once( GUM_ELEMENTOR_DIR."widgets/blog_post_meta.php" );
107 require_once( GUM_ELEMENTOR_DIR."widgets/blog_post_adjacent.php" );
108 require_once( GUM_ELEMENTOR_DIR."widgets/blog_post_related.php" );
109 require_once( GUM_ELEMENTOR_DIR."widgets/blog_post_share.php" );
110 require_once( GUM_ELEMENTOR_DIR."widgets/blog_term.php" );
111 require_once( GUM_ELEMENTOR_DIR."widgets/site_navigation.php" );
112 require_once( GUM_ELEMENTOR_DIR."widgets/blog_grid.php" );
113 require_once( GUM_ELEMENTOR_DIR."widgets/post_slider.php" );
114 require_once( GUM_ELEMENTOR_DIR."widgets/blog_image.php" );
115 require_once( GUM_ELEMENTOR_DIR."widgets/totop_btn.php" );
116 require_once( GUM_ELEMENTOR_DIR."widgets/carousel_ibox.php" );
117 require_once( GUM_ELEMENTOR_DIR."widgets/circle_bar.php" );
118
119 if(!class_exists('Month_Anual_Pricetable_Widget')){
120 require_once( GUM_ELEMENTOR_DIR."widgets/pricetable.php" );
121 }
122
123 if(!class_exists('Month_Anual_Pricetable_TogglePeriod_Elementor_Widget')){
124 require_once( GUM_ELEMENTOR_DIR."widgets/toggle_period.php" );
125 }
126 }
127 }
128
129 function deactive_notice(){
130
131 echo "<div class='error'>" . esc_html__( 'Gum Addon for Elementor deactivated. The plugin need Elementor plugin, please install the plugin first.' ,'gum-elementor-addon'). "</div>";
132
133 }
134
135 function deactive(){
136 deactivate_plugins( array('gum-elementor-addon/gum-elementor-addon.php'), true, is_network_admin() );
137 }
138
139 public static function get_image_size( $image_id,$img_size="thumbnail"){
140
141 global $_wp_additional_image_sizes;
142
143 if(''==$img_size)
144 $img_size="thumbnail";
145
146 if(''==$image_id)
147 return false;
148
149 if(in_array($img_size, array('thumbnail','thumb','small', 'medium', 'large','full'))){
150
151 if ( $img_size == 'thumb' || $img_size == 'small' || $img_size == 'thumbnail' ) {
152
153 $image=wp_get_attachment_image_src($image_id,'thumbnail');
154 }
155 elseif ( $img_size == 'medium' ) {
156 $image=wp_get_attachment_image_src($image_id,'medium');
157
158 }
159 elseif ( $img_size == 'large' ) {
160 $image=wp_get_attachment_image_src($image_id,'large');
161 }else{
162
163 $image=wp_get_attachment_image_src($image_id,'full');
164
165 }
166
167 }
168 elseif(!empty($_wp_additional_image_sizes[$img_size]) && is_array($_wp_additional_image_sizes[$img_size])){
169
170 $width=$_wp_additional_image_sizes[$img_size]['width'];
171 $height=$_wp_additional_image_sizes[$img_size]['height'];
172
173 $img_url = wp_get_attachment_image_src($image_id,'full',false);
174 $image= self::aq_resize( $img_url[0],$width, $height, true,false ) ;
175
176
177 }
178 else{
179
180 preg_match_all('/\d+/', $img_size, $thumb_matches);
181
182 if(isset($thumb_matches[0])) {
183 $thumb_size = array();
184 if(count($thumb_matches[0]) > 1) {
185 $thumb_size[] = $thumb_matches[0][0]; // width
186 $thumb_size[] = $thumb_matches[0][1]; // height
187 } elseif(count($thumb_matches[0]) > 0 && count($thumb_matches[0]) < 2) {
188 $thumb_size[] = $thumb_matches[0][0]; // width
189 $thumb_size[] = $thumb_matches[0][0]; // height
190 } else {
191 $thumb_size = false;
192 }
193 }
194
195 if($thumb_size){
196
197 $img_url = wp_get_attachment_image_src($image_id,'full',false);
198 $image= self::aq_resize( $img_url[0],$thumb_size[0], $thumb_size[1], true,false ) ;
199 }
200 else{
201 return false;
202 }
203 }
204
205 return $image;
206 }
207
208 public static function aq_resize( $url, $width, $height = null, $crop = null, $single = true ) {
209
210 if(!$url OR !($width || $height)) return false;
211
212 //define upload path & dir
213 $upload_info = wp_upload_dir();
214 $upload_dir = $upload_info['basedir'];
215 $upload_url = $upload_info['baseurl'];
216
217 //check if $img_url is local
218 /* Gray this out because WPML doesn't like it.
219 if(strpos( $url, home_url() ) === false) return false;
220 */
221
222 //define path of image
223 $rel_path = str_replace( str_replace( array( 'http://', 'https://' ),"",$upload_url), '', str_replace( array( 'http://', 'https://' ),"",$url));
224 $img_path = $upload_dir . $rel_path;
225
226 //check if img path exists, and is an image indeed
227 if( !file_exists($img_path) OR !getimagesize($img_path) ) return false;
228
229 //get image info
230 $info = pathinfo($img_path);
231 $ext = $info['extension'];
232 list($orig_w,$orig_h) = getimagesize($img_path);
233
234 $dims = image_resize_dimensions($orig_w, $orig_h, $width, $height, $crop);
235 if(!$dims){
236 return $single?$url:array('0'=>$url,'1'=>$orig_w,'2'=>$orig_h);
237 }
238
239 $dst_w = $dims[4];
240 $dst_h = $dims[5];
241
242 //use this to check if cropped image already exists, so we can return that instead
243 $suffix = "{$dst_w}x{$dst_h}";
244 $dst_rel_path = str_replace( '.'.$ext, '', $rel_path);
245 $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
246
247 //if orig size is smaller
248 if($width >= $orig_w) {
249
250 if(!$dst_h) :
251 //can't resize, so return original url
252 $img_url = $url;
253 $dst_w = $orig_w;
254 $dst_h = $orig_h;
255
256 else :
257 //else check if cache exists
258 if(file_exists($destfilename) && getimagesize($destfilename)) {
259 $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
260 }
261 else {
262
263 $imageEditor=wp_get_image_editor( $img_path );
264
265 if(!is_wp_error($imageEditor)){
266
267 $imageEditor->resize($width, $height, $crop );
268 $imageEditor->save($destfilename);
269
270 $resized_rel_path = str_replace( $upload_dir, '', $destfilename);
271 $img_url = $upload_url . $resized_rel_path;
272
273
274 }
275 else{
276 $img_url = $url;
277 $dst_w = $orig_w;
278 $dst_h = $orig_h;
279 }
280
281 }
282
283 endif;
284
285 }
286 //else check if cache exists
287 elseif(file_exists($destfilename) && getimagesize($destfilename)) {
288 $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
289 }
290 else {
291
292 $imageEditor=wp_get_image_editor( $img_path );
293
294 if(!is_wp_error($imageEditor)){
295 $imageEditor->resize($width, $height, $crop );
296 $imageEditor->save($destfilename);
297
298 $resized_rel_path = str_replace( $upload_dir, '', $destfilename);
299 $img_url = $upload_url . $resized_rel_path;
300 }
301 else{
302 $img_url = $url;
303 $dst_w = $orig_w;
304 $dst_h = $orig_h;
305 }
306
307
308 }
309
310 if(!$single) {
311 $image = array (
312 '0' => $img_url,
313 '1' => $dst_w,
314 '2' => $dst_h
315 );
316
317 } else {
318 $image = $img_url;
319 }
320
321 return $image;
322 }
323
324 public static function add_count_post_view(){
325
326 if(is_single()){
327
328 $post_id = get_the_ID();
329
330 $count = get_post_meta($post_id, '_post_views_count', true);
331
332 if($count==''){
333 $count = 0;
334 }else{
335 $count++;
336 }
337
338 return update_post_meta($post_id, '_post_views_count', $count);
339 }
340
341 }
342
343 }
344
345 Gum_Elementor_Addon::instance();
346