芝麻web文件管理V1.00
编辑当前文件:/home/disqkgca/aqanet.org/wp-content/plugins/htmega-pro/includes/helper-function.php
'); /** * Options return */ function htmega_get_option_pro( $option, $section, $default = '' ){ $options = get_option( $section ); if ( isset( $options[$option] ) ) { return $options[$option]; } return $default; } function htmega_pro_get_elementor() { return \Elementor\Plugin::instance(); } /** * [htmega_pro_template_endpoint] * @return [url] */ function htmega_pro_template_endpoint(){ return 'https://library.wphtmega.com/wp-json/htmega/v1promnmnsdc/templates'; } /** * [htmega_pro_template_url] * @return [url] */ function htmega_pro_template_url(){ return 'https://library.wphtmega.com/wp-json/htmega/v1/templates/%s'; } /** * [htmega_get_cookie_name] Get Compare cookie name * @return [string] */ function htmega_get_cookie_name() { $name = 'htmega_has_count'; if ( is_multisite() ){ $name .= '_' . get_current_blog_id(); } return $name; } /** * [htmega_setpostviews] * @param [int] $postid * @param [string] $posttype * @return [null] */ if( !function_exists('htmega_setpostviews') ){ function htmega_setpostviews( $postid, $posttype ) { if( $posttype == 'page' ){ $count_key = 'ht_page_views_count'; }else{ $count_key = 'ht_post_views_count'; } $count = get_post_meta( $postid, $count_key, true ); if( $count == '' ){ $count = 0; delete_post_meta( $postid, $count_key ); add_post_meta( $postid, $count_key, '0' ); }else{ // if the post has already been stored under the cookie $cookie_name = htmega_get_cookie_name(); if( !isset( $_COOKIE[ $cookie_name.'-'.$postid ] ) ){ setcookie( $cookie_name.'-'.$postid, 'htmega_already_count', 0, COOKIEPATH, COOKIE_DOMAIN, false, false ); $_COOKIE[$cookie_name.'-'.$postid] = "htmega_already_count"; $count++; update_post_meta( $postid, $count_key, $count ); } } } } /* * Get View Counter * return $count */ if( !function_exists('htmega_getpostviews') ){ function htmega_getpostviews( $postid, $posttype ){ if( $posttype == 'page' ){ $count_key = 'ht_page_views_count'; }else{ $count_key = 'ht_post_views_count'; } $count = get_post_meta( $postid, $count_key, true ); if( $count == '' ){ delete_post_meta( $postid, $count_key ); add_post_meta( $postid, $count_key, '0' ); return "0"; } return $count; } } /* * Get View Counter * return $count */ if( !function_exists('htmega_view_count') ){ function htmega_view_count(){ if( is_single() && get_post_type() == 'post' ){ htmega_setpostviews( get_the_ID(), 'post' ); }elseif( is_singular( 'page' ) && get_post_type() == 'page' ){ htmega_setpostviews( get_the_ID(), 'page' ); } } add_action('template_redirect', 'htmega_view_count'); } /** * [htmega_addons_language_code] * @return [array] */ function htmega_addons_language_code(){ return [ 'af' => 'Afrikaans', 'sq' => 'Albanian', 'ar' => 'Arabic', 'eu' => 'Basque', 'bn' => 'Bengali', 'bs' => 'Bosnian', 'bg' => 'Bulgarian', 'ca' => 'Catalan', 'zh-cn' => 'Chinese', 'zh-tw' => 'Chinese-tw', 'hr' => 'Croatian', 'cs' => 'Czech', 'da' => 'Danish', 'nl' => 'Dutch', 'en' => 'English', 'et' => 'Estonian', 'fi' => 'Finnish', 'fr' => 'French', 'gl' => 'Galician', 'ka' => 'Georgian', 'de' => 'German', 'el' => 'Greek (Modern)', 'he' => 'Hebrew', 'hi' => 'Hindi', 'hu' => 'Hungarian', 'is' => 'Icelandic', 'io' => 'Ido', 'id' => 'Indonesian', 'it' => 'Italian', 'ja' => 'Japanese', 'kk' => 'Kazakh', 'ko' => 'Korean', 'lv' => 'Latvian', 'lb' => 'Letzeburgesch', 'lt' => 'Lithuanian', 'lu' => 'Luba-Katanga', 'mk' => 'Macedonian', 'mg' => 'Malagasy', 'ms' => 'Malay', 'ro' => 'Moldovan, Moldavian, Romanian', 'nb' => 'Norwegian Bokmål', 'nn' => 'Norwegian Nynorsk', 'fa' => 'Persian', 'pl' => 'Polish', 'pt' => 'Portuguese', 'ru' => 'Russian', 'sr' => 'Serbian', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'es' => 'Spanish', 'sv' => 'Swedish', 'tr' => 'Turkish', 'uk' => 'Ukrainian', 'vi' => 'Vietnamese', ]; } /** * Escaped title html tags * * @param string $tag input string of title tag * @return string $default default tag will be return during no matches */ function htmega_escape_tags( $tag, $default = 'span', $extra = [] ) { $supports = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'span', 'p']; $supports = array_merge( $supports, $extra ); if ( !in_array($tag, $supports, true) ) { return $default; } return $tag; } /* * All Taxonomie Category Load * return Array */ if( !function_exists('all_object_taxonomie_show_catagory') ){ function all_object_taxonomie_show_catagory($taxonomieName){ $allTaxonomie = get_object_taxonomies($taxonomieName); if(isset($allTaxonomie['0'])){ if($allTaxonomie['0'] == "product_type"){ $allTaxonomie['0'] = 'product_cat'; } return htmega_get_taxonomies($allTaxonomie['0']); } } } /* * Get Taxonomie by Post Type * return Array */ if( !function_exists('get_taxonomie_by_post_type') ){ function get_taxonomie_by_post_type($taxonomieName){ $args=array('object_type' => array($taxonomieName)); $output = 'objects'; // or objects $operator = 'and'; // 'and' or 'or' $taxonomies = get_taxonomies($args,$output,$operator); $newTaxonomyList = array(); if ($taxonomies) { foreach ($taxonomies as $taxonomy ) { $newTaxonomyList[$taxonomy->name] = $taxonomy->label; } } return $newTaxonomyList; } } /* * Get Post Type * return Array */ if( !function_exists('htmega_get_terms_post_types') ){ function htmega_get_terms_post_types(){ $post_types = htmega_get_post_types(); $newTermsPost = array(); foreach($post_types as $typeKey => $typeValue){ if($typeKey != 'page' && $typeKey != 'e-landing-page'){ $newTermsPost[$typeKey] = $typeValue; } } return $newTermsPost; } } /* * Get rating * Input average value,font size, empty color, rated color,icon class * return html star with div */ if( !function_exists('htmega_get_avg_rating') ){ function htmega_get_avg_rating( $avg=100, $font_size=23, $empty_color="#E2E0E5", $rated_color="#FCBD23"){ $avg = (int)$avg; $font_size = (int)$font_size; $star_width = ($font_size * 5)+16; ?>
[ 'edit_posts' ], 'has_published_posts' => true, 'fields' => [ 'ID', 'display_name', ], ]; // Version check 5.9. if ( version_compare( $GLOBALS['wp_version'], '5.9-alpha', '<' ) ) { $args['who'] = 'authors'; unset( $args['capability'] ); } $authors = get_users( $args ); if ( ! empty( $authors ) ) { return wp_list_pluck( $authors, 'display_name', 'ID' ); } return []; } /** * Get all Tags List * * @param array $args * * @return array */ function htmega_get_tags_list( $args = array() ) { $options = []; $tags = get_tags( $args ); if (!is_wp_error( $tags ) && !empty( $tag )) { foreach ( $tags as $tag ) { $options[$tag->term_id] = $tag->name; } } return $options; } /** * Get all Database Table List * * @version 1.5.2 * @return array */ function htmega_all_db_tbl_list() { global $wpdb; $all_tbl_list = []; $all_tables = $wpdb->get_results('show tables', ARRAY_N); if ( $all_tables ) { $all_tables = wp_list_pluck($all_tables, 0); foreach ( $all_tables as $table ) { $all_tbl_list[$table] = $table; } } return $all_tbl_list; } /** * Get TablePress table list * * @version 1.5.2 * @return array */ function htmega_get_table_press_tbl_list() { $tbl_list = []; if ( !class_exists('TablePress') ) return $tbl_list; $all_tables = TablePress::$model_table->load_all(true); if ( $all_tables ) { foreach ( $all_tables as $table ) { $table = TablePress::$model_table->load( $table, false, false ); $tbl_list[$table['id']] = $table['name']; } } return $tbl_list; } /** * get all the user roll * * @version 1.5.3 * @return array */ function htmega_get_user_roles() { $wp_roles = []; $all_roles = wp_roles()->roles; foreach ( $all_roles as $slug => $role ) { $wp_roles[ $slug ] = $role['name']; } return $wp_roles; } /** * Compare value. * @since 1.6.0 * Compare two values based on Comparison operator * * @param mixed $left_value First value to compare. * @param mixed $right_value Second value to compare. * @param string $operator Comparison operator. * @return bool */ function htmega_value_compare( $left_value, $right_value, $operator ) { switch ( $operator ) { case 'is': return $left_value == $right_value; case 'not': return $left_value != $right_value; default: return $left_value === $right_value; } } /** * Get User Browser name * * @version 1.6.0 * @param $user_agent * @return string */ function htmega_get_browser_name( $user_agent ) { if ( strpos( $user_agent, 'Opera' ) || strpos( $user_agent, 'OPR/' ) ) return 'opera'; elseif ( strpos( $user_agent, 'Edge' ) ) return 'edge'; elseif ( strpos( $user_agent, 'Edg' ) ) return 'edge'; elseif ( strpos( $user_agent, 'Chrome' ) ) return 'chrome'; elseif ( strpos( $user_agent, 'Safari' ) ) return 'safari'; elseif ( strpos( $user_agent, 'Firefox' ) ) return 'firefox'; elseif ( strpos( $user_agent, 'MSIE' ) || strpos( $user_agent, 'Trident/7' ) ) return 'ie'; return 'other'; } /** * @version 1.6.0 * Get Client Website Time * @param string $format * @return string */ function htmega_get_local_time( $format = 'Y-m-d h:i:s A' ) { $local_time_zone = isset( $_COOKIE['HTMegaLocalTimeZone'] ) && !empty( $_COOKIE['HTMegaLocalTimeZone'] ) ? str_replace( 'GMT ', 'GMT+', $_COOKIE['HTMegaLocalTimeZone'] ) : date_default_timezone_get(); $now_date = new \DateTime( 'now', new \DateTimeZone( $local_time_zone ) ); $today = $now_date->format( $format ); return $today; } /** * @version 1.6.0 * Get Server Time * @param string $format * @return string */ function htmega_get_server_time( $format = 'Y-m-d h:i:s A' ) { $today = gmdate( $format, strtotime("now") + ( get_option( 'gmt_offset') * HOUR_IN_SECONDS ) ); return $today; } /** * @version 1.6.1 * Get Elementor template id using template title * * @param [type] $template_title * @return int/void */ function htmega_get_template_id_by_title( $template_title ) { $query = new WP_Query( array( 'post_type' => 'elementor_library', 'posts_per_page' => 1, 's' => $template_title, // Search by template title ) ); // Check if there are any posts found if ($query->have_posts()) { // Return the first template ID found $template_id = $query->posts[0]->ID; return $template_id; } // Template not found return false; } /** * ExtractVideoId * @since 1.7.4 * @param [type] $url * @return $videoid || null */ function htmega_extract_video_id($url) { // Parse the URL and extract the "v" parameter $parsed_url = wp_parse_url($url); // check if exist youtube.com in the url if ( strpos($url, 'youtube.com') !== false || strpos($url, 'youtu.be') !== false ) { if (isset($parsed_url['query'])) { parse_str($parsed_url['query'], $query_params); if (isset($query_params['v'])) { return $query_params['v']; } } // If the above method didn't work, try to extract the video ID from the path $path = trim($parsed_url['path'], '/'); $path_parts = explode('/', $path); foreach ($path_parts as $part) { if (strlen($part) === 11) { return $part; } } } else if ( strpos($url, 'vimeo.com') !== false ) { // If the URL is a Vimeo URL, extract the video ID from the path $path = trim($parsed_url['path'], '/'); $path_parts = explode('/', $path); foreach ($path_parts as $part) { if (is_numeric($part)) { return $part; } } } // Return null if the video ID couldn't be found return null; } /** * Slugify * Slugify a string to be used as a URL slug or class name. * * @param string $text * @param string $separator (optional) * @param string $as_class_name (optional) if slug has , then retun the text adding a space * @return string */ function htmega_slugify($text, $as_class_name = false, $separator = '-' ) { // Check if the text contains a comma if ( $as_class_name && strpos($text, ',') !== false ) { // Split the text by commas and process each word $words = explode(',', $text); $trimmed_and_cleaned_words = []; foreach ($words as $word) { // Trim each word and remove non-alphanumeric characters $word = preg_replace('/[^a-zA-Z0-9]+/', '', trim($word)); if (!empty($word)) { $trimmed_and_cleaned_words[] = $word; } } return $text = implode(' ', $trimmed_and_cleaned_words); } // Convert the string to lowercase and remove non-alphanumeric characters. $text = strtolower(preg_replace('/[^a-zA-Z0-9]+/', $separator, $text)); // Remove leading and trailing separator characters. $text = trim($text, $separator); return $text; } /** * [htmega_clean] * @param [JSON] $var * @return [array] */ if( !function_exists('htmega_clean') ) { function htmega_clean( $var ) { if ( is_array( $var ) ) { return array_map( 'htmega_clean', $var ); } else { return is_scalar( $var ) ? esc_html( $var ) : $var; } } } /** * [htmega_get_local_file_data] * @param string $file_path * @return mixed $data | false */ if ( ! function_exists( 'htmega_get_local_file_data' ) ) { function htmega_get_local_file_data( $file_path ) { if ( ! file_exists( $file_path ) ) { return false; } // Initialize the WordPress filesystem global $wp_filesystem; if ( empty( $wp_filesystem ) ) { require_once( ABSPATH . 'wp-admin/includes/file.php' ); WP_Filesystem(); } // Check if the file is readable if ( ! is_readable( $file_path ) ) { return false; } // Read the file contents using the WP_Filesystem API $data = $wp_filesystem->get_contents( $file_path ); if ( $data === false ) { return false; } return $data; } } /** * [htmega_get_remote_file_data] * @param string $file_url * @return mixed $data | false */ if ( ! function_exists( 'htmega_get_remote_file_data' ) ) { function htmega_get_remote_file_data( $file_url ) { // Using wp_remote_get to fetch the remote file $response = wp_remote_get( $file_url ); // Check if the response contains an error if ( is_wp_error( $response ) ) { return false; } // Retrieve the body of the response $data = wp_remote_retrieve_body( $response ); // Check if the body is empty if ( empty( $data ) ) { return false; } return $data; } }