select images for submission in development

Register an Account
Pligg Chat Room
Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-19-2008, 06:39 PM
Casual Pligger
 
Join Date: Feb 2008
Posts: 47
When users submit a url, I would like to have my pligg craw on that target url and catch images for users to choose for the submission, which is just like digg's submission.

now, you can type in any url in http://www.uspie.net/getimgs.php to get images. I have set my script to filter out smaller images from webpage design such as corners, spacers, etc. Currently, images smaller than 150px width and 40px height are filtered out. Large images are also scaled proportionally.

I wonder how to make the images out as radio buttons for users to choose from, anyone can give me a hint on this??

thanks!

Edit on July 17, 2008:

Here's the mod:

1. In your submit.php file, find the function do_submit1, around line 211 (or somewhere after the code: $linkres->status='discard';
$linkres->author=$current_user->user_id;
$linkres->store(),

add

PHP Code:
//catch images on destination url
    
$pageString = @file_get_contents($url);
    
preg_match_all('|<img .*?>|s'$pageString$matches);
    
//the array $matches[0] now contains the img tags, let's echo 'em:

$fulldomain 'http://www.'$domain;

$newimages = array();  //initialize an array as image container

foreach ($matches[0] as $path){

preg_match('/src="([^"]+)"/',$path$b); //get the image path by $b[1], however, will need to detect relative paths and convert to absolute paths

$location $linkres->relative2absolute($fulldomain$b[1]);//this is to convert relative image paths to absolute image paths

$filteredimg $linkres->filterimage($location120120);
 if (
$filteredimg) {
    
$image $linkres->scaleimage($filteredimg100100); //scale bigger images and filter out images smaller than 100x100. You can modify the picture dimensions limit based on your needs.
    
    
$newimages[] = array(
       
'url' => $location,
       
'img_tag' => $image,
        );
  }
}
 
$main_smarty->assign('newimages'$newimages);
//end of get images 
In the same submit.php file, after the code line ( if(isset($_POST['link_field15'])){$linkres->link_field15 = strip_tags(trim($_POST['link_field15']), Story_Content_Tags_To_Allow);}), add the following:

PHP Code:
//reset link_field1 as $product_image
if(!empty($product_image_manual)){           //entered manually by user
$linkres->link_field1 $product_image_manual;

}
else {
  if(!empty(
$linkres->product_image)){
  
$linkres->link_field1 $linkres->product_image;   //use link_field1 to store the image path
  
}

Now, find the link.php in the /libs folder, anywhere between two function close brackets, add the following code
PHP Code:
    //Tony, get images 20080226
function relative2absolute($absolute$relative) {
        
$p = @parse_url($relative);
        if(!
$p) {
            
//$relative is a seriously malformed URL
            
return false;
        }
        if(isset(
$p["scheme"])) return $relative;
 
        
$parts=(parse_url($absolute));
 
        if(
substr($relative,0,1)=='/') {
            
$cparts = (explode("/"$relative));
            
array_shift($cparts);
        } else {
            if(isset(
$parts['path'])){
                 
$aparts=explode('/',$parts['path']);
                 
array_pop($aparts);
                 
$aparts=array_filter($aparts);
            } else {
                 
$aparts=array();
            }
           
$rparts = (explode("/"$relative));
           
$cparts array_merge($aparts$rparts);
           foreach(
$cparts as $i => $part) {
                if(
$part == '.') {
                    unset(
$cparts[$i]);
                } else if(
$part == '..') {
                    unset(
$cparts[$i]);
                    unset(
$cparts[$i-1]);
                }
            }
        }
        
$path implode("/"$cparts);
 
        
$url '';
        if(
$parts['scheme']) {
            
$url "$parts[scheme]://";
        }
        if(isset(
$parts['user'])) {
            
$url .= $parts['user'];
            if(isset(
$parts['pass'])) {
                
$url .= ":".$parts['pass'];
            }
            
$url .= "@";
        }
        if(isset(
$parts['host'])) {
            
$url .= $parts['host']."/";
        }
        
$url .= $path;
 
        return 
$url;
}

function 
filterimage($location$minW=NULL$minH=NULL){
 
$img = @getimagesize($location);
   if (
$img){                      //if image exists
    
$w $img[0];
    
$h $img[1];

        if (
$w >= $minW && $h >= $minH){   //only if images greater than the minimums are they returned, otherwise, no
        
return $location;
        }
        else {
        return 
false;                  //return no images
        
}
    }
}

function 
scaleimage($location$maxw=NULL$maxh=NULL$alt=NULL$title=NULL){
    
$img = @getimagesize($location);
    if(
$img){
        
$w $img[0];
        
$h $img[1];

        
$dim = array('w','h');
        foreach(
$dim AS $val){
            
$max "max{$val}";
            if(${
$val} > ${$max} && ${$max}){
                
$alt = ($val == 'w') ? 'h' 'w';
                
$ratio = ${$alt} / ${$val};
                ${
$val} = ${$max};
                ${
$alt} = ${$val} * $ratio;
            }
        }

       return(
"<img src='{$location}' alt='{$alt}' width='{$w}' height='{$h}' title='{$title}'/>");

    }
}

    
//enf of get images 
You are almost done. Hang on! Next is to show the images on your template. In the submit_step2.tpl file, add the following html code to somewhere you think appropriate:

Quote:
<div class="submission">

<div class="tab">
<h3>Please Choose a Product Picture:</h3>
</div>
<div class="tab-details">If none of the images below is right, you can enter one in the text field below.</div>
<div class="sub-thumbs">
<div style="overflow:auto; height:180px; width:100%;">
<table><tr>
{section name=img loop=$newimages}
<td><div class="radio-img">

<div class="wrap">
{$newimages[img].img_tag}

</div>

<input name="product_image" type="radio" id="product_image" value="{$newimages[img].url}">

</div>
</td>
{/section}
<td><div class="radio-img">

<div class="wrap">
<img src="templates/yget/images/no_thumb.gif" border="0">

</div>

<input name="product_image" type="radio" id="product_image" value="">

</div>
</td>
</tr>
</table>
You can also enter the image manually here:
<input type="text" name="product_image_manual" id="product_image_manual" size="60" />
</div>
</div>
Because it has been too long since I coded for this mod, I forgot much of it. If you have any question, please post it in this thread so that I or someone else can figure out together.

For you to see the mod in action, you can take a look at my website DealsPiggy / Hot Deals or see this script stand-alone here: http://www.dealspiggy.com/getimgs.php

Good luck!
Attached Thumbnails
select images for submission in development-choose_thumbnail_j.jpg  

Last edited by ivytony; 07-17-2008 at 10:37 PM.
  #2 (permalink)  
Old 02-19-2008, 09:42 PM
Casual Pligger
 
Join Date: Feb 2008
Posts: 47
code deleted for testing. sorry

Last edited by ivytony; 02-19-2008 at 10:53 PM.
  #3 (permalink)  
Old 02-26-2008, 11:47 PM
Casual Pligger
 
Join Date: Feb 2008
Posts: 47
Quote:
Originally Posted by ivytony View Post
code deleted for testing. sorry
I finally got this 80% done. Right now, the code can grab images from target url and filter out small images (configurable), which allows users to choose from at the step 2 of submission. I will need to add an extra column in database for the selected image, because I don't know how make the extra field become a radio button. If someone knows how, my work will be very simplified.

Attached is a screenshot of the working script on my website DealPigg / Hot Deals

I am thinking of adding a page between step 1 and step2 showing: We are digging through the website you submitted, as you see on digg. Because I don't want users to see a blank page while waiting, this script takes a little more seconds to jump to the step 2.

oh, by the way. My code just grabs the image paths not the image file.

Cheers!
Attached Thumbnails
select images for submission in development-auto_img.jpg  
  #4 (permalink)  
Old 02-27-2008, 10:59 AM
gen3ric's Avatar
Casual Pligger
Pligg Version: 9.X
Pligg Template: Custom
 
Join Date: Jul 2007
Location: Atlanta, GA
Posts: 94
This is a very cool mod. Current also has a nice version of this functionality for their submission process.
  #5 (permalink)  
Old 02-27-2008, 11:07 AM
Casual Pligger
 
Join Date: Feb 2008
Posts: 47
does Current use pligg? I don't know that.
  #6 (permalink)  
Old 02-27-2008, 11:54 AM
gen3ric's Avatar
Casual Pligger
Pligg Version: 9.X
Pligg Template: Custom
 
Join Date: Jul 2007
Location: Atlanta, GA
Posts: 94
No they don't use Pligg, I just meant they have the same image selection ability .
  #7 (permalink)  
Old 04-22-2008, 04:04 PM
Casual Pligger/Designer
Pligg Version: 9.8.2
Pligg Template: Custom
 
Join Date: Jun 2007
Location: Norway [Form BKK]
Posts: 51
No one can make some module like this ?
  #8 (permalink)  
Old 04-22-2008, 04:25 PM
Pligg Donor
 
Join Date: Jul 2007
Posts: 286
This would be really nice tool to add.
  #9 (permalink)  
Old 04-23-2008, 07:56 AM
Casual Pligger/Designer
Pligg Version: 9.8.2
Pligg Template: Custom
 
Join Date: Jun 2007
Location: Norway [Form BKK]
Posts: 51
Is it possible ?
  #10 (permalink)  
Old 05-16-2008, 03:30 AM
Casual Pligger
Pligg Version: 9.8
Pligg Template: forum
 
Join Date: Oct 2007
Posts: 52
When will this script be available
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
RSS importer doesn't import images from feeds lostdeviant Questions and Comments 12 03-22-2009 09:35 PM
Profile Badges and Images EASY work 30 usd winner! bbrian017 Questions and Comments 0 04-25-2008 10:47 AM
The Real Cause Of High Load For My Server Using PLigg 9.9 and Was 9.8.2 argh2xxx Questions and Comments 18 01-10-2008 04:33 PM
'max_user_connections' suddenly exceeded mightyb Questions and Comments 10 06-13-2007 04:40 PM


Pligg Modules and Pligg Templates from Pligg Pro Find support on the Pligg CMS Forum - 24 hours a day! Make a donation to support Pligg CMS development