loader.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. include_once 'config/config.php';
  3. include_once "vendor/notorm/NotORM.php";
  4. //exit('Commentami, lanciami e ricommentami.');
  5. function getToken($length = 12){
  6. return uniqId();
  7. //PHP7
  8. //return bin2hex(random_bytes($length));
  9. }
  10. $pdo = new PDO("mysql:host=".$db_host.";dbname=".$db_dbname,
  11. $db_user,
  12. $db_pass
  13. );
  14. function getMyDateFormatted($datestr){
  15. $date = null;
  16. if(empty($datestr)){
  17. $date = new DateTime();
  18. } else {
  19. $date = new DateTime($datestr);
  20. }
  21. return $date->format('Y-m-d');
  22. }
  23. $db = new NotORM($pdo);
  24. $db->debug = true;
  25. $today = getMyDateFormatted("");
  26. $last = getMyDateFormatted($rollday);
  27. //Inserisco la mailing list e ottengo l'id
  28. $ret = $db->roll()->insert(array(
  29. "ml" => $ml,
  30. "startroll" => $today,
  31. "endroll" => $last
  32. ));
  33. $file = fopen($filename, "r");
  34. while(!feof($file)){
  35. $line = fgets($file);
  36. $sanitized_mail = filter_var($line, FILTER_SANITIZE_EMAIL);
  37. if($sanitized_mail !== "") {
  38. $token = getToken();
  39. //Inserisco le mail dei membri della mailing list
  40. $db->$db_table()->insert(array(
  41. "id" => $ret['id'],
  42. "token" => $token,
  43. "email" => $sanitized_mail
  44. ));
  45. }
  46. }
  47. fclose($file);