Go Back   Pligg CMS Forum > Pligg Development > Modification Tutorials

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-19-2008, 06:39 PM
Casual Pligger
 
Join Date: Feb 2008
Posts: 48
Thanks: 3
Thanked 4 Times in 3 Posts
select images for submission in development

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-submission-development-choose_thumbnail_j.jpg  

Last edited by ivytony; 07-17-2008 at 10:37 PM..
Reply With Quote
  #2 (permalink)  
Old 02-19-2008, 09:42 PM
Casual Pligger
 
Join Date: Feb 2008
Posts: 48
Thanks: 3
Thanked 4 Times in 3 Posts
code deleted for testing. sorry

Last edited by ivytony; 02-19-2008 at 10:53 PM..
Reply With Quote
  #3 (permalink)  
Old 02-26-2008, 11:47 PM
Casual Pligger
 
Join Date: Feb 2008
Posts: 48
Thanks: 3
Thanked 4 Times in 3 Posts
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-submission-development-auto_img.jpg  
Reply With Quote
The Following User Says Thank You to ivytony For This Useful Post:
  #4 (permalink)  
Old 02-27-2008, 10:59 AM
gen3ric's Avatar
Constant Pligger
Pligg Version: 9.X
Pligg Template: Custom
 
Join Date: Jul 2007
Location: Atlanta, GA
Posts: 112
Thanks: 22
Thanked 9 Times in 6 Posts
This is a very cool mod. Current also has a nice version of this functionality for their submission process.
__________________
Design Float - Digg For Designers
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 11:07 AM
Casual Pligger
 
Join Date: Feb 2008
Posts: 48
Thanks: 3
Thanked 4 Times in 3 Posts
does Current use pligg? I don't know that.
Reply With Quote
  #6 (permalink)  
Old 02-27-2008, 11:54 AM
gen3ric's Avatar
Constant Pligger
Pligg Version: 9.X
Pligg Template: Custom
 
Join Date: Jul 2007
Location: Atlanta, GA
Posts: 112
Thanks: 22
Thanked 9 Times in 6 Posts
No they don't use Pligg, I just meant they have the same image selection ability .
__________________
Design Float - Digg For Designers
Reply With Quote
  #7 (permalink)  
Old 04-22-2008, 04:04 PM
Designer
Pligg Version: 9.8.2
Pligg Template: Custom
 
Join Date: Jun 2007
Location: Norway [Form BKK]
Posts: 72
Thanks: 23
Thanked 2 Times in 1 Post
No one can make some module like this ?
__________________
http://www.kez6.com [My Pligg]
http://bookmarks.anivox.com [My Pligg#2]
Reply With Quote
  #8 (permalink)  
Old 04-22-2008, 04:25 PM
rubber2002's Avatar
Pligg Donor
 
Join Date: Jul 2007
Posts: 257
Thanks: 30
Thanked 7 Times in 6 Posts
This would be really nice tool to add.
Reply With Quote
  #9 (permalink)  
Old 04-23-2008, 07:56 AM
Designer
Pligg Version: 9.8.2
Pligg Template: Custom
 
Join Date: Jun 2007
Location: Norway [Form BKK]
Posts: 72
Thanks: 23
Thanked 2 Times in 1 Post
Is it possible ?
__________________
http://www.kez6.com [My Pligg]
http://bookmarks.anivox.com [My Pligg#2]
Reply With Quote
  #10 (permalink)  
Old 05-16-2008, 03:30 AM
Casual Pligger
Pligg Version: 9.8
Pligg Template: forum
 
Join Date: Oct 2007
Posts: 51
Thanks: 9
Thanked 1 Time in 1 Post
When will this script be available
Reply With Quote
Reply

Thread Tools
Display Modes
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Similar Threads
Thread Thread Starter Forum Replies Last Post
RSS importer doesn't import images from feeds lostdeviant General Help 2 05-07-2008 09:29 AM
The Real Cause Of High Load For My Server Using PLigg 9.9 and Was 9.8.2 argh2xxx Bug Report 18 01-10-2008 04:33 PM
How to use images in sneak/spy like digg's spy kbeeveer46 Modification Tutorials 18 08-10-2007 11:17 AM
'max_user_connections' suddenly exceeded mightyb Bug Report 10 06-13-2007 04:40 PM
Images with Lightbox in Desc w/ popup Thumb kanedaguy Modification Tutorials 0 02-02-2007 01:51 AM


Search Engine Friendly URLs by vBSEO 3.2.0