Documentation TYPO3 par Ameos

class.tx_tipafriend.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *  
00005 *  (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is 
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 * 
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license 
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 * 
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00057 require_once(PATH_tslib.'class.tslib_pibase.php');
00065 class tx_tipafriend extends tslib_pibase {
00066 
00067         var $cObj;              // The backReference to the parent cObj object set at call time
00068 
00076         function main_tipafriend($content,$conf)        {
00077                 $this->conf = $conf;
00078                 $this->config['code'] = $this->cObj->stdWrap($this->conf['code'],$this->conf['code.']);
00079 
00080                         // template is read.
00081                 $this->templateCode = $this->cObj->fileResource($this->conf['templateFile']);
00082 
00083                         // globally substituted markers, fonts and colors.
00084                 $splitMark = md5(microtime());
00085                 $globalMarkerArray=array();
00086                 list($globalMarkerArray['###GW1B###'],$globalMarkerArray['###GW1E###']) = explode($splitMark,$this->cObj->stdWrap($splitMark,$conf['wrap1.']));
00087                 list($globalMarkerArray['###GW2B###'],$globalMarkerArray['###GW2E###']) = explode($splitMark,$this->cObj->stdWrap($splitMark,$conf['wrap2.']));
00088                 $globalMarkerArray['###GC1###'] = $this->cObj->stdWrap($conf['color1'],$conf['color1.']);
00089                 $globalMarkerArray['###GC2###'] = $this->cObj->stdWrap($conf['color2'],$conf['color2.']);
00090                 $globalMarkerArray['###GC3###'] = $this->cObj->stdWrap($conf['color3'],$conf['color3.']);
00091 
00092                         // Substitute Global Marker Array
00093                 $this->templateCode= $this->cObj->substituteMarkerArray($this->templateCode, $globalMarkerArray);
00094 
00095                         // TYpoLink
00096                 $this->typolink_conf = $this->conf['typolink.'];
00097                 $this->typolink_conf['additionalParams'] = $this->cObj->stdWrap($this->typolink_conf['additionalParams'],$this->typolink_conf['additionalParams.']);
00098                 unset($this->typolink_conf['additionalParams.']);
00099 
00100                 $codes=t3lib_div::trimExplode(',', $this->config['code']?$this->config['code']:$this->conf['defaultCode'],1);
00101                 if (!count($codes))     $codes=array('');
00102                 while(list(,$theCode)=each($codes))     {
00103                         $theCode = (string)strtoupper(trim($theCode));
00104                         $this->theCode = $theCode;
00105                         switch($theCode)        {
00106                                 case 'TIPFORM':
00107                                         $content=$this->tipform();
00108                                 break;
00109                                 case 'TIPLINK':
00110                                         $content=$this->tiplink();
00111                                 break;
00112                                 default:
00113                                         $langKey = strtoupper($GLOBALS['TSFE']->config['config']['language']);
00114                                         $helpTemplate = $this->cObj->fileResource('EXT:tipafriend/pi/tipafriend_help.tmpl');
00115 
00116                                                 // Get language version
00117                                         $helpTemplate_lang='';
00118                                         if ($langKey)   {$helpTemplate_lang = $this->cObj->getSubpart($helpTemplate,'###TEMPLATE_'.$langKey.'###');}
00119                                         $helpTemplate = $helpTemplate_lang ? $helpTemplate_lang : $this->cObj->getSubpart($helpTemplate,'###TEMPLATE_DEFAULT###');
00120 
00121                                                 // Markers and substitution:
00122                                         $markerArray['###CODE###'] = $this->theCode;
00123                                         $content.=$this->cObj->substituteMarkerArray($helpTemplate,$markerArray);
00124                                 break;
00125                         }
00126                 }
00127                 return $content;
00128         }
00129 
00135         function tipform()      {
00136                 $GLOBALS['TSFE']->set_no_cache();
00137 
00138                 $tipData = t3lib_div::_GP('TIPFORM');
00139                 $tipData['recipient'] = $this->getRecipients($tipData['recipient']);
00140                 list($tipData['email']) = explode(',',$this->getRecipients($tipData['email']));
00141                 $url = t3lib_div::_GP('tipUrl');
00142 
00143                         // Preparing markers
00144                 $wrappedSubpartArray=array();
00145                 $subpartArray=array();
00146                 
00147                 $markerArray=array();
00148                 $markerArray['###FORM_URL###']=t3lib_div::getIndpEnv('REQUEST_URI');
00149                 $markerArray['###URL###']=$url;
00150                 $markerArray['###URL_ENCODED###']=rawurlencode($url);
00151                 $markerArray['###URL_SPECIALCHARS###']=htmlspecialchars($url);
00152                 
00153                 $wrappedSubpartArray['###LINK###']=array('<a href="'.htmlspecialchars($url).'">','</a>');
00154 
00155                         // validation
00156                 $error=0;
00157                 $sent=0;
00158                 if (t3lib_div::_GP('sendTip'))  {
00159                         if ($this->validate($tipData))  {
00160                                 $this->sendTip($tipData,$url);
00161                                 $sent=1;
00162                         } else {
00163                                 $error=1;
00164                         }
00165                 }
00166 
00167                         // Display form
00168                 if ($sent)      {
00169                         $subpart = $this->cObj->getSubpart($this->templateCode,'###TEMPLATE_TIPFORM_SENT###');
00170 
00171                         $markerArray['###RECIPIENT###']=htmlspecialchars($tipData['recipient']);
00172 
00173                         $content= $this->cObj->substituteMarkerArrayCached($subpart,$markerArray,$subpartArray,$wrappedSubpartArray);
00174                 } else {
00175                         $subpart = $this->cObj->getSubpart($this->templateCode,'###TEMPLATE_TIPFORM###');
00176         
00177                         $markerArray['###MESSAGE###']=htmlspecialchars($tipData['message']);
00178                         $markerArray['###RECIPIENT###']=htmlspecialchars($tipData['recipient']);
00179                         $markerArray['###YOUR_EMAIL###']=htmlspecialchars($tipData['email']);
00180                         $markerArray['###YOUR_NAME###']=htmlspecialchars($tipData['name']);
00181                         $markerArray['###HTML_MESSAGE###']=$tipData['html_message'] ? 'checked' : '';
00182         
00183                         if (!$error)    {
00184                                 $subpartArray['###ERROR_MSG###']='';
00185                         }
00186                 
00187 //                      debug($markerArray);
00188         
00189                                 // Substitute
00190                         $content= $this->cObj->substituteMarkerArrayCached($subpart,$markerArray,$subpartArray,$wrappedSubpartArray);
00191                 }
00192                 return $content;
00193         }
00194 
00201         function validate($tipData)     {
00202                 if (    
00203                         trim($tipData['name']) &&
00204                         $tipData['email'] &&
00205                         $tipData['recipient']
00206                         ) {
00207                                 return 1;
00208                         }
00209         }
00210 
00217         function getRecipients($emails) {
00218                 $emailArr = split('[, ;]',$emails);
00219                 reset($emailArr);
00220                 $listArr=array();
00221                 while(list(,$email)=each($emailArr))    {
00222                         $email = trim($email);
00223                         if ($email && t3lib_div::validEmail($email))    {
00224                                 $listArr[] = $email;
00225                         }
00226                 }
00227                 return implode(',',$listArr);
00228         }
00229 
00237         function sendTip($tipData,$url) {
00238                         // Get template
00239                 $subpart = $this->cObj->getSubpart($this->templateCode,'###TEMPLATE_EMAIL###');
00240 
00241                         // Set markers
00242                 $markerArray['###MESSAGE###']=htmlspecialchars($tipData['message']);
00243                 $markerArray['###RECIPIENT###']=htmlspecialchars($tipData['recipient']);
00244                 $markerArray['###YOUR_EMAIL###']=htmlspecialchars($tipData['email']);
00245                 $markerArray['###YOUR_NAME###']=htmlspecialchars($tipData['name']);
00246                 $markerArray['###URL###']=$url;
00247 
00248                         // Substitute in template
00249                 $content= $this->cObj->substituteMarkerArrayCached($subpart,$markerArray,$subpartArray,$wrappedSubpartArray);
00250                 
00251                         // Set subject, conten and headers
00252                 $headers=array();
00253                 $headers[]='FROM: '.$tipData['name'].' <'.$tipData['email'].'>';
00254                 list($subject,$plain_message) = explode(chr(10),trim($content),2);
00255         
00256 
00257                         // HTML
00258                 $cls=t3lib_div::makeInstanceClassName('t3lib_htmlmail');
00259 
00260                 if (class_exists($cls) && $this->conf['htmlmail'] && $tipData['html_message'])  {       // If htmlmail lib is included, then generate a nice HTML-email
00261                         $Typo3_htmlmail = t3lib_div::makeInstance('t3lib_htmlmail');
00262                         $Typo3_htmlmail->start();
00263                         $Typo3_htmlmail->useBase64();
00264 
00265                         $Typo3_htmlmail->subject = $subject;
00266                         $Typo3_htmlmail->from_email = $tipData['email'];
00267                         $Typo3_htmlmail->from_name = $tipData['name'];
00268                         $Typo3_htmlmail->replyto_email = $tipData['email'];
00269                         $Typo3_htmlmail->replyto_name = $tipData['name'];
00270                         $Typo3_htmlmail->organisation = '';
00271                         $Typo3_htmlmail->priority = 3;
00272 
00273         //              debug($url);
00274                 
00275                                 // this will fail if the url is password protected!
00276                         $Typo3_htmlmail->addHTML($url);
00277                         $Typo3_htmlmail->addPlain($plain_message);
00278         
00279                         $Typo3_htmlmail->setHeaders();
00280                         $Typo3_htmlmail->setContent();
00281                         $Typo3_htmlmail->setRecipient($tipData['recipient']);
00282 
00283 //                      debug($Typo3_htmlmail->theParts);
00284                         $Typo3_htmlmail->sendtheMail();
00285                 } else { // Plain mail:
00286                                 // Sending mail:                
00287 #                       $GLOBALS['TSFE']->plainMailEncoded(, $subject, , implode($headers,chr(10)));
00288                         $this->cObj->sendNotifyEmail($plain_message, $tipData['recipient'], '', $tipData['email'], $tipData['name']);
00289                 }
00290         }
00291 
00297         function tiplink()      {
00298                 $url=t3lib_div::getIndpEnv('TYPO3_REQUEST_URL');
00299 
00300                 $subpart = $this->cObj->getSubpart($this->templateCode,'###TEMPLATE_TIPLINK###');
00301                 
00302                 $wrappedSubpartArray=array();
00303                 $tConf = $this->typolink_conf;
00304                 $tConf['additionalParams'].= '&tipUrl='.rawurlencode($url);
00305 //              debug($tConf);
00306                 $wrappedSubpartArray['###LINK###']= $this->cObj->typolinkWrap($tConf);
00307 
00308                 $markerArray=array();
00309                 $markerArray['###URL###']=$url;
00310                 $markerArray['###URL_ENCODED###']=rawurlencode($url);
00311                 $markerArray['###URL_SPECIALCHARS###']=htmlspecialchars($url);
00312 
00313                         // Substitute
00314                 $content= $this->cObj->substituteMarkerArrayCached($subpart,$markerArray,array(),$wrappedSubpartArray);
00315                 return $content;
00316         }
00317 }
00318 
00319 
00320 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/tipafriend/pi/class.tx_tipafriend.php'])       {
00321         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/tipafriend/pi/class.tx_tipafriend.php']);
00322 }
00323 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6