| [ Index ] |
|
Code source de Typo3 4.1.3 |
1 <?php 2 /*************************************************************** 3 * Copyright notice 4 * 5 * (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com) 6 * All rights reserved 7 * 8 * This script is part of the TYPO3 project. The TYPO3 project is 9 * free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * The GNU General Public License can be found at 15 * http://www.gnu.org/copyleft/gpl.html. 16 * A copy is found in the textfile GPL.txt and important notices to the license 17 * from the author is found in LICENSE.txt distributed with these scripts. 18 * 19 * 20 * This script is distributed in the hope that it will be useful, 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 * GNU General Public License for more details. 24 * 25 * This copyright notice MUST APPEAR in all copies of the script! 26 ***************************************************************/ 27 /** 28 * HTML mail class 29 * 30 * $Id: class.t3lib_htmlmail.php 1609 2006-07-07 19:11:55Z mundaun $ 31 * 32 * @author Kasper Skaarhoj <kasperYYYY@typo3.com> 33 */ 34 /** 35 * [CLASS/FUNCTION INDEX of SCRIPT] 36 * 37 * 38 * 39 * 193: class t3lib_htmlmail 40 * 261: function t3lib_htmlmail () 41 * 268: function start () 42 * 305: function useQuotedPrintable() 43 * 315: function useBase64() 44 * 326: function use8Bit() 45 * 338: function encodeMsg($content) 46 * 348: function addPlain ($content) 47 * 360: function addAttachment($file) 48 * 378: function addHTML ($file) 49 * 401: function extractHtmlInit($html,$url) 50 * 412: function send($recipient) 51 * 52 * SECTION: Main functions 53 * 441: function setHeaders() 54 * 500: function setRecipient ($recip) 55 * 518: function getHTMLContentType() 56 * 527: function setContent() 57 * 554: function constructMixed ($boundary) 58 * 593: function constructHTML ($boundary) 59 * 617: function constructAlternative($boundary) 60 * 638: function constructHTML_media ($boundary) 61 * 691: function sendTheMail () 62 * 757: function getBoundary() 63 * 769: function setPlain ($content) 64 * 780: function setHtml ($content) 65 * 791: function add_header($header) 66 * 812: function add_message($string) 67 * 823: function getContent($type) 68 * 832: function preview() 69 * 70 * SECTION: Functions for acquiring attachments, HTML, analyzing and so on ** 71 * 860: function fetchHTML($file) 72 * 878: function fetchHTMLMedia() 73 * 899: function extractMediaLinks() 74 * 976: function extractHyperLinks() 75 * 1025: function extractFramesInfo() 76 * 1051: function substMediaNamesInHTML($absolute) 77 * 1078: function substHREFsInHTML() 78 * 1106: function substHTTPurlsInPlainText($content) 79 * 1142: function fixRollOvers() 80 * 81 * SECTION: File and URL-functions 82 * 1189: function makeBase64($inputstr) 83 * 1200: function getExtendedURL($url) 84 * 1222: function addUserPass($url) 85 * 1238: function getURL($url) 86 * 1250: function getStrippedURL($url) 87 * 1271: function getMimeType($url) 88 * 1300: function absRef($ref) 89 * 1320: function split_fileref($fileref) 90 * 1347: function extParseUrl($path) 91 * 1362: function tag_regex($tagArray) 92 * 1384: function get_tag_attributes($tag) 93 * 1426: function quoted_printable($string) 94 * 1437: function convertName($name) 95 * 96 * TOTAL FUNCTIONS: 49 97 * (This index is automatically created/updated by the extension "extdeveval") 98 * 99 */ 100 101 102 103 104 105 106 107 108 109 /** 110 * NOTES on MIME mail structures: 111 * 112 * Plain + HTML 113 * multipart/alternative (text, html) 114 * multipart/alternative (text, html) 115 * 116 * Plain + HTML + image 117 * multipart/related (m/a, cids) 118 * multipart/alternative (text, html) 119 * 120 * multipart/related (m/a, cids) 121 * multipart/alternative (text, html) 122 * 123 * plain + attachment 124 * multipart/mixed 125 * 126 * HTML + Attachment: 127 * multipart/mixed (text/html , attachments) 128 * 129 * Plain + HTML + Attachments: 130 * multipart/mixed (m/a, attachments) 131 * multipart/alternative (text, html) 132 * 133 * Plain + HTML + image + attachment 134 * 135 * Outlook expr. 136 * multipart/mixed (m/r, attachments) 137 * multipart/related (m/a, cids) 138 * multipart/alternative (text, html) 139 * 140 * 141 * 142 * FROM RFC 1521: 143 * 144 * 5.1 Quoted-Printable Content-Transfer-Encoding 145 * The Quoted-Printable encoding is intended to represent data that largely consists of octets that correspond to printable characters in the ASCII character set. It encodes the data in such a way that the resulting octets are unlikely to be modified by mail transport. If the data being encoded are mostly ASCII text, the encoded form of the data remains largely recognizable by humans. A body which is entirely ASCII may also be encoded in Quoted-Printable to ensure the integrity of the data should the message pass through a character- translating, and/or line-wrapping gateway. 146 * 147 * In this encoding, octets are to be represented as determined by the following rules: 148 * Rule #1: (General 8-bit representation) Any octet, except those indicating a line break according to the newline convention of the canonical (standard) form of the data being encoded, may be represented by an "=" followed by a two digit hexadecimal representation of the octet's value. The digits of the hexadecimal alphabet, for this purpose, are "0123456789ABCDEF". Uppercase letters must be used when sending hexadecimal data, though a robust implementation may choose to recognize lowercase letters on receipt. Thus, for example, the value 12 (ASCII form feed) can be represented by "=0C", and the value 61 (ASCII EQUAL SIGN) can be represented by "=3D". Except when the following rules allow an alternative encoding, this rule is mandatory. 149 * Rule #2: (Literal representation) Octets with decimal values of 33 through 60 inclusive, and 62 through 126, inclusive, MAY be represented as the ASCII characters which correspond to those octets (EXCLAMATION POINT through LESS THAN, and GREATER THAN through TILDE, respectively). 150 * Rule #3: (White Space): Octets with values of 9 and 32 MAY be represented as ASCII TAB (HT) and SPACE characters, respectively, but MUST NOT be so represented at the end of an encoded line. Any TAB (HT) or SPACE characters on an encoded line MUST thus be followed on that line by a printable character. In particular, an 151 * "=" at the end of an encoded line, indicating a soft line break (see rule #5) may follow one or more TAB (HT) or SPACE characters. It follows that an octet with value 9 or 32 appearing at the end of an encoded line must be represented according to Rule #1. This rule is necessary because some MTAs (Message Transport Agents, programs which transport messages from one user to another, or perform a part of such transfers) are known to pad lines of text with SPACEs, and others are known to remove "white space" characters from the end of a line. Therefore, when decoding a Quoted-Printable body, any trailing white space on a line must be deleted, as it will necessarily have been added by intermediate transport agents. 152 * Rule #4 (Line Breaks): A line break in a text body, independent of what its representation is following the canonical representation of the data being encoded, must be represented by a (RFC 822) line break, which is a CRLF sequence, in the Quoted-Printable encoding. Since the canonical representation of types other than text do not generally include the representation of line breaks, no hard line breaks (i.e. line breaks that are intended to be meaningful and to be displayed to the user) should occur in the quoted-printable encoding of such types. Of course, occurrences of "=0D", "=0A", "0A=0D" and "=0D=0A" will eventually be encountered. In general, however, base64 is preferred over quoted-printable for binary data. 153 * Note that many implementations may elect to encode the local representation of various content types directly, as described in Appendix G. In particular, this may apply to plain text material on systems that use newline conventions other than CRLF delimiters. Such an implementation is permissible, but the generation of line breaks must be generalized to account for the case where alternate representations of newline sequences are used. 154 * Rule #5 (Soft Line Breaks): The Quoted-Printable encoding REQUIRES that encoded lines be no more than 76 characters long. If longer lines are to be encoded with the Quoted-Printable encoding, 'soft' line breaks must be used. An equal sign as the last character on a encoded line indicates such a non-significant ('soft') line break in the encoded text. Thus if the "raw" form of the line is a single unencoded line that says: 155 * Now's the time for all folk to come to the aid of their country. 156 * 157 * This can be represented, in the Quoted-Printable encoding, as 158 * 159 * Now's the time = 160 * for all folk to come= 161 * to the aid of their country. 162 * 163 * This provides a mechanism with which long lines are encoded in such a way as to be restored by the user agent. The 76 character limit does not count the trailing CRLF, but counts all other characters, including any equal signs. 164 * Since the hyphen character ("-") is represented as itself in the Quoted-Printable encoding, care must be taken, when encapsulating a quoted-printable encoded body in a multipart entity, to ensure that the encapsulation boundary does not appear anywhere in the encoded body. (A good strategy is to choose a boundary that includes a character sequence such as "=_" which can never appear in a quoted- printable body. See the definition of multipart messages later in this document.) 165 * NOTE: The quoted-printable encoding represents something of a compromise between readability and reliability in transport. Bodies encoded with the quoted-printable encoding will work reliably over most mail gateways, but may not work perfectly over a few gateways, notably those involving translation into EBCDIC. (In theory, an EBCDIC gateway could decode a quoted-printable body and re-encode it using base64, but such gateways do not yet exist.) A higher level of confidence is offered by the base64 Content-Transfer-Encoding. A way to get reasonably reliable transport through EBCDIC gateways is to also quote the ASCII characters 166 * !"#$@[\]^`{|}~ 167 * according to rule #1. See Appendix B for more information. 168 * Because quoted-printable data is generally assumed to be line- oriented, it is to be expected that the representation of the breaks between the lines of quoted printable data may be altered in transport, in the same manner that plain text mail has always been altered in Internet mail when passing between systems with differing newline conventions. If such alterations are likely to constitute a corruption of the data, it is probably more sensible to use the base64 encoding rather than the quoted-printable encoding. 169 * WARNING TO IMPLEMENTORS: If binary data are encoded in quoted- printable, care must be taken to encode CR and LF characters as "=0D" and "=0A", respectively. In particular, a CRLF sequence in binary data should be encoded as "=0D=0A". Otherwise, if CRLF were represented as a hard line break, it might be incorrectly decoded on 170 * platforms with different line break conventions. 171 * For formalists, the syntax of quoted-printable data is described by the following grammar: 172 * 173 * quoted-printable := ([*(ptext / SPACE / TAB) ptext] ["="] CRLF) 174 * ; Maximum line length of 76 characters excluding CRLF 175 * 176 * ptext := octet /<any ASCII character except "=", SPACE, or TAB> 177 * ; characters not listed as "mail-safe" in Appendix B 178 * ; are also not recommended. 179 * 180 * octet := "=" 2(DIGIT / "A" / "B" / "C" / "D" / "E" / "F") 181 * ; octet must be used for characters > 127, =, SPACE, or TAB, 182 * ; and is recommended for any characters not listed in 183 * ; Appendix B as "mail-safe". 184 */ 185 186 /** 187 * HTML mail class 188 * 189 * @author Kasper Skaarhoj <kasperYYYY@typo3.com> 190 * @package TYPO3 191 * @subpackage t3lib 192 */ 193 class t3lib_htmlmail { 194 // Headerinfo: 195 var $recipient = "recipient@whatever.com"; 196 var $recipient_copy = ""; // This recipient (or list of...) will also receive the mail. Regard it as a copy. 197 var $subject = "This is the subject"; 198 var $from_email = "sender@php-mailer.com"; 199 var $from_name = "Mr. Sender"; 200 var $replyto_email = "reply@mailer.com"; 201 var $replyto_name = "Mr. Reply"; 202 var $organisation = "Your Company"; 203 var $priority = 3; // 1 = highest, 5 = lowest, 3 = normal 204 var $mailer = "PHP mailer"; // X-mailer 205 var $alt_base64=0; 206 var $alt_8bit=0; 207 var $jumperURL_prefix =""; // This is a prefix that will be added to all links in the mail. Example: 'http://www.mydomain.com/jump?userid=###FIELD_uid###&url='. if used, anything after url= is urlencoded. 208 var $jumperURL_useId=0; // If set, then the array-key of the urls are inserted instead of the url itself. Smart in order to reduce link-length 209 var $mediaList=""; // If set, this is a list of the media-files (index-keys to the array) that should be represented in the html-mail 210 var $http_password=""; 211 var $http_username=""; 212 var $postfix_version1=false; 213 214 // Internal 215 216 /* This is how the $theParts-array is normally looking 217 var $theParts = Array( 218 "plain" => Array ( 219 "content"=> "" 220 ), 221 "html" => Array ( 222 "content"=> "", 223 "path" => "", 224 "media" => Array(), 225 "hrefs" => Array() 226 ), 227 "attach" => Array () 228 ); 229 */ 230 var $theParts = Array(); 231 232 var $messageid = ""; 233 var $returnPath = ""; 234 var $Xid = ""; 235 var $dontEncodeHeader = false; // If set, the header will not be encoded 236 237 var $headers = ""; 238 var $message = ""; 239 var $part=0; 240 var $image_fullpath_list = ""; 241 var $href_fullpath_list = ""; 242 243 var $plain_text_header = ''; 244 var $html_text_header = ''; 245 var $charset = ''; 246 var $defaultCharset = 'iso-8859-1'; 247 248 249 250 251 252 253 254 255 /** 256 * Constructor. If the configuration variable forceReturnPath is set, calls to mail will be called with a 5th parameter. 257 * See function sendTheMail for more info 258 * 259 * @return [type] ... 260 */ 261 function t3lib_htmlmail () { 262 $this->forceReturnPath = $GLOBALS['TYPO3_CONF_VARS']['SYS']['forceReturnPath']; 263 } 264 265 /** 266 * @return [type] ... 267 */ 268 function start () { 269 global $TYPO3_CONF_VARS; 270 271 // Sets the message id 272 $host = t3lib_div::getHostname(); 273 if (!$host || $host == '127.0.0.1' || $host == 'localhost' || $host == 'localhost.localdomain') { 274 $host = ($TYPO3_CONF_VARS['SYS']['sitename'] ? preg_replace('/[^A-Za-z0-9_\-]/', '_', $TYPO3_CONF_VARS['SYS']['sitename']) : 'localhost') . '.TYPO3'; 275 } 276 $this->messageid = md5(microtime()) . '@' . $host; 277 278 // Default line break for Unix systems. 279 $this->linebreak = chr(10); 280 // Line break for Windows. This is needed because PHP on Windows systems send mails via SMTP instead of using sendmail, and thus the linebreak needs to be \r\n. 281 if (TYPO3_OS=='WIN') { 282 $this->linebreak = chr(13).chr(10); 283 } 284 285 if (!$this->charset) { 286 if (is_object($GLOBALS['TSFE']) && $GLOBALS['TSFE']->renderCharset) { 287 $this->charset = $GLOBALS['TSFE']->renderCharset; 288 } elseif (is_object($GLOBALS['LANG']) && $GLOBALS['LANG']->charSet) { 289 $this->charset = $GLOBALS['LANG']->charSet; 290 } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) { 291 $this->charset = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']; 292 } else { 293 $this->charset = $this->defaultCharset; 294 } 295 } 296 297 // Use quoted-printable headers by default 298 $this->useQuotedPrintable(); 299 } 300 301 /** 302 * [Describe function...] 303 * 304 * @return void 305 */ 306 function useQuotedPrintable() { 307 $this->plain_text_header = 'Content-Type: text/plain; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: quoted-printable'; 308 $this->html_text_header = 'Content-Type: text/html; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: quoted-printable'; 309 } 310 311 /** 312 * [Describe function...] 313 * 314 * @return void 315 */ 316 function useBase64() { 317 $this->plain_text_header = 'Content-Type: text/plain; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: base64'; 318 $this->html_text_header = 'Content-Type: text/html; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: base64'; 319 $this->alt_base64=1; 320 } 321 322 /** 323 * [Describe function...] 324 * 325 * @return void 326 */ 327 function use8Bit() { 328 $this->plain_text_header = 'Content-Type: text/plain; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: 8bit'; 329 $this->html_text_header = 'Content-Type: text/html; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: 8bit'; 330 $this->alt_8bit=1; 331 } 332 333 /** 334 * [Describe function...] 335 * 336 * @param [type] $content: ... 337 * @return [type] ... 338 */ 339 function encodeMsg($content) { 340 return $this->alt_base64 ? $this->makeBase64($content) : ($this->alt_8bit ? $content : t3lib_div::quoted_printable($content)); 341 } 342 343 /** 344 * [Describe function...] 345 * 346 * @param [type] $content: ... 347 * @return [type] ... 348 */ 349 function addPlain ($content) { 350 // Adds plain-text and qp-encodes it 351 $content=$this->substHTTPurlsInPlainText($content); 352 $this->setPlain($this->encodeMsg($content)); 353 } 354 355 /** 356 * [Describe function...] 357 * 358 * @param [type] $file: ... 359 * @return [type] ... 360 */ 361 function addAttachment($file) { 362 // Adds an attachment to the mail 363 $theArr = $this->getExtendedURL($file); // We fetch the content and the mime-type 364 if ($theArr) { 365 if (!$theArr["content_type"]){$theArr["content_type"]="application/octet-stream";} 366 $temp = $this->split_fileref($file); 367 $theArr["filename"]= (($temp["file"])?$temp["file"]:(strpos(" ".$theArr["content_type"],"htm")?"index.html":"unknown")); 368 $this->theParts["attach"][]=$theArr; 369 return true; 370 } else { return false;} 371 } 372 373 /** 374 * [Describe function...] 375 * 376 * @param [type] $file: ... 377 * @return [type] ... 378 */ 379 function addHTML ($file) { 380 // Adds HTML and media, encodes it from a URL or file 381 $status = $this->fetchHTML($file); 382 // debug(md5($status)); 383 if (!$status) {return false;} 384 if ($this->extractFramesInfo()) { 385 return "Document was a frameset. Stopped"; 386 } 387 $this->extractMediaLinks(); 388 $this->extractHyperLinks(); 389 $this->fetchHTMLMedia(); 390 $this->substMediaNamesInHTML(0); // 0 = relative 391 $this->substHREFsInHTML(); 392 $this->setHTML($this->encodeMsg($this->theParts["html"]["content"])); 393 } 394 395 /** 396 * External used to extract HTML-parts 397 * 398 * @param [type] $html: ... 399 * @param [type] $url: ... 400 * @return [type] ... 401 */ 402 function extractHtmlInit($html,$url) { 403 $this->theParts["html"]["content"]=$html; 404 $this->theParts["html"]["path"]=$url; 405 } 406 407 /** 408 * [Describe function...] 409 * 410 * @param [type] $recipient: ... 411 * @return [type] ... 412 */ 413 function send($recipient) { 414 // This function sends the mail to one $recipient 415 if ($recipient) {$this->recipient = $recipient;} 416 $this->setHeaders(); 417 $this->setContent(); 418 $this->sendTheMail(); 419 } 420 421 422 423 424 425 426 427 428 429 430 431 432 433 /***************************************** 434 * 435 * Main functions 436 * 437 *****************************************/ 438 439 /** 440 * @return [type] ... 441 */ 442 function setHeaders() { 443 // Clears the header-string and sets the headers based on object-vars. 444 $this->headers = ""; 445 // Message_id 446 $this->add_header("Message-ID: <".$this->messageid.">"); 447 // Return path 448 if ($this->returnPath) { 449 $this->add_header("Return-Path: ".$this->returnPath); 450 $this->add_header("Errors-To: ".$this->returnPath); 451 } 452 // X-id 453 if ($this->Xid) { 454 $this->add_header("X-Typo3MID: ".$this->Xid); 455 } 456 457 // From 458 if ($this->from_email) { 459 if ($this->from_name) { 460 $this->add_header('From: '.$this->from_name.' <'.$this->from_email.'>'); 461 } else { 462 $this->add_header('From: '.$this->from_email); 463 } 464 } 465 // Reply 466 if ($this->replyto_email) { 467 if ($this->replyto_name) { 468 $this->add_header('Reply-To: '.$this->replyto_name.' <'.$this->replyto_email.'>'); 469 } else { 470 $this->add_header('Reply-To: '.$this->replyto_email); 471 } 472 } 473 // Organisation 474 if ($this->organisation) { 475 $this->add_header('Organisation: '.$this->organisation); 476 } 477 // mailer 478 if ($this->mailer) { 479 $this->add_header("X-Mailer: $this->mailer"); 480 } 481 // priority 482 if ($this->priority) { 483 $this->add_header("X-Priority: $this->priority"); 484 } 485 $this->add_header("Mime-Version: 1.0"); 486 487 if (!$this->dontEncodeHeader) { 488 $enc = $this->alt_base64 ? 'base64' : 'quoted_printable'; // Header must be ASCII, therefore only base64 or quoted_printable are allowed! 489 // Quote recipient and subject 490 $this->recipient = t3lib_div::encodeHeader($this->recipient,$enc,$this->charset); 491 $this->subject = t3lib_div::encodeHeader($this->subject,$enc,$this->charset); 492 } 493 } 494 495 /** 496 * [Describe function...] 497 * 498 * @param [type] $recip: ... 499 * @return [type] ... 500 */ 501 function setRecipient ($recip) { 502 // Sets the recipient(s). If you supply a string, you set one recipient. If you supply an array, every value is added as a recipient. 503 if (is_array($recip)) { 504 $this->recipient = ""; 505 while (list($key,) = each($recip)) { 506 $this->recipient .= $recip[$key].","; 507 } 508 $this->recipient = ereg_replace(",$","",$this->recipient); 509 } else { 510 $this->recipient = $recip; 511 } 512 } 513 514 /** 515 * [Describe function...] 516 * 517 * @return [type] ... 518 */ 519 function getHTMLContentType() { 520 return count($this->theParts["html"]["media"]) ? 'multipart/related;' : 'multipart/alternative;'; 521 } 522 523 /** 524 * [Describe function...] 525 * 526 * @return [type] ... 527 */ 528 function setContent() { 529 // Begins building the message-body 530 $this->message = ""; 531 $boundary = $this->getBoundary(); 532 // Setting up headers 533 if (count($this->theParts["attach"])) { 534 $this->add_header('Content-Type: multipart/mixed;'); 535 $this->add_header(' boundary="'.$boundary.'"'); 536 $this->add_message("This is a multi-part message in MIME format.\n"); 537 $this->constructMixed($boundary); // Generate (plain/HTML) / attachments 538 } elseif ($this->theParts["html"]["content"]) { 539 $this->add_header('Content-Type: '.$this->getHTMLContentType()); 540 $this->add_header(' boundary="'.$boundary.'"'); 541 $this->add_message("This is a multi-part message in MIME format.\n"); 542 $this->constructHTML($boundary); // Generate plain/HTML mail 543 } else { 544 $this->add_header($this->plain_text_header); 545 $this->add_message($this->getContent("plain")); // Generate plain only 546 } 547 } 548 549 /** 550 * [Describe function...] 551 * 552 * @param [type] $boundary: ... 553 * @return [type] ... 554 */ 555 function constructMixed ($boundary) { 556 // Here (plain/HTML) is combined with the attachments 557 $this->add_message("--".$boundary); 558 // (plain/HTML) is added 559 if ($this->theParts["html"]["content"]) { 560 // HTML and plain 561 $newBoundary = $this->getBoundary(); 562 $this->add_message("Content-Type: ".$this->getHTMLContentType()); 563 $this->add_message(' boundary="'.$newBoundary.'"'); 564 $this->add_message(''); 565 $this->constructHTML($newBoundary); 566 } else { // Purely plain 567 $this->add_message($this->plain_text_header); 568 $this->add_message(''); 569 $this->add_message($this->getContent("plain")); 570 } 571 // attachments are added 572 if (is_array($this->theParts["attach"])) { 573 reset($this->theParts["attach"]); 574 while(list(,$media)=each($this->theParts["attach"])) { 575 $this->add_message("--".$boundary); 576 $this->add_message("Content-Type: ".$media["content_type"]); 577 $this->add_message(' name="'.$media["filename"].'"'); 578 $this->add_message("Content-Transfer-Encoding: base64"); 579 $this->add_message("Content-Disposition: attachment;"); 580 $this->add_message(' filename="'.$media["filename"].'"'); 581 $this->add_message(''); 582 $this->add_message($this->makeBase64($media["content"])); 583 } 584 } 585 $this->add_message("--".$boundary."--\n"); 586 } 587 588 /** 589 * [Describe function...] 590 * 591 * @param [type] $boundary: ... 592 * @return [type] ... 593 */ 594 function constructHTML ($boundary) { 595 if (count($this->theParts["html"]["media"])) { // If media, then we know, the multipart/related content-type has been set before this function call... 596 $this->add_message("--".$boundary); 597 // HTML has media 598 $newBoundary = $this->getBoundary(); 599 $this->add_message("Content-Type: multipart/alternative;"); 600 $this->add_message(' boundary="'.$newBoundary.'"'); 601 $this->add_message('Content-Transfer-Encoding: 7bit'); 602 $this->add_message(''); 603 604 $this->constructAlternative($newBoundary); // Adding the plaintext/html mix 605 606 $this->constructHTML_media($boundary); 607 } else { 608 $this->constructAlternative($boundary); // Adding the plaintext/html mix, and if no media, then use $boundary instead of $newBoundary 609 } 610 } 611 612 /** 613 * [Describe function...] 614 * 615 * @param [type] $boundary: ... 616 * @return [type] ... 617 */ 618 function constructAlternative($boundary) { 619 // Here plain is combined with HTML 620 $this->add_message("--".$boundary); 621 // plain is added 622 $this->add_message($this->plain_text_header); 623 $this->add_message(''); 624 $this->add_message($this->getContent("plain")); 625 $this->add_message("--".$boundary); 626 // html is added 627 $this->add_message($this->html_text_header); 628 $this->add_message(''); 629 $this->add_message($this->getContent("html")); 630 $this->add_message("--".$boundary."--\n"); 631 } 632 633 /** 634 * [Describe function...] 635 * 636 * @param [type] $boundary: ... 637 * @return [type] ... 638 */ 639 function constructHTML_media ($boundary) { 640 /* // Constructs the HTML-part of message if the HTML contains media 641 $this->add_message("--".$boundary); 642 // htmlcode is added 643 $this->add_message($this->html_text_header); 644 $this->add_message(''); 645 $this->add_message($this->getContent("html")); 646 647 OLD stuf... 648 649 */ 650 // media is added 651 if (is_array($this->theParts["html"]["media"])) { 652 reset($this->theParts["html"]["media"]); 653 while(list($key,$media)=each($this->theParts["html"]["media"])) { 654 if (!$this->mediaList || t3lib_div::inList($this->mediaList,$key)) { 655 $this->add_message("--".$boundary); 656 $this->add_message("Content-Type: ".$media["ctype"]); 657 $this->add_message("Content-ID: <part".$key.".".$this->messageid.">"); 658 $this->add_message("Content-Transfer-Encoding: base64"); 659 $this->add_message(''); 660 $this->add_message($this->makeBase64($media["content"])); 661 } 662 } 663 } 664 $this->add_message("--".$boundary."--\n"); 665 } 666 667 /** 668 * Sends the mail by calling the mail() function in php. On Linux systems this will invoke the MTA 669 * defined in php.ini (sendmail -t -i by default), on Windows a SMTP must be specified in the sys.ini. 670 * Most common MTA's on Linux has a Sendmail interface, including Postfix and Exim. 671 * For setting the return-path correctly, the parameter -f has to be added to the system call to sendmail. 672 * This obviously does not have any effect on Windows, but on Sendmail compliant systems this works. If safe mode 673 * is enabled, then extra parameters is not allowed, so a safe mode check is made before the mail() command is 674 * invoked. When using the -f parameter, some MTA's will put an X-AUTHENTICATION-WARNING saying that 675 * the return path was modified manually with the -f flag. To disable this warning make sure that the user running 676 * Apache is in the /etc/mail/trusted-users table. 677 * 678 * POSTFIX: With postfix version below 2.0 there is a problem that the -f parameter can not be used in conjunction 679 * with -t. Postfix will give an error in the maillog: 680 * 681 * cannot handle command-line recipients with -t 682 * 683 * The -f parameter is only enabled if the parameter forceReturnPath is enabled in the install tool. 684 * 685 * This whole problem of return-path turns out to be quite tricky. If you have a solution that works better, on all 686 * standard MTA's then we are very open for suggestions. 687 * 688 * With time this function should be made such that several ways of sending the mail is possible (local MTA, smtp other). 689 * 690 * @return [type] ... 691 */ 692 function sendTheMail () { 693 #debug(array($this->recipient,$this->subject,$this->message,$this->headers)); 694 // Sends the mail, requires the recipient, message and headers to be set. 695 if (trim($this->recipient) && trim($this->message)) { // && trim($this->headers) 696 $returnPath = (strlen($this->returnPath)>0)?"-f".$this->returnPath:''; 697 //On windows the -f flag is not used (specific for Sendmail and Postfix), but instead the php.ini parameter sendmail_from is used. 698 if($this->returnPath) { 699 ini_set(sendmail_from, $this->returnPath); 700 } 701 //If safe mode is on, the fifth parameter to mail is not allowed, so the fix wont work on unix with safe_mode=On 702 if(!ini_get('safe_mode') && $this->forceReturnPath) { 703 mail($this->recipient, 704 $this->subject, 705 $this->message, 706 $this->headers, 707 $returnPath); 708 } else { 709 mail($this->recipient, 710 $this->subject, 711 $this->message, 712 $this->headers); 713 } 714 // Sending copy: 715 if ($this->recipient_copy) { 716 if(!ini_get('safe_mode') && $this->forceReturnPath) { 717 mail( $this->recipient_copy, 718 $this->subject, 719 $this->message, 720 $this->headers, 721 $returnPath); 722 } else { 723 mail( $this->recipient_copy, 724 $this->subject, 725 $this->message, 726 $this->headers ); 727 } 728 } 729 // Auto response 730 if ($this->auto_respond_msg) { 731 $theParts = explode('/',$this->auto_respond_msg,2); 732 $theParts[1] = str_replace("/",chr(10),$theParts[1]); 733 if(!ini_get('safe_mode') && $this->forceReturnPath) { 734 mail( $this->from_email, 735 $theParts[0], 736 $theParts[1], 737 "From: ".$this->recipient, 738 $returnPath); 739 } else { 740 mail( $this->from_email, 741 $theParts[0], 742 $theParts[1], 743 "From: ".$this->recipient); 744 } 745 } 746 if($this->returnPath) { 747 ini_restore(sendmail_from); 748 } 749 return true; 750 } else {return false;} 751 } 752 753 /** 754 * [Describe function...] 755 * 756 * @return [type] ... 757 */ 758 function getBoundary() { 759 // Returns boundaries 760 $this->part++; 761 return "----------".uniqid("part_".$this->part."_"); 762 } 763 764 /** 765 * [Describe function...] 766 * 767 * @param [type] $content: ... 768 * @return [type] ... 769 */ 770 function setPlain ($content) { 771 // Sets the plain-text part. No processing done. 772 $this->theParts["plain"]["content"] = $content; 773 } 774 775 /** 776 * [Describe function...] 777 * 778 * @param [type] $content: ... 779 * @return [type] ... 780 */ 781 function setHtml ($content) { 782 // Sets the HTML-part. No processing done. 783 $this->theParts["html"]["content"] = $content; 784 } 785 786 /** 787 * [Describe function...] 788 * 789 * @param [type] $header: ... 790 * @return [type] ... 791 */ 792 function add_header($header) { 793 if (!$this->dontEncodeHeader && !stristr($header,'Content-Type') && !stristr($header,'Content-Transfer-Encoding')) { 794 // Mail headers must be ASCII, therefore we convert the whole header to either base64 or quoted_printable 795 $parts = explode(': ',$header,2); // Field tags must not be encoded 796 if (count($parts)==2) { 797 $enc = $this->alt_base64 ? 'base64' : 'quoted_printable'; 798 $parts[1] = t3lib_div::encodeHeader($parts[1],$enc,$this->charset); 799 $header = implode(': ',$parts); 800 } 801 } 802 803 // Adds a header to the mail. Use this AFTER the setHeaders()-function 804 $this->headers.=$header."\n"; 805 } 806 807 /** 808 * [Describe function...] 809 * 810 * @param [type] $string: ... 811 * @return [type] ... 812 */ 813 function add_message($string) { 814 // Adds a line of text to the mail-body. Is normally use internally 815 $this->message.=$string."\n"; 816 } 817 818 /** 819 * [Describe function...] 820 * 821 * @param [type] $type: ... 822 * @return [type] ... 823 */ 824 function getContent($type) { 825 return $this->theParts[$type]["content"]; 826 } 827 828 /** 829 * [Describe function...] 830 * 831 * @return [type] ... 832 */ 833 function preview() { 834 echo nl2br(HTMLSpecialChars($this->headers)); 835 echo "<BR>"; 836 echo nl2br(HTMLSpecialChars($this->message)); 837 } 838 839 840 841 842 843 844 845 846 847 848 849 850 851 /**************************************************** 852 * 853 * Functions for acquiring attachments, HTML, analyzing and so on ** 854 * 855 ***************************************************/ 856 857 /** 858 * @param [type] $file: ... 859 * @return [type] ... 860 */ 861 function fetchHTML($file) { 862 // Fetches the HTML-content from either url og local serverfile 863 $this->theParts["html"]["content"] = $this->getURL($file); // Fetches the content of the page 864 if ($this->theParts["html"]["content"]) { 865 $addr = $this->extParseUrl($file); 866 $path = ($addr['scheme']) ? $addr['scheme'].'://'.$addr['host'].(($addr['port'])?':'.$addr['port']:'').(($addr['filepath'])?$addr['filepath']:'/') : $addr['filepath']; 867 $this->theParts["html"]["path"] = $path; 868 return true; 869 } else { 870 return false; 871 } 872 } 873 874 /** 875 * [Describe function...] 876 * 877 * @return [type] ... 878 */ 879 function fetchHTMLMedia() { 880 // Fetches the mediafiles which are found by extractMediaLinks() 881 if (is_array($this->theParts["html"]["media"])) { 882 reset ($this->theParts["html"]["media"]); 883 if (count($this->theParts["html"]["media"]) > 0) { 884 while (list($key,$media) = each ($this->theParts["html"]["media"])) { 885 $picdata = $this->getExtendedURL($this->theParts["html"]["media"][$key]["absRef"]); // We fetch the content and the mime-type 886 if (is_array($picdata)) { 887 $this->theParts["html"]["media"][$key]["content"] = $picdata["content"]; 888 $this->theParts["html"]["media"][$key]["ctype"] = $picdata["content_type"]; 889 } 890 } 891 } 892 } 893 } 894 895 /** 896 * [Describe function...] 897 * 898 * @return [type] ... 899 */ 900 function extractMediaLinks() { 901 // extracts all media-links from $this->theParts["html"]["content"] 902 $html_code = $this->theParts["html"]["content"]; 903 $attribRegex = $this->tag_regex(Array("img","table","td","tr","body","iframe","script","input","embed")); 904 $codepieces = split($attribRegex, $html_code); // Splits the document by the beginning of the above tags 905 $len=strlen($codepieces[0]); 906 $pieces = count($codepieces); 907 $reg = array(); 908 for($i=1; $i < $pieces; $i++) { 909 $tag = strtolower(strtok(substr($html_code,$len+1,10)," ")); 910 $len+=strlen($tag)+strlen($codepieces[$i])+2; 911 $dummy = eregi("[^>]*", $codepieces[$i], $reg); 912 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag 913 $imageData=array(); 914 $imageData["ref"]=($attributes["src"]) ? $attributes["src"] : $attributes["background"]; // Finds the src or background attribute 915 if ($imageData["ref"]) { 916 $imageData["quotes"]=(substr($codepieces[$i],strpos($codepieces[$i], $imageData["ref"])-1,1)=='"')?'"':''; // Finds out if the value had quotes around it 917 $imageData["subst_str"] = $imageData["quotes"].$imageData["ref"].$imageData["quotes"]; // subst_str is the string to look for, when substituting lateron 918 if ($imageData["ref"] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) { 919 $this->image_fullpath_list.="|".$imageData["subst_str"]."|"; 920 $imageData["absRef"] = $this->absRef($imageData["ref"]); 921 $imageData["tag"]=$tag; 922 $imageData["use_jumpurl"]=$attributes["dmailerping"]?1:0; 923 $this->theParts["html"]["media"][]=$imageData; 924 } 925 } 926 } 927 // Extracts stylesheets 928 $attribRegex = $this->tag_regex(Array("link")); 929 $codepieces = split($attribRegex, $html_code); // Splits the document by the beginning of the above tags 930 $pieces = count($codepieces); 931 for($i=1; $i < $pieces; $i++) { 932 $dummy = eregi("[^>]*", $codepieces[$i], $reg); 933 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag 934 $imageData=array(); 935 if (strtolower($attributes["rel"])=="stylesheet" && $attributes["href"]) { 936 $imageData["ref"]=$attributes["href"]; // Finds the src or background attribute 937 $imageData["quotes"]=(substr($codepieces[$i],strpos($codepieces[$i], $imageData["ref"])-1,1)=='"')?'"':''; // Finds out if the value had quotes around it 938 $imageData["subst_str"] = $imageData["quotes"].$imageData["ref"].$imageData["quotes"]; // subst_str is the string to look for, when substituting lateron 939 if ($imageData["ref"] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) { 940 $this->image_fullpath_list.="|".$imageData["subst_str"]."|"; 941 $imageData["absRef"] = $this->absRef($imageData["ref"]); 942 $this->theParts["html"]["media"][]=$imageData; 943 } 944 } 945 } 946 // fixes javascript rollovers 947 $codepieces = split(quotemeta(".src"), $html_code); 948 $pieces = count($codepieces); 949 $expr = "^[^".quotemeta("\"").quotemeta("'")."]*"; 950 for($i=1; $i < $pieces; $i++) { 951 $temp = $codepieces[$i]; 952 $temp = trim(ereg_replace("=","",trim($temp))); 953 ereg ($expr,substr($temp,1,strlen($temp)),$reg); 954 $imageData["ref"] = $reg[0]; 955 $imageData["quotes"] = substr($temp,0,1); 956 $imageData["subst_str"] = $imageData["quotes"].$imageData["ref"].$imageData["quotes"]; // subst_str is the string to look for, when substituting lateron 957 $theInfo = $this->split_fileref($imageData["ref"]); 958 switch ($theInfo["fileext"]) { 959 case "gif": 960 case "jpeg": 961 case "jpg": 962 if ($imageData["ref"] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) { 963 $this->image_fullpath_list.="|".$imageData["subst_str"]."|"; 964 $imageData["absRef"] = $this->absRef($imageData["ref"]); 965 $this->theParts["html"]["media"][]=$imageData; 966 } 967 break; 968 } 969 } 970 } 971 972 /** 973 * [Describe function...] 974 * 975 * @return [type] ... 976 */ 977 function extractHyperLinks() { 978 // extracts all hyper-links from $this->theParts["html"]["content"] 979 $html_code = $this->theParts["html"]["content"]; 980 $attribRegex = $this->tag_regex(Array("a","form","area")); 981 $codepieces = split($attribRegex, $html_code); // Splits the document by the beginning of the above tags 982 $len=strlen($codepieces[0]); 983 $pieces = count($codepieces); 984 for($i=1; $i < $pieces; $i++) { 985 $tag = strtolower(strtok(substr($html_code,$len+1,10)," ")); 986 $len+=strlen($tag)+strlen($codepieces[$i])+2; 987 988 $dummy = eregi("[^>]*", $codepieces[$i], $reg); 989 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag 990 $hrefData=""; 991 if ($attributes["href"]) {$hrefData["ref"]=$attributes["href"];} else {$hrefData["ref"]=$attributes["action"];} 992 if ($hrefData["ref"]) { 993 $hrefData["quotes"]=(substr($codepieces[$i],strpos($codepieces[$i], $hrefData["ref"])-1,1)=='"')?'"':''; // Finds out if the value had quotes around it 994 $hrefData["subst_str"] = $hrefData["quotes"].$hrefData["ref"].$hrefData["quotes"]; // subst_str is the string to look for, when substituting lateron 995 if ($hrefData["ref"] && substr(trim($hrefData["ref"]),0,1)!="#" && !strstr($this->href_fullpath_list,"|".$hrefData["subst_str"]."|")) { 996 $this->href_fullpath_list.="|".$hrefData["subst_str"]."|"; 997 $hrefData["absRef"] = $this->absRef($hrefData["ref"]); 998 $hrefData["tag"]=$tag; 999 $this->theParts["html"]["hrefs"][]=$hrefData; 1000 } 1001 } 1002 } 1003 // Extracts TYPO3 specific links made by the openPic() JS function 1004 $codepieces = explode("onClick=\"openPic('", $html_code); 1005 $pieces = count($codepieces); 1006 for($i=1; $i < $pieces; $i++) { 1007 $showpic_linkArr = explode("'",$codepieces[$i]); 1008 $hrefData["ref"]=$showpic_linkArr[0]; 1009 if ($hrefData["ref"]) { 1010 $hrefData["quotes"]="'"; // Finds out if the value had quotes around it 1011 $hrefData["subst_str"] = $hrefData["quotes"].$hrefData["ref"].$hrefData["quotes"]; // subst_str is the string to look for, when substituting lateron 1012 if ($hrefData["ref"] && !strstr($this->href_fullpath_list,"|".$hrefData["subst_str"]."|")) { 1013 $this->href_fullpath_list.="|".$hrefData["subst_str"]."|"; 1014 $hrefData["absRef"] = $this->absRef($hrefData["ref"]); 1015 $this->theParts["html"]["hrefs"][]=$hrefData; 1016 } 1017 } 1018 } 1019 } 1020 1021 /** 1022 * [Describe function...] 1023 * 1024 * @return [type] ... 1025 */ 1026 function extractFramesInfo() { 1027 // extracts all media-links from $this->theParts["html"]["content"] 1028 $html_code = $this->theParts["html"]["content"]; 1029 if (strpos(" ".$html_code,"<frame ")) { 1030 $attribRegex = $this->tag_regex("frame"); 1031 $codepieces = split($attribRegex, $html_code, 1000000 ); // Splits the document by the beginning of the above tags 1032 $pieces = count($codepieces); 1033 for($i=1; $i < $pieces; $i++) { 1034 $dummy = eregi("[^>]*", $codepieces[$i], $reg); 1035 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag 1036 $frame=""; 1037 $frame["src"]=$attributes["src"]; 1038 $frame["name"]=$attributes["name"]; 1039 $frame["absRef"] = $this->absRef($frame["src"]); 1040 $theInfo[] = $frame; 1041 } 1042 return $theInfo; 1043 } 1044 } 1045 1046 /** 1047 * [Describe function...] 1048 * 1049 * @param [type] $absolute: ... 1050 * @return [type] ... 1051 */ 1052 function substMediaNamesInHTML($absolute) { 1053 // This substitutes the media-references in $this->theParts["html"]["content"] 1054 // If $absolute is true, then the refs are substituted with http:// ref's indstead of Content-ID's (cid). 1055 if (is_array($this->theParts["html"]["media"])) { 1056 reset ($this->theParts["html"]["media"]); 1057 while (list($key,$val) = each ($this->theParts["html"]["media"])) { 1058 if ($val["use_jumpurl"] && $this->jumperURL_prefix) { 1059 $theSubstVal = $this->jumperURL_prefix.t3lib_div::rawUrlEncodeFP($val['absRef']); 1060 } else { 1061 $theSubstVal = ($absolute) ? $val["absRef"] : "cid:part".$key.".".$this->messageid; 1062 } 1063 $this->theParts["html"]["content"] = str_replace( 1064 $val["subst_str"], 1065 $val["quotes"].$theSubstVal.$val["quotes"], 1066 $this->theParts["html"]["content"] ); 1067 } 1068 } 1069 if (!$absolute) { 1070 $this->fixRollOvers(); 1071 } 1072 } 1073 1074 /** 1075 * [Describe function...] 1076 * 1077 * @return [type] ... 1078 */ 1079 function substHREFsInHTML() { 1080 // This substitutes the hrefs in $this->theParts["html"]["content"] 1081 if (is_array($this->theParts["html"]["hrefs"])) { 1082 reset ($this->theParts["html"]["hrefs"]); 1083 while (list($key,$val) = each ($this->theParts["html"]["hrefs"])) { 1084 if ($this->jumperURL_prefix && $val["tag"]!="form") { // Form elements cannot use jumpurl! 1085 if ($this->jumperURL_useId) { 1086 $theSubstVal = $this->jumperURL_prefix.$key; 1087 } else { 1088 $theSubstVal = $this->jumperURL_prefix.t3lib_div::rawUrlEncodeFP($val['absRef']); 1089 } 1090 } else { 1091 $theSubstVal = $val["absRef"]; 1092 } 1093 $this->theParts["html"]["content"] = str_replace( 1094 $val["subst_str"], 1095 $val["quotes"].$theSubstVal.$val["quotes"], 1096 $this->theParts["html"]["content"] ); 1097 } 1098 } 1099 } 1100 1101 /** 1102 * [Describe function...] 1103 * 1104 * @param [type] $content: ... 1105 * @return [type] ... 1106 */ 1107 function substHTTPurlsInPlainText($content) { 1108 // This substitutes the http:// urls in plain text with links 1109 if ($this->jumperURL_prefix) { 1110 $textpieces = explode("http://", $content); 1111 $pieces = count($textpieces); 1112 $textstr = $textpieces[0]; 1113 for($i=1; $i<$pieces; $i++) { 1114 $len=strcspn($textpieces[$i],chr(32).chr(9).chr(13).chr(10)); 1115 if (trim(substr($textstr,-1))=="" && $len) { 1116 $lastChar=substr($textpieces[$i],$len-1,1); 1117 if (!ereg("[A-Za-z0-9\/#]",$lastChar)) {$len--;} // Included "\/" 3/12 1118 1119 $parts[0]="http://".substr($textpieces[$i],0,$len); 1120 $parts[1]=substr($textpieces[$i],$len); 1121 1122 if ($this->jumperURL_useId) { 1123 $this->theParts["plain"]["link_ids"][$i]=$parts[0]; 1124 $parts[0] = $this->jumperURL_prefix."-".$i; 1125 } else { 1126 $parts[0] = $this->jumperURL_prefix.t3lib_div::rawUrlEncodeFP($parts[0]); 1127 } 1128 $textstr.=$parts[0].$parts[1]; 1129 } else { 1130 $textstr.='http://'.$textpieces[$i]; 1131 } 1132 } 1133 $content = $textstr; 1134 } 1135 return $content; 1136 } 1137 1138 /** 1139 * [Describe function...] 1140 * 1141 * @return [type] ... 1142 */ 1143 function fixRollOvers() { 1144 // JavaScript rollOvers cannot support graphics inside of mail. If these exists we must let them refer to the absolute url. By the way: Roll-overs seems to work only on some mail-readers and so far I've seen it work on Netscape 4 message-center (but not 4.5!!) 1145 $theNewContent = ""; 1146 $theSplit = explode(".src",$this->theParts["html"]["content"]); 1147 if (count($theSplit)>1) { 1148 while(list($key,$part)=each($theSplit)) { 1149 $sub = substr($part,0,200); 1150 if (ereg("cid:part[^ \"']*",$sub,$reg)) { 1151 $thePos = strpos($part,$reg[0]); // The position of the string 1152 ereg("cid:part([^\.]*).*",$sub,$reg2); // Finds the id of the media... 1153 $theSubStr = $this->theParts["html"]["media"][intval($reg2[1])]["absRef"]; 1154 if ($thePos && $theSubStr) { // ... and substitutes the javaScript rollover image with this instead 1155 if (!strpos(" ".$theSubStr,"http://")) {$theSubStr = "http://";} // If the path is NOT and url, the reference is set to nothing 1156 $part = substr($part,0,$thePos).$theSubStr.substr($part,$thePos+strlen($reg[0]),strlen($part)); 1157 } 1158 } 1159 $theNewContent.= $part.((($key+1)!=count($theSplit))? ".src" : "" ); 1160 } 1161 $this->theParts["html"]["content"]=$theNewContent; 1162 } 1163 } 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 /******************************************* 1181 * 1182 * File and URL-functions 1183 * 1184 *******************************************/ 1185 1186 /** 1187 * @param [type] $inputstr: ... 1188 * @return [type] ... 1189 */ 1190 function makeBase64($inputstr) { 1191 // Returns base64-encoded content, which is broken every 76 character 1192 return chunk_split(base64_encode($inputstr)); 1193 } 1194 1195 /** 1196 * [Describe function...] 1197 * 1198 * @param [type] $url: ... 1199 * @return [type] ... 1200 */ 1201 function getExtendedURL($url) { 1202 // reads the URL or file and determines the Content-type by either guessing or opening a connection to the host 1203 $res["content"] = $this->getURL($url); 1204 if (!$res["content"]) {return false;} 1205 $pathInfo = parse_url($url); 1206 $fileInfo = $this->split_fileref($pathInfo["path"]); 1207 if ($fileInfo["fileext"] == "gif") {$res["content_type"] = "image/gif";} 1208 if ($fileInfo["fileext"] == "jpg" || $fileInfo["fileext"] == "jpeg") {$res["content_type"] = "image/jpeg";} 1209 if ($fileInfo['fileext'] == 'png') {$res['content_type'] = 'image/png';} 1210 if ($fileInfo["fileext"] == "html" || $fileInfo["fileext"] == "htm") {$res["content_type"] = "text/html";} 1211 if ($fileInfo['fileext'] == 'css') {$res['content_type'] = 'text/css';} 1212 if ($fileInfo["fileext"] == "swf") {$res["content_type"] = "application/x-shockwave-flash";} 1213 if (!$res["content_type"]) {$res["content_type"] = $this->getMimeType($url);} 1214 return $res; 1215 } 1216 1217 /** 1218 * [Describe function...] 1219 * 1220 * @param [type] $url: ... 1221 * @return [type] ... 1222 */ 1223 function addUserPass($url) { 1224 $user=$this->http_username; 1225 $pass=$this->http_password; 1226 $matches = array(); 1227 if ($user && $pass && preg_match('/^(https?:\/\/)/', $url, $matches)) { 1228 $url = $matches[1].$user.':'.$pass.'@'.substr($url,strlen($matches[1])); 1229 } 1230 return $url; 1231 } 1232 1233 /** 1234 * [Describe function...] 1235 * 1236 * @param [type] $url: ... 1237 * @return [type] ... 1238 */ 1239 function getURL($url) { 1240 $url = $this->addUserPass($url); 1241 // reads a url or file 1242 return t3lib_div::getURL($url); 1243 } 1244 1245 /** 1246 * [Describe function...] 1247 * 1248 * @param [type] $url: ... 1249 * @return [type] ... 1250 */ 1251 function getStrippedURL($url) { 1252 // reads a url or file and strips the HTML-tags AND removes all empty lines. This is used to read plain-text out of a HTML-page 1253 if($fd = fopen($url,"rb")) { 1254 $content = ""; 1255 while (!feof($fd)) { 1256 $line = fgetss($fd, 5000); 1257 if (trim($line)) { 1258 $content.=trim($line)."\n"; 1259 } 1260 } 1261 fclose( $fd ); 1262 return $content; 1263 } 1264 } 1265 1266 /** 1267 * This function returns the mime type of the file specified by the url 1268 * 1269 * @param string $url: the url 1270 * @return string $mimeType: the mime type found in the header 1271 */ 1272 function getMimeType($url) { 1273 $mimeType = ''; 1274 $headers = trim(t3lib_div::getURL($url, 2)); 1275 if ($headers) { 1276 $matches = array(); 1277 if (preg_match('/(Content-Type:[\s]*)([a-zA-Z_0-9\/\-\.\+]*)([\s]|$)/', $headers, $matches)) { 1278 $mimeType = trim($matches[2]); 1279 } 1280 } 1281 return $mimeType; 1282 } 1283 1284 /** 1285 * [Describe function...] 1286 * 1287 * @param [type] $ref: ... 1288 * @return [type] ... 1289 */ 1290 function absRef($ref) { 1291 // Returns the absolute address of a link. This is based on $this->theParts["html"]["path"] being the root-address 1292 $ref = trim($ref); 1293 $urlINFO = parse_url($ref); 1294 if ($urlINFO["scheme"]) { 1295 return $ref; 1296 } elseif (eregi("^/",$ref)){ 1297 $addr = parse_url($this->theParts["html"]["path"]); 1298 return $addr['scheme'].'://'.$addr['host'].($addr['port']?':'.$addr['port']:'').$ref; 1299 } else { 1300 return $this->theParts["html"]["path"].$ref; // If the reference is relative, the path is added, in order for us to fetch the content 1301 } 1302 } 1303 1304 /** 1305 * [Describe function...] 1306 * 1307 * @param [type] $fileref: ... 1308 * @return [type] ... 1309 */ 1310 function split_fileref($fileref) { 1311 // Returns an array with path, filename, filebody, fileext. 1312 if ( ereg("(.*/)(.*)$",$fileref,$reg) ) { 1313 $info["path"] = $reg[1]; 1314 $info["file"] = $reg[2]; 1315 } else { 1316 $info["path"] = ""; 1317 $info["file"] = $fileref; 1318 } 1319 $reg=""; 1320 if ( ereg("(.*)\.([^\.]*$)",$info["file"],$reg) ) { 1321 $info["filebody"] = $reg[1]; 1322 $info["fileext"] = strtolower($reg[2]); 1323 $info["realFileext"] = $reg[2]; 1324 } else { 1325 $info["filebody"] = $info["file"]; 1326 $info["fileext"] = ""; 1327 } 1328 return $info; 1329 } 1330 1331 /** 1332 * [Describe function...] 1333 * 1334 * @param [type] $path: ... 1335 * @return [type] ... 1336 */ 1337 function extParseUrl($path) { 1338 // Returns an array with file or url-information 1339 $res = parse_url($path); 1340 ereg("(.*/)([^/]*)$",$res["path"],$reg); 1341 $res["filepath"]=$reg[1]; 1342 $res["filename"]=$reg[2]; 1343 return $res; 1344 } 1345 1346 /** 1347 * [Describe function...] 1348 * 1349 * @param [type] $tagArray: ... 1350 * @return [type] ... 1351 */ 1352 function tag_regex($tagArray) { 1353 if (!is_array($tagArray)) { 1354 $tagArray=Array($tagArray); 1355 } 1356 $theRegex = ""; 1357 $c=count($tagArray); 1358 while(list(,$tag)=each($tagArray)) { 1359 $c--; 1360 $theRegex.="<".sql_regcase($tag)."[[:space:]]".(($c)?"|":""); 1361 } 1362 return $theRegex; 1363 } 1364 1365 /** 1366 * analyses a HTML-tag 1367 * $tag is either like this "<TAG OPTION ATTRIB=VALUE>" or this " OPTION ATTRIB=VALUE>" which means you can omit the tag-name 1368 * returns an array with the attributes as keys in lower-case 1369 * If an attribute is empty (like OPTION) the value of that key is just empty. Check it with is_set(); 1370 * 1371 * @param [type] $tag: ... 1372 * @return [type] ... 1373 */ 1374 function get_tag_attributes($tag) { 1375 $attributes = Array(); 1376 $tag = ltrim(eregi_replace ("^<[^ ]*","",trim($tag))); 1377 $tagLen = strlen($tag); 1378 $safetyCounter = 100; 1379 // Find attribute 1380 while ($tag) { 1381 $value = ""; 1382 $reg = split("[[:space:]=>]",$tag,2); 1383 $attrib = $reg[0]; 1384 1385 $tag = ltrim(substr($tag,strlen($attrib),$tagLen)); 1386 if (substr($tag,0,1)=="=") { 1387 $tag = ltrim(substr($tag,1,$tagLen)); 1388 if (substr($tag,0,1)=='"') { // Quotes around the value 1389 $reg = explode('"',substr($tag,1,$tagLen),2); 1390 $tag = ltrim($reg[1]); 1391 $value = $reg[0]; 1392 } else { // No qoutes around value 1393 ereg("^([^[:space:]>]*)(.*)",$tag,$reg); 1394 $value = trim($reg[1]); 1395 $tag = ltrim($reg[2]); 1396 if (substr($tag,0,1)==">") { 1397 $tag =""; 1398 } 1399 } 1400 } 1401 $attributes[strtolower($attrib)]=$value; 1402 $safetyCounter--; 1403 if ($safetyCounter<0) {break;} 1404 } 1405 return $attributes; 1406 } 1407 1408 /** 1409 * Implementation of quoted-printable encode. 1410 * This function was a duplicate of t3lib_div::quoted_printable, thus it's going to be removed. 1411 * 1412 * @param string Content to encode 1413 * @return string The QP encoded string 1414 * @obsolete 1415 */ 1416 function quoted_printable($string) { 1417 return t3lib_div::quoted_printable($string, 76); 1418 } 1419 1420 /** 1421 * [Describe function...] 1422 * 1423 * @param [type] $name: ... 1424 * @return [type] ... 1425 * @deprecated 1426 */ 1427 function convertName($name) { 1428 return $name; 1429 } 1430 } 1431 1432 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_htmlmail.php']) { 1433 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_htmlmail.php']); 1434 } 1435 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Nov 25 17:13:16 2007 | par Balluche grâce à PHPXref 0.7 |
|