PageRenderTime 39ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/assets/snippets/weblogin/weblogin.common.inc.php

https://github.com/good-web-master/modx.evo.custom
PHP | 133 lines | 104 code | 13 blank | 16 comment | 11 complexity | 3b465a947d467153a47b4cb341bb2a74 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0, MIT, BSD-3-Clause
  1. <?php
  2. /**
  3. * Commonly used login functions
  4. * Writen By Raymond Irving April, 2005
  5. *
  6. */
  7. // extract declarations
  8. function webLoginExtractDeclarations(&$html){
  9. $declare = array();
  10. if(strpos($html,"<!-- #declare:")===false) return $declare;
  11. $matches= array();
  12. if (preg_match_all("/<\!-- \#declare\:(.*)[^-->]?-->/i",$html,$matches)) {
  13. for($i=0;$i<count($matches[1]);$i++) {
  14. $tag = explode(" ",$matches[1][$i]);
  15. $tagname=trim($tag[0]);
  16. $tagvalue=trim($tag[1]);
  17. $declare[$tagname] = $tagvalue;
  18. }
  19. // remove declarations
  20. $html = str_replace($matches[0],"",$html);
  21. }
  22. return $declare;
  23. }
  24. // show javascript alert
  25. function webLoginAlert($msg,$alerttpl=''){
  26. global $modx;
  27. if(!empty($alerttpl)){
  28. $output = $modx->parseChunk($alerttpl, array("msg"=>$msg), '[+', '+]');
  29. }else{
  30. $output = "<script>window.setTimeout(\"alert('".addslashes($modx->db->escape($msg))."')\",10);</script>";
  31. }
  32. return $output;
  33. }
  34. // generate new password
  35. function webLoginGeneratePassword($length = 10) {
  36. $allowable_characters = "abcdefghjkmnpqrstuvxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
  37. $ps_len = strlen($allowable_characters);
  38. mt_srand((double)microtime()*1000000);
  39. $pass = "";
  40. for($i = 0; $i < $length; $i++) {
  41. $pass .= $allowable_characters[mt_rand(0,$ps_len-1)];
  42. }
  43. return $pass;
  44. }
  45. function sendMail($subject,$email,$body){
  46. global $modx;
  47. $charset = $modx->config['modx_charset'];
  48. $site_name = $modx->config['site_name'];
  49. $adminEmail = $modx->config['emailsender'];
  50. require_once(MODX_MANAGER_PATH . "includes/controls/class.phpmailer.php");
  51. $mail = new PHPMailer();
  52. $mail->IsMail();
  53. $mail->IsHTML(false);
  54. $mail->CharSet = $charset;
  55. $mail->From = $adminEmail;
  56. $mail->FromName = $site_name;
  57. $mail->Subject = $subject;
  58. $mail->Body = $body;
  59. $mail->AddAddress($email);
  60. if(!$mail->send()){
  61. echo $mail->ErrorInfo;
  62. exit;
  63. }
  64. }
  65. // Send new password to the user
  66. function webLoginSendNewPassword($email,$uid,$pwd,$ufn){
  67. global $modx, $site_url;
  68. $mailto = $modx->config['mailto'];
  69. $websignupemail_message = $modx->config['websignupemail_message'];
  70. $emailsubject = $modx->config['emailsubject'];
  71. $emailsender = $modx->config['emailsender'];
  72. $site_name = $modx->config['site_name'];
  73. $site_start = $modx->config['site_start'];
  74. $message = sprintf($websignupemail_message, $uid, $pwd); // use old method
  75. // replace placeholders
  76. $message = str_replace("[+uid+]",$uid,$message);
  77. $message = str_replace("[+pwd+]",$pwd,$message);
  78. $message = str_replace("[+ufn+]",$ufn,$message);
  79. $message = str_replace("[+sname+]",$site_name,$message);
  80. $message = str_replace("[+semail+]",$emailsender,$message);
  81. $message = str_replace("[+surl+]",$site_url,$message);
  82. /*
  83. if (!ini_get('safe_mode')) $sent = mail($email, $emailsubject, $message, "Content-type: text/plain; charset=UTF-8"."\r\n"."From: ".$emailsender."\r\n"."X-Mailer: Content Manager - PHP/".phpversion(), "-f {$emailsender}");
  84. else $sent = mail($email, $emailsubject, $message, "Content-type: text/plain; charset=UTF-8"."\r\n"."From: ".$emailsender."\r\n"."X-Mailer: Content Manager - PHP/".phpversion());
  85. if (!$sent) webLoginAlert($langTXT[16]." $mailto",$alerttpl);
  86. */
  87. sendMail($emailsubject,$email,$message);
  88. return true;
  89. }
  90. function preserveUrl($docid = '', $alias = '', $array_values = array(), $suffix = false) {
  91. global $modx;
  92. $array_get = $_GET;
  93. $urlstring = array();
  94. unset($array_get["id"]);
  95. unset($array_get["q"]);
  96. unset($array_get["webloginmode"]);
  97. $array_url = array_merge($array_get, $array_values);
  98. foreach ($array_url as $name => $value) {
  99. if (!is_null($value)) {
  100. if(!is_array($value)){
  101. $urlstring[] = urlencode($name) . '=' . urlencode($value);
  102. }else{
  103. foreach ($value as $val){
  104. $urlstring[] = urlencode($name) . '[]=' . urlencode($val);
  105. }
  106. unset($key,$val);
  107. }
  108. }
  109. }
  110. $url = join('&',$urlstring);
  111. if ($suffix) {
  112. if (empty($url)) {
  113. $url = "?";
  114. } else {
  115. $url .= "&";
  116. }
  117. }
  118. return $modx->makeUrl($docid, $alias, $url);
  119. }
  120. ?>