| 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 |
* HTML Tag Validation |
| 181 |
* return strig |
| 182 |
*/ |
| 183 |
if( !function_exists('htbuilder_validate_html_tag') ){ |
| 184 |
function htbuilder_validate_html_tag( $tag ) { |
| 185 |
$allowed_html_tags = [ |
| 186 |
'article', |
| 187 |
'aside', |
| 188 |
'footer', |
| 189 |
'header', |
| 190 |
'section', |
| 191 |
'nav', |
| 192 |
'main', |
| 193 |
'div', |
| 194 |
'h1', |
| 195 |
'h2', |
| 196 |
'h3', |
| 197 |
'h4', |
| 198 |
'h5', |
| 199 |
'h6', |
| 200 |
'p', |
| 201 |
'span', |
| 202 |
]; |
| 203 |
$valid_tag = is_string( $tag ) ? strtolower( $tag ) : 'div'; |
| 204 |
return in_array( $valid_tag, $allowed_html_tags ) ? $tag : 'div'; |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
/* |
| 209 |
* Custom Pagination |
| 210 |
*/ |
| 211 |
function htbuilder_custom_pagination( $totalpage ){ |
| 212 |
$big = 999999999; |
| 213 |
echo '<div class="htbuilder-pagination">'; |
| 214 |
echo paginate_links( array( |
| 215 |
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
| 216 |
'format' => '?paged=%#%', |
| 217 |
'current' => max( 1, get_query_var('paged') ), |
| 218 |
'total' => $totalpage, |
| 219 |
'prev_text' => '←', |
| 220 |
'next_text' => '→', |
| 221 |
'type' => 'list', |
| 222 |
'end_size' => 3, |
| 223 |
'mid_size' => 3 |
| 224 |
) ); |
| 225 |
echo '</div>'; |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
/* |
| 230 |
* Plugisn API Data Fetch |
| 231 |
*/ |
| 232 |
function htbuilder_get_org_plugins( $author = 'htplugins' ) { |
| 233 |
|
| 234 |
$plcachekey = 'hastech_plugins'; |
| 235 |
$plugins_data = get_transient( $plcachekey ); |
| 236 |
|
| 237 |
if ( !$plugins_data ) { |
| 238 |
|
| 239 |
$args = (object) array( |
| 240 |
'author' => $author, |
| 241 |
'per_page' => '50', |
| 242 |
'page' => '1', |
| 243 |
'fields' => array( 'slug', 'name', 'version', 'downloaded', 'active_installs' ) |
| 244 |
); |
| 245 |
$request = array( 'action' => 'query_plugins', 'timeout' => 15, 'request' => serialize( $args ) ); |
| 246 |
|
| 247 |
//https://codex.wordpress.org/WordPress.org_API |
| 248 |
$url = 'http://api.wordpress.org/plugins/info/1.0/'; |
| 249 |
$response = wp_remote_post( $url, array( 'body' => $request ) ); |
| 250 |
if ( ! is_wp_error( $response ) ) { |
| 251 |
$plugins_data = array(); |
| 252 |
$plugins = unserialize( $response['body'] ); |
| 253 |
if ( isset( $plugins->plugins ) && ( count( $plugins->plugins ) > 0 ) ) { |
| 254 |
foreach ( $plugins->plugins as $pl_info ) { |
| 255 |
$plugins_data[] = array( |
| 256 |
'slug' => $pl_info->slug, |
| 257 |
'name' => $pl_info->name, |
| 258 |
'version' => $pl_info->version, |
| 259 |
'downloaded' => $pl_info->downloaded, |
| 260 |
'active_installs' => $pl_info->active_installs |
| 261 |
); |
| 262 |
} |
| 263 |
} |
| 264 |
set_transient( $plcachekey, $plugins_data, 24 * HOUR_IN_SECONDS ); |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
if ( is_array( $plugins_data ) && ( count( $plugins_data ) > 0 ) ) { |
| 269 |
array_multisort( array_column( $plugins_data, 'active_installs' ), SORT_DESC, $plugins_data ); |
| 270 |
|
| 271 |
foreach ( $plugins_data as $pl_data ) { |
| 272 |
$extension = '.png'; |
| 273 |
$jpegs = array('quickswish', 'ht-social-share', 'docus', 'whols', 'wptemplata', 'wishsuite', 'ht-menu-lite', '99fy-core', 'ever-compare', 'wp-plugin-manager', 'extensions-for-cf7'); |
| 274 |
|
| 275 |
if( in_array($pl_data['slug'], $jpegs) ){ |
| 276 |
$extension = '.jpg'; |
| 277 |
} |
| 278 |
|
| 279 |
?> |
| 280 |
<div class="htoptions-single-plugins htfree-plugins"> |
| 281 |
<div class="htoptions-img"> |
| 282 |
<img src="https://ps.w.org/<?php echo $pl_data['slug']; ?>/assets/icon-128x128<?php echo $extension; ?>" alt=""> |
| 283 |
</div> |
| 284 |
<div class="htoptions-plugins-content"> |
| 285 |
<a href="https://wordpress.org/plugins/<?php echo $pl_data['slug']; ?>/"><h3><?php echo esc_html__( $pl_data['name'], 'ht-builder' ); ?></h3></a> |
| 286 |
<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> |
| 287 |
</div> |
| 288 |
</div> |
| 289 |
<?php |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
} |