GavickPro / Meet-GavernWP

Meet GavernWP is a responsive free Wordpress theme
35 stars 23 forks source link

An error occured during creating the thumbnail on GK news Show Pro #207

Closed Fiskaperdana closed 11 years ago

Fiskaperdana commented 11 years ago

I try widget GK news Show Pro. I try to show newest article's title & image on sidebar but not work properly. An error occured during creating the thumbnail was shown. WP: 3,5,1 Theme: Meet Gavern 1.7 gk news problem

dziudek commented 11 years ago

Hi,

First of all, please check the permissions for the gavern/cache_nsp directory.

Fiskaperdana commented 11 years ago

@dziudek i am sorry. I try it on localhost, My OS windows 7. How i check permissions for the gavern/cache_nsp directory.? i ask to my friend too, He told me, that the windows did not recognize the directory permissions like linux server.. Thanks..

My OS Windows 7, Xampp Version 1.8.0 lite

dziudek commented 11 years ago

In this case we will need more debug - please open file gavern/widgets.nsp.php and change method generate_art_image to:

function generate_art_image($i) {
        $art_ID = '';

        if($this->wdgt_config['data_source_type'] == 'custom') {
            $art_ID = $this->wdgt_results[0][$i]->ID;
        } else {
            $art_ID = $this->wdgt_results[$i]->ID;
        }

        $art_url = get_permalink($art_ID);

        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $art_ID ), 'single-post-thumbnail' );
        $image_path = $image[0];
        $upload_dir = wp_upload_dir();
        $image_path = str_replace($upload_dir['baseurl'] . DIRECTORY_SEPARATOR, '', $image_path);
                echo '$image_path: ' . $image_path;

        if($image_path != '') {
            $img_editor = wp_get_image_editor( $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $image_path);
                        echo '$img_editor: ' . $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $image_path;

            if(!is_wp_error($img_editor)) {
                $img_editor->resize($this->wdgt_config['article_image_w'], $this->wdgt_config['article_image_h'], true);
                $img_filename = $img_editor->generate_filename( $this->id, dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cache_nsp');
                $img_editor->save($img_filename);

                $new_path = $img_filename;  

                if(is_string($new_path)) {
                    $new_path_pos = stripos($new_path, '/gavern/cache_nsp');
                    $new_path = substr($new_path, $new_path_pos);
                    $new_path = get_template_directory_uri() . $new_path;

                    $style = '';

                    if($this->wdgt_config['image_block_padding'] != '' && $this->wdgt_config['image_block_padding'] != '0') {
                        $style = ' style="margin: '.$this->wdgt_config['image_block_padding'].';"';
                    }

                    if($this->wdgt_config['article_image_pos'] == 'left' && $this->wdgt_config['article_image_order'] == 1) {
                        return '<div class="gk-nsp-image-wrap"><a href="'.$art_url.'" class="gk-image-link"><img src="'.$new_path.'" alt="" class="gk-nsp-image" '.$style.' /></a></div>';
                    } else {
                        return '<a href="'.$art_url.'" class="gk-responsive gk-image-link"><img src="'.$new_path.'" alt="" class="gk-nsp-image gk-responsive" '.$style.' /></a>';
                    }
                } else {
                    return __('An error occured during creating the thumbnail.', GKTPLNAME);
                }
            } else {
                return __('An error occured during creating the thumbnail.', GKTPLNAME);
            }
        } else {
            return '';
        } 
     }

then please resave the widget configuration and write me what is returned.

Fiskaperdana commented 11 years ago

@dziudek after i change method generate_art_image browser show me error like this:

$image_path: http://localhost/meetwp17/wp-content/uploads/2013/04/logo-fiskawebcrp.png$img_editor: E:\xampp-win32-1.8.0-usb-lite\xampp\htdocs\meetwp17/wp-content/uploads\http://localhost/meetwp17/wp-content/uploads/2013/04/logo-fiskawebcrp.png

and still show me message "An error occured during creating the thumbnail "

Picture2

dziudek commented 11 years ago

Please add also after line:

echo '$image_path: ' . $image_path;

line:

echo '$dir: ' . $upload_dir['baseurl'] . DIRECTORY_SEPARATOR;

then I'll have probably all necessary information to fix your problem.

Fiskaperdana commented 11 years ago

after i add your line browser show me message like this:

$image_path: http://localhost/meetwp17/wp-content/uploads/2013/04/logo-fiskawebcrp.png$dir: http://localhost/meetwp17/wp-content/uploads\$img_editor: E:\xampp-win32-1.8.0-usb-lite\xampp\htdocs\meetwp17/wp-content/uploads\http://localhost/meetwp17/wp-content/uploads/2013/04/logo-fiskawebcrp.png

@dziudek Thanks very much for your help,

dziudek commented 11 years ago

Please try this code in the generate_art_image method:

function generate_art_image($i) {
        $art_ID = '';

        if($this->wdgt_config['data_source_type'] == 'custom') {
            $art_ID = $this->wdgt_results[0][$i]->ID;
        } else {
            $art_ID = $this->wdgt_results[$i]->ID;
        }

        $art_url = get_permalink($art_ID);

        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $art_ID ), 'single-post-thumbnail' );
        $image_path = $image[0];
        $upload_dir = wp_upload_dir();
        $image_path = str_replace($upload_dir['baseurl'] . '/', '', $image_path);

        if($image_path != '') {
            $img_editor = wp_get_image_editor( $upload_dir['basedir'] . '/' . $image_path);

            if(!is_wp_error($img_editor)) {
                $img_editor->resize($this->wdgt_config['article_image_w'], $this->wdgt_config['article_image_h'], true);
                $img_filename = $img_editor->generate_filename( $this->id, dirname(__FILE__) . '/' . 'cache_nsp');
                $img_editor->save($img_filename);

                $new_path = $img_filename;  

                if(is_string($new_path)) {
                    $new_path_pos = stripos($new_path, '/gavern/cache_nsp');
                    $new_path = substr($new_path, $new_path_pos);
                    $new_path = get_template_directory_uri() . $new_path;

                    $style = '';

                    if($this->wdgt_config['image_block_padding'] != '' && $this->wdgt_config['image_block_padding'] != '0') {
                        $style = ' style="margin: '.$this->wdgt_config['image_block_padding'].';"';
                    }

                    if($this->wdgt_config['article_image_pos'] == 'left' && $this->wdgt_config['article_image_order'] == 1) {
                        return apply_filters('gk_nsp_art_image', '<div class="gk-nsp-image-wrap"><a href="'.$art_url.'" class="gk-image-link"><img src="'.$new_path.'" alt="" class="gk-nsp-image" '.$style.' /></a></div>');
                    } else {
                        return apply_filters('gk_nsp_art_image', '<a href="'.$art_url.'" class="gk-responsive gk-image-link"><img src="'.$new_path.'" alt="" class="gk-nsp-image gk-responsive" '.$style.' /></a>');
                    }
                } else {
                    return __('An error occured during creating the thumbnail.', GKTPLNAME);
                }
            } else {
                return __('An error occured during creating the thumbnail.', GKTPLNAME);
            }
        } else {
            return '';
        } 
     }

Of course please remember to resave the widget configuration :)

Fiskaperdana commented 11 years ago

I have tested your code. Thumbnail generated correctly in gavern/cache_nsp directory,
but image not shown properly. I think. there is a mistake in making the link on src attribute. You can see copy src path below.

<img src="http://localhost/meetwp17/wp-content/themes/MeetGavernWPE:\xampp-win32-1.8.0-usb-lite\xampp\htdocs\meetwp17\wp-content\themes\meetme-fiska\gavern\cache_nsp/logo-fiskawebcrp-widget_gk_nsp-7.png" alt="" class="gk-nsp-image gk-responsive">
dziudek commented 11 years ago

OK, please change line:

$new_path_pos = stripos($new_path, '/gavern/cache_nsp');

to:

$new_path_pos = stripos($new_path, '/gavern/cache_nsp');
if($new_path_pos === FALSE) {
    $new_path_pos = stripos($new_path, '\gavern\cache_nsp');    
}

it should helps :)

Fiskaperdana commented 11 years ago

@dziudek , I am sorry friend, after i change it, my browser still show blank image. from your code, image path generated like HTML code below:

<img src="http://localhost/meetwp17/wp-content/themes/MeetGavernWP\gavern\cache_nsp/logo-fiskawebcrp-widget_gk_nsp-9.png" alt="" class="gk-nsp-image gk-responsive">

before i change your update like this :

<img src="http://localhost/meetwp17/wp-content/themes/MeetGavernWPE:\xampp-win32-1.8.0-usb-lite\xampp\htdocs\meetwp17\wp-content\themes\meetme-fiska\gavern\cache_nsp/logo-fiskawebcrp-widget_gk_nsp-7.png" alt="" class="gk-nsp-image gk-responsive">

in this case i use child theme (meetme fiska). image path should generated like this

<img src="http://localhost/meetwp17/wp-content/themes/meetme-fiska/gavern/cache_nsp/logo-fiskawebcrp-widget_gk_nsp-9.png" alt="" class="gk-nsp-image gk-responsive">

till now, i still learn your code..

I am sorry about my problem.. thanks very much

NormanUK commented 11 years ago

Perhaps it would be easier with below code.

$new_path = basename($img_filename);  
$cache_uri = get_template_directory_uri() . '/gavern/cache_nsp/';
if(is_string($new_path)) {
        $new_path = $cache_uri . $new_path;

Tested in local win server works fine.

dziudek commented 11 years ago

@NormanUK :+1:

@Fiskaperdana - please try to use this function:

function generate_art_image($i) {
        $art_ID = '';

        if($this->wdgt_config['data_source_type'] == 'custom') {
            $art_ID = $this->wdgt_results[0][$i]->ID;
        } else {
            $art_ID = $this->wdgt_results[$i]->ID;
        }

        $art_url = get_permalink($art_ID);

        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $art_ID ), 'single-post-thumbnail' );
        $image_path = $image[0];
        $upload_dir = wp_upload_dir();
        $image_path = str_replace($upload_dir['baseurl'] . '/', '', $image_path);

        if($image_path != '') {
            $img_editor = wp_get_image_editor( $upload_dir['basedir'] . '/' . $image_path);

            if(!is_wp_error($img_editor)) {
                $img_editor->resize($this->wdgt_config['article_image_w'], $this->wdgt_config['article_image_h'], true);
                $img_filename = $img_editor->generate_filename( $this->id, dirname(__FILE__) . '/' . 'cache_nsp');
                $img_editor->save($img_filename);

                $new_path = basename($img_filename);  
                $cache_uri = get_template_directory_uri() . '/gavern/cache_nsp/';

                if(is_string($new_path)) {
                    $new_path = $cache_uri . $new_path;

                    $style = '';

                    if($this->wdgt_config['image_block_padding'] != '' && $this->wdgt_config['image_block_padding'] != '0') {
                        $style = ' style="margin: '.$this->wdgt_config['image_block_padding'].';"';
                    }

                    if($this->wdgt_config['article_image_pos'] == 'left' && $this->wdgt_config['article_image_order'] == 1) {
                        return apply_filters('gk_nsp_art_image', '<div class="gk-nsp-image-wrap"><a href="'.$art_url.'" class="gk-image-link"><img src="'.$new_path.'" alt="" class="gk-nsp-image" '.$style.' /></a></div>');
                    } else {
                        return apply_filters('gk_nsp_art_image', '<a href="'.$art_url.'" class="gk-responsive gk-image-link"><img src="'.$new_path.'" alt="" class="gk-nsp-image gk-responsive" '.$style.' /></a>');
                    }
                } else {
                    return __('An error occured during creating the thumbnail.', GKTPLNAME);
                }
            } else {
                return __('An error occured during creating the thumbnail.', GKTPLNAME);
            }
        } else {
            return '';
        } 
     }

And sorry for slow fix process, but I don't have Windows workstation available :/

Fiskaperdana commented 11 years ago

@dziudek oh i am sorry. Actually i tested my web on localhost based on windows 7(with xampp 1.8.0). after i test my web i will upload it to linux hosting. I usually do it on my job.

Ok. i will try your code again.. Thanks for replay @NormanUK and @dziudek

dziudek commented 11 years ago

@Fiskaperdana - please check (if you can) this code on Windows 7 :) On normal server it should works fine (it can need adjustments with chmods for the cache_nsp directory).

Fiskaperdana commented 11 years ago

@dziudek On parent theme, its work fine, but on child-theme, the code not work properly. the child theme still use path image of parent-theme.

dziudek commented 11 years ago

@Fiskaperdana - could you check if changing line:

$cache_uri = get_template_directory_uri() . '/gavern/cache_nsp/';

to:

$cache_uri = get_stylesheet_directory_uri() . '/gavern/cache_nsp/';

helps?

Fiskaperdana commented 11 years ago

@dziudek thanks you... its help me.... thanks very much...

dziudek commented 11 years ago

@Fiskaperdana - Thank You for your feedback and reports :)

Fixed in: https://github.com/GavickPro/Meet-GavernWP/commit/6109daedde1eb4052d4784f2ed829b9f4ff482ce and https://github.com/GavickPro/Meet-GavernWP/commit/843ffcf18d9a161d13450976f0892a3c0df409f2