1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Post Images 1.8

Add thumb images to your posts

  1. Graeme

    Graeme Member

    Okay that solved the edit problem, but caused a new one when submitting new posts..

    So I've modified my fix slightly to ensure it all works...and it all seems to work really well now
     
  2. Graeme

    Graeme Member

    Post Images 1.6

    I think I've solved the black box issue...needs testing first

    the problem was quite common - you go back into a post, edit it and then submit...and the image turns to a black box...download it here:

    View attachment post_images_1.6.zip
     
    shibuya246, angolanmade and valMETNG like this.
  3. valMETNG

    valMETNG Administrator Staff Member Admin

    WOW. That sounds like it was no easy fix :) Thanx for fixing this. I hope to be able to test it out soon.
     
  4. Graeme

    Graeme Member


    no man, not an easy fix.. it was like hell, but i was determined to fix this!

    & your welcome...i hope it actually works for everyone, not just for me!
     
    shibuya246 likes this.
  5. valMETNG

    valMETNG Administrator Staff Member Admin

    All seems to be good.

    However, I noticed something that I'm wondering could have been contributing to the initial problem (and might still cause future problems). It was something I discovered when trying to fix gravatar: the private function cropImage (line 219), which includes $get_info = getimagesize($src) might return a 404 error if $src has your BASEURL. I don't remember exactly the problem I ran into with gravatar, but the gist is that getimagesize seemed to return height and width when you were using BASE . $filename , but didn't work when you used BASEURL . $filename. Some quick testing indicates post_images is populating $src with BASEURL. I'm wondering if that was partially causing the issue (e.g., because it couldn't find the file and, thus, was returning 0, which led to the black boxes).

    I don't have time to dive into it right now, but that might warrant some future investigation. The idea would be that, right after $src is defined, include something like:
    Code:
    if (strpos($src, BASEURL) === 0) { $src = str_replace(BASEURL, BASE, $src); }
     
    Graeme and shibuya246 like this.
  6. Graeme

    Graeme Member

    My fix only partially solved the black box problem..

    Further Issue: The black box comes up again when on the submit2 page, you make an error on posting - when a user causes the red message box to show at the top, such as: "No tags entered" or "No Title"/

    However, I have also fixed this... but I had to add 2 lines in SubmitFunctions.php within the submit plugin...so when there is an error caused by the user such as above, it appends a hash to the url, like a flag...then I utilized this flag in image_script.php to solve the 'further issue' outlined above.

    There may have been a better way to do it, but looking the whole image_script.php file is a bit tangled..If anyone wants this fix I will upload it..

    the only problem is that I've had to change the submit plugin very slightly to allow it to work...can anyone advise on how plugins are officially updated?
     
  7. valMETNG

    valMETNG Administrator Staff Member Admin

    Yes, please do upload it when you have a moment. And I agree with you - I think this plugin probably needs a revamp. One of the many things to add to our ever-growing to-do list, but this is probably one of the more important ones considering how important images are to these types of sites.
     
  8. shibuya246

    shibuya246 Hotaru Developer Staff Member Admin

    If you can let me know changes to the submit plugin I will update and release a new version for it.
    thanks
     
    Graeme likes this.
  9. Graeme

    Graeme Member

    The changes I made in SubmitFunctions.php are these, the two lines of javascript:

    PHP:
      // Return true if error is found
            
    if ($error_csrf == || $error_url == || $error_title == || $error_content == 
                
    || $error_category == || $error_tags == || $error_hooks == 1)
            { 
                
    //if errors, we need to know for post_images
               
    echo "<script>window.location.hash = 'retry'</script>";
                return 
    true;
                
                
            } else 
            {    
    //for post_images
             
    echo "<script>window.location.hash = 'submit'</script>";
                return 
    false
            }
    not very pretty lol

    aah and I also added just the one key in submit.php: 'editing'=>'true'

    PHP:
      // Edit button pressed so save data with newly assigned post id and go back to step 2
            
    if ($submitted) {
                
    $key $funcs->processSubmitted($h'submit3');
                
    $funcs->processSubmission($h$key);
                
                
    //I've added an extra key here - editing:
                
    $link $h->url(array('page'=>'submit2''key'=>$key'editing'=>'true'));
                
    $redirect htmlspecialchars_decode($link);
                
    header("Location: " $redirect);

                exit;
            }
            
     
    Last edited: Aug 3, 2013
  10. Graeme

    Graeme Member

    My updates to the submit plugin are above, and attached is all I've changed in the post_images plugin. It works perfectly if you set the default image from the post_images admin settings!

    - - - Updated - - -


    Also please could you check out the improvements in functionality to the Submit plugin I have made. I posted a couple videos along with the code in the submit thread...my coding of that addon is much cleaner (but it hasn't included these updates I've made for the post_images)
     

    Attached Files:

    valMETNG likes this.
  11. valMETNG

    valMETNG Administrator Staff Member Admin

    post image pulling only from hotaru images directory

    I haven't paid much attention to this plugin because of the continuing problems. However, I recently noticed that images are only being pulled from the current images directory instead of the target website (which appears what happened years ago according to this post). I'm using v. 1.6. Has anyone seen this problem recently?
     
  12. valMETNG

    valMETNG Administrator Staff Member Admin

    Hack for post images being pulled from current images directory instead of target

    I'm not sure I've discovered the underlying problem relative to the code's intention, but it appears that the script has problems pulling images depending on if the URL starts with http://, www. or nothing (e.g., hotaru.com). I'll post the hack here if anyone else has these problems, but there's probably a better, more fundamental way to solve the problem.

    In /post_images/templates/image_script.php, add the following line right under function getRemoteImages(url){:
    Code:
    if (!url) { return false; }
    Additionally, in /post_images/post_images.php, replace function theme_index_top with:
    Code:
    	public function theme_index_top($h){
    		// get the admin settings for this plugin
                    $h->vars['post_images_settings'] = $h->getSerializedSettings();
    
    		if($h->vars['post_images_settings']['default'] == 'sitethumbshot'){
    			if($h->vars['post_images_settings']['sitethumbshot_size'] == 'T'){
    				$h->vars['post_images_settings']['h'] = 70;
    				$h->vars['post_images_settings']['w'] = 90;
    			}
    			if($h->vars['post_images_settings']['sitethumbshot_size'] == 'S'){
    				$h->vars['post_images_settings']['h'] = 90;
    				$h->vars['post_images_settings']['w'] = 120;
    			}
    			if($h->vars['post_images_settings']['sitethumbshot_size'] == 'M'){
    				$h->vars['post_images_settings']['h'] = 150;
    				$h->vars['post_images_settings']['w'] = 200;
    			}
    		}
    		if (!$h->cage->post->testUri('url'))
    		{
    			$url = 'http://' . $h->cage->post->getHtmLawed('url');
    			$file_headers = @get_headers($url);
    			if($file_headers[0] == 'HTTP/1.1 404 Not Found') { $url = false; }
    		}
    		else { $url = $h->cage->post->getHtmLawed('url'); }
    		if($h->cage->post->getAlpha('type') == 'postImages' && $url){
    			$html =  file_get_contents($url);
    			$parseUrl = parse_url(trim($url));
    			$hostname = trim($parseUrl['host'] ? $parseUrl['host'] : array_shift(explode('/', $parseUrl['path'], 2)));
    			$html = str_replace('src="/','src="'.$parseUrl['scheme'].'://'.$hostname.'/',$html);
    			$html = str_replace("src='/","src='".$parseUrl['scheme']."://".$hostname.'/',$html);
    			preg_match_all('/( src=["\']{1}(?!http)\w{1})/',$html,$matches, PREG_OFFSET_CAPTURE);
    			echo '<pre>';
    			$matches = array_unique($matches);
    			print_r($matches);
    			if (isset($parseUrl['path']))
    			{
    				$rel_dir = (substr($parseUrl['path'],-1) == '/' || strlen($parseUrl['path']) == 0 ? $parseUrl['path'] : dirname($parseUrl['path']).'/');
    				$rel_path = $parseUrl['scheme']."://".$hostname.$rel_dir;
    				$rel_div_l = strlen($rel_path);
    				$i = 0;
    				foreach($matches[0] as $match){
    					echo $rel_div_l.' '.var_dump($match[1]);
    					echo '-'.$match[1]+6+$i*$rel_div_l."\n";
    					$html = substr($html,0,$match[1]+6+$i*$rel_div_l) . $rel_path . substr($html,$match[1]+6+$i*$rel_div_l);
    					$i++;
    				}
    			}
    			echo '</pre>';
    			echo $html;
    			die();
    		}
    	}
     
    nothingman likes this.
  13. shibuya246

    shibuya246 Hotaru Developer Staff Member Admin

  14. sereban

    sereban Active Member

  15. shibuya246

    shibuya246 Hotaru Developer Staff Member Admin

    Right now :)
     
    valMETNG likes this.
  16. shibuya246

    shibuya246 Hotaru Developer Staff Member Admin

  17. valMETNG

    valMETNG Administrator Staff Member Admin

    Both youtube and vimeo don't bring back thumbnails when using post_images. Inspired by @sereban's post, I added the following function to the bottom of /plugins/post_images/post_images.php (after line 340):
    Code:
      function addImages($h, $url, $html)
       {
         // to get youtube id and add picture as image - from http://stackoverflow.com/questions/9594943/regex-pattern-to-get-the-youtube-video-id-from-any-youtube-url and http://stackoverflow.com/questions/16222407/url-of-large-image-of-a-youtube-video
         // to get vimeo id and add picture as image - from http://stackoverflow.com/questions/10488943/easy-way-to-get-vimeo-id-from-a-vimeo-url and http://stackoverflow.com/questions/1361149/get-img-thumbnails-from-vimeo
    
         if (!$html) { return false; }
    
         $site = false;
         $values = false;
    
         $site_regex = array(
           'youtube' => array(
             '/youtube\.com\/watch\?v=([^\&\?\/]+)/',
             '/youtube\.com\/embed\/([^\&\?\/]+)/',
             '/youtube\.com\/v\/([^\&\?\/]+)/',
             '/youtu\.be\/([^\&\?\/]+)/',
             '/youtube\.com\/verify_age\?next_url=\/watch%3Fv%3D([^\&\?\/]+)/'
           ),
           'vimeo' => array(
             "/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/"
           )
         );
    
         foreach ($site_regex as $site_name => $regex_array)
         {
           foreach ($regex_array as $regex)
           {
             if (preg_match($regex, $url, $id))
             {
               $values = $id;
               $site = $site_name;
               break;
             }
    
             if ($values) { break; }
           }
         }
    
         // if there was an id, we will add as image
         if ($values)
         {
           switch ($site)
           {
             case 'youtube':
               $search = '<span class="yt-thumb-clip">';
               $replace = $search . '<img src="http://img.youtube.com/vi/' . $values[1] . '/0.jpg" >';
               break;
             case 'vimeo':
               $search = '<header id="page_header">';
               $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/" . $values[5] . ".php"));
    
               if (!$hash) { return $html; }
    
               $replace = $search . '<img src="' . $hash[0]['thumbnail_medium'] . '" >';
               break;
             default:
               return $html;
           }
    
           $html = str_replace($search, $replace, $html);
         }
    
         return $html;
       }
    ...and then call the function by adding this after line 315 (file_get_contents):
    Code:
    $html = $this->addImages($h, $h->cage->post->getHtmLawed('url'), $html);
    This should add the video's image as a choice.

    Edit: Fixed bug
     
    Last edited: Apr 21, 2015
  18. sereban

    sereban Active Member

    Updated plugin post images is slightly different from yours, I have tried several ways to add the code and did not get to pull the miniatures.
    Code:
    if($h->cage->post->getAlpha('type') == 'postImages' && $h->cage->post->testUri('url')){                 
                $html =  file_get_contents($h->cage->post->getHtmLawed('url'));
                $parseUrl = parse_url(trim($h->cage->post->getHtmLawed('url')));
                $hostname = trim($parseUrl['host'] ? $parseUrl['host'] : array_shift(explode('/', $parseUrl['path'], 2)));
                $html = str_replace('src="/','src="'.$parseUrl['scheme'].'://'.$hostname.'/',$html);
                $html = str_replace("src='/","src='".$parseUrl['scheme']."://".$hostname.'/',$html);
                preg_match_all('/( src=["\']{1}(?!http)\w{1})/',$html,$result, PREG_OFFSET_CAPTURE);
                echo '<pre>';
                //$matches =  is_array($result) ? array_unique($result) : array($result);
                            //error when trying to get unique items on array
                            $matches = $result;
                //print_r($matches);
                $rel_dir = (substr($parseUrl['path'],-1) == '/' || strlen($parseUrl['path']) == 0 ? $parseUrl['path'] : dirname($parseUrl['path']).'/');
                $rel_path = $parseUrl['scheme']."://".$hostname.$rel_dir;
                $rel_div_l = strlen($rel_path);
                $i = 0;
                foreach($matches[0] as $match){
                    echo $rel_div_l.' '.var_dump($match[1]);
                    echo '-'.$match[1]+6+$i*$rel_div_l."\n";
                    $html = substr($html,0,$match[1]+6+$i*$rel_div_l) . $rel_path . substr($html,$match[1]+6+$i*$rel_div_l);
                    $i++;
                }
                echo '</pre>';
                echo $html;
                die();
            }
        }
    }
    ?> Last line 336 
     
  19. valMETNG

    valMETNG Administrator Staff Member Admin

    I thought I used the line numbers from the latest version as my build is much different, so I'm sorry if I got them wrong. In your case, you can put the function before the } on line 335 and then you'll want to put the function call ( $html = $this->addImages($h, $url, $html); ) after the line that shows this (I think it's line 309 in your build):
    Code:
    $html =  file_get_contents($h->cage->post->getHtmLawed('url'));
     
  20. sereban

    sereban Active Member

    Still does not work. Maybe I'm wrong vragment added this code? Also, I have not worked as an editor summernote, he hung up.
    Code:
          line 308  if($h->cage->post->getAlpha('type') == 'postImages' && $h->cage->post->testUri('url')){                 
               $html =  file_get_contents($h->cage->post->getHtmLawed('url'));
               $html = $this->addImages($h, $url, $html);
                $parseUrl = parse_url(trim($h->cage->post->getHtmLawed('url')));
                $hostname = trim($parseUrl['host'] ? $parseUrl['host'] : array_shift(explode('/', $parseUrl['path'], 2)));
                $html = str_replace('src="/','src="'.$parseUrl['scheme'].'://'.$hostname.'/',$html);
                $html = str_replace("src='/","src='".$parseUrl['scheme']."://".$hostname.'/',$html);
                preg_match_all('/( src=["\']{1}(?!http)\w{1})/',$html,$result, PREG_OFFSET_CAPTURE);
                echo '<pre>';
                //$matches =  is_array($result) ? array_unique($result) : array($result);
                            //error when trying to get unique items on array
                            $matches = $result;
                //print_r($matches);
                $rel_dir = (substr($parseUrl['path'],-1) == '/' || strlen($parseUrl['path']) == 0 ? $parseUrl['path'] : dirname($parseUrl['path']).'/');
                $rel_path = $parseUrl['scheme']."://".$hostname.$rel_dir;
                $rel_div_l = strlen($rel_path);
                $i = 0;
                foreach($matches[0] as $match){
                    echo $rel_div_l.' '.var_dump($match[1]);
                    echo '-'.$match[1]+6+$i*$rel_div_l."\n";
                    $html = substr($html,0,$match[1]+6+$i*$rel_div_l) . $rel_path . substr($html,$match[1]+6+$i*$rel_div_l);
                    $i++;
                }
                echo '</pre>';
                echo $html;
                die();
            }
        }
    line 336 function addImages($h, $url, $html)
       {
         // to get youtube id and add picture as image - from http://stackoverflow.com/questions/9594943/regex-pattern-to-get-the-youtube-video-id-from-any-youtube-url and http://stackoverflow.com/questions/16222407/url-of-large-image-of-a-youtube-video
         // to get vimeo id and add picture as image - from http://stackoverflow.com/questions/10488943/easy-way-to-get-vimeo-id-from-a-vimeo-url and http://stackoverflow.com/questions/1361149/get-img-thumbnails-from-vimeo
    
         if (!$html) { return false; }
    
         $site = false;
         $values = false;
    
         $site_regex = array(
           'youtube' => array(
             '/youtube\.com\/watch\?v=([^\&\?\/]+)/',
             '/youtube\.com\/embed\/([^\&\?\/]+)/',
             '/youtube\.com\/v\/([^\&\?\/]+)/',
             '/youtu\.be\/([^\&\?\/]+)/',
             '/youtube\.com\/verify_age\?next_url=\/watch%3Fv%3D([^\&\?\/]+)/'
           ),
           'vimeo' => array(
             "/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/"
           )
         );
    
         foreach ($site_regex as $site_name => $regex_array)
         {
           foreach ($regex_array as $regex)
           {
             if (preg_match($regex, $url, $id))
             {
               $values = $id;
               $site = $site_name;
               break;
             }
    
             if ($values) { break; }
           }
         }
    
         // if there was an id, we will add as image
         if ($values)
         {
           switch ($site)
           {
             case 'youtube':
               $search = '<span class="yt-thumb-clip">';
               $replace = $search . '<img src="http://img.youtube.com/vi/' . $values[1] . '/0.jpg" >';
               break;
             case 'vimeo':
               $search = '<header id="page_header">';
               $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/" . $values[5] . ".php"));
    
               if (!$hash) { return $html; }
    
               $replace = $search . '<img src="' . $hash[0]['thumbnail_medium'] . '" >';
               break;
             default:
               return $html;
           }
    
           $html = str_replace($search, $replace, $html);
         }
    
         return $html;
       }}
    ?>
     

Share This Page