Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18
  1. #11
    Join Date
    Apr 2011
    Location
    UK
    Posts
    33
    Plugin Contributions
    0

    Default Re: Automatically Stamping Customer Name on PDF eBooks?

    And your brother in law passes it to someone else ... who passes it on to someone else ... who passes it to someone else ... who puts it as a free download on their website ... AND you get thousands of spam emails AND I take you to court.
    Of course, having your email on the bottom won't stop it being passed round (just like any book that you may have written your name on the cover may be given away), and with some effort it would be possible to take the stamping off. The deterrent is having YOUR email on it. The email your PayPal account is registered to. It will, if nothing else, make people think twice.

  2. #12
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,942
    Plugin Contributions
    96

    Default Re: Automatically Stamping Customer Name on PDF eBooks?

    For those that might be interested, here's the modified version that I'm using for /includes/modules/pages/downloads/header_php.php to work with the SetaPDF functions:

    Code:
    <?php
    /**
     * download header_php.php
     *
     * @package page
     * @copyright Copyright 2003-2011 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: header_php.php 18964 2011-06-22 19:58:38Z drbyte $
     */
    // This should be first line of the script:
    $zco_notifier->notify('NOTIFY_HEADER_START_DOWNLOAD');
    
    define('SYMLINK_GARBAGE_COLLECTION_THRESHOLD', 1*60*60); // 1 hour default
    
    
    require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
    
    // if the customer is not logged on, redirect them to the time out page
    if (!$_SESSION['customer_id']) {
      zen_redirect(zen_href_link(FILENAME_TIME_OUT));
    }
    
    // Check download.php was called with proper GET parameters
    if ((isset($_GET['order']) && !is_numeric($_GET['order'])) || (isset($_GET['id']) && !is_numeric($_GET['id'])) ) {
      // if the paramaters are wrong, redirect them to the time out page
      zen_redirect(zen_href_link(FILENAME_TIME_OUT));
    }
    
    // Check that order_id, customer_id and filename match
    $sql = "SELECT date_format(o.date_purchased, '%Y-%m-%d')
              AS date_purchased_day, opd.download_maxdays, opd.download_count, opd.download_maxdays, opd.orders_products_filename, o.customers_email_address
              FROM " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " opd
              WHERE o.customers_id = customersID
              AND o.orders_id = ordersID
              AND o.orders_id = op.orders_id
              AND op.orders_products_id = opd.orders_products_id
              AND opd.orders_products_download_id = downloadID
              AND opd.orders_products_filename != ''";
    
    $sql = $db->bindVars($sql, 'customersID', $_SESSION['customer_id'], 'integer');
    $sql = $db->bindVars($sql, 'downloadID', $_GET['id'], 'integer');
    $sql = $db->bindVars($sql, 'ordersID', $_GET['order'], 'integer');
    $downloads = $db->Execute($sql);
    if ($downloads->RecordCount() <= 0 ) die;
    
    $zco_notifier->notify('NOTIFY_CHECK_DOWNLOAD_HANDLER', array($downloads));
    
    // MySQL 3.22 does not have INTERVAL, so must calculate dates with PHP:
    list($dt_year, $dt_month, $dt_day) = explode('-', $downloads->fields['date_purchased_day']);
    $download_timestamp = mktime(23, 59, 59, $dt_month, $dt_day + $downloads->fields['download_maxdays'], $dt_year);
    
    // Die if time expired (maxdays = 0 means no time limit)
    if (($downloads->fields['download_maxdays'] != 0) && ($download_timestamp <= time())) {
      zen_redirect(zen_href_link(FILENAME_DOWNLOAD_TIME_OUT));
    }
    // Die if remaining count is <=0 (maxdays = 0 means no time limit)
    if ($downloads->fields['download_count'] <= 0 and $downloads->fields['download_maxdays'] != 0) {
      zen_redirect(zen_href_link(FILENAME_DOWNLOAD_TIME_OUT));
    }
    
    $zco_notifier->notify('NOTIFY_DOWNLOAD_DAYS_COUNT_OK');
    // FIX HERE AND GIVE ERROR PAGE FOR MISSING FILE
    // Die if file is not there
    if (!file_exists(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename'])) die('Sorry. File not found. Please contact the webmaster to report this error.<br />c/f: ' . $downloads->fields['orders_products_filename']);
    
    $zco_notifier->notify('NOTIFY_DOWNLOAD_FILE_OK');
    
    // Now decrement counter (probably should skip this if download_maxdays = 0, ie: unlimited) -- move it up to lines 48-54?
    $sql = "UPDATE " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . "
              SET download_count = download_count-1
              WHERE orders_products_download_id = :downloadID";
    
    $sql = $db->bindVars($sql, ':downloadID', $_GET['id'], 'integer');
    $db->Execute($sql);
    
    // Returns a random name, 16 to 20 characters long
    // There are more than 10^28 combinations
    // The directory is "hidden", i.e. starts with '.'
    function zen_random_name()
    {
      $letters = 'abcdefghijklmnopqrstuvwxyz';
      $dirname = '.';
      $length = floor(zen_rand(16,20));
      for ($i = 1; $i <= $length; $i++) {
        $q = floor(zen_rand(1,26));
        $dirname .= $letters[$q];
      }
      return $dirname;
    }
    
    // Unlinks all subdirectories and files in $dir
    // Works only on one subdir level, will not recurse
    function zen_unlink_temp_dir($dir)
    {
      $h1 = opendir($dir);
      while ($subdir = readdir($h1)) {
        // Ignore non directories
        if (!is_dir($dir . $subdir)) continue;
        // Ignore . and .. and .svn
        if ($subdir == '.' || $subdir == '..' || $subdir == '.svn') continue;
        // Loop and unlink files in subdirectory
        $h2 = opendir($dir . $subdir);
        list($fn, $exptime) = explode('-', $subdir);
        if ($exptime + SYMLINK_GARBAGE_COLLECTION_THRESHOLD > time()) continue;
        while ($file = readdir($h2)) {
          if ($file == '.' || $file == '..') continue;
          @unlink($dir . $subdir . '/' . $file);
        }
        closedir($h2);
        @rmdir($dir . $subdir);
      }
      closedir($h1);
    }
    
    // disable gzip output buffering if active:
    @ob_end_clean();
    if (@ini_get('zlib.output_compression')) @ini_set('zlib.output_compression', 'Off');
    
    // determine filename for download
    $origin_filename = $downloads->fields['orders_products_filename'];
    $browser_filename = str_replace(' ', '_', $origin_filename);
    if (strstr($browser_filename, '/')) $browser_filename = substr($browser_filename, strrpos($browser_filename, '/')+1);
    if (strstr($browser_filename, '\\')) $browser_filename = substr($browser_filename, strrpos($browser_filename, '\\')+1);
    if (substr(DIR_FS_DOWNLOAD, -1) != '/') $origin_filename = '/' . $origin_filename;
    if (!file_exists(DIR_FS_DOWNLOAD . $origin_filename)) {
      $msg = 'DOWNLOAD PROBLEM: Problems detected with download for ' . DIR_FS_DOWNLOAD . $origin_filename . ' because the file could not be found on the server. If the file exists, then its permissions are too low for PHP to access it. Contact your hosting company for specific help in determining correct permissions to make the file readable by PHP.';
      zen_mail('', STORE_OWNER_EMAIL_ADDRESS, ERROR_CUSTOMER_DOWNLOAD_FAILURE, $msg, STORE_NAME, EMAIL_FROM);
    }
    $downloadFilesize = @filesize(DIR_FS_DOWNLOAD . $origin_filename);
    if (!isset($downloadFilesize) || ($downloadFilesize < 1)) {
      $msg = 'DOWNLOAD PROBLEM: Problem detected with download for ' . DIR_FS_DOWNLOAD . $origin_filename . ' because the server is preventing PHP from reading the file size attributes, or the file is actually 0 bytes in size (which suggests the uploaded file is damaged or incomplete). Perhaps its permissions are too low for PHP to access it? Contact your hosting company for specific help in determining correct permissions to allow PHP to stat the file using the filesize() function.';
      zen_mail('', STORE_OWNER_EMAIL_ADDRESS, ERROR_CUSTOMER_DOWNLOAD_FAILURE, $msg, STORE_NAME, EMAIL_FROM);
    }
    
    
    /* ---- Start lat9 PDF Stamper ---
    **
    ** Stamped file is of the format:  originalname_ordernum_downloadcount.pdf
         */
    $stamp_fn_out = basename($origin_filename, '.pdf') . '_' . $_GET['order'] . '_' . $downloads->fields['download_count'] . '.pdf';
    
    $stamp_fn_out = str_replace(' ', '_', $stamp_fn_out);
    
    $stamp_file_out = DIR_FS_DOWNLOAD_PUBLIC . $stamp_fn_out;
    $stamp_file_in = DIR_FS_DOWNLOAD . $origin_filename;
    
        /**
     * set the includepath for SetaPDF APIs
     * You have to point to the root directory "SetaPDF"
         */
    set_include_path(get_include_path() . PATH_SEPARATOR . DIR_FS_SETAPDF);
    
    
    $zco_notifier->notify('NOTIFY_DOWNLOAD_PATH', get_include_path());
    
    // require the SetaPDF_Stamper-class
    require_once("Stamper/SetaPDF_Stamper.php");
    
    
    $zco_notifier->notify('NOTIFY_DOWNLOAD_STAMP_LOADED');
    
    // Define the path, where the SetaPDF-Stamper will find the font-definition files
    define('SetaPDF_STAMPER_FONTPATH', 'Stamper/font/');
    
    // Create a new instance of SetaPDF_Stamper with output method "Download" w/buffering
    $stamper =& SetaPDF_Stamper::factory('D', true);
    
    $stamper->addFile( 
    	array(
    		"in"  => $stamp_file_in,
    		"out" => $stamp_file_out, 
    		"compression" => true
    	) 
    ); 
    
    // Let's create the text stamp
    // require the SetaPDF_TextStamp-class
    require_once("Stamper/SetaPDF_Stamp/SetaPDF_TextStamp.php");
    // Initiate a new instance of text_stamp 
    $textstamp =& new SetaPDF_TextStamp();
    // Set the text 
    $textstamp->setText("Licensed to:" . "\n" . $downloads->fields['customers_email_address']); 
    // Set font definitions 
    $textstamp->setFont("Arial", "B", 20, 20, "C"); 
    // Set text color to red 
    $textstamp->SetFontColor(255, 0, 0); 
    // Set the charspacing 
    $textstamp->setCharSpacing(15); 
    // Set the rendering mode 
    $textstamp->setRenderingMode(2); 
    // Set the opacity 
    $textstamp->setAlpha(0.2); 
    
        /**
    * Now we assign the text stamp to our stamper 
    * - we define the position on the center and middle of a page (CM) 
    * - the stamp should appear on "all" pages 
    * - no translation of the x-axis nor the y-axis will be done 
    * - we rotate the stamp about 60 degree 
         */
    $stamper->setStamp($textstamp,"CM", "all", 0, 0, 60); 
    
    // Let's stamp! 
    $stamper->stampit(); 
    $stamper->cleanUp();
    
    // This should be last line of the script:
    $zco_notifier->notify('NOTIFY_HEADER_END_DOWNLOAD');
    
    // finally, upon completion of the download, the script should end here and not attempt to display any template components etc.
    zen_exit();

  3. #13
    Join Date
    May 2012
    Posts
    1
    Plugin Contributions
    0

    Default Re: Automatically Stamping Customer Name on PDF eBooks?

    Awesome, lat9! Many thanks!

  4. #14
    Join Date
    Feb 2010
    Location
    Vermont, USA
    Posts
    21
    Plugin Contributions
    0

    Default Re: Automatically Stamping Customer Name on PDF eBooks?

    Quote Originally Posted by lat9 View Post
    For those that might be interested, here's the modified version that I'm using for /includes/modules/pages/downloads/header_php.php to work with the SetaPDF functions:


    That is really awesome, thanks for the useful info. Looks like it's just what we need.

  5. #15
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: Automatically Stamping Customer Name on PDF eBooks?

    lat9,
    Can I offer a potentially even more friendly implementation that doesn't make as much core code changes as your altered header_php.php does?

    1. You added the email address to the SQL query. Good idea. In fact, adding ", o.*" makes all the main order details available, including the email address:
    Code:
              AS date_purchased_day, opd.download_maxdays, opd.download_count, opd.download_maxdays, opd.orders_products_filename, o.*
    2. Change the notifier call to pass all its parameters correctly as an array, plus the order info:
    Code:
        $zco_notifier->notify('NOTIFY_DOWNLOAD_READY_TO_START', $origin_filename, $browser_filename, $downloadFilesize, $_SESSION['customers_host_address']);
    becomes:
    Code:
        $zco_notifier->notify('NOTIFY_DOWNLOAD_READY_TO_START', array($origin_filename, $browser_filename, $downloadFilesize, $_SESSION['customers_host_address'], $downloads->fields));
    3. Add an observer class to take care of your SetaPDF custom code:
    /includes/classes/observers/class.observer_download_stamped_by_setapdf.php
    Code:
    <?php
    /**
     * @package plugins
     * @copyright Copyright 2003-2012 Zen Cart Development Team
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id$
     *
     * Designed for v1.5.0
     */
    
    class observer_download_stamped_by_setaPDF extends base {
    
      function __construct() {
        $this->attach($this, array('NOTIFY_DOWNLOAD_READY_TO_START'));
      }
    
      function update(&$class, $eventID, $paramsArray = array())
      {
        $origin_filename = $paramsArray[0];
        $browser_filename = $paramsArray[1];
        $downloadFilesize = $paramsArray[2];
        $ip_address = $paramsArray[3];
        $orderData = $paramsArray[4];
    
        // if not serving a PDF file, abort this observer class and use normal download procedures.
        if (!preg_match('~\.pdf$~', $origin_filename)) return false;
    
        /* ---- Start lat9 PDF Stamper ---
         **
        ** Stamped file is of the format:  originalname_ordernum_downloadcount.pdf
        */
        $stamp_fn_out = basename($origin_filename, '.pdf') . '_' . $orderData['orders_id'] . '_' . $orderData['download_count'] . '.pdf';
    
        $stamp_fn_out = str_replace(' ', '_', $stamp_fn_out);
    
        $stamp_file_out = DIR_FS_DOWNLOAD_PUBLIC . $stamp_fn_out;
        $stamp_file_in = DIR_FS_DOWNLOAD . $origin_filename;
    
        /**
         * set the includepath for SetaPDF APIs
         * You have to point to the root directory "SetaPDF"
         */
        set_include_path(get_include_path() . PATH_SEPARATOR . DIR_FS_SETAPDF);
        // require the SetaPDF_Stamper-class
        if (file_exists("Stamper/SetaPDF_Stamper.php")) require_once("Stamper/SetaPDF_Stamper.php");
        // if the require() failed (ie: SetaPDF_Stamper.php couldn't be loaded), then abort the observer and serve the file using normal methods)
        if (!class_exists('SetaPDF_Stamper', false)) return FALSE;
    
        // Define the path, where the SetaPDF-Stamper will find the font-definition files
        define('SetaPDF_STAMPER_FONTPATH', 'Stamper/font/');
    
        // Create a new instance of SetaPDF_Stamper with output method "Download" w/buffering
        $stamper =& SetaPDF_Stamper::factory('D', true);
    
        $stamper->addFile(
                  array(
                        "in"  => $stamp_file_in,
                        "out" => $stamp_file_out,
                        "compression" => true
                        ));
    
        // Let's create the text stamp
        // require the SetaPDF_TextStamp-class
        require_once("Stamper/SetaPDF_Stamp/SetaPDF_TextStamp.php");
        // Initiate a new instance of text_stamp
        $textstamp =& new SetaPDF_TextStamp();
        // Set the text
        $textstamp->setText("Licensed to:" . "\n" . $orderData['customers_email_address']);
        // Set font definitions
        $textstamp->setFont("Arial", "B", 20, 20, "C");
        // Set text color to red
        $textstamp->SetFontColor(255, 0, 0);
        // Set the charspacing
        $textstamp->setCharSpacing(15);
        // Set the rendering mode
        $textstamp->setRenderingMode(2);
        // Set the opacity
        $textstamp->setAlpha(0.2);
    
        /**
         * Now we assign the text stamp to our stamper
         * - we define the position on the center and middle of a page (CM)
         * - the stamp should appear on "all" pages
         * - no translation of the x-axis nor the y-axis will be done
         * - we rotate the stamp about 60 degree
        */
        $stamper->setStamp($textstamp,"CM", "all", 0, 0, 60);
    
        // Let's stamp!
        $stamper->stampit();
        $stamper->cleanUp();
    
        zen_exit();
    
      }
    }
    4. Add an auto_loader entry to enable the observer class:
    /includes/auto_loaders/config.observer_download_stamped_by_setapdf.php
    Code:
    <?php
    /**
     * @package plugins
     * @copyright Copyright 2003-2012 Zen Cart Development Team
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     */
    /**
     * Designed for v1.5.0
     */
    if (!defined('IS_ADMIN_FLAG')) {
     die('Illegal Access');
    }
    $autoLoadConfig[190][] = array('autoType'=>'class',
                                  'loadFile'=>'observers/class.observer_download_stamped_by_setapdf.php');
    $autoLoadConfig[190][] = array('autoType'=>'classInstantiate',
                                  'className'=>'observer_download_stamped_by_setaPDF',
                                  'objectName'=>'observer_download_stamped_by_setaPDF');
    Of course, one still needs to buy a license for and install the SetaPDF code on the server for this to work.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #16
    Join Date
    Feb 2010
    Location
    Vermont, USA
    Posts
    21
    Plugin Contributions
    0

    Default Re: Automatically Stamping Customer Name on PDF eBooks?

    That's great DrByte. How hard would it be to make that work with 1.3.9h?

  7. #17
    Join Date
    Jan 2004
    Posts
    66,446
    Plugin Contributions
    81

    Default Re: Automatically Stamping Customer Name on PDF eBooks?

    I'm guessing it should just work, but I haven't tested it on that old version.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  8. #18
    Join Date
    Feb 2010
    Location
    Vermont, USA
    Posts
    21
    Plugin Contributions
    0

    Default Re: Automatically Stamping Customer Name on PDF eBooks?

    I need some help. The owner wants this running and now. I got the WordPress version up and running on another site but we need it on a Zen Cart site today (tomorrow).

    I get an error message from SetaPDF that the source file cannot be found and it downloads a 0 k file.

    Any ideas?

 

 
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Automatically Include Customer Name in Newsletter Salutation?
    By rebelman in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 1
    Last Post: 8 Sep 2011, 07:07 PM
  2. Automatically Include customer name in E Mail
    By Axon in forum General Questions
    Replies: 3
    Last Post: 19 Jan 2011, 11:57 PM
  3. Add Order ID# and Customer Name to PDF Download
    By chrismarie in forum All Other Contributions/Addons
    Replies: 6
    Last Post: 26 Feb 2010, 02:24 PM
  4. Automatically Add products to category by name or attribute
    By divaboutiques in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 2 Feb 2010, 01:14 PM
  5. Automatically generate PDF invoices for customers – need something faster!
    By apemusic in forum Managing Customers and Orders
    Replies: 14
    Last Post: 6 Oct 2007, 10:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg