PluginProbe
HT Builder – WordPress Theme Builder for Elementor / 1.2.4
HT Builder – WordPress Theme Builder for Elementor v1.2.4
1.3.5 1.3.4 trunk 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.8 1.0.9 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3
ht-builder / includes / admin / recommended-plugins / class.recommended-plugins.php

class.recommended-plugins.php in HT Builder – WordPress Theme Builder for Elementor 1.2.4, at includes/admin/recommended-plugins/class.recommended-plugins.php

422 lines 19.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Hasthemes\HTBuilder;
3
4 /**
5 * Recommended Plugins handlers class
6 * @version 1.0.3
7 */
8 class HTRP_Recommended_Plugins {
9
10 /**
11 * [$_instance]
12 * @var null
13 */
14 private static $_instance = null;
15
16 /**
17 * [$plugins_allowedtags] allow tag
18 * @var array
19 */
20 public $plugins_allowedtags = array(
21 'a' => array(
22 'href' => array(),
23 'title' => array(),
24 'target' => array(),
25 ),
26 'abbr' => array( 'title' => array() ),
27 'acronym' => array( 'title' => array() ),
28 'code' => array(),
29 'pre' => array(),
30 'em' => array(),
31 'strong' => array(),
32 'ul' => array(),
33 'ol' => array(),
34 'li' => array(),
35 'p' => array(),
36 'br' => array(),
37 );
38
39 /**
40 * Veriable Initialize
41 */
42 public $text_domain = '';
43 public $parent_menu_slug = '';
44 public $menu_label = '';
45 public $menu_page_slug = '';
46 public $menu_capability = '';
47 public $priority = '';
48 public $hook_suffix = '';
49 public $assets_url = '';
50 public $tab_list = [];
51
52 /**
53 * [instance] Initializes a singleton instance
54 * @return [Recommended_Plugins]
55 */
56 public static function instance( $args = [] ) {
57 if ( is_null( self::$_instance ) ) {
58 self::$_instance = new self( $args );
59 }
60 return self::$_instance;
61 }
62
63 /**
64 * [__construct] Class construct
65 */
66 function __construct( $args ) {
67
68 // Initialize properties
69 $this->text_domain = !empty( $args['text_domain'] ) ? $args['text_domain'] : 'htrp';
70 $this->parent_menu_slug = !empty( $args['parent_menu_slug'] ) ? $args['parent_menu_slug'] : 'plugins.php';
71 $this->menu_label = !empty( $args['menu_label'] ) ? $args['menu_label'] : esc_html__( 'Recommendations', $this->text_domain );
72 $this->menu_capability = !empty( $args['menu_capability'] ) ? $args['menu_capability'] : 'manage_options';
73 $this->menu_page_slug = !empty( $args['menu_page_slug'] ) ? $args['menu_page_slug'] : $this->text_domain . '_extensions';
74 $this->priority = !empty( $args['priority'] ) ? $args['priority'] : 100;
75 $this->hook_suffix = !empty( $args['hook_suffix'] ) ? $args['hook_suffix'] : '';
76 $this->assets_url = !empty( $args['assets_url'] ) ? $args['assets_url'] : plugins_url( 'assets', __FILE__ );
77 $this->tab_list = !empty( $args['tab_list'] ) ? $args['assets_url'] : [];
78
79
80 add_action( 'admin_menu', [ $this, 'admin_menu' ], $this->priority );
81 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
82
83 // Ajax Action
84 add_action( 'wp_ajax_'.$this->text_domain.'_ajax_plugin_activation', [ $this, 'plugin_activation' ] );
85
86 }
87
88 /**
89 * [admin_menu] Add Recommended Menu
90 * @return [void]
91 */
92 public function admin_menu(){
93 add_submenu_page(
94 $this->parent_menu_slug,
95 $this->menu_label,
96 $this->menu_label,
97 $this->menu_capability,
98 $this->menu_page_slug,
99 [ $this, 'render_html' ]
100 );
101 }
102
103 /**
104 * [enqueue_assets]
105 * @param [string] $hook_suffix Current page hook
106 * @return [void]
107 */
108 public function enqueue_assets( $hook_suffix ) {
109 if( $this->hook_suffix ){
110 if( $this->hook_suffix == $hook_suffix ){
111 add_thickbox();
112 wp_enqueue_script( 'htrp-plugin-install-manager', $this->assets_url . '/js/plugins_install_manager.js', array('jquery','wp-util', 'updates'), '1.0.0', true );
113 }
114 } else {
115 add_thickbox();
116 wp_enqueue_script( 'htrp-plugin-install-manager', $this->assets_url . '/js/plugins_install_manager.js', array('jquery','wp-util', 'updates'), '1.0.0', true );
117 }
118
119 $localize_vars['ajaxurl'] = admin_url('admin-ajax.php');
120 $localize_vars['text_domain'] = sanitize_title_with_dashes( $this->text_domain );
121 $localize_vars['buttontxt'] = array(
122 'buynow' => esc_html__( 'Buy Now', $this->text_domain ),
123 'preview' => esc_html__( 'Preview', $this->text_domain ),
124 'installing' => esc_html__( 'Installing..', $this->text_domain ),
125 'activating' => esc_html__( 'Activating..', $this->text_domain ),
126 'active' => esc_html__( 'Activated', $this->text_domain ),
127 );
128 wp_localize_script( 'htrp-plugin-install-manager', 'htrp_params', $localize_vars );
129
130 }
131
132 /**
133 * [add_new_tab]
134 * @param [void] set tab content
135 */
136 public function add_new_tab( $tab_list ){
137 $this->tab_list[] = $tab_list;
138 }
139
140 /**
141 * [render_html]
142 * @return [void] Render HTML
143 */
144 public function render_html(){
145 if ( ! function_exists('plugins_api') ){ include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); }
146
147 $htplugins_plugin_list = $this->get_plugins();
148 $palscode_plugin_list = $this->get_plugins( 'palscode' );
149 $move_plugin_list = $this->get_plugins( 'moveaddons' );
150
151 $plugin_list = array_merge( $htplugins_plugin_list, $palscode_plugin_list, $move_plugin_list );
152
153 $prepare_plugin = array();
154 foreach ( $plugin_list as $plugin_key => $plugin ) {
155 $prepare_plugin[$plugin['slug']] = $plugin;
156 }
157
158 ?>
159 <div class="wrap">
160 <h2><?php echo get_admin_page_title(); ?></h2>
161 <style>
162 .htrp-admin-tab-pane{
163 display: none;
164 }
165 .htrp-admin-tab-pane.htrp-active{
166 display: block;
167 }
168 .htrp-extension-admin-tab-area .filter-links li>a:focus, .htrp-extension-admin-tab-area .filter-links li>a:hover {
169 color: inherit;
170 box-shadow: none;
171 }
172 .filter-links .htrp-active{
173 box-shadow: none;
174 border-bottom: 4px solid #646970;
175 color: #1d2327;
176 }
177 .downloaded-count{
178 display: block;
179 margin-top:5px;
180 }
181 </style>
182
183 <div class="htrp-extension-admin-tab-area wp-filter">
184 <ul class="htrp-admin-tabs filter-links">
185 <?php
186 foreach( $this->tab_list as $tab ){
187 $active_class = isset( $tab['active'] ) && $tab['active'] ? 'htrp-active' : '';
188 ?>
189 <li>
190 <a href="#<?php echo esc_attr( sanitize_title_with_dashes( $tab['title'] ) ) ?>" class="<?php echo esc_attr( $active_class ) ?>"><?php echo esc_html( $tab['title'] ) ?></a>
191 </li>
192 <?php
193 }
194 ?>
195 </ul>
196 </div>
197
198 <?php
199 $plugins_type = '';
200 foreach( $this->tab_list as $tab ):
201
202 $active_class = isset( $tab['active'] ) && $tab['active'] ? 'htrp-active' : '';
203 $plugins = $tab['plugins'];
204
205 echo '<div id="'.esc_attr( sanitize_title_with_dashes( $tab['title'] ) ).'" class="htrp-admin-tab-pane '.esc_attr( $active_class ).'">';
206 foreach( $plugins as $plugin ):
207
208 $data = array(
209 'slug' => isset( $plugin['slug'] ) ? $plugin['slug'] : '',
210 'location' => isset( $plugin['location'] ) ? $plugin['slug'].'/'.$plugin['location'] : '',
211 'name' => isset( $plugin['name'] ) ? $plugin['name'] : '',
212 );
213
214 if( array_key_exists( $plugin['slug'], $prepare_plugin ) ){
215 $plugins_type = 'free';
216 $title = $data['name'] ? $data['name'] : $prepare_plugin[$plugin['slug']]['name'];
217 $title = wp_kses( $title, $this->plugins_allowedtags );
218 $image_url = $this->plugin_icon( $plugins_type, $prepare_plugin[$data['slug']]['icons'] );
219 $description = strip_tags( $prepare_plugin[$data['slug']]['description'] );
220 $author_name = wp_kses( $prepare_plugin[$data['slug']]['author'], $this->plugins_allowedtags );
221 $details_link = self_admin_url('plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .'&amp;TB_iframe=true&amp;width=772&amp;height=577');
222 $target = '_self';
223 $modal_class = 'class="thickbox open-plugin-details-modal"';
224
225 }else{
226 $plugins_type = 'pro';
227 $title = wp_kses( $plugin['name'], $this->plugins_allowedtags );
228 $image_url = $this->plugin_icon( $plugins_type, $plugin['slug'] );
229 $description = isset($plugin['description']) ? $plugin['description'] : '';
230 $author_name = esc_html__( 'HasTheme', $this->text_domain );
231 $author_link = isset($plugin['author_link']) ? $plugin['author_link'] : '';
232 $details_link = isset($plugin['link']) ? $plugin['link'] : '';
233 $button_text = esc_html__('Buy Now', $this->text_domain );
234 $button_classes = 'button button-primary';
235 $target = '_blank';
236 $modal_class = '';
237 }
238
239 if ( ! is_wp_error( $data ) ):
240
241 // Installed but Inactive.
242 if ( file_exists( WP_PLUGIN_DIR . '/' . $data['location'] ) && is_plugin_inactive( $data['location'] ) ) {
243
244 $button_classes = 'button activate-now button-primary';
245 $button_text = esc_html__( 'Activate', $this->text_domain );
246
247 // Not Installed.
248 } elseif ( ! file_exists( WP_PLUGIN_DIR . '/' . $data['location'] ) ) {
249
250 $button_classes = 'button install-now';
251 $button_text = esc_html__( 'Install Now', $this->text_domain );
252
253 // Active.
254 } else {
255 $button_classes = 'button disabled';
256 $button_text = esc_html__( 'Activated', $this->text_domain );
257 }
258
259 ?>
260 <div class="plugin-card htrp-plugin-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
261 <div class="plugin-card-top">
262 <div class="name column-name" style="margin-right: 0;">
263 <h3>
264 <a href="<?php echo esc_url( $details_link ) ?>" target="<?php echo esc_attr( $target ) ?>" <?php echo $modal_class; ?>>
265 <?php echo esc_html( $title ) ?>
266 <img src="<?php echo esc_url( $image_url ) ?>" class="plugin-icon" alt="<?php echo esc_attr( $title ) ?>">
267 </a>
268 </h3>
269 </div>
270 <div class="desc column-description" style="margin-right: 0;">
271 <p><?php echo wp_trim_words( $description, 23, '....'); ?></p>
272 <p class="authors">
273 <cite><?php echo esc_html__( 'By ', $this->text_domain ); ?>
274 <?php if( $plugins_type == 'free' ): ?>
275 <?php echo $author_name; ?>
276 <?php else: ?>
277 <a href="<?php echo esc_url( $author_link ); ?>" target="_blank" ><?php echo $author_name; ?></a>
278 <?php endif; ?>
279 </cite>
280 </p>
281 </div>
282 </div>
283 <div class="plugin-card-bottom">
284 <div class="column-updated">
285 <?php
286 if (! file_exists( WP_PLUGIN_DIR . '/' . $data['location'] ) && $plugins_type == 'pro' ) {
287 echo '<a class="button button-primary" href="'.esc_url( $details_link ).'" target="'.esc_attr( $target ).'">'.esc_html__( 'Buy Now', $this->text_domain ).'</a>';
288 }else{
289 ?>
290 <button class="<?php echo $button_classes; ?>" data-pluginopt='<?php echo wp_json_encode( $data ); ?>'><?php echo $button_text; ?></button>
291
292 <?php } ?>
293 </div>
294 <div class="column-downloaded">
295 <a href="<?php echo esc_url( $details_link ) ?>" target="<?php echo esc_attr( $target ) ?>" <?php echo $modal_class; ?>><?php echo esc_html__('More Details', $this->text_domain) ?></a>
296 <span class="downloaded-count">
297 <?php
298 if( $plugins_type == 'free' ){
299 /* translators: %s: Number of installations. */
300 printf( __( '%s Active Installations' ), $this->active_install_count( $prepare_plugin[$data['slug']]['active_installs'] ) );
301 }
302 ?>
303 </span>
304 </div>
305 </div>
306 </div>
307 <?php
308 endif;
309 endforeach;
310 echo '</div>';
311
312 endforeach;
313 ?>
314
315 </div>
316 <?php
317
318 }
319
320 /**
321 * [get_plugins] Get plugin from wp.org API
322 * @param string $username wo.org username
323 * @return [array] plugin list
324 */
325 public function get_plugins( $username = 'htplugins' ){
326 $transient_var = 'htrp_htplugins_list_'.$username;
327 $org_plugins_list = get_transient( $transient_var );
328
329 if ( false === $org_plugins_list ) {
330 $plugins_list_by_author = plugins_api( 'query_plugins', array( 'author' => $username, 'per_page' => 100 ) );
331 set_transient( $transient_var, $plugins_list_by_author->plugins, 1 * WEEK_IN_SECONDS );
332 $org_plugins_list = $plugins_list_by_author->plugins;
333 }
334
335 return $org_plugins_list;
336 }
337
338 /**
339 * [plugin_icon] Generate plugin icon
340 * @param string $type plugin type
341 * @param [array|string] $icon
342 * @return [URL] icon URL
343 */
344 public function plugin_icon( $type, $icon ){
345 if( $type === 'free' ){
346 if ( ! empty( $icon['svg'] ) ) {
347 $plugin_icon_url = $icon['svg'];
348 } elseif ( ! empty( $icon['2x'] ) ) {
349 $plugin_icon_url = $icon['2x'];
350 } elseif ( ! empty( $icon['1x'] ) ) {
351 $plugin_icon_url = $icon['1x'];
352 } else {
353 $plugin_icon_url = $icon['default'];
354 }
355 }else{
356 $plugin_icon_url = $this->assets_url .'/images/extensions/'.$icon.'.png';
357 }
358
359 return $plugin_icon_url;
360
361 }
362
363 /**
364 * [active_install_count] Manage Active install count
365 * @param [int] $active_installs
366 * @return [string]
367 */
368 public function active_install_count( $active_installs ){
369
370 if ( $active_installs >= 1000000 ) {
371 $active_installs_millions = floor( $active_installs / 1000000 );
372 $active_installs_text = sprintf(
373 /* translators: %s: Number of millions. */
374 _nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ),
375 number_format_i18n( $active_installs_millions )
376 );
377 } elseif ( 0 === $active_installs ) {
378 $active_installs_text = _x( 'Less Than 10', 'Active plugin installations' );
379 } else {
380 $active_installs_text = number_format_i18n( $active_installs ) . '+';
381 }
382 return $active_installs_text;
383
384 }
385
386 /**
387 * [plugin_activation] Plugin activation ajax callable function
388 * @return [JSON]
389 */
390 public function plugin_activation() {
391
392 if ( ! current_user_can( 'install_plugins' ) || ! isset( $_POST['location'] ) || ! $_POST['location'] ) {
393 wp_send_json_error(
394 array(
395 'success' => false,
396 'message' => esc_html__( 'Plugin Not Found', $this->text_domain ),
397 )
398 );
399 }
400
401 $plugin_location = ( isset( $_POST['location'] ) ) ? esc_attr( $_POST['location'] ) : '';
402 $activate = activate_plugin( $plugin_location, '', false, true );
403
404 if ( is_wp_error( $activate ) ) {
405 wp_send_json_error(
406 array(
407 'success' => false,
408 'message' => $activate->get_error_message(),
409 )
410 );
411 }
412
413 wp_send_json_success(
414 array(
415 'success' => true,
416 'message' => esc_html__( 'Plugin Successfully Activated', $this->text_domain ),
417 )
418 );
419
420 }
421 }
422