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

Source for file class.php5.greeting.php

Documentation is available at class.php5.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. 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 5.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.      * @access public
  49.      * @var string 
  50.      */
  51.     public $mAddTxt         =    '';
  52.     
  53.     /**
  54.      * Card background
  55.      *
  56.      * @access public
  57.      * @var string 
  58.      */
  59.     public $mBg                =    '#FFFFFF';
  60.     
  61.     /**
  62.      * Full URL path to card image
  63.      *
  64.      * @access public
  65.      * @var string 
  66.      */
  67.     public $mFileName        =    '';
  68.     
  69.     /**
  70.      * Sender e-mail address
  71.      *
  72.      * @access public
  73.      * @var string 
  74.      */
  75.     public $mSendFromMail    =    '';
  76.     
  77.     /**
  78.      * Sender name
  79.      *
  80.      * @access public
  81.      * @var string 
  82.      */
  83.     public $mSendFromName    =    '';
  84.     
  85.     /**
  86.      * e-mail address to send
  87.      *
  88.      * @access public
  89.      * @var string 
  90.      */
  91.     public $mSendToMail        =    '';
  92.     
  93.     /**
  94.      * e-mail mSubject
  95.      *
  96.      * @access public
  97.      * @var string 
  98.      */
  99.     public $mSubject        =    'Greeting card';
  100.     
  101.     /**
  102.      * Greeting text
  103.      *
  104.      * @access public
  105.      * @var string 
  106.      */
  107.     public $mText            =    '';
  108.     
  109.     /**
  110.      * Text color
  111.      *
  112.      * @access public
  113.      * @var string 
  114.      */
  115.     public $mTextColor        =    '#000000';
  116.     
  117.     /**
  118.      * Font name on text
  119.      *
  120.      * @access public
  121.      * @var string 
  122.      */
  123.     public $mTextFont        =    'Verdana, Arial, Helvetica, sans-serif';
  124.     
  125.     /**
  126.      * card position
  127.      *
  128.      * @access public
  129.      * @var string 
  130.      */
  131.     public $mTextPos        =    'center';
  132.     
  133.     /**
  134.      * text size
  135.      *
  136.      * @access public
  137.      * @var string 
  138.      */
  139.     public $mTextSize        =    'medium';
  140.     
  141.     /**
  142.      * text style
  143.      *
  144.      * @access public
  145.      * @var string 
  146.      */
  147.     public $mTextStyle        =    '';
  148.     
  149.     /**
  150.      * type on e-mail( html or plaint)
  151.      *
  152.      * @access public
  153.      * @var string 
  154.      */
  155.     public $mType            =    'html';
  156.     
  157.     /**
  158.      * Array with errors
  159.      * 
  160.      * @access public
  161.      * @var    array(int=>string)    $error 
  162.      */
  163.     public $mError             = array();
  164.     
  165.     /**
  166.      * Greeting card constructor
  167.      *
  168.      * @param string $mFileName        Greeting card(file) path and name
  169.      * @return void 
  170.      */
  171.     function __construct($fileName{
  172.         $this->mFileName         = (!empty($fileName)) strval(htmlentities($fileName)) $this->mError['Empty file name';
  173.     }
  174.         
  175.     /**
  176.      * Crete greeting card header
  177.      * 
  178.      * @access protected
  179.      * @return string         header on html card content
  180.      */
  181.     protected function HeaderCard({
  182.         $header '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  183.             <html xmlns="http://www.w3.org/1999/xhtml">
  184.             <head>
  185.                 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  186.                 <title>Greeting by ' $this->mSendFromName  . '</title>
  187.                 <style type="text/css">
  188.                 <!--
  189.                 body { background-color:' $this->mBg . ';}
  190.                 #cb img {
  191.                     margin-top: 0px;
  192.                     margin-right: 5px;
  193.                     margin-bottom: 5px;
  194.                     margin-left: 0px;
  195.                     padding-top: 0px;
  196.                     padding-right: 5px;
  197.                     padding-bottom: 5px;
  198.                     padding-left: 0px;
  199.                     background-color: #808080;}
  200.                 
  201.                 p#text {
  202.                 color        :    ' .    $this->mTextColor . ';
  203.                 font-family: \'' $this->mTextFont . '\';
  204.                 font-size:    ' $this->mTextSize . ';';
  205.         if(!empty($this->mTextStyle)) {
  206.             switch($this->mTextStyle{
  207.                 case 'bold':
  208.                     $header .=     'font-weight: bold;';
  209.                     break;    
  210.                 case 'italic':
  211.                     $header .=     'font-style: italic;';
  212.                     break;    
  213.                 case 'underline':
  214.                     $header .=     'text-decoration: underline;';
  215.                     break;    
  216.             }
  217.         }
  218.         $header .=     '}
  219.                     -->
  220.                 </style>
  221.             </head>';
  222.             
  223.                 
  224.         return $header;
  225.     }  
  226.     
  227.     /**
  228.      * Greeting card footer
  229.      *
  230.      * @access protected
  231.      * @return string         end of HTML content
  232.      */
  233.     protected function FooterCard({
  234.         $footer ("</body>
  235.                 </html>");
  236.             
  237.         return $footer;
  238.     }
  239.     
  240.     /**
  241.      * Create card with image as HTML
  242.      *
  243.      * @access protected
  244.      * @return string         body without '</body><html>' tags
  245.      */
  246.     protected function CreateHtml({
  247.     
  248.         $body '<body>
  249.                     <div id="cb">
  250.                         <div align="center">
  251.                               <p><img src="' $this->mFileName . '" align="' $this->mTextPos . '"/>  </p>
  252.                               <p id="text">' nl2br($this->mText'</p>
  253.                         </div>
  254.                     </div>';
  255.     
  256.         $body .= $this->mAddTxt;
  257.     
  258.         return $body;
  259.     }
  260.     
  261.     /**
  262.      * Create card with Flash as HTML
  263.      * 
  264.      * @access protected
  265.      * @return string         body without '</body><html>' tags
  266.      */
  267.     protected function CreateFlash({
  268.     
  269.         $body '<body>
  270.                     <div id="cb">
  271.                         <div align="center">
  272.                         <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">
  273.                             <param name="movie" value="' $this->mFileName . '" />
  274.                             <param name="quality" value="high" />
  275.                             <param name="play" value="true" />
  276.                             <param name="loop" value="true" />
  277.                             <param name="scale" value="noborder">
  278.                             <embed src="' $this->mFileName . '" quality="high" loop="true" width="400" height="300" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
  279.                             </object>
  280.                               <p id="text">' nl2br($this->mText'</p>
  281.                         </div>
  282.                     </div>';
  283.     
  284.         $body .= $this->mAddTxt;
  285.     
  286.         return $body;
  287.     }
  288.     
  289.     /**
  290.      * Create body as TEXT
  291.      *
  292.      * @access protected
  293.      * @return string         Body
  294.      */
  295.     protected function CreateText({
  296.         
  297.         $body $this->mAddTxt;
  298.     
  299.         return $body;
  300.     }
  301.     
  302.     /**
  303.      * get greeting card
  304.      *
  305.      * @access public
  306.      * @return string         full greeting card content
  307.      */
  308.     public function GetCard({
  309.         $card  $this->HeaderCard();
  310.         
  311.         if(strcmp($this->mType,"flash"== 0{
  312.             $card .= $this->CreateFlash();
  313.         else {
  314.           $card .= $this->CreateHtml();
  315.         }
  316.         
  317.         $card .= $this->FooterCard();
  318.     
  319.         return $card;
  320.     }
  321.     
  322.     /**
  323.      * Show errors
  324.      * 
  325.      * @access public
  326.      * @return void 
  327.      */
  328.      public function ShowErrors({
  329.          for($i 0;$i count($this->mError);$i++{
  330.              echo ($this->mError[$i]);
  331.          }
  332.      }
  333.      
  334.     /**
  335.      * Send greeting card
  336.      *
  337.      * @access public
  338.      * @return boold        true on success or false on fail
  339.      */
  340.     public function SendCard({
  341.     
  342.         $charset "utf-8";
  343.         
  344.         $headers  "MIME-Version: 1.0\r\n";
  345.         $headers .= "From: " $this->mSendFromMail . "\r\n";
  346.         $headers .= "X-Sender: <" $this->mSendFromMail . ">\r\n"
  347.         $headers .= "X-Mailer: PHP\r\n";                                     // mailer
  348.         $headers .= "X-Priority: 1\r\n";                                     // 1-Urgent message! 2-very 3-normal
  349.         $headers .= "Return-Path: <" $this->mSendFromMail . ">\r\n";      // Return path for errors
  350.         
  351.         switch($this->mType{
  352.             
  353.             // Send as html
  354.             case 'html':
  355.                 $card $this->HeaderCard();
  356.                 $card .= $this->CreateHtml();
  357.                 $card .= $this->FooterCard();
  358.                 $headers .= "Content-Typetext/htmlcharset=$charset\r\n";
  359.                 $headers .= "Content-Transfer-Encoding: 8bit\r\n";
  360.                 break;
  361.                 
  362.             // Send as flash                
  363.             case 'flash':
  364.                 $card $this->CreateText(;
  365.                 $headers .= "Content-typetext/plaincharset=$charset\r\n";
  366.                 $headers .= "Content-Transfer-Encoding: 8bit\r\n";
  367.                 break;
  368.                 
  369.             // Send as text        
  370.             case 'text':
  371.                 $card $this->CreateText(;
  372.                 $headers .= "Content-typetext/plaincharset=$charset\r\n";
  373.                 $headers .= "Content-Transfer-Encoding: 8bit\r\n";
  374.                 break;
  375.         }
  376.         
  377.         if(false === @mail($this->mSendToMail ,$this->mSubject,$card,$headers)) {
  378.             $this->mError["Can't send greeting card";
  379.             return false;
  380.         else {
  381.             return true;
  382.         }
  383.           
  384.     }
  385.     
  386. }
  387.  
  388.  
  389. ?>

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