Pligg script image crawl from other site while submitting

Discussion in 'PHP' started by cleanbold, Apr 25, 2011.

  1. #1
    Here's the mod:
    i tried this is in Pligg 9.9.0

    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

    //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($location, 120, 120);
     if ($filteredimg) {
        $image = $linkres->scaleimage($filteredimg, 100, 100); //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:
    //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
      }
    } 
    PHP:
    Now, find the link.php in the /libs folder, anywhere between two function close brackets, add the following 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 
    PHP:
    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:
    
    <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>
    HTML:
    i tried this code in my site but failed but it seems to be correct any pligg expert can help me. Any suggestion or any change in code please help me. User want to select images from other site while submitting. Those selected image should be stored in links table (link_field1 column) in database. Help me out guys.
     
    Last edited: Apr 25, 2011
    cleanbold, Apr 25, 2011 IP
  2. cleanbold

    cleanbold Active Member

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    93
    #2
    help please!
     
    cleanbold, Apr 25, 2011 IP
  3. cleanbold

    cleanbold Active Member

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    93
    #3
    i am waiting more than 12 hrs... please help me!
     
    cleanbold, Apr 25, 2011 IP
  4. usupnew

    usupnew Greenhorn

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    I also have this problem...
     
    usupnew, Jun 25, 2011 IP