SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/ContentSubscribe.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers;
  15.  
  16. class ContentSubscribe
  17. {
  18.  
  19. /**
  20.   * Subscribe a user to a specified handler.
  21.   *
  22.   * @param string $handler_class The name of the handler class
  23.   * @param array $handler_settings The settings to be passed to the handler; can be an empty array
  24.   * @param string $name The name of the user
  25.   * @param string $email The email address of the user
  26.   **/
  27. public static function subscribe($handler_class, array $handler_settings, $name, $email)
  28. {
  29. $code = md5(strtolower(trim($email)));
  30.  
  31. $update_data = array();
  32. $update_data['handler_class'] = $handler_class;
  33. $update_data['handler_settings'] = json_encode($handler_settings);
  34. $update_data['name'] = $name;
  35. $update_data['email'] = $email;
  36. $update_data['code'] = $code;
  37. $update_data['subsite_id'] = SubsiteSelector::$subsite_id;
  38. $update_data['date_added'] = Pdb::now();
  39. $update_data['date_modified'] = Pdb::now();
  40.  
  41. Pdb::insert('content_subscriptions', $update_data);
  42. }
  43.  
  44.  
  45. /**
  46.   * Called by a usort() in the cronjob to sort by the timestamp field
  47.   **/
  48. public static function tsSort($a, $b)
  49. {
  50. if ($a['ts'] == $b['ts']) return 0;
  51. return ($a['ts'] < $b['ts']) ? -1 : 1;
  52. }
  53.  
  54. }
  55.  
  56.