11
11
use Chamilo \ThemeBundle \Controller \ExceptionController ;
12
12
use Chamilo \UserBundle \Entity \User ;
13
13
use ChamiloSession as Session ;
14
+ use Symfony \Bridge \Twig \Mime \TemplatedEmail ;
14
15
use Symfony \Component \Debug \Exception \FlattenException ;
15
16
use Symfony \Component \Finder \Finder ;
17
+ use Symfony \Component \Mime \Address ;
18
+ use Symfony \Component \Mime \Email ;
16
19
use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
17
20
18
21
/**
@@ -1845,7 +1848,7 @@ function api_get_anonymous_id()
1845
1848
$ ip = Database::escape_string (api_get_real_ip ());
1846
1849
$ max = (int ) api_get_configuration_value ('max_anonymous_users ' );
1847
1850
if ($ max >= 2 ) {
1848
- $ sql = "SELECT * FROM $ table as TEL
1851
+ $ sql = "SELECT * FROM $ table as TEL
1849
1852
JOIN $ tableU as U
1850
1853
ON U.user_id = TEL.login_user_id
1851
1854
WHERE TEL.user_ip = ' $ ip'
@@ -1880,8 +1883,8 @@ function api_get_anonymous_id()
1880
1883
}
1881
1884
1882
1885
$ table = Database::get_main_table (TABLE_MAIN_USER );
1883
- $ sql = "SELECT user_id
1884
- FROM $ table
1886
+ $ sql = "SELECT user_id
1887
+ FROM $ table
1885
1888
WHERE status = " .ANONYMOUS ." " ;
1886
1889
$ res = Database::query ($ sql );
1887
1890
if (Database::num_rows ($ res ) > 0 ) {
@@ -4679,7 +4682,7 @@ function api_display_language_form($hide_if_no_choice = false, $showAsButton = f
4679
4682
} else {
4680
4683
$ html = '
4681
4684
<a href=" ' .$ url .'" class="dropdown-toggle" data-toggle="dropdown" role="button">
4682
- <span class="flag-icon flag-icon- ' .$ countryCode .'"></span>
4685
+ <span class="flag-icon flag-icon- ' .$ countryCode .'"></span>
4683
4686
' .$ currentLanguageInfo ['original_name ' ].'
4684
4687
<span class="caret"></span>
4685
4688
</a>
@@ -4795,7 +4798,7 @@ function languageToCountryIsoCode($languageIsoCode)
4795
4798
function api_get_languages ()
4796
4799
{
4797
4800
$ table = Database::get_main_table (TABLE_MAIN_LANGUAGE );
4798
- $ sql = "SELECT * FROM $ table WHERE available='1'
4801
+ $ sql = "SELECT * FROM $ table WHERE available='1'
4799
4802
ORDER BY original_name ASC " ;
4800
4803
$ result = Database::query ($ sql );
4801
4804
$ languages = [];
@@ -8027,8 +8030,8 @@ function api_get_password_checker_js($usernameInputId, $passwordInputId)
8027
8030
};
8028
8031
8029
8032
$(function() {
8030
- var lang = " .json_encode ($ translations ).";
8031
- var options = {
8033
+ var lang = " .json_encode ($ translations ).";
8034
+ var options = {
8032
8035
onLoad : function () {
8033
8036
//$('#messages').text('Start typing password');
8034
8037
},
@@ -8046,7 +8049,7 @@ function api_get_password_checker_js($usernameInputId, $passwordInputId)
8046
8049
options.i18n = {
8047
8050
t: function (key) {
8048
8051
var result = lang[key];
8049
- return result === key ? '' : result; // This assumes you return the
8052
+ return result === key ? '' : result; // This assumes you return the
8050
8053
}
8051
8054
};
8052
8055
$(' " .$ passwordInputId ."').pwstrength(options);
@@ -8717,68 +8720,22 @@ function api_mail_html(
8717
8720
$ replyToName = $ extra_headers ['reply_to ' ]['name ' ];
8718
8721
}
8719
8722
8720
- //If the SMTP configuration only accept one sender
8721
- /*if (isset($platform_email['SMTP_UNIQUE_SENDER']) && $platform_email['SMTP_UNIQUE_SENDER']) {
8722
- $senderName = $platform_email['SMTP_FROM_NAME'];
8723
- $senderEmail = $platform_email['SMTP_FROM_EMAIL'];
8724
- $valid = PHPMailer::validateAddress($senderEmail);
8725
- if ($valid) {
8726
- //force-set Sender to $senderEmail, otherwise SetFrom only does it if it is currently empty
8727
- $mail->Sender = $senderEmail;
8728
- }
8729
- }*/
8730
-
8731
- /*$mail->SetFrom($senderEmail, $senderName);
8732
- $mail->Subject = $subject;
8733
- $mail->AltBody = strip_tags(
8734
- str_replace('<br />', "\n", api_html_entity_decode($message))
8735
- );*/
8736
-
8737
- /*if (is_array($extra_headers) && count($extra_headers) > 0) {
8738
- foreach ($extra_headers as $key => $value) {
8739
- switch (strtolower($key)) {
8740
- case 'encoding':
8741
- case 'content-transfer-encoding':
8742
- $mail->Encoding = $value;
8743
- break;
8744
- case 'charset':
8745
- $mail->Charset = $value;
8746
- break;
8747
- case 'contenttype':
8748
- case 'content-type':
8749
- $mail->ContentType = $value;
8750
- break;
8751
- default:
8752
- $mail->AddCustomHeader($key.':'.$value);
8753
- break;
8754
- }
8755
- }
8756
- } else {
8757
- if (!empty($extra_headers)) {
8758
- $mail->AddCustomHeader($extra_headers);
8759
- }
8760
- }*/
8761
-
8762
- // WordWrap the html body (phpMailer only fixes AltBody) FS#2988
8763
- //$mail->Body = $mail->WrapText($mail->Body, $mail->WordWrap);
8764
8723
try {
8765
- $ message = new \Swift_Message ($ subject );
8724
+ $ message = new TemplatedEmail ();
8725
+ $ message ->subject ($ subject );
8766
8726
8767
8727
$ list = api_get_configuration_value ('send_all_emails_to ' );
8768
8728
if (!empty ($ list ) && isset ($ list ['emails ' ])) {
8769
8729
foreach ($ list ['emails ' ] as $ email ) {
8770
- $ message ->addCc ($ email );
8730
+ $ message ->cc ($ email );
8771
8731
}
8772
8732
}
8773
8733
8774
8734
// Attachment
8775
8735
if (!empty ($ data_file )) {
8776
8736
foreach ($ data_file as $ file_attach ) {
8777
8737
if (!empty ($ file_attach ['path ' ]) && !empty ($ file_attach ['filename ' ])) {
8778
- //$message->attach(Swift_Attachment::fromPath($file_attach['path'], $file_attach['filename']);
8779
- $ message ->attach (
8780
- Swift_Attachment::fromPath ($ file_attach ['path ' ])->setFilename ($ file_attach ['filename ' ])
8781
- );
8738
+ $ message ->attachFromPath ($ file_attach ['path ' ], $ file_attach ['filename ' ]);
8782
8739
}
8783
8740
}
8784
8741
}
@@ -8800,41 +8757,27 @@ function api_mail_html(
8800
8757
$ paramsHtml = $ paramsText = $ params ;
8801
8758
8802
8759
$ paramsHtml ['content ' ] = $ body ;
8803
- $ paramsText ['content ' ] = str_replace ('<br /> ' , "\n" , api_html_entity_decode ($ body ));
8760
+ // $paramsText['content'] = str_replace('<br />', "\n", api_html_entity_decode($body));
8804
8761
8805
8762
if (!empty ($ senderEmail )) {
8806
- $ message ->setFrom ([ $ senderEmail => $ senderName] );
8763
+ $ message ->from ( new Address ( $ senderEmail, $ senderName) );
8807
8764
}
8808
8765
8809
8766
if (!empty ($ recipientEmail )) {
8810
- $ message ->setTo ([ $ recipientEmail => $ recipientName] );
8767
+ $ message ->to ( new Address ( $ recipientEmail, $ recipientName) );
8811
8768
}
8812
8769
8813
8770
if (!empty ($ replyToEmail )) {
8814
- $ message ->setReplyTo ([ $ replyToEmail => $ replyToName] );
8771
+ $ message ->replyTo ( new Address ( $ replyToEmail, $ replyToName) );
8815
8772
}
8816
8773
8817
8774
$ message
8818
- ->setBody (
8819
- Container::getTwig ()->render (
8820
- 'ChamiloThemeBundle:Mailer:Default/default.html.twig ' ,
8821
- $ paramsHtml
8822
- ),
8823
- 'text/html '
8824
- )
8825
- ->addPart (
8826
- Container::getTwig ()->render (
8827
- 'ChamiloThemeBundle:Mailer:Default/default.text.twig ' ,
8828
- $ paramsText
8829
- ),
8830
- 'text/plain '
8831
- )
8832
- //->setEncoder(\Swift_Encoding::get8BitEncoding())
8775
+ ->htmlTemplate ('ChamiloThemeBundle:Mailer:Default/default.html.twig ' )
8776
+ ->textTemplate ('ChamiloThemeBundle:Mailer:Default/default.text.twig ' )
8833
8777
;
8834
-
8835
- $ type = $ message ->getHeaders ()->get ('Content-Type ' );
8836
- $ type ->setCharset ('utf-8 ' );
8837
- Container::getMailer ()->send ($ message );
8778
+ $ message ->context ($ paramsHtml );
8779
+ $ result = Container::getMailer ()->send ($ message );
8780
+ var_dump ($ result );exit ;
8838
8781
8839
8782
return true ;
8840
8783
} catch (Exception $ e ) {
@@ -9325,7 +9268,7 @@ function api_find_template($template)
9325
9268
function api_get_language_list_for_flag ()
9326
9269
{
9327
9270
$ table = Database::get_main_table (TABLE_MAIN_LANGUAGE );
9328
- $ sql = "SELECT english_name, isocode FROM $ table
9271
+ $ sql = "SELECT english_name, isocode FROM $ table
9329
9272
ORDER BY original_name ASC " ;
9330
9273
static $ languages = [];
9331
9274
if (empty ($ languages )) {
@@ -9373,11 +9316,11 @@ function api_get_language_translate_html()
9373
9316
$ hideAll .= '
9374
9317
$("span:lang( ' .$ language ['isocode ' ].')").filter(
9375
9318
function(e, val) {
9376
- // Only find the spans if they have set the lang
9377
- if ($(this).attr("lang") == null) {
9319
+ // Only find the spans if they have set the lang
9320
+ if ($(this).attr("lang") == null) {
9378
9321
return false;
9379
9322
}
9380
-
9323
+
9381
9324
// Ignore ckeditor classes
9382
9325
return !this.className.match(/cke(.*)/);
9383
9326
}).hide(); ' ."\n" ;
@@ -9394,32 +9337,32 @@ function(e, val) {
9394
9337
9395
9338
return '
9396
9339
$(function() {
9397
- ' .$ hideAll .'
9398
- var defaultLanguageFromUser = " ' .$ isoCode .'";
9399
-
9340
+ ' .$ hideAll .'
9341
+ var defaultLanguageFromUser = " ' .$ isoCode .'";
9342
+
9400
9343
$("span:lang( ' .$ isoCode .')").filter(
9401
9344
function() {
9402
9345
// Ignore ckeditor classes
9403
9346
return !this.className.match(/cke(.*)/);
9404
9347
}).show();
9405
-
9348
+
9406
9349
var defaultLanguage = "";
9407
9350
var langFromUserFound = false;
9408
-
9351
+
9409
9352
$(this).find("span").filter(
9410
9353
function() {
9411
9354
// Ignore ckeditor classes
9412
9355
return !this.className.match(/cke(.*)/);
9413
9356
}).each(function() {
9414
- defaultLanguage = $(this).attr("lang");
9357
+ defaultLanguage = $(this).attr("lang");
9415
9358
if (defaultLanguage) {
9416
- $(this).before().next("br").remove();
9359
+ $(this).before().next("br").remove();
9417
9360
if (defaultLanguageFromUser == defaultLanguage) {
9418
9361
langFromUserFound = true;
9419
9362
}
9420
9363
}
9421
9364
});
9422
-
9365
+
9423
9366
// Show default language
9424
9367
if (langFromUserFound == false && defaultLanguage) {
9425
9368
$("span:lang("+defaultLanguage+")").filter(
0 commit comments