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 / helper-function.php

helper-function.php in HT Builder – WordPress Theme Builder for Elementor 1.2.4, at includes/helper-function.php

265 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * Helper Functions
5 */
6
7 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
8
9 /*
10 * Plugisn Options value
11 * return on/off
12 */
13 if( !function_exists('htbuilder_get_option') ){
14 function htbuilder_get_option( $option, $section, $default = '' ){
15 if(isset($_GET['header'])){
16 switch ($_GET['header']) {
17 case '1':
18 return 1884;
19 break;
20
21 case '2':
22 return 1986;
23 break;
24 }
25 }
26
27 $options = get_option( $section );
28 if ( isset( $options[$option] ) ) {
29 return $options[$option];
30 }
31 return $default;
32 }
33 }
34
35 /*
36 * Elementor Setting page value
37 * return $elget_value
38 */
39 if( !function_exists('htbuilder_get_elementor_setting') ){
40 function htbuilder_get_elementor_setting( $key, $post_id ){
41 // Get the page settings manager
42 $page_settings_manager = \Elementor\Core\Settings\Manager::get_settings_managers( 'page' );
43
44 // Get the settings model for current post
45 $page_settings_model = $page_settings_manager->get_model( $post_id );
46
47 // Retrieve value
48 $elget_value = $page_settings_model->get_settings( $key );
49 return $elget_value;
50 }
51 }
52
53
54 /*
55 * Elementor Templates List
56 * return array
57 */
58 if( !function_exists('htbuilder_elementor_template') ){
59 function htbuilder_elementor_template() {
60 $templates = \Elementor\Plugin::instance()->templates_manager->get_source( 'local' )->get_items();
61 $types = array();
62 if ( empty( $templates ) ) {
63 $template_lists = [ '0' => __( 'Do not Saved Templates.', 'ht-builder' ) ];
64 } else {
65 $template_lists = [ '0' => __( 'Select Template', 'ht-builder' ) ];
66 foreach ( $templates as $template ) {
67 $template_lists[ $template['template_id'] ] = $template['title'] . ' (' . $template['type'] . ')';
68 }
69 }
70 return $template_lists;
71 }
72 }
73
74
75 /**
76 * Elementor version
77 */
78 function htbuilder_elementor_version( $operator = '<', $version = '2.6.0' ) {
79 if( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, $version, $operator ) ) { return true; } else{ return false; }
80 }
81
82 /**
83 * Generate Elementor icon
84 */
85 function htbuilder_render_icon( $settings = [], $new_icon = 'selected_icon', $old_icon = 'icon', $attributes = [] ){
86
87 $migrated = isset( $settings['__fa4_migrated'][$new_icon] );
88 $is_new = empty( $settings[$old_icon] ) && \Elementor\Icons_Manager::is_migration_allowed();
89
90 $attributes['aria-hidden'] = 'true';
91 $output = '';
92
93 if ( htbuilder_elementor_version( '>=', '2.6.0' ) && ( $is_new || $migrated ) ) {
94
95 if ( empty( $settings[$new_icon]['library'] ) ) {
96 return false;
97 }
98
99 $tag = 'i';
100 // handler SVG Icon
101 if ( 'svg' === $settings[$new_icon]['library'] ) {
102 if ( ! isset( $settings[$new_icon]['value']['id'] ) ) {
103 return '';
104 }
105 $output = Elementor\Core\Files\Assets\Svg\Svg_Handler::get_inline_svg( $settings[$new_icon]['value']['id'] );
106
107 } else {
108 $icon_types = \Elementor\Icons_Manager::get_icon_manager_tabs();
109 if ( isset( $icon_types[ $settings[$new_icon]['library'] ]['render_callback'] ) && is_callable( $icon_types[ $settings[$new_icon]['library'] ]['render_callback'] ) ) {
110 return call_user_func_array( $icon_types[ $settings[$new_icon]['library'] ]['render_callback'], [ $settings[$new_icon], $attributes, $tag ] );
111 }
112
113 if ( empty( $attributes['class'] ) ) {
114 $attributes['class'] = $settings[$new_icon]['value'];
115 } else {
116 if ( is_array( $attributes['class'] ) ) {
117 $attributes['class'][] = $settings[$new_icon]['value'];
118 } else {
119 $attributes['class'] .= ' ' . $settings[$new_icon]['value'];
120 }
121 }
122 $output = '<' . $tag . ' ' . \Elementor\Utils::render_html_attributes( $attributes ) . '></' . $tag . '>';
123 }
124
125 } else {
126 if ( empty( $attributes['class'] ) ) {
127 $attributes['class'] = $settings[ $old_icon ];
128 } else {
129 if ( is_array( $attributes['class'] ) ) {
130 $attributes['class'][] = $settings[ $old_icon ];
131 } else {
132 $attributes['class'] .= ' ' . $settings[ $old_icon ];
133 }
134 }
135 $output = sprintf( '<i %s></i>', \Elementor\Utils::render_html_attributes( $attributes ) );
136 }
137
138 return $output;
139
140 }
141
142
143 /**
144 * Blog page return true
145 */
146 if( !function_exists('htbuilder_is_blog_page') ){
147 function htbuilder_is_blog_page() {
148 global $post;
149 //Post type must be 'post'.
150 $post_type = get_post_type( $post );
151 return (
152 ( is_home() || is_archive() )
153 && ( $post_type == 'post')
154 ) ? true : false ;
155 }
156 }
157
158 /*
159 * HTML Tag list
160 * return array
161 */
162 if( !function_exists('htbuilder_html_tag_lists') ){
163 function htbuilder_html_tag_lists() {
164 $html_tag_list = [
165 'h1' => __( 'H1', 'ht-builder' ),
166 'h2' => __( 'H2', 'ht-builder' ),
167 'h3' => __( 'H3', 'ht-builder' ),
168 'h4' => __( 'H4', 'ht-builder' ),
169 'h5' => __( 'H5', 'ht-builder' ),
170 'h6' => __( 'H6', 'ht-builder' ),
171 'p' => __( 'p', 'ht-builder' ),
172 'div' => __( 'div', 'ht-builder' ),
173 'span' => __( 'span', 'ht-builder' ),
174 ];
175 return $html_tag_list;
176 }
177 }
178
179
180 /*
181 * Custom Pagination
182 */
183 function htbuilder_custom_pagination( $totalpage ){
184 $big = 999999999;
185 echo '<div class="htbuilder-pagination">';
186 echo paginate_links( array(
187 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
188 'format' => '?paged=%#%',
189 'current' => max( 1, get_query_var('paged') ),
190 'total' => $totalpage,
191 'prev_text' => '&larr;',
192 'next_text' => '&rarr;',
193 'type' => 'list',
194 'end_size' => 3,
195 'mid_size' => 3
196 ) );
197 echo '</div>';
198 }
199
200
201 /*
202 * Plugisn API Data Fetch
203 */
204 function htbuilder_get_org_plugins( $author = 'htplugins' ) {
205
206 $plcachekey = 'hastech_plugins';
207 $plugins_data = get_transient( $plcachekey );
208
209 if ( !$plugins_data ) {
210
211 $args = (object) array(
212 'author' => $author,
213 'per_page' => '50',
214 'page' => '1',
215 'fields' => array( 'slug', 'name', 'version', 'downloaded', 'active_installs' )
216 );
217 $request = array( 'action' => 'query_plugins', 'timeout' => 15, 'request' => serialize( $args ) );
218
219 //https://codex.wordpress.org/WordPress.org_API
220 $url = 'http://api.wordpress.org/plugins/info/1.0/';
221 $response = wp_remote_post( $url, array( 'body' => $request ) );
222 if ( ! is_wp_error( $response ) ) {
223 $plugins_data = array();
224 $plugins = unserialize( $response['body'] );
225 if ( isset( $plugins->plugins ) && ( count( $plugins->plugins ) > 0 ) ) {
226 foreach ( $plugins->plugins as $pl_info ) {
227 $plugins_data[] = array(
228 'slug' => $pl_info->slug,
229 'name' => $pl_info->name,
230 'version' => $pl_info->version,
231 'downloaded' => $pl_info->downloaded,
232 'active_installs' => $pl_info->active_installs
233 );
234 }
235 }
236 set_transient( $plcachekey, $plugins_data, 24 * HOUR_IN_SECONDS );
237 }
238 }
239
240 if ( is_array( $plugins_data ) && ( count( $plugins_data ) > 0 ) ) {
241 array_multisort( array_column( $plugins_data, 'active_installs' ), SORT_DESC, $plugins_data );
242
243 foreach ( $plugins_data as $pl_data ) {
244 $extension = '.png';
245 $jpegs = array('quickswish', 'ht-social-share', 'docus', 'whols', 'wptemplata', 'wishsuite', 'ht-menu-lite', '99fy-core', 'ever-compare', 'wp-plugin-manager', 'extensions-for-cf7');
246
247 if( in_array($pl_data['slug'], $jpegs) ){
248 $extension = '.jpg';
249 }
250
251 ?>
252 <div class="htoptions-single-plugins htfree-plugins">
253 <div class="htoptions-img">
254 <img src="https://ps.w.org/<?php echo $pl_data['slug']; ?>/assets/icon-128x128<?php echo $extension; ?>" alt="">
255 </div>
256 <div class="htoptions-plugins-content">
257 <a href="https://wordpress.org/plugins/<?php echo $pl_data['slug']; ?>/"><h3><?php echo esc_html__( $pl_data['name'], 'ht-builder' ); ?></h3></a>
258 <a class="htoptions-button" href="<?php echo esc_url( admin_url() ); ?>plugin-install.php?s=<?php echo $pl_data['slug']; ?>&tab=search&type=term" target="_blank"><?php echo esc_html__( 'Install Now', 'ht-builder' ); ?></a>
259 </div>
260 </div>
261 <?php
262 }
263 }
264
265 }