예제 #1
0
                <?php 
if (isset($post->post_images)) {
    $post->post_images = trim($post->post_images, ",");
}
if (isset($post->post_images) && !empty($post->post_images)) {
    $post_images = explode(",", $post->post_images);
}
$main_slides = '';
$nav_slides = '';
if (empty($post_images)) {
    $default_img = '';
    $default_cat = '';
    if (isset($post->post_default_category)) {
        $default_cat = $post->post_default_category;
    }
    if ($default_catimg = geodir_get_default_catimage($default_cat, $post_type)) {
        $default_img = $default_catimg['src'];
    } elseif ($no_images = get_option('geodir_listing_no_img')) {
        $default_img = $no_images;
    }
    if (!empty($default_img)) {
        $post_images[] = $default_img;
    }
}
$slides = 0;
if (!empty($post_images)) {
    foreach ($post_images as $image) {
        if (!empty($image)) {
            @(list($width, $height) = getimagesize(trim($image)));
            if ($image && $width && $height) {
                $image = (object) array('src' => $image, 'width' => $width, 'height' => $height);
예제 #2
0
 /**
  * Gets the post images.
  *
  * @since 1.0.0
  * @package GeoDirectory
  * @global object $wpdb WordPress Database object.
  * @param int $post_id The post ID.
  * @param string $img_size Optional. Thumbnail size.
  * @param bool $no_images Optional. Do you want to return the default image when no image is available? Default: false.
  * @param bool $add_featured Optional. Do you want to include featured images too? Default: true.
  * @param int|string $limit Optional. Number of images.
  * @return array|bool Returns images as an array. Each item is an object.
  */
 function geodir_get_images($post_id = 0, $img_size = '', $no_images = false, $add_featured = true, $limit = '')
 {
     global $wpdb;
     if ($limit) {
         $limit_q = " LIMIT {$limit} ";
     } else {
         $limit_q = '';
     }
     $not_featured = '';
     $sub_dir = '';
     if (!$add_featured) {
         $not_featured = " AND is_featured = 0 ";
     }
     $arrImages = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE mime_type like %s AND post_id = %d" . $not_featured . " ORDER BY menu_order ASC, ID DESC {$limit_q} ", array('%image%', $post_id)));
     $counter = 0;
     $return_arr = array();
     if (!empty($arrImages)) {
         foreach ($arrImages as $attechment) {
             $img_arr = array();
             $img_arr['id'] = $attechment->ID;
             $img_arr['user_id'] = isset($attechment->user_id) ? $attechment->user_id : 0;
             $file_info = pathinfo($attechment->file);
             if ($file_info['dirname'] != '.' && $file_info['dirname'] != '..') {
                 $sub_dir = stripslashes_deep($file_info['dirname']);
             }
             $uploads = wp_upload_dir(trim($sub_dir, '/'));
             // Array of key => value pairs
             $uploads_baseurl = $uploads['baseurl'];
             $uploads_path = $uploads['path'];
             $file_name = $file_info['basename'];
             $uploads_url = $uploads_baseurl . $sub_dir;
             $img_arr['src'] = $uploads_url . '/' . $file_name;
             $img_arr['path'] = $uploads_path . '/' . $file_name;
             @(list($width, $height) = getimagesize($img_arr['path']));
             $img_arr['width'] = $width;
             $img_arr['height'] = $height;
             $img_arr['file'] = $file_name;
             // add the title to the array
             $img_arr['title'] = $attechment->title;
             // add the title to the array
             $img_arr['caption'] = isset($attechment->caption) ? $attechment->caption : '';
             // add the caption to the array
             $img_arr['content'] = $attechment->content;
             // add the description to the array
             $img_arr['is_approved'] = isset($attechment->is_approved) ? $attechment->is_approved : '';
             // used for user image moderation. For backward compatibility Default value is 1.
             $return_arr[] = (object) $img_arr;
             $counter++;
         }
         return (object) $return_arr;
     } else {
         if ($no_images) {
             $default_img = '';
             $default_cat = geodir_get_post_meta($post_id, 'default_category', true);
             $post_type = get_post_type($post_id);
             if ($default_catimg = geodir_get_default_catimage($default_cat, $post_type)) {
                 $default_img = $default_catimg['src'];
             } elseif ($no_images) {
                 $default_img = get_option('geodir_listing_no_img');
             }
             if (!empty($default_img)) {
                 $uploads = wp_upload_dir();
                 // Array of key => value pairs
                 $uploads_baseurl = $uploads['baseurl'];
                 $uploads_path = $uploads['path'];
                 $img_arr = array();
                 $file_info = pathinfo($default_img);
                 $file_name = $file_info['basename'];
                 $img_arr['src'] = $default_img;
                 $img_arr['path'] = $uploads_path . '/' . $file_name;
                 @(list($width, $height) = getimagesize($img_arr['path']));
                 $img_arr['width'] = $width;
                 $img_arr['height'] = $height;
                 $img_arr['file'] = $file_name;
                 // add the title to the array
                 $img_arr['title'] = $file_name;
                 // add the title to the array
                 $img_arr['content'] = $file_name;
                 // add the description to the array
                 $return_arr[] = (object) $img_arr;
                 return $return_arr;
             } else {
                 return false;
             }
         }
     }
 }
/**
 * Output the details page slider HTML.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global bool $preview True of on a preview page. False if not.
 * @global object $post The current post object.
 */
function geodir_action_details_slider()
{
    global $preview, $post;
    $is_backend_preview = is_single() && !empty($_REQUEST['post_type']) && !empty($_REQUEST['preview']) && !empty($_REQUEST['p']) && is_super_admin() ? true : false;
    // preview from backend
    if ($is_backend_preview && !empty($post) && !empty($post->ID) && !isset($post->post_images)) {
        $preview_get_images = geodir_get_images($post->ID, 'thumbnail', get_option('geodir_listing_no_img'));
        $preview_post_images = array();
        if ($preview_get_images) {
            foreach ($preview_get_images as $row) {
                $preview_post_images[] = $row->src;
            }
        }
        if (!empty($preview_post_images)) {
            $post->post_images = implode(',', $preview_post_images);
        }
    }
    if ($preview) {
        if (isset($post->post_images) && !empty($post->post_images)) {
            $post->post_images = trim($post->post_images, ",");
            $post_images = explode(",", $post->post_images);
        }
        $main_slides = '';
        $nav_slides = '';
        $slides = 0;
        if (empty($post_images)) {
            $default_img = '';
            $default_cat = '';
            if (isset($post->post_default_category)) {
                $default_cat = $post->post_default_category;
            }
            if ($default_catimg = geodir_get_default_catimage($default_cat, $post->listing_type)) {
                $default_img = $default_catimg['src'];
            } else {
                if ($no_images = get_option('geodir_listing_no_img')) {
                    $default_img = $no_images;
                }
            }
            if (!empty($default_img)) {
                $post_images[] = $default_img;
            }
        }
        if (!empty($post_images)) {
            foreach ($post_images as $image) {
                if (!empty($image)) {
                    @(list($width, $height) = getimagesize(trim($image)));
                    if ($image && $width && $height) {
                        $image = (object) array('src' => $image, 'width' => $width, 'height' => $height);
                    }
                    if (isset($image->src)) {
                        if ($image->height >= 400) {
                            $spacer_height = 0;
                        } else {
                            $spacer_height = (400 - $image->height) / 2;
                        }
                        $image_title = isset($image->title) ? $image->title : '';
                        $main_slides .= '<li><img src="' . geodir_plugin_url() . "/geodirectory-assets/images/spacer.gif" . '" alt="' . $image_title . '" title="' . $image_title . '" style="max-height:' . $spacer_height . 'px;margin:0 auto;" />';
                        $main_slides .= '<img src="' . $image->src . '" alt="' . $image_title . '" title="' . $image_title . '" style="max-height:400px;margin:0 auto;" /></li>';
                        $nav_slides .= '<li><img src="' . $image->src . '" alt="' . $image_title . '" title="' . $image_title . '" style="max-height:48px;margin:0 auto;" /></li>';
                        $slides++;
                    }
                }
            }
            // endfore
        }
        //end if
    } else {
        $main_slides = '';
        $nav_slides = '';
        $post_images = geodir_get_images($post->ID, 'thumbnail', get_option('geodir_listing_no_img'));
        $slides = 0;
        if (empty($post_images) && get_option('geodir_listing_no_img')) {
            $post_images = (object) array((object) array('src' => get_option('geodir_listing_no_img')));
        }
        if (!empty($post_images)) {
            foreach ($post_images as $image) {
                if ($image->height >= 400) {
                    $spacer_height = 0;
                } else {
                    $spacer_height = (400 - $image->height) / 2;
                }
                $main_slides .= '<li><img src="' . geodir_plugin_url() . "/geodirectory-assets/images/spacer.gif" . '" alt="' . $image->title . '" title="' . $image->title . '" style="max-height:' . $spacer_height . 'px;margin:0 auto;" />';
                $main_slides .= '<img src="' . $image->src . '" alt="' . $image->title . '" title="' . $image->title . '" style="max-height:400px;margin:0 auto;" itemprop="image"/></li>';
                $nav_slides .= '<li><img src="' . $image->src . '" alt="' . $image->title . '" title="' . $image->title . '" style="max-height:48px;margin:0 auto;" /></li>';
                $slides++;
            }
        }
        // endfore
    }
    if (!empty($post_images)) {
        ?>
        <div class="geodir_flex-container">
            <div class="geodir_flex-loader"><i class="fa fa-refresh fa-spin"></i></div>
            <div id="geodir_slider" class="geodir_flexslider ">
                <ul class="geodir-slides clearfix"><?php 
        echo $main_slides;
        ?>
</ul>
            </div>
            <?php 
        if ($slides > 1) {
            ?>
                <div id="geodir_carousel" class="geodir_flexslider">
                    <ul class="geodir-slides clearfix"><?php 
            echo $nav_slides;
            ?>
</ul>
                </div>
            <?php 
        }
        ?>
        </div>
    <?php 
    }
}
예제 #4
0
/**
 * Retrieve terms for given post type.
 *
 * @since 1.4.6
 * @package GeoDirectory
 *
 * @param  string $post_type The post type.
 * @return array Array of terms data.
 */
function geodir_imex_get_terms($post_type)
{
    $args = array('hide_empty' => 0, 'orderby' => 'id');
    remove_all_filters('get_terms');
    $taxonomy = $post_type . 'category';
    $terms = get_terms($taxonomy, $args);
    $csv_rows = array();
    if (!empty($terms)) {
        $csv_row = array();
        $csv_row[] = 'cat_id';
        $csv_row[] = 'cat_name';
        $csv_row[] = 'cat_slug';
        $csv_row[] = 'cat_posttype';
        $csv_row[] = 'cat_parent';
        $csv_row[] = 'cat_description';
        $csv_row[] = 'cat_top_description';
        $csv_row[] = 'cat_image';
        $csv_row[] = 'cat_icon';
        // WPML
        $is_wpml = geodir_is_wpml();
        if ($is_wpml) {
            $csv_row[] = 'cat_language';
        }
        // WPML
        $csv_rows[] = $csv_row;
        foreach ($terms as $term) {
            $cat_icon = get_tax_meta($term->term_id, 'ct_cat_icon', false, $post_type);
            $cat_icon = !empty($cat_icon) && isset($cat_icon['src']) ? $cat_icon['src'] : '';
            $cat_image = geodir_get_default_catimage($term->term_id, $post_type);
            $cat_image = !empty($cat_image) && isset($cat_image['src']) ? $cat_image['src'] : '';
            $cat_parent = '';
            if (isset($term->parent) && (int) $term->parent > 0 && term_exists((int) $term->parent, $taxonomy)) {
                $parent_term = (array) get_term_by('id', (int) $term->parent, $taxonomy);
                $cat_parent = !empty($parent_term) && isset($parent_term['name']) ? $parent_term['name'] : '';
            }
            $csv_row = array();
            $csv_row[] = $term->term_id;
            $csv_row[] = $term->name;
            $csv_row[] = $term->slug;
            $csv_row[] = $post_type;
            $csv_row[] = $cat_parent;
            $csv_row[] = $term->description;
            $csv_row[] = get_tax_meta($term->term_id, 'ct_cat_top_desc', false, $post_type);
            $csv_row[] = $cat_image;
            $csv_row[] = $cat_icon;
            // WPML
            if ($is_wpml) {
                $csv_row[] = geodir_get_language_for_element($term->term_id, 'tax_' . $taxonomy);
            }
            // WPML
            $csv_rows[] = $csv_row;
        }
    }
    return $csv_rows;
}