<commit_before><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  // Defines for log
  define('EZMLM_ADD',     '+');
  define('EZMLM_DEL',     '-');
  define('EZMLM_MOD',     '%');
  
  define('EZMLM_WHO',     'w');

  /**
   * Helper class to maintain sql based ezmlm mailinglists.
   *
   * @see      http://ezmlm.org
   * @purpose  Maintain mailing list subscriptions
   */
  class EzmlmSqlUtil extends Object {
    var
      $db=          NULL;
      $database=    '',
      $mailinglist= '';
      
    /**
     * Constructor.
     *
     * @access  public
     * @param   string database
     * @param   string mailinglist
     */
    function __construct($database, $mailinglist) {
      $this->database= $database;
      $this->mailinglist= $mailinglist;
    }
    
    /**
     * Set connection,
     *
     * @access  public
     * @param   &rdbms.mysql.MysqlConnection db
     */
    function setConnection(&$db) {
      $this->db= &$db;
    }
  
    /**
     * Check whether address is subscribed
     *
     * @access  public
     * @param   string address
     * @return  bool
     */
    function isSubscribed($address) {
      $s= $this->db->select('
          1
        from
          %c.%c
        where address= %s
          and hash between 1 and 52
        ',
        $this->database,
        $this->mailinglist
      );
      
      return (bool)sizeof($s);
    }
    
    /**
     * Get list of subscribers
     *
     * @access  public
     * @return  string[]
     */
    function getSubscribers() {
      $q= &$this->db->query('
        select
          address
        from
          %c.%c
        where hash between 1 and 52
        ',
        $this->database,
        $this->mailinglist
      );
      $s= array();
      while ($q && $r= $q->next('address')) { $s[]= $r; }
      return $s;
    }
    
    /**
     * Add subscriber
     *
     * @access  public
     * @param   string address
     */
    function addSubscriber($address) {
      $this->db->insert('
        into %c.%c (
          hash,
          address
        ) values (
          %d,
          %s
        )',
        $this->database,
        $this->mailinglist,
        (int)rand(1, 52),
        $address
      );
      $this->writeLog($to, '', EZMLM_ADD);
    }
    
    /**
     * Remove subscriber
     *
     * @access  public
     * @param   string address
     * @return  int
     */
    function removeSubscriber($address) {
      $cnt= $this->db->delete('
        from 
          %c.%c
        where address= %s
        ',
        $this->database,
        $this->mailinglist,
        $address
      );
      $cnt && $this->writeLog($address, '', EZMLM_DEL);
      return $cnt;
    }
    
    /**
     * Modify address
     *
     * @access  public
     * @param   string from
     * @param   string to
     * @return  int count
     */
    function alterAdress($from, $to) {
      $cnt= $this->db->update('
        %c.%c
        set
          address= %s
        where address= %s
        ',
        $this->database,
        $this->mailinglist,
        $to,
        $from
      );
      $cnt && $this->writeLog($to, $from, EZMLM_MOD);
      return $cnt;
    }
    
    /**
     * Write log information
     *
     * @access  protected
     * @param   string addr
     * @param   string from
     * @param   string action
     * @param   string who
     */
    function writeLog($addr, $from, $action, $who= EZMLM_WHO) {
      $this->db->insert('
        %c.%c_slog (
          tai,
          address,
          fromline,
          edit,
          etype
        ) values (
          now(),
          %s,
          %s,
          %s,
          %s
        )',
        $this->database,
        $this->mailinglist,
        $addr,
        $from,
        $action,
        $who
      );
    }    
  }
?><commit_msg>- fix some copy&paste errors<commit_after><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  // Defines for log
  define('EZMLM_ADD',     '+');
  define('EZMLM_DEL',     '-');
  define('EZMLM_MOD',     '%');
  
  define('EZMLM_WHO',     'w');

  /**
   * Helper class to maintain sql based ezmlm mailinglists.
   *
   * @see      http://ezmlm.org
   * @purpose  Maintain mailing list subscriptions
   */
  class EzmlmSqlUtil extends Object {
    var
      $db=          NULL,
      $database=    '',
      $mailinglist= '';
      
    /**
     * Constructor.
     *
     * @access  public
     * @param   string database
     * @param   string mailinglist
     */
    function __construct($database, $mailinglist) {
      $this->database= $database;
      $this->mailinglist= $mailinglist;
    }
    
    /**
     * Set connection,
     *
     * @access  public
     * @param   &rdbms.mysql.MysqlConnection db
     */
    function setConnection(&$db) {
      $this->db= &$db;
    }
  
    /**
     * Check whether address is subscribed
     *
     * @access  public
     * @param   string address
     * @return  bool
     */
    function isSubscribed($address) {
      $s= $this->db->select('
          1
        from
          %c.%c
        where address= %s
          and hash between 1 and 52
        ',
        $this->database,
        $this->mailinglist,
        $address
      );
      
      return (bool)sizeof($s);
    }
    
    /**
     * Get list of subscribers
     *
     * @access  public
     * @return  string[]
     */
    function getSubscribers() {
      $q= &$this->db->query('
        select
          address
        from
          %c.%c
        where hash between 1 and 52
        ',
        $this->database,
        $this->mailinglist
      );
      $s= array();
      while ($q && $r= $q->next('address')) { $s[]= $r; }
      return $s;
    }
    
    /**
     * Add subscriber
     *
     * @access  public
     * @param   string address
     */
    function addSubscriber($address) {
      $this->db->insert('
        into %c.%c (
          hash,
          address
        ) values (
          %d,
          %s
        )',
        $this->database,
        $this->mailinglist,
        (int)rand(1, 52),
        $address
      );
      $this->writeLog($address, '', EZMLM_ADD);
    }
    
    /**
     * Remove subscriber
     *
     * @access  public
     * @param   string address
     * @return  int
     */
    function removeSubscriber($address) {
      $cnt= $this->db->delete('
        from 
          %c.%c
        where address= %s
        ',
        $this->database,
        $this->mailinglist,
        $address
      );
      $cnt && $this->writeLog($address, '', EZMLM_DEL);
      return $cnt;
    }
    
    /**
     * Modify address
     *
     * @access  public
     * @param   string from
     * @param   string to
     * @return  int count
     */
    function alterAddress($from, $to) {
      if (!$this->isSubscribed($from)) return FALSE;
      $cnt= $this->db->update('
        %c.%c
        set
          address= %s
        where address= %s
        ',
        $this->database,
        $this->mailinglist,
        $to,
        $from
      );
      $cnt && $this->writeLog($to, $from, EZMLM_MOD);
      return $cnt;
    }
    
    /**
     * Write log information
     *
     * @access  protected
     * @param   string addr
     * @param   string from
     * @param   string action
     * @param   string who
     */
    function writeLog($addr, $from, $action, $who= EZMLM_WHO) {
      $this->db->insert('
        %c.%c_slog (
          tai,
          address,
          fromline,
          edir,
          etype
        ) values (
          now(),
          %s,
          %s,
          %s,
          %s
        )',
        $this->database,
        $this->mailinglist,
        $addr,
        $from,
        $action,
        $who
      );
    }    
  }
?>
{'fraction_non_alphanumeric': 0.13913267940113577, 'fraction_numerical': 0.002581311306143521, 'mean_word_length': 1.3354430379746836, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '360480', 'n_tokens_mistral': 2546, 'n_tokens_neox': 2476, 'n_words': 533}