@@ -892,6 +892,7 @@ discard block |
||
| 892 | 892 | /** |
| 893 | 893 | * Creates recipient headers. |
| 894 | 894 | * @access public |
| 895 | + * @param string $type |
|
| 895 | 896 | * @return string |
| 896 | 897 | */ |
| 897 | 898 | public function AddrAppend($type, $addr) { |
@@ -1259,6 +1260,9 @@ discard block |
||
| 1259 | 1260 | /** |
| 1260 | 1261 | * Returns the start of a message boundary. |
| 1261 | 1262 | * @access private |
| 1263 | + * @param string $charSet |
|
| 1264 | + * @param string $contentType |
|
| 1265 | + * @param string $encoding |
|
| 1262 | 1266 | */ |
| 1263 | 1267 | private function GetBoundary($boundary, $charSet, $contentType, $encoding) { |
| 1264 | 1268 | $result = ''; |
@@ -1312,6 +1316,7 @@ discard block |
||
| 1312 | 1316 | /** |
| 1313 | 1317 | * Returns a formatted header line. |
| 1314 | 1318 | * @access public |
| 1319 | + * @param string $name |
|
| 1315 | 1320 | * @return string |
| 1316 | 1321 | */ |
| 1317 | 1322 | public function HeaderLine($name, $value) { |
@@ -1321,6 +1326,7 @@ discard block |
||
| 1321 | 1326 | /** |
| 1322 | 1327 | * Returns a formatted mail line. |
| 1323 | 1328 | * @access public |
| 1329 | + * @param string $value |
|
| 1324 | 1330 | * @return string |
| 1325 | 1331 | */ |
| 1326 | 1332 | public function TextLine($value) { |
@@ -1517,6 +1523,7 @@ discard block |
||
| 1517 | 1523 | /** |
| 1518 | 1524 | * Encode a header string to best (shortest) of Q, B, quoted or none. |
| 1519 | 1525 | * @access public |
| 1526 | + * @param string $str |
|
| 1520 | 1527 | * @return string |
| 1521 | 1528 | */ |
| 1522 | 1529 | public function EncodeHeader ($str, $position = 'text') { |
@@ -1902,6 +1909,7 @@ discard block |
||
| 1902 | 1909 | /** |
| 1903 | 1910 | * Adds the error message to the error container. |
| 1904 | 1911 | * @access protected |
| 1912 | + * @param string $msg |
|
| 1905 | 1913 | * @return void |
| 1906 | 1914 | */ |
| 1907 | 1915 | protected function SetError($msg) { |
@@ -1951,6 +1959,7 @@ discard block |
||
| 1951 | 1959 | /** |
| 1952 | 1960 | * Returns a message in the appropriate language. |
| 1953 | 1961 | * @access private |
| 1962 | + * @param string $key |
|
| 1954 | 1963 | * @return string |
| 1955 | 1964 | */ |
| 1956 | 1965 | private function Lang($key) { |
@@ -1998,6 +2007,7 @@ discard block |
||
| 1998 | 2007 | /** |
| 1999 | 2008 | * Evaluates the message and returns modifications for inline images and backgrounds |
| 2000 | 2009 | * @access public |
| 2010 | + * @param string $message |
|
| 2001 | 2011 | * @return $message |
| 2002 | 2012 | */ |
| 2003 | 2013 | public function MsgHTML($message,$basedir='') { |
@@ -38,7 +38,9 @@ discard block |
||
| 38 | 38 | * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
| 39 | 39 | */ |
| 40 | 40 | |
| 41 | -if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n"); |
|
| 41 | +if (version_compare(PHP_VERSION, '5.0.0', '<') ) { |
|
| 42 | + exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n"); |
|
| 43 | +} |
|
| 42 | 44 | |
| 43 | 45 | class PHPMailer { |
| 44 | 46 | |
@@ -1498,8 +1500,9 @@ discard block |
||
| 1498 | 1500 | case '8bit': |
| 1499 | 1501 | $encoded = $this->FixEOL($str); |
| 1500 | 1502 | //Make sure it ends with a line break |
| 1501 | - if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
|
| 1502 | - $encoded .= $this->LE; |
|
| 1503 | + if (substr($encoded, -(strlen($this->LE))) != $this->LE) { |
|
| 1504 | + $encoded .= $this->LE; |
|
| 1505 | + } |
|
| 1503 | 1506 | break; |
| 1504 | 1507 | case 'binary': |
| 1505 | 1508 | $encoded = $str; |
@@ -2249,7 +2252,9 @@ discard block |
||
| 2249 | 2252 | * @param string $body Message Body |
| 2250 | 2253 | */ |
| 2251 | 2254 | public function DKIM_BodyC($body) { |
| 2252 | - if ($body == '') return "\r\n"; |
|
| 2255 | + if ($body == '') { |
|
| 2256 | + return "\r\n"; |
|
| 2257 | + } |
|
| 2253 | 2258 | // stabilize line endings |
| 2254 | 2259 | $body=str_replace("\r\n","\n",$body); |
| 2255 | 2260 | $body=str_replace("\n","\r\n",$body); |
@@ -251,9 +251,9 @@ discard block |
||
| 251 | 251 | public $SingleToArray = array(); |
| 252 | 252 | |
| 253 | 253 | /** |
| 254 | - * Provides the ability to change the line ending |
|
| 255 | - * @var string |
|
| 256 | - */ |
|
| 254 | + * Provides the ability to change the line ending |
|
| 255 | + * @var string |
|
| 256 | + */ |
|
| 257 | 257 | public $LE = "\n"; |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | * @param boolean $exceptions Should we throw external exceptions? |
| 341 | 341 | */ |
| 342 | 342 | public function __construct($exceptions = false) { |
| 343 | - $this->exceptions = ($exceptions == true); |
|
| 343 | + $this->exceptions = ($exceptions == true); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | /** |
@@ -349,11 +349,11 @@ discard block |
||
| 349 | 349 | * @return void |
| 350 | 350 | */ |
| 351 | 351 | public function IsHTML($ishtml = true) { |
| 352 | - if ($ishtml) { |
|
| 353 | - $this->ContentType = 'text/html'; |
|
| 354 | - } else { |
|
| 355 | - $this->ContentType = 'text/plain'; |
|
| 356 | - } |
|
| 352 | + if ($ishtml) { |
|
| 353 | + $this->ContentType = 'text/html'; |
|
| 354 | + } else { |
|
| 355 | + $this->ContentType = 'text/plain'; |
|
| 356 | + } |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | * @return void |
| 362 | 362 | */ |
| 363 | 363 | public function IsSMTP() { |
| 364 | - $this->Mailer = 'smtp'; |
|
| 364 | + $this->Mailer = 'smtp'; |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | * @return void |
| 370 | 370 | */ |
| 371 | 371 | public function IsMail() { |
| 372 | - $this->Mailer = 'mail'; |
|
| 372 | + $this->Mailer = 'mail'; |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -377,10 +377,10 @@ discard block |
||
| 377 | 377 | * @return void |
| 378 | 378 | */ |
| 379 | 379 | public function IsSendmail() { |
| 380 | - if (!stristr(ini_get('sendmail_path'), 'sendmail')) { |
|
| 381 | - $this->Sendmail = '/var/qmail/bin/sendmail'; |
|
| 382 | - } |
|
| 383 | - $this->Mailer = 'sendmail'; |
|
| 380 | + if (!stristr(ini_get('sendmail_path'), 'sendmail')) { |
|
| 381 | + $this->Sendmail = '/var/qmail/bin/sendmail'; |
|
| 382 | + } |
|
| 383 | + $this->Mailer = 'sendmail'; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -388,10 +388,10 @@ discard block |
||
| 388 | 388 | * @return void |
| 389 | 389 | */ |
| 390 | 390 | public function IsQmail() { |
| 391 | - if (stristr(ini_get('sendmail_path'), 'qmail')) { |
|
| 392 | - $this->Sendmail = '/var/qmail/bin/sendmail'; |
|
| 393 | - } |
|
| 394 | - $this->Mailer = 'sendmail'; |
|
| 391 | + if (stristr(ini_get('sendmail_path'), 'qmail')) { |
|
| 392 | + $this->Sendmail = '/var/qmail/bin/sendmail'; |
|
| 393 | + } |
|
| 394 | + $this->Mailer = 'sendmail'; |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | ///////////////////////////////////////////////// |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | * @return boolean true on success, false if address already used |
| 406 | 406 | */ |
| 407 | 407 | public function AddAddress($address, $name = '') { |
| 408 | - return $this->AddAnAddress('to', $address, $name); |
|
| 408 | + return $this->AddAnAddress('to', $address, $name); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @return boolean true on success, false if address already used |
| 417 | 417 | */ |
| 418 | 418 | public function AddCC($address, $name = '') { |
| 419 | - return $this->AddAnAddress('cc', $address, $name); |
|
| 419 | + return $this->AddAnAddress('cc', $address, $name); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | * @return boolean true on success, false if address already used |
| 428 | 428 | */ |
| 429 | 429 | public function AddBCC($address, $name = '') { |
| 430 | - return $this->AddAnAddress('bcc', $address, $name); |
|
| 430 | + return $this->AddAnAddress('bcc', $address, $name); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | * @return boolean |
| 438 | 438 | */ |
| 439 | 439 | public function AddReplyTo($address, $name = '') { |
| 440 | - return $this->AddAnAddress('ReplyTo', $address, $name); |
|
| 440 | + return $this->AddAnAddress('ReplyTo', $address, $name); |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | /** |
@@ -450,31 +450,31 @@ discard block |
||
| 450 | 450 | * @access private |
| 451 | 451 | */ |
| 452 | 452 | private function AddAnAddress($kind, $address, $name = '') { |
| 453 | - if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) { |
|
| 454 | - echo 'Invalid recipient array: ' . kind; |
|
| 455 | - return false; |
|
| 456 | - } |
|
| 457 | - $address = trim($address); |
|
| 458 | - $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim |
|
| 459 | - if (!self::ValidateAddress($address)) { |
|
| 460 | - $this->SetError($this->Lang('invalid_address').': '. $address); |
|
| 461 | - if ($this->exceptions) { |
|
| 462 | - throw new phpmailerException($this->Lang('invalid_address').': '.$address); |
|
| 463 | - } |
|
| 464 | - echo $this->Lang('invalid_address').': '.$address; |
|
| 465 | - return false; |
|
| 466 | - } |
|
| 467 | - if ($kind != 'ReplyTo') { |
|
| 468 | - if (!isset($this->all_recipients[strtolower($address)])) { |
|
| 469 | - array_push($this->$kind, array($address, $name)); |
|
| 470 | - $this->all_recipients[strtolower($address)] = true; |
|
| 471 | - return true; |
|
| 472 | - } |
|
| 473 | - } else { |
|
| 474 | - if (!array_key_exists(strtolower($address), $this->ReplyTo)) { |
|
| 475 | - $this->ReplyTo[strtolower($address)] = array($address, $name); |
|
| 476 | - return true; |
|
| 477 | - } |
|
| 453 | + if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) { |
|
| 454 | + echo 'Invalid recipient array: ' . kind; |
|
| 455 | + return false; |
|
| 456 | + } |
|
| 457 | + $address = trim($address); |
|
| 458 | + $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim |
|
| 459 | + if (!self::ValidateAddress($address)) { |
|
| 460 | + $this->SetError($this->Lang('invalid_address').': '. $address); |
|
| 461 | + if ($this->exceptions) { |
|
| 462 | + throw new phpmailerException($this->Lang('invalid_address').': '.$address); |
|
| 463 | + } |
|
| 464 | + echo $this->Lang('invalid_address').': '.$address; |
|
| 465 | + return false; |
|
| 466 | + } |
|
| 467 | + if ($kind != 'ReplyTo') { |
|
| 468 | + if (!isset($this->all_recipients[strtolower($address)])) { |
|
| 469 | + array_push($this->$kind, array($address, $name)); |
|
| 470 | + $this->all_recipients[strtolower($address)] = true; |
|
| 471 | + return true; |
|
| 472 | + } |
|
| 473 | + } else { |
|
| 474 | + if (!array_key_exists(strtolower($address), $this->ReplyTo)) { |
|
| 475 | + $this->ReplyTo[strtolower($address)] = array($address, $name); |
|
| 476 | + return true; |
|
| 477 | + } |
|
| 478 | 478 | } |
| 479 | 479 | return false; |
| 480 | 480 | } |
@@ -486,27 +486,27 @@ discard block |
||
| 486 | 486 | * @return boolean |
| 487 | 487 | */ |
| 488 | 488 | public function SetFrom($address, $name = '',$auto=1) { |
| 489 | - $address = trim($address); |
|
| 490 | - $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim |
|
| 491 | - if (!self::ValidateAddress($address)) { |
|
| 492 | - $this->SetError($this->Lang('invalid_address').': '. $address); |
|
| 493 | - if ($this->exceptions) { |
|
| 494 | - throw new phpmailerException($this->Lang('invalid_address').': '.$address); |
|
| 495 | - } |
|
| 496 | - echo $this->Lang('invalid_address').': '.$address; |
|
| 497 | - return false; |
|
| 498 | - } |
|
| 499 | - $this->From = $address; |
|
| 500 | - $this->FromName = $name; |
|
| 501 | - if ($auto) { |
|
| 502 | - if (empty($this->ReplyTo)) { |
|
| 503 | - $this->AddAnAddress('ReplyTo', $address, $name); |
|
| 504 | - } |
|
| 505 | - if (empty($this->Sender)) { |
|
| 506 | - $this->Sender = $address; |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - return true; |
|
| 489 | + $address = trim($address); |
|
| 490 | + $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim |
|
| 491 | + if (!self::ValidateAddress($address)) { |
|
| 492 | + $this->SetError($this->Lang('invalid_address').': '. $address); |
|
| 493 | + if ($this->exceptions) { |
|
| 494 | + throw new phpmailerException($this->Lang('invalid_address').': '.$address); |
|
| 495 | + } |
|
| 496 | + echo $this->Lang('invalid_address').': '.$address; |
|
| 497 | + return false; |
|
| 498 | + } |
|
| 499 | + $this->From = $address; |
|
| 500 | + $this->FromName = $name; |
|
| 501 | + if ($auto) { |
|
| 502 | + if (empty($this->ReplyTo)) { |
|
| 503 | + $this->AddAnAddress('ReplyTo', $address, $name); |
|
| 504 | + } |
|
| 505 | + if (empty($this->Sender)) { |
|
| 506 | + $this->Sender = $address; |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + return true; |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
@@ -521,15 +521,15 @@ discard block |
||
| 521 | 521 | * @access public |
| 522 | 522 | */ |
| 523 | 523 | public static function ValidateAddress($address) { |
| 524 | - if (function_exists('filter_var')) { //Introduced in PHP 5.2 |
|
| 525 | - if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) { |
|
| 526 | - return false; |
|
| 527 | - } else { |
|
| 528 | - return true; |
|
| 529 | - } |
|
| 530 | - } else { |
|
| 531 | - return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address); |
|
| 532 | - } |
|
| 524 | + if (function_exists('filter_var')) { //Introduced in PHP 5.2 |
|
| 525 | + if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) { |
|
| 526 | + return false; |
|
| 527 | + } else { |
|
| 528 | + return true; |
|
| 529 | + } |
|
| 530 | + } else { |
|
| 531 | + return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address); |
|
| 532 | + } |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | ///////////////////////////////////////////////// |
@@ -543,49 +543,49 @@ discard block |
||
| 543 | 543 | * @return bool |
| 544 | 544 | */ |
| 545 | 545 | public function Send() { |
| 546 | - try { |
|
| 547 | - if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
|
| 548 | - throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - // Set whether the message is multipart/alternative |
|
| 552 | - if(!empty($this->AltBody)) { |
|
| 553 | - $this->ContentType = 'multipart/alternative'; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - $this->error_count = 0; // reset errors |
|
| 557 | - $this->SetMessageType(); |
|
| 558 | - $header = $this->CreateHeader(); |
|
| 559 | - $body = $this->CreateBody(); |
|
| 560 | - |
|
| 561 | - if (empty($this->Body)) { |
|
| 562 | - throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - // digitally sign with DKIM if enabled |
|
| 566 | - if ($this->DKIM_domain && $this->DKIM_private) { |
|
| 567 | - $header_dkim = $this->DKIM_Add($header,$this->Subject,$body); |
|
| 568 | - $header = str_replace("\r\n","\n",$header_dkim) . $header; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - // Choose the mailer and send through it |
|
| 572 | - switch($this->Mailer) { |
|
| 573 | - case 'sendmail': |
|
| 574 | - return $this->SendmailSend($header, $body); |
|
| 575 | - case 'smtp': |
|
| 576 | - return $this->SmtpSend($header, $body); |
|
| 577 | - default: |
|
| 578 | - return $this->MailSend($header, $body); |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - } catch (phpmailerException $e) { |
|
| 582 | - $this->SetError($e->getMessage()); |
|
| 583 | - if ($this->exceptions) { |
|
| 584 | - throw $e; |
|
| 585 | - } |
|
| 586 | - echo $e->getMessage()."\n"; |
|
| 587 | - return false; |
|
| 588 | - } |
|
| 546 | + try { |
|
| 547 | + if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
|
| 548 | + throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + // Set whether the message is multipart/alternative |
|
| 552 | + if(!empty($this->AltBody)) { |
|
| 553 | + $this->ContentType = 'multipart/alternative'; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + $this->error_count = 0; // reset errors |
|
| 557 | + $this->SetMessageType(); |
|
| 558 | + $header = $this->CreateHeader(); |
|
| 559 | + $body = $this->CreateBody(); |
|
| 560 | + |
|
| 561 | + if (empty($this->Body)) { |
|
| 562 | + throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + // digitally sign with DKIM if enabled |
|
| 566 | + if ($this->DKIM_domain && $this->DKIM_private) { |
|
| 567 | + $header_dkim = $this->DKIM_Add($header,$this->Subject,$body); |
|
| 568 | + $header = str_replace("\r\n","\n",$header_dkim) . $header; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + // Choose the mailer and send through it |
|
| 572 | + switch($this->Mailer) { |
|
| 573 | + case 'sendmail': |
|
| 574 | + return $this->SendmailSend($header, $body); |
|
| 575 | + case 'smtp': |
|
| 576 | + return $this->SmtpSend($header, $body); |
|
| 577 | + default: |
|
| 578 | + return $this->MailSend($header, $body); |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + } catch (phpmailerException $e) { |
|
| 582 | + $this->SetError($e->getMessage()); |
|
| 583 | + if ($this->exceptions) { |
|
| 584 | + throw $e; |
|
| 585 | + } |
|
| 586 | + echo $e->getMessage()."\n"; |
|
| 587 | + return false; |
|
| 588 | + } |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | /** |
@@ -596,42 +596,42 @@ discard block |
||
| 596 | 596 | * @return bool |
| 597 | 597 | */ |
| 598 | 598 | protected function SendmailSend($header, $body) { |
| 599 | - if ($this->Sender != '') { |
|
| 600 | - $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender)); |
|
| 601 | - } else { |
|
| 602 | - $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); |
|
| 603 | - } |
|
| 604 | - if ($this->SingleTo === true) { |
|
| 605 | - foreach ($this->SingleToArray as $key => $val) { |
|
| 606 | - if(!@$mail = popen($sendmail, 'w')) { |
|
| 607 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 608 | - } |
|
| 609 | - fputs($mail, "To: " . $val . "\n"); |
|
| 610 | - fputs($mail, $header); |
|
| 611 | - fputs($mail, $body); |
|
| 612 | - $result = pclose($mail); |
|
| 613 | - // implement call back function if it exists |
|
| 614 | - $isSent = ($result == 0) ? 1 : 0; |
|
| 615 | - $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 616 | - if($result != 0) { |
|
| 617 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - } else { |
|
| 621 | - if(!@$mail = popen($sendmail, 'w')) { |
|
| 622 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 623 | - } |
|
| 624 | - fputs($mail, $header); |
|
| 625 | - fputs($mail, $body); |
|
| 626 | - $result = pclose($mail); |
|
| 627 | - // implement call back function if it exists |
|
| 628 | - $isSent = ($result == 0) ? 1 : 0; |
|
| 629 | - $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 630 | - if($result != 0) { |
|
| 631 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - return true; |
|
| 599 | + if ($this->Sender != '') { |
|
| 600 | + $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender)); |
|
| 601 | + } else { |
|
| 602 | + $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); |
|
| 603 | + } |
|
| 604 | + if ($this->SingleTo === true) { |
|
| 605 | + foreach ($this->SingleToArray as $key => $val) { |
|
| 606 | + if(!@$mail = popen($sendmail, 'w')) { |
|
| 607 | + throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 608 | + } |
|
| 609 | + fputs($mail, "To: " . $val . "\n"); |
|
| 610 | + fputs($mail, $header); |
|
| 611 | + fputs($mail, $body); |
|
| 612 | + $result = pclose($mail); |
|
| 613 | + // implement call back function if it exists |
|
| 614 | + $isSent = ($result == 0) ? 1 : 0; |
|
| 615 | + $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 616 | + if($result != 0) { |
|
| 617 | + throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + } else { |
|
| 621 | + if(!@$mail = popen($sendmail, 'w')) { |
|
| 622 | + throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 623 | + } |
|
| 624 | + fputs($mail, $header); |
|
| 625 | + fputs($mail, $body); |
|
| 626 | + $result = pclose($mail); |
|
| 627 | + // implement call back function if it exists |
|
| 628 | + $isSent = ($result == 0) ? 1 : 0; |
|
| 629 | + $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 630 | + if($result != 0) { |
|
| 631 | + throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + return true; |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | /** |
@@ -642,51 +642,51 @@ discard block |
||
| 642 | 642 | * @return bool |
| 643 | 643 | */ |
| 644 | 644 | protected function MailSend($header, $body) { |
| 645 | - $toArr = array(); |
|
| 646 | - foreach($this->to as $t) { |
|
| 647 | - $toArr[] = $this->AddrFormat($t); |
|
| 648 | - } |
|
| 649 | - $to = implode(', ', $toArr); |
|
| 650 | - |
|
| 651 | - $params = sprintf("-oi -f %s", $this->Sender); |
|
| 652 | - if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) { |
|
| 653 | - $old_from = ini_get('sendmail_from'); |
|
| 654 | - ini_set('sendmail_from', $this->Sender); |
|
| 655 | - if ($this->SingleTo === true && count($toArr) > 1) { |
|
| 656 | - foreach ($toArr as $key => $val) { |
|
| 657 | - $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 658 | - // implement call back function if it exists |
|
| 659 | - $isSent = ($rt == 1) ? 1 : 0; |
|
| 660 | - $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 661 | - } |
|
| 662 | - } else { |
|
| 663 | - $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 664 | - // implement call back function if it exists |
|
| 665 | - $isSent = ($rt == 1) ? 1 : 0; |
|
| 666 | - $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 667 | - } |
|
| 668 | - } else { |
|
| 669 | - if ($this->SingleTo === true && count($toArr) > 1) { |
|
| 670 | - foreach ($toArr as $key => $val) { |
|
| 671 | - $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 672 | - // implement call back function if it exists |
|
| 673 | - $isSent = ($rt == 1) ? 1 : 0; |
|
| 674 | - $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 675 | - } |
|
| 676 | - } else { |
|
| 677 | - $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); |
|
| 678 | - // implement call back function if it exists |
|
| 679 | - $isSent = ($rt == 1) ? 1 : 0; |
|
| 680 | - $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - if (isset($old_from)) { |
|
| 684 | - ini_set('sendmail_from', $old_from); |
|
| 685 | - } |
|
| 686 | - if(!$rt) { |
|
| 687 | - throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL); |
|
| 688 | - } |
|
| 689 | - return true; |
|
| 645 | + $toArr = array(); |
|
| 646 | + foreach($this->to as $t) { |
|
| 647 | + $toArr[] = $this->AddrFormat($t); |
|
| 648 | + } |
|
| 649 | + $to = implode(', ', $toArr); |
|
| 650 | + |
|
| 651 | + $params = sprintf("-oi -f %s", $this->Sender); |
|
| 652 | + if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) { |
|
| 653 | + $old_from = ini_get('sendmail_from'); |
|
| 654 | + ini_set('sendmail_from', $this->Sender); |
|
| 655 | + if ($this->SingleTo === true && count($toArr) > 1) { |
|
| 656 | + foreach ($toArr as $key => $val) { |
|
| 657 | + $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 658 | + // implement call back function if it exists |
|
| 659 | + $isSent = ($rt == 1) ? 1 : 0; |
|
| 660 | + $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 661 | + } |
|
| 662 | + } else { |
|
| 663 | + $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 664 | + // implement call back function if it exists |
|
| 665 | + $isSent = ($rt == 1) ? 1 : 0; |
|
| 666 | + $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 667 | + } |
|
| 668 | + } else { |
|
| 669 | + if ($this->SingleTo === true && count($toArr) > 1) { |
|
| 670 | + foreach ($toArr as $key => $val) { |
|
| 671 | + $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
|
| 672 | + // implement call back function if it exists |
|
| 673 | + $isSent = ($rt == 1) ? 1 : 0; |
|
| 674 | + $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 675 | + } |
|
| 676 | + } else { |
|
| 677 | + $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); |
|
| 678 | + // implement call back function if it exists |
|
| 679 | + $isSent = ($rt == 1) ? 1 : 0; |
|
| 680 | + $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + if (isset($old_from)) { |
|
| 684 | + ini_set('sendmail_from', $old_from); |
|
| 685 | + } |
|
| 686 | + if(!$rt) { |
|
| 687 | + throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL); |
|
| 688 | + } |
|
| 689 | + return true; |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | /** |
@@ -699,67 +699,67 @@ discard block |
||
| 699 | 699 | * @return bool |
| 700 | 700 | */ |
| 701 | 701 | protected function SmtpSend($header, $body) { |
| 702 | - require_once $this->PluginDir . 'smtp.php'; |
|
| 703 | - $bad_rcpt = array(); |
|
| 704 | - |
|
| 705 | - if(!$this->SmtpConnect()) { |
|
| 706 | - throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL); |
|
| 707 | - } |
|
| 708 | - $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; |
|
| 709 | - if(!$this->smtp->Mail($smtp_from)) { |
|
| 710 | - throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL); |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - // Attempt to send attach all recipients |
|
| 714 | - foreach($this->to as $to) { |
|
| 715 | - if (!$this->smtp->Recipient($to[0])) { |
|
| 716 | - $bad_rcpt[] = $to[0]; |
|
| 717 | - // implement call back function if it exists |
|
| 718 | - $isSent = 0; |
|
| 719 | - $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); |
|
| 720 | - } else { |
|
| 721 | - // implement call back function if it exists |
|
| 722 | - $isSent = 1; |
|
| 723 | - $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - foreach($this->cc as $cc) { |
|
| 727 | - if (!$this->smtp->Recipient($cc[0])) { |
|
| 728 | - $bad_rcpt[] = $cc[0]; |
|
| 729 | - // implement call back function if it exists |
|
| 730 | - $isSent = 0; |
|
| 731 | - $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); |
|
| 732 | - } else { |
|
| 733 | - // implement call back function if it exists |
|
| 734 | - $isSent = 1; |
|
| 735 | - $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - foreach($this->bcc as $bcc) { |
|
| 739 | - if (!$this->smtp->Recipient($bcc[0])) { |
|
| 740 | - $bad_rcpt[] = $bcc[0]; |
|
| 741 | - // implement call back function if it exists |
|
| 742 | - $isSent = 0; |
|
| 743 | - $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); |
|
| 744 | - } else { |
|
| 745 | - // implement call back function if it exists |
|
| 746 | - $isSent = 1; |
|
| 747 | - $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); |
|
| 748 | - } |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - |
|
| 752 | - if (count($bad_rcpt) > 0 ) { //Create error message for any bad addresses |
|
| 753 | - $badaddresses = implode(', ', $bad_rcpt); |
|
| 754 | - throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses); |
|
| 755 | - } |
|
| 756 | - if(!$this->smtp->Data($header . $body)) { |
|
| 757 | - throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL); |
|
| 758 | - } |
|
| 759 | - if($this->SMTPKeepAlive == true) { |
|
| 760 | - $this->smtp->Reset(); |
|
| 761 | - } |
|
| 762 | - return true; |
|
| 702 | + require_once $this->PluginDir . 'smtp.php'; |
|
| 703 | + $bad_rcpt = array(); |
|
| 704 | + |
|
| 705 | + if(!$this->SmtpConnect()) { |
|
| 706 | + throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL); |
|
| 707 | + } |
|
| 708 | + $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; |
|
| 709 | + if(!$this->smtp->Mail($smtp_from)) { |
|
| 710 | + throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL); |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + // Attempt to send attach all recipients |
|
| 714 | + foreach($this->to as $to) { |
|
| 715 | + if (!$this->smtp->Recipient($to[0])) { |
|
| 716 | + $bad_rcpt[] = $to[0]; |
|
| 717 | + // implement call back function if it exists |
|
| 718 | + $isSent = 0; |
|
| 719 | + $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); |
|
| 720 | + } else { |
|
| 721 | + // implement call back function if it exists |
|
| 722 | + $isSent = 1; |
|
| 723 | + $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + foreach($this->cc as $cc) { |
|
| 727 | + if (!$this->smtp->Recipient($cc[0])) { |
|
| 728 | + $bad_rcpt[] = $cc[0]; |
|
| 729 | + // implement call back function if it exists |
|
| 730 | + $isSent = 0; |
|
| 731 | + $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); |
|
| 732 | + } else { |
|
| 733 | + // implement call back function if it exists |
|
| 734 | + $isSent = 1; |
|
| 735 | + $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + foreach($this->bcc as $bcc) { |
|
| 739 | + if (!$this->smtp->Recipient($bcc[0])) { |
|
| 740 | + $bad_rcpt[] = $bcc[0]; |
|
| 741 | + // implement call back function if it exists |
|
| 742 | + $isSent = 0; |
|
| 743 | + $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); |
|
| 744 | + } else { |
|
| 745 | + // implement call back function if it exists |
|
| 746 | + $isSent = 1; |
|
| 747 | + $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); |
|
| 748 | + } |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + |
|
| 752 | + if (count($bad_rcpt) > 0 ) { //Create error message for any bad addresses |
|
| 753 | + $badaddresses = implode(', ', $bad_rcpt); |
|
| 754 | + throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses); |
|
| 755 | + } |
|
| 756 | + if(!$this->smtp->Data($header . $body)) { |
|
| 757 | + throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL); |
|
| 758 | + } |
|
| 759 | + if($this->SMTPKeepAlive == true) { |
|
| 760 | + $this->smtp->Reset(); |
|
| 761 | + } |
|
| 762 | + return true; |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -770,61 +770,61 @@ discard block |
||
| 770 | 770 | * @return bool |
| 771 | 771 | */ |
| 772 | 772 | public function SmtpConnect() { |
| 773 | - if(is_null($this->smtp)) { |
|
| 774 | - $this->smtp = new SMTP(); |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - $this->smtp->do_debug = $this->SMTPDebug; |
|
| 778 | - $hosts = explode(';', $this->Host); |
|
| 779 | - $index = 0; |
|
| 780 | - $connection = $this->smtp->Connected(); |
|
| 781 | - |
|
| 782 | - // Retry while there is no connection |
|
| 783 | - try { |
|
| 784 | - while($index < count($hosts) && !$connection) { |
|
| 785 | - $hostinfo = array(); |
|
| 786 | - if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) { |
|
| 787 | - $host = $hostinfo[1]; |
|
| 788 | - $port = $hostinfo[2]; |
|
| 789 | - } else { |
|
| 790 | - $host = $hosts[$index]; |
|
| 791 | - $port = $this->Port; |
|
| 792 | - } |
|
| 793 | - |
|
| 794 | - $tls = ($this->SMTPSecure == 'tls'); |
|
| 795 | - $ssl = ($this->SMTPSecure == 'ssl'); |
|
| 796 | - |
|
| 797 | - if($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) { |
|
| 798 | - |
|
| 799 | - $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname()); |
|
| 800 | - $this->smtp->Hello($hello); |
|
| 801 | - |
|
| 802 | - if($tls) { |
|
| 803 | - if(!$this->smtp->StartTLS()) { |
|
| 804 | - throw new phpmailerException($this->Lang('tls')); |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - //We must resend HELO after tls negotiation |
|
| 808 | - $this->smtp->Hello($hello); |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - $connection = true; |
|
| 812 | - if($this->SMTPAuth) { |
|
| 813 | - if(!$this->smtp->Authenticate($this->Username, $this->Password)) { |
|
| 814 | - throw new phpmailerException($this->Lang('authenticate')); |
|
| 815 | - } |
|
| 816 | - } |
|
| 817 | - } |
|
| 818 | - $index++; |
|
| 819 | - if(!$connection) { |
|
| 820 | - throw new phpmailerException($this->Lang('connect_host')); |
|
| 821 | - } |
|
| 822 | - } |
|
| 823 | - } catch (phpmailerException $e) { |
|
| 824 | - $this->smtp->Reset(); |
|
| 825 | - throw $e; |
|
| 826 | - } |
|
| 827 | - return true; |
|
| 773 | + if(is_null($this->smtp)) { |
|
| 774 | + $this->smtp = new SMTP(); |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + $this->smtp->do_debug = $this->SMTPDebug; |
|
| 778 | + $hosts = explode(';', $this->Host); |
|
| 779 | + $index = 0; |
|
| 780 | + $connection = $this->smtp->Connected(); |
|
| 781 | + |
|
| 782 | + // Retry while there is no connection |
|
| 783 | + try { |
|
| 784 | + while($index < count($hosts) && !$connection) { |
|
| 785 | + $hostinfo = array(); |
|
| 786 | + if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) { |
|
| 787 | + $host = $hostinfo[1]; |
|
| 788 | + $port = $hostinfo[2]; |
|
| 789 | + } else { |
|
| 790 | + $host = $hosts[$index]; |
|
| 791 | + $port = $this->Port; |
|
| 792 | + } |
|
| 793 | + |
|
| 794 | + $tls = ($this->SMTPSecure == 'tls'); |
|
| 795 | + $ssl = ($this->SMTPSecure == 'ssl'); |
|
| 796 | + |
|
| 797 | + if($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) { |
|
| 798 | + |
|
| 799 | + $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname()); |
|
| 800 | + $this->smtp->Hello($hello); |
|
| 801 | + |
|
| 802 | + if($tls) { |
|
| 803 | + if(!$this->smtp->StartTLS()) { |
|
| 804 | + throw new phpmailerException($this->Lang('tls')); |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + //We must resend HELO after tls negotiation |
|
| 808 | + $this->smtp->Hello($hello); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + $connection = true; |
|
| 812 | + if($this->SMTPAuth) { |
|
| 813 | + if(!$this->smtp->Authenticate($this->Username, $this->Password)) { |
|
| 814 | + throw new phpmailerException($this->Lang('authenticate')); |
|
| 815 | + } |
|
| 816 | + } |
|
| 817 | + } |
|
| 818 | + $index++; |
|
| 819 | + if(!$connection) { |
|
| 820 | + throw new phpmailerException($this->Lang('connect_host')); |
|
| 821 | + } |
|
| 822 | + } |
|
| 823 | + } catch (phpmailerException $e) { |
|
| 824 | + $this->smtp->Reset(); |
|
| 825 | + throw $e; |
|
| 826 | + } |
|
| 827 | + return true; |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | /** |
@@ -832,57 +832,57 @@ discard block |
||
| 832 | 832 | * @return void |
| 833 | 833 | */ |
| 834 | 834 | public function SmtpClose() { |
| 835 | - if(!is_null($this->smtp)) { |
|
| 836 | - if($this->smtp->Connected()) { |
|
| 837 | - $this->smtp->Quit(); |
|
| 838 | - $this->smtp->Close(); |
|
| 839 | - } |
|
| 840 | - } |
|
| 835 | + if(!is_null($this->smtp)) { |
|
| 836 | + if($this->smtp->Connected()) { |
|
| 837 | + $this->smtp->Quit(); |
|
| 838 | + $this->smtp->Close(); |
|
| 839 | + } |
|
| 840 | + } |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | /** |
| 844 | - * Sets the language for all class error messages. |
|
| 845 | - * Returns false if it cannot load the language file. The default language is English. |
|
| 846 | - * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br") |
|
| 844 | + * Sets the language for all class error messages. |
|
| 845 | + * Returns false if it cannot load the language file. The default language is English. |
|
| 846 | + * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br") |
|
| 847 | 847 | * @param string $lang_path Path to the language file directory |
| 848 | 848 | * @access public |
| 849 | 849 | */ |
| 850 | 850 | function SetLanguage($langcode = 'en', $lang_path = 'language/') { |
| 851 | - //Define full set of translatable strings |
|
| 852 | - $PHPMAILER_LANG = array( |
|
| 853 | - 'provide_address' => 'You must provide at least one recipient email address.', |
|
| 854 | - 'mailer_not_supported' => ' mailer is not supported.', |
|
| 855 | - 'execute' => 'Could not execute: ', |
|
| 856 | - 'instantiate' => 'Could not instantiate mail function.', |
|
| 857 | - 'authenticate' => 'SMTP Error: Could not authenticate.', |
|
| 858 | - 'from_failed' => 'The following From address failed: ', |
|
| 859 | - 'recipients_failed' => 'SMTP Error: The following recipients failed: ', |
|
| 860 | - 'data_not_accepted' => 'SMTP Error: Data not accepted.', |
|
| 861 | - 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', |
|
| 862 | - 'file_access' => 'Could not access file: ', |
|
| 863 | - 'file_open' => 'File Error: Could not open file: ', |
|
| 864 | - 'encoding' => 'Unknown encoding: ', |
|
| 865 | - 'signing' => 'Signing Error: ', |
|
| 866 | - 'smtp_error' => 'SMTP server error: ', |
|
| 867 | - 'empty_message' => 'Message body empty', |
|
| 868 | - 'invalid_address' => 'Invalid address', |
|
| 869 | - 'variable_set' => 'Cannot set or reset variable: ' |
|
| 870 | - ); |
|
| 871 | - //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"! |
|
| 872 | - $l = true; |
|
| 873 | - if ($langcode != 'en') { //There is no English translation file |
|
| 874 | - $l = @include $lang_path.'phpmailer.lang-'.$langcode.'.php'; |
|
| 875 | - } |
|
| 876 | - $this->language = $PHPMAILER_LANG; |
|
| 877 | - return ($l == true); //Returns false if language not found |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - /** |
|
| 881 | - * Return the current array of language strings |
|
| 882 | - * @return array |
|
| 883 | - */ |
|
| 851 | + //Define full set of translatable strings |
|
| 852 | + $PHPMAILER_LANG = array( |
|
| 853 | + 'provide_address' => 'You must provide at least one recipient email address.', |
|
| 854 | + 'mailer_not_supported' => ' mailer is not supported.', |
|
| 855 | + 'execute' => 'Could not execute: ', |
|
| 856 | + 'instantiate' => 'Could not instantiate mail function.', |
|
| 857 | + 'authenticate' => 'SMTP Error: Could not authenticate.', |
|
| 858 | + 'from_failed' => 'The following From address failed: ', |
|
| 859 | + 'recipients_failed' => 'SMTP Error: The following recipients failed: ', |
|
| 860 | + 'data_not_accepted' => 'SMTP Error: Data not accepted.', |
|
| 861 | + 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', |
|
| 862 | + 'file_access' => 'Could not access file: ', |
|
| 863 | + 'file_open' => 'File Error: Could not open file: ', |
|
| 864 | + 'encoding' => 'Unknown encoding: ', |
|
| 865 | + 'signing' => 'Signing Error: ', |
|
| 866 | + 'smtp_error' => 'SMTP server error: ', |
|
| 867 | + 'empty_message' => 'Message body empty', |
|
| 868 | + 'invalid_address' => 'Invalid address', |
|
| 869 | + 'variable_set' => 'Cannot set or reset variable: ' |
|
| 870 | + ); |
|
| 871 | + //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"! |
|
| 872 | + $l = true; |
|
| 873 | + if ($langcode != 'en') { //There is no English translation file |
|
| 874 | + $l = @include $lang_path.'phpmailer.lang-'.$langcode.'.php'; |
|
| 875 | + } |
|
| 876 | + $this->language = $PHPMAILER_LANG; |
|
| 877 | + return ($l == true); //Returns false if language not found |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * Return the current array of language strings |
|
| 882 | + * @return array |
|
| 883 | + */ |
|
| 884 | 884 | public function GetTranslations() { |
| 885 | - return $this->language; |
|
| 885 | + return $this->language; |
|
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | ///////////////////////////////////////////////// |
@@ -895,15 +895,15 @@ discard block |
||
| 895 | 895 | * @return string |
| 896 | 896 | */ |
| 897 | 897 | public function AddrAppend($type, $addr) { |
| 898 | - $addr_str = $type . ': '; |
|
| 899 | - $addresses = array(); |
|
| 900 | - foreach ($addr as $a) { |
|
| 901 | - $addresses[] = $this->AddrFormat($a); |
|
| 902 | - } |
|
| 903 | - $addr_str .= implode(', ', $addresses); |
|
| 904 | - $addr_str .= $this->LE; |
|
| 898 | + $addr_str = $type . ': '; |
|
| 899 | + $addresses = array(); |
|
| 900 | + foreach ($addr as $a) { |
|
| 901 | + $addresses[] = $this->AddrFormat($a); |
|
| 902 | + } |
|
| 903 | + $addr_str .= implode(', ', $addresses); |
|
| 904 | + $addr_str .= $this->LE; |
|
| 905 | 905 | |
| 906 | - return $addr_str; |
|
| 906 | + return $addr_str; |
|
| 907 | 907 | } |
| 908 | 908 | |
| 909 | 909 | /** |
@@ -912,11 +912,11 @@ discard block |
||
| 912 | 912 | * @return string |
| 913 | 913 | */ |
| 914 | 914 | public function AddrFormat($addr) { |
| 915 | - if(empty($addr[1])) { |
|
| 916 | - return $this->SecureHeader($addr[0]); |
|
| 917 | - } else { |
|
| 918 | - return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; |
|
| 919 | - } |
|
| 915 | + if(empty($addr[1])) { |
|
| 916 | + return $this->SecureHeader($addr[0]); |
|
| 917 | + } else { |
|
| 918 | + return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; |
|
| 919 | + } |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | /** |
@@ -930,76 +930,76 @@ discard block |
||
| 930 | 930 | * @return string |
| 931 | 931 | */ |
| 932 | 932 | public function WrapText($message, $length, $qp_mode = false) { |
| 933 | - $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; |
|
| 934 | - // If utf-8 encoding is used, we will need to make sure we don't |
|
| 935 | - // split multibyte characters when we wrap |
|
| 936 | - $is_utf8 = (strtolower($this->CharSet) == "utf-8"); |
|
| 937 | - |
|
| 938 | - $message = $this->FixEOL($message); |
|
| 939 | - if (substr($message, -1) == $this->LE) { |
|
| 940 | - $message = substr($message, 0, -1); |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - $line = explode($this->LE, $message); |
|
| 944 | - $message = ''; |
|
| 945 | - for ($i=0 ;$i < count($line); $i++) { |
|
| 946 | - $line_part = explode(' ', $line[$i]); |
|
| 947 | - $buf = ''; |
|
| 948 | - for ($e = 0; $e<count($line_part); $e++) { |
|
| 949 | - $word = $line_part[$e]; |
|
| 950 | - if ($qp_mode and (strlen($word) > $length)) { |
|
| 951 | - $space_left = $length - strlen($buf) - 1; |
|
| 952 | - if ($e != 0) { |
|
| 953 | - if ($space_left > 20) { |
|
| 954 | - $len = $space_left; |
|
| 955 | - if ($is_utf8) { |
|
| 956 | - $len = $this->UTF8CharBoundary($word, $len); |
|
| 957 | - } elseif (substr($word, $len - 1, 1) == "=") { |
|
| 958 | - $len--; |
|
| 959 | - } elseif (substr($word, $len - 2, 1) == "=") { |
|
| 960 | - $len -= 2; |
|
| 961 | - } |
|
| 962 | - $part = substr($word, 0, $len); |
|
| 963 | - $word = substr($word, $len); |
|
| 964 | - $buf .= ' ' . $part; |
|
| 965 | - $message .= $buf . sprintf("=%s", $this->LE); |
|
| 966 | - } else { |
|
| 967 | - $message .= $buf . $soft_break; |
|
| 968 | - } |
|
| 969 | - $buf = ''; |
|
| 970 | - } |
|
| 971 | - while (strlen($word) > 0) { |
|
| 972 | - $len = $length; |
|
| 973 | - if ($is_utf8) { |
|
| 974 | - $len = $this->UTF8CharBoundary($word, $len); |
|
| 975 | - } elseif (substr($word, $len - 1, 1) == "=") { |
|
| 976 | - $len--; |
|
| 977 | - } elseif (substr($word, $len - 2, 1) == "=") { |
|
| 978 | - $len -= 2; |
|
| 979 | - } |
|
| 980 | - $part = substr($word, 0, $len); |
|
| 981 | - $word = substr($word, $len); |
|
| 982 | - |
|
| 983 | - if (strlen($word) > 0) { |
|
| 984 | - $message .= $part . sprintf("=%s", $this->LE); |
|
| 985 | - } else { |
|
| 986 | - $buf = $part; |
|
| 987 | - } |
|
| 988 | - } |
|
| 989 | - } else { |
|
| 990 | - $buf_o = $buf; |
|
| 991 | - $buf .= ($e == 0) ? $word : (' ' . $word); |
|
| 992 | - |
|
| 993 | - if (strlen($buf) > $length and $buf_o != '') { |
|
| 994 | - $message .= $buf_o . $soft_break; |
|
| 995 | - $buf = $word; |
|
| 996 | - } |
|
| 997 | - } |
|
| 998 | - } |
|
| 999 | - $message .= $buf . $this->LE; |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - return $message; |
|
| 933 | + $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; |
|
| 934 | + // If utf-8 encoding is used, we will need to make sure we don't |
|
| 935 | + // split multibyte characters when we wrap |
|
| 936 | + $is_utf8 = (strtolower($this->CharSet) == "utf-8"); |
|
| 937 | + |
|
| 938 | + $message = $this->FixEOL($message); |
|
| 939 | + if (substr($message, -1) == $this->LE) { |
|
| 940 | + $message = substr($message, 0, -1); |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + $line = explode($this->LE, $message); |
|
| 944 | + $message = ''; |
|
| 945 | + for ($i=0 ;$i < count($line); $i++) { |
|
| 946 | + $line_part = explode(' ', $line[$i]); |
|
| 947 | + $buf = ''; |
|
| 948 | + for ($e = 0; $e<count($line_part); $e++) { |
|
| 949 | + $word = $line_part[$e]; |
|
| 950 | + if ($qp_mode and (strlen($word) > $length)) { |
|
| 951 | + $space_left = $length - strlen($buf) - 1; |
|
| 952 | + if ($e != 0) { |
|
| 953 | + if ($space_left > 20) { |
|
| 954 | + $len = $space_left; |
|
| 955 | + if ($is_utf8) { |
|
| 956 | + $len = $this->UTF8CharBoundary($word, $len); |
|
| 957 | + } elseif (substr($word, $len - 1, 1) == "=") { |
|
| 958 | + $len--; |
|
| 959 | + } elseif (substr($word, $len - 2, 1) == "=") { |
|
| 960 | + $len -= 2; |
|
| 961 | + } |
|
| 962 | + $part = substr($word, 0, $len); |
|
| 963 | + $word = substr($word, $len); |
|
| 964 | + $buf .= ' ' . $part; |
|
| 965 | + $message .= $buf . sprintf("=%s", $this->LE); |
|
| 966 | + } else { |
|
| 967 | + $message .= $buf . $soft_break; |
|
| 968 | + } |
|
| 969 | + $buf = ''; |
|
| 970 | + } |
|
| 971 | + while (strlen($word) > 0) { |
|
| 972 | + $len = $length; |
|
| 973 | + if ($is_utf8) { |
|
| 974 | + $len = $this->UTF8CharBoundary($word, $len); |
|
| 975 | + } elseif (substr($word, $len - 1, 1) == "=") { |
|
| 976 | + $len--; |
|
| 977 | + } elseif (substr($word, $len - 2, 1) == "=") { |
|
| 978 | + $len -= 2; |
|
| 979 | + } |
|
| 980 | + $part = substr($word, 0, $len); |
|
| 981 | + $word = substr($word, $len); |
|
| 982 | + |
|
| 983 | + if (strlen($word) > 0) { |
|
| 984 | + $message .= $part . sprintf("=%s", $this->LE); |
|
| 985 | + } else { |
|
| 986 | + $buf = $part; |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | + } else { |
|
| 990 | + $buf_o = $buf; |
|
| 991 | + $buf .= ($e == 0) ? $word : (' ' . $word); |
|
| 992 | + |
|
| 993 | + if (strlen($buf) > $length and $buf_o != '') { |
|
| 994 | + $message .= $buf_o . $soft_break; |
|
| 995 | + $buf = $word; |
|
| 996 | + } |
|
| 997 | + } |
|
| 998 | + } |
|
| 999 | + $message .= $buf . $this->LE; |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + return $message; |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | /** |
@@ -1012,35 +1012,35 @@ discard block |
||
| 1012 | 1012 | * @return int |
| 1013 | 1013 | */ |
| 1014 | 1014 | public function UTF8CharBoundary($encodedText, $maxLength) { |
| 1015 | - $foundSplitPos = false; |
|
| 1016 | - $lookBack = 3; |
|
| 1017 | - while (!$foundSplitPos) { |
|
| 1018 | - $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack); |
|
| 1019 | - $encodedCharPos = strpos($lastChunk, "="); |
|
| 1020 | - if ($encodedCharPos !== false) { |
|
| 1021 | - // Found start of encoded character byte within $lookBack block. |
|
| 1022 | - // Check the encoded byte value (the 2 chars after the '=') |
|
| 1023 | - $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2); |
|
| 1024 | - $dec = hexdec($hex); |
|
| 1025 | - if ($dec < 128) { // Single byte character. |
|
| 1026 | - // If the encoded char was found at pos 0, it will fit |
|
| 1027 | - // otherwise reduce maxLength to start of the encoded char |
|
| 1028 | - $maxLength = ($encodedCharPos == 0) ? $maxLength : |
|
| 1029 | - $maxLength - ($lookBack - $encodedCharPos); |
|
| 1030 | - $foundSplitPos = true; |
|
| 1031 | - } elseif ($dec >= 192) { // First byte of a multi byte character |
|
| 1032 | - // Reduce maxLength to split at start of character |
|
| 1033 | - $maxLength = $maxLength - ($lookBack - $encodedCharPos); |
|
| 1034 | - $foundSplitPos = true; |
|
| 1035 | - } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back |
|
| 1036 | - $lookBack += 3; |
|
| 1037 | - } |
|
| 1038 | - } else { |
|
| 1039 | - // No encoded character found |
|
| 1040 | - $foundSplitPos = true; |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - return $maxLength; |
|
| 1015 | + $foundSplitPos = false; |
|
| 1016 | + $lookBack = 3; |
|
| 1017 | + while (!$foundSplitPos) { |
|
| 1018 | + $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack); |
|
| 1019 | + $encodedCharPos = strpos($lastChunk, "="); |
|
| 1020 | + if ($encodedCharPos !== false) { |
|
| 1021 | + // Found start of encoded character byte within $lookBack block. |
|
| 1022 | + // Check the encoded byte value (the 2 chars after the '=') |
|
| 1023 | + $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2); |
|
| 1024 | + $dec = hexdec($hex); |
|
| 1025 | + if ($dec < 128) { // Single byte character. |
|
| 1026 | + // If the encoded char was found at pos 0, it will fit |
|
| 1027 | + // otherwise reduce maxLength to start of the encoded char |
|
| 1028 | + $maxLength = ($encodedCharPos == 0) ? $maxLength : |
|
| 1029 | + $maxLength - ($lookBack - $encodedCharPos); |
|
| 1030 | + $foundSplitPos = true; |
|
| 1031 | + } elseif ($dec >= 192) { // First byte of a multi byte character |
|
| 1032 | + // Reduce maxLength to split at start of character |
|
| 1033 | + $maxLength = $maxLength - ($lookBack - $encodedCharPos); |
|
| 1034 | + $foundSplitPos = true; |
|
| 1035 | + } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back |
|
| 1036 | + $lookBack += 3; |
|
| 1037 | + } |
|
| 1038 | + } else { |
|
| 1039 | + // No encoded character found |
|
| 1040 | + $foundSplitPos = true; |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + return $maxLength; |
|
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | |
@@ -1050,19 +1050,19 @@ discard block |
||
| 1050 | 1050 | * @return void |
| 1051 | 1051 | */ |
| 1052 | 1052 | public function SetWordWrap() { |
| 1053 | - if($this->WordWrap < 1) { |
|
| 1054 | - return; |
|
| 1055 | - } |
|
| 1053 | + if($this->WordWrap < 1) { |
|
| 1054 | + return; |
|
| 1055 | + } |
|
| 1056 | 1056 | |
| 1057 | - switch($this->message_type) { |
|
| 1058 | - case 'alt': |
|
| 1059 | - case 'alt_attachments': |
|
| 1060 | - $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
|
| 1061 | - break; |
|
| 1062 | - default: |
|
| 1063 | - $this->Body = $this->WrapText($this->Body, $this->WordWrap); |
|
| 1064 | - break; |
|
| 1065 | - } |
|
| 1057 | + switch($this->message_type) { |
|
| 1058 | + case 'alt': |
|
| 1059 | + case 'alt_attachments': |
|
| 1060 | + $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
|
| 1061 | + break; |
|
| 1062 | + default: |
|
| 1063 | + $this->Body = $this->WrapText($this->Body, $this->WordWrap); |
|
| 1064 | + break; |
|
| 1065 | + } |
|
| 1066 | 1066 | } |
| 1067 | 1067 | |
| 1068 | 1068 | /** |
@@ -1071,81 +1071,81 @@ discard block |
||
| 1071 | 1071 | * @return string The assembled header |
| 1072 | 1072 | */ |
| 1073 | 1073 | public function CreateHeader() { |
| 1074 | - $result = ''; |
|
| 1075 | - |
|
| 1076 | - // Set the boundaries |
|
| 1077 | - $uniq_id = md5(uniqid(time())); |
|
| 1078 | - $this->boundary[1] = 'b1_' . $uniq_id; |
|
| 1079 | - $this->boundary[2] = 'b2_' . $uniq_id; |
|
| 1080 | - |
|
| 1081 | - $result .= $this->HeaderLine('Date', self::RFCDate()); |
|
| 1082 | - if($this->Sender == '') { |
|
| 1083 | - $result .= $this->HeaderLine('Return-Path', trim($this->From)); |
|
| 1084 | - } else { |
|
| 1085 | - $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); |
|
| 1086 | - } |
|
| 1087 | - |
|
| 1088 | - // To be created automatically by mail() |
|
| 1089 | - if($this->Mailer != 'mail') { |
|
| 1090 | - if ($this->SingleTo === true) { |
|
| 1091 | - foreach($this->to as $t) { |
|
| 1092 | - $this->SingleToArray[] = $this->AddrFormat($t); |
|
| 1093 | - } |
|
| 1094 | - } else { |
|
| 1095 | - if(count($this->to) > 0) { |
|
| 1096 | - $result .= $this->AddrAppend('To', $this->to); |
|
| 1097 | - } elseif (count($this->cc) == 0) { |
|
| 1098 | - $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); |
|
| 1099 | - } |
|
| 1100 | - } |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - $from = array(); |
|
| 1104 | - $from[0][0] = trim($this->From); |
|
| 1105 | - $from[0][1] = $this->FromName; |
|
| 1106 | - $result .= $this->AddrAppend('From', $from); |
|
| 1107 | - |
|
| 1108 | - // sendmail and mail() extract Cc from the header before sending |
|
| 1109 | - if(count($this->cc) > 0) { |
|
| 1110 | - $result .= $this->AddrAppend('Cc', $this->cc); |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - // sendmail and mail() extract Bcc from the header before sending |
|
| 1114 | - if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { |
|
| 1115 | - $result .= $this->AddrAppend('Bcc', $this->bcc); |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - if(count($this->ReplyTo) > 0) { |
|
| 1119 | - $result .= $this->AddrAppend('Reply-to', $this->ReplyTo); |
|
| 1120 | - } |
|
| 1121 | - |
|
| 1122 | - // mail() sets the subject itself |
|
| 1123 | - if($this->Mailer != 'mail') { |
|
| 1124 | - $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject))); |
|
| 1125 | - } |
|
| 1126 | - |
|
| 1127 | - if($this->MessageID != '') { |
|
| 1128 | - $result .= $this->HeaderLine('Message-ID',$this->MessageID); |
|
| 1129 | - } else { |
|
| 1130 | - $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); |
|
| 1131 | - } |
|
| 1132 | - $result .= $this->HeaderLine('X-Priority', $this->Priority); |
|
| 1133 | - $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)'); |
|
| 1134 | - |
|
| 1135 | - if($this->ConfirmReadingTo != '') { |
|
| 1136 | - $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>'); |
|
| 1137 | - } |
|
| 1138 | - |
|
| 1139 | - // Add custom headers |
|
| 1140 | - for($index = 0; $index < count($this->CustomHeader); $index++) { |
|
| 1141 | - $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
|
| 1142 | - } |
|
| 1143 | - if (!$this->sign_key_file) { |
|
| 1144 | - $result .= $this->HeaderLine('MIME-Version', '1.0'); |
|
| 1145 | - $result .= $this->GetMailMIME(); |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - return $result; |
|
| 1074 | + $result = ''; |
|
| 1075 | + |
|
| 1076 | + // Set the boundaries |
|
| 1077 | + $uniq_id = md5(uniqid(time())); |
|
| 1078 | + $this->boundary[1] = 'b1_' . $uniq_id; |
|
| 1079 | + $this->boundary[2] = 'b2_' . $uniq_id; |
|
| 1080 | + |
|
| 1081 | + $result .= $this->HeaderLine('Date', self::RFCDate()); |
|
| 1082 | + if($this->Sender == '') { |
|
| 1083 | + $result .= $this->HeaderLine('Return-Path', trim($this->From)); |
|
| 1084 | + } else { |
|
| 1085 | + $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + // To be created automatically by mail() |
|
| 1089 | + if($this->Mailer != 'mail') { |
|
| 1090 | + if ($this->SingleTo === true) { |
|
| 1091 | + foreach($this->to as $t) { |
|
| 1092 | + $this->SingleToArray[] = $this->AddrFormat($t); |
|
| 1093 | + } |
|
| 1094 | + } else { |
|
| 1095 | + if(count($this->to) > 0) { |
|
| 1096 | + $result .= $this->AddrAppend('To', $this->to); |
|
| 1097 | + } elseif (count($this->cc) == 0) { |
|
| 1098 | + $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); |
|
| 1099 | + } |
|
| 1100 | + } |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + $from = array(); |
|
| 1104 | + $from[0][0] = trim($this->From); |
|
| 1105 | + $from[0][1] = $this->FromName; |
|
| 1106 | + $result .= $this->AddrAppend('From', $from); |
|
| 1107 | + |
|
| 1108 | + // sendmail and mail() extract Cc from the header before sending |
|
| 1109 | + if(count($this->cc) > 0) { |
|
| 1110 | + $result .= $this->AddrAppend('Cc', $this->cc); |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + // sendmail and mail() extract Bcc from the header before sending |
|
| 1114 | + if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { |
|
| 1115 | + $result .= $this->AddrAppend('Bcc', $this->bcc); |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + if(count($this->ReplyTo) > 0) { |
|
| 1119 | + $result .= $this->AddrAppend('Reply-to', $this->ReplyTo); |
|
| 1120 | + } |
|
| 1121 | + |
|
| 1122 | + // mail() sets the subject itself |
|
| 1123 | + if($this->Mailer != 'mail') { |
|
| 1124 | + $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject))); |
|
| 1125 | + } |
|
| 1126 | + |
|
| 1127 | + if($this->MessageID != '') { |
|
| 1128 | + $result .= $this->HeaderLine('Message-ID',$this->MessageID); |
|
| 1129 | + } else { |
|
| 1130 | + $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); |
|
| 1131 | + } |
|
| 1132 | + $result .= $this->HeaderLine('X-Priority', $this->Priority); |
|
| 1133 | + $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)'); |
|
| 1134 | + |
|
| 1135 | + if($this->ConfirmReadingTo != '') { |
|
| 1136 | + $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>'); |
|
| 1137 | + } |
|
| 1138 | + |
|
| 1139 | + // Add custom headers |
|
| 1140 | + for($index = 0; $index < count($this->CustomHeader); $index++) { |
|
| 1141 | + $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
|
| 1142 | + } |
|
| 1143 | + if (!$this->sign_key_file) { |
|
| 1144 | + $result .= $this->HeaderLine('MIME-Version', '1.0'); |
|
| 1145 | + $result .= $this->GetMailMIME(); |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + return $result; |
|
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | 1151 | /** |
@@ -1154,32 +1154,32 @@ discard block |
||
| 1154 | 1154 | * @return string |
| 1155 | 1155 | */ |
| 1156 | 1156 | public function GetMailMIME() { |
| 1157 | - $result = ''; |
|
| 1158 | - switch($this->message_type) { |
|
| 1159 | - case 'plain': |
|
| 1160 | - $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); |
|
| 1161 | - $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet); |
|
| 1162 | - break; |
|
| 1163 | - case 'attachments': |
|
| 1164 | - case 'alt_attachments': |
|
| 1165 | - if($this->InlineImageExists()){ |
|
| 1166 | - $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE); |
|
| 1167 | - } else { |
|
| 1168 | - $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); |
|
| 1169 | - $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 1170 | - } |
|
| 1171 | - break; |
|
| 1172 | - case 'alt': |
|
| 1173 | - $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); |
|
| 1174 | - $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 1175 | - break; |
|
| 1176 | - } |
|
| 1177 | - |
|
| 1178 | - if($this->Mailer != 'mail') { |
|
| 1179 | - $result .= $this->LE.$this->LE; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - return $result; |
|
| 1157 | + $result = ''; |
|
| 1158 | + switch($this->message_type) { |
|
| 1159 | + case 'plain': |
|
| 1160 | + $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); |
|
| 1161 | + $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet); |
|
| 1162 | + break; |
|
| 1163 | + case 'attachments': |
|
| 1164 | + case 'alt_attachments': |
|
| 1165 | + if($this->InlineImageExists()){ |
|
| 1166 | + $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE); |
|
| 1167 | + } else { |
|
| 1168 | + $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); |
|
| 1169 | + $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 1170 | + } |
|
| 1171 | + break; |
|
| 1172 | + case 'alt': |
|
| 1173 | + $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); |
|
| 1174 | + $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 1175 | + break; |
|
| 1176 | + } |
|
| 1177 | + |
|
| 1178 | + if($this->Mailer != 'mail') { |
|
| 1179 | + $result .= $this->LE.$this->LE; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + return $result; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | /** |
@@ -1188,72 +1188,72 @@ discard block |
||
| 1188 | 1188 | * @return string The assembled message body |
| 1189 | 1189 | */ |
| 1190 | 1190 | public function CreateBody() { |
| 1191 | - $body = ''; |
|
| 1192 | - |
|
| 1193 | - if ($this->sign_key_file) { |
|
| 1194 | - $body .= $this->GetMailMIME(); |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - $this->SetWordWrap(); |
|
| 1198 | - |
|
| 1199 | - switch($this->message_type) { |
|
| 1200 | - case 'alt': |
|
| 1201 | - $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); |
|
| 1202 | - $body .= $this->EncodeString($this->AltBody, $this->Encoding); |
|
| 1203 | - $body .= $this->LE.$this->LE; |
|
| 1204 | - $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', ''); |
|
| 1205 | - $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1206 | - $body .= $this->LE.$this->LE; |
|
| 1207 | - $body .= $this->EndBoundary($this->boundary[1]); |
|
| 1208 | - break; |
|
| 1209 | - case 'plain': |
|
| 1210 | - $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1211 | - break; |
|
| 1212 | - case 'attachments': |
|
| 1213 | - $body .= $this->GetBoundary($this->boundary[1], '', '', ''); |
|
| 1214 | - $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1215 | - $body .= $this->LE; |
|
| 1216 | - $body .= $this->AttachAll(); |
|
| 1217 | - break; |
|
| 1218 | - case 'alt_attachments': |
|
| 1219 | - $body .= sprintf("--%s%s", $this->boundary[1], $this->LE); |
|
| 1220 | - $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); |
|
| 1221 | - $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body |
|
| 1222 | - $body .= $this->EncodeString($this->AltBody, $this->Encoding); |
|
| 1223 | - $body .= $this->LE.$this->LE; |
|
| 1224 | - $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body |
|
| 1225 | - $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1226 | - $body .= $this->LE.$this->LE; |
|
| 1227 | - $body .= $this->EndBoundary($this->boundary[2]); |
|
| 1228 | - $body .= $this->AttachAll(); |
|
| 1229 | - break; |
|
| 1230 | - } |
|
| 1231 | - |
|
| 1232 | - if($this->IsError()) { |
|
| 1233 | - $body = ''; |
|
| 1234 | - } else if ($this->sign_key_file) { |
|
| 1235 | - try { |
|
| 1236 | - $file = tempnam('', 'mail'); |
|
| 1237 | - file_put_contents($file, $body, LOCK_EX); //TODO check this worked |
|
| 1238 | - $signed = tempnam("", "signed"); |
|
| 1239 | - if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) { |
|
| 1240 | - @unlink($file); |
|
| 1241 | - @unlink($signed); |
|
| 1242 | - $body = file_get_contents($signed); |
|
| 1243 | - } else { |
|
| 1244 | - @unlink($file); |
|
| 1245 | - @unlink($signed); |
|
| 1246 | - throw new phpmailerException($this->Lang("signing").openssl_error_string()); |
|
| 1247 | - } |
|
| 1248 | - } catch (phpmailerException $e) { |
|
| 1249 | - $body = ''; |
|
| 1250 | - if ($this->exceptions) { |
|
| 1251 | - throw $e; |
|
| 1252 | - } |
|
| 1253 | - } |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - return $body; |
|
| 1191 | + $body = ''; |
|
| 1192 | + |
|
| 1193 | + if ($this->sign_key_file) { |
|
| 1194 | + $body .= $this->GetMailMIME(); |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + $this->SetWordWrap(); |
|
| 1198 | + |
|
| 1199 | + switch($this->message_type) { |
|
| 1200 | + case 'alt': |
|
| 1201 | + $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); |
|
| 1202 | + $body .= $this->EncodeString($this->AltBody, $this->Encoding); |
|
| 1203 | + $body .= $this->LE.$this->LE; |
|
| 1204 | + $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', ''); |
|
| 1205 | + $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1206 | + $body .= $this->LE.$this->LE; |
|
| 1207 | + $body .= $this->EndBoundary($this->boundary[1]); |
|
| 1208 | + break; |
|
| 1209 | + case 'plain': |
|
| 1210 | + $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1211 | + break; |
|
| 1212 | + case 'attachments': |
|
| 1213 | + $body .= $this->GetBoundary($this->boundary[1], '', '', ''); |
|
| 1214 | + $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1215 | + $body .= $this->LE; |
|
| 1216 | + $body .= $this->AttachAll(); |
|
| 1217 | + break; |
|
| 1218 | + case 'alt_attachments': |
|
| 1219 | + $body .= sprintf("--%s%s", $this->boundary[1], $this->LE); |
|
| 1220 | + $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); |
|
| 1221 | + $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body |
|
| 1222 | + $body .= $this->EncodeString($this->AltBody, $this->Encoding); |
|
| 1223 | + $body .= $this->LE.$this->LE; |
|
| 1224 | + $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body |
|
| 1225 | + $body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1226 | + $body .= $this->LE.$this->LE; |
|
| 1227 | + $body .= $this->EndBoundary($this->boundary[2]); |
|
| 1228 | + $body .= $this->AttachAll(); |
|
| 1229 | + break; |
|
| 1230 | + } |
|
| 1231 | + |
|
| 1232 | + if($this->IsError()) { |
|
| 1233 | + $body = ''; |
|
| 1234 | + } else if ($this->sign_key_file) { |
|
| 1235 | + try { |
|
| 1236 | + $file = tempnam('', 'mail'); |
|
| 1237 | + file_put_contents($file, $body, LOCK_EX); //TODO check this worked |
|
| 1238 | + $signed = tempnam("", "signed"); |
|
| 1239 | + if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) { |
|
| 1240 | + @unlink($file); |
|
| 1241 | + @unlink($signed); |
|
| 1242 | + $body = file_get_contents($signed); |
|
| 1243 | + } else { |
|
| 1244 | + @unlink($file); |
|
| 1245 | + @unlink($signed); |
|
| 1246 | + throw new phpmailerException($this->Lang("signing").openssl_error_string()); |
|
| 1247 | + } |
|
| 1248 | + } catch (phpmailerException $e) { |
|
| 1249 | + $body = ''; |
|
| 1250 | + if ($this->exceptions) { |
|
| 1251 | + throw $e; |
|
| 1252 | + } |
|
| 1253 | + } |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + return $body; |
|
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | 1259 | /** |
@@ -1261,23 +1261,23 @@ discard block |
||
| 1261 | 1261 | * @access private |
| 1262 | 1262 | */ |
| 1263 | 1263 | private function GetBoundary($boundary, $charSet, $contentType, $encoding) { |
| 1264 | - $result = ''; |
|
| 1265 | - if($charSet == '') { |
|
| 1266 | - $charSet = $this->CharSet; |
|
| 1267 | - } |
|
| 1268 | - if($contentType == '') { |
|
| 1269 | - $contentType = $this->ContentType; |
|
| 1270 | - } |
|
| 1271 | - if($encoding == '') { |
|
| 1272 | - $encoding = $this->Encoding; |
|
| 1273 | - } |
|
| 1274 | - $result .= $this->TextLine('--' . $boundary); |
|
| 1275 | - $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet); |
|
| 1276 | - $result .= $this->LE; |
|
| 1277 | - $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); |
|
| 1278 | - $result .= $this->LE; |
|
| 1279 | - |
|
| 1280 | - return $result; |
|
| 1264 | + $result = ''; |
|
| 1265 | + if($charSet == '') { |
|
| 1266 | + $charSet = $this->CharSet; |
|
| 1267 | + } |
|
| 1268 | + if($contentType == '') { |
|
| 1269 | + $contentType = $this->ContentType; |
|
| 1270 | + } |
|
| 1271 | + if($encoding == '') { |
|
| 1272 | + $encoding = $this->Encoding; |
|
| 1273 | + } |
|
| 1274 | + $result .= $this->TextLine('--' . $boundary); |
|
| 1275 | + $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet); |
|
| 1276 | + $result .= $this->LE; |
|
| 1277 | + $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); |
|
| 1278 | + $result .= $this->LE; |
|
| 1279 | + |
|
| 1280 | + return $result; |
|
| 1281 | 1281 | } |
| 1282 | 1282 | |
| 1283 | 1283 | /** |
@@ -1285,7 +1285,7 @@ discard block |
||
| 1285 | 1285 | * @access private |
| 1286 | 1286 | */ |
| 1287 | 1287 | private function EndBoundary($boundary) { |
| 1288 | - return $this->LE . '--' . $boundary . '--' . $this->LE; |
|
| 1288 | + return $this->LE . '--' . $boundary . '--' . $this->LE; |
|
| 1289 | 1289 | } |
| 1290 | 1290 | |
| 1291 | 1291 | /** |
@@ -1294,19 +1294,19 @@ discard block |
||
| 1294 | 1294 | * @return void |
| 1295 | 1295 | */ |
| 1296 | 1296 | private function SetMessageType() { |
| 1297 | - if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) { |
|
| 1298 | - $this->message_type = 'plain'; |
|
| 1299 | - } else { |
|
| 1300 | - if(count($this->attachment) > 0) { |
|
| 1301 | - $this->message_type = 'attachments'; |
|
| 1302 | - } |
|
| 1303 | - if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) { |
|
| 1304 | - $this->message_type = 'alt'; |
|
| 1305 | - } |
|
| 1306 | - if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) { |
|
| 1307 | - $this->message_type = 'alt_attachments'; |
|
| 1308 | - } |
|
| 1309 | - } |
|
| 1297 | + if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) { |
|
| 1298 | + $this->message_type = 'plain'; |
|
| 1299 | + } else { |
|
| 1300 | + if(count($this->attachment) > 0) { |
|
| 1301 | + $this->message_type = 'attachments'; |
|
| 1302 | + } |
|
| 1303 | + if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) { |
|
| 1304 | + $this->message_type = 'alt'; |
|
| 1305 | + } |
|
| 1306 | + if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) { |
|
| 1307 | + $this->message_type = 'alt_attachments'; |
|
| 1308 | + } |
|
| 1309 | + } |
|
| 1310 | 1310 | } |
| 1311 | 1311 | |
| 1312 | 1312 | /** |
@@ -1315,7 +1315,7 @@ discard block |
||
| 1315 | 1315 | * @return string |
| 1316 | 1316 | */ |
| 1317 | 1317 | public function HeaderLine($name, $value) { |
| 1318 | - return $name . ': ' . $value . $this->LE; |
|
| 1318 | + return $name . ': ' . $value . $this->LE; |
|
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | 1321 | /** |
@@ -1324,7 +1324,7 @@ discard block |
||
| 1324 | 1324 | * @return string |
| 1325 | 1325 | */ |
| 1326 | 1326 | public function TextLine($value) { |
| 1327 | - return $value . $this->LE; |
|
| 1327 | + return $value . $this->LE; |
|
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | ///////////////////////////////////////////////// |
@@ -1342,45 +1342,45 @@ discard block |
||
| 1342 | 1342 | * @return bool |
| 1343 | 1343 | */ |
| 1344 | 1344 | public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { |
| 1345 | - try { |
|
| 1346 | - if(!@is_file($path)) { |
|
| 1347 | - throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE); |
|
| 1348 | - } |
|
| 1349 | - $filename = basename($path); |
|
| 1350 | - if($name == '') { |
|
| 1351 | - $name = $filename; |
|
| 1352 | - } |
|
| 1353 | - |
|
| 1354 | - $this->attachment[] = array( |
|
| 1355 | - 0 => $path, |
|
| 1356 | - 1 => $filename, |
|
| 1357 | - 2 => $name, |
|
| 1358 | - 3 => $encoding, |
|
| 1359 | - 4 => $type, |
|
| 1360 | - 5 => false, // isStringAttachment |
|
| 1361 | - 6 => 'attachment', |
|
| 1362 | - 7 => 0 |
|
| 1363 | - ); |
|
| 1364 | - |
|
| 1365 | - } catch (phpmailerException $e) { |
|
| 1366 | - $this->SetError($e->getMessage()); |
|
| 1367 | - if ($this->exceptions) { |
|
| 1368 | - throw $e; |
|
| 1369 | - } |
|
| 1370 | - echo $e->getMessage()."\n"; |
|
| 1371 | - if ( $e->getCode() == self::STOP_CRITICAL ) { |
|
| 1372 | - return false; |
|
| 1373 | - } |
|
| 1374 | - } |
|
| 1375 | - return true; |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * Return the current array of attachments |
|
| 1380 | - * @return array |
|
| 1381 | - */ |
|
| 1345 | + try { |
|
| 1346 | + if(!@is_file($path)) { |
|
| 1347 | + throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE); |
|
| 1348 | + } |
|
| 1349 | + $filename = basename($path); |
|
| 1350 | + if($name == '') { |
|
| 1351 | + $name = $filename; |
|
| 1352 | + } |
|
| 1353 | + |
|
| 1354 | + $this->attachment[] = array( |
|
| 1355 | + 0 => $path, |
|
| 1356 | + 1 => $filename, |
|
| 1357 | + 2 => $name, |
|
| 1358 | + 3 => $encoding, |
|
| 1359 | + 4 => $type, |
|
| 1360 | + 5 => false, // isStringAttachment |
|
| 1361 | + 6 => 'attachment', |
|
| 1362 | + 7 => 0 |
|
| 1363 | + ); |
|
| 1364 | + |
|
| 1365 | + } catch (phpmailerException $e) { |
|
| 1366 | + $this->SetError($e->getMessage()); |
|
| 1367 | + if ($this->exceptions) { |
|
| 1368 | + throw $e; |
|
| 1369 | + } |
|
| 1370 | + echo $e->getMessage()."\n"; |
|
| 1371 | + if ( $e->getCode() == self::STOP_CRITICAL ) { |
|
| 1372 | + return false; |
|
| 1373 | + } |
|
| 1374 | + } |
|
| 1375 | + return true; |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * Return the current array of attachments |
|
| 1380 | + * @return array |
|
| 1381 | + */ |
|
| 1382 | 1382 | public function GetAttachments() { |
| 1383 | - return $this->attachment; |
|
| 1383 | + return $this->attachment; |
|
| 1384 | 1384 | } |
| 1385 | 1385 | |
| 1386 | 1386 | /** |
@@ -1390,61 +1390,61 @@ discard block |
||
| 1390 | 1390 | * @return string |
| 1391 | 1391 | */ |
| 1392 | 1392 | private function AttachAll() { |
| 1393 | - // Return text of body |
|
| 1394 | - $mime = array(); |
|
| 1395 | - $cidUniq = array(); |
|
| 1396 | - $incl = array(); |
|
| 1397 | - |
|
| 1398 | - // Add all attachments |
|
| 1399 | - foreach ($this->attachment as $attachment) { |
|
| 1400 | - // Check for string attachment |
|
| 1401 | - $bString = $attachment[5]; |
|
| 1402 | - if ($bString) { |
|
| 1403 | - $string = $attachment[0]; |
|
| 1404 | - } else { |
|
| 1405 | - $path = $attachment[0]; |
|
| 1406 | - } |
|
| 1407 | - |
|
| 1408 | - if (in_array($attachment[0], $incl)) { continue; } |
|
| 1409 | - $filename = $attachment[1]; |
|
| 1410 | - $name = $attachment[2]; |
|
| 1411 | - $encoding = $attachment[3]; |
|
| 1412 | - $type = $attachment[4]; |
|
| 1413 | - $disposition = $attachment[6]; |
|
| 1414 | - $cid = $attachment[7]; |
|
| 1415 | - $incl[] = $attachment[0]; |
|
| 1416 | - if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; } |
|
| 1417 | - $cidUniq[$cid] = true; |
|
| 1418 | - |
|
| 1419 | - $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); |
|
| 1420 | - $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); |
|
| 1421 | - $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); |
|
| 1422 | - |
|
| 1423 | - if($disposition == 'inline') { |
|
| 1424 | - $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); |
|
| 1425 | - } |
|
| 1426 | - |
|
| 1427 | - $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); |
|
| 1428 | - |
|
| 1429 | - // Encode as string attachment |
|
| 1430 | - if($bString) { |
|
| 1431 | - $mime[] = $this->EncodeString($string, $encoding); |
|
| 1432 | - if($this->IsError()) { |
|
| 1433 | - return ''; |
|
| 1434 | - } |
|
| 1435 | - $mime[] = $this->LE.$this->LE; |
|
| 1436 | - } else { |
|
| 1437 | - $mime[] = $this->EncodeFile($path, $encoding); |
|
| 1438 | - if($this->IsError()) { |
|
| 1439 | - return ''; |
|
| 1440 | - } |
|
| 1441 | - $mime[] = $this->LE.$this->LE; |
|
| 1442 | - } |
|
| 1443 | - } |
|
| 1444 | - |
|
| 1445 | - $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); |
|
| 1446 | - |
|
| 1447 | - return join('', $mime); |
|
| 1393 | + // Return text of body |
|
| 1394 | + $mime = array(); |
|
| 1395 | + $cidUniq = array(); |
|
| 1396 | + $incl = array(); |
|
| 1397 | + |
|
| 1398 | + // Add all attachments |
|
| 1399 | + foreach ($this->attachment as $attachment) { |
|
| 1400 | + // Check for string attachment |
|
| 1401 | + $bString = $attachment[5]; |
|
| 1402 | + if ($bString) { |
|
| 1403 | + $string = $attachment[0]; |
|
| 1404 | + } else { |
|
| 1405 | + $path = $attachment[0]; |
|
| 1406 | + } |
|
| 1407 | + |
|
| 1408 | + if (in_array($attachment[0], $incl)) { continue; } |
|
| 1409 | + $filename = $attachment[1]; |
|
| 1410 | + $name = $attachment[2]; |
|
| 1411 | + $encoding = $attachment[3]; |
|
| 1412 | + $type = $attachment[4]; |
|
| 1413 | + $disposition = $attachment[6]; |
|
| 1414 | + $cid = $attachment[7]; |
|
| 1415 | + $incl[] = $attachment[0]; |
|
| 1416 | + if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; } |
|
| 1417 | + $cidUniq[$cid] = true; |
|
| 1418 | + |
|
| 1419 | + $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); |
|
| 1420 | + $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); |
|
| 1421 | + $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); |
|
| 1422 | + |
|
| 1423 | + if($disposition == 'inline') { |
|
| 1424 | + $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); |
|
| 1425 | + } |
|
| 1426 | + |
|
| 1427 | + $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); |
|
| 1428 | + |
|
| 1429 | + // Encode as string attachment |
|
| 1430 | + if($bString) { |
|
| 1431 | + $mime[] = $this->EncodeString($string, $encoding); |
|
| 1432 | + if($this->IsError()) { |
|
| 1433 | + return ''; |
|
| 1434 | + } |
|
| 1435 | + $mime[] = $this->LE.$this->LE; |
|
| 1436 | + } else { |
|
| 1437 | + $mime[] = $this->EncodeFile($path, $encoding); |
|
| 1438 | + if($this->IsError()) { |
|
| 1439 | + return ''; |
|
| 1440 | + } |
|
| 1441 | + $mime[] = $this->LE.$this->LE; |
|
| 1442 | + } |
|
| 1443 | + } |
|
| 1444 | + |
|
| 1445 | + $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); |
|
| 1446 | + |
|
| 1447 | + return join('', $mime); |
|
| 1448 | 1448 | } |
| 1449 | 1449 | |
| 1450 | 1450 | /** |
@@ -1457,27 +1457,27 @@ discard block |
||
| 1457 | 1457 | * @return string |
| 1458 | 1458 | */ |
| 1459 | 1459 | private function EncodeFile($path, $encoding = 'base64') { |
| 1460 | - try { |
|
| 1461 | - if (!is_readable($path)) { |
|
| 1462 | - throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); |
|
| 1463 | - } |
|
| 1464 | - if (function_exists('get_magic_quotes')) { |
|
| 1465 | - function get_magic_quotes() { |
|
| 1466 | - return false; |
|
| 1467 | - } |
|
| 1460 | + try { |
|
| 1461 | + if (!is_readable($path)) { |
|
| 1462 | + throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); |
|
| 1463 | + } |
|
| 1464 | + if (function_exists('get_magic_quotes')) { |
|
| 1465 | + function get_magic_quotes() { |
|
| 1466 | + return false; |
|
| 1467 | + } |
|
| 1468 | 1468 | } |
| 1469 | - if (PHP_VERSION < 5) { |
|
| 1470 | - $magic_quotes = get_magic_quotes_runtime(); |
|
| 1471 | - set_magic_quotes_runtime(0); |
|
| 1472 | - } |
|
| 1473 | - $file_buffer = file_get_contents($path); |
|
| 1474 | - $file_buffer = $this->EncodeString($file_buffer, $encoding); |
|
| 1475 | - if (PHP_VERSION < 5) { set_magic_quotes_runtime($magic_quotes); } |
|
| 1476 | - return $file_buffer; |
|
| 1477 | - } catch (Exception $e) { |
|
| 1478 | - $this->SetError($e->getMessage()); |
|
| 1479 | - return ''; |
|
| 1480 | - } |
|
| 1469 | + if (PHP_VERSION < 5) { |
|
| 1470 | + $magic_quotes = get_magic_quotes_runtime(); |
|
| 1471 | + set_magic_quotes_runtime(0); |
|
| 1472 | + } |
|
| 1473 | + $file_buffer = file_get_contents($path); |
|
| 1474 | + $file_buffer = $this->EncodeString($file_buffer, $encoding); |
|
| 1475 | + if (PHP_VERSION < 5) { set_magic_quotes_runtime($magic_quotes); } |
|
| 1476 | + return $file_buffer; |
|
| 1477 | + } catch (Exception $e) { |
|
| 1478 | + $this->SetError($e->getMessage()); |
|
| 1479 | + return ''; |
|
| 1480 | + } |
|
| 1481 | 1481 | } |
| 1482 | 1482 | |
| 1483 | 1483 | /** |
@@ -1489,29 +1489,29 @@ discard block |
||
| 1489 | 1489 | * @return string |
| 1490 | 1490 | */ |
| 1491 | 1491 | public function EncodeString ($str, $encoding = 'base64') { |
| 1492 | - $encoded = ''; |
|
| 1493 | - switch(strtolower($encoding)) { |
|
| 1494 | - case 'base64': |
|
| 1495 | - $encoded = chunk_split(base64_encode($str), 76, $this->LE); |
|
| 1496 | - break; |
|
| 1497 | - case '7bit': |
|
| 1498 | - case '8bit': |
|
| 1499 | - $encoded = $this->FixEOL($str); |
|
| 1500 | - //Make sure it ends with a line break |
|
| 1501 | - if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
|
| 1502 | - $encoded .= $this->LE; |
|
| 1503 | - break; |
|
| 1504 | - case 'binary': |
|
| 1505 | - $encoded = $str; |
|
| 1506 | - break; |
|
| 1507 | - case 'quoted-printable': |
|
| 1508 | - $encoded = $this->EncodeQP($str); |
|
| 1509 | - break; |
|
| 1510 | - default: |
|
| 1511 | - $this->SetError($this->Lang('encoding') . $encoding); |
|
| 1512 | - break; |
|
| 1513 | - } |
|
| 1514 | - return $encoded; |
|
| 1492 | + $encoded = ''; |
|
| 1493 | + switch(strtolower($encoding)) { |
|
| 1494 | + case 'base64': |
|
| 1495 | + $encoded = chunk_split(base64_encode($str), 76, $this->LE); |
|
| 1496 | + break; |
|
| 1497 | + case '7bit': |
|
| 1498 | + case '8bit': |
|
| 1499 | + $encoded = $this->FixEOL($str); |
|
| 1500 | + //Make sure it ends with a line break |
|
| 1501 | + if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
|
| 1502 | + $encoded .= $this->LE; |
|
| 1503 | + break; |
|
| 1504 | + case 'binary': |
|
| 1505 | + $encoded = $str; |
|
| 1506 | + break; |
|
| 1507 | + case 'quoted-printable': |
|
| 1508 | + $encoded = $this->EncodeQP($str); |
|
| 1509 | + break; |
|
| 1510 | + default: |
|
| 1511 | + $this->SetError($this->Lang('encoding') . $encoding); |
|
| 1512 | + break; |
|
| 1513 | + } |
|
| 1514 | + return $encoded; |
|
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | 1517 | /** |
@@ -1520,58 +1520,58 @@ discard block |
||
| 1520 | 1520 | * @return string |
| 1521 | 1521 | */ |
| 1522 | 1522 | public function EncodeHeader ($str, $position = 'text') { |
| 1523 | - $x = 0; |
|
| 1524 | - |
|
| 1525 | - switch (strtolower($position)) { |
|
| 1526 | - case 'phrase': |
|
| 1527 | - if (!preg_match('/[\200-\377]/', $str)) { |
|
| 1528 | - // Can't use addslashes as we don't know what value has magic_quotes_sybase |
|
| 1529 | - $encoded = addcslashes($str, "\0..\37\177\\\""); |
|
| 1530 | - if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) { |
|
| 1531 | - return ($encoded); |
|
| 1532 | - } else { |
|
| 1533 | - return ("\"$encoded\""); |
|
| 1534 | - } |
|
| 1535 | - } |
|
| 1536 | - $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches); |
|
| 1537 | - break; |
|
| 1538 | - case 'comment': |
|
| 1539 | - $x = preg_match_all('/[()"]/', $str, $matches); |
|
| 1540 | - // Fall-through |
|
| 1541 | - case 'text': |
|
| 1542 | - default: |
|
| 1543 | - $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); |
|
| 1544 | - break; |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - if ($x == 0) { |
|
| 1548 | - return ($str); |
|
| 1549 | - } |
|
| 1550 | - |
|
| 1551 | - $maxlen = 75 - 7 - strlen($this->CharSet); |
|
| 1552 | - // Try to select the encoding which should produce the shortest output |
|
| 1553 | - if (strlen($str)/3 < $x) { |
|
| 1554 | - $encoding = 'B'; |
|
| 1555 | - if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) { |
|
| 1556 | - // Use a custom function which correctly encodes and wraps long |
|
| 1557 | - // multibyte strings without breaking lines within a character |
|
| 1558 | - $encoded = $this->Base64EncodeWrapMB($str); |
|
| 1559 | - } else { |
|
| 1560 | - $encoded = base64_encode($str); |
|
| 1561 | - $maxlen -= $maxlen % 4; |
|
| 1562 | - $encoded = trim(chunk_split($encoded, $maxlen, "\n")); |
|
| 1563 | - } |
|
| 1564 | - } else { |
|
| 1565 | - $encoding = 'Q'; |
|
| 1566 | - $encoded = $this->EncodeQ($str, $position); |
|
| 1567 | - $encoded = $this->WrapText($encoded, $maxlen, true); |
|
| 1568 | - $encoded = str_replace('='.$this->LE, "\n", trim($encoded)); |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); |
|
| 1572 | - $encoded = trim(str_replace("\n", $this->LE, $encoded)); |
|
| 1573 | - |
|
| 1574 | - return $encoded; |
|
| 1523 | + $x = 0; |
|
| 1524 | + |
|
| 1525 | + switch (strtolower($position)) { |
|
| 1526 | + case 'phrase': |
|
| 1527 | + if (!preg_match('/[\200-\377]/', $str)) { |
|
| 1528 | + // Can't use addslashes as we don't know what value has magic_quotes_sybase |
|
| 1529 | + $encoded = addcslashes($str, "\0..\37\177\\\""); |
|
| 1530 | + if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) { |
|
| 1531 | + return ($encoded); |
|
| 1532 | + } else { |
|
| 1533 | + return ("\"$encoded\""); |
|
| 1534 | + } |
|
| 1535 | + } |
|
| 1536 | + $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches); |
|
| 1537 | + break; |
|
| 1538 | + case 'comment': |
|
| 1539 | + $x = preg_match_all('/[()"]/', $str, $matches); |
|
| 1540 | + // Fall-through |
|
| 1541 | + case 'text': |
|
| 1542 | + default: |
|
| 1543 | + $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); |
|
| 1544 | + break; |
|
| 1545 | + } |
|
| 1546 | + |
|
| 1547 | + if ($x == 0) { |
|
| 1548 | + return ($str); |
|
| 1549 | + } |
|
| 1550 | + |
|
| 1551 | + $maxlen = 75 - 7 - strlen($this->CharSet); |
|
| 1552 | + // Try to select the encoding which should produce the shortest output |
|
| 1553 | + if (strlen($str)/3 < $x) { |
|
| 1554 | + $encoding = 'B'; |
|
| 1555 | + if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) { |
|
| 1556 | + // Use a custom function which correctly encodes and wraps long |
|
| 1557 | + // multibyte strings without breaking lines within a character |
|
| 1558 | + $encoded = $this->Base64EncodeWrapMB($str); |
|
| 1559 | + } else { |
|
| 1560 | + $encoded = base64_encode($str); |
|
| 1561 | + $maxlen -= $maxlen % 4; |
|
| 1562 | + $encoded = trim(chunk_split($encoded, $maxlen, "\n")); |
|
| 1563 | + } |
|
| 1564 | + } else { |
|
| 1565 | + $encoding = 'Q'; |
|
| 1566 | + $encoded = $this->EncodeQ($str, $position); |
|
| 1567 | + $encoded = $this->WrapText($encoded, $maxlen, true); |
|
| 1568 | + $encoded = str_replace('='.$this->LE, "\n", trim($encoded)); |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); |
|
| 1572 | + $encoded = trim(str_replace("\n", $this->LE, $encoded)); |
|
| 1573 | + |
|
| 1574 | + return $encoded; |
|
| 1575 | 1575 | } |
| 1576 | 1576 | |
| 1577 | 1577 | /** |
@@ -1581,11 +1581,11 @@ discard block |
||
| 1581 | 1581 | * @return bool |
| 1582 | 1582 | */ |
| 1583 | 1583 | public function HasMultiBytes($str) { |
| 1584 | - if (function_exists('mb_strlen')) { |
|
| 1585 | - return (strlen($str) > mb_strlen($str, $this->CharSet)); |
|
| 1586 | - } else { // Assume no multibytes (we can't handle without mbstring functions anyway) |
|
| 1587 | - return false; |
|
| 1588 | - } |
|
| 1584 | + if (function_exists('mb_strlen')) { |
|
| 1585 | + return (strlen($str) > mb_strlen($str, $this->CharSet)); |
|
| 1586 | + } else { // Assume no multibytes (we can't handle without mbstring functions anyway) |
|
| 1587 | + return false; |
|
| 1588 | + } |
|
| 1589 | 1589 | } |
| 1590 | 1590 | |
| 1591 | 1591 | /** |
@@ -1597,117 +1597,117 @@ discard block |
||
| 1597 | 1597 | * @return string |
| 1598 | 1598 | */ |
| 1599 | 1599 | public function Base64EncodeWrapMB($str) { |
| 1600 | - $start = "=?".$this->CharSet."?B?"; |
|
| 1601 | - $end = "?="; |
|
| 1602 | - $encoded = ""; |
|
| 1603 | - |
|
| 1604 | - $mb_length = mb_strlen($str, $this->CharSet); |
|
| 1605 | - // Each line must have length <= 75, including $start and $end |
|
| 1606 | - $length = 75 - strlen($start) - strlen($end); |
|
| 1607 | - // Average multi-byte ratio |
|
| 1608 | - $ratio = $mb_length / strlen($str); |
|
| 1609 | - // Base64 has a 4:3 ratio |
|
| 1610 | - $offset = $avgLength = floor($length * $ratio * .75); |
|
| 1611 | - |
|
| 1612 | - for ($i = 0; $i < $mb_length; $i += $offset) { |
|
| 1613 | - $lookBack = 0; |
|
| 1614 | - |
|
| 1615 | - do { |
|
| 1616 | - $offset = $avgLength - $lookBack; |
|
| 1617 | - $chunk = mb_substr($str, $i, $offset, $this->CharSet); |
|
| 1618 | - $chunk = base64_encode($chunk); |
|
| 1619 | - $lookBack++; |
|
| 1620 | - } |
|
| 1621 | - while (strlen($chunk) > $length); |
|
| 1622 | - |
|
| 1623 | - $encoded .= $chunk . $this->LE; |
|
| 1624 | - } |
|
| 1625 | - |
|
| 1626 | - // Chomp the last linefeed |
|
| 1627 | - $encoded = substr($encoded, 0, -strlen($this->LE)); |
|
| 1628 | - return $encoded; |
|
| 1629 | - } |
|
| 1630 | - |
|
| 1631 | - /** |
|
| 1632 | - * Encode string to quoted-printable. |
|
| 1633 | - * Only uses standard PHP, slow, but will always work |
|
| 1634 | - * @access public |
|
| 1635 | - * @param string $string the text to encode |
|
| 1636 | - * @param integer $line_max Number of chars allowed on a line before wrapping |
|
| 1637 | - * @return string |
|
| 1638 | - */ |
|
| 1600 | + $start = "=?".$this->CharSet."?B?"; |
|
| 1601 | + $end = "?="; |
|
| 1602 | + $encoded = ""; |
|
| 1603 | + |
|
| 1604 | + $mb_length = mb_strlen($str, $this->CharSet); |
|
| 1605 | + // Each line must have length <= 75, including $start and $end |
|
| 1606 | + $length = 75 - strlen($start) - strlen($end); |
|
| 1607 | + // Average multi-byte ratio |
|
| 1608 | + $ratio = $mb_length / strlen($str); |
|
| 1609 | + // Base64 has a 4:3 ratio |
|
| 1610 | + $offset = $avgLength = floor($length * $ratio * .75); |
|
| 1611 | + |
|
| 1612 | + for ($i = 0; $i < $mb_length; $i += $offset) { |
|
| 1613 | + $lookBack = 0; |
|
| 1614 | + |
|
| 1615 | + do { |
|
| 1616 | + $offset = $avgLength - $lookBack; |
|
| 1617 | + $chunk = mb_substr($str, $i, $offset, $this->CharSet); |
|
| 1618 | + $chunk = base64_encode($chunk); |
|
| 1619 | + $lookBack++; |
|
| 1620 | + } |
|
| 1621 | + while (strlen($chunk) > $length); |
|
| 1622 | + |
|
| 1623 | + $encoded .= $chunk . $this->LE; |
|
| 1624 | + } |
|
| 1625 | + |
|
| 1626 | + // Chomp the last linefeed |
|
| 1627 | + $encoded = substr($encoded, 0, -strlen($this->LE)); |
|
| 1628 | + return $encoded; |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + /** |
|
| 1632 | + * Encode string to quoted-printable. |
|
| 1633 | + * Only uses standard PHP, slow, but will always work |
|
| 1634 | + * @access public |
|
| 1635 | + * @param string $string the text to encode |
|
| 1636 | + * @param integer $line_max Number of chars allowed on a line before wrapping |
|
| 1637 | + * @return string |
|
| 1638 | + */ |
|
| 1639 | 1639 | public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) { |
| 1640 | - $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
| 1641 | - $lines = preg_split('/(?:\r\n|\r|\n)/', $input); |
|
| 1642 | - $eol = "\r\n"; |
|
| 1643 | - $escape = '='; |
|
| 1644 | - $output = ''; |
|
| 1645 | - while( list(, $line) = each($lines) ) { |
|
| 1646 | - $linlen = strlen($line); |
|
| 1647 | - $newline = ''; |
|
| 1648 | - for($i = 0; $i < $linlen; $i++) { |
|
| 1649 | - $c = substr( $line, $i, 1 ); |
|
| 1650 | - $dec = ord( $c ); |
|
| 1651 | - if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E |
|
| 1652 | - $c = '=2E'; |
|
| 1653 | - } |
|
| 1654 | - if ( $dec == 32 ) { |
|
| 1655 | - if ( $i == ( $linlen - 1 ) ) { // convert space at eol only |
|
| 1656 | - $c = '=20'; |
|
| 1657 | - } else if ( $space_conv ) { |
|
| 1658 | - $c = '=20'; |
|
| 1659 | - } |
|
| 1660 | - } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required |
|
| 1661 | - $h2 = floor($dec/16); |
|
| 1662 | - $h1 = floor($dec%16); |
|
| 1663 | - $c = $escape.$hex[$h2].$hex[$h1]; |
|
| 1664 | - } |
|
| 1665 | - if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted |
|
| 1666 | - $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay |
|
| 1667 | - $newline = ''; |
|
| 1668 | - // check if newline first character will be point or not |
|
| 1669 | - if ( $dec == 46 ) { |
|
| 1670 | - $c = '=2E'; |
|
| 1671 | - } |
|
| 1672 | - } |
|
| 1673 | - $newline .= $c; |
|
| 1674 | - } // end of for |
|
| 1675 | - $output .= $newline.$eol; |
|
| 1676 | - } // end of while |
|
| 1677 | - return $output; |
|
| 1678 | - } |
|
| 1679 | - |
|
| 1680 | - /** |
|
| 1681 | - * Encode string to RFC2045 (6.7) quoted-printable format |
|
| 1682 | - * Uses a PHP5 stream filter to do the encoding about 64x faster than the old version |
|
| 1683 | - * Also results in same content as you started with after decoding |
|
| 1684 | - * @see EncodeQPphp() |
|
| 1685 | - * @access public |
|
| 1686 | - * @param string $string the text to encode |
|
| 1687 | - * @param integer $line_max Number of chars allowed on a line before wrapping |
|
| 1688 | - * @param boolean $space_conv Dummy param for compatibility with existing EncodeQP function |
|
| 1689 | - * @return string |
|
| 1690 | - * @author Marcus Bointon |
|
| 1691 | - */ |
|
| 1640 | + $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
| 1641 | + $lines = preg_split('/(?:\r\n|\r|\n)/', $input); |
|
| 1642 | + $eol = "\r\n"; |
|
| 1643 | + $escape = '='; |
|
| 1644 | + $output = ''; |
|
| 1645 | + while( list(, $line) = each($lines) ) { |
|
| 1646 | + $linlen = strlen($line); |
|
| 1647 | + $newline = ''; |
|
| 1648 | + for($i = 0; $i < $linlen; $i++) { |
|
| 1649 | + $c = substr( $line, $i, 1 ); |
|
| 1650 | + $dec = ord( $c ); |
|
| 1651 | + if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E |
|
| 1652 | + $c = '=2E'; |
|
| 1653 | + } |
|
| 1654 | + if ( $dec == 32 ) { |
|
| 1655 | + if ( $i == ( $linlen - 1 ) ) { // convert space at eol only |
|
| 1656 | + $c = '=20'; |
|
| 1657 | + } else if ( $space_conv ) { |
|
| 1658 | + $c = '=20'; |
|
| 1659 | + } |
|
| 1660 | + } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required |
|
| 1661 | + $h2 = floor($dec/16); |
|
| 1662 | + $h1 = floor($dec%16); |
|
| 1663 | + $c = $escape.$hex[$h2].$hex[$h1]; |
|
| 1664 | + } |
|
| 1665 | + if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted |
|
| 1666 | + $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay |
|
| 1667 | + $newline = ''; |
|
| 1668 | + // check if newline first character will be point or not |
|
| 1669 | + if ( $dec == 46 ) { |
|
| 1670 | + $c = '=2E'; |
|
| 1671 | + } |
|
| 1672 | + } |
|
| 1673 | + $newline .= $c; |
|
| 1674 | + } // end of for |
|
| 1675 | + $output .= $newline.$eol; |
|
| 1676 | + } // end of while |
|
| 1677 | + return $output; |
|
| 1678 | + } |
|
| 1679 | + |
|
| 1680 | + /** |
|
| 1681 | + * Encode string to RFC2045 (6.7) quoted-printable format |
|
| 1682 | + * Uses a PHP5 stream filter to do the encoding about 64x faster than the old version |
|
| 1683 | + * Also results in same content as you started with after decoding |
|
| 1684 | + * @see EncodeQPphp() |
|
| 1685 | + * @access public |
|
| 1686 | + * @param string $string the text to encode |
|
| 1687 | + * @param integer $line_max Number of chars allowed on a line before wrapping |
|
| 1688 | + * @param boolean $space_conv Dummy param for compatibility with existing EncodeQP function |
|
| 1689 | + * @return string |
|
| 1690 | + * @author Marcus Bointon |
|
| 1691 | + */ |
|
| 1692 | 1692 | public function EncodeQP($string, $line_max = 76, $space_conv = false) { |
| 1693 | - if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3) |
|
| 1694 | - return quoted_printable_encode($string); |
|
| 1695 | - } |
|
| 1696 | - $filters = stream_get_filters(); |
|
| 1697 | - if (!in_array('convert.*', $filters)) { //Got convert stream filter? |
|
| 1698 | - return $this->EncodeQPphp($string, $line_max, $space_conv); //Fall back to old implementation |
|
| 1699 | - } |
|
| 1700 | - $fp = fopen('php://temp/', 'r+'); |
|
| 1701 | - $string = preg_replace('/\r\n?/', $this->LE, $string); //Normalise line breaks |
|
| 1702 | - $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE); |
|
| 1703 | - $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params); |
|
| 1704 | - fputs($fp, $string); |
|
| 1705 | - rewind($fp); |
|
| 1706 | - $out = stream_get_contents($fp); |
|
| 1707 | - stream_filter_remove($s); |
|
| 1708 | - $out = preg_replace('/^\./m', '=2E', $out); //Encode . if it is first char on a line, workaround for bug in Exchange |
|
| 1709 | - fclose($fp); |
|
| 1710 | - return $out; |
|
| 1693 | + if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3) |
|
| 1694 | + return quoted_printable_encode($string); |
|
| 1695 | + } |
|
| 1696 | + $filters = stream_get_filters(); |
|
| 1697 | + if (!in_array('convert.*', $filters)) { //Got convert stream filter? |
|
| 1698 | + return $this->EncodeQPphp($string, $line_max, $space_conv); //Fall back to old implementation |
|
| 1699 | + } |
|
| 1700 | + $fp = fopen('php://temp/', 'r+'); |
|
| 1701 | + $string = preg_replace('/\r\n?/', $this->LE, $string); //Normalise line breaks |
|
| 1702 | + $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE); |
|
| 1703 | + $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params); |
|
| 1704 | + fputs($fp, $string); |
|
| 1705 | + rewind($fp); |
|
| 1706 | + $out = stream_get_contents($fp); |
|
| 1707 | + stream_filter_remove($s); |
|
| 1708 | + $out = preg_replace('/^\./m', '=2E', $out); //Encode . if it is first char on a line, workaround for bug in Exchange |
|
| 1709 | + fclose($fp); |
|
| 1710 | + return $out; |
|
| 1711 | 1711 | } |
| 1712 | 1712 | |
| 1713 | 1713 | /** |
@@ -1719,28 +1719,28 @@ discard block |
||
| 1719 | 1719 | * @return string |
| 1720 | 1720 | */ |
| 1721 | 1721 | public function EncodeQ ($str, $position = 'text') { |
| 1722 | - // There should not be any EOL in the string |
|
| 1723 | - $encoded = preg_replace('/[\r\n]*/', '', $str); |
|
| 1722 | + // There should not be any EOL in the string |
|
| 1723 | + $encoded = preg_replace('/[\r\n]*/', '', $str); |
|
| 1724 | 1724 | |
| 1725 | - switch (strtolower($position)) { |
|
| 1726 | - case 'phrase': |
|
| 1725 | + switch (strtolower($position)) { |
|
| 1726 | + case 'phrase': |
|
| 1727 | 1727 | $encoded = preg_replace_callback('/([^A-Za-z0-9!*+\/ -])/', function($n) { return '='.sprintf('%02X', ord('\\1')); }, $encoded); |
| 1728 | - break; |
|
| 1729 | - case 'comment': |
|
| 1728 | + break; |
|
| 1729 | + case 'comment': |
|
| 1730 | 1730 | $encoded = preg_replace_callback('/([\(\)\"])/', function($n) { return '='.sprintf('%02X', ord('\\1')); }, $encoded); |
| 1731 | - case 'text': |
|
| 1732 | - default: |
|
| 1733 | - // Replace every high ascii, control =, ? and _ characters |
|
| 1734 | - //TODO using /e (equivalent to eval()) is probably not a good idea |
|
| 1735 | - $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', |
|
| 1736 | - "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|
| 1737 | - break; |
|
| 1738 | - } |
|
| 1731 | + case 'text': |
|
| 1732 | + default: |
|
| 1733 | + // Replace every high ascii, control =, ? and _ characters |
|
| 1734 | + //TODO using /e (equivalent to eval()) is probably not a good idea |
|
| 1735 | + $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', |
|
| 1736 | + "'='.sprintf('%02X', ord('\\1'))", $encoded); |
|
| 1737 | + break; |
|
| 1738 | + } |
|
| 1739 | 1739 | |
| 1740 | - // Replace every spaces to _ (more readable than =20) |
|
| 1741 | - $encoded = str_replace(' ', '_', $encoded); |
|
| 1740 | + // Replace every spaces to _ (more readable than =20) |
|
| 1741 | + $encoded = str_replace(' ', '_', $encoded); |
|
| 1742 | 1742 | |
| 1743 | - return $encoded; |
|
| 1743 | + return $encoded; |
|
| 1744 | 1744 | } |
| 1745 | 1745 | |
| 1746 | 1746 | /** |
@@ -1754,17 +1754,17 @@ discard block |
||
| 1754 | 1754 | * @return void |
| 1755 | 1755 | */ |
| 1756 | 1756 | public function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') { |
| 1757 | - // Append to $attachment array |
|
| 1758 | - $this->attachment[] = array( |
|
| 1759 | - 0 => $string, |
|
| 1760 | - 1 => $filename, |
|
| 1761 | - 2 => basename($filename), |
|
| 1762 | - 3 => $encoding, |
|
| 1763 | - 4 => $type, |
|
| 1764 | - 5 => true, // isStringAttachment |
|
| 1765 | - 6 => 'attachment', |
|
| 1766 | - 7 => 0 |
|
| 1767 | - ); |
|
| 1757 | + // Append to $attachment array |
|
| 1758 | + $this->attachment[] = array( |
|
| 1759 | + 0 => $string, |
|
| 1760 | + 1 => $filename, |
|
| 1761 | + 2 => basename($filename), |
|
| 1762 | + 3 => $encoding, |
|
| 1763 | + 4 => $type, |
|
| 1764 | + 5 => true, // isStringAttachment |
|
| 1765 | + 6 => 'attachment', |
|
| 1766 | + 7 => 0 |
|
| 1767 | + ); |
|
| 1768 | 1768 | } |
| 1769 | 1769 | |
| 1770 | 1770 | /** |
@@ -1782,29 +1782,29 @@ discard block |
||
| 1782 | 1782 | */ |
| 1783 | 1783 | public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { |
| 1784 | 1784 | |
| 1785 | - if(!@is_file($path)) { |
|
| 1786 | - $this->SetError($this->Lang('file_access') . $path); |
|
| 1787 | - return false; |
|
| 1788 | - } |
|
| 1785 | + if(!@is_file($path)) { |
|
| 1786 | + $this->SetError($this->Lang('file_access') . $path); |
|
| 1787 | + return false; |
|
| 1788 | + } |
|
| 1789 | 1789 | |
| 1790 | - $filename = basename($path); |
|
| 1791 | - if($name == '') { |
|
| 1792 | - $name = $filename; |
|
| 1793 | - } |
|
| 1790 | + $filename = basename($path); |
|
| 1791 | + if($name == '') { |
|
| 1792 | + $name = $filename; |
|
| 1793 | + } |
|
| 1794 | 1794 | |
| 1795 | - // Append to $attachment array |
|
| 1796 | - $this->attachment[] = array( |
|
| 1797 | - 0 => $path, |
|
| 1798 | - 1 => $filename, |
|
| 1799 | - 2 => $name, |
|
| 1800 | - 3 => $encoding, |
|
| 1801 | - 4 => $type, |
|
| 1802 | - 5 => false, // isStringAttachment |
|
| 1803 | - 6 => 'inline', |
|
| 1804 | - 7 => $cid |
|
| 1805 | - ); |
|
| 1795 | + // Append to $attachment array |
|
| 1796 | + $this->attachment[] = array( |
|
| 1797 | + 0 => $path, |
|
| 1798 | + 1 => $filename, |
|
| 1799 | + 2 => $name, |
|
| 1800 | + 3 => $encoding, |
|
| 1801 | + 4 => $type, |
|
| 1802 | + 5 => false, // isStringAttachment |
|
| 1803 | + 6 => 'inline', |
|
| 1804 | + 7 => $cid |
|
| 1805 | + ); |
|
| 1806 | 1806 | |
| 1807 | - return true; |
|
| 1807 | + return true; |
|
| 1808 | 1808 | } |
| 1809 | 1809 | |
| 1810 | 1810 | /** |
@@ -1813,12 +1813,12 @@ discard block |
||
| 1813 | 1813 | * @return bool |
| 1814 | 1814 | */ |
| 1815 | 1815 | public function InlineImageExists() { |
| 1816 | - foreach($this->attachment as $attachment) { |
|
| 1817 | - if ($attachment[6] == 'inline') { |
|
| 1818 | - return true; |
|
| 1819 | - } |
|
| 1820 | - } |
|
| 1821 | - return false; |
|
| 1816 | + foreach($this->attachment as $attachment) { |
|
| 1817 | + if ($attachment[6] == 'inline') { |
|
| 1818 | + return true; |
|
| 1819 | + } |
|
| 1820 | + } |
|
| 1821 | + return false; |
|
| 1822 | 1822 | } |
| 1823 | 1823 | |
| 1824 | 1824 | ///////////////////////////////////////////////// |
@@ -1830,10 +1830,10 @@ discard block |
||
| 1830 | 1830 | * @return void |
| 1831 | 1831 | */ |
| 1832 | 1832 | public function ClearAddresses() { |
| 1833 | - foreach($this->to as $to) { |
|
| 1834 | - unset($this->all_recipients[strtolower($to[0])]); |
|
| 1835 | - } |
|
| 1836 | - $this->to = array(); |
|
| 1833 | + foreach($this->to as $to) { |
|
| 1834 | + unset($this->all_recipients[strtolower($to[0])]); |
|
| 1835 | + } |
|
| 1836 | + $this->to = array(); |
|
| 1837 | 1837 | } |
| 1838 | 1838 | |
| 1839 | 1839 | /** |
@@ -1841,10 +1841,10 @@ discard block |
||
| 1841 | 1841 | * @return void |
| 1842 | 1842 | */ |
| 1843 | 1843 | public function ClearCCs() { |
| 1844 | - foreach($this->cc as $cc) { |
|
| 1845 | - unset($this->all_recipients[strtolower($cc[0])]); |
|
| 1846 | - } |
|
| 1847 | - $this->cc = array(); |
|
| 1844 | + foreach($this->cc as $cc) { |
|
| 1845 | + unset($this->all_recipients[strtolower($cc[0])]); |
|
| 1846 | + } |
|
| 1847 | + $this->cc = array(); |
|
| 1848 | 1848 | } |
| 1849 | 1849 | |
| 1850 | 1850 | /** |
@@ -1852,10 +1852,10 @@ discard block |
||
| 1852 | 1852 | * @return void |
| 1853 | 1853 | */ |
| 1854 | 1854 | public function ClearBCCs() { |
| 1855 | - foreach($this->bcc as $bcc) { |
|
| 1856 | - unset($this->all_recipients[strtolower($bcc[0])]); |
|
| 1857 | - } |
|
| 1858 | - $this->bcc = array(); |
|
| 1855 | + foreach($this->bcc as $bcc) { |
|
| 1856 | + unset($this->all_recipients[strtolower($bcc[0])]); |
|
| 1857 | + } |
|
| 1858 | + $this->bcc = array(); |
|
| 1859 | 1859 | } |
| 1860 | 1860 | |
| 1861 | 1861 | /** |
@@ -1863,7 +1863,7 @@ discard block |
||
| 1863 | 1863 | * @return void |
| 1864 | 1864 | */ |
| 1865 | 1865 | public function ClearReplyTos() { |
| 1866 | - $this->ReplyTo = array(); |
|
| 1866 | + $this->ReplyTo = array(); |
|
| 1867 | 1867 | } |
| 1868 | 1868 | |
| 1869 | 1869 | /** |
@@ -1872,10 +1872,10 @@ discard block |
||
| 1872 | 1872 | * @return void |
| 1873 | 1873 | */ |
| 1874 | 1874 | public function ClearAllRecipients() { |
| 1875 | - $this->to = array(); |
|
| 1876 | - $this->cc = array(); |
|
| 1877 | - $this->bcc = array(); |
|
| 1878 | - $this->all_recipients = array(); |
|
| 1875 | + $this->to = array(); |
|
| 1876 | + $this->cc = array(); |
|
| 1877 | + $this->bcc = array(); |
|
| 1878 | + $this->all_recipients = array(); |
|
| 1879 | 1879 | } |
| 1880 | 1880 | |
| 1881 | 1881 | /** |
@@ -1884,7 +1884,7 @@ discard block |
||
| 1884 | 1884 | * @return void |
| 1885 | 1885 | */ |
| 1886 | 1886 | public function ClearAttachments() { |
| 1887 | - $this->attachment = array(); |
|
| 1887 | + $this->attachment = array(); |
|
| 1888 | 1888 | } |
| 1889 | 1889 | |
| 1890 | 1890 | /** |
@@ -1892,7 +1892,7 @@ discard block |
||
| 1892 | 1892 | * @return void |
| 1893 | 1893 | */ |
| 1894 | 1894 | public function ClearCustomHeaders() { |
| 1895 | - $this->CustomHeader = array(); |
|
| 1895 | + $this->CustomHeader = array(); |
|
| 1896 | 1896 | } |
| 1897 | 1897 | |
| 1898 | 1898 | ///////////////////////////////////////////////// |
@@ -1905,14 +1905,14 @@ discard block |
||
| 1905 | 1905 | * @return void |
| 1906 | 1906 | */ |
| 1907 | 1907 | protected function SetError($msg) { |
| 1908 | - $this->error_count++; |
|
| 1909 | - if ($this->Mailer == 'smtp' and !is_null($this->smtp)) { |
|
| 1910 | - $lasterror = $this->smtp->getError(); |
|
| 1911 | - if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) { |
|
| 1912 | - $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n"; |
|
| 1913 | - } |
|
| 1914 | - } |
|
| 1915 | - $this->ErrorInfo = $msg; |
|
| 1908 | + $this->error_count++; |
|
| 1909 | + if ($this->Mailer == 'smtp' and !is_null($this->smtp)) { |
|
| 1910 | + $lasterror = $this->smtp->getError(); |
|
| 1911 | + if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) { |
|
| 1912 | + $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n"; |
|
| 1913 | + } |
|
| 1914 | + } |
|
| 1915 | + $this->ErrorInfo = $msg; |
|
| 1916 | 1916 | } |
| 1917 | 1917 | |
| 1918 | 1918 | /** |
@@ -1922,13 +1922,13 @@ discard block |
||
| 1922 | 1922 | * @static |
| 1923 | 1923 | */ |
| 1924 | 1924 | public static function RFCDate() { |
| 1925 | - $tz = date('Z'); |
|
| 1926 | - $tzs = ($tz < 0) ? '-' : '+'; |
|
| 1927 | - $tz = abs($tz); |
|
| 1928 | - $tz = (int)($tz/3600)*100 + ($tz%3600)/60; |
|
| 1929 | - $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz); |
|
| 1925 | + $tz = date('Z'); |
|
| 1926 | + $tzs = ($tz < 0) ? '-' : '+'; |
|
| 1927 | + $tz = abs($tz); |
|
| 1928 | + $tz = (int)($tz/3600)*100 + ($tz%3600)/60; |
|
| 1929 | + $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz); |
|
| 1930 | 1930 | |
| 1931 | - return $result; |
|
| 1931 | + return $result; |
|
| 1932 | 1932 | } |
| 1933 | 1933 | |
| 1934 | 1934 | /** |
@@ -1937,15 +1937,15 @@ discard block |
||
| 1937 | 1937 | * @return string |
| 1938 | 1938 | */ |
| 1939 | 1939 | private function ServerHostname() { |
| 1940 | - if (!empty($this->Hostname)) { |
|
| 1941 | - $result = $this->Hostname; |
|
| 1942 | - } elseif (isset($_SERVER['SERVER_NAME'])) { |
|
| 1943 | - $result = $_SERVER['SERVER_NAME']; |
|
| 1944 | - } else { |
|
| 1945 | - $result = 'localhost.localdomain'; |
|
| 1946 | - } |
|
| 1940 | + if (!empty($this->Hostname)) { |
|
| 1941 | + $result = $this->Hostname; |
|
| 1942 | + } elseif (isset($_SERVER['SERVER_NAME'])) { |
|
| 1943 | + $result = $_SERVER['SERVER_NAME']; |
|
| 1944 | + } else { |
|
| 1945 | + $result = 'localhost.localdomain'; |
|
| 1946 | + } |
|
| 1947 | 1947 | |
| 1948 | - return $result; |
|
| 1948 | + return $result; |
|
| 1949 | 1949 | } |
| 1950 | 1950 | |
| 1951 | 1951 | /** |
@@ -1954,15 +1954,15 @@ discard block |
||
| 1954 | 1954 | * @return string |
| 1955 | 1955 | */ |
| 1956 | 1956 | private function Lang($key) { |
| 1957 | - if(count($this->language) < 1) { |
|
| 1958 | - $this->SetLanguage('en'); // set the default language |
|
| 1959 | - } |
|
| 1957 | + if(count($this->language) < 1) { |
|
| 1958 | + $this->SetLanguage('en'); // set the default language |
|
| 1959 | + } |
|
| 1960 | 1960 | |
| 1961 | - if(isset($this->language[$key])) { |
|
| 1962 | - return $this->language[$key]; |
|
| 1963 | - } else { |
|
| 1964 | - return 'Language string failed to load: ' . $key; |
|
| 1965 | - } |
|
| 1961 | + if(isset($this->language[$key])) { |
|
| 1962 | + return $this->language[$key]; |
|
| 1963 | + } else { |
|
| 1964 | + return 'Language string failed to load: ' . $key; |
|
| 1965 | + } |
|
| 1966 | 1966 | } |
| 1967 | 1967 | |
| 1968 | 1968 | /** |
@@ -1971,7 +1971,7 @@ discard block |
||
| 1971 | 1971 | * @return bool |
| 1972 | 1972 | */ |
| 1973 | 1973 | public function IsError() { |
| 1974 | - return ($this->error_count > 0); |
|
| 1974 | + return ($this->error_count > 0); |
|
| 1975 | 1975 | } |
| 1976 | 1976 | |
| 1977 | 1977 | /** |
@@ -1980,10 +1980,10 @@ discard block |
||
| 1980 | 1980 | * @return string |
| 1981 | 1981 | */ |
| 1982 | 1982 | private function FixEOL($str) { |
| 1983 | - $str = str_replace("\r\n", "\n", $str); |
|
| 1984 | - $str = str_replace("\r", "\n", $str); |
|
| 1985 | - $str = str_replace("\n", $this->LE, $str); |
|
| 1986 | - return $str; |
|
| 1983 | + $str = str_replace("\r\n", "\n", $str); |
|
| 1984 | + $str = str_replace("\r", "\n", $str); |
|
| 1985 | + $str = str_replace("\n", $this->LE, $str); |
|
| 1986 | + return $str; |
|
| 1987 | 1987 | } |
| 1988 | 1988 | |
| 1989 | 1989 | /** |
@@ -1992,7 +1992,7 @@ discard block |
||
| 1992 | 1992 | * @return void |
| 1993 | 1993 | */ |
| 1994 | 1994 | public function AddCustomHeader($custom_header) { |
| 1995 | - $this->CustomHeader[] = explode(':', $custom_header, 2); |
|
| 1995 | + $this->CustomHeader[] = explode(':', $custom_header, 2); |
|
| 1996 | 1996 | } |
| 1997 | 1997 | |
| 1998 | 1998 | /** |
@@ -2001,34 +2001,34 @@ discard block |
||
| 2001 | 2001 | * @return $message |
| 2002 | 2002 | */ |
| 2003 | 2003 | public function MsgHTML($message,$basedir='') { |
| 2004 | - preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images); |
|
| 2005 | - if(isset($images[2])) { |
|
| 2006 | - foreach($images[2] as $i => $url) { |
|
| 2007 | - // do not change urls for absolute images (thanks to corvuscorax) |
|
| 2008 | - if (!preg_match('#^[A-z]+://#',$url)) { |
|
| 2009 | - $filename = basename($url); |
|
| 2010 | - $directory = dirname($url); |
|
| 2011 | - ($directory == '.')?$directory='':''; |
|
| 2012 | - $cid = 'cid:' . md5($filename); |
|
| 2013 | - $ext = pathinfo($filename, PATHINFO_EXTENSION); |
|
| 2014 | - $mimeType = self::_mime_types($ext); |
|
| 2015 | - if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; } |
|
| 2016 | - if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; } |
|
| 2017 | - if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) { |
|
| 2018 | - $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message); |
|
| 2019 | - } |
|
| 2020 | - } |
|
| 2021 | - } |
|
| 2022 | - } |
|
| 2023 | - $this->IsHTML(true); |
|
| 2024 | - $this->Body = $message; |
|
| 2025 | - $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message))); |
|
| 2026 | - if ( !empty($textMsg) && empty($this->AltBody) ) { |
|
| 2027 | - $this->AltBody = html_entity_decode($textMsg); |
|
| 2028 | - } |
|
| 2029 | - if ( empty($this->AltBody) ) { |
|
| 2030 | - $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; |
|
| 2031 | - } |
|
| 2004 | + preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images); |
|
| 2005 | + if(isset($images[2])) { |
|
| 2006 | + foreach($images[2] as $i => $url) { |
|
| 2007 | + // do not change urls for absolute images (thanks to corvuscorax) |
|
| 2008 | + if (!preg_match('#^[A-z]+://#',$url)) { |
|
| 2009 | + $filename = basename($url); |
|
| 2010 | + $directory = dirname($url); |
|
| 2011 | + ($directory == '.')?$directory='':''; |
|
| 2012 | + $cid = 'cid:' . md5($filename); |
|
| 2013 | + $ext = pathinfo($filename, PATHINFO_EXTENSION); |
|
| 2014 | + $mimeType = self::_mime_types($ext); |
|
| 2015 | + if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; } |
|
| 2016 | + if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; } |
|
| 2017 | + if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) { |
|
| 2018 | + $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message); |
|
| 2019 | + } |
|
| 2020 | + } |
|
| 2021 | + } |
|
| 2022 | + } |
|
| 2023 | + $this->IsHTML(true); |
|
| 2024 | + $this->Body = $message; |
|
| 2025 | + $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message))); |
|
| 2026 | + if ( !empty($textMsg) && empty($this->AltBody) ) { |
|
| 2027 | + $this->AltBody = html_entity_decode($textMsg); |
|
| 2028 | + } |
|
| 2029 | + if ( empty($this->AltBody) ) { |
|
| 2030 | + $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; |
|
| 2031 | + } |
|
| 2032 | 2032 | } |
| 2033 | 2033 | |
| 2034 | 2034 | /** |
@@ -2039,96 +2039,96 @@ discard block |
||
| 2039 | 2039 | * @static |
| 2040 | 2040 | */ |
| 2041 | 2041 | public static function _mime_types($ext = '') { |
| 2042 | - $mimes = array( |
|
| 2043 | - 'hqx' => 'application/mac-binhex40', |
|
| 2044 | - 'cpt' => 'application/mac-compactpro', |
|
| 2045 | - 'doc' => 'application/msword', |
|
| 2046 | - 'bin' => 'application/macbinary', |
|
| 2047 | - 'dms' => 'application/octet-stream', |
|
| 2048 | - 'lha' => 'application/octet-stream', |
|
| 2049 | - 'lzh' => 'application/octet-stream', |
|
| 2050 | - 'exe' => 'application/octet-stream', |
|
| 2051 | - 'class' => 'application/octet-stream', |
|
| 2052 | - 'psd' => 'application/octet-stream', |
|
| 2053 | - 'so' => 'application/octet-stream', |
|
| 2054 | - 'sea' => 'application/octet-stream', |
|
| 2055 | - 'dll' => 'application/octet-stream', |
|
| 2056 | - 'oda' => 'application/oda', |
|
| 2057 | - 'pdf' => 'application/pdf', |
|
| 2058 | - 'ai' => 'application/postscript', |
|
| 2059 | - 'eps' => 'application/postscript', |
|
| 2060 | - 'ps' => 'application/postscript', |
|
| 2061 | - 'smi' => 'application/smil', |
|
| 2062 | - 'smil' => 'application/smil', |
|
| 2063 | - 'mif' => 'application/vnd.mif', |
|
| 2064 | - 'xls' => 'application/vnd.ms-excel', |
|
| 2065 | - 'ppt' => 'application/vnd.ms-powerpoint', |
|
| 2066 | - 'wbxml' => 'application/vnd.wap.wbxml', |
|
| 2067 | - 'wmlc' => 'application/vnd.wap.wmlc', |
|
| 2068 | - 'dcr' => 'application/x-director', |
|
| 2069 | - 'dir' => 'application/x-director', |
|
| 2070 | - 'dxr' => 'application/x-director', |
|
| 2071 | - 'dvi' => 'application/x-dvi', |
|
| 2072 | - 'gtar' => 'application/x-gtar', |
|
| 2073 | - 'php' => 'application/x-httpd-php', |
|
| 2074 | - 'php4' => 'application/x-httpd-php', |
|
| 2075 | - 'php3' => 'application/x-httpd-php', |
|
| 2076 | - 'phtml' => 'application/x-httpd-php', |
|
| 2077 | - 'phps' => 'application/x-httpd-php-source', |
|
| 2078 | - 'js' => 'application/x-javascript', |
|
| 2079 | - 'swf' => 'application/x-shockwave-flash', |
|
| 2080 | - 'sit' => 'application/x-stuffit', |
|
| 2081 | - 'tar' => 'application/x-tar', |
|
| 2082 | - 'tgz' => 'application/x-tar', |
|
| 2083 | - 'xhtml' => 'application/xhtml+xml', |
|
| 2084 | - 'xht' => 'application/xhtml+xml', |
|
| 2085 | - 'zip' => 'application/zip', |
|
| 2086 | - 'mid' => 'audio/midi', |
|
| 2087 | - 'midi' => 'audio/midi', |
|
| 2088 | - 'mpga' => 'audio/mpeg', |
|
| 2089 | - 'mp2' => 'audio/mpeg', |
|
| 2090 | - 'mp3' => 'audio/mpeg', |
|
| 2091 | - 'aif' => 'audio/x-aiff', |
|
| 2092 | - 'aiff' => 'audio/x-aiff', |
|
| 2093 | - 'aifc' => 'audio/x-aiff', |
|
| 2094 | - 'ram' => 'audio/x-pn-realaudio', |
|
| 2095 | - 'rm' => 'audio/x-pn-realaudio', |
|
| 2096 | - 'rpm' => 'audio/x-pn-realaudio-plugin', |
|
| 2097 | - 'ra' => 'audio/x-realaudio', |
|
| 2098 | - 'rv' => 'video/vnd.rn-realvideo', |
|
| 2099 | - 'wav' => 'audio/x-wav', |
|
| 2100 | - 'bmp' => 'image/bmp', |
|
| 2101 | - 'gif' => 'image/gif', |
|
| 2102 | - 'jpeg' => 'image/jpeg', |
|
| 2103 | - 'jpg' => 'image/jpeg', |
|
| 2104 | - 'jpe' => 'image/jpeg', |
|
| 2105 | - 'png' => 'image/png', |
|
| 2106 | - 'tiff' => 'image/tiff', |
|
| 2107 | - 'tif' => 'image/tiff', |
|
| 2108 | - 'css' => 'text/css', |
|
| 2109 | - 'html' => 'text/html', |
|
| 2110 | - 'htm' => 'text/html', |
|
| 2111 | - 'shtml' => 'text/html', |
|
| 2112 | - 'txt' => 'text/plain', |
|
| 2113 | - 'text' => 'text/plain', |
|
| 2114 | - 'log' => 'text/plain', |
|
| 2115 | - 'rtx' => 'text/richtext', |
|
| 2116 | - 'rtf' => 'text/rtf', |
|
| 2117 | - 'xml' => 'text/xml', |
|
| 2118 | - 'xsl' => 'text/xml', |
|
| 2119 | - 'mpeg' => 'video/mpeg', |
|
| 2120 | - 'mpg' => 'video/mpeg', |
|
| 2121 | - 'mpe' => 'video/mpeg', |
|
| 2122 | - 'qt' => 'video/quicktime', |
|
| 2123 | - 'mov' => 'video/quicktime', |
|
| 2124 | - 'avi' => 'video/x-msvideo', |
|
| 2125 | - 'movie' => 'video/x-sgi-movie', |
|
| 2126 | - 'doc' => 'application/msword', |
|
| 2127 | - 'word' => 'application/msword', |
|
| 2128 | - 'xl' => 'application/excel', |
|
| 2129 | - 'eml' => 'message/rfc822' |
|
| 2130 | - ); |
|
| 2131 | - return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; |
|
| 2042 | + $mimes = array( |
|
| 2043 | + 'hqx' => 'application/mac-binhex40', |
|
| 2044 | + 'cpt' => 'application/mac-compactpro', |
|
| 2045 | + 'doc' => 'application/msword', |
|
| 2046 | + 'bin' => 'application/macbinary', |
|
| 2047 | + 'dms' => 'application/octet-stream', |
|
| 2048 | + 'lha' => 'application/octet-stream', |
|
| 2049 | + 'lzh' => 'application/octet-stream', |
|
| 2050 | + 'exe' => 'application/octet-stream', |
|
| 2051 | + 'class' => 'application/octet-stream', |
|
| 2052 | + 'psd' => 'application/octet-stream', |
|
| 2053 | + 'so' => 'application/octet-stream', |
|
| 2054 | + 'sea' => 'application/octet-stream', |
|
| 2055 | + 'dll' => 'application/octet-stream', |
|
| 2056 | + 'oda' => 'application/oda', |
|
| 2057 | + 'pdf' => 'application/pdf', |
|
| 2058 | + 'ai' => 'application/postscript', |
|
| 2059 | + 'eps' => 'application/postscript', |
|
| 2060 | + 'ps' => 'application/postscript', |
|
| 2061 | + 'smi' => 'application/smil', |
|
| 2062 | + 'smil' => 'application/smil', |
|
| 2063 | + 'mif' => 'application/vnd.mif', |
|
| 2064 | + 'xls' => 'application/vnd.ms-excel', |
|
| 2065 | + 'ppt' => 'application/vnd.ms-powerpoint', |
|
| 2066 | + 'wbxml' => 'application/vnd.wap.wbxml', |
|
| 2067 | + 'wmlc' => 'application/vnd.wap.wmlc', |
|
| 2068 | + 'dcr' => 'application/x-director', |
|
| 2069 | + 'dir' => 'application/x-director', |
|
| 2070 | + 'dxr' => 'application/x-director', |
|
| 2071 | + 'dvi' => 'application/x-dvi', |
|
| 2072 | + 'gtar' => 'application/x-gtar', |
|
| 2073 | + 'php' => 'application/x-httpd-php', |
|
| 2074 | + 'php4' => 'application/x-httpd-php', |
|
| 2075 | + 'php3' => 'application/x-httpd-php', |
|
| 2076 | + 'phtml' => 'application/x-httpd-php', |
|
| 2077 | + 'phps' => 'application/x-httpd-php-source', |
|
| 2078 | + 'js' => 'application/x-javascript', |
|
| 2079 | + 'swf' => 'application/x-shockwave-flash', |
|
| 2080 | + 'sit' => 'application/x-stuffit', |
|
| 2081 | + 'tar' => 'application/x-tar', |
|
| 2082 | + 'tgz' => 'application/x-tar', |
|
| 2083 | + 'xhtml' => 'application/xhtml+xml', |
|
| 2084 | + 'xht' => 'application/xhtml+xml', |
|
| 2085 | + 'zip' => 'application/zip', |
|
| 2086 | + 'mid' => 'audio/midi', |
|
| 2087 | + 'midi' => 'audio/midi', |
|
| 2088 | + 'mpga' => 'audio/mpeg', |
|
| 2089 | + 'mp2' => 'audio/mpeg', |
|
| 2090 | + 'mp3' => 'audio/mpeg', |
|
| 2091 | + 'aif' => 'audio/x-aiff', |
|
| 2092 | + 'aiff' => 'audio/x-aiff', |
|
| 2093 | + 'aifc' => 'audio/x-aiff', |
|
| 2094 | + 'ram' => 'audio/x-pn-realaudio', |
|
| 2095 | + 'rm' => 'audio/x-pn-realaudio', |
|
| 2096 | + 'rpm' => 'audio/x-pn-realaudio-plugin', |
|
| 2097 | + 'ra' => 'audio/x-realaudio', |
|
| 2098 | + 'rv' => 'video/vnd.rn-realvideo', |
|
| 2099 | + 'wav' => 'audio/x-wav', |
|
| 2100 | + 'bmp' => 'image/bmp', |
|
| 2101 | + 'gif' => 'image/gif', |
|
| 2102 | + 'jpeg' => 'image/jpeg', |
|
| 2103 | + 'jpg' => 'image/jpeg', |
|
| 2104 | + 'jpe' => 'image/jpeg', |
|
| 2105 | + 'png' => 'image/png', |
|
| 2106 | + 'tiff' => 'image/tiff', |
|
| 2107 | + 'tif' => 'image/tiff', |
|
| 2108 | + 'css' => 'text/css', |
|
| 2109 | + 'html' => 'text/html', |
|
| 2110 | + 'htm' => 'text/html', |
|
| 2111 | + 'shtml' => 'text/html', |
|
| 2112 | + 'txt' => 'text/plain', |
|
| 2113 | + 'text' => 'text/plain', |
|
| 2114 | + 'log' => 'text/plain', |
|
| 2115 | + 'rtx' => 'text/richtext', |
|
| 2116 | + 'rtf' => 'text/rtf', |
|
| 2117 | + 'xml' => 'text/xml', |
|
| 2118 | + 'xsl' => 'text/xml', |
|
| 2119 | + 'mpeg' => 'video/mpeg', |
|
| 2120 | + 'mpg' => 'video/mpeg', |
|
| 2121 | + 'mpe' => 'video/mpeg', |
|
| 2122 | + 'qt' => 'video/quicktime', |
|
| 2123 | + 'mov' => 'video/quicktime', |
|
| 2124 | + 'avi' => 'video/x-msvideo', |
|
| 2125 | + 'movie' => 'video/x-sgi-movie', |
|
| 2126 | + 'doc' => 'application/msword', |
|
| 2127 | + 'word' => 'application/msword', |
|
| 2128 | + 'xl' => 'application/excel', |
|
| 2129 | + 'eml' => 'message/rfc822' |
|
| 2130 | + ); |
|
| 2131 | + return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; |
|
| 2132 | 2132 | } |
| 2133 | 2133 | |
| 2134 | 2134 | /** |
@@ -2141,22 +2141,22 @@ discard block |
||
| 2141 | 2141 | * @param string $name Parameter Name |
| 2142 | 2142 | * @param mixed $value Parameter Value |
| 2143 | 2143 | * NOTE: will not work with arrays, there are no arrays to set/reset |
| 2144 | - * @todo Should this not be using __set() magic function? |
|
| 2144 | + * @todo Should this not be using __set() magic function? |
|
| 2145 | 2145 | */ |
| 2146 | 2146 | public function set ( $name, $value = '' ) { |
| 2147 | - try { |
|
| 2148 | - if ( isset($this->$name) ) { |
|
| 2149 | - $this->$name = $value; |
|
| 2150 | - } else { |
|
| 2151 | - throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL); |
|
| 2147 | + try { |
|
| 2148 | + if ( isset($this->$name) ) { |
|
| 2149 | + $this->$name = $value; |
|
| 2150 | + } else { |
|
| 2151 | + throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL); |
|
| 2152 | 2152 | } |
| 2153 | - } catch (Exception $e) { |
|
| 2154 | - $this->SetError($e->getMessage()); |
|
| 2155 | - if ($e->getCode() == self::STOP_CRITICAL) { |
|
| 2156 | - return false; |
|
| 2157 | - } |
|
| 2153 | + } catch (Exception $e) { |
|
| 2154 | + $this->SetError($e->getMessage()); |
|
| 2155 | + if ($e->getCode() == self::STOP_CRITICAL) { |
|
| 2156 | + return false; |
|
| 2157 | + } |
|
| 2158 | 2158 | } |
| 2159 | - return true; |
|
| 2159 | + return true; |
|
| 2160 | 2160 | } |
| 2161 | 2161 | |
| 2162 | 2162 | /** |
@@ -2166,9 +2166,9 @@ discard block |
||
| 2166 | 2166 | * @return string |
| 2167 | 2167 | */ |
| 2168 | 2168 | public function SecureHeader($str) { |
| 2169 | - $str = str_replace("\r", '', $str); |
|
| 2170 | - $str = str_replace("\n", '', $str); |
|
| 2171 | - return trim($str); |
|
| 2169 | + $str = str_replace("\r", '', $str); |
|
| 2170 | + $str = str_replace("\n", '', $str); |
|
| 2171 | + return trim($str); |
|
| 2172 | 2172 | } |
| 2173 | 2173 | |
| 2174 | 2174 | /** |
@@ -2179,9 +2179,9 @@ discard block |
||
| 2179 | 2179 | * @param string $key_pass Password for private key |
| 2180 | 2180 | */ |
| 2181 | 2181 | public function Sign($cert_filename, $key_filename, $key_pass) { |
| 2182 | - $this->sign_cert_file = $cert_filename; |
|
| 2183 | - $this->sign_key_file = $key_filename; |
|
| 2184 | - $this->sign_key_pass = $key_pass; |
|
| 2182 | + $this->sign_cert_file = $cert_filename; |
|
| 2183 | + $this->sign_key_file = $key_filename; |
|
| 2184 | + $this->sign_key_pass = $key_pass; |
|
| 2185 | 2185 | } |
| 2186 | 2186 | |
| 2187 | 2187 | /** |
@@ -2192,17 +2192,17 @@ discard block |
||
| 2192 | 2192 | * @param string $key_pass Password for private key |
| 2193 | 2193 | */ |
| 2194 | 2194 | public function DKIM_QP($txt) { |
| 2195 | - $tmp=""; |
|
| 2196 | - $line=""; |
|
| 2197 | - for ($i=0;$i<strlen($txt);$i++) { |
|
| 2198 | - $ord=ord($txt[$i]); |
|
| 2199 | - if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) { |
|
| 2200 | - $line.=$txt[$i]; |
|
| 2201 | - } else { |
|
| 2202 | - $line.="=".sprintf("%02X",$ord); |
|
| 2203 | - } |
|
| 2204 | - } |
|
| 2205 | - return $line; |
|
| 2195 | + $tmp=""; |
|
| 2196 | + $line=""; |
|
| 2197 | + for ($i=0;$i<strlen($txt);$i++) { |
|
| 2198 | + $ord=ord($txt[$i]); |
|
| 2199 | + if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) { |
|
| 2200 | + $line.=$txt[$i]; |
|
| 2201 | + } else { |
|
| 2202 | + $line.="=".sprintf("%02X",$ord); |
|
| 2203 | + } |
|
| 2204 | + } |
|
| 2205 | + return $line; |
|
| 2206 | 2206 | } |
| 2207 | 2207 | |
| 2208 | 2208 | /** |
@@ -2212,15 +2212,15 @@ discard block |
||
| 2212 | 2212 | * @param string $s Header |
| 2213 | 2213 | */ |
| 2214 | 2214 | public function DKIM_Sign($s) { |
| 2215 | - $privKeyStr = file_get_contents($this->DKIM_private); |
|
| 2216 | - if ($this->DKIM_passphrase!='') { |
|
| 2217 | - $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase); |
|
| 2218 | - } else { |
|
| 2219 | - $privKey = $privKeyStr; |
|
| 2220 | - } |
|
| 2221 | - if (openssl_sign($s, $signature, $privKey)) { |
|
| 2222 | - return base64_encode($signature); |
|
| 2223 | - } |
|
| 2215 | + $privKeyStr = file_get_contents($this->DKIM_private); |
|
| 2216 | + if ($this->DKIM_passphrase!='') { |
|
| 2217 | + $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase); |
|
| 2218 | + } else { |
|
| 2219 | + $privKey = $privKeyStr; |
|
| 2220 | + } |
|
| 2221 | + if (openssl_sign($s, $signature, $privKey)) { |
|
| 2222 | + return base64_encode($signature); |
|
| 2223 | + } |
|
| 2224 | 2224 | } |
| 2225 | 2225 | |
| 2226 | 2226 | /** |
@@ -2230,16 +2230,16 @@ discard block |
||
| 2230 | 2230 | * @param string $s Header |
| 2231 | 2231 | */ |
| 2232 | 2232 | public function DKIM_HeaderC($s) { |
| 2233 | - $s=preg_replace("/\r\n\s+/"," ",$s); |
|
| 2234 | - $lines=explode("\r\n",$s); |
|
| 2235 | - foreach ($lines as $key=>$line) { |
|
| 2236 | - list($heading,$value)=explode(":",$line,2); |
|
| 2237 | - $heading=strtolower($heading); |
|
| 2238 | - $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces |
|
| 2239 | - $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value |
|
| 2240 | - } |
|
| 2241 | - $s=implode("\r\n",$lines); |
|
| 2242 | - return $s; |
|
| 2233 | + $s=preg_replace("/\r\n\s+/"," ",$s); |
|
| 2234 | + $lines=explode("\r\n",$s); |
|
| 2235 | + foreach ($lines as $key=>$line) { |
|
| 2236 | + list($heading,$value)=explode(":",$line,2); |
|
| 2237 | + $heading=strtolower($heading); |
|
| 2238 | + $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces |
|
| 2239 | + $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value |
|
| 2240 | + } |
|
| 2241 | + $s=implode("\r\n",$lines); |
|
| 2242 | + return $s; |
|
| 2243 | 2243 | } |
| 2244 | 2244 | |
| 2245 | 2245 | /** |
@@ -2249,15 +2249,15 @@ discard block |
||
| 2249 | 2249 | * @param string $body Message Body |
| 2250 | 2250 | */ |
| 2251 | 2251 | public function DKIM_BodyC($body) { |
| 2252 | - if ($body == '') return "\r\n"; |
|
| 2253 | - // stabilize line endings |
|
| 2254 | - $body=str_replace("\r\n","\n",$body); |
|
| 2255 | - $body=str_replace("\n","\r\n",$body); |
|
| 2256 | - // END stabilize line endings |
|
| 2257 | - while (substr($body,strlen($body)-4,4) == "\r\n\r\n") { |
|
| 2258 | - $body=substr($body,0,strlen($body)-2); |
|
| 2259 | - } |
|
| 2260 | - return $body; |
|
| 2252 | + if ($body == '') return "\r\n"; |
|
| 2253 | + // stabilize line endings |
|
| 2254 | + $body=str_replace("\r\n","\n",$body); |
|
| 2255 | + $body=str_replace("\n","\r\n",$body); |
|
| 2256 | + // END stabilize line endings |
|
| 2257 | + while (substr($body,strlen($body)-4,4) == "\r\n\r\n") { |
|
| 2258 | + $body=substr($body,0,strlen($body)-2); |
|
| 2259 | + } |
|
| 2260 | + return $body; |
|
| 2261 | 2261 | } |
| 2262 | 2262 | |
| 2263 | 2263 | /** |
@@ -2269,52 +2269,52 @@ discard block |
||
| 2269 | 2269 | * @param string $body Body |
| 2270 | 2270 | */ |
| 2271 | 2271 | public function DKIM_Add($headers_line,$subject,$body) { |
| 2272 | - $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms |
|
| 2273 | - $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body |
|
| 2274 | - $DKIMquery = 'dns/txt'; // Query method |
|
| 2275 | - $DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) |
|
| 2276 | - $subject_header = "Subject: $subject"; |
|
| 2277 | - $headers = explode("\r\n",$headers_line); |
|
| 2278 | - foreach($headers as $header) { |
|
| 2279 | - if (strpos($header,'From:') === 0) { |
|
| 2280 | - $from_header=$header; |
|
| 2281 | - } elseif (strpos($header,'To:') === 0) { |
|
| 2282 | - $to_header=$header; |
|
| 2283 | - } |
|
| 2284 | - } |
|
| 2285 | - $from = str_replace('|','=7C',$this->DKIM_QP($from_header)); |
|
| 2286 | - $to = str_replace('|','=7C',$this->DKIM_QP($to_header)); |
|
| 2287 | - $subject = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable |
|
| 2288 | - $body = $this->DKIM_BodyC($body); |
|
| 2289 | - $DKIMlen = strlen($body) ; // Length of body |
|
| 2290 | - $DKIMb64 = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body |
|
| 2291 | - $ident = ($this->DKIM_identity == '')? '' : " i=" . $this->DKIM_identity . ";"; |
|
| 2292 | - $dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n". |
|
| 2293 | - "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n". |
|
| 2294 | - "\th=From:To:Subject;\r\n". |
|
| 2295 | - "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n". |
|
| 2296 | - "\tz=$from\r\n". |
|
| 2297 | - "\t|$to\r\n". |
|
| 2298 | - "\t|$subject;\r\n". |
|
| 2299 | - "\tbh=" . $DKIMb64 . ";\r\n". |
|
| 2300 | - "\tb="; |
|
| 2301 | - $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs); |
|
| 2302 | - $signed = $this->DKIM_Sign($toSign); |
|
| 2303 | - return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n"; |
|
| 2272 | + $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms |
|
| 2273 | + $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body |
|
| 2274 | + $DKIMquery = 'dns/txt'; // Query method |
|
| 2275 | + $DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) |
|
| 2276 | + $subject_header = "Subject: $subject"; |
|
| 2277 | + $headers = explode("\r\n",$headers_line); |
|
| 2278 | + foreach($headers as $header) { |
|
| 2279 | + if (strpos($header,'From:') === 0) { |
|
| 2280 | + $from_header=$header; |
|
| 2281 | + } elseif (strpos($header,'To:') === 0) { |
|
| 2282 | + $to_header=$header; |
|
| 2283 | + } |
|
| 2284 | + } |
|
| 2285 | + $from = str_replace('|','=7C',$this->DKIM_QP($from_header)); |
|
| 2286 | + $to = str_replace('|','=7C',$this->DKIM_QP($to_header)); |
|
| 2287 | + $subject = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable |
|
| 2288 | + $body = $this->DKIM_BodyC($body); |
|
| 2289 | + $DKIMlen = strlen($body) ; // Length of body |
|
| 2290 | + $DKIMb64 = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body |
|
| 2291 | + $ident = ($this->DKIM_identity == '')? '' : " i=" . $this->DKIM_identity . ";"; |
|
| 2292 | + $dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n". |
|
| 2293 | + "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n". |
|
| 2294 | + "\th=From:To:Subject;\r\n". |
|
| 2295 | + "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n". |
|
| 2296 | + "\tz=$from\r\n". |
|
| 2297 | + "\t|$to\r\n". |
|
| 2298 | + "\t|$subject;\r\n". |
|
| 2299 | + "\tbh=" . $DKIMb64 . ";\r\n". |
|
| 2300 | + "\tb="; |
|
| 2301 | + $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs); |
|
| 2302 | + $signed = $this->DKIM_Sign($toSign); |
|
| 2303 | + return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n"; |
|
| 2304 | 2304 | } |
| 2305 | 2305 | |
| 2306 | 2306 | protected function doCallback($isSent,$to,$cc,$bcc,$subject,$body) { |
| 2307 | - if (!empty($this->action_function) && function_exists($this->action_function)) { |
|
| 2308 | - $params = array($isSent,$to,$cc,$bcc,$subject,$body); |
|
| 2309 | - call_user_func_array($this->action_function,$params); |
|
| 2310 | - } |
|
| 2307 | + if (!empty($this->action_function) && function_exists($this->action_function)) { |
|
| 2308 | + $params = array($isSent,$to,$cc,$bcc,$subject,$body); |
|
| 2309 | + call_user_func_array($this->action_function,$params); |
|
| 2310 | + } |
|
| 2311 | 2311 | } |
| 2312 | 2312 | } |
| 2313 | 2313 | |
| 2314 | 2314 | class phpmailerException extends Exception { |
| 2315 | 2315 | public function errorMessage() { |
| 2316 | - $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n"; |
|
| 2317 | - return $errorMsg; |
|
| 2316 | + $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n"; |
|
| 2317 | + return $errorMsg; |
|
| 2318 | 2318 | } |
| 2319 | 2319 | } |
| 2320 | 2320 | ?> |
| 2321 | 2321 | \ No newline at end of file |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
| 39 | 39 | */ |
| 40 | 40 | |
| 41 | -if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n"); |
|
| 41 | +if (version_compare(PHP_VERSION, '5.0.0', '<')) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n"); |
|
| 42 | 42 | |
| 43 | 43 | class PHPMailer { |
| 44 | 44 | |
@@ -50,64 +50,64 @@ discard block |
||
| 50 | 50 | * Email priority (1 = High, 3 = Normal, 5 = low). |
| 51 | 51 | * @var int |
| 52 | 52 | */ |
| 53 | - public $Priority = 3; |
|
| 53 | + public $Priority = 3; |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Sets the CharSet of the message. |
| 57 | 57 | * @var string |
| 58 | 58 | */ |
| 59 | - public $CharSet = 'utf-8'; |
|
| 59 | + public $CharSet = 'utf-8'; |
|
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * Sets the Content-type of the message. |
| 63 | 63 | * @var string |
| 64 | 64 | */ |
| 65 | - public $ContentType = 'text/plain'; |
|
| 65 | + public $ContentType = 'text/plain'; |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * Sets the Encoding of the message. Options for this are |
| 69 | 69 | * "8bit", "7bit", "binary", "base64", and "quoted-printable". |
| 70 | 70 | * @var string |
| 71 | 71 | */ |
| 72 | - public $Encoding = '8bit'; |
|
| 72 | + public $Encoding = '8bit'; |
|
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * Holds the most recent mailer error message. |
| 76 | 76 | * @var string |
| 77 | 77 | */ |
| 78 | - public $ErrorInfo = ''; |
|
| 78 | + public $ErrorInfo = ''; |
|
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * Sets the From email address for the message. |
| 82 | 82 | * @var string |
| 83 | 83 | */ |
| 84 | - public $From = 'root@localhost'; |
|
| 84 | + public $From = 'root@localhost'; |
|
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | 87 | * Sets the From name of the message. |
| 88 | 88 | * @var string |
| 89 | 89 | */ |
| 90 | - public $FromName = 'Root User'; |
|
| 90 | + public $FromName = 'Root User'; |
|
| 91 | 91 | |
| 92 | 92 | /** |
| 93 | 93 | * Sets the Sender email (Return-Path) of the message. If not empty, |
| 94 | 94 | * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. |
| 95 | 95 | * @var string |
| 96 | 96 | */ |
| 97 | - public $Sender = ''; |
|
| 97 | + public $Sender = ''; |
|
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * Sets the Subject of the message. |
| 101 | 101 | * @var string |
| 102 | 102 | */ |
| 103 | - public $Subject = ''; |
|
| 103 | + public $Subject = ''; |
|
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | 106 | * Sets the Body of the message. This can be either an HTML or text body. |
| 107 | 107 | * If HTML then run IsHTML(true). |
| 108 | 108 | * @var string |
| 109 | 109 | */ |
| 110 | - public $Body = ''; |
|
| 110 | + public $Body = ''; |
|
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | 113 | * Sets the text-only body of the message. This automatically sets the |
@@ -116,39 +116,39 @@ discard block |
||
| 116 | 116 | * that can read HTML will view the normal Body. |
| 117 | 117 | * @var string |
| 118 | 118 | */ |
| 119 | - public $AltBody = ''; |
|
| 119 | + public $AltBody = ''; |
|
| 120 | 120 | |
| 121 | 121 | /** |
| 122 | 122 | * Sets word wrapping on the body of the message to a given number of |
| 123 | 123 | * characters. |
| 124 | 124 | * @var int |
| 125 | 125 | */ |
| 126 | - public $WordWrap = 0; |
|
| 126 | + public $WordWrap = 0; |
|
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | 129 | * Method to send mail: ("mail", "sendmail", or "smtp"). |
| 130 | 130 | * @var string |
| 131 | 131 | */ |
| 132 | - public $Mailer = 'mail'; |
|
| 132 | + public $Mailer = 'mail'; |
|
| 133 | 133 | |
| 134 | 134 | /** |
| 135 | 135 | * Sets the path of the sendmail program. |
| 136 | 136 | * @var string |
| 137 | 137 | */ |
| 138 | - public $Sendmail = '/usr/sbin/sendmail'; |
|
| 138 | + public $Sendmail = '/usr/sbin/sendmail'; |
|
| 139 | 139 | |
| 140 | 140 | /** |
| 141 | 141 | * Path to PHPMailer plugins. Useful if the SMTP class |
| 142 | 142 | * is in a different directory than the PHP include path. |
| 143 | 143 | * @var string |
| 144 | 144 | */ |
| 145 | - public $PluginDir = ''; |
|
| 145 | + public $PluginDir = ''; |
|
| 146 | 146 | |
| 147 | 147 | /** |
| 148 | 148 | * Sets the email address that a reading confirmation will be sent. |
| 149 | 149 | * @var string |
| 150 | 150 | */ |
| 151 | - public $ConfirmReadingTo = ''; |
|
| 151 | + public $ConfirmReadingTo = ''; |
|
| 152 | 152 | |
| 153 | 153 | /** |
| 154 | 154 | * Sets the hostname to use in Message-Id and Received headers |
@@ -156,14 +156,14 @@ discard block |
||
| 156 | 156 | * by SERVER_NAME is used or 'localhost.localdomain'. |
| 157 | 157 | * @var string |
| 158 | 158 | */ |
| 159 | - public $Hostname = ''; |
|
| 159 | + public $Hostname = ''; |
|
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | 162 | * Sets the message ID to be used in the Message-Id header. |
| 163 | 163 | * If empty, a unique id will be generated. |
| 164 | 164 | * @var string |
| 165 | 165 | */ |
| 166 | - public $MessageID = ''; |
|
| 166 | + public $MessageID = ''; |
|
| 167 | 167 | |
| 168 | 168 | ///////////////////////////////////////////////// |
| 169 | 169 | // PROPERTIES FOR SMTP |
@@ -177,57 +177,57 @@ discard block |
||
| 177 | 177 | * Hosts will be tried in order. |
| 178 | 178 | * @var string |
| 179 | 179 | */ |
| 180 | - public $Host = 'localhost'; |
|
| 180 | + public $Host = 'localhost'; |
|
| 181 | 181 | |
| 182 | 182 | /** |
| 183 | 183 | * Sets the default SMTP server port. |
| 184 | 184 | * @var int |
| 185 | 185 | */ |
| 186 | - public $Port = 25; |
|
| 186 | + public $Port = 25; |
|
| 187 | 187 | |
| 188 | 188 | /** |
| 189 | 189 | * Sets the SMTP HELO of the message (Default is $Hostname). |
| 190 | 190 | * @var string |
| 191 | 191 | */ |
| 192 | - public $Helo = ''; |
|
| 192 | + public $Helo = ''; |
|
| 193 | 193 | |
| 194 | 194 | /** |
| 195 | 195 | * Sets connection prefix. |
| 196 | 196 | * Options are "", "ssl" or "tls" |
| 197 | 197 | * @var string |
| 198 | 198 | */ |
| 199 | - public $SMTPSecure = ''; |
|
| 199 | + public $SMTPSecure = ''; |
|
| 200 | 200 | |
| 201 | 201 | /** |
| 202 | 202 | * Sets SMTP authentication. Utilizes the Username and Password variables. |
| 203 | 203 | * @var bool |
| 204 | 204 | */ |
| 205 | - public $SMTPAuth = false; |
|
| 205 | + public $SMTPAuth = false; |
|
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | 208 | * Sets SMTP username. |
| 209 | 209 | * @var string |
| 210 | 210 | */ |
| 211 | - public $Username = ''; |
|
| 211 | + public $Username = ''; |
|
| 212 | 212 | |
| 213 | 213 | /** |
| 214 | 214 | * Sets SMTP password. |
| 215 | 215 | * @var string |
| 216 | 216 | */ |
| 217 | - public $Password = ''; |
|
| 217 | + public $Password = ''; |
|
| 218 | 218 | |
| 219 | 219 | /** |
| 220 | 220 | * Sets the SMTP server timeout in seconds. |
| 221 | 221 | * This function will not work with the win32 version. |
| 222 | 222 | * @var int |
| 223 | 223 | */ |
| 224 | - public $Timeout = 10; |
|
| 224 | + public $Timeout = 10; |
|
| 225 | 225 | |
| 226 | 226 | /** |
| 227 | 227 | * Sets SMTP class debugging on or off. |
| 228 | 228 | * @var bool |
| 229 | 229 | */ |
| 230 | - public $SMTPDebug = false; |
|
| 230 | + public $SMTPDebug = false; |
|
| 231 | 231 | |
| 232 | 232 | /** |
| 233 | 233 | * Prevents the SMTP connection from being closed after each mail |
@@ -254,34 +254,34 @@ discard block |
||
| 254 | 254 | * Provides the ability to change the line ending |
| 255 | 255 | * @var string |
| 256 | 256 | */ |
| 257 | - public $LE = "\n"; |
|
| 257 | + public $LE = "\n"; |
|
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | 260 | * Used with DKIM DNS Resource Record |
| 261 | 261 | * @var string |
| 262 | 262 | */ |
| 263 | - public $DKIM_selector = 'phpmailer'; |
|
| 263 | + public $DKIM_selector = 'phpmailer'; |
|
| 264 | 264 | |
| 265 | 265 | /** |
| 266 | 266 | * Used with DKIM DNS Resource Record |
| 267 | 267 | * optional, in format of email address '[email protected]' |
| 268 | 268 | * @var string |
| 269 | 269 | */ |
| 270 | - public $DKIM_identity = ''; |
|
| 270 | + public $DKIM_identity = ''; |
|
| 271 | 271 | |
| 272 | 272 | /** |
| 273 | 273 | * Used with DKIM DNS Resource Record |
| 274 | 274 | * optional, in format of email address '[email protected]' |
| 275 | 275 | * @var string |
| 276 | 276 | */ |
| 277 | - public $DKIM_domain = ''; |
|
| 277 | + public $DKIM_domain = ''; |
|
| 278 | 278 | |
| 279 | 279 | /** |
| 280 | 280 | * Used with DKIM DNS Resource Record |
| 281 | 281 | * optional, in format of email address '[email protected]' |
| 282 | 282 | * @var string |
| 283 | 283 | */ |
| 284 | - public $DKIM_private = ''; |
|
| 284 | + public $DKIM_private = ''; |
|
| 285 | 285 | |
| 286 | 286 | /** |
| 287 | 287 | * Callback Action function name |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | * Sets the PHPMailer Version number |
| 301 | 301 | * @var string |
| 302 | 302 | */ |
| 303 | - public $Version = '5.1'; |
|
| 303 | + public $Version = '5.1'; |
|
| 304 | 304 | |
| 305 | 305 | ///////////////////////////////////////////////// |
| 306 | 306 | // PROPERTIES, PRIVATE AND PROTECTED |
@@ -316,12 +316,12 @@ discard block |
||
| 316 | 316 | private $CustomHeader = array(); |
| 317 | 317 | private $message_type = ''; |
| 318 | 318 | private $boundary = array(); |
| 319 | - protected $language = array(); |
|
| 319 | + protected $language = array(); |
|
| 320 | 320 | private $error_count = 0; |
| 321 | 321 | private $sign_cert_file = ""; |
| 322 | 322 | private $sign_key_file = ""; |
| 323 | 323 | private $sign_key_pass = ""; |
| 324 | - private $exceptions = false; |
|
| 324 | + private $exceptions = false; |
|
| 325 | 325 | |
| 326 | 326 | ///////////////////////////////////////////////// |
| 327 | 327 | // CONSTANTS |
@@ -451,13 +451,13 @@ discard block |
||
| 451 | 451 | */ |
| 452 | 452 | private function AddAnAddress($kind, $address, $name = '') { |
| 453 | 453 | if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) { |
| 454 | - echo 'Invalid recipient array: ' . kind; |
|
| 454 | + echo 'Invalid recipient array: '.kind; |
|
| 455 | 455 | return false; |
| 456 | 456 | } |
| 457 | 457 | $address = trim($address); |
| 458 | 458 | $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim |
| 459 | 459 | if (!self::ValidateAddress($address)) { |
| 460 | - $this->SetError($this->Lang('invalid_address').': '. $address); |
|
| 460 | + $this->SetError($this->Lang('invalid_address').': '.$address); |
|
| 461 | 461 | if ($this->exceptions) { |
| 462 | 462 | throw new phpmailerException($this->Lang('invalid_address').': '.$address); |
| 463 | 463 | } |
@@ -485,11 +485,11 @@ discard block |
||
| 485 | 485 | * @param string $name |
| 486 | 486 | * @return boolean |
| 487 | 487 | */ |
| 488 | - public function SetFrom($address, $name = '',$auto=1) { |
|
| 488 | + public function SetFrom($address, $name = '', $auto = 1) { |
|
| 489 | 489 | $address = trim($address); |
| 490 | 490 | $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim |
| 491 | 491 | if (!self::ValidateAddress($address)) { |
| 492 | - $this->SetError($this->Lang('invalid_address').': '. $address); |
|
| 492 | + $this->SetError($this->Lang('invalid_address').': '.$address); |
|
| 493 | 493 | if ($this->exceptions) { |
| 494 | 494 | throw new phpmailerException($this->Lang('invalid_address').': '.$address); |
| 495 | 495 | } |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | */ |
| 523 | 523 | public static function ValidateAddress($address) { |
| 524 | 524 | if (function_exists('filter_var')) { //Introduced in PHP 5.2 |
| 525 | - if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) { |
|
| 525 | + if (filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) { |
|
| 526 | 526 | return false; |
| 527 | 527 | } else { |
| 528 | 528 | return true; |
@@ -544,12 +544,12 @@ discard block |
||
| 544 | 544 | */ |
| 545 | 545 | public function Send() { |
| 546 | 546 | try { |
| 547 | - if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
|
| 547 | + if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
|
| 548 | 548 | throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); |
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | // Set whether the message is multipart/alternative |
| 552 | - if(!empty($this->AltBody)) { |
|
| 552 | + if (!empty($this->AltBody)) { |
|
| 553 | 553 | $this->ContentType = 'multipart/alternative'; |
| 554 | 554 | } |
| 555 | 555 | |
@@ -564,12 +564,12 @@ discard block |
||
| 564 | 564 | |
| 565 | 565 | // digitally sign with DKIM if enabled |
| 566 | 566 | if ($this->DKIM_domain && $this->DKIM_private) { |
| 567 | - $header_dkim = $this->DKIM_Add($header,$this->Subject,$body); |
|
| 568 | - $header = str_replace("\r\n","\n",$header_dkim) . $header; |
|
| 567 | + $header_dkim = $this->DKIM_Add($header, $this->Subject, $body); |
|
| 568 | + $header = str_replace("\r\n", "\n", $header_dkim).$header; |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | // Choose the mailer and send through it |
| 572 | - switch($this->Mailer) { |
|
| 572 | + switch ($this->Mailer) { |
|
| 573 | 573 | case 'sendmail': |
| 574 | 574 | return $this->SendmailSend($header, $body); |
| 575 | 575 | case 'smtp': |
@@ -603,32 +603,32 @@ discard block |
||
| 603 | 603 | } |
| 604 | 604 | if ($this->SingleTo === true) { |
| 605 | 605 | foreach ($this->SingleToArray as $key => $val) { |
| 606 | - if(!@$mail = popen($sendmail, 'w')) { |
|
| 607 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 606 | + if (!@$mail = popen($sendmail, 'w')) { |
|
| 607 | + throw new phpmailerException($this->Lang('execute').$this->Sendmail, self::STOP_CRITICAL); |
|
| 608 | 608 | } |
| 609 | - fputs($mail, "To: " . $val . "\n"); |
|
| 609 | + fputs($mail, "To: ".$val."\n"); |
|
| 610 | 610 | fputs($mail, $header); |
| 611 | 611 | fputs($mail, $body); |
| 612 | 612 | $result = pclose($mail); |
| 613 | 613 | // implement call back function if it exists |
| 614 | 614 | $isSent = ($result == 0) ? 1 : 0; |
| 615 | - $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 616 | - if($result != 0) { |
|
| 617 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 615 | + $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); |
|
| 616 | + if ($result != 0) { |
|
| 617 | + throw new phpmailerException($this->Lang('execute').$this->Sendmail, self::STOP_CRITICAL); |
|
| 618 | 618 | } |
| 619 | 619 | } |
| 620 | 620 | } else { |
| 621 | - if(!@$mail = popen($sendmail, 'w')) { |
|
| 622 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 621 | + if (!@$mail = popen($sendmail, 'w')) { |
|
| 622 | + throw new phpmailerException($this->Lang('execute').$this->Sendmail, self::STOP_CRITICAL); |
|
| 623 | 623 | } |
| 624 | 624 | fputs($mail, $header); |
| 625 | 625 | fputs($mail, $body); |
| 626 | 626 | $result = pclose($mail); |
| 627 | 627 | // implement call back function if it exists |
| 628 | 628 | $isSent = ($result == 0) ? 1 : 0; |
| 629 | - $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 630 | - if($result != 0) { |
|
| 631 | - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
| 629 | + $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body); |
|
| 630 | + if ($result != 0) { |
|
| 631 | + throw new phpmailerException($this->Lang('execute').$this->Sendmail, self::STOP_CRITICAL); |
|
| 632 | 632 | } |
| 633 | 633 | } |
| 634 | 634 | return true; |
@@ -643,13 +643,13 @@ discard block |
||
| 643 | 643 | */ |
| 644 | 644 | protected function MailSend($header, $body) { |
| 645 | 645 | $toArr = array(); |
| 646 | - foreach($this->to as $t) { |
|
| 646 | + foreach ($this->to as $t) { |
|
| 647 | 647 | $toArr[] = $this->AddrFormat($t); |
| 648 | 648 | } |
| 649 | 649 | $to = implode(', ', $toArr); |
| 650 | 650 | |
| 651 | 651 | $params = sprintf("-oi -f %s", $this->Sender); |
| 652 | - if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) { |
|
| 652 | + if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) { |
|
| 653 | 653 | $old_from = ini_get('sendmail_from'); |
| 654 | 654 | ini_set('sendmail_from', $this->Sender); |
| 655 | 655 | if ($this->SingleTo === true && count($toArr) > 1) { |
@@ -657,13 +657,13 @@ discard block |
||
| 657 | 657 | $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
| 658 | 658 | // implement call back function if it exists |
| 659 | 659 | $isSent = ($rt == 1) ? 1 : 0; |
| 660 | - $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 660 | + $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); |
|
| 661 | 661 | } |
| 662 | 662 | } else { |
| 663 | 663 | $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
| 664 | 664 | // implement call back function if it exists |
| 665 | 665 | $isSent = ($rt == 1) ? 1 : 0; |
| 666 | - $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 666 | + $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); |
|
| 667 | 667 | } |
| 668 | 668 | } else { |
| 669 | 669 | if ($this->SingleTo === true && count($toArr) > 1) { |
@@ -671,19 +671,19 @@ discard block |
||
| 671 | 671 | $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
| 672 | 672 | // implement call back function if it exists |
| 673 | 673 | $isSent = ($rt == 1) ? 1 : 0; |
| 674 | - $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 674 | + $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); |
|
| 675 | 675 | } |
| 676 | 676 | } else { |
| 677 | 677 | $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); |
| 678 | 678 | // implement call back function if it exists |
| 679 | 679 | $isSent = ($rt == 1) ? 1 : 0; |
| 680 | - $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); |
|
| 680 | + $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); |
|
| 681 | 681 | } |
| 682 | 682 | } |
| 683 | 683 | if (isset($old_from)) { |
| 684 | 684 | ini_set('sendmail_from', $old_from); |
| 685 | 685 | } |
| 686 | - if(!$rt) { |
|
| 686 | + if (!$rt) { |
|
| 687 | 687 | throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL); |
| 688 | 688 | } |
| 689 | 689 | return true; |
@@ -699,64 +699,64 @@ discard block |
||
| 699 | 699 | * @return bool |
| 700 | 700 | */ |
| 701 | 701 | protected function SmtpSend($header, $body) { |
| 702 | - require_once $this->PluginDir . 'smtp.php'; |
|
| 702 | + require_once $this->PluginDir.'smtp.php'; |
|
| 703 | 703 | $bad_rcpt = array(); |
| 704 | 704 | |
| 705 | - if(!$this->SmtpConnect()) { |
|
| 705 | + if (!$this->SmtpConnect()) { |
|
| 706 | 706 | throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL); |
| 707 | 707 | } |
| 708 | 708 | $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; |
| 709 | - if(!$this->smtp->Mail($smtp_from)) { |
|
| 710 | - throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL); |
|
| 709 | + if (!$this->smtp->Mail($smtp_from)) { |
|
| 710 | + throw new phpmailerException($this->Lang('from_failed').$smtp_from, self::STOP_CRITICAL); |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | // Attempt to send attach all recipients |
| 714 | - foreach($this->to as $to) { |
|
| 714 | + foreach ($this->to as $to) { |
|
| 715 | 715 | if (!$this->smtp->Recipient($to[0])) { |
| 716 | 716 | $bad_rcpt[] = $to[0]; |
| 717 | 717 | // implement call back function if it exists |
| 718 | 718 | $isSent = 0; |
| 719 | - $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); |
|
| 719 | + $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body); |
|
| 720 | 720 | } else { |
| 721 | 721 | // implement call back function if it exists |
| 722 | 722 | $isSent = 1; |
| 723 | - $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); |
|
| 723 | + $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body); |
|
| 724 | 724 | } |
| 725 | 725 | } |
| 726 | - foreach($this->cc as $cc) { |
|
| 726 | + foreach ($this->cc as $cc) { |
|
| 727 | 727 | if (!$this->smtp->Recipient($cc[0])) { |
| 728 | 728 | $bad_rcpt[] = $cc[0]; |
| 729 | 729 | // implement call back function if it exists |
| 730 | 730 | $isSent = 0; |
| 731 | - $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); |
|
| 731 | + $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body); |
|
| 732 | 732 | } else { |
| 733 | 733 | // implement call back function if it exists |
| 734 | 734 | $isSent = 1; |
| 735 | - $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); |
|
| 735 | + $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body); |
|
| 736 | 736 | } |
| 737 | 737 | } |
| 738 | - foreach($this->bcc as $bcc) { |
|
| 738 | + foreach ($this->bcc as $bcc) { |
|
| 739 | 739 | if (!$this->smtp->Recipient($bcc[0])) { |
| 740 | 740 | $bad_rcpt[] = $bcc[0]; |
| 741 | 741 | // implement call back function if it exists |
| 742 | 742 | $isSent = 0; |
| 743 | - $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); |
|
| 743 | + $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body); |
|
| 744 | 744 | } else { |
| 745 | 745 | // implement call back function if it exists |
| 746 | 746 | $isSent = 1; |
| 747 | - $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); |
|
| 747 | + $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body); |
|
| 748 | 748 | } |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | |
| 752 | - if (count($bad_rcpt) > 0 ) { //Create error message for any bad addresses |
|
| 752 | + if (count($bad_rcpt) > 0) { //Create error message for any bad addresses |
|
| 753 | 753 | $badaddresses = implode(', ', $bad_rcpt); |
| 754 | - throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses); |
|
| 754 | + throw new phpmailerException($this->Lang('recipients_failed').$badaddresses); |
|
| 755 | 755 | } |
| 756 | - if(!$this->smtp->Data($header . $body)) { |
|
| 756 | + if (!$this->smtp->Data($header.$body)) { |
|
| 757 | 757 | throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL); |
| 758 | 758 | } |
| 759 | - if($this->SMTPKeepAlive == true) { |
|
| 759 | + if ($this->SMTPKeepAlive == true) { |
|
| 760 | 760 | $this->smtp->Reset(); |
| 761 | 761 | } |
| 762 | 762 | return true; |
@@ -770,7 +770,7 @@ discard block |
||
| 770 | 770 | * @return bool |
| 771 | 771 | */ |
| 772 | 772 | public function SmtpConnect() { |
| 773 | - if(is_null($this->smtp)) { |
|
| 773 | + if (is_null($this->smtp)) { |
|
| 774 | 774 | $this->smtp = new SMTP(); |
| 775 | 775 | } |
| 776 | 776 | |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | |
| 782 | 782 | // Retry while there is no connection |
| 783 | 783 | try { |
| 784 | - while($index < count($hosts) && !$connection) { |
|
| 784 | + while ($index < count($hosts) && !$connection) { |
|
| 785 | 785 | $hostinfo = array(); |
| 786 | 786 | if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) { |
| 787 | 787 | $host = $hostinfo[1]; |
@@ -794,13 +794,13 @@ discard block |
||
| 794 | 794 | $tls = ($this->SMTPSecure == 'tls'); |
| 795 | 795 | $ssl = ($this->SMTPSecure == 'ssl'); |
| 796 | 796 | |
| 797 | - if($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) { |
|
| 797 | + if ($this->smtp->Connect(($ssl ? 'ssl://' : '').$host, $port, $this->Timeout)) { |
|
| 798 | 798 | |
| 799 | 799 | $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname()); |
| 800 | 800 | $this->smtp->Hello($hello); |
| 801 | 801 | |
| 802 | - if($tls) { |
|
| 803 | - if(!$this->smtp->StartTLS()) { |
|
| 802 | + if ($tls) { |
|
| 803 | + if (!$this->smtp->StartTLS()) { |
|
| 804 | 804 | throw new phpmailerException($this->Lang('tls')); |
| 805 | 805 | } |
| 806 | 806 | |
@@ -809,14 +809,14 @@ discard block |
||
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | $connection = true; |
| 812 | - if($this->SMTPAuth) { |
|
| 813 | - if(!$this->smtp->Authenticate($this->Username, $this->Password)) { |
|
| 812 | + if ($this->SMTPAuth) { |
|
| 813 | + if (!$this->smtp->Authenticate($this->Username, $this->Password)) { |
|
| 814 | 814 | throw new phpmailerException($this->Lang('authenticate')); |
| 815 | 815 | } |
| 816 | 816 | } |
| 817 | 817 | } |
| 818 | 818 | $index++; |
| 819 | - if(!$connection) { |
|
| 819 | + if (!$connection) { |
|
| 820 | 820 | throw new phpmailerException($this->Lang('connect_host')); |
| 821 | 821 | } |
| 822 | 822 | } |
@@ -832,8 +832,8 @@ discard block |
||
| 832 | 832 | * @return void |
| 833 | 833 | */ |
| 834 | 834 | public function SmtpClose() { |
| 835 | - if(!is_null($this->smtp)) { |
|
| 836 | - if($this->smtp->Connected()) { |
|
| 835 | + if (!is_null($this->smtp)) { |
|
| 836 | + if ($this->smtp->Connected()) { |
|
| 837 | 837 | $this->smtp->Quit(); |
| 838 | 838 | $this->smtp->Close(); |
| 839 | 839 | } |
@@ -895,7 +895,7 @@ discard block |
||
| 895 | 895 | * @return string |
| 896 | 896 | */ |
| 897 | 897 | public function AddrAppend($type, $addr) { |
| 898 | - $addr_str = $type . ': '; |
|
| 898 | + $addr_str = $type.': '; |
|
| 899 | 899 | $addresses = array(); |
| 900 | 900 | foreach ($addr as $a) { |
| 901 | 901 | $addresses[] = $this->AddrFormat($a); |
@@ -912,10 +912,10 @@ discard block |
||
| 912 | 912 | * @return string |
| 913 | 913 | */ |
| 914 | 914 | public function AddrFormat($addr) { |
| 915 | - if(empty($addr[1])) { |
|
| 915 | + if (empty($addr[1])) { |
|
| 916 | 916 | return $this->SecureHeader($addr[0]); |
| 917 | 917 | } else { |
| 918 | - return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; |
|
| 918 | + return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase')." <".$this->SecureHeader($addr[0]).">"; |
|
| 919 | 919 | } |
| 920 | 920 | } |
| 921 | 921 | |
@@ -942,10 +942,10 @@ discard block |
||
| 942 | 942 | |
| 943 | 943 | $line = explode($this->LE, $message); |
| 944 | 944 | $message = ''; |
| 945 | - for ($i=0 ;$i < count($line); $i++) { |
|
| 945 | + for ($i = 0; $i < count($line); $i++) { |
|
| 946 | 946 | $line_part = explode(' ', $line[$i]); |
| 947 | 947 | $buf = ''; |
| 948 | - for ($e = 0; $e<count($line_part); $e++) { |
|
| 948 | + for ($e = 0; $e < count($line_part); $e++) { |
|
| 949 | 949 | $word = $line_part[$e]; |
| 950 | 950 | if ($qp_mode and (strlen($word) > $length)) { |
| 951 | 951 | $space_left = $length - strlen($buf) - 1; |
@@ -961,10 +961,10 @@ discard block |
||
| 961 | 961 | } |
| 962 | 962 | $part = substr($word, 0, $len); |
| 963 | 963 | $word = substr($word, $len); |
| 964 | - $buf .= ' ' . $part; |
|
| 965 | - $message .= $buf . sprintf("=%s", $this->LE); |
|
| 964 | + $buf .= ' '.$part; |
|
| 965 | + $message .= $buf.sprintf("=%s", $this->LE); |
|
| 966 | 966 | } else { |
| 967 | - $message .= $buf . $soft_break; |
|
| 967 | + $message .= $buf.$soft_break; |
|
| 968 | 968 | } |
| 969 | 969 | $buf = ''; |
| 970 | 970 | } |
@@ -981,22 +981,22 @@ discard block |
||
| 981 | 981 | $word = substr($word, $len); |
| 982 | 982 | |
| 983 | 983 | if (strlen($word) > 0) { |
| 984 | - $message .= $part . sprintf("=%s", $this->LE); |
|
| 984 | + $message .= $part.sprintf("=%s", $this->LE); |
|
| 985 | 985 | } else { |
| 986 | 986 | $buf = $part; |
| 987 | 987 | } |
| 988 | 988 | } |
| 989 | 989 | } else { |
| 990 | 990 | $buf_o = $buf; |
| 991 | - $buf .= ($e == 0) ? $word : (' ' . $word); |
|
| 991 | + $buf .= ($e == 0) ? $word : (' '.$word); |
|
| 992 | 992 | |
| 993 | 993 | if (strlen($buf) > $length and $buf_o != '') { |
| 994 | - $message .= $buf_o . $soft_break; |
|
| 994 | + $message .= $buf_o.$soft_break; |
|
| 995 | 995 | $buf = $word; |
| 996 | 996 | } |
| 997 | 997 | } |
| 998 | 998 | } |
| 999 | - $message .= $buf . $this->LE; |
|
| 999 | + $message .= $buf.$this->LE; |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | return $message; |
@@ -1025,8 +1025,7 @@ discard block |
||
| 1025 | 1025 | if ($dec < 128) { // Single byte character. |
| 1026 | 1026 | // If the encoded char was found at pos 0, it will fit |
| 1027 | 1027 | // otherwise reduce maxLength to start of the encoded char |
| 1028 | - $maxLength = ($encodedCharPos == 0) ? $maxLength : |
|
| 1029 | - $maxLength - ($lookBack - $encodedCharPos); |
|
| 1028 | + $maxLength = ($encodedCharPos == 0) ? $maxLength : $maxLength - ($lookBack - $encodedCharPos); |
|
| 1030 | 1029 | $foundSplitPos = true; |
| 1031 | 1030 | } elseif ($dec >= 192) { // First byte of a multi byte character |
| 1032 | 1031 | // Reduce maxLength to split at start of character |
@@ -1050,11 +1049,11 @@ discard block |
||
| 1050 | 1049 | * @return void |
| 1051 | 1050 | */ |
| 1052 | 1051 | public function SetWordWrap() { |
| 1053 | - if($this->WordWrap < 1) { |
|
| 1052 | + if ($this->WordWrap < 1) { |
|
| 1054 | 1053 | return; |
| 1055 | 1054 | } |
| 1056 | 1055 | |
| 1057 | - switch($this->message_type) { |
|
| 1056 | + switch ($this->message_type) { |
|
| 1058 | 1057 | case 'alt': |
| 1059 | 1058 | case 'alt_attachments': |
| 1060 | 1059 | $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
@@ -1075,24 +1074,24 @@ discard block |
||
| 1075 | 1074 | |
| 1076 | 1075 | // Set the boundaries |
| 1077 | 1076 | $uniq_id = md5(uniqid(time())); |
| 1078 | - $this->boundary[1] = 'b1_' . $uniq_id; |
|
| 1079 | - $this->boundary[2] = 'b2_' . $uniq_id; |
|
| 1077 | + $this->boundary[1] = 'b1_'.$uniq_id; |
|
| 1078 | + $this->boundary[2] = 'b2_'.$uniq_id; |
|
| 1080 | 1079 | |
| 1081 | 1080 | $result .= $this->HeaderLine('Date', self::RFCDate()); |
| 1082 | - if($this->Sender == '') { |
|
| 1081 | + if ($this->Sender == '') { |
|
| 1083 | 1082 | $result .= $this->HeaderLine('Return-Path', trim($this->From)); |
| 1084 | 1083 | } else { |
| 1085 | 1084 | $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); |
| 1086 | 1085 | } |
| 1087 | 1086 | |
| 1088 | 1087 | // To be created automatically by mail() |
| 1089 | - if($this->Mailer != 'mail') { |
|
| 1088 | + if ($this->Mailer != 'mail') { |
|
| 1090 | 1089 | if ($this->SingleTo === true) { |
| 1091 | - foreach($this->to as $t) { |
|
| 1090 | + foreach ($this->to as $t) { |
|
| 1092 | 1091 | $this->SingleToArray[] = $this->AddrFormat($t); |
| 1093 | 1092 | } |
| 1094 | 1093 | } else { |
| 1095 | - if(count($this->to) > 0) { |
|
| 1094 | + if (count($this->to) > 0) { |
|
| 1096 | 1095 | $result .= $this->AddrAppend('To', $this->to); |
| 1097 | 1096 | } elseif (count($this->cc) == 0) { |
| 1098 | 1097 | $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); |
@@ -1106,38 +1105,38 @@ discard block |
||
| 1106 | 1105 | $result .= $this->AddrAppend('From', $from); |
| 1107 | 1106 | |
| 1108 | 1107 | // sendmail and mail() extract Cc from the header before sending |
| 1109 | - if(count($this->cc) > 0) { |
|
| 1108 | + if (count($this->cc) > 0) { |
|
| 1110 | 1109 | $result .= $this->AddrAppend('Cc', $this->cc); |
| 1111 | 1110 | } |
| 1112 | 1111 | |
| 1113 | 1112 | // sendmail and mail() extract Bcc from the header before sending |
| 1114 | - if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { |
|
| 1113 | + if ((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { |
|
| 1115 | 1114 | $result .= $this->AddrAppend('Bcc', $this->bcc); |
| 1116 | 1115 | } |
| 1117 | 1116 | |
| 1118 | - if(count($this->ReplyTo) > 0) { |
|
| 1117 | + if (count($this->ReplyTo) > 0) { |
|
| 1119 | 1118 | $result .= $this->AddrAppend('Reply-to', $this->ReplyTo); |
| 1120 | 1119 | } |
| 1121 | 1120 | |
| 1122 | 1121 | // mail() sets the subject itself |
| 1123 | - if($this->Mailer != 'mail') { |
|
| 1122 | + if ($this->Mailer != 'mail') { |
|
| 1124 | 1123 | $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject))); |
| 1125 | 1124 | } |
| 1126 | 1125 | |
| 1127 | - if($this->MessageID != '') { |
|
| 1128 | - $result .= $this->HeaderLine('Message-ID',$this->MessageID); |
|
| 1126 | + if ($this->MessageID != '') { |
|
| 1127 | + $result .= $this->HeaderLine('Message-ID', $this->MessageID); |
|
| 1129 | 1128 | } else { |
| 1130 | 1129 | $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); |
| 1131 | 1130 | } |
| 1132 | 1131 | $result .= $this->HeaderLine('X-Priority', $this->Priority); |
| 1133 | 1132 | $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)'); |
| 1134 | 1133 | |
| 1135 | - if($this->ConfirmReadingTo != '') { |
|
| 1136 | - $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>'); |
|
| 1134 | + if ($this->ConfirmReadingTo != '') { |
|
| 1135 | + $result .= $this->HeaderLine('Disposition-Notification-To', '<'.trim($this->ConfirmReadingTo).'>'); |
|
| 1137 | 1136 | } |
| 1138 | 1137 | |
| 1139 | 1138 | // Add custom headers |
| 1140 | - for($index = 0; $index < count($this->CustomHeader); $index++) { |
|
| 1139 | + for ($index = 0; $index < count($this->CustomHeader); $index++) { |
|
| 1141 | 1140 | $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
| 1142 | 1141 | } |
| 1143 | 1142 | if (!$this->sign_key_file) { |
@@ -1155,27 +1154,27 @@ discard block |
||
| 1155 | 1154 | */ |
| 1156 | 1155 | public function GetMailMIME() { |
| 1157 | 1156 | $result = ''; |
| 1158 | - switch($this->message_type) { |
|
| 1157 | + switch ($this->message_type) { |
|
| 1159 | 1158 | case 'plain': |
| 1160 | 1159 | $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); |
| 1161 | 1160 | $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet); |
| 1162 | 1161 | break; |
| 1163 | 1162 | case 'attachments': |
| 1164 | 1163 | case 'alt_attachments': |
| 1165 | - if($this->InlineImageExists()){ |
|
| 1164 | + if ($this->InlineImageExists()) { |
|
| 1166 | 1165 | $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE); |
| 1167 | 1166 | } else { |
| 1168 | 1167 | $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); |
| 1169 | - $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 1168 | + $result .= $this->TextLine("\tboundary=\"".$this->boundary[1].'"'); |
|
| 1170 | 1169 | } |
| 1171 | 1170 | break; |
| 1172 | 1171 | case 'alt': |
| 1173 | 1172 | $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); |
| 1174 | - $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
| 1173 | + $result .= $this->TextLine("\tboundary=\"".$this->boundary[1].'"'); |
|
| 1175 | 1174 | break; |
| 1176 | 1175 | } |
| 1177 | 1176 | |
| 1178 | - if($this->Mailer != 'mail') { |
|
| 1177 | + if ($this->Mailer != 'mail') { |
|
| 1179 | 1178 | $result .= $this->LE.$this->LE; |
| 1180 | 1179 | } |
| 1181 | 1180 | |
@@ -1196,7 +1195,7 @@ discard block |
||
| 1196 | 1195 | |
| 1197 | 1196 | $this->SetWordWrap(); |
| 1198 | 1197 | |
| 1199 | - switch($this->message_type) { |
|
| 1198 | + switch ($this->message_type) { |
|
| 1200 | 1199 | case 'alt': |
| 1201 | 1200 | $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); |
| 1202 | 1201 | $body .= $this->EncodeString($this->AltBody, $this->Encoding); |
@@ -1217,11 +1216,11 @@ discard block |
||
| 1217 | 1216 | break; |
| 1218 | 1217 | case 'alt_attachments': |
| 1219 | 1218 | $body .= sprintf("--%s%s", $this->boundary[1], $this->LE); |
| 1220 | - $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); |
|
| 1221 | - $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body |
|
| 1219 | + $body .= sprintf("Content-Type: %s;%s"."\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); |
|
| 1220 | + $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '').$this->LE; // Create text body |
|
| 1222 | 1221 | $body .= $this->EncodeString($this->AltBody, $this->Encoding); |
| 1223 | 1222 | $body .= $this->LE.$this->LE; |
| 1224 | - $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body |
|
| 1223 | + $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '').$this->LE; // Create the HTML body |
|
| 1225 | 1224 | $body .= $this->EncodeString($this->Body, $this->Encoding); |
| 1226 | 1225 | $body .= $this->LE.$this->LE; |
| 1227 | 1226 | $body .= $this->EndBoundary($this->boundary[2]); |
@@ -1229,7 +1228,7 @@ discard block |
||
| 1229 | 1228 | break; |
| 1230 | 1229 | } |
| 1231 | 1230 | |
| 1232 | - if($this->IsError()) { |
|
| 1231 | + if ($this->IsError()) { |
|
| 1233 | 1232 | $body = ''; |
| 1234 | 1233 | } else if ($this->sign_key_file) { |
| 1235 | 1234 | try { |
@@ -1262,16 +1261,16 @@ discard block |
||
| 1262 | 1261 | */ |
| 1263 | 1262 | private function GetBoundary($boundary, $charSet, $contentType, $encoding) { |
| 1264 | 1263 | $result = ''; |
| 1265 | - if($charSet == '') { |
|
| 1264 | + if ($charSet == '') { |
|
| 1266 | 1265 | $charSet = $this->CharSet; |
| 1267 | 1266 | } |
| 1268 | - if($contentType == '') { |
|
| 1267 | + if ($contentType == '') { |
|
| 1269 | 1268 | $contentType = $this->ContentType; |
| 1270 | 1269 | } |
| 1271 | - if($encoding == '') { |
|
| 1270 | + if ($encoding == '') { |
|
| 1272 | 1271 | $encoding = $this->Encoding; |
| 1273 | 1272 | } |
| 1274 | - $result .= $this->TextLine('--' . $boundary); |
|
| 1273 | + $result .= $this->TextLine('--'.$boundary); |
|
| 1275 | 1274 | $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet); |
| 1276 | 1275 | $result .= $this->LE; |
| 1277 | 1276 | $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); |
@@ -1285,7 +1284,7 @@ discard block |
||
| 1285 | 1284 | * @access private |
| 1286 | 1285 | */ |
| 1287 | 1286 | private function EndBoundary($boundary) { |
| 1288 | - return $this->LE . '--' . $boundary . '--' . $this->LE; |
|
| 1287 | + return $this->LE.'--'.$boundary.'--'.$this->LE; |
|
| 1289 | 1288 | } |
| 1290 | 1289 | |
| 1291 | 1290 | /** |
@@ -1294,16 +1293,16 @@ discard block |
||
| 1294 | 1293 | * @return void |
| 1295 | 1294 | */ |
| 1296 | 1295 | private function SetMessageType() { |
| 1297 | - if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) { |
|
| 1296 | + if (count($this->attachment) < 1 && strlen($this->AltBody) < 1) { |
|
| 1298 | 1297 | $this->message_type = 'plain'; |
| 1299 | 1298 | } else { |
| 1300 | - if(count($this->attachment) > 0) { |
|
| 1299 | + if (count($this->attachment) > 0) { |
|
| 1301 | 1300 | $this->message_type = 'attachments'; |
| 1302 | 1301 | } |
| 1303 | - if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) { |
|
| 1302 | + if (strlen($this->AltBody) > 0 && count($this->attachment) < 1) { |
|
| 1304 | 1303 | $this->message_type = 'alt'; |
| 1305 | 1304 | } |
| 1306 | - if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) { |
|
| 1305 | + if (strlen($this->AltBody) > 0 && count($this->attachment) > 0) { |
|
| 1307 | 1306 | $this->message_type = 'alt_attachments'; |
| 1308 | 1307 | } |
| 1309 | 1308 | } |
@@ -1315,7 +1314,7 @@ discard block |
||
| 1315 | 1314 | * @return string |
| 1316 | 1315 | */ |
| 1317 | 1316 | public function HeaderLine($name, $value) { |
| 1318 | - return $name . ': ' . $value . $this->LE; |
|
| 1317 | + return $name.': '.$value.$this->LE; |
|
| 1319 | 1318 | } |
| 1320 | 1319 | |
| 1321 | 1320 | /** |
@@ -1324,7 +1323,7 @@ discard block |
||
| 1324 | 1323 | * @return string |
| 1325 | 1324 | */ |
| 1326 | 1325 | public function TextLine($value) { |
| 1327 | - return $value . $this->LE; |
|
| 1326 | + return $value.$this->LE; |
|
| 1328 | 1327 | } |
| 1329 | 1328 | |
| 1330 | 1329 | ///////////////////////////////////////////////// |
@@ -1343,11 +1342,11 @@ discard block |
||
| 1343 | 1342 | */ |
| 1344 | 1343 | public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { |
| 1345 | 1344 | try { |
| 1346 | - if(!@is_file($path)) { |
|
| 1347 | - throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE); |
|
| 1345 | + if (!@is_file($path)) { |
|
| 1346 | + throw new phpmailerException($this->Lang('file_access').$path, self::STOP_CONTINUE); |
|
| 1348 | 1347 | } |
| 1349 | 1348 | $filename = basename($path); |
| 1350 | - if($name == '') { |
|
| 1349 | + if ($name == '') { |
|
| 1351 | 1350 | $name = $filename; |
| 1352 | 1351 | } |
| 1353 | 1352 | |
@@ -1357,7 +1356,7 @@ discard block |
||
| 1357 | 1356 | 2 => $name, |
| 1358 | 1357 | 3 => $encoding, |
| 1359 | 1358 | 4 => $type, |
| 1360 | - 5 => false, // isStringAttachment |
|
| 1359 | + 5 => false, // isStringAttachment |
|
| 1361 | 1360 | 6 => 'attachment', |
| 1362 | 1361 | 7 => 0 |
| 1363 | 1362 | ); |
@@ -1368,7 +1367,7 @@ discard block |
||
| 1368 | 1367 | throw $e; |
| 1369 | 1368 | } |
| 1370 | 1369 | echo $e->getMessage()."\n"; |
| 1371 | - if ( $e->getCode() == self::STOP_CRITICAL ) { |
|
| 1370 | + if ($e->getCode() == self::STOP_CRITICAL) { |
|
| 1372 | 1371 | return false; |
| 1373 | 1372 | } |
| 1374 | 1373 | } |
@@ -1413,29 +1412,29 @@ discard block |
||
| 1413 | 1412 | $disposition = $attachment[6]; |
| 1414 | 1413 | $cid = $attachment[7]; |
| 1415 | 1414 | $incl[] = $attachment[0]; |
| 1416 | - if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; } |
|
| 1415 | + if ($disposition == 'inline' && isset($cidUniq[$cid])) { continue; } |
|
| 1417 | 1416 | $cidUniq[$cid] = true; |
| 1418 | 1417 | |
| 1419 | 1418 | $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); |
| 1420 | 1419 | $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); |
| 1421 | 1420 | $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); |
| 1422 | 1421 | |
| 1423 | - if($disposition == 'inline') { |
|
| 1422 | + if ($disposition == 'inline') { |
|
| 1424 | 1423 | $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); |
| 1425 | 1424 | } |
| 1426 | 1425 | |
| 1427 | 1426 | $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); |
| 1428 | 1427 | |
| 1429 | 1428 | // Encode as string attachment |
| 1430 | - if($bString) { |
|
| 1429 | + if ($bString) { |
|
| 1431 | 1430 | $mime[] = $this->EncodeString($string, $encoding); |
| 1432 | - if($this->IsError()) { |
|
| 1431 | + if ($this->IsError()) { |
|
| 1433 | 1432 | return ''; |
| 1434 | 1433 | } |
| 1435 | 1434 | $mime[] = $this->LE.$this->LE; |
| 1436 | 1435 | } else { |
| 1437 | 1436 | $mime[] = $this->EncodeFile($path, $encoding); |
| 1438 | - if($this->IsError()) { |
|
| 1437 | + if ($this->IsError()) { |
|
| 1439 | 1438 | return ''; |
| 1440 | 1439 | } |
| 1441 | 1440 | $mime[] = $this->LE.$this->LE; |
@@ -1459,7 +1458,7 @@ discard block |
||
| 1459 | 1458 | private function EncodeFile($path, $encoding = 'base64') { |
| 1460 | 1459 | try { |
| 1461 | 1460 | if (!is_readable($path)) { |
| 1462 | - throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); |
|
| 1461 | + throw new phpmailerException($this->Lang('file_open').$path, self::STOP_CONTINUE); |
|
| 1463 | 1462 | } |
| 1464 | 1463 | if (function_exists('get_magic_quotes')) { |
| 1465 | 1464 | function get_magic_quotes() { |
@@ -1488,9 +1487,9 @@ discard block |
||
| 1488 | 1487 | * @access public |
| 1489 | 1488 | * @return string |
| 1490 | 1489 | */ |
| 1491 | - public function EncodeString ($str, $encoding = 'base64') { |
|
| 1490 | + public function EncodeString($str, $encoding = 'base64') { |
|
| 1492 | 1491 | $encoded = ''; |
| 1493 | - switch(strtolower($encoding)) { |
|
| 1492 | + switch (strtolower($encoding)) { |
|
| 1494 | 1493 | case 'base64': |
| 1495 | 1494 | $encoded = chunk_split(base64_encode($str), 76, $this->LE); |
| 1496 | 1495 | break; |
@@ -1508,7 +1507,7 @@ discard block |
||
| 1508 | 1507 | $encoded = $this->EncodeQP($str); |
| 1509 | 1508 | break; |
| 1510 | 1509 | default: |
| 1511 | - $this->SetError($this->Lang('encoding') . $encoding); |
|
| 1510 | + $this->SetError($this->Lang('encoding').$encoding); |
|
| 1512 | 1511 | break; |
| 1513 | 1512 | } |
| 1514 | 1513 | return $encoded; |
@@ -1519,7 +1518,7 @@ discard block |
||
| 1519 | 1518 | * @access public |
| 1520 | 1519 | * @return string |
| 1521 | 1520 | */ |
| 1522 | - public function EncodeHeader ($str, $position = 'text') { |
|
| 1521 | + public function EncodeHeader($str, $position = 'text') { |
|
| 1523 | 1522 | $x = 0; |
| 1524 | 1523 | |
| 1525 | 1524 | switch (strtolower($position)) { |
@@ -1550,7 +1549,7 @@ discard block |
||
| 1550 | 1549 | |
| 1551 | 1550 | $maxlen = 75 - 7 - strlen($this->CharSet); |
| 1552 | 1551 | // Try to select the encoding which should produce the shortest output |
| 1553 | - if (strlen($str)/3 < $x) { |
|
| 1552 | + if (strlen($str) / 3 < $x) { |
|
| 1554 | 1553 | $encoding = 'B'; |
| 1555 | 1554 | if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) { |
| 1556 | 1555 | // Use a custom function which correctly encodes and wraps long |
@@ -1620,7 +1619,7 @@ discard block |
||
| 1620 | 1619 | } |
| 1621 | 1620 | while (strlen($chunk) > $length); |
| 1622 | 1621 | |
| 1623 | - $encoded .= $chunk . $this->LE; |
|
| 1622 | + $encoded .= $chunk.$this->LE; |
|
| 1624 | 1623 | } |
| 1625 | 1624 | |
| 1626 | 1625 | // Chomp the last linefeed |
@@ -1636,37 +1635,37 @@ discard block |
||
| 1636 | 1635 | * @param integer $line_max Number of chars allowed on a line before wrapping |
| 1637 | 1636 | * @return string |
| 1638 | 1637 | */ |
| 1639 | - public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) { |
|
| 1640 | - $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
| 1638 | + public function EncodeQPphp($input = '', $line_max = 76, $space_conv = false) { |
|
| 1639 | + $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
|
| 1641 | 1640 | $lines = preg_split('/(?:\r\n|\r|\n)/', $input); |
| 1642 | 1641 | $eol = "\r\n"; |
| 1643 | 1642 | $escape = '='; |
| 1644 | 1643 | $output = ''; |
| 1645 | - while( list(, $line) = each($lines) ) { |
|
| 1644 | + while (list(, $line) = each($lines)) { |
|
| 1646 | 1645 | $linlen = strlen($line); |
| 1647 | 1646 | $newline = ''; |
| 1648 | - for($i = 0; $i < $linlen; $i++) { |
|
| 1649 | - $c = substr( $line, $i, 1 ); |
|
| 1650 | - $dec = ord( $c ); |
|
| 1651 | - if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E |
|
| 1647 | + for ($i = 0; $i < $linlen; $i++) { |
|
| 1648 | + $c = substr($line, $i, 1); |
|
| 1649 | + $dec = ord($c); |
|
| 1650 | + if (($i == 0) && ($dec == 46)) { // convert first point in the line into =2E |
|
| 1652 | 1651 | $c = '=2E'; |
| 1653 | 1652 | } |
| 1654 | - if ( $dec == 32 ) { |
|
| 1655 | - if ( $i == ( $linlen - 1 ) ) { // convert space at eol only |
|
| 1653 | + if ($dec == 32) { |
|
| 1654 | + if ($i == ($linlen - 1)) { // convert space at eol only |
|
| 1656 | 1655 | $c = '=20'; |
| 1657 | - } else if ( $space_conv ) { |
|
| 1656 | + } else if ($space_conv) { |
|
| 1658 | 1657 | $c = '=20'; |
| 1659 | 1658 | } |
| 1660 | - } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required |
|
| 1661 | - $h2 = floor($dec/16); |
|
| 1662 | - $h1 = floor($dec%16); |
|
| 1659 | + } elseif (($dec == 61) || ($dec < 32) || ($dec > 126)) { // always encode "\t", which is *not* required |
|
| 1660 | + $h2 = floor($dec / 16); |
|
| 1661 | + $h1 = floor($dec % 16); |
|
| 1663 | 1662 | $c = $escape.$hex[$h2].$hex[$h1]; |
| 1664 | 1663 | } |
| 1665 | - if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted |
|
| 1664 | + if ((strlen($newline) + strlen($c)) >= $line_max) { // CRLF is not counted |
|
| 1666 | 1665 | $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay |
| 1667 | 1666 | $newline = ''; |
| 1668 | 1667 | // check if newline first character will be point or not |
| 1669 | - if ( $dec == 46 ) { |
|
| 1668 | + if ($dec == 46) { |
|
| 1670 | 1669 | $c = '=2E'; |
| 1671 | 1670 | } |
| 1672 | 1671 | } |
@@ -1718,7 +1717,7 @@ discard block |
||
| 1718 | 1717 | * @access public |
| 1719 | 1718 | * @return string |
| 1720 | 1719 | */ |
| 1721 | - public function EncodeQ ($str, $position = 'text') { |
|
| 1720 | + public function EncodeQ($str, $position = 'text') { |
|
| 1722 | 1721 | // There should not be any EOL in the string |
| 1723 | 1722 | $encoded = preg_replace('/[\r\n]*/', '', $str); |
| 1724 | 1723 | |
@@ -1761,7 +1760,7 @@ discard block |
||
| 1761 | 1760 | 2 => basename($filename), |
| 1762 | 1761 | 3 => $encoding, |
| 1763 | 1762 | 4 => $type, |
| 1764 | - 5 => true, // isStringAttachment |
|
| 1763 | + 5 => true, // isStringAttachment |
|
| 1765 | 1764 | 6 => 'attachment', |
| 1766 | 1765 | 7 => 0 |
| 1767 | 1766 | ); |
@@ -1782,13 +1781,13 @@ discard block |
||
| 1782 | 1781 | */ |
| 1783 | 1782 | public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { |
| 1784 | 1783 | |
| 1785 | - if(!@is_file($path)) { |
|
| 1786 | - $this->SetError($this->Lang('file_access') . $path); |
|
| 1784 | + if (!@is_file($path)) { |
|
| 1785 | + $this->SetError($this->Lang('file_access').$path); |
|
| 1787 | 1786 | return false; |
| 1788 | 1787 | } |
| 1789 | 1788 | |
| 1790 | 1789 | $filename = basename($path); |
| 1791 | - if($name == '') { |
|
| 1790 | + if ($name == '') { |
|
| 1792 | 1791 | $name = $filename; |
| 1793 | 1792 | } |
| 1794 | 1793 | |
@@ -1799,7 +1798,7 @@ discard block |
||
| 1799 | 1798 | 2 => $name, |
| 1800 | 1799 | 3 => $encoding, |
| 1801 | 1800 | 4 => $type, |
| 1802 | - 5 => false, // isStringAttachment |
|
| 1801 | + 5 => false, // isStringAttachment |
|
| 1803 | 1802 | 6 => 'inline', |
| 1804 | 1803 | 7 => $cid |
| 1805 | 1804 | ); |
@@ -1813,7 +1812,7 @@ discard block |
||
| 1813 | 1812 | * @return bool |
| 1814 | 1813 | */ |
| 1815 | 1814 | public function InlineImageExists() { |
| 1816 | - foreach($this->attachment as $attachment) { |
|
| 1815 | + foreach ($this->attachment as $attachment) { |
|
| 1817 | 1816 | if ($attachment[6] == 'inline') { |
| 1818 | 1817 | return true; |
| 1819 | 1818 | } |
@@ -1830,7 +1829,7 @@ discard block |
||
| 1830 | 1829 | * @return void |
| 1831 | 1830 | */ |
| 1832 | 1831 | public function ClearAddresses() { |
| 1833 | - foreach($this->to as $to) { |
|
| 1832 | + foreach ($this->to as $to) { |
|
| 1834 | 1833 | unset($this->all_recipients[strtolower($to[0])]); |
| 1835 | 1834 | } |
| 1836 | 1835 | $this->to = array(); |
@@ -1841,7 +1840,7 @@ discard block |
||
| 1841 | 1840 | * @return void |
| 1842 | 1841 | */ |
| 1843 | 1842 | public function ClearCCs() { |
| 1844 | - foreach($this->cc as $cc) { |
|
| 1843 | + foreach ($this->cc as $cc) { |
|
| 1845 | 1844 | unset($this->all_recipients[strtolower($cc[0])]); |
| 1846 | 1845 | } |
| 1847 | 1846 | $this->cc = array(); |
@@ -1852,7 +1851,7 @@ discard block |
||
| 1852 | 1851 | * @return void |
| 1853 | 1852 | */ |
| 1854 | 1853 | public function ClearBCCs() { |
| 1855 | - foreach($this->bcc as $bcc) { |
|
| 1854 | + foreach ($this->bcc as $bcc) { |
|
| 1856 | 1855 | unset($this->all_recipients[strtolower($bcc[0])]); |
| 1857 | 1856 | } |
| 1858 | 1857 | $this->bcc = array(); |
@@ -1909,7 +1908,7 @@ discard block |
||
| 1909 | 1908 | if ($this->Mailer == 'smtp' and !is_null($this->smtp)) { |
| 1910 | 1909 | $lasterror = $this->smtp->getError(); |
| 1911 | 1910 | if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) { |
| 1912 | - $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n"; |
|
| 1911 | + $msg .= '<p>'.$this->Lang('smtp_error').$lasterror['smtp_msg']."</p>\n"; |
|
| 1913 | 1912 | } |
| 1914 | 1913 | } |
| 1915 | 1914 | $this->ErrorInfo = $msg; |
@@ -1925,7 +1924,7 @@ discard block |
||
| 1925 | 1924 | $tz = date('Z'); |
| 1926 | 1925 | $tzs = ($tz < 0) ? '-' : '+'; |
| 1927 | 1926 | $tz = abs($tz); |
| 1928 | - $tz = (int)($tz/3600)*100 + ($tz%3600)/60; |
|
| 1927 | + $tz = (int) ($tz / 3600) * 100 + ($tz % 3600) / 60; |
|
| 1929 | 1928 | $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz); |
| 1930 | 1929 | |
| 1931 | 1930 | return $result; |
@@ -1954,14 +1953,14 @@ discard block |
||
| 1954 | 1953 | * @return string |
| 1955 | 1954 | */ |
| 1956 | 1955 | private function Lang($key) { |
| 1957 | - if(count($this->language) < 1) { |
|
| 1956 | + if (count($this->language) < 1) { |
|
| 1958 | 1957 | $this->SetLanguage('en'); // set the default language |
| 1959 | 1958 | } |
| 1960 | 1959 | |
| 1961 | - if(isset($this->language[$key])) { |
|
| 1960 | + if (isset($this->language[$key])) { |
|
| 1962 | 1961 | return $this->language[$key]; |
| 1963 | 1962 | } else { |
| 1964 | - return 'Language string failed to load: ' . $key; |
|
| 1963 | + return 'Language string failed to load: '.$key; |
|
| 1965 | 1964 | } |
| 1966 | 1965 | } |
| 1967 | 1966 | |
@@ -2000,21 +1999,21 @@ discard block |
||
| 2000 | 1999 | * @access public |
| 2001 | 2000 | * @return $message |
| 2002 | 2001 | */ |
| 2003 | - public function MsgHTML($message,$basedir='') { |
|
| 2002 | + public function MsgHTML($message, $basedir = '') { |
|
| 2004 | 2003 | preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images); |
| 2005 | - if(isset($images[2])) { |
|
| 2006 | - foreach($images[2] as $i => $url) { |
|
| 2004 | + if (isset($images[2])) { |
|
| 2005 | + foreach ($images[2] as $i => $url) { |
|
| 2007 | 2006 | // do not change urls for absolute images (thanks to corvuscorax) |
| 2008 | - if (!preg_match('#^[A-z]+://#',$url)) { |
|
| 2007 | + if (!preg_match('#^[A-z]+://#', $url)) { |
|
| 2009 | 2008 | $filename = basename($url); |
| 2010 | 2009 | $directory = dirname($url); |
| 2011 | - ($directory == '.')?$directory='':''; |
|
| 2012 | - $cid = 'cid:' . md5($filename); |
|
| 2010 | + ($directory == '.') ? $directory = '' : ''; |
|
| 2011 | + $cid = 'cid:'.md5($filename); |
|
| 2013 | 2012 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
| 2014 | - $mimeType = self::_mime_types($ext); |
|
| 2015 | - if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; } |
|
| 2016 | - if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; } |
|
| 2017 | - if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) { |
|
| 2013 | + $mimeType = self::_mime_types($ext); |
|
| 2014 | + if (strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; } |
|
| 2015 | + if (strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; } |
|
| 2016 | + if ($this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType)) { |
|
| 2018 | 2017 | $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message); |
| 2019 | 2018 | } |
| 2020 | 2019 | } |
@@ -2022,12 +2021,12 @@ discard block |
||
| 2022 | 2021 | } |
| 2023 | 2022 | $this->IsHTML(true); |
| 2024 | 2023 | $this->Body = $message; |
| 2025 | - $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message))); |
|
| 2026 | - if ( !empty($textMsg) && empty($this->AltBody) ) { |
|
| 2024 | + $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message))); |
|
| 2025 | + if (!empty($textMsg) && empty($this->AltBody)) { |
|
| 2027 | 2026 | $this->AltBody = html_entity_decode($textMsg); |
| 2028 | 2027 | } |
| 2029 | - if ( empty($this->AltBody) ) { |
|
| 2030 | - $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; |
|
| 2028 | + if (empty($this->AltBody)) { |
|
| 2029 | + $this->AltBody = 'To view this email message, open it in a program that understands HTML!'."\n\n"; |
|
| 2031 | 2030 | } |
| 2032 | 2031 | } |
| 2033 | 2032 | |
@@ -2128,7 +2127,7 @@ discard block |
||
| 2128 | 2127 | 'xl' => 'application/excel', |
| 2129 | 2128 | 'eml' => 'message/rfc822' |
| 2130 | 2129 | ); |
| 2131 | - return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; |
|
| 2130 | + return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; |
|
| 2132 | 2131 | } |
| 2133 | 2132 | |
| 2134 | 2133 | /** |
@@ -2143,12 +2142,12 @@ discard block |
||
| 2143 | 2142 | * NOTE: will not work with arrays, there are no arrays to set/reset |
| 2144 | 2143 | * @todo Should this not be using __set() magic function? |
| 2145 | 2144 | */ |
| 2146 | - public function set ( $name, $value = '' ) { |
|
| 2145 | + public function set($name, $value = '') { |
|
| 2147 | 2146 | try { |
| 2148 | - if ( isset($this->$name) ) { |
|
| 2147 | + if (isset($this->$name)) { |
|
| 2149 | 2148 | $this->$name = $value; |
| 2150 | 2149 | } else { |
| 2151 | - throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL); |
|
| 2150 | + throw new phpmailerException($this->Lang('variable_set').$name, self::STOP_CRITICAL); |
|
| 2152 | 2151 | } |
| 2153 | 2152 | } catch (Exception $e) { |
| 2154 | 2153 | $this->SetError($e->getMessage()); |
@@ -2192,14 +2191,14 @@ discard block |
||
| 2192 | 2191 | * @param string $key_pass Password for private key |
| 2193 | 2192 | */ |
| 2194 | 2193 | public function DKIM_QP($txt) { |
| 2195 | - $tmp=""; |
|
| 2196 | - $line=""; |
|
| 2197 | - for ($i=0;$i<strlen($txt);$i++) { |
|
| 2198 | - $ord=ord($txt[$i]); |
|
| 2199 | - if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) { |
|
| 2200 | - $line.=$txt[$i]; |
|
| 2194 | + $tmp = ""; |
|
| 2195 | + $line = ""; |
|
| 2196 | + for ($i = 0; $i < strlen($txt); $i++) { |
|
| 2197 | + $ord = ord($txt[$i]); |
|
| 2198 | + if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) { |
|
| 2199 | + $line .= $txt[$i]; |
|
| 2201 | 2200 | } else { |
| 2202 | - $line.="=".sprintf("%02X",$ord); |
|
| 2201 | + $line .= "=".sprintf("%02X", $ord); |
|
| 2203 | 2202 | } |
| 2204 | 2203 | } |
| 2205 | 2204 | return $line; |
@@ -2213,8 +2212,8 @@ discard block |
||
| 2213 | 2212 | */ |
| 2214 | 2213 | public function DKIM_Sign($s) { |
| 2215 | 2214 | $privKeyStr = file_get_contents($this->DKIM_private); |
| 2216 | - if ($this->DKIM_passphrase!='') { |
|
| 2217 | - $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase); |
|
| 2215 | + if ($this->DKIM_passphrase != '') { |
|
| 2216 | + $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase); |
|
| 2218 | 2217 | } else { |
| 2219 | 2218 | $privKey = $privKeyStr; |
| 2220 | 2219 | } |
@@ -2230,15 +2229,15 @@ discard block |
||
| 2230 | 2229 | * @param string $s Header |
| 2231 | 2230 | */ |
| 2232 | 2231 | public function DKIM_HeaderC($s) { |
| 2233 | - $s=preg_replace("/\r\n\s+/"," ",$s); |
|
| 2234 | - $lines=explode("\r\n",$s); |
|
| 2232 | + $s = preg_replace("/\r\n\s+/", " ", $s); |
|
| 2233 | + $lines = explode("\r\n", $s); |
|
| 2235 | 2234 | foreach ($lines as $key=>$line) { |
| 2236 | - list($heading,$value)=explode(":",$line,2); |
|
| 2237 | - $heading=strtolower($heading); |
|
| 2238 | - $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces |
|
| 2239 | - $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value |
|
| 2235 | + list($heading, $value) = explode(":", $line, 2); |
|
| 2236 | + $heading = strtolower($heading); |
|
| 2237 | + $value = preg_replace("/\s+/", " ", $value); // Compress useless spaces |
|
| 2238 | + $lines[$key] = $heading.":".trim($value); // Don't forget to remove WSP around the value |
|
| 2240 | 2239 | } |
| 2241 | - $s=implode("\r\n",$lines); |
|
| 2240 | + $s = implode("\r\n", $lines); |
|
| 2242 | 2241 | return $s; |
| 2243 | 2242 | } |
| 2244 | 2243 | |
@@ -2251,11 +2250,11 @@ discard block |
||
| 2251 | 2250 | public function DKIM_BodyC($body) { |
| 2252 | 2251 | if ($body == '') return "\r\n"; |
| 2253 | 2252 | // stabilize line endings |
| 2254 | - $body=str_replace("\r\n","\n",$body); |
|
| 2255 | - $body=str_replace("\n","\r\n",$body); |
|
| 2253 | + $body = str_replace("\r\n", "\n", $body); |
|
| 2254 | + $body = str_replace("\n", "\r\n", $body); |
|
| 2256 | 2255 | // END stabilize line endings |
| 2257 | - while (substr($body,strlen($body)-4,4) == "\r\n\r\n") { |
|
| 2258 | - $body=substr($body,0,strlen($body)-2); |
|
| 2256 | + while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") { |
|
| 2257 | + $body = substr($body, 0, strlen($body) - 2); |
|
| 2259 | 2258 | } |
| 2260 | 2259 | return $body; |
| 2261 | 2260 | } |
@@ -2268,52 +2267,52 @@ discard block |
||
| 2268 | 2267 | * @param string $subject Subject |
| 2269 | 2268 | * @param string $body Body |
| 2270 | 2269 | */ |
| 2271 | - public function DKIM_Add($headers_line,$subject,$body) { |
|
| 2270 | + public function DKIM_Add($headers_line, $subject, $body) { |
|
| 2272 | 2271 | $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms |
| 2273 | 2272 | $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body |
| 2274 | 2273 | $DKIMquery = 'dns/txt'; // Query method |
| 2275 | - $DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) |
|
| 2274 | + $DKIMtime = time(); // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) |
|
| 2276 | 2275 | $subject_header = "Subject: $subject"; |
| 2277 | - $headers = explode("\r\n",$headers_line); |
|
| 2278 | - foreach($headers as $header) { |
|
| 2279 | - if (strpos($header,'From:') === 0) { |
|
| 2280 | - $from_header=$header; |
|
| 2281 | - } elseif (strpos($header,'To:') === 0) { |
|
| 2282 | - $to_header=$header; |
|
| 2276 | + $headers = explode("\r\n", $headers_line); |
|
| 2277 | + foreach ($headers as $header) { |
|
| 2278 | + if (strpos($header, 'From:') === 0) { |
|
| 2279 | + $from_header = $header; |
|
| 2280 | + } elseif (strpos($header, 'To:') === 0) { |
|
| 2281 | + $to_header = $header; |
|
| 2283 | 2282 | } |
| 2284 | 2283 | } |
| 2285 | - $from = str_replace('|','=7C',$this->DKIM_QP($from_header)); |
|
| 2286 | - $to = str_replace('|','=7C',$this->DKIM_QP($to_header)); |
|
| 2287 | - $subject = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable |
|
| 2284 | + $from = str_replace('|', '=7C', $this->DKIM_QP($from_header)); |
|
| 2285 | + $to = str_replace('|', '=7C', $this->DKIM_QP($to_header)); |
|
| 2286 | + $subject = str_replace('|', '=7C', $this->DKIM_QP($subject_header)); // Copied header fields (dkim-quoted-printable |
|
| 2288 | 2287 | $body = $this->DKIM_BodyC($body); |
| 2289 | - $DKIMlen = strlen($body) ; // Length of body |
|
| 2290 | - $DKIMb64 = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body |
|
| 2291 | - $ident = ($this->DKIM_identity == '')? '' : " i=" . $this->DKIM_identity . ";"; |
|
| 2292 | - $dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n". |
|
| 2293 | - "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n". |
|
| 2288 | + $DKIMlen = strlen($body); // Length of body |
|
| 2289 | + $DKIMb64 = base64_encode(pack("H*", sha1($body))); // Base64 of packed binary SHA-1 hash of body |
|
| 2290 | + $ident = ($this->DKIM_identity == '') ? '' : " i=".$this->DKIM_identity.";"; |
|
| 2291 | + $dkimhdrs = "DKIM-Signature: v=1; a=".$DKIMsignatureType."; q=".$DKIMquery."; l=".$DKIMlen."; s=".$this->DKIM_selector.";\r\n". |
|
| 2292 | + "\tt=".$DKIMtime."; c=".$DKIMcanonicalization.";\r\n". |
|
| 2294 | 2293 | "\th=From:To:Subject;\r\n". |
| 2295 | - "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n". |
|
| 2294 | + "\td=".$this->DKIM_domain.";".$ident."\r\n". |
|
| 2296 | 2295 | "\tz=$from\r\n". |
| 2297 | 2296 | "\t|$to\r\n". |
| 2298 | 2297 | "\t|$subject;\r\n". |
| 2299 | - "\tbh=" . $DKIMb64 . ";\r\n". |
|
| 2298 | + "\tbh=".$DKIMb64.";\r\n". |
|
| 2300 | 2299 | "\tb="; |
| 2301 | - $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs); |
|
| 2300 | + $toSign = $this->DKIM_HeaderC($from_header."\r\n".$to_header."\r\n".$subject_header."\r\n".$dkimhdrs); |
|
| 2302 | 2301 | $signed = $this->DKIM_Sign($toSign); |
| 2303 | 2302 | return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n"; |
| 2304 | 2303 | } |
| 2305 | 2304 | |
| 2306 | - protected function doCallback($isSent,$to,$cc,$bcc,$subject,$body) { |
|
| 2305 | + protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) { |
|
| 2307 | 2306 | if (!empty($this->action_function) && function_exists($this->action_function)) { |
| 2308 | - $params = array($isSent,$to,$cc,$bcc,$subject,$body); |
|
| 2309 | - call_user_func_array($this->action_function,$params); |
|
| 2307 | + $params = array($isSent, $to, $cc, $bcc, $subject, $body); |
|
| 2308 | + call_user_func_array($this->action_function, $params); |
|
| 2310 | 2309 | } |
| 2311 | 2310 | } |
| 2312 | 2311 | } |
| 2313 | 2312 | |
| 2314 | 2313 | class phpmailerException extends Exception { |
| 2315 | 2314 | public function errorMessage() { |
| 2316 | - $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n"; |
|
| 2315 | + $errorMsg = '<strong>'.$this->getMessage()."</strong><br />\n"; |
|
| 2317 | 2316 | return $errorMsg; |
| 2318 | 2317 | } |
| 2319 | 2318 | } |
@@ -107,6 +107,7 @@ discard block |
||
| 107 | 107 | * SMTP CODE SUCCESS: 220 |
| 108 | 108 | * SMTP CODE FAILURE: 421 |
| 109 | 109 | * @access public |
| 110 | + * @param string $host |
|
| 110 | 111 | * @return bool |
| 111 | 112 | */ |
| 112 | 113 | public function Connect($host,$port=0,$tval=30) { |
@@ -205,6 +206,8 @@ discard block |
||
| 205 | 206 | * Performs SMTP authentication. Must be run after running the |
| 206 | 207 | * Hello() method. Returns true if successfully authenticated. |
| 207 | 208 | * @access public |
| 209 | + * @param string $username |
|
| 210 | + * @param string $password |
|
| 208 | 211 | * @return bool |
| 209 | 212 | */ |
| 210 | 213 | public function Authenticate($username, $password) { |
@@ -321,6 +324,7 @@ discard block |
||
| 321 | 324 | * SMTP CODE FAILURE: 451,554 |
| 322 | 325 | * SMTP CODE ERROR : 500,501,503,421 |
| 323 | 326 | * @access public |
| 327 | + * @param string $msg_data |
|
| 324 | 328 | * @return bool |
| 325 | 329 | */ |
| 326 | 330 | public function Data($msg_data) { |
@@ -489,6 +493,8 @@ discard block |
||
| 489 | 493 | /** |
| 490 | 494 | * Sends a HELO/EHLO command. |
| 491 | 495 | * @access private |
| 496 | + * @param string $hello |
|
| 497 | + * @param string $host |
|
| 492 | 498 | * @return bool |
| 493 | 499 | */ |
| 494 | 500 | private function SendHello($hello, $host) { |
@@ -529,6 +535,7 @@ discard block |
||
| 529 | 535 | * SMTP CODE SUCCESS: 552,451,452 |
| 530 | 536 | * SMTP CODE SUCCESS: 500,501,421 |
| 531 | 537 | * @access public |
| 538 | + * @param string $from |
|
| 532 | 539 | * @return bool |
| 533 | 540 | */ |
| 534 | 541 | public function Mail($from) { |
@@ -85,11 +85,11 @@ discard block |
||
| 85 | 85 | * @return void |
| 86 | 86 | */ |
| 87 | 87 | public function __construct() { |
| 88 | - $this->smtp_conn = 0; |
|
| 89 | - $this->error = null; |
|
| 90 | - $this->helo_rply = null; |
|
| 88 | + $this->smtp_conn = 0; |
|
| 89 | + $this->error = null; |
|
| 90 | + $this->helo_rply = null; |
|
| 91 | 91 | |
| 92 | - $this->do_debug = 0; |
|
| 92 | + $this->do_debug = 0; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | ///////////////////////////////////////////////// |
@@ -110,50 +110,50 @@ discard block |
||
| 110 | 110 | * @return bool |
| 111 | 111 | */ |
| 112 | 112 | public function Connect($host,$port=0,$tval=30) { |
| 113 | - // set the error val to null so there is no confusion |
|
| 114 | - $this->error = null; |
|
| 115 | - |
|
| 116 | - // make sure we are __not__ connected |
|
| 117 | - if($this->connected()) { |
|
| 118 | - // already connected, generate error |
|
| 119 | - $this->error = array("error" => "Already connected to a server"); |
|
| 120 | - return false; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - if(empty($port)) { |
|
| 124 | - $port = $this->SMTP_PORT; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // connect to the smtp server |
|
| 128 | - $this->smtp_conn = @fsockopen($host, // the host of the server |
|
| 129 | - $port, // the port to use |
|
| 130 | - $errno, // error number if any |
|
| 131 | - $errstr, // error message if any |
|
| 132 | - $tval); // give up after ? secs |
|
| 133 | - // verify we connected properly |
|
| 134 | - if(empty($this->smtp_conn)) { |
|
| 135 | - $this->error = array("error" => "Failed to connect to server", |
|
| 136 | - "errno" => $errno, |
|
| 137 | - "errstr" => $errstr); |
|
| 138 | - if($this->do_debug >= 1) { |
|
| 139 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />'; |
|
| 140 | - } |
|
| 141 | - return false; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // SMTP server can take longer to respond, give longer timeout for first read |
|
| 145 | - // Windows does not have support for this timeout function |
|
| 146 | - if(substr(PHP_OS, 0, 3) != "WIN") |
|
| 147 | - socket_set_timeout($this->smtp_conn, $tval, 0); |
|
| 148 | - |
|
| 149 | - // get any announcement |
|
| 150 | - $announce = $this->get_lines(); |
|
| 151 | - |
|
| 152 | - if($this->do_debug >= 2) { |
|
| 153 | - echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />'; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return true; |
|
| 113 | + // set the error val to null so there is no confusion |
|
| 114 | + $this->error = null; |
|
| 115 | + |
|
| 116 | + // make sure we are __not__ connected |
|
| 117 | + if($this->connected()) { |
|
| 118 | + // already connected, generate error |
|
| 119 | + $this->error = array("error" => "Already connected to a server"); |
|
| 120 | + return false; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + if(empty($port)) { |
|
| 124 | + $port = $this->SMTP_PORT; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // connect to the smtp server |
|
| 128 | + $this->smtp_conn = @fsockopen($host, // the host of the server |
|
| 129 | + $port, // the port to use |
|
| 130 | + $errno, // error number if any |
|
| 131 | + $errstr, // error message if any |
|
| 132 | + $tval); // give up after ? secs |
|
| 133 | + // verify we connected properly |
|
| 134 | + if(empty($this->smtp_conn)) { |
|
| 135 | + $this->error = array("error" => "Failed to connect to server", |
|
| 136 | + "errno" => $errno, |
|
| 137 | + "errstr" => $errstr); |
|
| 138 | + if($this->do_debug >= 1) { |
|
| 139 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />'; |
|
| 140 | + } |
|
| 141 | + return false; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // SMTP server can take longer to respond, give longer timeout for first read |
|
| 145 | + // Windows does not have support for this timeout function |
|
| 146 | + if(substr(PHP_OS, 0, 3) != "WIN") |
|
| 147 | + socket_set_timeout($this->smtp_conn, $tval, 0); |
|
| 148 | + |
|
| 149 | + // get any announcement |
|
| 150 | + $announce = $this->get_lines(); |
|
| 151 | + |
|
| 152 | + if($this->do_debug >= 2) { |
|
| 153 | + echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />'; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return true; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -166,39 +166,39 @@ discard block |
||
| 166 | 166 | * @return bool success |
| 167 | 167 | */ |
| 168 | 168 | public function StartTLS() { |
| 169 | - $this->error = null; # to avoid confusion |
|
| 170 | - |
|
| 171 | - if(!$this->connected()) { |
|
| 172 | - $this->error = array("error" => "Called StartTLS() without being connected"); |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - fputs($this->smtp_conn,"STARTTLS" . $this->CRLF); |
|
| 177 | - |
|
| 178 | - $rply = $this->get_lines(); |
|
| 179 | - $code = substr($rply,0,3); |
|
| 180 | - |
|
| 181 | - if($this->do_debug >= 2) { |
|
| 182 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - if($code != 220) { |
|
| 186 | - $this->error = |
|
| 187 | - array("error" => "STARTTLS not accepted from server", |
|
| 188 | - "smtp_code" => $code, |
|
| 189 | - "smtp_msg" => substr($rply,4)); |
|
| 190 | - if($this->do_debug >= 1) { |
|
| 191 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 192 | - } |
|
| 193 | - return false; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - //Begin encrypted connection |
|
| 197 | - if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
| 198 | - return false; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return true; |
|
| 169 | + $this->error = null; # to avoid confusion |
|
| 170 | + |
|
| 171 | + if(!$this->connected()) { |
|
| 172 | + $this->error = array("error" => "Called StartTLS() without being connected"); |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + fputs($this->smtp_conn,"STARTTLS" . $this->CRLF); |
|
| 177 | + |
|
| 178 | + $rply = $this->get_lines(); |
|
| 179 | + $code = substr($rply,0,3); |
|
| 180 | + |
|
| 181 | + if($this->do_debug >= 2) { |
|
| 182 | + echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + if($code != 220) { |
|
| 186 | + $this->error = |
|
| 187 | + array("error" => "STARTTLS not accepted from server", |
|
| 188 | + "smtp_code" => $code, |
|
| 189 | + "smtp_msg" => substr($rply,4)); |
|
| 190 | + if($this->do_debug >= 1) { |
|
| 191 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 192 | + } |
|
| 193 | + return false; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + //Begin encrypted connection |
|
| 197 | + if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return true; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -208,58 +208,58 @@ discard block |
||
| 208 | 208 | * @return bool |
| 209 | 209 | */ |
| 210 | 210 | public function Authenticate($username, $password) { |
| 211 | - // Start authentication |
|
| 212 | - fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); |
|
| 213 | - |
|
| 214 | - $rply = $this->get_lines(); |
|
| 215 | - $code = substr($rply,0,3); |
|
| 216 | - |
|
| 217 | - if($code != 334) { |
|
| 218 | - $this->error = |
|
| 219 | - array("error" => "AUTH not accepted from server", |
|
| 220 | - "smtp_code" => $code, |
|
| 221 | - "smtp_msg" => substr($rply,4)); |
|
| 222 | - if($this->do_debug >= 1) { |
|
| 223 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 224 | - } |
|
| 225 | - return false; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // Send encoded username |
|
| 229 | - fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); |
|
| 230 | - |
|
| 231 | - $rply = $this->get_lines(); |
|
| 232 | - $code = substr($rply,0,3); |
|
| 233 | - |
|
| 234 | - if($code != 334) { |
|
| 235 | - $this->error = |
|
| 236 | - array("error" => "Username not accepted from server", |
|
| 237 | - "smtp_code" => $code, |
|
| 238 | - "smtp_msg" => substr($rply,4)); |
|
| 239 | - if($this->do_debug >= 1) { |
|
| 240 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 241 | - } |
|
| 242 | - return false; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - // Send encoded password |
|
| 246 | - fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); |
|
| 247 | - |
|
| 248 | - $rply = $this->get_lines(); |
|
| 249 | - $code = substr($rply,0,3); |
|
| 250 | - |
|
| 251 | - if($code != 235) { |
|
| 252 | - $this->error = |
|
| 253 | - array("error" => "Password not accepted from server", |
|
| 254 | - "smtp_code" => $code, |
|
| 255 | - "smtp_msg" => substr($rply,4)); |
|
| 256 | - if($this->do_debug >= 1) { |
|
| 257 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 258 | - } |
|
| 259 | - return false; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - return true; |
|
| 211 | + // Start authentication |
|
| 212 | + fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); |
|
| 213 | + |
|
| 214 | + $rply = $this->get_lines(); |
|
| 215 | + $code = substr($rply,0,3); |
|
| 216 | + |
|
| 217 | + if($code != 334) { |
|
| 218 | + $this->error = |
|
| 219 | + array("error" => "AUTH not accepted from server", |
|
| 220 | + "smtp_code" => $code, |
|
| 221 | + "smtp_msg" => substr($rply,4)); |
|
| 222 | + if($this->do_debug >= 1) { |
|
| 223 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 224 | + } |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // Send encoded username |
|
| 229 | + fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); |
|
| 230 | + |
|
| 231 | + $rply = $this->get_lines(); |
|
| 232 | + $code = substr($rply,0,3); |
|
| 233 | + |
|
| 234 | + if($code != 334) { |
|
| 235 | + $this->error = |
|
| 236 | + array("error" => "Username not accepted from server", |
|
| 237 | + "smtp_code" => $code, |
|
| 238 | + "smtp_msg" => substr($rply,4)); |
|
| 239 | + if($this->do_debug >= 1) { |
|
| 240 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 241 | + } |
|
| 242 | + return false; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + // Send encoded password |
|
| 246 | + fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); |
|
| 247 | + |
|
| 248 | + $rply = $this->get_lines(); |
|
| 249 | + $code = substr($rply,0,3); |
|
| 250 | + |
|
| 251 | + if($code != 235) { |
|
| 252 | + $this->error = |
|
| 253 | + array("error" => "Password not accepted from server", |
|
| 254 | + "smtp_code" => $code, |
|
| 255 | + "smtp_msg" => substr($rply,4)); |
|
| 256 | + if($this->do_debug >= 1) { |
|
| 257 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 258 | + } |
|
| 259 | + return false; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + return true; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
@@ -268,19 +268,19 @@ discard block |
||
| 268 | 268 | * @return bool |
| 269 | 269 | */ |
| 270 | 270 | public function Connected() { |
| 271 | - if(!empty($this->smtp_conn)) { |
|
| 272 | - $sock_status = socket_get_status($this->smtp_conn); |
|
| 273 | - if($sock_status["eof"]) { |
|
| 274 | - // the socket is valid but we are not connected |
|
| 275 | - if($this->do_debug >= 1) { |
|
| 276 | - echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected"; |
|
| 277 | - } |
|
| 278 | - $this->Close(); |
|
| 279 | - return false; |
|
| 280 | - } |
|
| 281 | - return true; // everything looks good |
|
| 282 | - } |
|
| 283 | - return false; |
|
| 271 | + if(!empty($this->smtp_conn)) { |
|
| 272 | + $sock_status = socket_get_status($this->smtp_conn); |
|
| 273 | + if($sock_status["eof"]) { |
|
| 274 | + // the socket is valid but we are not connected |
|
| 275 | + if($this->do_debug >= 1) { |
|
| 276 | + echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected"; |
|
| 277 | + } |
|
| 278 | + $this->Close(); |
|
| 279 | + return false; |
|
| 280 | + } |
|
| 281 | + return true; // everything looks good |
|
| 282 | + } |
|
| 283 | + return false; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -291,13 +291,13 @@ discard block |
||
| 291 | 291 | * @return void |
| 292 | 292 | */ |
| 293 | 293 | public function Close() { |
| 294 | - $this->error = null; // so there is no confusion |
|
| 295 | - $this->helo_rply = null; |
|
| 296 | - if(!empty($this->smtp_conn)) { |
|
| 297 | - // close the connection and cleanup |
|
| 298 | - fclose($this->smtp_conn); |
|
| 299 | - $this->smtp_conn = 0; |
|
| 300 | - } |
|
| 294 | + $this->error = null; // so there is no confusion |
|
| 295 | + $this->helo_rply = null; |
|
| 296 | + if(!empty($this->smtp_conn)) { |
|
| 297 | + // close the connection and cleanup |
|
| 298 | + fclose($this->smtp_conn); |
|
| 299 | + $this->smtp_conn = 0; |
|
| 300 | + } |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | ///////////////////////////////////////////////// |
@@ -324,35 +324,35 @@ discard block |
||
| 324 | 324 | * @return bool |
| 325 | 325 | */ |
| 326 | 326 | public function Data($msg_data) { |
| 327 | - $this->error = null; // so no confusion is caused |
|
| 328 | - |
|
| 329 | - if(!$this->connected()) { |
|
| 330 | - $this->error = array( |
|
| 331 | - "error" => "Called Data() without being connected"); |
|
| 332 | - return false; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - fputs($this->smtp_conn,"DATA" . $this->CRLF); |
|
| 336 | - |
|
| 337 | - $rply = $this->get_lines(); |
|
| 338 | - $code = substr($rply,0,3); |
|
| 339 | - |
|
| 340 | - if($this->do_debug >= 2) { |
|
| 341 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - if($code != 354) { |
|
| 345 | - $this->error = |
|
| 346 | - array("error" => "DATA command not accepted from server", |
|
| 347 | - "smtp_code" => $code, |
|
| 348 | - "smtp_msg" => substr($rply,4)); |
|
| 349 | - if($this->do_debug >= 1) { |
|
| 350 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 351 | - } |
|
| 352 | - return false; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /* the server is ready to accept data! |
|
| 327 | + $this->error = null; // so no confusion is caused |
|
| 328 | + |
|
| 329 | + if(!$this->connected()) { |
|
| 330 | + $this->error = array( |
|
| 331 | + "error" => "Called Data() without being connected"); |
|
| 332 | + return false; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + fputs($this->smtp_conn,"DATA" . $this->CRLF); |
|
| 336 | + |
|
| 337 | + $rply = $this->get_lines(); |
|
| 338 | + $code = substr($rply,0,3); |
|
| 339 | + |
|
| 340 | + if($this->do_debug >= 2) { |
|
| 341 | + echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + if($code != 354) { |
|
| 345 | + $this->error = |
|
| 346 | + array("error" => "DATA command not accepted from server", |
|
| 347 | + "smtp_code" => $code, |
|
| 348 | + "smtp_msg" => substr($rply,4)); |
|
| 349 | + if($this->do_debug >= 1) { |
|
| 350 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 351 | + } |
|
| 352 | + return false; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /* the server is ready to accept data! |
|
| 356 | 356 | * according to rfc 821 we should not send more than 1000 |
| 357 | 357 | * including the CRLF |
| 358 | 358 | * characters on a single line so we will break the data up |
@@ -363,12 +363,12 @@ discard block |
||
| 363 | 363 | * line. NOTE: this does not count towards limit. |
| 364 | 364 | */ |
| 365 | 365 | |
| 366 | - // normalize the line breaks so we know the explode works |
|
| 367 | - $msg_data = str_replace("\r\n","\n",$msg_data); |
|
| 368 | - $msg_data = str_replace("\r","\n",$msg_data); |
|
| 369 | - $lines = explode("\n",$msg_data); |
|
| 366 | + // normalize the line breaks so we know the explode works |
|
| 367 | + $msg_data = str_replace("\r\n","\n",$msg_data); |
|
| 368 | + $msg_data = str_replace("\r","\n",$msg_data); |
|
| 369 | + $lines = explode("\n",$msg_data); |
|
| 370 | 370 | |
| 371 | - /* we need to find a good way to determine is headers are |
|
| 371 | + /* we need to find a good way to determine is headers are |
|
| 372 | 372 | * in the msg_data or if it is a straight msg body |
| 373 | 373 | * currently I am assuming rfc 822 definitions of msg headers |
| 374 | 374 | * and if the first field of the first line (':' sperated) |
@@ -377,76 +377,76 @@ discard block |
||
| 377 | 377 | * headers. |
| 378 | 378 | */ |
| 379 | 379 | |
| 380 | - $field = substr($lines[0],0,strpos($lines[0],":")); |
|
| 381 | - $in_headers = false; |
|
| 382 | - if(!empty($field) && !strstr($field," ")) { |
|
| 383 | - $in_headers = true; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - $max_line_length = 998; // used below; set here for ease in change |
|
| 387 | - |
|
| 388 | - while(list(,$line) = @each($lines)) { |
|
| 389 | - $lines_out = null; |
|
| 390 | - if($line == "" && $in_headers) { |
|
| 391 | - $in_headers = false; |
|
| 392 | - } |
|
| 393 | - // ok we need to break this line up into several smaller lines |
|
| 394 | - while(strlen($line) > $max_line_length) { |
|
| 395 | - $pos = strrpos(substr($line,0,$max_line_length)," "); |
|
| 396 | - |
|
| 397 | - // Patch to fix DOS attack |
|
| 398 | - if(!$pos) { |
|
| 399 | - $pos = $max_line_length - 1; |
|
| 400 | - $lines_out[] = substr($line,0,$pos); |
|
| 401 | - $line = substr($line,$pos); |
|
| 402 | - } else { |
|
| 403 | - $lines_out[] = substr($line,0,$pos); |
|
| 404 | - $line = substr($line,$pos + 1); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /* if we are processing headers we need to |
|
| 380 | + $field = substr($lines[0],0,strpos($lines[0],":")); |
|
| 381 | + $in_headers = false; |
|
| 382 | + if(!empty($field) && !strstr($field," ")) { |
|
| 383 | + $in_headers = true; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + $max_line_length = 998; // used below; set here for ease in change |
|
| 387 | + |
|
| 388 | + while(list(,$line) = @each($lines)) { |
|
| 389 | + $lines_out = null; |
|
| 390 | + if($line == "" && $in_headers) { |
|
| 391 | + $in_headers = false; |
|
| 392 | + } |
|
| 393 | + // ok we need to break this line up into several smaller lines |
|
| 394 | + while(strlen($line) > $max_line_length) { |
|
| 395 | + $pos = strrpos(substr($line,0,$max_line_length)," "); |
|
| 396 | + |
|
| 397 | + // Patch to fix DOS attack |
|
| 398 | + if(!$pos) { |
|
| 399 | + $pos = $max_line_length - 1; |
|
| 400 | + $lines_out[] = substr($line,0,$pos); |
|
| 401 | + $line = substr($line,$pos); |
|
| 402 | + } else { |
|
| 403 | + $lines_out[] = substr($line,0,$pos); |
|
| 404 | + $line = substr($line,$pos + 1); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /* if we are processing headers we need to |
|
| 408 | 408 | * add a LWSP-char to the front of the new line |
| 409 | 409 | * rfc 822 on long msg headers |
| 410 | 410 | */ |
| 411 | - if($in_headers) { |
|
| 412 | - $line = "\t" . $line; |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - $lines_out[] = $line; |
|
| 416 | - |
|
| 417 | - // send the lines to the server |
|
| 418 | - while(list(,$line_out) = @each($lines_out)) { |
|
| 419 | - if(strlen($line_out) > 0) |
|
| 420 | - { |
|
| 421 | - if(substr($line_out, 0, 1) == ".") { |
|
| 422 | - $line_out = "." . $line_out; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - fputs($this->smtp_conn,$line_out . $this->CRLF); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // message data has been sent |
|
| 430 | - fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); |
|
| 431 | - |
|
| 432 | - $rply = $this->get_lines(); |
|
| 433 | - $code = substr($rply,0,3); |
|
| 434 | - |
|
| 435 | - if($this->do_debug >= 2) { |
|
| 436 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - if($code != 250) { |
|
| 440 | - $this->error = |
|
| 441 | - array("error" => "DATA not accepted from server", |
|
| 442 | - "smtp_code" => $code, |
|
| 443 | - "smtp_msg" => substr($rply,4)); |
|
| 444 | - if($this->do_debug >= 1) { |
|
| 445 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 446 | - } |
|
| 447 | - return false; |
|
| 448 | - } |
|
| 449 | - return true; |
|
| 411 | + if($in_headers) { |
|
| 412 | + $line = "\t" . $line; |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + $lines_out[] = $line; |
|
| 416 | + |
|
| 417 | + // send the lines to the server |
|
| 418 | + while(list(,$line_out) = @each($lines_out)) { |
|
| 419 | + if(strlen($line_out) > 0) |
|
| 420 | + { |
|
| 421 | + if(substr($line_out, 0, 1) == ".") { |
|
| 422 | + $line_out = "." . $line_out; |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + fputs($this->smtp_conn,$line_out . $this->CRLF); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // message data has been sent |
|
| 430 | + fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); |
|
| 431 | + |
|
| 432 | + $rply = $this->get_lines(); |
|
| 433 | + $code = substr($rply,0,3); |
|
| 434 | + |
|
| 435 | + if($this->do_debug >= 2) { |
|
| 436 | + echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + if($code != 250) { |
|
| 440 | + $this->error = |
|
| 441 | + array("error" => "DATA not accepted from server", |
|
| 442 | + "smtp_code" => $code, |
|
| 443 | + "smtp_msg" => substr($rply,4)); |
|
| 444 | + if($this->do_debug >= 1) { |
|
| 445 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 446 | + } |
|
| 447 | + return false; |
|
| 448 | + } |
|
| 449 | + return true; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
@@ -462,28 +462,28 @@ discard block |
||
| 462 | 462 | * @return bool |
| 463 | 463 | */ |
| 464 | 464 | public function Hello($host = '') { |
| 465 | - $this->error = null; // so no confusion is caused |
|
| 466 | - |
|
| 467 | - if(!$this->connected()) { |
|
| 468 | - $this->error = array( |
|
| 469 | - "error" => "Called Hello() without being connected"); |
|
| 470 | - return false; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - // if hostname for HELO was not specified send default |
|
| 474 | - if(empty($host)) { |
|
| 475 | - // determine appropriate default to send to server |
|
| 476 | - $host = "localhost"; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - // Send extended hello first (RFC 2821) |
|
| 480 | - if(!$this->SendHello("EHLO", $host)) { |
|
| 481 | - if(!$this->SendHello("HELO", $host)) { |
|
| 482 | - return false; |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return true; |
|
| 465 | + $this->error = null; // so no confusion is caused |
|
| 466 | + |
|
| 467 | + if(!$this->connected()) { |
|
| 468 | + $this->error = array( |
|
| 469 | + "error" => "Called Hello() without being connected"); |
|
| 470 | + return false; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + // if hostname for HELO was not specified send default |
|
| 474 | + if(empty($host)) { |
|
| 475 | + // determine appropriate default to send to server |
|
| 476 | + $host = "localhost"; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + // Send extended hello first (RFC 2821) |
|
| 480 | + if(!$this->SendHello("EHLO", $host)) { |
|
| 481 | + if(!$this->SendHello("HELO", $host)) { |
|
| 482 | + return false; |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return true; |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -492,29 +492,29 @@ discard block |
||
| 492 | 492 | * @return bool |
| 493 | 493 | */ |
| 494 | 494 | private function SendHello($hello, $host) { |
| 495 | - fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); |
|
| 495 | + fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); |
|
| 496 | 496 | |
| 497 | - $rply = $this->get_lines(); |
|
| 498 | - $code = substr($rply,0,3); |
|
| 497 | + $rply = $this->get_lines(); |
|
| 498 | + $code = substr($rply,0,3); |
|
| 499 | 499 | |
| 500 | - if($this->do_debug >= 2) { |
|
| 501 | - echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />'; |
|
| 502 | - } |
|
| 500 | + if($this->do_debug >= 2) { |
|
| 501 | + echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />'; |
|
| 502 | + } |
|
| 503 | 503 | |
| 504 | - if($code != 250) { |
|
| 505 | - $this->error = |
|
| 506 | - array("error" => $hello . " not accepted from server", |
|
| 507 | - "smtp_code" => $code, |
|
| 508 | - "smtp_msg" => substr($rply,4)); |
|
| 509 | - if($this->do_debug >= 1) { |
|
| 510 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 511 | - } |
|
| 512 | - return false; |
|
| 513 | - } |
|
| 504 | + if($code != 250) { |
|
| 505 | + $this->error = |
|
| 506 | + array("error" => $hello . " not accepted from server", |
|
| 507 | + "smtp_code" => $code, |
|
| 508 | + "smtp_msg" => substr($rply,4)); |
|
| 509 | + if($this->do_debug >= 1) { |
|
| 510 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 511 | + } |
|
| 512 | + return false; |
|
| 513 | + } |
|
| 514 | 514 | |
| 515 | - $this->helo_rply = $rply; |
|
| 515 | + $this->helo_rply = $rply; |
|
| 516 | 516 | |
| 517 | - return true; |
|
| 517 | + return true; |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -532,35 +532,35 @@ discard block |
||
| 532 | 532 | * @return bool |
| 533 | 533 | */ |
| 534 | 534 | public function Mail($from) { |
| 535 | - $this->error = null; // so no confusion is caused |
|
| 536 | - |
|
| 537 | - if(!$this->connected()) { |
|
| 538 | - $this->error = array( |
|
| 539 | - "error" => "Called Mail() without being connected"); |
|
| 540 | - return false; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - $useVerp = ($this->do_verp ? "XVERP" : ""); |
|
| 544 | - fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); |
|
| 545 | - |
|
| 546 | - $rply = $this->get_lines(); |
|
| 547 | - $code = substr($rply,0,3); |
|
| 548 | - |
|
| 549 | - if($this->do_debug >= 2) { |
|
| 550 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - if($code != 250) { |
|
| 554 | - $this->error = |
|
| 555 | - array("error" => "MAIL not accepted from server", |
|
| 556 | - "smtp_code" => $code, |
|
| 557 | - "smtp_msg" => substr($rply,4)); |
|
| 558 | - if($this->do_debug >= 1) { |
|
| 559 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 560 | - } |
|
| 561 | - return false; |
|
| 562 | - } |
|
| 563 | - return true; |
|
| 535 | + $this->error = null; // so no confusion is caused |
|
| 536 | + |
|
| 537 | + if(!$this->connected()) { |
|
| 538 | + $this->error = array( |
|
| 539 | + "error" => "Called Mail() without being connected"); |
|
| 540 | + return false; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + $useVerp = ($this->do_verp ? "XVERP" : ""); |
|
| 544 | + fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); |
|
| 545 | + |
|
| 546 | + $rply = $this->get_lines(); |
|
| 547 | + $code = substr($rply,0,3); |
|
| 548 | + |
|
| 549 | + if($this->do_debug >= 2) { |
|
| 550 | + echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + if($code != 250) { |
|
| 554 | + $this->error = |
|
| 555 | + array("error" => "MAIL not accepted from server", |
|
| 556 | + "smtp_code" => $code, |
|
| 557 | + "smtp_msg" => substr($rply,4)); |
|
| 558 | + if($this->do_debug >= 1) { |
|
| 559 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 560 | + } |
|
| 561 | + return false; |
|
| 562 | + } |
|
| 563 | + return true; |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -575,44 +575,44 @@ discard block |
||
| 575 | 575 | * @return bool |
| 576 | 576 | */ |
| 577 | 577 | public function Quit($close_on_error=true) { |
| 578 | - $this->error = null; // so there is no confusion |
|
| 579 | - |
|
| 580 | - if(!$this->connected()) { |
|
| 581 | - $this->error = array( |
|
| 582 | - "error" => "Called Quit() without being connected"); |
|
| 583 | - return false; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - // send the quit command to the server |
|
| 587 | - fputs($this->smtp_conn,"quit" . $this->CRLF); |
|
| 588 | - |
|
| 589 | - // get any good-bye messages |
|
| 590 | - $byemsg = $this->get_lines(); |
|
| 591 | - |
|
| 592 | - if($this->do_debug >= 2) { |
|
| 593 | - echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />'; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - $rval = true; |
|
| 597 | - $e = null; |
|
| 598 | - |
|
| 599 | - $code = substr($byemsg,0,3); |
|
| 600 | - if($code != 221) { |
|
| 601 | - // use e as a tmp var cause Close will overwrite $this->error |
|
| 602 | - $e = array("error" => "SMTP server rejected quit command", |
|
| 603 | - "smtp_code" => $code, |
|
| 604 | - "smtp_rply" => substr($byemsg,4)); |
|
| 605 | - $rval = false; |
|
| 606 | - if($this->do_debug >= 1) { |
|
| 607 | - echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />'; |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - if(empty($e) || $close_on_error) { |
|
| 612 | - $this->Close(); |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - return $rval; |
|
| 578 | + $this->error = null; // so there is no confusion |
|
| 579 | + |
|
| 580 | + if(!$this->connected()) { |
|
| 581 | + $this->error = array( |
|
| 582 | + "error" => "Called Quit() without being connected"); |
|
| 583 | + return false; |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + // send the quit command to the server |
|
| 587 | + fputs($this->smtp_conn,"quit" . $this->CRLF); |
|
| 588 | + |
|
| 589 | + // get any good-bye messages |
|
| 590 | + $byemsg = $this->get_lines(); |
|
| 591 | + |
|
| 592 | + if($this->do_debug >= 2) { |
|
| 593 | + echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />'; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + $rval = true; |
|
| 597 | + $e = null; |
|
| 598 | + |
|
| 599 | + $code = substr($byemsg,0,3); |
|
| 600 | + if($code != 221) { |
|
| 601 | + // use e as a tmp var cause Close will overwrite $this->error |
|
| 602 | + $e = array("error" => "SMTP server rejected quit command", |
|
| 603 | + "smtp_code" => $code, |
|
| 604 | + "smtp_rply" => substr($byemsg,4)); |
|
| 605 | + $rval = false; |
|
| 606 | + if($this->do_debug >= 1) { |
|
| 607 | + echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />'; |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + if(empty($e) || $close_on_error) { |
|
| 612 | + $this->Close(); |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + return $rval; |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -628,34 +628,34 @@ discard block |
||
| 628 | 628 | * @return bool |
| 629 | 629 | */ |
| 630 | 630 | public function Recipient($to) { |
| 631 | - $this->error = null; // so no confusion is caused |
|
| 632 | - |
|
| 633 | - if(!$this->connected()) { |
|
| 634 | - $this->error = array( |
|
| 635 | - "error" => "Called Recipient() without being connected"); |
|
| 636 | - return false; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF); |
|
| 640 | - |
|
| 641 | - $rply = $this->get_lines(); |
|
| 642 | - $code = substr($rply,0,3); |
|
| 643 | - |
|
| 644 | - if($this->do_debug >= 2) { |
|
| 645 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - if($code != 250 && $code != 251) { |
|
| 649 | - $this->error = |
|
| 650 | - array("error" => "RCPT not accepted from server", |
|
| 651 | - "smtp_code" => $code, |
|
| 652 | - "smtp_msg" => substr($rply,4)); |
|
| 653 | - if($this->do_debug >= 1) { |
|
| 654 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 655 | - } |
|
| 656 | - return false; |
|
| 657 | - } |
|
| 658 | - return true; |
|
| 631 | + $this->error = null; // so no confusion is caused |
|
| 632 | + |
|
| 633 | + if(!$this->connected()) { |
|
| 634 | + $this->error = array( |
|
| 635 | + "error" => "Called Recipient() without being connected"); |
|
| 636 | + return false; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF); |
|
| 640 | + |
|
| 641 | + $rply = $this->get_lines(); |
|
| 642 | + $code = substr($rply,0,3); |
|
| 643 | + |
|
| 644 | + if($this->do_debug >= 2) { |
|
| 645 | + echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + if($code != 250 && $code != 251) { |
|
| 649 | + $this->error = |
|
| 650 | + array("error" => "RCPT not accepted from server", |
|
| 651 | + "smtp_code" => $code, |
|
| 652 | + "smtp_msg" => substr($rply,4)); |
|
| 653 | + if($this->do_debug >= 1) { |
|
| 654 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 655 | + } |
|
| 656 | + return false; |
|
| 657 | + } |
|
| 658 | + return true; |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | /** |
@@ -671,35 +671,35 @@ discard block |
||
| 671 | 671 | * @return bool |
| 672 | 672 | */ |
| 673 | 673 | public function Reset() { |
| 674 | - $this->error = null; // so no confusion is caused |
|
| 675 | - |
|
| 676 | - if(!$this->connected()) { |
|
| 677 | - $this->error = array( |
|
| 678 | - "error" => "Called Reset() without being connected"); |
|
| 679 | - return false; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - fputs($this->smtp_conn,"RSET" . $this->CRLF); |
|
| 683 | - |
|
| 684 | - $rply = $this->get_lines(); |
|
| 685 | - $code = substr($rply,0,3); |
|
| 686 | - |
|
| 687 | - if($this->do_debug >= 2) { |
|
| 688 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - if($code != 250) { |
|
| 692 | - $this->error = |
|
| 693 | - array("error" => "RSET failed", |
|
| 694 | - "smtp_code" => $code, |
|
| 695 | - "smtp_msg" => substr($rply,4)); |
|
| 696 | - if($this->do_debug >= 1) { |
|
| 697 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 698 | - } |
|
| 699 | - return false; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - return true; |
|
| 674 | + $this->error = null; // so no confusion is caused |
|
| 675 | + |
|
| 676 | + if(!$this->connected()) { |
|
| 677 | + $this->error = array( |
|
| 678 | + "error" => "Called Reset() without being connected"); |
|
| 679 | + return false; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + fputs($this->smtp_conn,"RSET" . $this->CRLF); |
|
| 683 | + |
|
| 684 | + $rply = $this->get_lines(); |
|
| 685 | + $code = substr($rply,0,3); |
|
| 686 | + |
|
| 687 | + if($this->do_debug >= 2) { |
|
| 688 | + echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + if($code != 250) { |
|
| 692 | + $this->error = |
|
| 693 | + array("error" => "RSET failed", |
|
| 694 | + "smtp_code" => $code, |
|
| 695 | + "smtp_msg" => substr($rply,4)); |
|
| 696 | + if($this->do_debug >= 1) { |
|
| 697 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 698 | + } |
|
| 699 | + return false; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + return true; |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | /** |
@@ -719,34 +719,34 @@ discard block |
||
| 719 | 719 | * @return bool |
| 720 | 720 | */ |
| 721 | 721 | public function SendAndMail($from) { |
| 722 | - $this->error = null; // so no confusion is caused |
|
| 723 | - |
|
| 724 | - if(!$this->connected()) { |
|
| 725 | - $this->error = array( |
|
| 726 | - "error" => "Called SendAndMail() without being connected"); |
|
| 727 | - return false; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF); |
|
| 731 | - |
|
| 732 | - $rply = $this->get_lines(); |
|
| 733 | - $code = substr($rply,0,3); |
|
| 734 | - |
|
| 735 | - if($this->do_debug >= 2) { |
|
| 736 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - if($code != 250) { |
|
| 740 | - $this->error = |
|
| 741 | - array("error" => "SAML not accepted from server", |
|
| 742 | - "smtp_code" => $code, |
|
| 743 | - "smtp_msg" => substr($rply,4)); |
|
| 744 | - if($this->do_debug >= 1) { |
|
| 745 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 746 | - } |
|
| 747 | - return false; |
|
| 748 | - } |
|
| 749 | - return true; |
|
| 722 | + $this->error = null; // so no confusion is caused |
|
| 723 | + |
|
| 724 | + if(!$this->connected()) { |
|
| 725 | + $this->error = array( |
|
| 726 | + "error" => "Called SendAndMail() without being connected"); |
|
| 727 | + return false; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF); |
|
| 731 | + |
|
| 732 | + $rply = $this->get_lines(); |
|
| 733 | + $code = substr($rply,0,3); |
|
| 734 | + |
|
| 735 | + if($this->do_debug >= 2) { |
|
| 736 | + echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + if($code != 250) { |
|
| 740 | + $this->error = |
|
| 741 | + array("error" => "SAML not accepted from server", |
|
| 742 | + "smtp_code" => $code, |
|
| 743 | + "smtp_msg" => substr($rply,4)); |
|
| 744 | + if($this->do_debug >= 1) { |
|
| 745 | + echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 746 | + } |
|
| 747 | + return false; |
|
| 748 | + } |
|
| 749 | + return true; |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | /** |
@@ -763,22 +763,22 @@ discard block |
||
| 763 | 763 | * @return bool |
| 764 | 764 | */ |
| 765 | 765 | public function Turn() { |
| 766 | - $this->error = array("error" => "This method, TURN, of the SMTP ". |
|
| 767 | - "is not implemented"); |
|
| 768 | - if($this->do_debug >= 1) { |
|
| 769 | - echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />'; |
|
| 770 | - } |
|
| 771 | - return false; |
|
| 766 | + $this->error = array("error" => "This method, TURN, of the SMTP ". |
|
| 767 | + "is not implemented"); |
|
| 768 | + if($this->do_debug >= 1) { |
|
| 769 | + echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />'; |
|
| 770 | + } |
|
| 771 | + return false; |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | /** |
| 775 | - * Get the current error |
|
| 775 | + * Get the current error |
|
| 776 | 776 | * @access public |
| 777 | - * @return array |
|
| 777 | + * @return array |
|
| 778 | 778 | */ |
| 779 | 779 | public function getError() { |
| 780 | - return $this->error; |
|
| 781 | - } |
|
| 780 | + return $this->error; |
|
| 781 | + } |
|
| 782 | 782 | |
| 783 | 783 | ///////////////////////////////////////////////// |
| 784 | 784 | // INTERNAL FUNCTIONS |
@@ -794,20 +794,20 @@ discard block |
||
| 794 | 794 | * @return string |
| 795 | 795 | */ |
| 796 | 796 | private function get_lines() { |
| 797 | - $data = ""; |
|
| 798 | - while($str = @fgets($this->smtp_conn,515)) { |
|
| 799 | - if($this->do_debug >= 4) { |
|
| 800 | - echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />'; |
|
| 801 | - echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />'; |
|
| 802 | - } |
|
| 803 | - $data .= $str; |
|
| 804 | - if($this->do_debug >= 4) { |
|
| 805 | - echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />'; |
|
| 806 | - } |
|
| 807 | - // if 4th character is a space, we are done reading, break the loop |
|
| 808 | - if(substr($str,3,1) == " ") { break; } |
|
| 809 | - } |
|
| 810 | - return $data; |
|
| 797 | + $data = ""; |
|
| 798 | + while($str = @fgets($this->smtp_conn,515)) { |
|
| 799 | + if($this->do_debug >= 4) { |
|
| 800 | + echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />'; |
|
| 801 | + echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />'; |
|
| 802 | + } |
|
| 803 | + $data .= $str; |
|
| 804 | + if($this->do_debug >= 4) { |
|
| 805 | + echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />'; |
|
| 806 | + } |
|
| 807 | + // if 4th character is a space, we are done reading, break the loop |
|
| 808 | + if(substr($str,3,1) == " ") { break; } |
|
| 809 | + } |
|
| 810 | + return $data; |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | } |
@@ -143,8 +143,9 @@ |
||
| 143 | 143 | |
| 144 | 144 | // SMTP server can take longer to respond, give longer timeout for first read |
| 145 | 145 | // Windows does not have support for this timeout function |
| 146 | - if(substr(PHP_OS, 0, 3) != "WIN") |
|
| 147 | - socket_set_timeout($this->smtp_conn, $tval, 0); |
|
| 146 | + if(substr(PHP_OS, 0, 3) != "WIN") { |
|
| 147 | + socket_set_timeout($this->smtp_conn, $tval, 0); |
|
| 148 | + } |
|
| 148 | 149 | |
| 149 | 150 | // get any announcement |
| 150 | 151 | $announce = $this->get_lines(); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * Sets whether debugging is turned on |
| 64 | 64 | * @var bool |
| 65 | 65 | */ |
| 66 | - public $do_debug; // the level of debug to perform |
|
| 66 | + public $do_debug; // the level of debug to perform |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * Sets VERP use on/off (default is off) |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | // PROPERTIES, PRIVATE AND PROTECTED |
| 76 | 76 | ///////////////////////////////////////////////// |
| 77 | 77 | |
| 78 | - private $smtp_conn; // the socket to the server |
|
| 79 | - private $error; // error if any on the last call |
|
| 80 | - private $helo_rply; // the reply the server sent to us for HELO |
|
| 78 | + private $smtp_conn; // the socket to the server |
|
| 79 | + private $error; // error if any on the last call |
|
| 80 | + private $helo_rply; // the reply the server sent to us for HELO |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * Initialize the class so that the data is in a known state. |
@@ -109,48 +109,48 @@ discard block |
||
| 109 | 109 | * @access public |
| 110 | 110 | * @return bool |
| 111 | 111 | */ |
| 112 | - public function Connect($host,$port=0,$tval=30) { |
|
| 112 | + public function Connect($host, $port = 0, $tval = 30) { |
|
| 113 | 113 | // set the error val to null so there is no confusion |
| 114 | 114 | $this->error = null; |
| 115 | 115 | |
| 116 | 116 | // make sure we are __not__ connected |
| 117 | - if($this->connected()) { |
|
| 117 | + if ($this->connected()) { |
|
| 118 | 118 | // already connected, generate error |
| 119 | 119 | $this->error = array("error" => "Already connected to a server"); |
| 120 | 120 | return false; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - if(empty($port)) { |
|
| 123 | + if (empty($port)) { |
|
| 124 | 124 | $port = $this->SMTP_PORT; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // connect to the smtp server |
| 128 | - $this->smtp_conn = @fsockopen($host, // the host of the server |
|
| 129 | - $port, // the port to use |
|
| 130 | - $errno, // error number if any |
|
| 131 | - $errstr, // error message if any |
|
| 132 | - $tval); // give up after ? secs |
|
| 128 | + $this->smtp_conn = @fsockopen($host, // the host of the server |
|
| 129 | + $port, // the port to use |
|
| 130 | + $errno, // error number if any |
|
| 131 | + $errstr, // error message if any |
|
| 132 | + $tval); // give up after ? secs |
|
| 133 | 133 | // verify we connected properly |
| 134 | - if(empty($this->smtp_conn)) { |
|
| 134 | + if (empty($this->smtp_conn)) { |
|
| 135 | 135 | $this->error = array("error" => "Failed to connect to server", |
| 136 | 136 | "errno" => $errno, |
| 137 | 137 | "errstr" => $errstr); |
| 138 | - if($this->do_debug >= 1) { |
|
| 139 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />'; |
|
| 138 | + if ($this->do_debug >= 1) { |
|
| 139 | + echo "SMTP -> ERROR: ".$this->error["error"].": $errstr ($errno)".$this->CRLF.'<br />'; |
|
| 140 | 140 | } |
| 141 | 141 | return false; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // SMTP server can take longer to respond, give longer timeout for first read |
| 145 | 145 | // Windows does not have support for this timeout function |
| 146 | - if(substr(PHP_OS, 0, 3) != "WIN") |
|
| 146 | + if (substr(PHP_OS, 0, 3) != "WIN") |
|
| 147 | 147 | socket_set_timeout($this->smtp_conn, $tval, 0); |
| 148 | 148 | |
| 149 | 149 | // get any announcement |
| 150 | 150 | $announce = $this->get_lines(); |
| 151 | 151 | |
| 152 | - if($this->do_debug >= 2) { |
|
| 153 | - echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />'; |
|
| 152 | + if ($this->do_debug >= 2) { |
|
| 153 | + echo "SMTP -> FROM SERVER:".$announce.$this->CRLF.'<br />'; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | return true; |
@@ -168,33 +168,33 @@ discard block |
||
| 168 | 168 | public function StartTLS() { |
| 169 | 169 | $this->error = null; # to avoid confusion |
| 170 | 170 | |
| 171 | - if(!$this->connected()) { |
|
| 171 | + if (!$this->connected()) { |
|
| 172 | 172 | $this->error = array("error" => "Called StartTLS() without being connected"); |
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - fputs($this->smtp_conn,"STARTTLS" . $this->CRLF); |
|
| 176 | + fputs($this->smtp_conn, "STARTTLS".$this->CRLF); |
|
| 177 | 177 | |
| 178 | 178 | $rply = $this->get_lines(); |
| 179 | - $code = substr($rply,0,3); |
|
| 179 | + $code = substr($rply, 0, 3); |
|
| 180 | 180 | |
| 181 | - if($this->do_debug >= 2) { |
|
| 182 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 181 | + if ($this->do_debug >= 2) { |
|
| 182 | + echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />'; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if($code != 220) { |
|
| 185 | + if ($code != 220) { |
|
| 186 | 186 | $this->error = |
| 187 | 187 | array("error" => "STARTTLS not accepted from server", |
| 188 | 188 | "smtp_code" => $code, |
| 189 | - "smtp_msg" => substr($rply,4)); |
|
| 190 | - if($this->do_debug >= 1) { |
|
| 191 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 189 | + "smtp_msg" => substr($rply, 4)); |
|
| 190 | + if ($this->do_debug >= 1) { |
|
| 191 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 192 | 192 | } |
| 193 | 193 | return false; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | //Begin encrypted connection |
| 197 | - if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
| 197 | + if (!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
| 198 | 198 | return false; |
| 199 | 199 | } |
| 200 | 200 | |
@@ -209,52 +209,52 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | public function Authenticate($username, $password) { |
| 211 | 211 | // Start authentication |
| 212 | - fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); |
|
| 212 | + fputs($this->smtp_conn, "AUTH LOGIN".$this->CRLF); |
|
| 213 | 213 | |
| 214 | 214 | $rply = $this->get_lines(); |
| 215 | - $code = substr($rply,0,3); |
|
| 215 | + $code = substr($rply, 0, 3); |
|
| 216 | 216 | |
| 217 | - if($code != 334) { |
|
| 217 | + if ($code != 334) { |
|
| 218 | 218 | $this->error = |
| 219 | 219 | array("error" => "AUTH not accepted from server", |
| 220 | 220 | "smtp_code" => $code, |
| 221 | - "smtp_msg" => substr($rply,4)); |
|
| 222 | - if($this->do_debug >= 1) { |
|
| 223 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 221 | + "smtp_msg" => substr($rply, 4)); |
|
| 222 | + if ($this->do_debug >= 1) { |
|
| 223 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 224 | 224 | } |
| 225 | 225 | return false; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | // Send encoded username |
| 229 | - fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); |
|
| 229 | + fputs($this->smtp_conn, base64_encode($username).$this->CRLF); |
|
| 230 | 230 | |
| 231 | 231 | $rply = $this->get_lines(); |
| 232 | - $code = substr($rply,0,3); |
|
| 232 | + $code = substr($rply, 0, 3); |
|
| 233 | 233 | |
| 234 | - if($code != 334) { |
|
| 234 | + if ($code != 334) { |
|
| 235 | 235 | $this->error = |
| 236 | 236 | array("error" => "Username not accepted from server", |
| 237 | 237 | "smtp_code" => $code, |
| 238 | - "smtp_msg" => substr($rply,4)); |
|
| 239 | - if($this->do_debug >= 1) { |
|
| 240 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 238 | + "smtp_msg" => substr($rply, 4)); |
|
| 239 | + if ($this->do_debug >= 1) { |
|
| 240 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 241 | 241 | } |
| 242 | 242 | return false; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // Send encoded password |
| 246 | - fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); |
|
| 246 | + fputs($this->smtp_conn, base64_encode($password).$this->CRLF); |
|
| 247 | 247 | |
| 248 | 248 | $rply = $this->get_lines(); |
| 249 | - $code = substr($rply,0,3); |
|
| 249 | + $code = substr($rply, 0, 3); |
|
| 250 | 250 | |
| 251 | - if($code != 235) { |
|
| 251 | + if ($code != 235) { |
|
| 252 | 252 | $this->error = |
| 253 | 253 | array("error" => "Password not accepted from server", |
| 254 | 254 | "smtp_code" => $code, |
| 255 | - "smtp_msg" => substr($rply,4)); |
|
| 256 | - if($this->do_debug >= 1) { |
|
| 257 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 255 | + "smtp_msg" => substr($rply, 4)); |
|
| 256 | + if ($this->do_debug >= 1) { |
|
| 257 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 258 | 258 | } |
| 259 | 259 | return false; |
| 260 | 260 | } |
@@ -268,12 +268,12 @@ discard block |
||
| 268 | 268 | * @return bool |
| 269 | 269 | */ |
| 270 | 270 | public function Connected() { |
| 271 | - if(!empty($this->smtp_conn)) { |
|
| 271 | + if (!empty($this->smtp_conn)) { |
|
| 272 | 272 | $sock_status = socket_get_status($this->smtp_conn); |
| 273 | - if($sock_status["eof"]) { |
|
| 273 | + if ($sock_status["eof"]) { |
|
| 274 | 274 | // the socket is valid but we are not connected |
| 275 | - if($this->do_debug >= 1) { |
|
| 276 | - echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected"; |
|
| 275 | + if ($this->do_debug >= 1) { |
|
| 276 | + echo "SMTP -> NOTICE:".$this->CRLF."EOF caught while checking if connected"; |
|
| 277 | 277 | } |
| 278 | 278 | $this->Close(); |
| 279 | 279 | return false; |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | public function Close() { |
| 294 | 294 | $this->error = null; // so there is no confusion |
| 295 | 295 | $this->helo_rply = null; |
| 296 | - if(!empty($this->smtp_conn)) { |
|
| 296 | + if (!empty($this->smtp_conn)) { |
|
| 297 | 297 | // close the connection and cleanup |
| 298 | 298 | fclose($this->smtp_conn); |
| 299 | 299 | $this->smtp_conn = 0; |
@@ -326,28 +326,28 @@ discard block |
||
| 326 | 326 | public function Data($msg_data) { |
| 327 | 327 | $this->error = null; // so no confusion is caused |
| 328 | 328 | |
| 329 | - if(!$this->connected()) { |
|
| 329 | + if (!$this->connected()) { |
|
| 330 | 330 | $this->error = array( |
| 331 | 331 | "error" => "Called Data() without being connected"); |
| 332 | 332 | return false; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - fputs($this->smtp_conn,"DATA" . $this->CRLF); |
|
| 335 | + fputs($this->smtp_conn, "DATA".$this->CRLF); |
|
| 336 | 336 | |
| 337 | 337 | $rply = $this->get_lines(); |
| 338 | - $code = substr($rply,0,3); |
|
| 338 | + $code = substr($rply, 0, 3); |
|
| 339 | 339 | |
| 340 | - if($this->do_debug >= 2) { |
|
| 341 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 340 | + if ($this->do_debug >= 2) { |
|
| 341 | + echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />'; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - if($code != 354) { |
|
| 344 | + if ($code != 354) { |
|
| 345 | 345 | $this->error = |
| 346 | 346 | array("error" => "DATA command not accepted from server", |
| 347 | 347 | "smtp_code" => $code, |
| 348 | - "smtp_msg" => substr($rply,4)); |
|
| 349 | - if($this->do_debug >= 1) { |
|
| 350 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 348 | + "smtp_msg" => substr($rply, 4)); |
|
| 349 | + if ($this->do_debug >= 1) { |
|
| 350 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 351 | 351 | } |
| 352 | 352 | return false; |
| 353 | 353 | } |
@@ -364,9 +364,9 @@ discard block |
||
| 364 | 364 | */ |
| 365 | 365 | |
| 366 | 366 | // normalize the line breaks so we know the explode works |
| 367 | - $msg_data = str_replace("\r\n","\n",$msg_data); |
|
| 368 | - $msg_data = str_replace("\r","\n",$msg_data); |
|
| 369 | - $lines = explode("\n",$msg_data); |
|
| 367 | + $msg_data = str_replace("\r\n", "\n", $msg_data); |
|
| 368 | + $msg_data = str_replace("\r", "\n", $msg_data); |
|
| 369 | + $lines = explode("\n", $msg_data); |
|
| 370 | 370 | |
| 371 | 371 | /* we need to find a good way to determine is headers are |
| 372 | 372 | * in the msg_data or if it is a straight msg body |
@@ -377,72 +377,72 @@ discard block |
||
| 377 | 377 | * headers. |
| 378 | 378 | */ |
| 379 | 379 | |
| 380 | - $field = substr($lines[0],0,strpos($lines[0],":")); |
|
| 380 | + $field = substr($lines[0], 0, strpos($lines[0], ":")); |
|
| 381 | 381 | $in_headers = false; |
| 382 | - if(!empty($field) && !strstr($field," ")) { |
|
| 382 | + if (!empty($field) && !strstr($field, " ")) { |
|
| 383 | 383 | $in_headers = true; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | $max_line_length = 998; // used below; set here for ease in change |
| 387 | 387 | |
| 388 | - while(list(,$line) = @each($lines)) { |
|
| 388 | + while (list(,$line) = @each($lines)) { |
|
| 389 | 389 | $lines_out = null; |
| 390 | - if($line == "" && $in_headers) { |
|
| 390 | + if ($line == "" && $in_headers) { |
|
| 391 | 391 | $in_headers = false; |
| 392 | 392 | } |
| 393 | 393 | // ok we need to break this line up into several smaller lines |
| 394 | - while(strlen($line) > $max_line_length) { |
|
| 395 | - $pos = strrpos(substr($line,0,$max_line_length)," "); |
|
| 394 | + while (strlen($line) > $max_line_length) { |
|
| 395 | + $pos = strrpos(substr($line, 0, $max_line_length), " "); |
|
| 396 | 396 | |
| 397 | 397 | // Patch to fix DOS attack |
| 398 | - if(!$pos) { |
|
| 398 | + if (!$pos) { |
|
| 399 | 399 | $pos = $max_line_length - 1; |
| 400 | - $lines_out[] = substr($line,0,$pos); |
|
| 401 | - $line = substr($line,$pos); |
|
| 400 | + $lines_out[] = substr($line, 0, $pos); |
|
| 401 | + $line = substr($line, $pos); |
|
| 402 | 402 | } else { |
| 403 | - $lines_out[] = substr($line,0,$pos); |
|
| 404 | - $line = substr($line,$pos + 1); |
|
| 403 | + $lines_out[] = substr($line, 0, $pos); |
|
| 404 | + $line = substr($line, $pos + 1); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | /* if we are processing headers we need to |
| 408 | 408 | * add a LWSP-char to the front of the new line |
| 409 | 409 | * rfc 822 on long msg headers |
| 410 | 410 | */ |
| 411 | - if($in_headers) { |
|
| 412 | - $line = "\t" . $line; |
|
| 411 | + if ($in_headers) { |
|
| 412 | + $line = "\t".$line; |
|
| 413 | 413 | } |
| 414 | 414 | } |
| 415 | 415 | $lines_out[] = $line; |
| 416 | 416 | |
| 417 | 417 | // send the lines to the server |
| 418 | - while(list(,$line_out) = @each($lines_out)) { |
|
| 419 | - if(strlen($line_out) > 0) |
|
| 418 | + while (list(,$line_out) = @each($lines_out)) { |
|
| 419 | + if (strlen($line_out) > 0) |
|
| 420 | 420 | { |
| 421 | - if(substr($line_out, 0, 1) == ".") { |
|
| 422 | - $line_out = "." . $line_out; |
|
| 421 | + if (substr($line_out, 0, 1) == ".") { |
|
| 422 | + $line_out = ".".$line_out; |
|
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | - fputs($this->smtp_conn,$line_out . $this->CRLF); |
|
| 425 | + fputs($this->smtp_conn, $line_out.$this->CRLF); |
|
| 426 | 426 | } |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | // message data has been sent |
| 430 | - fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF); |
|
| 430 | + fputs($this->smtp_conn, $this->CRLF.".".$this->CRLF); |
|
| 431 | 431 | |
| 432 | 432 | $rply = $this->get_lines(); |
| 433 | - $code = substr($rply,0,3); |
|
| 433 | + $code = substr($rply, 0, 3); |
|
| 434 | 434 | |
| 435 | - if($this->do_debug >= 2) { |
|
| 436 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 435 | + if ($this->do_debug >= 2) { |
|
| 436 | + echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />'; |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | - if($code != 250) { |
|
| 439 | + if ($code != 250) { |
|
| 440 | 440 | $this->error = |
| 441 | 441 | array("error" => "DATA not accepted from server", |
| 442 | 442 | "smtp_code" => $code, |
| 443 | - "smtp_msg" => substr($rply,4)); |
|
| 444 | - if($this->do_debug >= 1) { |
|
| 445 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 443 | + "smtp_msg" => substr($rply, 4)); |
|
| 444 | + if ($this->do_debug >= 1) { |
|
| 445 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 446 | 446 | } |
| 447 | 447 | return false; |
| 448 | 448 | } |
@@ -464,21 +464,21 @@ discard block |
||
| 464 | 464 | public function Hello($host = '') { |
| 465 | 465 | $this->error = null; // so no confusion is caused |
| 466 | 466 | |
| 467 | - if(!$this->connected()) { |
|
| 467 | + if (!$this->connected()) { |
|
| 468 | 468 | $this->error = array( |
| 469 | 469 | "error" => "Called Hello() without being connected"); |
| 470 | 470 | return false; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | // if hostname for HELO was not specified send default |
| 474 | - if(empty($host)) { |
|
| 474 | + if (empty($host)) { |
|
| 475 | 475 | // determine appropriate default to send to server |
| 476 | 476 | $host = "localhost"; |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | // Send extended hello first (RFC 2821) |
| 480 | - if(!$this->SendHello("EHLO", $host)) { |
|
| 481 | - if(!$this->SendHello("HELO", $host)) { |
|
| 480 | + if (!$this->SendHello("EHLO", $host)) { |
|
| 481 | + if (!$this->SendHello("HELO", $host)) { |
|
| 482 | 482 | return false; |
| 483 | 483 | } |
| 484 | 484 | } |
@@ -492,22 +492,22 @@ discard block |
||
| 492 | 492 | * @return bool |
| 493 | 493 | */ |
| 494 | 494 | private function SendHello($hello, $host) { |
| 495 | - fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF); |
|
| 495 | + fputs($this->smtp_conn, $hello." ".$host.$this->CRLF); |
|
| 496 | 496 | |
| 497 | 497 | $rply = $this->get_lines(); |
| 498 | - $code = substr($rply,0,3); |
|
| 498 | + $code = substr($rply, 0, 3); |
|
| 499 | 499 | |
| 500 | - if($this->do_debug >= 2) { |
|
| 501 | - echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />'; |
|
| 500 | + if ($this->do_debug >= 2) { |
|
| 501 | + echo "SMTP -> FROM SERVER: ".$rply.$this->CRLF.'<br />'; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | - if($code != 250) { |
|
| 504 | + if ($code != 250) { |
|
| 505 | 505 | $this->error = |
| 506 | - array("error" => $hello . " not accepted from server", |
|
| 506 | + array("error" => $hello." not accepted from server", |
|
| 507 | 507 | "smtp_code" => $code, |
| 508 | - "smtp_msg" => substr($rply,4)); |
|
| 509 | - if($this->do_debug >= 1) { |
|
| 510 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 508 | + "smtp_msg" => substr($rply, 4)); |
|
| 509 | + if ($this->do_debug >= 1) { |
|
| 510 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 511 | 511 | } |
| 512 | 512 | return false; |
| 513 | 513 | } |
@@ -534,29 +534,29 @@ discard block |
||
| 534 | 534 | public function Mail($from) { |
| 535 | 535 | $this->error = null; // so no confusion is caused |
| 536 | 536 | |
| 537 | - if(!$this->connected()) { |
|
| 537 | + if (!$this->connected()) { |
|
| 538 | 538 | $this->error = array( |
| 539 | 539 | "error" => "Called Mail() without being connected"); |
| 540 | 540 | return false; |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | $useVerp = ($this->do_verp ? "XVERP" : ""); |
| 544 | - fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); |
|
| 544 | + fputs($this->smtp_conn, "MAIL FROM:<".$from.">".$useVerp.$this->CRLF); |
|
| 545 | 545 | |
| 546 | 546 | $rply = $this->get_lines(); |
| 547 | - $code = substr($rply,0,3); |
|
| 547 | + $code = substr($rply, 0, 3); |
|
| 548 | 548 | |
| 549 | - if($this->do_debug >= 2) { |
|
| 550 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 549 | + if ($this->do_debug >= 2) { |
|
| 550 | + echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />'; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | - if($code != 250) { |
|
| 553 | + if ($code != 250) { |
|
| 554 | 554 | $this->error = |
| 555 | 555 | array("error" => "MAIL not accepted from server", |
| 556 | 556 | "smtp_code" => $code, |
| 557 | - "smtp_msg" => substr($rply,4)); |
|
| 558 | - if($this->do_debug >= 1) { |
|
| 559 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 557 | + "smtp_msg" => substr($rply, 4)); |
|
| 558 | + if ($this->do_debug >= 1) { |
|
| 559 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 560 | 560 | } |
| 561 | 561 | return false; |
| 562 | 562 | } |
@@ -574,41 +574,41 @@ discard block |
||
| 574 | 574 | * @access public |
| 575 | 575 | * @return bool |
| 576 | 576 | */ |
| 577 | - public function Quit($close_on_error=true) { |
|
| 577 | + public function Quit($close_on_error = true) { |
|
| 578 | 578 | $this->error = null; // so there is no confusion |
| 579 | 579 | |
| 580 | - if(!$this->connected()) { |
|
| 580 | + if (!$this->connected()) { |
|
| 581 | 581 | $this->error = array( |
| 582 | 582 | "error" => "Called Quit() without being connected"); |
| 583 | 583 | return false; |
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | // send the quit command to the server |
| 587 | - fputs($this->smtp_conn,"quit" . $this->CRLF); |
|
| 587 | + fputs($this->smtp_conn, "quit".$this->CRLF); |
|
| 588 | 588 | |
| 589 | 589 | // get any good-bye messages |
| 590 | 590 | $byemsg = $this->get_lines(); |
| 591 | 591 | |
| 592 | - if($this->do_debug >= 2) { |
|
| 593 | - echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />'; |
|
| 592 | + if ($this->do_debug >= 2) { |
|
| 593 | + echo "SMTP -> FROM SERVER:".$byemsg.$this->CRLF.'<br />'; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | $rval = true; |
| 597 | 597 | $e = null; |
| 598 | 598 | |
| 599 | - $code = substr($byemsg,0,3); |
|
| 600 | - if($code != 221) { |
|
| 599 | + $code = substr($byemsg, 0, 3); |
|
| 600 | + if ($code != 221) { |
|
| 601 | 601 | // use e as a tmp var cause Close will overwrite $this->error |
| 602 | 602 | $e = array("error" => "SMTP server rejected quit command", |
| 603 | 603 | "smtp_code" => $code, |
| 604 | - "smtp_rply" => substr($byemsg,4)); |
|
| 604 | + "smtp_rply" => substr($byemsg, 4)); |
|
| 605 | 605 | $rval = false; |
| 606 | - if($this->do_debug >= 1) { |
|
| 607 | - echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />'; |
|
| 606 | + if ($this->do_debug >= 1) { |
|
| 607 | + echo "SMTP -> ERROR: ".$e["error"].": ".$byemsg.$this->CRLF.'<br />'; |
|
| 608 | 608 | } |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | - if(empty($e) || $close_on_error) { |
|
| 611 | + if (empty($e) || $close_on_error) { |
|
| 612 | 612 | $this->Close(); |
| 613 | 613 | } |
| 614 | 614 | |
@@ -630,28 +630,28 @@ discard block |
||
| 630 | 630 | public function Recipient($to) { |
| 631 | 631 | $this->error = null; // so no confusion is caused |
| 632 | 632 | |
| 633 | - if(!$this->connected()) { |
|
| 633 | + if (!$this->connected()) { |
|
| 634 | 634 | $this->error = array( |
| 635 | 635 | "error" => "Called Recipient() without being connected"); |
| 636 | 636 | return false; |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | - fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF); |
|
| 639 | + fputs($this->smtp_conn, "RCPT TO:<".$to.">".$this->CRLF); |
|
| 640 | 640 | |
| 641 | 641 | $rply = $this->get_lines(); |
| 642 | - $code = substr($rply,0,3); |
|
| 642 | + $code = substr($rply, 0, 3); |
|
| 643 | 643 | |
| 644 | - if($this->do_debug >= 2) { |
|
| 645 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 644 | + if ($this->do_debug >= 2) { |
|
| 645 | + echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />'; |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | - if($code != 250 && $code != 251) { |
|
| 648 | + if ($code != 250 && $code != 251) { |
|
| 649 | 649 | $this->error = |
| 650 | 650 | array("error" => "RCPT not accepted from server", |
| 651 | 651 | "smtp_code" => $code, |
| 652 | - "smtp_msg" => substr($rply,4)); |
|
| 653 | - if($this->do_debug >= 1) { |
|
| 654 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 652 | + "smtp_msg" => substr($rply, 4)); |
|
| 653 | + if ($this->do_debug >= 1) { |
|
| 654 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 655 | 655 | } |
| 656 | 656 | return false; |
| 657 | 657 | } |
@@ -673,28 +673,28 @@ discard block |
||
| 673 | 673 | public function Reset() { |
| 674 | 674 | $this->error = null; // so no confusion is caused |
| 675 | 675 | |
| 676 | - if(!$this->connected()) { |
|
| 676 | + if (!$this->connected()) { |
|
| 677 | 677 | $this->error = array( |
| 678 | 678 | "error" => "Called Reset() without being connected"); |
| 679 | 679 | return false; |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | - fputs($this->smtp_conn,"RSET" . $this->CRLF); |
|
| 682 | + fputs($this->smtp_conn, "RSET".$this->CRLF); |
|
| 683 | 683 | |
| 684 | 684 | $rply = $this->get_lines(); |
| 685 | - $code = substr($rply,0,3); |
|
| 685 | + $code = substr($rply, 0, 3); |
|
| 686 | 686 | |
| 687 | - if($this->do_debug >= 2) { |
|
| 688 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 687 | + if ($this->do_debug >= 2) { |
|
| 688 | + echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />'; |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - if($code != 250) { |
|
| 691 | + if ($code != 250) { |
|
| 692 | 692 | $this->error = |
| 693 | 693 | array("error" => "RSET failed", |
| 694 | 694 | "smtp_code" => $code, |
| 695 | - "smtp_msg" => substr($rply,4)); |
|
| 696 | - if($this->do_debug >= 1) { |
|
| 697 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 695 | + "smtp_msg" => substr($rply, 4)); |
|
| 696 | + if ($this->do_debug >= 1) { |
|
| 697 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 698 | 698 | } |
| 699 | 699 | return false; |
| 700 | 700 | } |
@@ -721,28 +721,28 @@ discard block |
||
| 721 | 721 | public function SendAndMail($from) { |
| 722 | 722 | $this->error = null; // so no confusion is caused |
| 723 | 723 | |
| 724 | - if(!$this->connected()) { |
|
| 724 | + if (!$this->connected()) { |
|
| 725 | 725 | $this->error = array( |
| 726 | 726 | "error" => "Called SendAndMail() without being connected"); |
| 727 | 727 | return false; |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | - fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF); |
|
| 730 | + fputs($this->smtp_conn, "SAML FROM:".$from.$this->CRLF); |
|
| 731 | 731 | |
| 732 | 732 | $rply = $this->get_lines(); |
| 733 | - $code = substr($rply,0,3); |
|
| 733 | + $code = substr($rply, 0, 3); |
|
| 734 | 734 | |
| 735 | - if($this->do_debug >= 2) { |
|
| 736 | - echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'; |
|
| 735 | + if ($this->do_debug >= 2) { |
|
| 736 | + echo "SMTP -> FROM SERVER:".$rply.$this->CRLF.'<br />'; |
|
| 737 | 737 | } |
| 738 | 738 | |
| 739 | - if($code != 250) { |
|
| 739 | + if ($code != 250) { |
|
| 740 | 740 | $this->error = |
| 741 | 741 | array("error" => "SAML not accepted from server", |
| 742 | 742 | "smtp_code" => $code, |
| 743 | - "smtp_msg" => substr($rply,4)); |
|
| 744 | - if($this->do_debug >= 1) { |
|
| 745 | - echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; |
|
| 743 | + "smtp_msg" => substr($rply, 4)); |
|
| 744 | + if ($this->do_debug >= 1) { |
|
| 745 | + echo "SMTP -> ERROR: ".$this->error["error"].": ".$rply.$this->CRLF.'<br />'; |
|
| 746 | 746 | } |
| 747 | 747 | return false; |
| 748 | 748 | } |
@@ -765,8 +765,8 @@ discard block |
||
| 765 | 765 | public function Turn() { |
| 766 | 766 | $this->error = array("error" => "This method, TURN, of the SMTP ". |
| 767 | 767 | "is not implemented"); |
| 768 | - if($this->do_debug >= 1) { |
|
| 769 | - echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />'; |
|
| 768 | + if ($this->do_debug >= 1) { |
|
| 769 | + echo "SMTP -> NOTICE: ".$this->error["error"].$this->CRLF.'<br />'; |
|
| 770 | 770 | } |
| 771 | 771 | return false; |
| 772 | 772 | } |
@@ -795,17 +795,17 @@ discard block |
||
| 795 | 795 | */ |
| 796 | 796 | private function get_lines() { |
| 797 | 797 | $data = ""; |
| 798 | - while($str = @fgets($this->smtp_conn,515)) { |
|
| 799 | - if($this->do_debug >= 4) { |
|
| 800 | - echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />'; |
|
| 801 | - echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />'; |
|
| 798 | + while ($str = @fgets($this->smtp_conn, 515)) { |
|
| 799 | + if ($this->do_debug >= 4) { |
|
| 800 | + echo "SMTP -> get_lines(): \$data was \"$data\"".$this->CRLF.'<br />'; |
|
| 801 | + echo "SMTP -> get_lines(): \$str is \"$str\"".$this->CRLF.'<br />'; |
|
| 802 | 802 | } |
| 803 | 803 | $data .= $str; |
| 804 | - if($this->do_debug >= 4) { |
|
| 805 | - echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />'; |
|
| 804 | + if ($this->do_debug >= 4) { |
|
| 805 | + echo "SMTP -> get_lines(): \$data is \"$data\"".$this->CRLF.'<br />'; |
|
| 806 | 806 | } |
| 807 | 807 | // if 4th character is a space, we are done reading, break the loop |
| 808 | - if(substr($str,3,1) == " ") { break; } |
|
| 808 | + if (substr($str, 3, 1) == " ") { break; } |
|
| 809 | 809 | } |
| 810 | 810 | return $data; |
| 811 | 811 | } |
@@ -84,6 +84,10 @@ discard block |
||
| 84 | 84 | // Computes the unsigned Checksum of a file's header |
| 85 | 85 | // to try to ensure valid file |
| 86 | 86 | // PRIVATE ACCESS FUNCTION |
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @param string $bytestring |
|
| 90 | + */ |
|
| 87 | 91 | function __computeUnsignedChecksum($bytestring) { |
| 88 | 92 | for($i=0; $i<512; $i++) |
| 89 | 93 | $unsigned_chksum += ord($bytestring[$i]); |
@@ -97,6 +101,10 @@ discard block |
||
| 97 | 101 | |
| 98 | 102 | // Converts a NULL padded string to a non-NULL padded string |
| 99 | 103 | // PRIVATE ACCESS FUNCTION |
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @param string $string |
|
| 107 | + */ |
|
| 100 | 108 | function __parseNullPaddedString($string) { |
| 101 | 109 | $position = strpos($string,chr(0)); |
| 102 | 110 | if(!$position) |
@@ -357,6 +365,10 @@ discard block |
||
| 357 | 365 | |
| 358 | 366 | |
| 359 | 367 | // Open a TAR file |
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * @param string $filename |
|
| 371 | + */ |
|
| 360 | 372 | function openTAR($filename) { |
| 361 | 373 | // Clear any values from previous tar archives |
| 362 | 374 | unset($this->filename); |
@@ -393,6 +405,10 @@ discard block |
||
| 393 | 405 | |
| 394 | 406 | |
| 395 | 407 | // Retrieves information about a file in the current tar archive |
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * @param string $filename |
|
| 411 | + */ |
|
| 396 | 412 | function getFile($filename) { |
| 397 | 413 | if($this->numFiles > 0) { |
| 398 | 414 | foreach($this->files as $key => $information) { |
@@ -467,6 +483,10 @@ discard block |
||
| 467 | 483 | |
| 468 | 484 | |
| 469 | 485 | // Add a file to the tar archive |
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * @param string $filename |
|
| 489 | + */ |
|
| 470 | 490 | function addFile($filename,$from=null,$to=null) { |
| 471 | 491 | // Make sure the file we are adding exists! |
| 472 | 492 | if(!file_exists($filename)) |
@@ -555,6 +575,10 @@ discard block |
||
| 555 | 575 | |
| 556 | 576 | |
| 557 | 577 | // Saves tar archive to a different file than the current file |
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * @param boolean $useGzip |
|
| 581 | + */ |
|
| 558 | 582 | function toTar($filename,$useGzip) { |
| 559 | 583 | if(!$filename) |
| 560 | 584 | return false; |
@@ -63,99 +63,99 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | |
| 65 | 65 | class tar { |
| 66 | - // Unprocessed Archive Information |
|
| 67 | - var $filename; |
|
| 68 | - var $isGzipped; |
|
| 69 | - var $tar_file; |
|
| 70 | - |
|
| 71 | - // Processed Archive Information |
|
| 72 | - var $files; |
|
| 73 | - var $directories; |
|
| 74 | - var $numFiles; |
|
| 75 | - var $numDirectories; |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - // Class Constructor -- Does nothing... |
|
| 79 | - function tar() { |
|
| 80 | - return true; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - // Computes the unsigned Checksum of a file's header |
|
| 85 | - // to try to ensure valid file |
|
| 86 | - // PRIVATE ACCESS FUNCTION |
|
| 87 | - function __computeUnsignedChecksum($bytestring) { |
|
| 88 | - for($i=0; $i<512; $i++) |
|
| 89 | - $unsigned_chksum += ord($bytestring[$i]); |
|
| 90 | - for($i=0; $i<8; $i++) |
|
| 91 | - $unsigned_chksum -= ord($bytestring[148 + $i]); |
|
| 92 | - $unsigned_chksum += ord(" ") * 8; |
|
| 93 | - |
|
| 94 | - return $unsigned_chksum; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - // Converts a NULL padded string to a non-NULL padded string |
|
| 99 | - // PRIVATE ACCESS FUNCTION |
|
| 100 | - function __parseNullPaddedString($string) { |
|
| 101 | - $position = strpos($string,chr(0)); |
|
| 66 | + // Unprocessed Archive Information |
|
| 67 | + var $filename; |
|
| 68 | + var $isGzipped; |
|
| 69 | + var $tar_file; |
|
| 70 | + |
|
| 71 | + // Processed Archive Information |
|
| 72 | + var $files; |
|
| 73 | + var $directories; |
|
| 74 | + var $numFiles; |
|
| 75 | + var $numDirectories; |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + // Class Constructor -- Does nothing... |
|
| 79 | + function tar() { |
|
| 80 | + return true; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + // Computes the unsigned Checksum of a file's header |
|
| 85 | + // to try to ensure valid file |
|
| 86 | + // PRIVATE ACCESS FUNCTION |
|
| 87 | + function __computeUnsignedChecksum($bytestring) { |
|
| 88 | + for($i=0; $i<512; $i++) |
|
| 89 | + $unsigned_chksum += ord($bytestring[$i]); |
|
| 90 | + for($i=0; $i<8; $i++) |
|
| 91 | + $unsigned_chksum -= ord($bytestring[148 + $i]); |
|
| 92 | + $unsigned_chksum += ord(" ") * 8; |
|
| 93 | + |
|
| 94 | + return $unsigned_chksum; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + // Converts a NULL padded string to a non-NULL padded string |
|
| 99 | + // PRIVATE ACCESS FUNCTION |
|
| 100 | + function __parseNullPaddedString($string) { |
|
| 101 | + $position = strpos($string,chr(0)); |
|
| 102 | 102 | if(!$position) |
| 103 | 103 | { |
| 104 | 104 | $position = strlen($string); |
| 105 | 105 | } |
| 106 | - return substr($string,0,$position); |
|
| 107 | - } |
|
| 106 | + return substr($string,0,$position); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | |
| 110 | - // This function parses the current TAR file |
|
| 111 | - // PRIVATE ACCESS FUNCTION |
|
| 112 | - function __parseTar() { |
|
| 113 | - // Read Files from archive |
|
| 114 | - $tar_length = strlen($this->tar_file); |
|
| 115 | - $main_offset = 0; |
|
| 110 | + // This function parses the current TAR file |
|
| 111 | + // PRIVATE ACCESS FUNCTION |
|
| 112 | + function __parseTar() { |
|
| 113 | + // Read Files from archive |
|
| 114 | + $tar_length = strlen($this->tar_file); |
|
| 115 | + $main_offset = 0; |
|
| 116 | 116 | $flag_longlink = false; |
| 117 | - while($main_offset < $tar_length) { |
|
| 118 | - // If we read a block of 512 nulls, we are at the end of the archive |
|
| 119 | - if(substr($this->tar_file,$main_offset,512) == str_repeat(chr(0),512)) |
|
| 120 | - break; |
|
| 117 | + while($main_offset < $tar_length) { |
|
| 118 | + // If we read a block of 512 nulls, we are at the end of the archive |
|
| 119 | + if(substr($this->tar_file,$main_offset,512) == str_repeat(chr(0),512)) |
|
| 120 | + break; |
|
| 121 | 121 | |
| 122 | - // Parse file name |
|
| 123 | - $file_name = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset,100)); |
|
| 122 | + // Parse file name |
|
| 123 | + $file_name = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset,100)); |
|
| 124 | 124 | |
| 125 | - // Parse the file mode |
|
| 126 | - $file_mode = substr($this->tar_file,$main_offset + 100,8); |
|
| 125 | + // Parse the file mode |
|
| 126 | + $file_mode = substr($this->tar_file,$main_offset + 100,8); |
|
| 127 | 127 | |
| 128 | - // Parse the file user ID |
|
| 129 | - $file_uid = octdec(substr($this->tar_file,$main_offset + 108,8)); |
|
| 128 | + // Parse the file user ID |
|
| 129 | + $file_uid = octdec(substr($this->tar_file,$main_offset + 108,8)); |
|
| 130 | 130 | |
| 131 | - // Parse the file group ID |
|
| 132 | - $file_gid = octdec(substr($this->tar_file,$main_offset + 116,8)); |
|
| 131 | + // Parse the file group ID |
|
| 132 | + $file_gid = octdec(substr($this->tar_file,$main_offset + 116,8)); |
|
| 133 | 133 | |
| 134 | - // Parse the file size |
|
| 135 | - $file_size = octdec(substr($this->tar_file,$main_offset + 124,12)); |
|
| 134 | + // Parse the file size |
|
| 135 | + $file_size = octdec(substr($this->tar_file,$main_offset + 124,12)); |
|
| 136 | 136 | |
| 137 | - // Parse the file update time - unix timestamp format |
|
| 138 | - $file_time = octdec(substr($this->tar_file,$main_offset + 136,12)); |
|
| 137 | + // Parse the file update time - unix timestamp format |
|
| 138 | + $file_time = octdec(substr($this->tar_file,$main_offset + 136,12)); |
|
| 139 | 139 | |
| 140 | - // Parse Checksum |
|
| 141 | - $file_chksum = octdec(substr($this->tar_file,$main_offset + 148,6)); |
|
| 140 | + // Parse Checksum |
|
| 141 | + $file_chksum = octdec(substr($this->tar_file,$main_offset + 148,6)); |
|
| 142 | 142 | |
| 143 | - // Parse user name |
|
| 144 | - $file_uname = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset + 265,32)); |
|
| 143 | + // Parse user name |
|
| 144 | + $file_uname = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset + 265,32)); |
|
| 145 | 145 | |
| 146 | - // Parse Group name |
|
| 147 | - $file_gname = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset + 297,32)); |
|
| 146 | + // Parse Group name |
|
| 147 | + $file_gname = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset + 297,32)); |
|
| 148 | 148 | |
| 149 | - $file_type = substr($this->tar_file,$main_offset + 156,1); |
|
| 149 | + $file_type = substr($this->tar_file,$main_offset + 156,1); |
|
| 150 | 150 | |
| 151 | - // Make sure our file is valid |
|
| 152 | - if($this->__computeUnsignedChecksum(substr($this->tar_file,$main_offset,512)) != $file_chksum) |
|
| 153 | - return false; |
|
| 151 | + // Make sure our file is valid |
|
| 152 | + if($this->__computeUnsignedChecksum(substr($this->tar_file,$main_offset,512)) != $file_chksum) |
|
| 153 | + return false; |
|
| 154 | 154 | |
| 155 | - // Parse File Contents |
|
| 156 | - $file_contents = substr($this->tar_file,$main_offset + 512,$file_size); |
|
| 155 | + // Parse File Contents |
|
| 156 | + $file_contents = substr($this->tar_file,$main_offset + 512,$file_size); |
|
| 157 | 157 | |
| 158 | - /* ### Unused Header Information ### |
|
| 158 | + /* ### Unused Header Information ### |
|
| 159 | 159 | $activeFile["typeflag"] = substr($this->tar_file,$main_offset + 156,1); |
| 160 | 160 | $activeFile["linkname"] = substr($this->tar_file,$main_offset + 157,100); |
| 161 | 161 | $activeFile["magic"] = substr($this->tar_file,$main_offset + 257,6); |
@@ -228,363 +228,363 @@ discard block |
||
| 228 | 228 | $flag_longlink = false; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - // Move our offset the number of blocks we have processed |
|
| 232 | - $main_offset += 512 + (ceil($file_size / 512) * 512); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return true; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - // Read a non gzipped tar file in for processing |
|
| 240 | - // PRIVATE ACCESS FUNCTION |
|
| 241 | - function __readTar($filename='') { |
|
| 242 | - // Set the filename to load |
|
| 243 | - if(!$filename) |
|
| 244 | - $filename = $this->filename; |
|
| 245 | - |
|
| 246 | - // Read in the TAR file |
|
| 247 | - $fp = fopen($filename,"rb"); |
|
| 248 | - $this->tar_file = fread($fp,filesize($filename)); |
|
| 249 | - fclose($fp); |
|
| 250 | - |
|
| 251 | - if($this->tar_file[0] == chr(31) && $this->tar_file[1] == chr(139) && $this->tar_file[2] == chr(8)) { |
|
| 252 | - if(!function_exists("gzinflate")) |
|
| 253 | - return false; |
|
| 254 | - |
|
| 255 | - $this->isGzipped = TRUE; |
|
| 256 | - |
|
| 257 | - $this->tar_file = gzinflate(substr($this->tar_file,10,-4)); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - // Parse the TAR file |
|
| 261 | - $this->__parseTar(); |
|
| 262 | - |
|
| 263 | - return true; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - // Generates a TAR file from the processed data |
|
| 268 | - // PRIVATE ACCESS FUNCTION |
|
| 269 | - function __generateTAR() { |
|
| 270 | - // Clear any data currently in $this->tar_file |
|
| 271 | - unset($this->tar_file); |
|
| 272 | - |
|
| 273 | - // Generate Records for each directory, if we have directories |
|
| 274 | - if($this->numDirectories > 0) { |
|
| 275 | - foreach($this->directories as $key => $information) { |
|
| 276 | - unset($header); |
|
| 277 | - |
|
| 278 | - // Generate tar header for this directory |
|
| 279 | - // Filename, Permissions, UID, GID, size, Time, checksum, typeflag, linkname, magic, version, user name, group name, devmajor, devminor, prefix, end |
|
| 280 | - $header .= str_pad($information["name"],100,chr(0)); |
|
| 281 | - $header .= str_pad(decoct($information["mode"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 282 | - $header .= str_pad(decoct($information["user_id"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 283 | - $header .= str_pad(decoct($information["group_id"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 284 | - $header .= str_pad(decoct(0),11,"0",STR_PAD_LEFT) . chr(0); |
|
| 285 | - $header .= str_pad(decoct($information["time"]),11,"0",STR_PAD_LEFT) . chr(0); |
|
| 286 | - $header .= str_repeat(" ",8); |
|
| 287 | - $header .= "5"; |
|
| 288 | - $header .= str_repeat(chr(0),100); |
|
| 289 | - $header .= str_pad("ustar",6,chr(32)); |
|
| 290 | - $header .= chr(32) . chr(0); |
|
| 291 | - $header .= str_pad("",32,chr(0)); |
|
| 292 | - $header .= str_pad("",32,chr(0)); |
|
| 293 | - $header .= str_repeat(chr(0),8); |
|
| 294 | - $header .= str_repeat(chr(0),8); |
|
| 295 | - $header .= str_repeat(chr(0),155); |
|
| 296 | - $header .= str_repeat(chr(0),12); |
|
| 297 | - |
|
| 298 | - // Compute header checksum |
|
| 299 | - $checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)),6,"0",STR_PAD_LEFT); |
|
| 300 | - for($i=0; $i<6; $i++) { |
|
| 301 | - $header[(148 + $i)] = substr($checksum,$i,1); |
|
| 302 | - } |
|
| 303 | - $header[154] = chr(0); |
|
| 304 | - $header[155] = chr(32); |
|
| 305 | - |
|
| 306 | - // Add new tar formatted data to tar file contents |
|
| 307 | - $this->tar_file .= $header; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - // Generate Records for each file, if we have files (We should...) |
|
| 312 | - if($this->numFiles > 0) { |
|
| 313 | - foreach($this->files as $key => $information) { |
|
| 314 | - unset($header); |
|
| 315 | - |
|
| 316 | - // Generate the TAR header for this file |
|
| 317 | - // Filename, Permissions, UID, GID, size, Time, checksum, typeflag, linkname, magic, version, user name, group name, devmajor, devminor, prefix, end |
|
| 318 | - $header .= str_pad($information["name"],100,chr(0)); |
|
| 319 | - $header .= str_pad(decoct($information["mode"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 320 | - $header .= str_pad(decoct($information["user_id"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 321 | - $header .= str_pad(decoct($information["group_id"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 322 | - $header .= str_pad(decoct($information["size"]),11,"0",STR_PAD_LEFT) . chr(0); |
|
| 323 | - $header .= str_pad(decoct($information["time"]),11,"0",STR_PAD_LEFT) . chr(0); |
|
| 324 | - $header .= str_repeat(" ",8); |
|
| 325 | - $header .= "0"; |
|
| 326 | - $header .= str_repeat(chr(0),100); |
|
| 327 | - $header .= str_pad("ustar",6,chr(32)); |
|
| 328 | - $header .= chr(32) . chr(0); |
|
| 329 | - $header .= str_pad($information["user_name"],32,chr(0)); // How do I get a file's user name from PHP? |
|
| 330 | - $header .= str_pad($information["group_name"],32,chr(0)); // How do I get a file's group name from PHP? |
|
| 331 | - $header .= str_repeat(chr(0),8); |
|
| 332 | - $header .= str_repeat(chr(0),8); |
|
| 333 | - $header .= str_repeat(chr(0),155); |
|
| 334 | - $header .= str_repeat(chr(0),12); |
|
| 335 | - |
|
| 336 | - // Compute header checksum |
|
| 337 | - $checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)),6,"0",STR_PAD_LEFT); |
|
| 338 | - for($i=0; $i<6; $i++) { |
|
| 339 | - $header[(148 + $i)] = substr($checksum,$i,1); |
|
| 340 | - } |
|
| 341 | - $header[154] = chr(0); |
|
| 342 | - $header[155] = chr(32); |
|
| 343 | - |
|
| 344 | - // Pad file contents to byte count divisible by 512 |
|
| 345 | - $file_contents = str_pad($information["file"],(ceil($information["size"] / 512) * 512),chr(0)); |
|
| 346 | - |
|
| 347 | - // Add new tar formatted data to tar file contents |
|
| 348 | - $this->tar_file .= $header . $file_contents; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - // Add 512 bytes of NULLs to designate EOF |
|
| 353 | - $this->tar_file .= str_repeat(chr(0),512); |
|
| 354 | - |
|
| 355 | - return true; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - // Open a TAR file |
|
| 360 | - function openTAR($filename) { |
|
| 361 | - // Clear any values from previous tar archives |
|
| 362 | - unset($this->filename); |
|
| 363 | - unset($this->isGzipped); |
|
| 364 | - unset($this->tar_file); |
|
| 365 | - unset($this->files); |
|
| 366 | - unset($this->directories); |
|
| 367 | - unset($this->numFiles); |
|
| 368 | - unset($this->numDirectories); |
|
| 369 | - |
|
| 370 | - // If the tar file doesn't exist... |
|
| 371 | - if(!file_exists($filename)) |
|
| 372 | - return false; |
|
| 373 | - |
|
| 374 | - $this->filename = $filename; |
|
| 375 | - |
|
| 376 | - // Parse this file |
|
| 377 | - $this->__readTar(); |
|
| 378 | - |
|
| 379 | - return true; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - // Appends a tar file to the end of the currently opened tar file |
|
| 384 | - function appendTar($filename) { |
|
| 385 | - // If the tar file doesn't exist... |
|
| 386 | - if(!file_exists($filename)) |
|
| 387 | - return false; |
|
| 388 | - |
|
| 389 | - $this->__readTar($filename); |
|
| 390 | - |
|
| 391 | - return true; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - // Retrieves information about a file in the current tar archive |
|
| 396 | - function getFile($filename) { |
|
| 397 | - if($this->numFiles > 0) { |
|
| 398 | - foreach($this->files as $key => $information) { |
|
| 399 | - if($information["name"] == $filename) |
|
| 400 | - return $information; |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - return false; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - // Retrieves information about a directory in the current tar archive |
|
| 409 | - function getDirectory($dirname) { |
|
| 410 | - if($this->numDirectories > 0) { |
|
| 411 | - foreach($this->directories as $key => $information) { |
|
| 412 | - if($information["name"] == $dirname) |
|
| 413 | - return $information; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - return false; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - // Check if this tar archive contains a specific file |
|
| 422 | - function containsFile($filename) { |
|
| 423 | - if($this->numFiles > 0) { |
|
| 424 | - foreach($this->files as $key => $information) { |
|
| 425 | - if($information["name"] == $filename) |
|
| 426 | - return true; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - return false; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - // Check if this tar archive contains a specific directory |
|
| 435 | - function containsDirectory($dirname) { |
|
| 436 | - if($this->numDirectories > 0) { |
|
| 437 | - foreach($this->directories as $key => $information) { |
|
| 438 | - if($information["name"] == $dirname) |
|
| 439 | - return true; |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - return false; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - // Add a directory to this tar archive |
|
| 448 | - function addDirectory($dirname) { |
|
| 449 | - if(!file_exists($dirname)) |
|
| 450 | - return false; |
|
| 451 | - |
|
| 452 | - // Get directory information |
|
| 453 | - $file_information = stat($dirname); |
|
| 454 | - |
|
| 455 | - // Add directory to processed data |
|
| 456 | - $this->numDirectories++; |
|
| 457 | - $activeDir = &$this->directories[]; |
|
| 458 | - $activeDir["name"] = $dirname; |
|
| 459 | - $activeDir["mode"] = $file_information["mode"]; |
|
| 460 | - $activeDir["time"] = $file_information["time"]; |
|
| 461 | - $activeDir["user_id"] = $file_information["uid"]; |
|
| 462 | - $activeDir["group_id"] = $file_information["gid"]; |
|
| 463 | - $activeDir["checksum"] = $checksum; |
|
| 464 | - |
|
| 465 | - return true; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - // Add a file to the tar archive |
|
| 470 | - function addFile($filename,$from=null,$to=null) { |
|
| 471 | - // Make sure the file we are adding exists! |
|
| 472 | - if(!file_exists($filename)) |
|
| 473 | - return false; |
|
| 474 | - |
|
| 475 | - if(filesize($filename)==0) |
|
| 476 | - return false; |
|
| 477 | - |
|
| 478 | - // Make sure there are no other files in the archive that have this same filename |
|
| 479 | - if($this->containsFile($filename)) |
|
| 480 | - return false; |
|
| 481 | - |
|
| 482 | - // Get file information |
|
| 483 | - $file_information = stat($filename); |
|
| 484 | - |
|
| 485 | - // Read in the file's contents |
|
| 486 | - $fp = fopen($filename,"rb"); |
|
| 487 | - $file_contents = fread($fp,filesize($filename)); |
|
| 488 | - fclose($fp); |
|
| 489 | - |
|
| 490 | - if($from && $to){ |
|
| 491 | - $file_contents = str_replace($from,$to,$file_contents); |
|
| 492 | - $file_information["size"] = strlen($file_contents); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - // Add file to processed data |
|
| 496 | - $this->numFiles++; |
|
| 497 | - $activeFile = &$this->files[]; |
|
| 498 | - $activeFile["name"] = $filename; |
|
| 499 | - $activeFile["mode"] = $file_information["mode"]; |
|
| 500 | - $activeFile["user_id"] = $file_information["uid"]; |
|
| 501 | - $activeFile["group_id"] = $file_information["gid"]; |
|
| 502 | - $activeFile["size"] = $file_information["size"]; |
|
| 503 | - $activeFile["time"] = $file_information["mtime"]; |
|
| 504 | - $activeFile["checksum"] = $checksum; |
|
| 505 | - $activeFile["user_name"] = ""; |
|
| 506 | - $activeFile["group_name"] = ""; |
|
| 507 | - $activeFile["file"] = $file_contents; |
|
| 508 | - |
|
| 509 | - return true; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - // Remove a file from the tar archive |
|
| 514 | - function removeFile($filename) { |
|
| 515 | - if($this->numFiles > 0) { |
|
| 516 | - foreach($this->files as $key => $information) { |
|
| 517 | - if($information["name"] == $filename) { |
|
| 518 | - $this->numFiles--; |
|
| 519 | - unset($this->files[$key]); |
|
| 520 | - return true; |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - return false; |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - // Remove a directory from the tar archive |
|
| 530 | - function removeDirectory($dirname) { |
|
| 531 | - if($this->numDirectories > 0) { |
|
| 532 | - foreach($this->directories as $key => $information) { |
|
| 533 | - if($information["name"] == $dirname) { |
|
| 534 | - $this->numDirectories--; |
|
| 535 | - unset($this->directories[$key]); |
|
| 536 | - return true; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - return false; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - // Write the currently loaded tar archive to disk |
|
| 546 | - function saveTar() { |
|
| 547 | - if(!$this->filename) |
|
| 548 | - return false; |
|
| 549 | - |
|
| 550 | - // Write tar to current file using specified gzip compression |
|
| 551 | - $this->toTar($this->filename,$this->isGzipped); |
|
| 552 | - |
|
| 553 | - return true; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - |
|
| 557 | - // Saves tar archive to a different file than the current file |
|
| 558 | - function toTar($filename,$useGzip) { |
|
| 559 | - if(!$filename) |
|
| 560 | - return false; |
|
| 561 | - |
|
| 562 | - // Encode processed files into TAR file format |
|
| 563 | - $this->__generateTar(); |
|
| 564 | - |
|
| 565 | - // GZ Compress the data if we need to |
|
| 566 | - if($useGzip) { |
|
| 567 | - // Make sure we have gzip support |
|
| 568 | - if(!function_exists("gzencode")) |
|
| 569 | - return false; |
|
| 570 | - |
|
| 571 | - $file = gzencode($this->tar_file); |
|
| 572 | - } else { |
|
| 573 | - $file = $this->tar_file; |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - // Write the TAR file |
|
| 577 | - $fp = fopen($filename,"wb"); |
|
| 578 | - fwrite($fp,$file); |
|
| 579 | - fclose($fp); |
|
| 580 | - |
|
| 581 | - return true; |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - function toTarStream() { |
|
| 586 | - $this->__generateTar(); |
|
| 587 | - return $this->tar_file; |
|
| 588 | - } |
|
| 231 | + // Move our offset the number of blocks we have processed |
|
| 232 | + $main_offset += 512 + (ceil($file_size / 512) * 512); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return true; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + // Read a non gzipped tar file in for processing |
|
| 240 | + // PRIVATE ACCESS FUNCTION |
|
| 241 | + function __readTar($filename='') { |
|
| 242 | + // Set the filename to load |
|
| 243 | + if(!$filename) |
|
| 244 | + $filename = $this->filename; |
|
| 245 | + |
|
| 246 | + // Read in the TAR file |
|
| 247 | + $fp = fopen($filename,"rb"); |
|
| 248 | + $this->tar_file = fread($fp,filesize($filename)); |
|
| 249 | + fclose($fp); |
|
| 250 | + |
|
| 251 | + if($this->tar_file[0] == chr(31) && $this->tar_file[1] == chr(139) && $this->tar_file[2] == chr(8)) { |
|
| 252 | + if(!function_exists("gzinflate")) |
|
| 253 | + return false; |
|
| 254 | + |
|
| 255 | + $this->isGzipped = TRUE; |
|
| 256 | + |
|
| 257 | + $this->tar_file = gzinflate(substr($this->tar_file,10,-4)); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + // Parse the TAR file |
|
| 261 | + $this->__parseTar(); |
|
| 262 | + |
|
| 263 | + return true; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + // Generates a TAR file from the processed data |
|
| 268 | + // PRIVATE ACCESS FUNCTION |
|
| 269 | + function __generateTAR() { |
|
| 270 | + // Clear any data currently in $this->tar_file |
|
| 271 | + unset($this->tar_file); |
|
| 272 | + |
|
| 273 | + // Generate Records for each directory, if we have directories |
|
| 274 | + if($this->numDirectories > 0) { |
|
| 275 | + foreach($this->directories as $key => $information) { |
|
| 276 | + unset($header); |
|
| 277 | + |
|
| 278 | + // Generate tar header for this directory |
|
| 279 | + // Filename, Permissions, UID, GID, size, Time, checksum, typeflag, linkname, magic, version, user name, group name, devmajor, devminor, prefix, end |
|
| 280 | + $header .= str_pad($information["name"],100,chr(0)); |
|
| 281 | + $header .= str_pad(decoct($information["mode"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 282 | + $header .= str_pad(decoct($information["user_id"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 283 | + $header .= str_pad(decoct($information["group_id"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 284 | + $header .= str_pad(decoct(0),11,"0",STR_PAD_LEFT) . chr(0); |
|
| 285 | + $header .= str_pad(decoct($information["time"]),11,"0",STR_PAD_LEFT) . chr(0); |
|
| 286 | + $header .= str_repeat(" ",8); |
|
| 287 | + $header .= "5"; |
|
| 288 | + $header .= str_repeat(chr(0),100); |
|
| 289 | + $header .= str_pad("ustar",6,chr(32)); |
|
| 290 | + $header .= chr(32) . chr(0); |
|
| 291 | + $header .= str_pad("",32,chr(0)); |
|
| 292 | + $header .= str_pad("",32,chr(0)); |
|
| 293 | + $header .= str_repeat(chr(0),8); |
|
| 294 | + $header .= str_repeat(chr(0),8); |
|
| 295 | + $header .= str_repeat(chr(0),155); |
|
| 296 | + $header .= str_repeat(chr(0),12); |
|
| 297 | + |
|
| 298 | + // Compute header checksum |
|
| 299 | + $checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)),6,"0",STR_PAD_LEFT); |
|
| 300 | + for($i=0; $i<6; $i++) { |
|
| 301 | + $header[(148 + $i)] = substr($checksum,$i,1); |
|
| 302 | + } |
|
| 303 | + $header[154] = chr(0); |
|
| 304 | + $header[155] = chr(32); |
|
| 305 | + |
|
| 306 | + // Add new tar formatted data to tar file contents |
|
| 307 | + $this->tar_file .= $header; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + // Generate Records for each file, if we have files (We should...) |
|
| 312 | + if($this->numFiles > 0) { |
|
| 313 | + foreach($this->files as $key => $information) { |
|
| 314 | + unset($header); |
|
| 315 | + |
|
| 316 | + // Generate the TAR header for this file |
|
| 317 | + // Filename, Permissions, UID, GID, size, Time, checksum, typeflag, linkname, magic, version, user name, group name, devmajor, devminor, prefix, end |
|
| 318 | + $header .= str_pad($information["name"],100,chr(0)); |
|
| 319 | + $header .= str_pad(decoct($information["mode"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 320 | + $header .= str_pad(decoct($information["user_id"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 321 | + $header .= str_pad(decoct($information["group_id"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 322 | + $header .= str_pad(decoct($information["size"]),11,"0",STR_PAD_LEFT) . chr(0); |
|
| 323 | + $header .= str_pad(decoct($information["time"]),11,"0",STR_PAD_LEFT) . chr(0); |
|
| 324 | + $header .= str_repeat(" ",8); |
|
| 325 | + $header .= "0"; |
|
| 326 | + $header .= str_repeat(chr(0),100); |
|
| 327 | + $header .= str_pad("ustar",6,chr(32)); |
|
| 328 | + $header .= chr(32) . chr(0); |
|
| 329 | + $header .= str_pad($information["user_name"],32,chr(0)); // How do I get a file's user name from PHP? |
|
| 330 | + $header .= str_pad($information["group_name"],32,chr(0)); // How do I get a file's group name from PHP? |
|
| 331 | + $header .= str_repeat(chr(0),8); |
|
| 332 | + $header .= str_repeat(chr(0),8); |
|
| 333 | + $header .= str_repeat(chr(0),155); |
|
| 334 | + $header .= str_repeat(chr(0),12); |
|
| 335 | + |
|
| 336 | + // Compute header checksum |
|
| 337 | + $checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)),6,"0",STR_PAD_LEFT); |
|
| 338 | + for($i=0; $i<6; $i++) { |
|
| 339 | + $header[(148 + $i)] = substr($checksum,$i,1); |
|
| 340 | + } |
|
| 341 | + $header[154] = chr(0); |
|
| 342 | + $header[155] = chr(32); |
|
| 343 | + |
|
| 344 | + // Pad file contents to byte count divisible by 512 |
|
| 345 | + $file_contents = str_pad($information["file"],(ceil($information["size"] / 512) * 512),chr(0)); |
|
| 346 | + |
|
| 347 | + // Add new tar formatted data to tar file contents |
|
| 348 | + $this->tar_file .= $header . $file_contents; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + // Add 512 bytes of NULLs to designate EOF |
|
| 353 | + $this->tar_file .= str_repeat(chr(0),512); |
|
| 354 | + |
|
| 355 | + return true; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + // Open a TAR file |
|
| 360 | + function openTAR($filename) { |
|
| 361 | + // Clear any values from previous tar archives |
|
| 362 | + unset($this->filename); |
|
| 363 | + unset($this->isGzipped); |
|
| 364 | + unset($this->tar_file); |
|
| 365 | + unset($this->files); |
|
| 366 | + unset($this->directories); |
|
| 367 | + unset($this->numFiles); |
|
| 368 | + unset($this->numDirectories); |
|
| 369 | + |
|
| 370 | + // If the tar file doesn't exist... |
|
| 371 | + if(!file_exists($filename)) |
|
| 372 | + return false; |
|
| 373 | + |
|
| 374 | + $this->filename = $filename; |
|
| 375 | + |
|
| 376 | + // Parse this file |
|
| 377 | + $this->__readTar(); |
|
| 378 | + |
|
| 379 | + return true; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + // Appends a tar file to the end of the currently opened tar file |
|
| 384 | + function appendTar($filename) { |
|
| 385 | + // If the tar file doesn't exist... |
|
| 386 | + if(!file_exists($filename)) |
|
| 387 | + return false; |
|
| 388 | + |
|
| 389 | + $this->__readTar($filename); |
|
| 390 | + |
|
| 391 | + return true; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + // Retrieves information about a file in the current tar archive |
|
| 396 | + function getFile($filename) { |
|
| 397 | + if($this->numFiles > 0) { |
|
| 398 | + foreach($this->files as $key => $information) { |
|
| 399 | + if($information["name"] == $filename) |
|
| 400 | + return $information; |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + return false; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + // Retrieves information about a directory in the current tar archive |
|
| 409 | + function getDirectory($dirname) { |
|
| 410 | + if($this->numDirectories > 0) { |
|
| 411 | + foreach($this->directories as $key => $information) { |
|
| 412 | + if($information["name"] == $dirname) |
|
| 413 | + return $information; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + return false; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + // Check if this tar archive contains a specific file |
|
| 422 | + function containsFile($filename) { |
|
| 423 | + if($this->numFiles > 0) { |
|
| 424 | + foreach($this->files as $key => $information) { |
|
| 425 | + if($information["name"] == $filename) |
|
| 426 | + return true; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + return false; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + // Check if this tar archive contains a specific directory |
|
| 435 | + function containsDirectory($dirname) { |
|
| 436 | + if($this->numDirectories > 0) { |
|
| 437 | + foreach($this->directories as $key => $information) { |
|
| 438 | + if($information["name"] == $dirname) |
|
| 439 | + return true; |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + return false; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + // Add a directory to this tar archive |
|
| 448 | + function addDirectory($dirname) { |
|
| 449 | + if(!file_exists($dirname)) |
|
| 450 | + return false; |
|
| 451 | + |
|
| 452 | + // Get directory information |
|
| 453 | + $file_information = stat($dirname); |
|
| 454 | + |
|
| 455 | + // Add directory to processed data |
|
| 456 | + $this->numDirectories++; |
|
| 457 | + $activeDir = &$this->directories[]; |
|
| 458 | + $activeDir["name"] = $dirname; |
|
| 459 | + $activeDir["mode"] = $file_information["mode"]; |
|
| 460 | + $activeDir["time"] = $file_information["time"]; |
|
| 461 | + $activeDir["user_id"] = $file_information["uid"]; |
|
| 462 | + $activeDir["group_id"] = $file_information["gid"]; |
|
| 463 | + $activeDir["checksum"] = $checksum; |
|
| 464 | + |
|
| 465 | + return true; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + // Add a file to the tar archive |
|
| 470 | + function addFile($filename,$from=null,$to=null) { |
|
| 471 | + // Make sure the file we are adding exists! |
|
| 472 | + if(!file_exists($filename)) |
|
| 473 | + return false; |
|
| 474 | + |
|
| 475 | + if(filesize($filename)==0) |
|
| 476 | + return false; |
|
| 477 | + |
|
| 478 | + // Make sure there are no other files in the archive that have this same filename |
|
| 479 | + if($this->containsFile($filename)) |
|
| 480 | + return false; |
|
| 481 | + |
|
| 482 | + // Get file information |
|
| 483 | + $file_information = stat($filename); |
|
| 484 | + |
|
| 485 | + // Read in the file's contents |
|
| 486 | + $fp = fopen($filename,"rb"); |
|
| 487 | + $file_contents = fread($fp,filesize($filename)); |
|
| 488 | + fclose($fp); |
|
| 489 | + |
|
| 490 | + if($from && $to){ |
|
| 491 | + $file_contents = str_replace($from,$to,$file_contents); |
|
| 492 | + $file_information["size"] = strlen($file_contents); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + // Add file to processed data |
|
| 496 | + $this->numFiles++; |
|
| 497 | + $activeFile = &$this->files[]; |
|
| 498 | + $activeFile["name"] = $filename; |
|
| 499 | + $activeFile["mode"] = $file_information["mode"]; |
|
| 500 | + $activeFile["user_id"] = $file_information["uid"]; |
|
| 501 | + $activeFile["group_id"] = $file_information["gid"]; |
|
| 502 | + $activeFile["size"] = $file_information["size"]; |
|
| 503 | + $activeFile["time"] = $file_information["mtime"]; |
|
| 504 | + $activeFile["checksum"] = $checksum; |
|
| 505 | + $activeFile["user_name"] = ""; |
|
| 506 | + $activeFile["group_name"] = ""; |
|
| 507 | + $activeFile["file"] = $file_contents; |
|
| 508 | + |
|
| 509 | + return true; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + // Remove a file from the tar archive |
|
| 514 | + function removeFile($filename) { |
|
| 515 | + if($this->numFiles > 0) { |
|
| 516 | + foreach($this->files as $key => $information) { |
|
| 517 | + if($information["name"] == $filename) { |
|
| 518 | + $this->numFiles--; |
|
| 519 | + unset($this->files[$key]); |
|
| 520 | + return true; |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + return false; |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + // Remove a directory from the tar archive |
|
| 530 | + function removeDirectory($dirname) { |
|
| 531 | + if($this->numDirectories > 0) { |
|
| 532 | + foreach($this->directories as $key => $information) { |
|
| 533 | + if($information["name"] == $dirname) { |
|
| 534 | + $this->numDirectories--; |
|
| 535 | + unset($this->directories[$key]); |
|
| 536 | + return true; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + return false; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + // Write the currently loaded tar archive to disk |
|
| 546 | + function saveTar() { |
|
| 547 | + if(!$this->filename) |
|
| 548 | + return false; |
|
| 549 | + |
|
| 550 | + // Write tar to current file using specified gzip compression |
|
| 551 | + $this->toTar($this->filename,$this->isGzipped); |
|
| 552 | + |
|
| 553 | + return true; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + |
|
| 557 | + // Saves tar archive to a different file than the current file |
|
| 558 | + function toTar($filename,$useGzip) { |
|
| 559 | + if(!$filename) |
|
| 560 | + return false; |
|
| 561 | + |
|
| 562 | + // Encode processed files into TAR file format |
|
| 563 | + $this->__generateTar(); |
|
| 564 | + |
|
| 565 | + // GZ Compress the data if we need to |
|
| 566 | + if($useGzip) { |
|
| 567 | + // Make sure we have gzip support |
|
| 568 | + if(!function_exists("gzencode")) |
|
| 569 | + return false; |
|
| 570 | + |
|
| 571 | + $file = gzencode($this->tar_file); |
|
| 572 | + } else { |
|
| 573 | + $file = $this->tar_file; |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + // Write the TAR file |
|
| 577 | + $fp = fopen($filename,"wb"); |
|
| 578 | + fwrite($fp,$file); |
|
| 579 | + fclose($fp); |
|
| 580 | + |
|
| 581 | + return true; |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + function toTarStream() { |
|
| 586 | + $this->__generateTar(); |
|
| 587 | + return $this->tar_file; |
|
| 588 | + } |
|
| 589 | 589 | } |
| 590 | 590 | ?> |
@@ -85,10 +85,12 @@ discard block |
||
| 85 | 85 | // to try to ensure valid file |
| 86 | 86 | // PRIVATE ACCESS FUNCTION |
| 87 | 87 | function __computeUnsignedChecksum($bytestring) { |
| 88 | - for($i=0; $i<512; $i++) |
|
| 89 | - $unsigned_chksum += ord($bytestring[$i]); |
|
| 90 | - for($i=0; $i<8; $i++) |
|
| 91 | - $unsigned_chksum -= ord($bytestring[148 + $i]); |
|
| 88 | + for($i=0; $i<512; $i++) { |
|
| 89 | + $unsigned_chksum += ord($bytestring[$i]); |
|
| 90 | + } |
|
| 91 | + for($i=0; $i<8; $i++) { |
|
| 92 | + $unsigned_chksum -= ord($bytestring[148 + $i]); |
|
| 93 | + } |
|
| 92 | 94 | $unsigned_chksum += ord(" ") * 8; |
| 93 | 95 | |
| 94 | 96 | return $unsigned_chksum; |
@@ -116,8 +118,9 @@ discard block |
||
| 116 | 118 | $flag_longlink = false; |
| 117 | 119 | while($main_offset < $tar_length) { |
| 118 | 120 | // If we read a block of 512 nulls, we are at the end of the archive |
| 119 | - if(substr($this->tar_file,$main_offset,512) == str_repeat(chr(0),512)) |
|
| 120 | - break; |
|
| 121 | + if(substr($this->tar_file,$main_offset,512) == str_repeat(chr(0),512)) { |
|
| 122 | + break; |
|
| 123 | + } |
|
| 121 | 124 | |
| 122 | 125 | // Parse file name |
| 123 | 126 | $file_name = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset,100)); |
@@ -149,8 +152,9 @@ discard block |
||
| 149 | 152 | $file_type = substr($this->tar_file,$main_offset + 156,1); |
| 150 | 153 | |
| 151 | 154 | // Make sure our file is valid |
| 152 | - if($this->__computeUnsignedChecksum(substr($this->tar_file,$main_offset,512)) != $file_chksum) |
|
| 153 | - return false; |
|
| 155 | + if($this->__computeUnsignedChecksum(substr($this->tar_file,$main_offset,512)) != $file_chksum) { |
|
| 156 | + return false; |
|
| 157 | + } |
|
| 154 | 158 | |
| 155 | 159 | // Parse File Contents |
| 156 | 160 | $file_contents = substr($this->tar_file,$main_offset + 512,$file_size); |
@@ -170,8 +174,7 @@ discard block |
||
| 170 | 174 | { |
| 171 | 175 | $flag_longlink = true; |
| 172 | 176 | $longlink_name = $this->__parseNullPaddedString($file_contents); |
| 173 | - } |
|
| 174 | - elseif($file_type == '0') { |
|
| 177 | + } elseif($file_type == '0') { |
|
| 175 | 178 | // Increment number of files |
| 176 | 179 | $this->numFiles++; |
| 177 | 180 | |
@@ -182,8 +185,7 @@ discard block |
||
| 182 | 185 | if($flag_longlink) |
| 183 | 186 | { |
| 184 | 187 | $activeFile["name"] = $longlink_name; |
| 185 | - } |
|
| 186 | - else |
|
| 188 | + } else |
|
| 187 | 189 | { |
| 188 | 190 | $activeFile["name"] = $file_name; |
| 189 | 191 | } |
@@ -211,8 +213,7 @@ discard block |
||
| 211 | 213 | if($flag_longlink) |
| 212 | 214 | { |
| 213 | 215 | $activeDir["name"] = $longlink_name; |
| 214 | - } |
|
| 215 | - else |
|
| 216 | + } else |
|
| 216 | 217 | { |
| 217 | 218 | $activeDir["name"] = $file_name; |
| 218 | 219 | } |
@@ -240,8 +241,9 @@ discard block |
||
| 240 | 241 | // PRIVATE ACCESS FUNCTION |
| 241 | 242 | function __readTar($filename='') { |
| 242 | 243 | // Set the filename to load |
| 243 | - if(!$filename) |
|
| 244 | - $filename = $this->filename; |
|
| 244 | + if(!$filename) { |
|
| 245 | + $filename = $this->filename; |
|
| 246 | + } |
|
| 245 | 247 | |
| 246 | 248 | // Read in the TAR file |
| 247 | 249 | $fp = fopen($filename,"rb"); |
@@ -249,8 +251,9 @@ discard block |
||
| 249 | 251 | fclose($fp); |
| 250 | 252 | |
| 251 | 253 | if($this->tar_file[0] == chr(31) && $this->tar_file[1] == chr(139) && $this->tar_file[2] == chr(8)) { |
| 252 | - if(!function_exists("gzinflate")) |
|
| 253 | - return false; |
|
| 254 | + if(!function_exists("gzinflate")) { |
|
| 255 | + return false; |
|
| 256 | + } |
|
| 254 | 257 | |
| 255 | 258 | $this->isGzipped = TRUE; |
| 256 | 259 | |
@@ -368,8 +371,9 @@ discard block |
||
| 368 | 371 | unset($this->numDirectories); |
| 369 | 372 | |
| 370 | 373 | // If the tar file doesn't exist... |
| 371 | - if(!file_exists($filename)) |
|
| 372 | - return false; |
|
| 374 | + if(!file_exists($filename)) { |
|
| 375 | + return false; |
|
| 376 | + } |
|
| 373 | 377 | |
| 374 | 378 | $this->filename = $filename; |
| 375 | 379 | |
@@ -383,8 +387,9 @@ discard block |
||
| 383 | 387 | // Appends a tar file to the end of the currently opened tar file |
| 384 | 388 | function appendTar($filename) { |
| 385 | 389 | // If the tar file doesn't exist... |
| 386 | - if(!file_exists($filename)) |
|
| 387 | - return false; |
|
| 390 | + if(!file_exists($filename)) { |
|
| 391 | + return false; |
|
| 392 | + } |
|
| 388 | 393 | |
| 389 | 394 | $this->__readTar($filename); |
| 390 | 395 | |
@@ -396,8 +401,9 @@ discard block |
||
| 396 | 401 | function getFile($filename) { |
| 397 | 402 | if($this->numFiles > 0) { |
| 398 | 403 | foreach($this->files as $key => $information) { |
| 399 | - if($information["name"] == $filename) |
|
| 400 | - return $information; |
|
| 404 | + if($information["name"] == $filename) { |
|
| 405 | + return $information; |
|
| 406 | + } |
|
| 401 | 407 | } |
| 402 | 408 | } |
| 403 | 409 | |
@@ -409,8 +415,9 @@ discard block |
||
| 409 | 415 | function getDirectory($dirname) { |
| 410 | 416 | if($this->numDirectories > 0) { |
| 411 | 417 | foreach($this->directories as $key => $information) { |
| 412 | - if($information["name"] == $dirname) |
|
| 413 | - return $information; |
|
| 418 | + if($information["name"] == $dirname) { |
|
| 419 | + return $information; |
|
| 420 | + } |
|
| 414 | 421 | } |
| 415 | 422 | } |
| 416 | 423 | |
@@ -422,8 +429,9 @@ discard block |
||
| 422 | 429 | function containsFile($filename) { |
| 423 | 430 | if($this->numFiles > 0) { |
| 424 | 431 | foreach($this->files as $key => $information) { |
| 425 | - if($information["name"] == $filename) |
|
| 426 | - return true; |
|
| 432 | + if($information["name"] == $filename) { |
|
| 433 | + return true; |
|
| 434 | + } |
|
| 427 | 435 | } |
| 428 | 436 | } |
| 429 | 437 | |
@@ -435,8 +443,9 @@ discard block |
||
| 435 | 443 | function containsDirectory($dirname) { |
| 436 | 444 | if($this->numDirectories > 0) { |
| 437 | 445 | foreach($this->directories as $key => $information) { |
| 438 | - if($information["name"] == $dirname) |
|
| 439 | - return true; |
|
| 446 | + if($information["name"] == $dirname) { |
|
| 447 | + return true; |
|
| 448 | + } |
|
| 440 | 449 | } |
| 441 | 450 | } |
| 442 | 451 | |
@@ -446,8 +455,9 @@ discard block |
||
| 446 | 455 | |
| 447 | 456 | // Add a directory to this tar archive |
| 448 | 457 | function addDirectory($dirname) { |
| 449 | - if(!file_exists($dirname)) |
|
| 450 | - return false; |
|
| 458 | + if(!file_exists($dirname)) { |
|
| 459 | + return false; |
|
| 460 | + } |
|
| 451 | 461 | |
| 452 | 462 | // Get directory information |
| 453 | 463 | $file_information = stat($dirname); |
@@ -469,15 +479,18 @@ discard block |
||
| 469 | 479 | // Add a file to the tar archive |
| 470 | 480 | function addFile($filename,$from=null,$to=null) { |
| 471 | 481 | // Make sure the file we are adding exists! |
| 472 | - if(!file_exists($filename)) |
|
| 473 | - return false; |
|
| 482 | + if(!file_exists($filename)) { |
|
| 483 | + return false; |
|
| 484 | + } |
|
| 474 | 485 | |
| 475 | - if(filesize($filename)==0) |
|
| 476 | - return false; |
|
| 486 | + if(filesize($filename)==0) { |
|
| 487 | + return false; |
|
| 488 | + } |
|
| 477 | 489 | |
| 478 | 490 | // Make sure there are no other files in the archive that have this same filename |
| 479 | - if($this->containsFile($filename)) |
|
| 480 | - return false; |
|
| 491 | + if($this->containsFile($filename)) { |
|
| 492 | + return false; |
|
| 493 | + } |
|
| 481 | 494 | |
| 482 | 495 | // Get file information |
| 483 | 496 | $file_information = stat($filename); |
@@ -544,8 +557,9 @@ discard block |
||
| 544 | 557 | |
| 545 | 558 | // Write the currently loaded tar archive to disk |
| 546 | 559 | function saveTar() { |
| 547 | - if(!$this->filename) |
|
| 548 | - return false; |
|
| 560 | + if(!$this->filename) { |
|
| 561 | + return false; |
|
| 562 | + } |
|
| 549 | 563 | |
| 550 | 564 | // Write tar to current file using specified gzip compression |
| 551 | 565 | $this->toTar($this->filename,$this->isGzipped); |
@@ -556,8 +570,9 @@ discard block |
||
| 556 | 570 | |
| 557 | 571 | // Saves tar archive to a different file than the current file |
| 558 | 572 | function toTar($filename,$useGzip) { |
| 559 | - if(!$filename) |
|
| 560 | - return false; |
|
| 573 | + if(!$filename) { |
|
| 574 | + return false; |
|
| 575 | + } |
|
| 561 | 576 | |
| 562 | 577 | // Encode processed files into TAR file format |
| 563 | 578 | $this->__generateTar(); |
@@ -565,8 +580,9 @@ discard block |
||
| 565 | 580 | // GZ Compress the data if we need to |
| 566 | 581 | if($useGzip) { |
| 567 | 582 | // Make sure we have gzip support |
| 568 | - if(!function_exists("gzencode")) |
|
| 569 | - return false; |
|
| 583 | + if(!function_exists("gzencode")) { |
|
| 584 | + return false; |
|
| 585 | + } |
|
| 570 | 586 | |
| 571 | 587 | $file = gzencode($this->tar_file); |
| 572 | 588 | } else { |
@@ -85,9 +85,9 @@ discard block |
||
| 85 | 85 | // to try to ensure valid file |
| 86 | 86 | // PRIVATE ACCESS FUNCTION |
| 87 | 87 | function __computeUnsignedChecksum($bytestring) { |
| 88 | - for($i=0; $i<512; $i++) |
|
| 88 | + for ($i = 0; $i < 512; $i++) |
|
| 89 | 89 | $unsigned_chksum += ord($bytestring[$i]); |
| 90 | - for($i=0; $i<8; $i++) |
|
| 90 | + for ($i = 0; $i < 8; $i++) |
|
| 91 | 91 | $unsigned_chksum -= ord($bytestring[148 + $i]); |
| 92 | 92 | $unsigned_chksum += ord(" ") * 8; |
| 93 | 93 | |
@@ -98,12 +98,12 @@ discard block |
||
| 98 | 98 | // Converts a NULL padded string to a non-NULL padded string |
| 99 | 99 | // PRIVATE ACCESS FUNCTION |
| 100 | 100 | function __parseNullPaddedString($string) { |
| 101 | - $position = strpos($string,chr(0)); |
|
| 102 | - if(!$position) |
|
| 101 | + $position = strpos($string, chr(0)); |
|
| 102 | + if (!$position) |
|
| 103 | 103 | { |
| 104 | 104 | $position = strlen($string); |
| 105 | 105 | } |
| 106 | - return substr($string,0,$position); |
|
| 106 | + return substr($string, 0, $position); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | |
@@ -114,46 +114,46 @@ discard block |
||
| 114 | 114 | $tar_length = strlen($this->tar_file); |
| 115 | 115 | $main_offset = 0; |
| 116 | 116 | $flag_longlink = false; |
| 117 | - while($main_offset < $tar_length) { |
|
| 117 | + while ($main_offset < $tar_length) { |
|
| 118 | 118 | // If we read a block of 512 nulls, we are at the end of the archive |
| 119 | - if(substr($this->tar_file,$main_offset,512) == str_repeat(chr(0),512)) |
|
| 119 | + if (substr($this->tar_file, $main_offset, 512) == str_repeat(chr(0), 512)) |
|
| 120 | 120 | break; |
| 121 | 121 | |
| 122 | 122 | // Parse file name |
| 123 | - $file_name = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset,100)); |
|
| 123 | + $file_name = $this->__parseNullPaddedString(substr($this->tar_file, $main_offset, 100)); |
|
| 124 | 124 | |
| 125 | 125 | // Parse the file mode |
| 126 | - $file_mode = substr($this->tar_file,$main_offset + 100,8); |
|
| 126 | + $file_mode = substr($this->tar_file, $main_offset + 100, 8); |
|
| 127 | 127 | |
| 128 | 128 | // Parse the file user ID |
| 129 | - $file_uid = octdec(substr($this->tar_file,$main_offset + 108,8)); |
|
| 129 | + $file_uid = octdec(substr($this->tar_file, $main_offset + 108, 8)); |
|
| 130 | 130 | |
| 131 | 131 | // Parse the file group ID |
| 132 | - $file_gid = octdec(substr($this->tar_file,$main_offset + 116,8)); |
|
| 132 | + $file_gid = octdec(substr($this->tar_file, $main_offset + 116, 8)); |
|
| 133 | 133 | |
| 134 | 134 | // Parse the file size |
| 135 | - $file_size = octdec(substr($this->tar_file,$main_offset + 124,12)); |
|
| 135 | + $file_size = octdec(substr($this->tar_file, $main_offset + 124, 12)); |
|
| 136 | 136 | |
| 137 | 137 | // Parse the file update time - unix timestamp format |
| 138 | - $file_time = octdec(substr($this->tar_file,$main_offset + 136,12)); |
|
| 138 | + $file_time = octdec(substr($this->tar_file, $main_offset + 136, 12)); |
|
| 139 | 139 | |
| 140 | 140 | // Parse Checksum |
| 141 | - $file_chksum = octdec(substr($this->tar_file,$main_offset + 148,6)); |
|
| 141 | + $file_chksum = octdec(substr($this->tar_file, $main_offset + 148, 6)); |
|
| 142 | 142 | |
| 143 | 143 | // Parse user name |
| 144 | - $file_uname = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset + 265,32)); |
|
| 144 | + $file_uname = $this->__parseNullPaddedString(substr($this->tar_file, $main_offset + 265, 32)); |
|
| 145 | 145 | |
| 146 | 146 | // Parse Group name |
| 147 | - $file_gname = $this->__parseNullPaddedString(substr($this->tar_file,$main_offset + 297,32)); |
|
| 147 | + $file_gname = $this->__parseNullPaddedString(substr($this->tar_file, $main_offset + 297, 32)); |
|
| 148 | 148 | |
| 149 | - $file_type = substr($this->tar_file,$main_offset + 156,1); |
|
| 149 | + $file_type = substr($this->tar_file, $main_offset + 156, 1); |
|
| 150 | 150 | |
| 151 | 151 | // Make sure our file is valid |
| 152 | - if($this->__computeUnsignedChecksum(substr($this->tar_file,$main_offset,512)) != $file_chksum) |
|
| 152 | + if ($this->__computeUnsignedChecksum(substr($this->tar_file, $main_offset, 512)) != $file_chksum) |
|
| 153 | 153 | return false; |
| 154 | 154 | |
| 155 | 155 | // Parse File Contents |
| 156 | - $file_contents = substr($this->tar_file,$main_offset + 512,$file_size); |
|
| 156 | + $file_contents = substr($this->tar_file, $main_offset + 512, $file_size); |
|
| 157 | 157 | |
| 158 | 158 | /* ### Unused Header Information ### |
| 159 | 159 | $activeFile["typeflag"] = substr($this->tar_file,$main_offset + 156,1); |
@@ -166,12 +166,12 @@ discard block |
||
| 166 | 166 | $activeFile["endheader"] = substr($this->tar_file,$main_offset + 500,12); |
| 167 | 167 | */ |
| 168 | 168 | |
| 169 | - if(strtolower($file_type) == 'l' || $file_name == '././@LongLink') |
|
| 169 | + if (strtolower($file_type) == 'l' || $file_name == '././@LongLink') |
|
| 170 | 170 | { |
| 171 | 171 | $flag_longlink = true; |
| 172 | 172 | $longlink_name = $this->__parseNullPaddedString($file_contents); |
| 173 | 173 | } |
| 174 | - elseif($file_type == '0') { |
|
| 174 | + elseif ($file_type == '0') { |
|
| 175 | 175 | // Increment number of files |
| 176 | 176 | $this->numFiles++; |
| 177 | 177 | |
@@ -179,13 +179,13 @@ discard block |
||
| 179 | 179 | $activeFile = &$this->files[]; |
| 180 | 180 | |
| 181 | 181 | // Asign Values |
| 182 | - if($flag_longlink) |
|
| 182 | + if ($flag_longlink) |
|
| 183 | 183 | { |
| 184 | - $activeFile["name"] = $longlink_name; |
|
| 184 | + $activeFile["name"] = $longlink_name; |
|
| 185 | 185 | } |
| 186 | 186 | else |
| 187 | 187 | { |
| 188 | - $activeFile["name"] = $file_name; |
|
| 188 | + $activeFile["name"] = $file_name; |
|
| 189 | 189 | } |
| 190 | 190 | $activeFile["type"] = $file_type; |
| 191 | 191 | $activeFile["mode"] = $file_mode; |
@@ -196,11 +196,11 @@ discard block |
||
| 196 | 196 | $activeFile["user_name"] = $file_uname; |
| 197 | 197 | $activeFile["group_name"] = $file_gname; |
| 198 | 198 | $activeFile["checksum"] = $file_chksum; |
| 199 | - $activeFile["file"] = $file_contents; |
|
| 199 | + $activeFile["file"] = $file_contents; |
|
| 200 | 200 | |
| 201 | 201 | $flag_longlink = false; |
| 202 | 202 | |
| 203 | - } elseif($file_type == '5') { |
|
| 203 | + } elseif ($file_type == '5') { |
|
| 204 | 204 | // Increment number of directories |
| 205 | 205 | $this->numDirectories++; |
| 206 | 206 | |
@@ -208,9 +208,9 @@ discard block |
||
| 208 | 208 | $activeDir = &$this->directories[]; |
| 209 | 209 | |
| 210 | 210 | // Assign values |
| 211 | - if($flag_longlink) |
|
| 211 | + if ($flag_longlink) |
|
| 212 | 212 | { |
| 213 | - $activeDir["name"] = $longlink_name; |
|
| 213 | + $activeDir["name"] = $longlink_name; |
|
| 214 | 214 | } |
| 215 | 215 | else |
| 216 | 216 | { |
@@ -238,23 +238,23 @@ discard block |
||
| 238 | 238 | |
| 239 | 239 | // Read a non gzipped tar file in for processing |
| 240 | 240 | // PRIVATE ACCESS FUNCTION |
| 241 | - function __readTar($filename='') { |
|
| 241 | + function __readTar($filename = '') { |
|
| 242 | 242 | // Set the filename to load |
| 243 | - if(!$filename) |
|
| 243 | + if (!$filename) |
|
| 244 | 244 | $filename = $this->filename; |
| 245 | 245 | |
| 246 | 246 | // Read in the TAR file |
| 247 | - $fp = fopen($filename,"rb"); |
|
| 248 | - $this->tar_file = fread($fp,filesize($filename)); |
|
| 247 | + $fp = fopen($filename, "rb"); |
|
| 248 | + $this->tar_file = fread($fp, filesize($filename)); |
|
| 249 | 249 | fclose($fp); |
| 250 | 250 | |
| 251 | - if($this->tar_file[0] == chr(31) && $this->tar_file[1] == chr(139) && $this->tar_file[2] == chr(8)) { |
|
| 252 | - if(!function_exists("gzinflate")) |
|
| 251 | + if ($this->tar_file[0] == chr(31) && $this->tar_file[1] == chr(139) && $this->tar_file[2] == chr(8)) { |
|
| 252 | + if (!function_exists("gzinflate")) |
|
| 253 | 253 | return false; |
| 254 | 254 | |
| 255 | 255 | $this->isGzipped = TRUE; |
| 256 | 256 | |
| 257 | - $this->tar_file = gzinflate(substr($this->tar_file,10,-4)); |
|
| 257 | + $this->tar_file = gzinflate(substr($this->tar_file, 10, -4)); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | // Parse the TAR file |
@@ -271,34 +271,34 @@ discard block |
||
| 271 | 271 | unset($this->tar_file); |
| 272 | 272 | |
| 273 | 273 | // Generate Records for each directory, if we have directories |
| 274 | - if($this->numDirectories > 0) { |
|
| 275 | - foreach($this->directories as $key => $information) { |
|
| 274 | + if ($this->numDirectories > 0) { |
|
| 275 | + foreach ($this->directories as $key => $information) { |
|
| 276 | 276 | unset($header); |
| 277 | 277 | |
| 278 | 278 | // Generate tar header for this directory |
| 279 | 279 | // Filename, Permissions, UID, GID, size, Time, checksum, typeflag, linkname, magic, version, user name, group name, devmajor, devminor, prefix, end |
| 280 | - $header .= str_pad($information["name"],100,chr(0)); |
|
| 281 | - $header .= str_pad(decoct($information["mode"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 282 | - $header .= str_pad(decoct($information["user_id"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 283 | - $header .= str_pad(decoct($information["group_id"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 284 | - $header .= str_pad(decoct(0),11,"0",STR_PAD_LEFT) . chr(0); |
|
| 285 | - $header .= str_pad(decoct($information["time"]),11,"0",STR_PAD_LEFT) . chr(0); |
|
| 286 | - $header .= str_repeat(" ",8); |
|
| 280 | + $header .= str_pad($information["name"], 100, chr(0)); |
|
| 281 | + $header .= str_pad(decoct($information["mode"]), 7, "0", STR_PAD_LEFT).chr(0); |
|
| 282 | + $header .= str_pad(decoct($information["user_id"]), 7, "0", STR_PAD_LEFT).chr(0); |
|
| 283 | + $header .= str_pad(decoct($information["group_id"]), 7, "0", STR_PAD_LEFT).chr(0); |
|
| 284 | + $header .= str_pad(decoct(0), 11, "0", STR_PAD_LEFT).chr(0); |
|
| 285 | + $header .= str_pad(decoct($information["time"]), 11, "0", STR_PAD_LEFT).chr(0); |
|
| 286 | + $header .= str_repeat(" ", 8); |
|
| 287 | 287 | $header .= "5"; |
| 288 | - $header .= str_repeat(chr(0),100); |
|
| 289 | - $header .= str_pad("ustar",6,chr(32)); |
|
| 290 | - $header .= chr(32) . chr(0); |
|
| 291 | - $header .= str_pad("",32,chr(0)); |
|
| 292 | - $header .= str_pad("",32,chr(0)); |
|
| 293 | - $header .= str_repeat(chr(0),8); |
|
| 294 | - $header .= str_repeat(chr(0),8); |
|
| 295 | - $header .= str_repeat(chr(0),155); |
|
| 296 | - $header .= str_repeat(chr(0),12); |
|
| 288 | + $header .= str_repeat(chr(0), 100); |
|
| 289 | + $header .= str_pad("ustar", 6, chr(32)); |
|
| 290 | + $header .= chr(32).chr(0); |
|
| 291 | + $header .= str_pad("", 32, chr(0)); |
|
| 292 | + $header .= str_pad("", 32, chr(0)); |
|
| 293 | + $header .= str_repeat(chr(0), 8); |
|
| 294 | + $header .= str_repeat(chr(0), 8); |
|
| 295 | + $header .= str_repeat(chr(0), 155); |
|
| 296 | + $header .= str_repeat(chr(0), 12); |
|
| 297 | 297 | |
| 298 | 298 | // Compute header checksum |
| 299 | - $checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)),6,"0",STR_PAD_LEFT); |
|
| 300 | - for($i=0; $i<6; $i++) { |
|
| 301 | - $header[(148 + $i)] = substr($checksum,$i,1); |
|
| 299 | + $checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)), 6, "0", STR_PAD_LEFT); |
|
| 300 | + for ($i = 0; $i < 6; $i++) { |
|
| 301 | + $header[(148 + $i)] = substr($checksum, $i, 1); |
|
| 302 | 302 | } |
| 303 | 303 | $header[154] = chr(0); |
| 304 | 304 | $header[155] = chr(32); |
@@ -309,48 +309,48 @@ discard block |
||
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | // Generate Records for each file, if we have files (We should...) |
| 312 | - if($this->numFiles > 0) { |
|
| 313 | - foreach($this->files as $key => $information) { |
|
| 312 | + if ($this->numFiles > 0) { |
|
| 313 | + foreach ($this->files as $key => $information) { |
|
| 314 | 314 | unset($header); |
| 315 | 315 | |
| 316 | 316 | // Generate the TAR header for this file |
| 317 | 317 | // Filename, Permissions, UID, GID, size, Time, checksum, typeflag, linkname, magic, version, user name, group name, devmajor, devminor, prefix, end |
| 318 | - $header .= str_pad($information["name"],100,chr(0)); |
|
| 319 | - $header .= str_pad(decoct($information["mode"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 320 | - $header .= str_pad(decoct($information["user_id"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 321 | - $header .= str_pad(decoct($information["group_id"]),7,"0",STR_PAD_LEFT) . chr(0); |
|
| 322 | - $header .= str_pad(decoct($information["size"]),11,"0",STR_PAD_LEFT) . chr(0); |
|
| 323 | - $header .= str_pad(decoct($information["time"]),11,"0",STR_PAD_LEFT) . chr(0); |
|
| 324 | - $header .= str_repeat(" ",8); |
|
| 318 | + $header .= str_pad($information["name"], 100, chr(0)); |
|
| 319 | + $header .= str_pad(decoct($information["mode"]), 7, "0", STR_PAD_LEFT).chr(0); |
|
| 320 | + $header .= str_pad(decoct($information["user_id"]), 7, "0", STR_PAD_LEFT).chr(0); |
|
| 321 | + $header .= str_pad(decoct($information["group_id"]), 7, "0", STR_PAD_LEFT).chr(0); |
|
| 322 | + $header .= str_pad(decoct($information["size"]), 11, "0", STR_PAD_LEFT).chr(0); |
|
| 323 | + $header .= str_pad(decoct($information["time"]), 11, "0", STR_PAD_LEFT).chr(0); |
|
| 324 | + $header .= str_repeat(" ", 8); |
|
| 325 | 325 | $header .= "0"; |
| 326 | - $header .= str_repeat(chr(0),100); |
|
| 327 | - $header .= str_pad("ustar",6,chr(32)); |
|
| 328 | - $header .= chr(32) . chr(0); |
|
| 329 | - $header .= str_pad($information["user_name"],32,chr(0)); // How do I get a file's user name from PHP? |
|
| 330 | - $header .= str_pad($information["group_name"],32,chr(0)); // How do I get a file's group name from PHP? |
|
| 331 | - $header .= str_repeat(chr(0),8); |
|
| 332 | - $header .= str_repeat(chr(0),8); |
|
| 333 | - $header .= str_repeat(chr(0),155); |
|
| 334 | - $header .= str_repeat(chr(0),12); |
|
| 326 | + $header .= str_repeat(chr(0), 100); |
|
| 327 | + $header .= str_pad("ustar", 6, chr(32)); |
|
| 328 | + $header .= chr(32).chr(0); |
|
| 329 | + $header .= str_pad($information["user_name"], 32, chr(0)); // How do I get a file's user name from PHP? |
|
| 330 | + $header .= str_pad($information["group_name"], 32, chr(0)); // How do I get a file's group name from PHP? |
|
| 331 | + $header .= str_repeat(chr(0), 8); |
|
| 332 | + $header .= str_repeat(chr(0), 8); |
|
| 333 | + $header .= str_repeat(chr(0), 155); |
|
| 334 | + $header .= str_repeat(chr(0), 12); |
|
| 335 | 335 | |
| 336 | 336 | // Compute header checksum |
| 337 | - $checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)),6,"0",STR_PAD_LEFT); |
|
| 338 | - for($i=0; $i<6; $i++) { |
|
| 339 | - $header[(148 + $i)] = substr($checksum,$i,1); |
|
| 337 | + $checksum = str_pad(decoct($this->__computeUnsignedChecksum($header)), 6, "0", STR_PAD_LEFT); |
|
| 338 | + for ($i = 0; $i < 6; $i++) { |
|
| 339 | + $header[(148 + $i)] = substr($checksum, $i, 1); |
|
| 340 | 340 | } |
| 341 | 341 | $header[154] = chr(0); |
| 342 | 342 | $header[155] = chr(32); |
| 343 | 343 | |
| 344 | 344 | // Pad file contents to byte count divisible by 512 |
| 345 | - $file_contents = str_pad($information["file"],(ceil($information["size"] / 512) * 512),chr(0)); |
|
| 345 | + $file_contents = str_pad($information["file"], (ceil($information["size"] / 512) * 512), chr(0)); |
|
| 346 | 346 | |
| 347 | 347 | // Add new tar formatted data to tar file contents |
| 348 | - $this->tar_file .= $header . $file_contents; |
|
| 348 | + $this->tar_file .= $header.$file_contents; |
|
| 349 | 349 | } |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | // Add 512 bytes of NULLs to designate EOF |
| 353 | - $this->tar_file .= str_repeat(chr(0),512); |
|
| 353 | + $this->tar_file .= str_repeat(chr(0), 512); |
|
| 354 | 354 | |
| 355 | 355 | return true; |
| 356 | 356 | } |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | unset($this->numDirectories); |
| 369 | 369 | |
| 370 | 370 | // If the tar file doesn't exist... |
| 371 | - if(!file_exists($filename)) |
|
| 371 | + if (!file_exists($filename)) |
|
| 372 | 372 | return false; |
| 373 | 373 | |
| 374 | 374 | $this->filename = $filename; |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | // Appends a tar file to the end of the currently opened tar file |
| 384 | 384 | function appendTar($filename) { |
| 385 | 385 | // If the tar file doesn't exist... |
| 386 | - if(!file_exists($filename)) |
|
| 386 | + if (!file_exists($filename)) |
|
| 387 | 387 | return false; |
| 388 | 388 | |
| 389 | 389 | $this->__readTar($filename); |
@@ -394,9 +394,9 @@ discard block |
||
| 394 | 394 | |
| 395 | 395 | // Retrieves information about a file in the current tar archive |
| 396 | 396 | function getFile($filename) { |
| 397 | - if($this->numFiles > 0) { |
|
| 398 | - foreach($this->files as $key => $information) { |
|
| 399 | - if($information["name"] == $filename) |
|
| 397 | + if ($this->numFiles > 0) { |
|
| 398 | + foreach ($this->files as $key => $information) { |
|
| 399 | + if ($information["name"] == $filename) |
|
| 400 | 400 | return $information; |
| 401 | 401 | } |
| 402 | 402 | } |
@@ -407,9 +407,9 @@ discard block |
||
| 407 | 407 | |
| 408 | 408 | // Retrieves information about a directory in the current tar archive |
| 409 | 409 | function getDirectory($dirname) { |
| 410 | - if($this->numDirectories > 0) { |
|
| 411 | - foreach($this->directories as $key => $information) { |
|
| 412 | - if($information["name"] == $dirname) |
|
| 410 | + if ($this->numDirectories > 0) { |
|
| 411 | + foreach ($this->directories as $key => $information) { |
|
| 412 | + if ($information["name"] == $dirname) |
|
| 413 | 413 | return $information; |
| 414 | 414 | } |
| 415 | 415 | } |
@@ -420,9 +420,9 @@ discard block |
||
| 420 | 420 | |
| 421 | 421 | // Check if this tar archive contains a specific file |
| 422 | 422 | function containsFile($filename) { |
| 423 | - if($this->numFiles > 0) { |
|
| 424 | - foreach($this->files as $key => $information) { |
|
| 425 | - if($information["name"] == $filename) |
|
| 423 | + if ($this->numFiles > 0) { |
|
| 424 | + foreach ($this->files as $key => $information) { |
|
| 425 | + if ($information["name"] == $filename) |
|
| 426 | 426 | return true; |
| 427 | 427 | } |
| 428 | 428 | } |
@@ -433,9 +433,9 @@ discard block |
||
| 433 | 433 | |
| 434 | 434 | // Check if this tar archive contains a specific directory |
| 435 | 435 | function containsDirectory($dirname) { |
| 436 | - if($this->numDirectories > 0) { |
|
| 437 | - foreach($this->directories as $key => $information) { |
|
| 438 | - if($information["name"] == $dirname) |
|
| 436 | + if ($this->numDirectories > 0) { |
|
| 437 | + foreach ($this->directories as $key => $information) { |
|
| 438 | + if ($information["name"] == $dirname) |
|
| 439 | 439 | return true; |
| 440 | 440 | } |
| 441 | 441 | } |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | |
| 447 | 447 | // Add a directory to this tar archive |
| 448 | 448 | function addDirectory($dirname) { |
| 449 | - if(!file_exists($dirname)) |
|
| 449 | + if (!file_exists($dirname)) |
|
| 450 | 450 | return false; |
| 451 | 451 | |
| 452 | 452 | // Get directory information |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | |
| 455 | 455 | // Add directory to processed data |
| 456 | 456 | $this->numDirectories++; |
| 457 | - $activeDir = &$this->directories[]; |
|
| 457 | + $activeDir = &$this->directories[]; |
|
| 458 | 458 | $activeDir["name"] = $dirname; |
| 459 | 459 | $activeDir["mode"] = $file_information["mode"]; |
| 460 | 460 | $activeDir["time"] = $file_information["time"]; |
@@ -467,34 +467,34 @@ discard block |
||
| 467 | 467 | |
| 468 | 468 | |
| 469 | 469 | // Add a file to the tar archive |
| 470 | - function addFile($filename,$from=null,$to=null) { |
|
| 470 | + function addFile($filename, $from = null, $to = null) { |
|
| 471 | 471 | // Make sure the file we are adding exists! |
| 472 | - if(!file_exists($filename)) |
|
| 472 | + if (!file_exists($filename)) |
|
| 473 | 473 | return false; |
| 474 | 474 | |
| 475 | - if(filesize($filename)==0) |
|
| 475 | + if (filesize($filename) == 0) |
|
| 476 | 476 | return false; |
| 477 | 477 | |
| 478 | 478 | // Make sure there are no other files in the archive that have this same filename |
| 479 | - if($this->containsFile($filename)) |
|
| 479 | + if ($this->containsFile($filename)) |
|
| 480 | 480 | return false; |
| 481 | 481 | |
| 482 | 482 | // Get file information |
| 483 | 483 | $file_information = stat($filename); |
| 484 | 484 | |
| 485 | 485 | // Read in the file's contents |
| 486 | - $fp = fopen($filename,"rb"); |
|
| 487 | - $file_contents = fread($fp,filesize($filename)); |
|
| 486 | + $fp = fopen($filename, "rb"); |
|
| 487 | + $file_contents = fread($fp, filesize($filename)); |
|
| 488 | 488 | fclose($fp); |
| 489 | 489 | |
| 490 | - if($from && $to){ |
|
| 491 | - $file_contents = str_replace($from,$to,$file_contents); |
|
| 490 | + if ($from && $to) { |
|
| 491 | + $file_contents = str_replace($from, $to, $file_contents); |
|
| 492 | 492 | $file_information["size"] = strlen($file_contents); |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | // Add file to processed data |
| 496 | 496 | $this->numFiles++; |
| 497 | - $activeFile = &$this->files[]; |
|
| 497 | + $activeFile = &$this->files[]; |
|
| 498 | 498 | $activeFile["name"] = $filename; |
| 499 | 499 | $activeFile["mode"] = $file_information["mode"]; |
| 500 | 500 | $activeFile["user_id"] = $file_information["uid"]; |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | $activeFile["checksum"] = $checksum; |
| 505 | 505 | $activeFile["user_name"] = ""; |
| 506 | 506 | $activeFile["group_name"] = ""; |
| 507 | - $activeFile["file"] = $file_contents; |
|
| 507 | + $activeFile["file"] = $file_contents; |
|
| 508 | 508 | |
| 509 | 509 | return true; |
| 510 | 510 | } |
@@ -512,9 +512,9 @@ discard block |
||
| 512 | 512 | |
| 513 | 513 | // Remove a file from the tar archive |
| 514 | 514 | function removeFile($filename) { |
| 515 | - if($this->numFiles > 0) { |
|
| 516 | - foreach($this->files as $key => $information) { |
|
| 517 | - if($information["name"] == $filename) { |
|
| 515 | + if ($this->numFiles > 0) { |
|
| 516 | + foreach ($this->files as $key => $information) { |
|
| 517 | + if ($information["name"] == $filename) { |
|
| 518 | 518 | $this->numFiles--; |
| 519 | 519 | unset($this->files[$key]); |
| 520 | 520 | return true; |
@@ -528,9 +528,9 @@ discard block |
||
| 528 | 528 | |
| 529 | 529 | // Remove a directory from the tar archive |
| 530 | 530 | function removeDirectory($dirname) { |
| 531 | - if($this->numDirectories > 0) { |
|
| 532 | - foreach($this->directories as $key => $information) { |
|
| 533 | - if($information["name"] == $dirname) { |
|
| 531 | + if ($this->numDirectories > 0) { |
|
| 532 | + foreach ($this->directories as $key => $information) { |
|
| 533 | + if ($information["name"] == $dirname) { |
|
| 534 | 534 | $this->numDirectories--; |
| 535 | 535 | unset($this->directories[$key]); |
| 536 | 536 | return true; |
@@ -544,28 +544,28 @@ discard block |
||
| 544 | 544 | |
| 545 | 545 | // Write the currently loaded tar archive to disk |
| 546 | 546 | function saveTar() { |
| 547 | - if(!$this->filename) |
|
| 547 | + if (!$this->filename) |
|
| 548 | 548 | return false; |
| 549 | 549 | |
| 550 | 550 | // Write tar to current file using specified gzip compression |
| 551 | - $this->toTar($this->filename,$this->isGzipped); |
|
| 551 | + $this->toTar($this->filename, $this->isGzipped); |
|
| 552 | 552 | |
| 553 | 553 | return true; |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | |
| 557 | 557 | // Saves tar archive to a different file than the current file |
| 558 | - function toTar($filename,$useGzip) { |
|
| 559 | - if(!$filename) |
|
| 558 | + function toTar($filename, $useGzip) { |
|
| 559 | + if (!$filename) |
|
| 560 | 560 | return false; |
| 561 | 561 | |
| 562 | 562 | // Encode processed files into TAR file format |
| 563 | 563 | $this->__generateTar(); |
| 564 | 564 | |
| 565 | 565 | // GZ Compress the data if we need to |
| 566 | - if($useGzip) { |
|
| 566 | + if ($useGzip) { |
|
| 567 | 567 | // Make sure we have gzip support |
| 568 | - if(!function_exists("gzencode")) |
|
| 568 | + if (!function_exists("gzencode")) |
|
| 569 | 569 | return false; |
| 570 | 570 | |
| 571 | 571 | $file = gzencode($this->tar_file); |
@@ -574,8 +574,8 @@ discard block |
||
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | // Write the TAR file |
| 577 | - $fp = fopen($filename,"wb"); |
|
| 578 | - fwrite($fp,$file); |
|
| 577 | + $fp = fopen($filename, "wb"); |
|
| 578 | + fwrite($fp, $file); |
|
| 579 | 579 | fclose($fp); |
| 580 | 580 | |
| 581 | 581 | return true; |
@@ -141,7 +141,7 @@ |
||
| 141 | 141 | * @param string $addon Name to get information |
| 142 | 142 | * @param int $site_srl Site srl |
| 143 | 143 | * @param string $gtype site or global |
| 144 | - * @return object Returns a information |
|
| 144 | + * @return null|stdClass Returns a information |
|
| 145 | 145 | */ |
| 146 | 146 | function getAddonInfoXml($addon, $site_srl = 0, $gtype = 'site') |
| 147 | 147 | { |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | function getAddonPath($addon_name) |
| 28 | 28 | { |
| 29 | 29 | $class_path = sprintf('./addons/%s/', $addon_name); |
| 30 | - if(is_dir($class_path)) |
|
| 30 | + if (is_dir($class_path)) |
|
| 31 | 31 | { |
| 32 | 32 | return $class_path; |
| 33 | 33 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $addonList = $this->getAddonList(0, 'site'); |
| 45 | 45 | |
| 46 | 46 | $oAutoinstallModel = getModel('autoinstall'); |
| 47 | - foreach($addonList as $key => $addon) |
|
| 47 | + foreach ($addonList as $key => $addon) |
|
| 48 | 48 | { |
| 49 | 49 | // get easyinstall remove url |
| 50 | 50 | $packageSrl = $oAutoinstallModel->getPackageSrlByPath($addon->path); |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $addonList[$key]->need_update = $package[$packageSrl]->need_update; |
| 56 | 56 | |
| 57 | 57 | // get easyinstall update url |
| 58 | - if($addonList[$key]->need_update == 'Y') |
|
| 58 | + if ($addonList[$key]->need_update == 'Y') |
|
| 59 | 59 | { |
| 60 | 60 | $addonList[$key]->update_url = $oAutoinstallModel->getUpdateUrlByPackageSrl($packageSrl); |
| 61 | 61 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | // Downloaded and installed add-on to the list of Wanted |
| 79 | 79 | $searched_list = FileHandler::readDir('./addons', '/^([a-zA-Z0-9-_]+)$/'); |
| 80 | 80 | $searched_count = count($searched_list); |
| 81 | - if(!$searched_count) |
|
| 81 | + if (!$searched_count) |
|
| 82 | 82 | { |
| 83 | 83 | return; |
| 84 | 84 | } |
@@ -87,11 +87,11 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | $oAddonAdminController = getAdminController('addon'); |
| 89 | 89 | |
| 90 | - for($i = 0; $i < $searched_count; $i++) |
|
| 90 | + for ($i = 0; $i < $searched_count; $i++) |
|
| 91 | 91 | { |
| 92 | 92 | // Add the name of |
| 93 | 93 | $addon_name = $searched_list[$i]; |
| 94 | - if($addon_name == "smartphone") |
|
| 94 | + if ($addon_name == "smartphone") |
|
| 95 | 95 | { |
| 96 | 96 | continue; |
| 97 | 97 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | // Wanted information on the add-on |
| 101 | 101 | $info = $this->getAddonInfoXml($addon_name, $site_srl, $gtype); |
| 102 | 102 | |
| 103 | - if(!$info) $info = new stdClass(); |
|
| 103 | + if (!$info) $info = new stdClass(); |
|
| 104 | 104 | |
| 105 | 105 | $info->addon = $addon_name; |
| 106 | 106 | $info->path = $path; |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $info->mactivated = FALSE; |
| 109 | 109 | $info->fixed = FALSE; |
| 110 | 110 | // Check if a permossion is granted entered in DB |
| 111 | - if(!in_array($addon_name, array_keys($inserted_addons))) |
|
| 111 | + if (!in_array($addon_name, array_keys($inserted_addons))) |
|
| 112 | 112 | { |
| 113 | 113 | // If not, type in the DB type (model, perhaps because of the hate doing this haneungeo .. ㅡ. ㅜ) |
| 114 | 114 | $oAddonAdminController->doInsert($addon_name, $site_srl, $type); |
@@ -116,15 +116,15 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | else |
| 118 | 118 | { |
| 119 | - if($inserted_addons[$addon_name]->is_used == 'Y') |
|
| 119 | + if ($inserted_addons[$addon_name]->is_used == 'Y') |
|
| 120 | 120 | { |
| 121 | 121 | $info->activated = TRUE; |
| 122 | 122 | } |
| 123 | - if($inserted_addons[$addon_name]->is_used_m == 'Y') |
|
| 123 | + if ($inserted_addons[$addon_name]->is_used_m == 'Y') |
|
| 124 | 124 | { |
| 125 | 125 | $info->mactivated = TRUE; |
| 126 | 126 | } |
| 127 | - if($gtype == 'global' && $inserted_addons[$addon_name]->is_fixed == 'Y') |
|
| 127 | + if ($gtype == 'global' && $inserted_addons[$addon_name]->is_fixed == 'Y') |
|
| 128 | 128 | { |
| 129 | 129 | $info->fixed = TRUE; |
| 130 | 130 | } |
@@ -147,14 +147,14 @@ discard block |
||
| 147 | 147 | { |
| 148 | 148 | // Get a path of the requested module. Return if not exists. |
| 149 | 149 | $addon_path = $this->getAddonPath($addon); |
| 150 | - if(!$addon_path) |
|
| 150 | + if (!$addon_path) |
|
| 151 | 151 | { |
| 152 | 152 | return; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | // Read the xml file for module skin information |
| 156 | 156 | $xml_file = sprintf("%sconf/info.xml", FileHandler::getRealpath($addon_path)); |
| 157 | - if(!file_exists($xml_file)) |
|
| 157 | + if (!file_exists($xml_file)) |
|
| 158 | 158 | { |
| 159 | 159 | return; |
| 160 | 160 | } |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | $tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file); |
| 164 | 164 | $xml_obj = $tmp_xml_obj->addon; |
| 165 | 165 | |
| 166 | - if(!$xml_obj) |
|
| 166 | + if (!$xml_obj) |
|
| 167 | 167 | { |
| 168 | 168 | return; |
| 169 | 169 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | // DB is set to bring history |
| 172 | 172 | $db_args = new stdClass(); |
| 173 | 173 | $db_args->addon = $addon; |
| 174 | - if($gtype == 'global') |
|
| 174 | + if ($gtype == 'global') |
|
| 175 | 175 | { |
| 176 | 176 | $output = executeQuery('addon.getAddonInfo', $db_args); |
| 177 | 177 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | $extra_vals = unserialize($output->data->extra_vars); |
| 184 | 184 | |
| 185 | 185 | $addon_info = new stdClass(); |
| 186 | - if($extra_vals->mid_list) |
|
| 186 | + if ($extra_vals->mid_list) |
|
| 187 | 187 | { |
| 188 | 188 | $addon_info->mid_list = $extra_vals->mid_list; |
| 189 | 189 | } |
@@ -192,13 +192,13 @@ discard block |
||
| 192 | 192 | $addon_info->mid_list = array(); |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - if($extra_vals->xe_run_method) |
|
| 195 | + if ($extra_vals->xe_run_method) |
|
| 196 | 196 | { |
| 197 | 197 | $addon_info->xe_run_method = $extra_vals->xe_run_method; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Add information |
| 201 | - if($xml_obj->version && $xml_obj->attrs->version == '0.2') |
|
| 201 | + if ($xml_obj->version && $xml_obj->attrs->version == '0.2') |
|
| 202 | 202 | { |
| 203 | 203 | // addon format v0.2 |
| 204 | 204 | $date_obj = new stdClass(); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | $addon_info->license = $xml_obj->license->body; |
| 214 | 214 | $addon_info->license_link = $xml_obj->license->attrs->link; |
| 215 | 215 | |
| 216 | - if(!is_array($xml_obj->author)) |
|
| 216 | + if (!is_array($xml_obj->author)) |
|
| 217 | 217 | { |
| 218 | 218 | $author_list = array(); |
| 219 | 219 | $author_list[] = $xml_obj->author; |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | $addon_info->author = array(); |
| 227 | - foreach($author_list as $author) |
|
| 227 | + foreach ($author_list as $author) |
|
| 228 | 228 | { |
| 229 | 229 | $author_obj = new stdClass(); |
| 230 | 230 | $author_obj->name = $author->name->body; |
@@ -234,39 +234,39 @@ discard block |
||
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | // Expand the variable order |
| 237 | - if($xml_obj->extra_vars) |
|
| 237 | + if ($xml_obj->extra_vars) |
|
| 238 | 238 | { |
| 239 | 239 | $extra_var_groups = $xml_obj->extra_vars->group; |
| 240 | - if(!$extra_var_groups) |
|
| 240 | + if (!$extra_var_groups) |
|
| 241 | 241 | { |
| 242 | 242 | $extra_var_groups = $xml_obj->extra_vars; |
| 243 | 243 | } |
| 244 | - if(!is_array($extra_var_groups)) |
|
| 244 | + if (!is_array($extra_var_groups)) |
|
| 245 | 245 | { |
| 246 | 246 | $extra_var_groups = array($extra_var_groups); |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - foreach($extra_var_groups as $group) |
|
| 249 | + foreach ($extra_var_groups as $group) |
|
| 250 | 250 | { |
| 251 | 251 | $extra_vars = $group->var; |
| 252 | - if(!is_array($group->var)) |
|
| 252 | + if (!is_array($group->var)) |
|
| 253 | 253 | { |
| 254 | 254 | $extra_vars = array($group->var); |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - foreach($extra_vars as $key => $val) |
|
| 257 | + foreach ($extra_vars as $key => $val) |
|
| 258 | 258 | { |
| 259 | - if(!$val) |
|
| 259 | + if (!$val) |
|
| 260 | 260 | { |
| 261 | 261 | continue; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | $obj = new stdClass(); |
| 265 | - if(!$val->attrs) |
|
| 265 | + if (!$val->attrs) |
|
| 266 | 266 | { |
| 267 | 267 | $val->attrs = new stdClass(); |
| 268 | 268 | } |
| 269 | - if(!$val->attrs->type) |
|
| 269 | + if (!$val->attrs->type) |
|
| 270 | 270 | { |
| 271 | 271 | $val->attrs->type = 'text'; |
| 272 | 272 | } |
@@ -276,26 +276,26 @@ discard block |
||
| 276 | 276 | $obj->title = $val->title->body; |
| 277 | 277 | $obj->type = $val->attrs->type; |
| 278 | 278 | $obj->description = $val->description->body; |
| 279 | - if($obj->name) |
|
| 279 | + if ($obj->name) |
|
| 280 | 280 | { |
| 281 | 281 | $obj->value = $extra_vals->{$obj->name}; |
| 282 | 282 | } |
| 283 | - if(strpos($obj->value, '|@|') != FALSE) |
|
| 283 | + if (strpos($obj->value, '|@|') != FALSE) |
|
| 284 | 284 | { |
| 285 | 285 | $obj->value = explode('|@|', $obj->value); |
| 286 | 286 | } |
| 287 | - if($obj->type == 'mid_list' && !is_array($obj->value)) |
|
| 287 | + if ($obj->type == 'mid_list' && !is_array($obj->value)) |
|
| 288 | 288 | { |
| 289 | 289 | $obj->value = array($obj->value); |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | // 'Select'type obtained from the option list. |
| 293 | - if($val->options && !is_array($val->options)) |
|
| 293 | + if ($val->options && !is_array($val->options)) |
|
| 294 | 294 | { |
| 295 | 295 | $val->options = array($val->options); |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - for($i = 0, $c = count($val->options); $i < $c; $i++) |
|
| 298 | + for ($i = 0, $c = count($val->options); $i < $c; $i++) |
|
| 299 | 299 | { |
| 300 | 300 | $obj->options[$i] = new stdClass(); |
| 301 | 301 | $obj->options[$i]->title = $val->options[$i]->title->body; |
@@ -328,30 +328,30 @@ discard block |
||
| 328 | 328 | $addon_info->author = array(); |
| 329 | 329 | $addon_info->author[] = $author_obj; |
| 330 | 330 | |
| 331 | - if($xml_obj->extra_vars) |
|
| 331 | + if ($xml_obj->extra_vars) |
|
| 332 | 332 | { |
| 333 | 333 | // Expand the variable order |
| 334 | 334 | $extra_var_groups = $xml_obj->extra_vars->group; |
| 335 | - if(!$extra_var_groups) |
|
| 335 | + if (!$extra_var_groups) |
|
| 336 | 336 | { |
| 337 | 337 | $extra_var_groups = $xml_obj->extra_vars; |
| 338 | 338 | } |
| 339 | - if(!is_array($extra_var_groups)) |
|
| 339 | + if (!is_array($extra_var_groups)) |
|
| 340 | 340 | { |
| 341 | 341 | $extra_var_groups = array($extra_var_groups); |
| 342 | 342 | } |
| 343 | - foreach($extra_var_groups as $group) |
|
| 343 | + foreach ($extra_var_groups as $group) |
|
| 344 | 344 | { |
| 345 | 345 | $extra_vars = $group->var; |
| 346 | - if(!is_array($group->var)) |
|
| 346 | + if (!is_array($group->var)) |
|
| 347 | 347 | { |
| 348 | 348 | $extra_vars = array($group->var); |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | $addon_info->extra_vars = array(); |
| 352 | - foreach($extra_vars as $key => $val) |
|
| 352 | + foreach ($extra_vars as $key => $val) |
|
| 353 | 353 | { |
| 354 | - if(!$val) |
|
| 354 | + if (!$val) |
|
| 355 | 355 | { |
| 356 | 356 | continue; |
| 357 | 357 | } |
@@ -363,26 +363,26 @@ discard block |
||
| 363 | 363 | $obj->title = $val->title->body; |
| 364 | 364 | $obj->type = $val->type->body ? $val->type->body : 'text'; |
| 365 | 365 | $obj->description = $val->description->body; |
| 366 | - if($obj->name) |
|
| 366 | + if ($obj->name) |
|
| 367 | 367 | { |
| 368 | 368 | $obj->value = $extra_vals->{$obj->name}; |
| 369 | 369 | } |
| 370 | - if(strpos($obj->value, '|@|') != false) |
|
| 370 | + if (strpos($obj->value, '|@|') != false) |
|
| 371 | 371 | { |
| 372 | 372 | $obj->value = explode('|@|', $obj->value); |
| 373 | 373 | } |
| 374 | - if($obj->type == 'mid_list' && !is_array($obj->value)) |
|
| 374 | + if ($obj->type == 'mid_list' && !is_array($obj->value)) |
|
| 375 | 375 | { |
| 376 | 376 | $obj->value = array($obj->value); |
| 377 | 377 | } |
| 378 | 378 | // 'Select'type obtained from the option list. |
| 379 | - if($val->options && !is_array($val->options)) |
|
| 379 | + if ($val->options && !is_array($val->options)) |
|
| 380 | 380 | { |
| 381 | 381 | $val->options = array($val->options); |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | $obj->options = array(); |
| 385 | - for($i = 0, $c = count($val->options); $i < $c; $i++) |
|
| 385 | + for ($i = 0, $c = count($val->options); $i < $c; $i++) |
|
| 386 | 386 | { |
| 387 | 387 | $obj->options[$i]->title = $val->options[$i]->title->body; |
| 388 | 388 | $obj->options[$i]->value = $val->options[$i]->value->body; |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | { |
| 407 | 407 | $args = new stdClass(); |
| 408 | 408 | $args->list_order = 'addon'; |
| 409 | - if($gtype == 'global') |
|
| 409 | + if ($gtype == 'global') |
|
| 410 | 410 | { |
| 411 | 411 | $output = executeQueryArray('addon.getAddons', $args); |
| 412 | 412 | } |
@@ -415,14 +415,14 @@ discard block |
||
| 415 | 415 | $args->site_srl = $site_srl; |
| 416 | 416 | $output = executeQueryArray('addon.getSiteAddons', $args); |
| 417 | 417 | } |
| 418 | - if(!$output->data) |
|
| 418 | + if (!$output->data) |
|
| 419 | 419 | { |
| 420 | 420 | return array(); |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | $activated_count = count($output->data); |
| 424 | 424 | $addon_list = array(); |
| 425 | - for($i = 0; $i < $activated_count; $i++) |
|
| 425 | + for ($i = 0; $i < $activated_count; $i++) |
|
| 426 | 426 | { |
| 427 | 427 | $addon = $output->data[$i]; |
| 428 | 428 | $addon_list[$addon->addon] = $addon; |
@@ -443,9 +443,9 @@ discard block |
||
| 443 | 443 | { |
| 444 | 444 | $args = new stdClass(); |
| 445 | 445 | $args->addon = $addon; |
| 446 | - if($gtype == 'global') |
|
| 446 | + if ($gtype == 'global') |
|
| 447 | 447 | { |
| 448 | - if($type == "pc") |
|
| 448 | + if ($type == "pc") |
|
| 449 | 449 | { |
| 450 | 450 | $output = executeQuery('addon.getAddonIsActivated', $args); |
| 451 | 451 | } |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | else |
| 458 | 458 | { |
| 459 | 459 | $args->site_srl = $site_srl; |
| 460 | - if($type == "pc") |
|
| 460 | + if ($type == "pc") |
|
| 461 | 461 | { |
| 462 | 462 | $output = executeQuery('addon.getSiteAddonIsActivated', $args); |
| 463 | 463 | } |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | $output = executeQuery('addon.getSiteMAddonIsActivated', $args); |
| 467 | 467 | } |
| 468 | 468 | } |
| 469 | - if($output->data->count > 0) |
|
| 469 | + if ($output->data->count > 0) |
|
| 470 | 470 | { |
| 471 | 471 | return TRUE; |
| 472 | 472 | } |
@@ -100,7 +100,9 @@ discard block |
||
| 100 | 100 | // Wanted information on the add-on |
| 101 | 101 | $info = $this->getAddonInfoXml($addon_name, $site_srl, $gtype); |
| 102 | 102 | |
| 103 | - if(!$info) $info = new stdClass(); |
|
| 103 | + if(!$info) { |
|
| 104 | + $info = new stdClass(); |
|
| 105 | + } |
|
| 104 | 106 | |
| 105 | 107 | $info->addon = $addon_name; |
| 106 | 108 | $info->path = $path; |
@@ -113,8 +115,7 @@ discard block |
||
| 113 | 115 | // If not, type in the DB type (model, perhaps because of the hate doing this haneungeo .. ㅡ. ㅜ) |
| 114 | 116 | $oAddonAdminController->doInsert($addon_name, $site_srl, $type); |
| 115 | 117 | // Is activated |
| 116 | - } |
|
| 117 | - else |
|
| 118 | + } else |
|
| 118 | 119 | { |
| 119 | 120 | if($inserted_addons[$addon_name]->is_used == 'Y') |
| 120 | 121 | { |
@@ -174,8 +175,7 @@ discard block |
||
| 174 | 175 | if($gtype == 'global') |
| 175 | 176 | { |
| 176 | 177 | $output = executeQuery('addon.getAddonInfo', $db_args); |
| 177 | - } |
|
| 178 | - else |
|
| 178 | + } else |
|
| 179 | 179 | { |
| 180 | 180 | $db_args->site_srl = $site_srl; |
| 181 | 181 | $output = executeQuery('addon.getSiteAddonInfo', $db_args); |
@@ -186,8 +186,7 @@ discard block |
||
| 186 | 186 | if($extra_vals->mid_list) |
| 187 | 187 | { |
| 188 | 188 | $addon_info->mid_list = $extra_vals->mid_list; |
| 189 | - } |
|
| 190 | - else |
|
| 189 | + } else |
|
| 191 | 190 | { |
| 192 | 191 | $addon_info->mid_list = array(); |
| 193 | 192 | } |
@@ -217,8 +216,7 @@ discard block |
||
| 217 | 216 | { |
| 218 | 217 | $author_list = array(); |
| 219 | 218 | $author_list[] = $xml_obj->author; |
| 220 | - } |
|
| 221 | - else |
|
| 219 | + } else |
|
| 222 | 220 | { |
| 223 | 221 | $author_list = $xml_obj->author; |
| 224 | 222 | } |
@@ -306,8 +304,7 @@ discard block |
||
| 306 | 304 | } |
| 307 | 305 | } |
| 308 | 306 | } |
| 309 | - } |
|
| 310 | - else |
|
| 307 | + } else |
|
| 311 | 308 | { |
| 312 | 309 | // addon format 0.1 |
| 313 | 310 | $addon_info = new stdClass(); |
@@ -409,8 +406,7 @@ discard block |
||
| 409 | 406 | if($gtype == 'global') |
| 410 | 407 | { |
| 411 | 408 | $output = executeQueryArray('addon.getAddons', $args); |
| 412 | - } |
|
| 413 | - else |
|
| 409 | + } else |
|
| 414 | 410 | { |
| 415 | 411 | $args->site_srl = $site_srl; |
| 416 | 412 | $output = executeQueryArray('addon.getSiteAddons', $args); |
@@ -448,20 +444,17 @@ discard block |
||
| 448 | 444 | if($type == "pc") |
| 449 | 445 | { |
| 450 | 446 | $output = executeQuery('addon.getAddonIsActivated', $args); |
| 451 | - } |
|
| 452 | - else |
|
| 447 | + } else |
|
| 453 | 448 | { |
| 454 | 449 | $output = executeQuery('addon.getMAddonIsActivated', $args); |
| 455 | 450 | } |
| 456 | - } |
|
| 457 | - else |
|
| 451 | + } else |
|
| 458 | 452 | { |
| 459 | 453 | $args->site_srl = $site_srl; |
| 460 | 454 | if($type == "pc") |
| 461 | 455 | { |
| 462 | 456 | $output = executeQuery('addon.getSiteAddonIsActivated', $args); |
| 463 | - } |
|
| 464 | - else |
|
| 457 | + } else |
|
| 465 | 458 | { |
| 466 | 459 | $output = executeQuery('addon.getSiteMAddonIsActivated', $args); |
| 467 | 460 | } |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Initilization |
| 44 | - * @return void |
|
| 44 | + * @return ModuleObject|null |
|
| 45 | 45 | */ |
| 46 | 46 | function init() |
| 47 | 47 | { |
@@ -566,7 +566,7 @@ |
||
| 566 | 566 | /** |
| 567 | 567 | * Retrun server environment to XML string |
| 568 | 568 | * @return object |
| 569 | - */ |
|
| 569 | + */ |
|
| 570 | 570 | function dispAdminViewServerEnv() |
| 571 | 571 | { |
| 572 | 572 | $info = array(); |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $db_info = Context::getDBInfo(); |
| 30 | 30 | |
| 31 | - if(strpos($db_info->default_url, 'xn--') !== FALSE) |
|
| 31 | + if (strpos($db_info->default_url, 'xn--') !== FALSE) |
|
| 32 | 32 | { |
| 33 | 33 | $xe_default_url = Context::decodeIdna($db_info->default_url); |
| 34 | 34 | } |
@@ -48,13 +48,13 @@ discard block |
||
| 48 | 48 | // forbit access if the user is not an administrator |
| 49 | 49 | $oMemberModel = getModel('member'); |
| 50 | 50 | $logged_info = $oMemberModel->getLoggedInfo(); |
| 51 | - if($logged_info->is_admin != 'Y') |
|
| 51 | + if ($logged_info->is_admin != 'Y') |
|
| 52 | 52 | { |
| 53 | 53 | return $this->stop("msg_is_not_administrator"); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // change into administration layout |
| 57 | - $this->setTemplatePath($this->module_path . 'tpl'); |
|
| 57 | + $this->setTemplatePath($this->module_path.'tpl'); |
|
| 58 | 58 | $this->setLayoutPath($this->getTemplatePath()); |
| 59 | 59 | $this->setLayoutFile('layout.html'); |
| 60 | 60 | |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | Context::set('use_db_session', $db_info->use_db_session == 'N' ? 'N' : 'Y'); |
| 75 | 75 | Context::set('use_mobile_view', $db_info->use_mobile_view == 'Y' ? 'Y' : 'N'); |
| 76 | 76 | Context::set('use_ssl', $db_info->use_ssl ? $db_info->use_ssl : "none"); |
| 77 | - if($db_info->http_port) |
|
| 77 | + if ($db_info->http_port) |
|
| 78 | 78 | { |
| 79 | 79 | Context::set('http_port', $db_info->http_port); |
| 80 | 80 | } |
| 81 | - if($db_info->https_port) |
|
| 81 | + if ($db_info->https_port) |
|
| 82 | 82 | { |
| 83 | 83 | Context::set('https_port', $db_info->https_port); |
| 84 | 84 | } |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | function checkEasyinstall() |
| 95 | 95 | { |
| 96 | 96 | $lastTime = (int) FileHandler::readFile($this->easyinstallCheckFile); |
| 97 | - if($lastTime > $_SERVER['REQUEST_TIME'] - 60 * 60 * 24 * 30) |
|
| 97 | + if ($lastTime > $_SERVER['REQUEST_TIME'] - 60 * 60 * 24 * 30) |
|
| 98 | 98 | { |
| 99 | 99 | return; |
| 100 | 100 | } |
@@ -108,14 +108,14 @@ discard block |
||
| 108 | 108 | $lUpdateDoc = $xml_lUpdate->parse($buff); |
| 109 | 109 | $updateDate = $lUpdateDoc->response->updatedate->body; |
| 110 | 110 | |
| 111 | - if(!$updateDate) |
|
| 111 | + if (!$updateDate) |
|
| 112 | 112 | { |
| 113 | 113 | $this->_markingCheckEasyinstall(); |
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | $item = $oAutoinstallModel->getLatestPackage(); |
| 118 | - if(!$item || $item->updatedate < $updateDate) |
|
| 118 | + if (!$item || $item->updatedate < $updateDate) |
|
| 119 | 119 | { |
| 120 | 120 | $oController = getAdminController('autoinstall'); |
| 121 | 121 | $oController->_updateinfo(); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | // Check is_shortcut column |
| 146 | 146 | $oDB = DB::getInstance(); |
| 147 | - if(!$oDB->isColumnExists('menu_item', 'is_shortcut')) |
|
| 147 | + if (!$oDB->isColumnExists('menu_item', 'is_shortcut')) |
|
| 148 | 148 | { |
| 149 | 149 | return; |
| 150 | 150 | } |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | $currentAct = Context::get('act'); |
| 163 | 163 | $subMenuTitle = ''; |
| 164 | 164 | |
| 165 | - foreach((array) $moduleActionInfo->menu as $key => $value) |
|
| 165 | + foreach ((array) $moduleActionInfo->menu as $key => $value) |
|
| 166 | 166 | { |
| 167 | - if(isset($value->acts) && is_array($value->acts) && in_array($currentAct, $value->acts)) |
|
| 167 | + if (isset($value->acts) && is_array($value->acts) && in_array($currentAct, $value->acts)) |
|
| 168 | 168 | { |
| 169 | 169 | $subMenuTitle = $value->title; |
| 170 | 170 | break; |
@@ -173,21 +173,21 @@ discard block |
||
| 173 | 173 | // get current menu's srl(=parentSrl) |
| 174 | 174 | $parentSrl = 0; |
| 175 | 175 | $oMenuAdminConroller = getAdminController('menu'); |
| 176 | - foreach((array) $menu->list as $parentKey => $parentMenu) |
|
| 176 | + foreach ((array) $menu->list as $parentKey => $parentMenu) |
|
| 177 | 177 | { |
| 178 | - if(!is_array($parentMenu['list']) || !count($parentMenu['list'])) |
|
| 178 | + if (!is_array($parentMenu['list']) || !count($parentMenu['list'])) |
|
| 179 | 179 | { |
| 180 | 180 | continue; |
| 181 | 181 | } |
| 182 | - if($parentMenu['href'] == '#' && count($parentMenu['list'])) |
|
| 182 | + if ($parentMenu['href'] == '#' && count($parentMenu['list'])) |
|
| 183 | 183 | { |
| 184 | 184 | $firstChild = current($parentMenu['list']); |
| 185 | 185 | $menu->list[$parentKey]['href'] = $firstChild['href']; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - foreach($parentMenu['list'] as $childKey => $childMenu) |
|
| 188 | + foreach ($parentMenu['list'] as $childKey => $childMenu) |
|
| 189 | 189 | { |
| 190 | - if($subMenuTitle == $childMenu['text'] && $parentSrl == 0) |
|
| 190 | + if ($subMenuTitle == $childMenu['text'] && $parentSrl == 0) |
|
| 191 | 191 | { |
| 192 | 192 | $parentSrl = $childMenu['parent_srl']; |
| 193 | 193 | } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | $gnbTitleInfo->adminTitle = $objConfig->adminTitle ? $objConfig->adminTitle : 'XE Admin'; |
| 201 | 201 | $gnbTitleInfo->adminLogo = $objConfig->adminLogo ? $objConfig->adminLogo : 'modules/admin/tpl/img/xe.h1.png'; |
| 202 | 202 | |
| 203 | - $browserTitle = ($subMenuTitle ? $subMenuTitle : 'Dashboard') . ' - ' . $gnbTitleInfo->adminTitle; |
|
| 203 | + $browserTitle = ($subMenuTitle ? $subMenuTitle : 'Dashboard').' - '.$gnbTitleInfo->adminTitle; |
|
| 204 | 204 | |
| 205 | 205 | // Get list of favorite |
| 206 | 206 | $oAdminAdminModel = getAdminModel('admin'); |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | // move from index method, because use in admin footer |
| 212 | 212 | $newest_news_url = sprintf("http://news.xpressengine.com/%s/news.php?version=%s&package=%s", _XE_LOCATION_, __XE_VERSION__, _XE_PACKAGE_); |
| 213 | 213 | $cache_file = sprintf("%sfiles/cache/newest_news.%s.cache.php", _XE_PATH_, _XE_LOCATION_); |
| 214 | - if(!file_exists($cache_file) || filemtime($cache_file) + 60 * 60 < $_SERVER['REQUEST_TIME']) |
|
| 214 | + if (!file_exists($cache_file) || filemtime($cache_file) + 60 * 60 < $_SERVER['REQUEST_TIME']) |
|
| 215 | 215 | { |
| 216 | 216 | // Considering if data cannot be retrieved due to network problem, modify filemtime to prevent trying to reload again when refreshing administration page |
| 217 | 217 | // Ensure to access the administration page even though news cannot be displayed |
@@ -219,20 +219,20 @@ discard block |
||
| 219 | 219 | FileHandler::getRemoteFile($newest_news_url, $cache_file, null, 1, 'GET', 'text/html', array('REQUESTURL' => getFullUrl(''))); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - if(file_exists($cache_file)) |
|
| 222 | + if (file_exists($cache_file)) |
|
| 223 | 223 | { |
| 224 | 224 | $oXml = new XmlParser(); |
| 225 | 225 | $buff = $oXml->parse(FileHandler::readFile($cache_file)); |
| 226 | 226 | |
| 227 | 227 | $item = $buff->zbxe_news->item; |
| 228 | - if($item) |
|
| 228 | + if ($item) |
|
| 229 | 229 | { |
| 230 | - if(!is_array($item)) |
|
| 230 | + if (!is_array($item)) |
|
| 231 | 231 | { |
| 232 | 232 | $item = array($item); |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - foreach($item as $key => $val) |
|
| 235 | + foreach ($item as $key => $val) |
|
| 236 | 236 | { |
| 237 | 237 | $obj = new stdClass(); |
| 238 | 238 | $obj->title = $val->body; |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | $news[] = $obj; |
| 242 | 242 | } |
| 243 | 243 | Context::set('news', $news); |
| 244 | - if(isset($news) && is_array($news)) |
|
| 244 | + if (isset($news) && is_array($news)) |
|
| 245 | 245 | { |
| 246 | 246 | Context::set('latestVersion', array_shift($news)); |
| 247 | 247 | } |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | function dispAdminIndex() |
| 265 | 265 | { |
| 266 | 266 | $db_info = Context::getDBInfo(); |
| 267 | - Context::set('db_info',$db_info); |
|
| 267 | + Context::set('db_info', $db_info); |
|
| 268 | 268 | |
| 269 | 269 | // Get statistics |
| 270 | 270 | $args = new stdClass(); |
@@ -301,9 +301,9 @@ discard block |
||
| 301 | 301 | $args = new stdClass(); |
| 302 | 302 | $args->list_count = 5; |
| 303 | 303 | $output = $oCommentModel->getNewestCommentList($args, $columnList); |
| 304 | - if(is_array($output)) |
|
| 304 | + if (is_array($output)) |
|
| 305 | 305 | { |
| 306 | - foreach($output AS $key => $value) |
|
| 306 | + foreach ($output AS $key => $value) |
|
| 307 | 307 | { |
| 308 | 308 | $value->content = strip_tags($value->content); |
| 309 | 309 | } |
@@ -314,17 +314,17 @@ discard block |
||
| 314 | 314 | // Get list of modules |
| 315 | 315 | $oModuleModel = getModel('module'); |
| 316 | 316 | $module_list = $oModuleModel->getModuleList(); |
| 317 | - if(is_array($module_list)) |
|
| 317 | + if (is_array($module_list)) |
|
| 318 | 318 | { |
| 319 | 319 | $needUpdate = FALSE; |
| 320 | 320 | $addTables = FALSE; |
| 321 | - foreach($module_list AS $key => $value) |
|
| 321 | + foreach ($module_list AS $key => $value) |
|
| 322 | 322 | { |
| 323 | - if($value->need_install) |
|
| 323 | + if ($value->need_install) |
|
| 324 | 324 | { |
| 325 | 325 | $addTables = TRUE; |
| 326 | 326 | } |
| 327 | - if($value->need_update) |
|
| 327 | + if ($value->need_update) |
|
| 328 | 328 | { |
| 329 | 329 | $needUpdate = TRUE; |
| 330 | 330 | } |
@@ -335,12 +335,12 @@ discard block |
||
| 335 | 335 | $oAutoinstallAdminModel = getAdminModel('autoinstall'); |
| 336 | 336 | $needUpdateList = $oAutoinstallAdminModel->getNeedUpdateList(); |
| 337 | 337 | |
| 338 | - if(is_array($needUpdateList)) |
|
| 338 | + if (is_array($needUpdateList)) |
|
| 339 | 339 | { |
| 340 | - foreach($needUpdateList AS $key => $value) |
|
| 340 | + foreach ($needUpdateList AS $key => $value) |
|
| 341 | 341 | { |
| 342 | 342 | $helpUrl = './admin/help/index.html#'; |
| 343 | - switch($value->type) |
|
| 343 | + switch ($value->type) |
|
| 344 | 344 | { |
| 345 | 345 | case 'addon': |
| 346 | 346 | $helpUrl .= 'UMAN_terminology_addon'; |
@@ -367,8 +367,8 @@ discard block |
||
| 367 | 367 | |
| 368 | 368 | $site_module_info = Context::get('site_module_info'); |
| 369 | 369 | $oAddonAdminModel = getAdminModel('addon'); |
| 370 | - $counterAddonActivated = $oAddonAdminModel->isActivatedAddon('counter', $site_module_info->site_srl ); |
|
| 371 | - if(!$counterAddonActivated) |
|
| 370 | + $counterAddonActivated = $oAddonAdminModel->isActivatedAddon('counter', $site_module_info->site_srl); |
|
| 371 | + if (!$counterAddonActivated) |
|
| 372 | 372 | { |
| 373 | 373 | $columnList = array('member_srl', 'nick_name', 'user_name', 'user_id', 'email_address'); |
| 374 | 374 | $args = new stdClass; |
@@ -391,9 +391,9 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | // gathering enviroment check |
| 393 | 393 | $mainVersion = join('.', array_slice(explode('.', __XE_VERSION__), 0, 2)); |
| 394 | - $path = FileHandler::getRealPath('./files/env/' . $mainVersion); |
|
| 394 | + $path = FileHandler::getRealPath('./files/env/'.$mainVersion); |
|
| 395 | 395 | $isEnviromentGatheringAgreement = FALSE; |
| 396 | - if(file_exists($path)) |
|
| 396 | + if (file_exists($path)) |
|
| 397 | 397 | { |
| 398 | 398 | $isEnviromentGatheringAgreement = TRUE; |
| 399 | 399 | } |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | $isLicenseAgreement = FALSE; |
| 404 | 404 | $path = FileHandler::getRealPath('./files/env/license_agreement'); |
| 405 | 405 | $isLicenseAgreement = FALSE; |
| 406 | - if(file_exists($path)) |
|
| 406 | + if (file_exists($path)) |
|
| 407 | 407 | { |
| 408 | 408 | $isLicenseAgreement = TRUE; |
| 409 | 409 | } |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | |
| 426 | 426 | Context::set('selected_lang', $db_info->lang_type); |
| 427 | 427 | |
| 428 | - if(strpos($db_info->default_url, 'xn--') !== FALSE) |
|
| 428 | + if (strpos($db_info->default_url, 'xn--') !== FALSE) |
|
| 429 | 429 | { |
| 430 | 430 | $db_info->default_url = Context::decodeIdna($db_info->default_url); |
| 431 | 431 | } |
@@ -434,9 +434,9 @@ discard block |
||
| 434 | 434 | |
| 435 | 435 | // site lock |
| 436 | 436 | Context::set('IP', $_SERVER['REMOTE_ADDR']); |
| 437 | - if(!$db_info->sitelock_title) $db_info->sitelock_title = 'Maintenance in progress...'; |
|
| 438 | - if(!in_array('127.0.0.1', $db_info->sitelock_whitelist)) $db_info->sitelock_whitelist[] = '127.0.0.1'; |
|
| 439 | - if(!in_array($_SERVER['REMOTE_ADDR'], $db_info->sitelock_whitelist)) $db_info->sitelock_whitelist[] = $_SERVER['REMOTE_ADDR']; |
|
| 437 | + if (!$db_info->sitelock_title) $db_info->sitelock_title = 'Maintenance in progress...'; |
|
| 438 | + if (!in_array('127.0.0.1', $db_info->sitelock_whitelist)) $db_info->sitelock_whitelist[] = '127.0.0.1'; |
|
| 439 | + if (!in_array($_SERVER['REMOTE_ADDR'], $db_info->sitelock_whitelist)) $db_info->sitelock_whitelist[] = $_SERVER['REMOTE_ADDR']; |
|
| 440 | 440 | $db_info->sitelock_whitelist = array_unique($db_info->sitelock_whitelist); |
| 441 | 441 | Context::set('remote_addr', $_SERVER['REMOTE_ADDR']); |
| 442 | 442 | Context::set('use_sitelock', $db_info->use_sitelock); |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | Context::set('sitelock_whitelist', $whitelist); |
| 448 | 448 | |
| 449 | 449 | |
| 450 | - if($db_info->admin_ip_list) $admin_ip_list = implode("\r\n", $db_info->admin_ip_list); |
|
| 450 | + if ($db_info->admin_ip_list) $admin_ip_list = implode("\r\n", $db_info->admin_ip_list); |
|
| 451 | 451 | else $admin_ip_list = ''; |
| 452 | 452 | Context::set('admin_ip_list', $admin_ip_list); |
| 453 | 453 | |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | Context::set('htmlFooter', htmlspecialchars($config->htmlFooter)); |
| 471 | 471 | |
| 472 | 472 | // embed filter |
| 473 | - require_once(_XE_PATH_ . 'classes/security/EmbedFilter.class.php'); |
|
| 473 | + require_once(_XE_PATH_.'classes/security/EmbedFilter.class.php'); |
|
| 474 | 474 | $oEmbedFilter = EmbedFilter::getInstance(); |
| 475 | 475 | context::set('embed_white_object', implode(PHP_EOL, $oEmbedFilter->whiteUrlList)); |
| 476 | 476 | context::set('embed_white_iframe', implode(PHP_EOL, $oEmbedFilter->whiteIframeUrlList)); |
@@ -529,36 +529,36 @@ discard block |
||
| 529 | 529 | */ |
| 530 | 530 | function showSendEnv() |
| 531 | 531 | { |
| 532 | - if(Context::getResponseMethod() != 'HTML') |
|
| 532 | + if (Context::getResponseMethod() != 'HTML') |
|
| 533 | 533 | { |
| 534 | 534 | return; |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | $server = 'http://collect.xpressengine.com/env/img.php?'; |
| 538 | 538 | $path = './files/env/'; |
| 539 | - $install_env = $path . 'install'; |
|
| 539 | + $install_env = $path.'install'; |
|
| 540 | 540 | $mainVersion = join('.', array_slice(explode('.', __XE_VERSION__), 0, 2)); |
| 541 | 541 | |
| 542 | - if(file_exists(FileHandler::getRealPath($install_env))) |
|
| 542 | + if (file_exists(FileHandler::getRealPath($install_env))) |
|
| 543 | 543 | { |
| 544 | 544 | $oAdminAdminModel = getAdminModel('admin'); |
| 545 | 545 | $params = $oAdminAdminModel->getEnv('INSTALL'); |
| 546 | - $img = sprintf('<img src="%s" alt="" style="height:0px;width:0px" />', $server . $params); |
|
| 546 | + $img = sprintf('<img src="%s" alt="" style="height:0px;width:0px" />', $server.$params); |
|
| 547 | 547 | Context::addHtmlFooter($img); |
| 548 | 548 | |
| 549 | - FileHandler::writeFile($path . $mainVersion, '1'); |
|
| 549 | + FileHandler::writeFile($path.$mainVersion, '1'); |
|
| 550 | 550 | } |
| 551 | - else if(isset($_SESSION['enviroment_gather']) && !file_exists(FileHandler::getRealPath($path . $mainVersion))) |
|
| 551 | + else if (isset($_SESSION['enviroment_gather']) && !file_exists(FileHandler::getRealPath($path.$mainVersion))) |
|
| 552 | 552 | { |
| 553 | - if($_SESSION['enviroment_gather'] == 'Y') |
|
| 553 | + if ($_SESSION['enviroment_gather'] == 'Y') |
|
| 554 | 554 | { |
| 555 | 555 | $oAdminAdminModel = getAdminModel('admin'); |
| 556 | 556 | $params = $oAdminAdminModel->getEnv(); |
| 557 | - $img = sprintf('<img src="%s" alt="" style="height:0px;width:0px" />', $server . $params); |
|
| 557 | + $img = sprintf('<img src="%s" alt="" style="height:0px;width:0px" />', $server.$params); |
|
| 558 | 558 | Context::addHtmlFooter($img); |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - FileHandler::writeFile($path . $mainVersion, '1'); |
|
| 561 | + FileHandler::writeFile($path.$mainVersion, '1'); |
|
| 562 | 562 | unset($_SESSION['enviroment_gather']); |
| 563 | 563 | } |
| 564 | 564 | } |
@@ -576,64 +576,64 @@ discard block |
||
| 576 | 576 | $tmp = explode("&", $envInfo); |
| 577 | 577 | $arrInfo = array(); |
| 578 | 578 | $xe_check_env = array(); |
| 579 | - foreach($tmp as $value) { |
|
| 579 | + foreach ($tmp as $value) { |
|
| 580 | 580 | $arr = explode("=", $value); |
| 581 | - if($arr[0]=="type") { |
|
| 581 | + if ($arr[0] == "type") { |
|
| 582 | 582 | continue; |
| 583 | - }elseif($arr[0]=="phpext" ) { |
|
| 583 | + }elseif ($arr[0] == "phpext") { |
|
| 584 | 584 | $str = urldecode($arr[1]); |
| 585 | - $xe_check_env[$arr[0]]= str_replace("|", ", ", $str); |
|
| 586 | - } elseif($arr[0]=="module" ) { |
|
| 585 | + $xe_check_env[$arr[0]] = str_replace("|", ", ", $str); |
|
| 586 | + } elseif ($arr[0] == "module") { |
|
| 587 | 587 | $str = urldecode($arr[1]); |
| 588 | 588 | $arrModuleName = explode("|", $str); |
| 589 | 589 | $oModuleModel = getModel("module"); |
| 590 | 590 | $mInfo = array(); |
| 591 | - foreach($arrModuleName as $moduleName) { |
|
| 591 | + foreach ($arrModuleName as $moduleName) { |
|
| 592 | 592 | $moduleInfo = $oModuleModel->getModuleInfoXml($moduleName); |
| 593 | 593 | $mInfo[] = "{$moduleName}({$moduleInfo->version})"; |
| 594 | 594 | } |
| 595 | - $xe_check_env[$arr[0]]= join(", ", $mInfo); |
|
| 596 | - } elseif($arr[0]=="addon") { |
|
| 595 | + $xe_check_env[$arr[0]] = join(", ", $mInfo); |
|
| 596 | + } elseif ($arr[0] == "addon") { |
|
| 597 | 597 | $str = urldecode($arr[1]); |
| 598 | 598 | $arrAddonName = explode("|", $str); |
| 599 | 599 | $oAddonModel = getAdminModel("addon"); |
| 600 | 600 | $mInfo = array(); |
| 601 | - foreach($arrAddonName as $addonName) { |
|
| 601 | + foreach ($arrAddonName as $addonName) { |
|
| 602 | 602 | $addonInfo = $oAddonModel->getAddonInfoXml($addonName); |
| 603 | 603 | $mInfo[] = "{$addonName}({$addonInfo->version})"; |
| 604 | 604 | } |
| 605 | - $xe_check_env[$arr[0]]= join(", ", $mInfo); |
|
| 606 | - } elseif($arr[0]=="widget") { |
|
| 605 | + $xe_check_env[$arr[0]] = join(", ", $mInfo); |
|
| 606 | + } elseif ($arr[0] == "widget") { |
|
| 607 | 607 | $str = urldecode($arr[1]); |
| 608 | 608 | $arrWidgetName = explode("|", $str); |
| 609 | 609 | $oWidgetModel = getModel("widget"); |
| 610 | 610 | $mInfo = array(); |
| 611 | - foreach($arrWidgetName as $widgetName) { |
|
| 611 | + foreach ($arrWidgetName as $widgetName) { |
|
| 612 | 612 | $widgetInfo = $oWidgetModel->getWidgetInfo($widgetName); |
| 613 | 613 | $mInfo[] = "{$widgetName}({$widgetInfo->version})"; |
| 614 | 614 | } |
| 615 | - $xe_check_env[$arr[0]]= join(", ", $mInfo); |
|
| 616 | - } elseif($arr[0]=="widgetstyle") { |
|
| 615 | + $xe_check_env[$arr[0]] = join(", ", $mInfo); |
|
| 616 | + } elseif ($arr[0] == "widgetstyle") { |
|
| 617 | 617 | $str = urldecode($arr[1]); |
| 618 | 618 | $arrWidgetstyleName = explode("|", $str); |
| 619 | 619 | $oWidgetModel = getModel("widget"); |
| 620 | 620 | $mInfo = array(); |
| 621 | - foreach($arrWidgetstyleName as $widgetstyleName) { |
|
| 621 | + foreach ($arrWidgetstyleName as $widgetstyleName) { |
|
| 622 | 622 | $widgetstyleInfo = $oWidgetModel->getWidgetStyleInfo($widgetstyleName); |
| 623 | 623 | $mInfo[] = "{$widgetstyleName}({$widgetstyleInfo->version})"; |
| 624 | 624 | } |
| 625 | - $xe_check_env[$arr[0]]= join(", ", $mInfo); |
|
| 625 | + $xe_check_env[$arr[0]] = join(", ", $mInfo); |
|
| 626 | 626 | |
| 627 | - } elseif($arr[0]=="layout") { |
|
| 627 | + } elseif ($arr[0] == "layout") { |
|
| 628 | 628 | $str = urldecode($arr[1]); |
| 629 | 629 | $arrLayoutName = explode("|", $str); |
| 630 | 630 | $oLayoutModel = getModel("layout"); |
| 631 | 631 | $mInfo = array(); |
| 632 | - foreach($arrLayoutName as $layoutName) { |
|
| 632 | + foreach ($arrLayoutName as $layoutName) { |
|
| 633 | 633 | $layoutInfo = $oLayoutModel->getLayoutInfo($layoutName); |
| 634 | 634 | $mInfo[] = "{$layoutName}({$layoutInfo->version})"; |
| 635 | 635 | } |
| 636 | - $xe_check_env[$arr[0]]= join(", ", $mInfo); |
|
| 636 | + $xe_check_env[$arr[0]] = join(", ", $mInfo); |
|
| 637 | 637 | } else { |
| 638 | 638 | $xe_check_env[$arr[0]] = urldecode($arr[1]); |
| 639 | 639 | } |
@@ -647,15 +647,15 @@ discard block |
||
| 647 | 647 | $php_core['memory_limit'] = "{$ini_info['memory_limit']['local_value']}"; |
| 648 | 648 | $info['PHP_Core'] = $php_core; |
| 649 | 649 | |
| 650 | - $str_info = "[XE Server Environment " . date("Y-m-d") . "]\n\n"; |
|
| 650 | + $str_info = "[XE Server Environment ".date("Y-m-d")."]\n\n"; |
|
| 651 | 651 | $str_info .= "realpath : ".realpath('./')."\n"; |
| 652 | - foreach( $info as $key=>$value ) |
|
| 652 | + foreach ($info as $key=>$value) |
|
| 653 | 653 | { |
| 654 | - if( is_array( $value ) == false ) { |
|
| 654 | + if (is_array($value) == false) { |
|
| 655 | 655 | $str_info .= "{$key} : {$value}\n"; |
| 656 | 656 | } else { |
| 657 | 657 | //$str_info .= "\n{$key} \n"; |
| 658 | - foreach( $value as $key2=>$value2 ) |
|
| 658 | + foreach ($value as $key2=>$value2) |
|
| 659 | 659 | $str_info .= "{$key2} : {$value2}\n"; |
| 660 | 660 | } |
| 661 | 661 | } |
@@ -672,7 +672,7 @@ discard block |
||
| 672 | 672 | Context::set('use_rewrite', $useRewrite); |
| 673 | 673 | |
| 674 | 674 | // nginx 체크, rewrite 사용법 안내 |
| 675 | - if($useRewrite == 'N' && stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false) Context::set('use_nginx', 'Y'); |
|
| 675 | + if ($useRewrite == 'N' && stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false) Context::set('use_nginx', 'Y'); |
|
| 676 | 676 | |
| 677 | 677 | Context::set('useable', $oInstallController->checkInstallEnv()); |
| 678 | 678 | $this->setTemplateFile('check_env.html'); |
@@ -31,8 +31,7 @@ discard block |
||
| 31 | 31 | if(strpos($db_info->default_url, 'xn--') !== FALSE) |
| 32 | 32 | { |
| 33 | 33 | $xe_default_url = Context::decodeIdna($db_info->default_url); |
| 34 | - } |
|
| 35 | - else |
|
| 34 | + } else |
|
| 36 | 35 | { |
| 37 | 36 | $xe_default_url = $db_info->default_url; |
| 38 | 37 | } |
@@ -434,9 +433,15 @@ discard block |
||
| 434 | 433 | |
| 435 | 434 | // site lock |
| 436 | 435 | Context::set('IP', $_SERVER['REMOTE_ADDR']); |
| 437 | - if(!$db_info->sitelock_title) $db_info->sitelock_title = 'Maintenance in progress...'; |
|
| 438 | - if(!in_array('127.0.0.1', $db_info->sitelock_whitelist)) $db_info->sitelock_whitelist[] = '127.0.0.1'; |
|
| 439 | - if(!in_array($_SERVER['REMOTE_ADDR'], $db_info->sitelock_whitelist)) $db_info->sitelock_whitelist[] = $_SERVER['REMOTE_ADDR']; |
|
| 436 | + if(!$db_info->sitelock_title) { |
|
| 437 | + $db_info->sitelock_title = 'Maintenance in progress...'; |
|
| 438 | + } |
|
| 439 | + if(!in_array('127.0.0.1', $db_info->sitelock_whitelist)) { |
|
| 440 | + $db_info->sitelock_whitelist[] = '127.0.0.1'; |
|
| 441 | + } |
|
| 442 | + if(!in_array($_SERVER['REMOTE_ADDR'], $db_info->sitelock_whitelist)) { |
|
| 443 | + $db_info->sitelock_whitelist[] = $_SERVER['REMOTE_ADDR']; |
|
| 444 | + } |
|
| 440 | 445 | $db_info->sitelock_whitelist = array_unique($db_info->sitelock_whitelist); |
| 441 | 446 | Context::set('remote_addr', $_SERVER['REMOTE_ADDR']); |
| 442 | 447 | Context::set('use_sitelock', $db_info->use_sitelock); |
@@ -447,8 +452,11 @@ discard block |
||
| 447 | 452 | Context::set('sitelock_whitelist', $whitelist); |
| 448 | 453 | |
| 449 | 454 | |
| 450 | - if($db_info->admin_ip_list) $admin_ip_list = implode("\r\n", $db_info->admin_ip_list); |
|
| 451 | - else $admin_ip_list = ''; |
|
| 455 | + if($db_info->admin_ip_list) { |
|
| 456 | + $admin_ip_list = implode("\r\n", $db_info->admin_ip_list); |
|
| 457 | + } else { |
|
| 458 | + $admin_ip_list = ''; |
|
| 459 | + } |
|
| 452 | 460 | Context::set('admin_ip_list', $admin_ip_list); |
| 453 | 461 | |
| 454 | 462 | Context::set('lang_selected', Context::loadLangSelected()); |
@@ -547,8 +555,7 @@ discard block |
||
| 547 | 555 | Context::addHtmlFooter($img); |
| 548 | 556 | |
| 549 | 557 | FileHandler::writeFile($path . $mainVersion, '1'); |
| 550 | - } |
|
| 551 | - else if(isset($_SESSION['enviroment_gather']) && !file_exists(FileHandler::getRealPath($path . $mainVersion))) |
|
| 558 | + } else if(isset($_SESSION['enviroment_gather']) && !file_exists(FileHandler::getRealPath($path . $mainVersion))) |
|
| 552 | 559 | { |
| 553 | 560 | if($_SESSION['enviroment_gather'] == 'Y') |
| 554 | 561 | { |
@@ -580,7 +587,7 @@ discard block |
||
| 580 | 587 | $arr = explode("=", $value); |
| 581 | 588 | if($arr[0]=="type") { |
| 582 | 589 | continue; |
| 583 | - }elseif($arr[0]=="phpext" ) { |
|
| 590 | + } elseif($arr[0]=="phpext" ) { |
|
| 584 | 591 | $str = urldecode($arr[1]); |
| 585 | 592 | $xe_check_env[$arr[0]]= str_replace("|", ", ", $str); |
| 586 | 593 | } elseif($arr[0]=="module" ) { |
@@ -655,8 +662,9 @@ discard block |
||
| 655 | 662 | $str_info .= "{$key} : {$value}\n"; |
| 656 | 663 | } else { |
| 657 | 664 | //$str_info .= "\n{$key} \n"; |
| 658 | - foreach( $value as $key2=>$value2 ) |
|
| 659 | - $str_info .= "{$key2} : {$value2}\n"; |
|
| 665 | + foreach( $value as $key2=>$value2 ) { |
|
| 666 | + $str_info .= "{$key2} : {$value2}\n"; |
|
| 667 | + } |
|
| 660 | 668 | } |
| 661 | 669 | } |
| 662 | 670 | |
@@ -672,7 +680,9 @@ discard block |
||
| 672 | 680 | Context::set('use_rewrite', $useRewrite); |
| 673 | 681 | |
| 674 | 682 | // nginx 체크, rewrite 사용법 안내 |
| 675 | - if($useRewrite == 'N' && stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false) Context::set('use_nginx', 'Y'); |
|
| 683 | + if($useRewrite == 'N' && stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false) { |
|
| 684 | + Context::set('use_nginx', 'Y'); |
|
| 685 | + } |
|
| 676 | 686 | |
| 677 | 687 | Context::set('useable', $oInstallController->checkInstallEnv()); |
| 678 | 688 | $this->setTemplateFile('check_env.html'); |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * Initialization |
| 17 | - * @return void |
|
| 17 | + * @return ModuleObject|null |
|
| 18 | 18 | */ |
| 19 | 19 | function init() |
| 20 | 20 | { |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | // forbit access if the user is not an administrator |
| 22 | 22 | $oMemberModel = getModel('member'); |
| 23 | 23 | $logged_info = $oMemberModel->getLoggedInfo(); |
| 24 | - if($logged_info->is_admin != 'Y') |
|
| 24 | + if ($logged_info->is_admin != 'Y') |
|
| 25 | 25 | { |
| 26 | 26 | return $this->stop("msg_is_not_administrator"); |
| 27 | 27 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function insertLog($module, $act) |
| 35 | 35 | { |
| 36 | - if(!$module || !$act) |
|
| 36 | + if (!$module || !$act) |
|
| 37 | 37 | { |
| 38 | 38 | return; |
| 39 | 39 | } |
@@ -15,6 +15,9 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * Pre process parameters |
| 18 | + * @param string $order_target |
|
| 19 | + * @param string $order_type |
|
| 20 | + * @param string $page |
|
| 18 | 21 | */ |
| 19 | 22 | function preProcParam(&$order_target, &$order_type, &$page) |
| 20 | 23 | { |
@@ -115,6 +118,10 @@ discard block |
||
| 115 | 118 | |
| 116 | 119 | /** |
| 117 | 120 | * Get Package List |
| 121 | + * @param string $type |
|
| 122 | + * @param string $search_keyword |
|
| 123 | + * @param integer $category_srl |
|
| 124 | + * @param string $parent_program |
|
| 118 | 125 | */ |
| 119 | 126 | function getPackageList($type, $order_target = 'newest', $order_type = 'desc', $page = '1', $search_keyword = NULL, $category_srl = NULL, $parent_program = NULL) |
| 120 | 127 | { |
@@ -71,8 +71,7 @@ discard block |
||
| 71 | 71 | if($type == 'P') |
| 72 | 72 | { |
| 73 | 73 | $category_srl = $this->layout_category_srl; |
| 74 | - } |
|
| 75 | - else |
|
| 74 | + } else |
|
| 76 | 75 | { |
| 77 | 76 | $category_srl = $this->mobile_layout_category_srl; |
| 78 | 77 | } |
@@ -103,8 +102,7 @@ discard block |
||
| 103 | 102 | if($type == 'P') |
| 104 | 103 | { |
| 105 | 104 | $category_srl = $this->module_skin_category_srl; |
| 106 | - } |
|
| 107 | - else |
|
| 105 | + } else |
|
| 108 | 106 | { |
| 109 | 107 | $category_srl = $this->module_mobile_skin_category_srl; |
| 110 | 108 | } |
@@ -121,13 +119,11 @@ discard block |
||
| 121 | 119 | if($type == 'menu') |
| 122 | 120 | { |
| 123 | 121 | $params["act"] = "getResourceapiMenuPackageList"; |
| 124 | - } |
|
| 125 | - elseif($type == 'skin') |
|
| 122 | + } elseif($type == 'skin') |
|
| 126 | 123 | { |
| 127 | 124 | $params["act"] = "getResourceapiSkinPackageList"; |
| 128 | 125 | $params['parent_program'] = $parent_program; |
| 129 | - } |
|
| 130 | - else |
|
| 126 | + } else |
|
| 131 | 127 | { |
| 132 | 128 | $params["act"] = "getResourceapiPackagelist"; |
| 133 | 129 | } |
@@ -172,15 +168,13 @@ discard block |
||
| 172 | 168 | if($output->toBool()==TRUE) |
| 173 | 169 | { |
| 174 | 170 | $is_authed = 1; |
| 175 | - } |
|
| 176 | - else |
|
| 171 | + } else |
|
| 177 | 172 | { |
| 178 | 173 | $ftp_info = Context::getFTPInfo(); |
| 179 | 174 | if(!$ftp_info->ftp_root_path) |
| 180 | 175 | { |
| 181 | 176 | $is_authed = -1; |
| 182 | - } |
|
| 183 | - else |
|
| 177 | + } else |
|
| 184 | 178 | { |
| 185 | 179 | $is_authed = (int) isset($_SESSION['ftp_password']); |
| 186 | 180 | } |
@@ -216,8 +210,7 @@ discard block |
||
| 216 | 210 | if($packageInfo->type == 'core') |
| 217 | 211 | { |
| 218 | 212 | $title = 'XpressEngine'; |
| 219 | - } |
|
| 220 | - else |
|
| 213 | + } else |
|
| 221 | 214 | { |
| 222 | 215 | $configFile = $oModel->getConfigFilePath($packageInfo->type); |
| 223 | 216 | $xmlDoc = $xml->loadXmlFile(FileHandler::getRealPath($package->path) . $configFile); |
@@ -238,8 +231,7 @@ discard block |
||
| 238 | 231 | $type = "layout"; |
| 239 | 232 | } |
| 240 | 233 | $title = $xmlDoc->{$type}->title->body; |
| 241 | - } |
|
| 242 | - else |
|
| 234 | + } else |
|
| 243 | 235 | { |
| 244 | 236 | $pathInfo = explode('/', $package->path); |
| 245 | 237 | $title = $pathInfo[count($pathInfo) - 1]; |
@@ -303,8 +295,7 @@ discard block |
||
| 303 | 295 | { |
| 304 | 296 | $package->depends[$key]->installed = FALSE; |
| 305 | 297 | $package->package_srl .= "," . $dep->package_srl; |
| 306 | - } |
|
| 307 | - else |
|
| 298 | + } else |
|
| 308 | 299 | { |
| 309 | 300 | $package->depends[$key]->installed = TRUE; |
| 310 | 301 | $package->depends[$key]->cur_version = $packages[$dep->package_srl]->current_version; |
@@ -318,8 +309,7 @@ discard block |
||
| 318 | 309 | $package->contain_core = TRUE; |
| 319 | 310 | $package->contain_core_version = $dep->version; |
| 320 | 311 | } |
| 321 | - } |
|
| 322 | - else |
|
| 312 | + } else |
|
| 323 | 313 | { |
| 324 | 314 | $package->need_update = FALSE; |
| 325 | 315 | } |
@@ -19,19 +19,19 @@ discard block |
||
| 19 | 19 | function preProcParam(&$order_target, &$order_type, &$page) |
| 20 | 20 | { |
| 21 | 21 | $order_target_array = array('newest' => 1, 'download' => 1, 'popular' => 1); |
| 22 | - if(!isset($order_target_array[$order_target])) |
|
| 22 | + if (!isset($order_target_array[$order_target])) |
|
| 23 | 23 | { |
| 24 | 24 | $order_target = 'newest'; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | $order_type_array = array('asc' => 1, 'desc' => 1); |
| 28 | - if(!isset($order_type_array[$order_type])) |
|
| 28 | + if (!isset($order_type_array[$order_type])) |
|
| 29 | 29 | { |
| 30 | 30 | $order_type = 'desc'; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | $page = (int) $page; |
| 34 | - if($page < 1) |
|
| 34 | + if ($page < 1) |
|
| 35 | 35 | { |
| 36 | 36 | $page = 1; |
| 37 | 37 | } |
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | $type_array = array('M' => 1, 'P' => 1); |
| 65 | 65 | $type = Context::get('type'); |
| 66 | - if(!isset($type_array[$type])) |
|
| 66 | + if (!isset($type_array[$type])) |
|
| 67 | 67 | { |
| 68 | 68 | $type = 'P'; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if($type == 'P') |
|
| 71 | + if ($type == 'P') |
|
| 72 | 72 | { |
| 73 | 73 | $category_srl = $this->layout_category_srl; |
| 74 | 74 | } |
@@ -95,12 +95,12 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | $type_array = array('M' => 1, 'P' => 1); |
| 97 | 97 | $type = Context::get('type'); |
| 98 | - if(!isset($type_array[$type])) |
|
| 98 | + if (!isset($type_array[$type])) |
|
| 99 | 99 | { |
| 100 | 100 | $type = 'P'; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - if($type == 'P') |
|
| 103 | + if ($type == 'P') |
|
| 104 | 104 | { |
| 105 | 105 | $category_srl = $this->module_skin_category_srl; |
| 106 | 106 | } |
@@ -118,11 +118,11 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | function getPackageList($type, $order_target = 'newest', $order_type = 'desc', $page = '1', $search_keyword = NULL, $category_srl = NULL, $parent_program = NULL) |
| 120 | 120 | { |
| 121 | - if($type == 'menu') |
|
| 121 | + if ($type == 'menu') |
|
| 122 | 122 | { |
| 123 | 123 | $params["act"] = "getResourceapiMenuPackageList"; |
| 124 | 124 | } |
| 125 | - elseif($type == 'skin') |
|
| 125 | + elseif ($type == 'skin') |
|
| 126 | 126 | { |
| 127 | 127 | $params["act"] = "getResourceapiSkinPackageList"; |
| 128 | 128 | $params['parent_program'] = $parent_program; |
@@ -137,18 +137,18 @@ discard block |
||
| 137 | 137 | $params["order_type"] = $order_type; |
| 138 | 138 | $params["page"] = $page; |
| 139 | 139 | |
| 140 | - if($category_srl) |
|
| 140 | + if ($category_srl) |
|
| 141 | 141 | { |
| 142 | 142 | $params["category_srl"] = $category_srl; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - if($search_keyword) |
|
| 145 | + if ($search_keyword) |
|
| 146 | 146 | { |
| 147 | 147 | $params["search_keyword"] = $search_keyword; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | $xmlDoc = XmlGenerater::getXmlDoc($params); |
| 151 | - if($xmlDoc && $xmlDoc->response->packagelist->item) |
|
| 151 | + if ($xmlDoc && $xmlDoc->response->packagelist->item) |
|
| 152 | 152 | { |
| 153 | 153 | $item_list = $oAdminView->rearranges($xmlDoc->response->packagelist->item); |
| 154 | 154 | $this->add('item_list', $item_list); |
@@ -169,14 +169,14 @@ discard block |
||
| 169 | 169 | |
| 170 | 170 | $is_authed = 0; |
| 171 | 171 | $output = $oAdminModel->checkUseDirectModuleInstall($package); |
| 172 | - if($output->toBool()==TRUE) |
|
| 172 | + if ($output->toBool() == TRUE) |
|
| 173 | 173 | { |
| 174 | 174 | $is_authed = 1; |
| 175 | 175 | } |
| 176 | 176 | else |
| 177 | 177 | { |
| 178 | 178 | $ftp_info = Context::getFTPInfo(); |
| 179 | - if(!$ftp_info->ftp_root_path) |
|
| 179 | + if (!$ftp_info->ftp_root_path) |
|
| 180 | 180 | { |
| 181 | 181 | $is_authed = -1; |
| 182 | 182 | } |
@@ -196,14 +196,14 @@ discard block |
||
| 196 | 196 | { |
| 197 | 197 | $oModel = getModel('autoinstall'); |
| 198 | 198 | $output = executeQueryArray('autoinstall.getNeedUpdate'); |
| 199 | - if(!is_array($output->data)) |
|
| 199 | + if (!is_array($output->data)) |
|
| 200 | 200 | { |
| 201 | 201 | return NULL; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | $result = array(); |
| 205 | 205 | $xml = new XmlParser(); |
| 206 | - foreach($output->data as $package) |
|
| 206 | + foreach ($output->data as $package) |
|
| 207 | 207 | { |
| 208 | 208 | $packageSrl = $package->package_srl; |
| 209 | 209 | |
@@ -213,27 +213,27 @@ discard block |
||
| 213 | 213 | $packageInfo->type = $oModel->getTypeFromPath($package->path); |
| 214 | 214 | $packageInfo->url = $oModel->getUpdateUrlByPackageSrl($package->package_srl); |
| 215 | 215 | |
| 216 | - if($packageInfo->type == 'core') |
|
| 216 | + if ($packageInfo->type == 'core') |
|
| 217 | 217 | { |
| 218 | 218 | $title = 'XpressEngine'; |
| 219 | 219 | } |
| 220 | 220 | else |
| 221 | 221 | { |
| 222 | 222 | $configFile = $oModel->getConfigFilePath($packageInfo->type); |
| 223 | - $xmlDoc = $xml->loadXmlFile(FileHandler::getRealPath($package->path) . $configFile); |
|
| 223 | + $xmlDoc = $xml->loadXmlFile(FileHandler::getRealPath($package->path).$configFile); |
|
| 224 | 224 | |
| 225 | - if($xmlDoc) |
|
| 225 | + if ($xmlDoc) |
|
| 226 | 226 | { |
| 227 | 227 | $type = $packageInfo->type; |
| 228 | - if($type == "drcomponent") |
|
| 228 | + if ($type == "drcomponent") |
|
| 229 | 229 | { |
| 230 | 230 | $type = "component"; |
| 231 | 231 | } |
| 232 | - if($type == "style" || $type == "m.skin") |
|
| 232 | + if ($type == "style" || $type == "m.skin") |
|
| 233 | 233 | { |
| 234 | 234 | $type = "skin"; |
| 235 | 235 | } |
| 236 | - if($type == "m.layout") |
|
| 236 | + if ($type == "m.layout") |
|
| 237 | 237 | { |
| 238 | 238 | $type = "layout"; |
| 239 | 239 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | $oModel = getModel('autoinstall'); |
| 268 | 268 | |
| 269 | 269 | $targetpackages = array(); |
| 270 | - if($xmlDoc) |
|
| 270 | + if ($xmlDoc) |
|
| 271 | 271 | { |
| 272 | 272 | $xmlPackage = $xmlDoc->response->package; |
| 273 | 273 | $package = new stdClass(); |
@@ -276,15 +276,15 @@ discard block |
||
| 276 | 276 | $package->package_description = $xmlPackage->package_description->body; |
| 277 | 277 | $package->version = $xmlPackage->version->body; |
| 278 | 278 | $package->path = $xmlPackage->path->body; |
| 279 | - if($xmlPackage->depends) |
|
| 279 | + if ($xmlPackage->depends) |
|
| 280 | 280 | { |
| 281 | - if(!is_array($xmlPackage->depends->item)) |
|
| 281 | + if (!is_array($xmlPackage->depends->item)) |
|
| 282 | 282 | { |
| 283 | 283 | $xmlPackage->depends->item = array($xmlPackage->depends->item); |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | $package->depends = array(); |
| 287 | - foreach($xmlPackage->depends->item as $item) |
|
| 287 | + foreach ($xmlPackage->depends->item as $item) |
|
| 288 | 288 | { |
| 289 | 289 | $dep_item = new stdClass(); |
| 290 | 290 | $dep_item->package_srl = $item->package_srl->body; |
@@ -297,23 +297,23 @@ discard block |
||
| 297 | 297 | |
| 298 | 298 | $packages = $oModel->getInstalledPackages(array_keys($targetpackages)); |
| 299 | 299 | $package->deplist = ""; |
| 300 | - foreach($package->depends as $key => $dep) |
|
| 300 | + foreach ($package->depends as $key => $dep) |
|
| 301 | 301 | { |
| 302 | - if(!$packages[$dep->package_srl]) |
|
| 302 | + if (!$packages[$dep->package_srl]) |
|
| 303 | 303 | { |
| 304 | 304 | $package->depends[$key]->installed = FALSE; |
| 305 | - $package->package_srl .= "," . $dep->package_srl; |
|
| 305 | + $package->package_srl .= ",".$dep->package_srl; |
|
| 306 | 306 | } |
| 307 | 307 | else |
| 308 | 308 | { |
| 309 | 309 | $package->depends[$key]->installed = TRUE; |
| 310 | 310 | $package->depends[$key]->cur_version = $packages[$dep->package_srl]->current_version; |
| 311 | - if(version_compare($dep->version, $packages[$dep->package_srl]->current_version, ">")) |
|
| 311 | + if (version_compare($dep->version, $packages[$dep->package_srl]->current_version, ">")) |
|
| 312 | 312 | { |
| 313 | 313 | $package->depends[$key]->need_update = TRUE; |
| 314 | - $package->package_srl .= "," . $dep->package_srl; |
|
| 314 | + $package->package_srl .= ",".$dep->package_srl; |
|
| 315 | 315 | |
| 316 | - if($dep->path === '.') |
|
| 316 | + if ($dep->path === '.') |
|
| 317 | 317 | { |
| 318 | 318 | $package->contain_core = TRUE; |
| 319 | 319 | $package->contain_core_version = $dep->version; |
@@ -328,14 +328,14 @@ discard block |
||
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | $installedPackage = $oModel->getInstalledPackage($packageSrl); |
| 331 | - if($installedPackage) |
|
| 331 | + if ($installedPackage) |
|
| 332 | 332 | { |
| 333 | 333 | $package->installed = TRUE; |
| 334 | 334 | $package->cur_version = $installedPackage->current_version; |
| 335 | 335 | $package->need_update = version_compare($package->version, $installedPackage->current_version, ">"); |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - if($package->path === '.') |
|
| 338 | + if ($package->path === '.') |
|
| 339 | 339 | { |
| 340 | 340 | $package->contain_core = TRUE; |
| 341 | 341 | $package->contain_core_version = $package->version; |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | public function getAutoInstallAdminInstallInfo() |
| 352 | 352 | { |
| 353 | 353 | $packageSrl = Context::get('package_srl'); |
| 354 | - if(!$packageSrl) |
|
| 354 | + if (!$packageSrl) |
|
| 355 | 355 | { |
| 356 | 356 | return new BaseObject(-1, 'msg_invalid_request'); |
| 357 | 357 | } |
@@ -365,23 +365,23 @@ discard block |
||
| 365 | 365 | $directModuleInstall = TRUE; |
| 366 | 366 | $arrUnwritableDir = array(); |
| 367 | 367 | $output = $this->isWritableDir($package->path); |
| 368 | - if($output->toBool()==FALSE) |
|
| 368 | + if ($output->toBool() == FALSE) |
|
| 369 | 369 | { |
| 370 | 370 | $directModuleInstall = FALSE; |
| 371 | 371 | $arrUnwritableDir[] = $output->get('path'); |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - foreach($package->depends as $dep) |
|
| 374 | + foreach ($package->depends as $dep) |
|
| 375 | 375 | { |
| 376 | 376 | $output = $this->isWritableDir($dep->path); |
| 377 | - if($output->toBool()==FALSE) |
|
| 377 | + if ($output->toBool() == FALSE) |
|
| 378 | 378 | { |
| 379 | 379 | $directModuleInstall = FALSE; |
| 380 | 380 | $arrUnwritableDir[] = $output->get('path'); |
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - if($directModuleInstall==FALSE) |
|
| 384 | + if ($directModuleInstall == FALSE) |
|
| 385 | 385 | { |
| 386 | 386 | $output = new BaseObject(-1, 'msg_direct_inall_invalid'); |
| 387 | 387 | $output->add('path', $arrUnwritableDir); |
@@ -396,17 +396,17 @@ discard block |
||
| 396 | 396 | $path_list = explode('/', dirname($path)); |
| 397 | 397 | $real_path = './'; |
| 398 | 398 | |
| 399 | - while($path_list) |
|
| 399 | + while ($path_list) |
|
| 400 | 400 | { |
| 401 | - $check_path = realpath($real_path . implode('/', $path_list)); |
|
| 402 | - if(FileHandler::isDir($check_path)) |
|
| 401 | + $check_path = realpath($real_path.implode('/', $path_list)); |
|
| 402 | + if (FileHandler::isDir($check_path)) |
|
| 403 | 403 | { |
| 404 | 404 | break; |
| 405 | 405 | } |
| 406 | 406 | array_pop($path_list); |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - if(FileHandler::isWritableDir($check_path)==FALSE) |
|
| 409 | + if (FileHandler::isWritableDir($check_path) == FALSE) |
|
| 410 | 410 | { |
| 411 | 411 | $output = new BaseObject(-1, 'msg_unwritable_directory'); |
| 412 | 412 | $output->add('path', FileHandler::getRealPath($check_path)); |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * Get the board module admin simple setting page |
| 24 | - * @return void |
|
| 24 | + * @return null|string |
|
| 25 | 25 | */ |
| 26 | 26 | public function getBoardAdminSimpleSetup($moduleSrl, $setupUrl) |
| 27 | 27 | { |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function getBoardAdminSimpleSetup($moduleSrl, $setupUrl) |
| 27 | 27 | { |
| 28 | - if(!$moduleSrl) |
|
| 28 | + if (!$moduleSrl) |
|
| 29 | 29 | { |
| 30 | 30 | return; |
| 31 | 31 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | $oModuleModel = getModel('module'); |
| 36 | 36 | $moduleInfo = $oModuleModel->getModuleInfoByModuleSrl($moduleSrl); |
| 37 | 37 | $moduleInfo->use_status = explode('|@|', $moduleInfo->use_status); |
| 38 | - if($moduleInfo) |
|
| 38 | + if ($moduleInfo) |
|
| 39 | 39 | { |
| 40 | 40 | Context::set('module_info', $moduleInfo); |
| 41 | 41 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | Context::set('document_status_list', $documentStatusList); |
| 47 | 47 | |
| 48 | 48 | // set order target list |
| 49 | - foreach($this->order_target AS $key) |
|
| 49 | + foreach ($this->order_target AS $key) |
|
| 50 | 50 | { |
| 51 | 51 | $order_target[$key] = Context::getLang($key); |
| 52 | 52 | } |
@@ -87,6 +87,9 @@ discard block |
||
| 87 | 87 | $oModule->add('comment_list',$this->arrangeComment(Context::get('comment_list')));
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | + /** |
|
| 91 | + * @param string $content_list |
|
| 92 | + */ |
|
| 90 | 93 | function arrangeContentList($content_list) {
|
| 91 | 94 | $output = array(); |
| 92 | 95 | if(count($content_list)) {
|
@@ -120,6 +123,9 @@ discard block |
||
| 120 | 123 | return $output; |
| 121 | 124 | } |
| 122 | 125 | |
| 126 | + /** |
|
| 127 | + * @param string $comment_list |
|
| 128 | + */ |
|
| 123 | 129 | function arrangeComment($comment_list) {
|
| 124 | 130 | $output = array(); |
| 125 | 131 | if(count($comment_list) > 0 ) {
|
@@ -133,6 +139,9 @@ discard block |
||
| 133 | 139 | } |
| 134 | 140 | |
| 135 | 141 | |
| 142 | + /** |
|
| 143 | + * @param string $file_list |
|
| 144 | + */ |
|
| 136 | 145 | function arrangeFile($file_list) {
|
| 137 | 146 | $output = array(); |
| 138 | 147 | if(count($file_list) > 0) {
|
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @brief notice list |
| 19 | 19 | **/ |
| 20 | 20 | function dispBoardNoticeList(&$oModule) {
|
| 21 | - $oModule->add('notice_list',$this->arrangeContentList(Context::get('notice_list')));
|
|
| 21 | + $oModule->add('notice_list', $this->arrangeContentList(Context::get('notice_list')));
|
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -29,11 +29,11 @@ discard block |
||
| 29 | 29 | $api_type = Context::get('api_type');
|
| 30 | 30 | $document_list = $this->arrangeContentList(Context::get('document_list'));
|
| 31 | 31 | |
| 32 | - if($api_type =='summary') |
|
| 32 | + if ($api_type == 'summary') |
|
| 33 | 33 | {
|
| 34 | 34 | $content_cut_size = Context::get('content_cut_size');
|
| 35 | - $content_cut_size = $content_cut_size?$content_cut_size:50; |
|
| 36 | - foreach($document_list as $k=>$v) |
|
| 35 | + $content_cut_size = $content_cut_size ? $content_cut_size : 50; |
|
| 36 | + foreach ($document_list as $k=>$v) |
|
| 37 | 37 | {
|
| 38 | 38 | $oDocument = new documentItem(); |
| 39 | 39 | $oDocument->setAttribute($v, false); |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - $oModule->add('document_list',$document_list);
|
|
| 46 | - $oModule->add('page_navigation',Context::get('page_navigation'));
|
|
| 45 | + $oModule->add('document_list', $document_list);
|
|
| 46 | + $oModule->add('page_navigation', Context::get('page_navigation'));
|
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @brief category list |
| 52 | 52 | **/ |
| 53 | 53 | function dispBoardCategoryList(&$oModule) {
|
| 54 | - $oModule->add('category_list',Context::get('category_list'));
|
|
| 54 | + $oModule->add('category_list', Context::get('category_list'));
|
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | function dispBoardContentView(&$oModule) {
|
| 61 | 61 | $oDocument = Context::get('oDocument');
|
| 62 | 62 | $extra_vars = $oDocument->getExtraVars(); |
| 63 | - if($oDocument->isGranted()) |
|
| 63 | + if ($oDocument->isGranted()) |
|
| 64 | 64 | {
|
| 65 | - $oDocument->add('extra_vars',$this->arrangeExtraVars($extra_vars)); |
|
| 65 | + $oDocument->add('extra_vars', $this->arrangeExtraVars($extra_vars)); |
|
| 66 | 66 | } |
| 67 | - $oModule->add('oDocument',$this->arrangeContent($oDocument));
|
|
| 67 | + $oModule->add('oDocument', $this->arrangeContent($oDocument));
|
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | **/ |
| 74 | 74 | function dispBoardContentFileList(&$oModule) {
|
| 75 | 75 | $oDocument = Context::get('oDocument'); |
| 76 | - if($oDocument->isAccessible()) |
|
| 76 | + if ($oDocument->isAccessible()) |
|
| 77 | 77 | { |
| 78 | 78 | $oModule->add('file_list', $this->arrangeFile(Context::get('file_list'))); |
| 79 | 79 | } |
@@ -88,20 +88,20 @@ discard block |
||
| 88 | 88 | * @brief tag list |
| 89 | 89 | **/ |
| 90 | 90 | function dispBoardTagList(&$oModule) {
|
| 91 | - $oModule->add('tag_list',Context::get('tag_list'));
|
|
| 91 | + $oModule->add('tag_list', Context::get('tag_list'));
|
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | 95 | * @brief comments list |
| 96 | 96 | **/ |
| 97 | 97 | function dispBoardContentCommentList(&$oModule) {
|
| 98 | - $oModule->add('comment_list',$this->arrangeComment(Context::get('comment_list')));
|
|
| 98 | + $oModule->add('comment_list', $this->arrangeComment(Context::get('comment_list')));
|
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | function arrangeContentList($content_list) {
|
| 102 | 102 | $output = array(); |
| 103 | - if(count($content_list)) {
|
|
| 104 | - foreach($content_list as $key => $val) $output[] = $this->arrangeContent($val); |
|
| 103 | + if (count($content_list)) {
|
|
| 104 | + foreach ($content_list as $key => $val) $output[] = $this->arrangeContent($val); |
|
| 105 | 105 | } |
| 106 | 106 | return $output; |
| 107 | 107 | } |
@@ -110,16 +110,16 @@ discard block |
||
| 110 | 110 | function arrangeContent($content) {
|
| 111 | 111 | $oBoardView = getView('board');
|
| 112 | 112 | $output = new stdClass; |
| 113 | - if($content){
|
|
| 114 | - $output = $content->gets('document_srl','category_srl','member_srl','nick_name','title','content','tags','readed_count','voted_count','blamed_count','comment_count','regdate','last_update','extra_vars','status');
|
|
| 113 | + if ($content) {
|
|
| 114 | + $output = $content->gets('document_srl', 'category_srl', 'member_srl', 'nick_name', 'title', 'content', 'tags', 'readed_count', 'voted_count', 'blamed_count', 'comment_count', 'regdate', 'last_update', 'extra_vars', 'status');
|
|
| 115 | 115 | |
| 116 | - if(!$oBoardView->grant->view) |
|
| 116 | + if (!$oBoardView->grant->view) |
|
| 117 | 117 | {
|
| 118 | 118 | unset($output->content); |
| 119 | 119 | unset($output->tags); |
| 120 | 120 | unset($output->extra_vars); |
| 121 | 121 | } |
| 122 | - if(!$content->isAccessible()) |
|
| 122 | + if (!$content->isAccessible()) |
|
| 123 | 123 | { |
| 124 | 124 | $output->content = Context::getLang('msg_is_secret'); |
| 125 | 125 | } |
@@ -137,11 +137,11 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | function arrangeComment($comment_list) {
|
| 139 | 139 | $output = array(); |
| 140 | - if(count($comment_list) > 0 ) {
|
|
| 141 | - foreach($comment_list as $key => $val){
|
|
| 140 | + if (count($comment_list) > 0) {
|
|
| 141 | + foreach ($comment_list as $key => $val) {
|
|
| 142 | 142 | $item = null; |
| 143 | - $item = $val->gets('comment_srl','parent_srl','depth','nick_name','content','is_secret','voted_count','blamed_count','regdate','last_update');
|
|
| 144 | - if(!$val->isAccessible()) |
|
| 143 | + $item = $val->gets('comment_srl', 'parent_srl', 'depth', 'nick_name', 'content', 'is_secret', 'voted_count', 'blamed_count', 'regdate', 'last_update');
|
|
| 144 | + if (!$val->isAccessible()) |
|
| 145 | 145 | { |
| 146 | 146 | $item->content = Context::getLang('msg_is_secret'); |
| 147 | 147 | } |
@@ -154,8 +154,8 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | function arrangeFile($file_list) {
|
| 156 | 156 | $output = array(); |
| 157 | - if(count($file_list) > 0) {
|
|
| 158 | - foreach($file_list as $key => $val){
|
|
| 157 | + if (count($file_list) > 0) {
|
|
| 158 | + foreach ($file_list as $key => $val) {
|
|
| 159 | 159 | $item = new stdClass; |
| 160 | 160 | $item->download_count = $val->download_count; |
| 161 | 161 | $item->source_filename = $val->source_filename; |
@@ -169,8 +169,8 @@ discard block |
||
| 169 | 169 | |
| 170 | 170 | function arrangeExtraVars($list) {
|
| 171 | 171 | $output = array(); |
| 172 | - if(count($list)) {
|
|
| 173 | - foreach($list as $key => $val){
|
|
| 172 | + if (count($list)) {
|
|
| 173 | + foreach ($list as $key => $val) {
|
|
| 174 | 174 | $item = new stdClass; |
| 175 | 175 | $item->name = $val->name; |
| 176 | 176 | $item->type = $val->type; |
@@ -76,8 +76,7 @@ discard block |
||
| 76 | 76 | if($oDocument->isAccessible()) |
| 77 | 77 | { |
| 78 | 78 | $oModule->add('file_list', $this->arrangeFile(Context::get('file_list'))); |
| 79 | - } |
|
| 80 | - else |
|
| 79 | + } else |
|
| 81 | 80 | { |
| 82 | 81 | $oModule->add('file_list', array()); |
| 83 | 82 | } |
@@ -101,7 +100,9 @@ discard block |
||
| 101 | 100 | function arrangeContentList($content_list) {
|
| 102 | 101 | $output = array(); |
| 103 | 102 | if(count($content_list)) {
|
| 104 | - foreach($content_list as $key => $val) $output[] = $this->arrangeContent($val); |
|
| 103 | + foreach($content_list as $key => $val) { |
|
| 104 | + $output[] = $this->arrangeContent($val); |
|
| 105 | + } |
|
| 105 | 106 | } |
| 106 | 107 | return $output; |
| 107 | 108 | } |