68 Classifieds Forums

68 Classifieds Forums (http://www.68classifieds.com/forums/)
-   Modules / Plugins / Modifications (http://www.68classifieds.com/forums/modules-plugins-modifications/)
-   -   alternative for "SOLD" button (http://www.68classifieds.com/forums/modules-plugins-modifications/6053-alternative-sold-button.html)

frommarcq 10-01-2008 07:05 AM

alternative for "SOLD" button
 
Hi,
I want to replace the "remove" button in "userbrowselistings" with a button which change the status of the ad (from "Y" to "Z" for example).
The ad with "Z" status would still be displayed (not searchable and not present in showlistings) but with the mention "this ad has been desactivated by its owner", in order to keep it referenced in Google and to prove that the service is efficient.
I have the idea, but don't know how to do, could you please help me ?
regards,
Pascal

free2take 10-01-2008 06:22 PM

Hi,

I did something like this in ver 3.10 to stamp an image as SOLD. Worked well but it was a big mod, I'll dig out the code and show you what I did.

Sorry meant to post it ages ago but been hectic...

Mully

richartj 10-03-2008 01:17 AM

I'm interested
 
I would be very interested in your code as well.

free2take 10-05-2008 05:38 PM

Hi there,

Sorry big post this so spread across threads...

Ok so the first change I did for this was to modify the userbrowselistings.tpl.phpp file to reflect the new buttons I wanted in my case these were Sold and Relist. Sold marked an item as Sold stamping a banner across it whie Relist allowed the user to re-advertise it if the sale fell through without having to resubmit the pictures. Here's the code I added @ the top;

PHP Code:

function relist(id){
    
document.mainform.lid.value id;
    
document.mainform.act.value "relist";
    
document.mainform.submit();
}
function 
changerec(id){
    
document.mainform.lid.value id;
    
document.mainform.act.value "sold";
    
document.mainform.submit();


then whereever you wanted the buttons to appear;

PHP Code:

               <td class="{cycle values="row1,row2" advance=true}">
                   <
input type="button" value="Sold" onClick="changerec('{$entry.id}')" style="width:70px;font-color=red;>
               </td>
              <td colspan="
2" class="{cycle values="row1,row2" advance=true}" align="left">
                 <input type="
button" value="Relist" onClick="relist('{$entry.id}')" style="width:140px;border-color=#F1F1F1; font-weight:bold; color:#050;">
             
</td

After this you then have to handle the processing of this functions as you've made them available. This was done in userbrowselistings.php with the following code;
**Continued in next reply

free2take 10-05-2008 05:39 PM

PHP Code:

//NM:16-MAR-07 Added for SOLD watermark
    
if(isset($_POST["act"]) && $_POST["act"] == "sold" && isset($_POST["lid"])) 
    {
        
$lid=(int)$_POST['lid'];         

      
//Run functions to set renewal date and replace Picture
      
if(!$MyFunctions->setSold($lid$userid)==TRUE
            {
                
$location="userbrowselistings.php";
                
$class_tpl->assign('forward',FALSE);
                
$class_tpl->assign('location',$location);
                
$class_tpl->assign('body','forward.tpl.php');
              }
      else
          {    
                    
//echo "Mark as sold true";
              //Run functions to set renewal date and replace Picture
                
$location="userbrowselistings.php";
                
$class_tpl->assign('forward',TRUE);
                
$class_tpl->assign('location',$location);
                
$class_tpl->assign('body','forward.tpl.php');
          }
      }
        

    if(isset(
$_POST["act"]) && $_POST["act"] == "relist" && isset($_POST["lid"])) 
    {
        
$lid=(int)$_POST['lid'];         

      
//Run functions to set renewal date and replace Picture
      
if(!$MyFunctions->relist($lid$userid)==TRUE
            {
                
//not successfull
                
$location="userbrowselistings.php";
                
$class_tpl->assign('forward',FALSE);
                
$class_tpl->assign('location',$location);
                
$class_tpl->assign('body','forward.tpl.php');
              }
      else
          {    
              
//Run functions to set renewal date and replace Picture
                
$location="userbrowselistings.php";
                
$class_tpl->assign('forward',TRUE);
                
$class_tpl->assign('location',$location);
                
$class_tpl->assign('body','forward.tpl.php');
          }
      } 

I also had to add the path to MyFunctions into the header i.e.
PHP Code:

require_once('includes/init.php');
require_once(
FILESYSTEM_PATH .'includes/classes/kernel/Listings.php');
//NM:06-Aug-07 Include MyFunctions file for setSold, quikRenew & relist options
require_once(FILESYSTEM_PATH .'includes/classes/kernel/MyFunctions.php');
$MyFunctions = new MyFunctions$db ); 

After this had to make sure MyFunctions was present the file contained the following code
PHP Code:

<?php

/**

 * This file is used to perform custom functions.
 *
 * @package 68classifieds
 * @author  NM
 * @copyright 
 * @link http://
 */

/**
 * MyFunctions class handles actions specific to listings.
 */

/**
 *Include the litestamp class for watermarking images
*/   

require_once(FILESYSTEM_PATH .'includes/classes/images/litestamp.php');
 
class 
MyFunctions
{
     
/*
      * Instance of database connection class
      * @access private
      * @var object
      */
    
var $db;
    
    
/*
     * MyFunctions Constructor
     *
      * @param object database Database functions
      * @access public
     */
    
function MyFunctions(&$db
    {
        
$this->db=& $db;
    }        
    
     
//NM:16-MAR-07 Added for SOLD watermark
     /*
      * Watermark all photos \ thumbs with user specified SOLD watermark      
      */
     

    
    
function setSold($id)
     {

         
$myres True;
         
        if ( !
is_numeric($id) )
         {         
          
$myres False;
            
$id=1;
        
    }

        IF (
$myres == TRUE)
        {
         
//Move original files to photos->photos_orig & thumbs->thumbs_orig
         //**This allows users to avoid reloading photos if they want to relist an ad
         //Need to make sure they are collected by the ad delete later

         
$path=FILESYSTEM_PATH .'photos';
     
$thumbPath=FILESYSTEM_PATH .'thumbs';

         
$watermark='SOLD_wmclear.jpg';

          
$sSQL sprintf("SELECT image FROM ".PREFIX."prodimages WHERE pid=%s"$id);
        
$result=$this->db->query($sSQL);
        if(
$result->size()>0)
        {
            while(
$rs=$result->fetch())
            {
                
$fileName=$rs['image'];                                
                  if (
file_exists($thumbPath.'/small_'.$fileName)) 
                  {                                                                                     
                        
                             
//Copy original thumbs across to new folder
                            
if (!copy($thumbPath.'/small_'.$fileName$thumbPath.'/small_stamped_'.$fileName)) {
                     echo 
"Cannot copy thumb file ($thumbPath.'/small_stamped_'.$fileName)";
                     exit;
                };
                            
                            
                            
//Ensure write permissions on the file                            
                            
if (!chmod($thumbPath.'/small_stamped_'.$fileName0777)) {
                     echo 
"Cannot change the mode of file ($thumbPath.'/small_stamped_'.$fileName)";
                     exit;
                };
                            
                            
//Upscale user image to fit watermark if required
                            
checkimagesize($thumbPath.'/small_stamped_'.$fileName$thumbPath.'/small_'.$watermark'');                        

                            
//Watermark the thumb
                        
$stamp = new LiteStamp();
                        
$stamp->stampPicture($thumbPath.'/small_stamped_'.$fileName,$thumbPath.'/small_'.$watermark'');    
                                                                
                  }
                  if (
file_exists($path.'/'.$fileName)) 
                  {                                                     
                                                    
                             
//Copy original photos across to new folder                        
                            
if (!copy($path.'/'.$fileName,$path.'/stamped_'.$fileName)) {
                     echo 
"Cannot copy photo file ($path.'/stamped_'.$fileName)";
                     exit;
                };                            
                            
                            
//Ensure write permissions on the file
                            
if (!chmod($path.'/stamped_'.$fileName0777)) {
                    echo 
"Cannot change the mode of file ($path.'/stamped_'.$fileName)";
                    exit;
                };
                            
                            
//Upscale user image to fit watermark if required
                            
checkimagesize($path.'/stamped_'.$fileName$path.'/'.$watermark'');

                            echo 
"Got to stamping func";
                            
                            
//Watermark the picture                
                        
$stamp = new LiteStamp();
                        
$stamp->stampPicture($path.'/stamped_'.$fileName$path.'/'.$watermark'');                            
                  }                            
            }
        }                                  
        }
    
        
//Update expiration to n days - INTERVAL n DAY (28) - this lets visitors see sold items on your site
        //UPdate photos to new name i.e.wm_
      
$sSQL=sprintf("UPDATE ".PREFIX."products SET title=CONCAT('SOLD - ',title), expiration=DATE_ADD(CURDATE(),INTERVAL 28 DAY),status='S',notified='Y' WHERE id=%s"$id );
      
$this->db->query($sSQL);
      if(!
$this->db->isError()) 
        {
            
$sSQL=sprintf("UPDATE ".PREFIX."prodimages SET image=CONCAT('stamped_',image) WHERE pid=%s"$id );
          
$this->db->query($sSQL);
          if(!
$this->db->isError()) 
            {
                        return 
True;
            }
        }
        else
        {
            return 
False;
        }
    }
        
    
//NM:06-Aug-07 Relist function without need to upload original pictures
     /*
      * Copy original images back over watermarked, set status to A and expiration to +90 days      
      */
    
function relist($id)
     {
         
//Check for good listing id
         
$myres TRUE;    
         if ( !
is_numeric($id) )
         {         
          
$myres False;
            
$id=1;
    }
        
        
//Set image paths
        
$path=FILESYSTEM_PATH .'photos';
    
$thumbPath=FILESYSTEM_PATH .'thumbs';
                      
        
//Nuts and bolts of relist                
        
IF ($myres == TRUE)
        {
             
//Delete stamped image files
          
$sSQL sprintf("SELECT image FROM ".PREFIX."prodimages WHERE pid=%s"$id);
      
$result=$this->db->query($sSQL);
      if(
$result->size()>0)
      {
          while(
$rs=$result->fetch())
          {
              
$fileName=$rs['image'];            
                    
//echo $fileName;        
                    //If not dealing with old SOLD Banner then remove stamped photos                
                    
if ( $fileName != lrg_sold.jpg )
                    {
                          if (
file_exists($thumbPath.'/small_'.$fileName)) 
                      {
                                 
//echo $fileName;
                                 //Delete the file
                                
unlink($thumbPath.'/small_'.$fileName);                                                                                                                                                                
                         }
                      if (
file_exists($path.'/'.$fileName))
                      {
                                  
//Delete the file
                                
unlink($path.'/'.$fileName);                                                                                
                     }                            
                 
//Rename picture to original i.e. remove stamped_ prefix from filename          
                         
$sSQL=sprintf("UPDATE ".PREFIX."prodimages SET image=SUBSTR(image,9) WHERE pid=%s"$id );
                       
$this->db->query($sSQL);
                       if(!
$this->db->isError()) 
                       {
                               
$myres True;
                       }
                         else
                         {
                                  
$MYRES False;
                         }
                    }                                
        }
            }        

            
//If ok to here then continue to set image for relist with expiration 1 month ahead
            
IF ($myres == TRUE)
            {        
            
//Update expiration to n days - INTERVAL n DAY (42) 
            
$sSQL=sprintf("UPDATE ".PREFIX."products SET title=SUBSTR(title,8), expiration=DATE_ADD(CURDATE(),INTERVAL 42 DAY),status='A',notified='N' WHERE id=%s"$id );
            
$this->db->query($sSQL);
            if(!
$this->db->isError()) 
              {
               
$myres True;              
              }
              else
              {
               
$myres False;
              }    
            }
            
            
//Return value
            
IF ($myres == FALSE)
            {
              return 
false;
            }
            else
            {
              return 
true;
            }                
        }
    }
    
    
     
//NM:12-JUL-07 Added to renew listing
    /*
      * @access public
     */    
    
function quikRenew($id)
     {
         if ( !
is_numeric($id) )
         {         
          
$myres False;
            
$id=1;
        }
        
      
//Update expiration to n days - INTERVAL n DAY
      
      
$sSQL=sprintf("UPDATE ".PREFIX."products SET expiration=DATE_ADD(CURDATE(),INTERVAL 42 DAY),notified='N' WHERE id=%s"$id );
      
$this->db->query($sSQL);
      if(!
$this->db->isError()) 
        {
            return  
True;
        }
        else
        {
            return 
False;
        }
                
        
    }
}
?>

There is a function in there for a quick renew but I don't think I ever really used it. This file performed a number of functions such as retitled the listing when it was marked sold and setting the length of time it would remain on the site before being deleted after being marked sold etc, was good for holding onto content. It also used some image files for the stamping e.g. lrg_sold.jpg, both thumbnail and photo were stamped.

free2take 10-05-2008 05:43 PM

I'm not going to go through it all as I don't remember it fully and tbh you'll need to get familiar with it yourself if implementing it.

The last big things to note was the inclusion of the litestamp.php file, I had modified this to suit my own needs, here's the code I ended up with.
PHP Code:

<?php
// NOTE: class is experimental
// Copyright (c) 2006, Simon Jansson <http://www.litewebsite.com> all rights reserved.
// License <http://litewebsite.com/license_BSD.html>

//liteStamp::GDversion();
//$stamp = new LiteStamp('originalImage.jpg', 'stampImage.jpg', 'stamp_');
//$stamp->stampPicture();

class LiteStamp{

        
// class variables
        
var $fileHandle null;
        var 
$newPictureName null;
        var 
$pictureInfo null;
        var 
$pictureName null;
        var 
$prefix null;
        var 
$stampInfo null;
        var 
$stampName null;
        var 
$stampXpos null;
        var 
$stampYpos null;

        function 
openImage($fileName$type){

                
// open picture with correct image function. Add more types if needed.
                // GIF: http://php.net/manual/en/function.imagecreatefromgif.php
                // JPG/JPEG: http://php.net/manual/en/function.imagecreatefromjpeg.php
                // PNG: http://php.net/manual/en/function.imagecreatefrompng.php
                
switch ($type){

                case 
1// GIF
                        
$this->fileHandle imagecreatefromgif($fileName);
                        break;
// case 1

                
case 2// JPG/JPEG
                        
$this->fileHandle imagecreatefromjpeg($fileName);
                        break;
// case 2

                
case 3// PNG
                        
$this->fileHandle imagecreatefrompng($fileName);
                        break;
// case 3

                
default:
                        die(
'Unsupported filetype: '.$fileName);
                }

        return 
$this->fileHandle;
        }
// end of openImage                
                

        
function stampPicture($picture$stamp$prefix){
                
                                
$this->pictureName $picture// original picture to place stamp/watermark on
                
$this->stampName $stamp// stamp/watermark picture
                
$this->prefix $prefix// prefix of new stamped picture

                // get picture info such as width, height and extension
                // http://php.net/manual/en/function.getimagesize.php

                                
echo $this->pictureInfo;
                
$this->pictureInfo getimagesize($this->pictureName) or die($this->pictureInfo.' Error getting picture info. Double check file path.');
                
$this->stampInfo getimagesize($this->stampName) or die('Error getting stamp info. Double check file path.');
                                
                
// open images with class method openImage()
                
$this->pictureFile $this->openImage($this->pictureName$this->pictureInfo[2]);
                
$this->stampFile $this->openImage($this->stampName$this->stampInfo[2]);                                                                                                                                        
                                
                                
// alpha blending: http://php.net/manual/en/function.imagealphablending.php
                
imagealphablending($this->pictureFiletrue);                                                            

                
//middle 
                
if( $pos == 
                { 
                    
$dest_x = ( $sourcefile_width ) - ( $insertfile_width ); 
                    
$dest_y = ( $sourcefile_height ) - ( $insertfile_height ); 
                } 

                                
$this->stampXpos = ($this->pictureInfo[0] / 2) - ($this->stampInfo[0] / 2);
                                
$this->stampYpos = ($this->pictureInfo[1] / 2) - ($this->stampInfo[1] / 2);             

                
// set a new name for the stamped picture and keep the original picture intact
                
$this->newPictureName $this->prefix.$this->pictureName;

                
// merge the two images: http://php.net/manual/en/function.imagecopymerge.php
                
imagecopymerge($this->pictureFile$this->stampFile$this->stampXpos$this->stampYpos00$this->stampInfo[0], $this->stampInfo[1], 100);
                                                                
                
// output the stamped image as GIF, JPG/JPEG or PNG. Add more types if needed.
                // default type is the same as the original file
                // GIF: http://php.net/manual/en/function.imagegif.php
                // JPG/JPEG: http://php.net/manual/en/function.imagejpeg.php
                // PNG: http://php.net/manual/en/function.imagepng.php
                
switch ($this->pictureInfo[2]){

                case 
1// GIF
                        
imagegif($this->pictureFile$this->newPictureName);
                        break;
// case 1

                
case 2:// JPG/JPEG
                        
imagejpeg($this->pictureFile$this->newPictureName);
                        break;
// case 2

                
case 3// PNG
                        
imagepng($this->pictureFile$this->newPictureName);
                        break;
// case 3

                
default:
                        die(
'Unsupported filetype: '.$fileName);

            }

        return 
true;
        }
// end of stampPicture

        

        
function destruct(){
                unset(
$fileHandle$newPictureName$pictureInfo$pictureName$prefix$stampInfo$stampName$stampXpos$stampYpos);
        }
// end of destruct



}// end of class

function checkimagesize($filename$watermark$dest){
                
          
$pictype=thumb;
            
$width 200;     //Default to stamp size
            
$height 100;    //Default to stamp size

            
list($org_width$org_height) = getimagesize($filename);
            list(
$wm_width$wm_height) = getimagesize($watermark);            
                                
            
//If user submitted picture is smaller in width than watermark - then resize it            
            
if($org_width $wm_width)
            {
                  
//Get ratio of original picture heigth->width
                
$pictureratio $org_height $org_width;
                                             
                
//Set original to width of watermark
        
$width $wm_width;
                
//Set height to scaled value
        
$height = ($width $pictureratio);                                                

              
//Prefix the resized file
              
$dest=$dest.$filename;

              
$format strtolower(substr(strrchr($filename,"."),1));

                    switch(
$format)
                    {
                      case 
'gif' :
                      
$type ="gif";
                      
$img imagecreatefromgif($filename);
                      break;
                      case 
'png' :
                      
$type ="png";
                      
$img imagecreatefrompng($filename);
                      break;
                      case 
'jpg' :
                      
$type ="jpg";
                      
$img imagecreatefromjpeg($filename);
                      break;
                      case 
'jpeg' :
                      
$type ="jpg";
                      
$img imagecreatefromjpeg($filename);
                      break;
                      default :
                      die (
"ERROR; UNSUPPORTED IMAGE TYPE");
                      break;
                    }
                  
                    list(
$org_width$org_height) = getimagesize($filename);
                    
$xoffset 0;
                    
$yoffset 0;
                    if (
$pictype == "thumb"// To minimize destortion
                    
{
                      if (
$org_width $width $org_height$height)
                      {
                        
$xtmp $org_width;
                        
$xratio 1-((($org_width/$org_height)-($width/$height))/2);
                        
$org_width $org_width $xratio;
                        
$xoffset = ($xtmp $org_width)/2;
                      }
                      elseif (
$org_height$height $org_width $width)
                      {
                        
$ytmp $org_height;
                        
$yratio 1-((($width/$height)-($org_width/$org_height))/2);
                        
$org_height $org_height $yratio;
                        
$yoffset = ($ytmp $org_height)/2;
                      }
                    
//Added this else part -------------
                    
} else {    
                        
$xtmp $org_width/$width;
                        
$new_width $width;
                        
$new_height $org_height/$xtmp;
                        if (
$new_height $height){
                          
$ytmp $org_height/$height;
                          
$new_height $height;
                          
$new_width $org_width/$ytmp;
                        }
                        
$width round($new_width);
                        
$height round($new_height);
                    }                                  
                    
$img_n=imagecreatetruecolor ($width$height);
                    
imagecopyresampled($img_n$img00$xoffset$yoffset$width$height$org_width$org_height);
                  
                    if(
$type=="gif")
                    {
                      
imagegif($img_n$dest);
                    }
                    elseif(
$type=="jpg")
                    {
                      
imagejpeg($img_n$dest);
                    }
                    elseif(
$type=="png")
                    {
                      
imagepng($img_n$dest);
                    }
                    elseif(
$type=="bmp")
                    {
                      
imagewbmp($img_n$dest);
                    }            
        }                        
    }
?>

note the original authors info in header.

free2take 10-05-2008 05:43 PM

Final things to note about this implementation were that I modified the class_products table to include a col called `status` which I populated with either `S` for sold or `A` for active I then used this info when deciding whether to enable the Sold button in the userbrowse listings template or not. I have included the images I used for stamping aswell.

Although this implementation was a big change there were several things I liked about it, for instance your stamps would resize to match the supplied photos so never got skewed or stretched, all the main image file types were supported but litestamp. I would avoid adding a col to the db if doing it again as ths made it too complicated and I also think there is an issue deleting all photos, as in order to relist without resubmitting a copy of the original photo was made.

Hope is of use to you all, bear in mind I did do this for V3 as of yet haven't implemented for v4 although thinking about it....

Mully
http://www.ebuyni.com/photos/SOLD_wmclear.jpg
http://www.ebuyni.com/thumbs/small_SOLD_wmclear.jpg

free2take 10-07-2008 05:52 PM

Coolio dude !!!

Is great for people to have option to do this if they choose, dunno when I would have gotten around to upgrading it.

One thought on the extra field for SOLD status, might be best in another table linked to the listing id. This keeps it isolated like in the module scenario and leaves you safer for any db upgrades etc going forward.

:D


All times are GMT -4. The time now is 03:38 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27