term_id] = $term->name;
}
}
} else {
$qt = 'SELECT * FROM ' . $wpdb->terms . ' AS t INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = "' . $taxonomy . '" AND tt.count > 0 ORDER BY t.term_id DESC LIMIT 0 , 30';
$terms = $wpdb->get_results( $qt, ARRAY_A );
if ( $terms && !is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
$term_coll[$term['term_id']] = $term['name'];
}
}
}
return $term_coll;
}
function lvca_get_chosen_terms( $query_args )
{
$chosen_terms = array();
$taxonomies = array();
if ( !empty($query_args) ) {
if ( !empty($query_args['cat']) ) {
$taxonomies[] = 'category';
$term_ids = explode( ',', $query_args['cat'] );
foreach ( $term_ids as $term_id ) {
$chosen_terms[] = get_term( $term_id, 'category' );
}
} elseif ( !empty($query_args['tag__in']) ) {
$taxonomies[] = 'post_tag';
$term_ids = $query_args['tag__in'];
foreach ( $term_ids as $term_id ) {
$chosen_terms[] = get_term( $term_id, 'post_tag' );
}
} elseif ( !empty($query_args['tax_query']) ) {
$term_queries = $query_args['tax_query'];
foreach ( $term_queries as $terms_query ) {
if ( !is_array( $terms_query ) ) {
continue;
}
$field = $terms_query['field'];
$taxonomy = $terms_query['taxonomy'];
$terms = $terms_query['terms'];
if ( empty($taxonomy) || empty($terms) ) {
continue;
}
if ( !in_array( $taxonomy, $taxonomies ) ) {
$taxonomies[] = $taxonomy;
}
if ( is_array( $terms ) ) {
foreach ( $terms as $term ) {
$chosen_terms[] = get_term_by( $field, $term, $taxonomy );
}
} else {
$chosen_terms[] = get_term_by( $field, $terms, $taxonomy );
}
}
}
}
// Remove duplicates
$taxonomies = array_unique( $taxonomies );
return array( $chosen_terms, $taxonomies );
}
function lvca_entry_terms_list(
$taxonomy = 'category',
$separator = ', ',
$before = ' ',
$after = ' '
)
{
global $post ;
$output = '';
$output .= get_the_term_list(
$post->ID,
$taxonomy,
$before,
$separator,
$after
);
$output .= '';
return $output;
}
function lvca_get_taxonomy_info( $taxonomy )
{
$output = '';
$terms = get_the_terms( get_the_ID(), $taxonomy );
if ( !empty($terms) && !is_wp_error( $terms ) ) {
$output .= '';
$term_count = 0;
foreach ( $terms as $term ) {
if ( $term_count != 0 ) {
$output .= ', ';
}
$output .= '' . $term->name . '';
$term_count = $term_count + 1;
}
$output .= '';
}
return $output;
}
function lvca_get_info_for_taxonomies( $taxonomies )
{
$output = '';
foreach ( $taxonomies as $taxonomy ) {
$output .= lvca_get_taxonomy_info( $taxonomy );
}
return $output;
}
if ( !function_exists( 'lvca_get_posts' ) ) {
function lvca_get_posts()
{
$list = array();
$args = $args = array(
'posts_per_page' => -1,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'post_status' => 'publish',
'suppress_filters' => true,
);
$posts = get_posts( $args );
if ( !empty($posts) ) {
foreach ( $posts as $post ) {
$list[$post->ID] = $post->post_title;
}
}
return $list;
}
}
if ( !function_exists( 'lvca_entry_published' ) ) {
function lvca_entry_published( $format = null )
{
if ( empty($format) ) {
$format = get_option( 'date_format' );
}
$published = '' . sprintf( get_the_time( $format ) ) . '';
return $published;
$link = '' . '' . '' . get_the_time( $format ) . '' . '';
return $link;
}
}
if ( !function_exists( 'lvca_entry_author' ) ) {
function lvca_entry_author()
{
$author = '' . esc_html__( 'By ', 'livemesh-vc-addons' ) . '' . esc_html( get_the_author_meta( 'display_name' ) ) . '';
return $author;
}
}
/** Isotope filtering support for Portfolio pages * */
function lvca_get_taxonomy_terms_filter( $taxonomies, $chosen_terms = array() )
{
$output = '';
if ( empty($chosen_terms) ) {
global $wp_version ;
if ( version_compare( $wp_version, '4.5', '>=' ) ) {
$terms = get_terms( $taxonomies );
} else {
$terms = get_terms( $taxonomies[0] );
}
} else {
$terms = $chosen_terms;
}
if ( !empty($terms) && !is_wp_error( $terms ) ) {
$output .= '
';
$output .= '
';
$segment_count = 1;
foreach ( $terms as $term ) {
$output .= '
';
$segment_count++;
}
$output .= '
';
}
return $output;
}
/* Return the css class name to help achieve the number of columns specified for mobile resolution */
function lvca_get_grid_classes( $settings, $columns_field = 'per_line' )
{
$grid_classes = ' lvca-grid-desktop-';
$grid_classes .= $settings[$columns_field];
$grid_classes .= ' lvca-grid-tablet-';
$grid_classes .= $settings[$columns_field . '_tablet'];
$grid_classes .= ' lvca-grid-mobile-';
$grid_classes .= $settings[$columns_field . '_mobile'];
return $grid_classes;
}
/*
* Converting string to boolean is a big one in PHP
*/
if ( !function_exists( 'lvca_to_boolean' ) ) {
function lvca_to_boolean( $value )
{
if ( !isset( $value ) ) {
return false;
}
if ( $value == 'true' || $value == '1' ) {
$value = true;
} elseif ( $value == 'false' || $value == '0' ) {
$value = false;
}
return (bool) $value;
// Make sure you do not touch the value if the value is not a string
}
}
/*
* Get icon font given a font family
*/
if ( !function_exists( 'lvca_get_icon' ) ) {
function lvca_get_icon( $icon_class )
{
return '';
}
}
// get all registered taxonomies
if ( !function_exists( 'lvca_get_taxonomies_map' ) ) {
function lvca_get_taxonomies_map()
{
$map = array();
$taxonomies = get_taxonomies();
foreach ( $taxonomies as $taxonomy ) {
$map[$taxonomy] = $taxonomy;
}
return $map;
}
}
/**
* Lightens/darkens a given colour (hex format), returning the altered colour in hex format.7
* @param str $hex Colour as hexadecimal (with or without hash);
* @percent float $percent Decimal ( 0.2 = lighten by 20%(), -0.4 = darken by 40%() )
* @return str Lightened/Darkend colour as hexadecimal (with hash);
*/
function lvca_color_luminance( $hex, $percent )
{
// validate hex string
$hex = preg_replace( '/[^0-9a-f]/i', '', $hex );
$new_hex = '#';
if ( strlen( $hex ) < 6 ) {
$hex = $hex[0] + $hex[0] + $hex[1] + $hex[1] + $hex[2] + $hex[2];
}
// convert to decimal and change luminosity
for ( $i = 0 ; $i < 3 ; $i++ ) {
$dec = hexdec( substr( $hex, $i * 2, 2 ) );
$dec = min( max( 0, $dec + $dec * $percent ), 255 );
$new_hex .= str_pad(
dechex( $dec ),
2,
0,
STR_PAD_LEFT
);
}
return $new_hex;
}
function lvca_get_option( $option_name, $default = null )
{
$settings = get_option( 'lvca_settings' );
if ( !empty($settings) && isset( $settings[$option_name] ) ) {
$option_value = $settings[$option_name];
} else {
$option_value = $default;
}
return $option_value;
}
function lvca_update_option( $option_name, $option_value )
{
$settings = get_option( 'lvca_settings' );
if ( empty($settings) ) {
$settings = array();
}
$settings[$option_name] = $option_value;
update_option( 'lvca_settings', $settings );
}
/**
* Update multiple options in one go
* @param array $setting_data An collection of settings key value pairs;
*/
function lvca_update_options( $setting_data )
{
$settings = get_option( 'lvca_settings' );
if ( empty($settings) ) {
$settings = array();
}
foreach ( $setting_data as $setting => $value ) {
// because of get_magic_quotes_gpc()
$value = stripslashes( $value );
$settings[$setting] = $value;
}
update_option( 'lvca_settings', $settings );
}
/**
* Get system info
*
*/
function lvca_get_sysinfo()
{
global $wpdb ;
// Get theme info
$theme_data = wp_get_theme();
$theme = $theme_data->Name . ' ' . $theme_data->Version;
$return = '### Begin System Info ###' . "\n\n";
// Start with the basics...
$return .= '-- Site Info' . "\n\n";
$return .= 'Site URL: ' . site_url() . "\n";
$return .= 'Home URL: ' . home_url() . "\n";
$return .= 'Multisite: ' . (( is_multisite() ? 'Yes' : 'No' )) . "\n";
// Theme info
$plugin = get_plugin_data( LVCA_PLUGIN_FILE );
// Plugin configuration
$return .= "\n" . '-- Plugin Configuration' . "\n\n";
$return .= 'Name: ' . $plugin['Name'] . "\n";
$return .= 'Version: ' . $plugin['Version'] . "\n";
// WordPress configuration
$return .= "\n" . '-- WordPress Configuration' . "\n\n";
$return .= 'Version: ' . get_bloginfo( 'version' ) . "\n";
$return .= 'Language: ' . (( defined( 'WPLANG' ) && WPLANG ? WPLANG : 'en_US' )) . "\n";
$return .= 'Permalink Structure: ' . (( get_option( 'permalink_structure' ) ? get_option( 'permalink_structure' ) : 'Default' )) . "\n";
$return .= 'Active Theme: ' . $theme . "\n";
$return .= 'Show On Front: ' . get_option( 'show_on_front' ) . "\n";
// Only show page specs if frontpage is set to 'page'
if ( get_option( 'show_on_front' ) == 'page' ) {
$front_page_id = get_option( 'page_on_front' );
$blog_page_id = get_option( 'page_for_posts' );
$return .= 'Page On Front: ' . (( $front_page_id != 0 ? get_the_title( $front_page_id ) . ' (#' . $front_page_id . ')' : 'Unset' )) . "\n";
$return .= 'Page For Posts: ' . (( $blog_page_id != 0 ? get_the_title( $blog_page_id ) . ' (#' . $blog_page_id . ')' : 'Unset' )) . "\n";
}
$return .= 'ABSPATH: ' . ABSPATH . "\n";
$return .= 'WP_DEBUG: ' . (( defined( 'WP_DEBUG' ) ? ( WP_DEBUG ? 'Enabled' : 'Disabled' ) : 'Not set' )) . "\n";
$return .= 'Memory Limit: ' . WP_MEMORY_LIMIT . "\n";
$return .= 'Registered Post Stati: ' . implode( ', ', get_post_stati() ) . "\n";
// Get plugins that have an update
$updates = get_plugin_updates();
// WordPress active plugins
$return .= "\n" . '-- WordPress Active Plugins' . "\n\n";
$plugins = get_plugins();
$active_plugins = get_option( 'active_plugins', array() );
foreach ( $plugins as $plugin_path => $plugin ) {
if ( !in_array( $plugin_path, $active_plugins ) ) {
continue;
}
$update = ( array_key_exists( $plugin_path, $updates ) ? ' (needs update - ' . $updates[$plugin_path]->update->new_version . ')' : '' );
$return .= $plugin['Name'] . ': ' . $plugin['Version'] . $update . "\n";
}
// WordPress inactive plugins
$return .= "\n" . '-- WordPress Inactive Plugins' . "\n\n";
foreach ( $plugins as $plugin_path => $plugin ) {
if ( in_array( $plugin_path, $active_plugins ) ) {
continue;
}
$update = ( array_key_exists( $plugin_path, $updates ) ? ' (needs update - ' . $updates[$plugin_path]->update->new_version . ')' : '' );
$return .= $plugin['Name'] . ': ' . $plugin['Version'] . $update . "\n";
}
if ( is_multisite() ) {
// WordPress Multisite active plugins
$return .= "\n" . '-- Network Active Plugins' . "\n\n";
$plugins = wp_get_active_network_plugins();
$active_plugins = get_site_option( 'active_sitewide_plugins', array() );
foreach ( $plugins as $plugin_path ) {
$plugin_base = plugin_basename( $plugin_path );
if ( !array_key_exists( $plugin_base, $active_plugins ) ) {
continue;
}
$update = ( array_key_exists( $plugin_path, $updates ) ? ' (needs update - ' . $updates[$plugin_path]->update->new_version . ')' : '' );
$plugin = get_plugin_data( $plugin_path );
$return .= $plugin['Name'] . ': ' . $plugin['Version'] . $update . "\n";
}
}
// Server configuration (really just versioning)
$return .= "\n" . '-- Webserver Configuration' . "\n\n";
$return .= 'PHP Version: ' . PHP_VERSION . "\n";
$return .= 'MySQL Version: ' . $wpdb->db_version() . "\n";
$return .= 'Webserver Info: ' . $_SERVER['SERVER_SOFTWARE'] . "\n";
// PHP configs... now we're getting to the important stuff
$return .= "\n" . '-- PHP Configuration' . "\n\n";
$return .= 'Memory Limit: ' . ini_get( 'memory_limit' ) . "\n";
$return .= 'Upload Max Size: ' . ini_get( 'upload_max_filesize' ) . "\n";
$return .= 'Post Max Size: ' . ini_get( 'post_max_size' ) . "\n";
$return .= 'Upload Max Filesize: ' . ini_get( 'upload_max_filesize' ) . "\n";
$return .= 'Time Limit: ' . ini_get( 'max_execution_time' ) . "\n";
$return .= 'Max Input Vars: ' . ini_get( 'max_input_vars' ) . "\n";
$return .= 'Display Errors: ' . (( ini_get( 'display_errors' ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A' )) . "\n";
$return = apply_filters( 'edd_sysinfo_after_php_config', $return );
// PHP extensions and such
$return .= "\n" . '-- PHP Extensions' . "\n\n";
$return .= 'cURL: ' . (( function_exists( 'curl_init' ) ? 'Supported' : 'Not Supported' )) . "\n";
$return .= 'fsockopen: ' . (( function_exists( 'fsockopen' ) ? 'Supported' : 'Not Supported' )) . "\n";
$return .= 'SOAP Client: ' . (( class_exists( 'SoapClient' ) ? 'Installed' : 'Not Installed' )) . "\n";
$return .= 'Suhosin: ' . (( extension_loaded( 'suhosin' ) ? 'Installed' : 'Not Installed' )) . "\n";
$return .= "\n" . '### End System Info ###';
return $return;
}
function lvca_get_animation_atts( $animation )
{
$animate_class = "";
$animation_attr = "";
if ( $animation != "none" ) {
$animate_class = ' lvca-animate-on-scroll';
if ( in_array( $animation, array(
'bounceIn',
'bounceInUp',
'bounceInDown',
'bounceInLeft',
'bounceInRight',
'fadeIn',
'fadeInLeft',
'fadeInRight',
'fadeInUp',
'fadeInDown',
'fadeInLeftBig',
'fadeInRightBig',
'fadeInUpBig',
'fadeInDownBig',
'flipInX',
'flipInY',
'lightSpeedIn',
'rotateIn',
'rotateInDownLeft',
'rotateInDownRight',
'rotateInUpLeft',
'rotateInUpRight',
'slideInUp',
'slideInDown',
'slideInLeft',
'slideInRight',
'zoomIn',
'zoomInUp',
'zoomInDown',
'zoomInLeft',
'zoomInRight',
'rollIn'
) ) ) {
$animate_class .= ' lvca-visible-on-scroll';
}
$animation_attr = ' data-animation="' . esc_attr( $animation ) . '"';
}
return array( $animate_class, $animation_attr );
}
function lvca_get_animation_options()
{
return array(
'none' => __( 'None', 'livemesh-vc-addons' ),
'fadeIn' => __( 'Fade In', 'livemesh-vc-addons' ),
'fadeInLeft' => __( 'Fade In Left', 'livemesh-vc-addons' ),
'fadeInRight' => __( 'Fade In Right', 'livemesh-vc-addons' ),
);
}
/**
* List all available image sizes
*/
function lvca_get_image_sizes()
{
global $_wp_additional_image_sizes ;
$new_sizes = array();
$added_sizes = get_intermediate_image_sizes();
foreach ( $added_sizes as $size ) {
$size_name = ucfirst( str_replace( '_', ' ', $size ) );
// Hidden size added in 4.4 for responsive images. We don't need it.
if ( 'medium_large' == $size ) {
continue;
}
if ( in_array( $size, array( 'thumbnail', 'medium', 'large' ) ) ) {
$new_sizes[$size] = $size_name . ' ' . get_option( $size . '_size_w' ) . 'x' . get_option( $size . '_size_h' );
} elseif ( isset( $_wp_additional_image_sizes ) && isset( $_wp_additional_image_sizes[$size] ) ) {
$new_sizes[$size] = $size_name . ' ' . $_wp_additional_image_sizes[$size]['width'] . 'x' . $_wp_additional_image_sizes[$size]['height'];
}
}
$std_sizes = array(
'full' => __( 'Original Size', 'livemesh-vc-addons' ),
'thumbnail' => __( 'Thumbnail', 'livemesh-vc-addons' ),
'medium' => __( 'Medium', 'livemesh-vc-addons' ),
'large' => __( 'Large', 'livemesh-vc-addons' ),
);
$new_sizes = array_merge( $std_sizes, $new_sizes );
return array_flip( $new_sizes );
}