| @@ 307-369 (lines=63) @@ | ||
| 304 | * @return bool Result of the send |
|
| 305 | * @internal param string $tpl_name Template's name |
|
| 306 | */ |
|
| 307 | public static function sendEmailFromTpl($tplName, $recipients, $subject, $variables) |
|
| 308 | { |
|
| 309 | global $xoopsConfig; |
|
| 310 | require_once XOOPS_ROOT_PATH . '/class/xoopsmailer.php'; |
|
| 311 | if (!is_array($recipients)) { |
|
| 312 | if (trim($recipients) == '') { |
|
| 313 | return false; |
|
| 314 | } |
|
| 315 | } else { |
|
| 316 | if (count($recipients) == 0) { |
|
| 317 | return false; |
|
| 318 | } |
|
| 319 | } |
|
| 320 | if (function_exists('xoops_getMailer')) { |
|
| 321 | $xoopsMailer = xoops_getMailer(); |
|
| 322 | } else { |
|
| 323 | $xoopsMailer = xoops_getMailer(); |
|
| 324 | } |
|
| 325 | ||
| 326 | $xoopsMailer->useMail(); |
|
| 327 | $templateDir = XOOPS_ROOT_PATH . '/modules/' . static::MODULE_NAME . '/language/' . $xoopsConfig['language'] . '/mail_template'; |
|
| 328 | if (!is_dir($templateDir)) { |
|
| 329 | $templateDir = XOOPS_ROOT_PATH . '/modules/' . static::MODULE_NAME . '/language/english/mail_template'; |
|
| 330 | } |
|
| 331 | $xoopsMailer->setTemplateDir($templateDir); |
|
| 332 | $xoopsMailer->setTemplate($tplName); |
|
| 333 | $xoopsMailer->setToEmails($recipients); |
|
| 334 | // TODO: Change ! |
|
| 335 | // $xoopsMailer->setFromEmail('[email protected]'); |
|
| 336 | //$xoopsMailer->setFromName('MonSite'); |
|
| 337 | $xoopsMailer->setSubject($subject); |
|
| 338 | foreach ($variables as $key => $value) { |
|
| 339 | $xoopsMailer->assign($key, $value); |
|
| 340 | } |
|
| 341 | $res = $xoopsMailer->send(); |
|
| 342 | unset($xoopsMailer); |
|
| 343 | // B.R. $filename = XOOPS_UPLOAD_PATH . '/logmail_' . static::MODULE_NAME . '.php'; |
|
| 344 | $filename = OLEDRION_UPLOAD_PATH . '/logmail_' . static::MODULE_NAME . '.php'; |
|
| 345 | if (!file_exists($filename)) { |
|
| 346 | $fp = @fopen($filename, 'a'); |
|
| 347 | if ($fp) { |
|
| 348 | fwrite($fp, "<?php exit(); ?>\n"); |
|
| 349 | fclose($fp); |
|
| 350 | } |
|
| 351 | } |
|
| 352 | $fp = @fopen($filename, 'a'); |
|
| 353 | ||
| 354 | if ($fp) { |
|
| 355 | fwrite($fp, str_repeat('-', 120) . "\n"); |
|
| 356 | fwrite($fp, date('d/m/Y H:i:s') . "\n"); |
|
| 357 | fwrite($fp, 'Template name : ' . $tplName . "\n"); |
|
| 358 | fwrite($fp, 'Email subject : ' . $subject . "\n"); |
|
| 359 | if (is_array($recipients)) { |
|
| 360 | fwrite($fp, 'Recipient(s) : ' . implode(',', $recipients) . "\n"); |
|
| 361 | } else { |
|
| 362 | fwrite($fp, 'Recipient(s) : ' . $recipients . "\n"); |
|
| 363 | } |
|
| 364 | fwrite($fp, 'Transmited variables : ' . implode(',', $variables) . "\n"); |
|
| 365 | fclose($fp); |
|
| 366 | } |
|
| 367 | ||
| 368 | return $res; |
|
| 369 | } |
|
| 370 | ||
| 371 | /** |
|
| 372 | * Remove module's cache |
|
| @@ 451-512 (lines=62) @@ | ||
| 448 | * @return bool Result of the send |
|
| 449 | * @internal param string $tpl_name Template's name |
|
| 450 | */ |
|
| 451 | public static function sendEmailFromTpl($tplName, $recipients, $subject, $variables) |
|
| 452 | { |
|
| 453 | global $xoopsConfig; |
|
| 454 | require_once XOOPS_ROOT_PATH . '/class/xoopsmailer.php'; |
|
| 455 | if (!is_array($recipients)) { |
|
| 456 | if (trim($recipients) == '') { |
|
| 457 | return false; |
|
| 458 | } |
|
| 459 | } else { |
|
| 460 | if (count($recipients) == 0) { |
|
| 461 | return false; |
|
| 462 | } |
|
| 463 | } |
|
| 464 | if (function_exists('xoops_getMailer')) { |
|
| 465 | $xoopsMailer = xoops_getMailer(); |
|
| 466 | } else { |
|
| 467 | $xoopsMailer = xoops_getMailer(); |
|
| 468 | } |
|
| 469 | ||
| 470 | $xoopsMailer->useMail(); |
|
| 471 | $templateDir = XOOPS_ROOT_PATH . '/modules/' . self::MODULE_NAME . '/language/' . $xoopsConfig['language'] . '/mail_template'; |
|
| 472 | if (!is_dir($templateDir)) { |
|
| 473 | $templateDir = XOOPS_ROOT_PATH . '/modules/' . self::MODULE_NAME . '/language/english/mail_template'; |
|
| 474 | } |
|
| 475 | $xoopsMailer->setTemplateDir($templateDir); |
|
| 476 | $xoopsMailer->setTemplate($tplName); |
|
| 477 | $xoopsMailer->setToEmails($recipients); |
|
| 478 | // TODO: Change ! |
|
| 479 | // $xoopsMailer->setFromEmail('[email protected]'); |
|
| 480 | //$xoopsMailer->setFromName('MonSite'); |
|
| 481 | $xoopsMailer->setSubject($subject); |
|
| 482 | foreach ($variables as $key => $value) { |
|
| 483 | $xoopsMailer->assign($key, $value); |
|
| 484 | } |
|
| 485 | $res = $xoopsMailer->send(); |
|
| 486 | unset($xoopsMailer); |
|
| 487 | $filename = XOOPS_UPLOAD_PATH . '/logmail_' . self::MODULE_NAME . '.php'; |
|
| 488 | if (!file_exists($filename)) { |
|
| 489 | $fp = @fopen($filename, 'a'); |
|
| 490 | if ($fp) { |
|
| 491 | fwrite($fp, "<?php exit(); ?>\n"); |
|
| 492 | fclose($fp); |
|
| 493 | } |
|
| 494 | } |
|
| 495 | $fp = @fopen($filename, 'a'); |
|
| 496 | ||
| 497 | if ($fp) { |
|
| 498 | fwrite($fp, str_repeat('-', 120) . "\n"); |
|
| 499 | fwrite($fp, date('d/m/Y H:i:s') . "\n"); |
|
| 500 | fwrite($fp, 'Template name : ' . $tplName . "\n"); |
|
| 501 | fwrite($fp, 'Email subject : ' . $subject . "\n"); |
|
| 502 | if (is_array($recipients)) { |
|
| 503 | fwrite($fp, 'Recipient(s) : ' . implode(',', $recipients) . "\n"); |
|
| 504 | } else { |
|
| 505 | fwrite($fp, 'Recipient(s) : ' . $recipients . "\n"); |
|
| 506 | } |
|
| 507 | fwrite($fp, 'Transmited variables : ' . implode(',', $variables) . "\n"); |
|
| 508 | fclose($fp); |
|
| 509 | } |
|
| 510 | ||
| 511 | return $res; |
|
| 512 | } |
|
| 513 | ||
| 514 | /** |
|
| 515 | * Remove module's cache |
|