Greeting
[ class tree: Greeting ] [ index: Greeting ] [ all elements ]

Source for file class.php4.greeting.php

Documentation is available at class.php4.greeting.php

  1. <?php 
  2. /**
  3.  * File contain the greeting class.
  4.  *
  5.  * @package     Greeting
  6.  * @version     1.1
  7.  * @copyright     Copyright (C)2006 Todor Iliev (TheLordOfWeb). All rights reserved.
  8.  * @license     http://www.gnu.org/copyleft/gpl.html GNU Public License
  9.  * @filesource
  10.  */
  11.  
  12. /**
  13.  *     LICENSE
  14.  *     This program is free software; you can redistribute it and/or
  15.  *     modify it under the terms of the GNU General Public License (GPL)
  16.  *     as published by the Free Software Foundation; either version 2
  17.  *     of the License, or (at your option) any later version.
  18.  *    This program is distributed in the hope that it will be useful,
  19.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  *    GNU General Public License for more details.
  22.  *    To read the license please visit http://www.gnu.org/copyleft/gpl.html
  23.  *    ----------------------------------------------------------------------
  24.  *    Original Author of file:
  25.  *    Purpose of file:
  26.  *    ----------------------------------------------------------------------
  27.  *     Tested with IE 6,IE 7, Netscape 7, Opera 9, Firefox 2.0
  28.  *     This is free software. Use at your own risk.
  29.  */
  30.  
  31. /**
  32.  * Greeting card class for php 4.x
  33.  *
  34.  * 
  35.  * @package     Greeting
  36.  * @author         Todor Iliev (TheLordOfWeb) <todor.iliev@viplord.com> <http://viplord.com/>
  37.  * @version     1.1
  38.  * @copyright     Copyright (C)2006 Todor Iliev . All rights reserved.
  39.  * @license     http://www.gnu.org/copyleft/gpl.html GNU Public License
  40.  * @example        example_1.php
  41.  * @example        example_2.php
  42.  * @example     example_3.php
  43.  */
  44. class Greeting  {
  45.     /**
  46.      * Additional text to card
  47.      *
  48.      * @var string 
  49.      */
  50.     var $mAddTxt         =    '';
  51.     
  52.     /**
  53.      * Card background
  54.      *
  55.      * @var string 
  56.      */
  57.     var $mBg            =    '#FFFFFF';
  58.     
  59.     /**
  60.      * Full URL path to card image
  61.      *
  62.      * @var string 
  63.      */
  64.     var $mFileName        =    '';
  65.     
  66.     /**
  67.      * Sender e-mail address
  68.      *
  69.      * @var string 
  70.      */
  71.     var $mSendFromMail    =    '';
  72.     
  73.     /**
  74.      * Sender name
  75.      *
  76.      * @var string 
  77.      */
  78.     var $mSendFromName    =    '';
  79.     
  80.     /**
  81.      * e-mail address to send
  82.      *
  83.      * @var string 
  84.      */
  85.     var $mSendToMail    =    '';
  86.     
  87.     /**
  88.      * e-mail mSubject
  89.      *
  90.      * @var string 
  91.      */
  92.     var $mSubject        =    'Greeting card';
  93.     
  94.     /**
  95.      * Greeting text
  96.      *
  97.      * @var string 
  98.      */
  99.     var $mText            =    '';
  100.     
  101.     /**
  102.      * Text color
  103.      *
  104.      * @var string 
  105.      */
  106.     var $mTextColor        =    '#000000';
  107.     
  108.     /**
  109.      * Font name on text
  110.      *
  111.      * @var string 
  112.      */
  113.     var $mTextFont        =    'Verdana, Arial, Helvetica, sans-serif';
  114.     
  115.     /**
  116.      * card position
  117.      *
  118.      * @var string 
  119.      */
  120.     var $mTextPos        =    'center';
  121.     
  122.     /**
  123.      * text size
  124.      *
  125.      * @var string 
  126.      */
  127.     var $mTextSize        =    'medium';
  128.     
  129.     /**
  130.      * text style
  131.      *
  132.      * @var string 
  133.      */
  134.     var $mTextStyle        =    '';
  135.     
  136.     /**
  137.      * type on e-mail( html or plaint)
  138.      *
  139.      * @var string 
  140.      */
  141.     var $mType            =    'html';
  142.     
  143.     /**
  144.      * Array with errors
  145.      * @var    array(int=>string)    $error 
  146.      */
  147.     var $mError         = array();
  148.     
  149.     /**
  150.      * Greeting card constructor
  151.      *
  152.      * @param string $mFileName        Greeting card(file) path and name
  153.      * @return void 
  154.      */
  155.     function Greeting($fileName{
  156.         $this->mFileName         = (!empty($fileName)) strval(htmlentities($fileName)) $this->mError['Empty file name';
  157.     }
  158.         
  159.     /**
  160.      * Crete greeting card header
  161.      *
  162.      * @return string         header on html card content
  163.      */
  164.     function HeaderCard({
  165.         $header '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  166.             <html xmlns="http://www.w3.org/1999/xhtml">
  167.             <head>
  168.                 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  169.                 <title>Greeting by ' $this->mSendFromName  . '</title>
  170.                 <style type="text/css">
  171.                 <!--
  172.                 body { background-color:' $this->mBg . ';}
  173.                 #cb img {
  174.                     margin-top: 0px;
  175.                     margin-right: 5px;
  176.                     margin-bottom: 5px;
  177.                     margin-left: 0px;
  178.                     padding-top: 0px;
  179.                     padding-right: 5px;
  180.                     padding-bottom: 5px;
  181.                     padding-left: 0px;
  182.                     background-color: #808080;}
  183.                 
  184.                 p#text {
  185.                 color        :    ' .    $this->mTextColor . ';
  186.                 font-family: \'' $this->mTextFont . '\';
  187.                 font-size:    ' $this->mTextSize . ';';
  188.         if(!empty($this->mTextStyle)) {
  189.             switch($this->mTextStyle{
  190.                 case 'bold':
  191.                     $header .=     'font-weight: bold;';
  192.                     break;    
  193.                 case 'italic':
  194.                     $header .=     'font-style: italic;';
  195.                     break;    
  196.                 case 'underline':
  197.                     $header .=     'text-decoration: underline;';
  198.                     break;    
  199.             }
  200.         }
  201.         $header .=     '}
  202.                     -->
  203.                 </style>
  204.             </head>';
  205.             
  206.                 
  207.         return $header;
  208.     }  
  209.     
  210.         
  211.     /**
  212.      * Greeting card footer
  213.      *
  214.      * @return string         end of HTML content
  215.      */
  216.     function FooterCard({
  217.         $footer ("</body>
  218.                 </html>");
  219.             
  220.         return $footer;
  221.     }
  222.     
  223.       
  224.     /**
  225.      * Create card with image as HTML
  226.      *
  227.      * @return string         body without '</body><html>' tags
  228.      */
  229.     function CreateHtml({
  230.     
  231.         $body '<body>
  232.                     <div id="cb">
  233.                         <div align="center">
  234.                               <p><img src="' $this->mFileName . '" align="' $this->mTextPos . '"/>  </p>
  235.                               <p id="text">' nl2br($this->mText'</p>
  236.                         </div>
  237.                     </div>';
  238.     
  239.         $body .= $this->mAddTxt;
  240.     
  241.         return $body;
  242.     }
  243.     
  244.     /**
  245.      * Create card with Flash as HTML
  246.      *
  247.      * @return string         body without '</body><html>' tags
  248.      */
  249.     function CreateFlash({
  250.     
  251.         $body '<body>
  252.                     <div id="cb">
  253.                         <div align="center">
  254.                         <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="300" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">
  255.                             <param name="movie" value="' $this->mFileName . '" />
  256.                             <param name="quality" value="high" />
  257.                             <param name="play" value="true" />
  258.                             <param name="loop" value="true" />
  259.                             <param name="scale" value="noborder">
  260.                             <embed src="' $this->mFileName . '" quality="high" loop="true" width="400" height="300" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
  261.                             </object>
  262.                               <p id="text">' nl2br($this->mText'</p>
  263.                         </div>
  264.                     </div>';
  265.     
  266.         $body .= $this->mAddTxt;
  267.     
  268.         return $body;
  269.     }
  270.     
  271.     /**
  272.      * Create body as TEXT
  273.      *
  274.      * @return string         Body
  275.      */
  276.     function CreateText({
  277.         
  278.         $body $this->mAddTxt;
  279.     
  280.         return $body;
  281.     }
  282.     
  283.      
  284.     /**
  285.      * Get greeting card content
  286.      *
  287.      * @return string         full greeting card content
  288.      */
  289.     function GetCard({
  290.         $card  $this->HeaderCard();
  291.         
  292.         if(strcmp($this->mType,"flash"== 0{
  293.             $card .= $this->CreateFlash();
  294.         else {
  295.           $card .= $this->CreateHtml();
  296.         }
  297.         
  298.         $card .= $this->FooterCard();
  299.     
  300.         return $card;
  301.     }
  302.     
  303.     /**
  304.      * Show errors
  305.      * @return void 
  306.      */
  307.      function ShowErrors({
  308.          for($i 0;$i count($this->mError);$i++{
  309.              echo ($this->mError[$i]);
  310.          }
  311.      }
  312.      
  313.     /**
  314.      * Send greeting card
  315.      *
  316.      * @return boold        true on success or false on fail
  317.      */
  318.     function SendCard({
  319.     
  320.         $charset "utf-8";
  321.         
  322.         $headers  "MIME-Version: 1.0\r\n";
  323.         $headers .= "From: " $this->mSendFromMail . "\r\n";
  324.         $headers .= "X-Sender: <" $this->mSendFromMail . ">\r\n"
  325.         $headers .= "X-Mailer: PHP\r\n";                                     // mailer
  326.         $headers .= "X-Priority: 1\r\n";                                     // 1-Urgent message! 2-very 3-normal
  327.         $headers .= "Return-Path: <" $this->mSendFromMail . ">\r\n";      // Return path for errors
  328.         
  329.         switch($this->mType{
  330.             
  331.             // Send as html
  332.             case 'html':
  333.                 $card $this->HeaderCard();
  334.                 $card .= $this->CreateHtml();
  335.                 $card .= $this->FooterCard();
  336.                 $headers .= "Content-Typetext/htmlcharset=$charset\r\n";
  337.                 $headers .= "Content-Transfer-Encoding: 8bit\r\n";
  338.                 break;
  339.             
  340.             // Send as flash                
  341.             case 'flash':
  342.                 $card $this->CreateText(;
  343.                 $headers .= "Content-typetext/plaincharset=$charset\r\n";
  344.                 $headers .= "Content-Transfer-Encoding: 8bit\r\n";
  345.                 break;
  346.                 
  347.             // Send as text                
  348.             case 'text':
  349.                 $card $this->CreateText(;
  350.                 $headers .= "Content-typetext/plaincharset=$charset\r\n";
  351.                 $headers .= "Content-Transfer-Encoding: 8bit\r\n";
  352.                 break;
  353.         }
  354.         
  355.         if(false === @mail($this->mSendToMail ,$this->mSubject,$card,$headers)) {
  356.             $this->mError["Can't send greeting card.";
  357.             return false;
  358.         else {
  359.             return true;
  360.         }
  361.           
  362.     }
  363.      
  364. }
  365.  
  366.  
  367. ?>

Documentation generated on Mon, 18 Dec 2006 00:26:03 +0200 by phpDocumentor 1.3.1