/[drupal]/contributions/modules/mlm/backend/mlm_ezmlm_idx.inc
ViewVC logotype

Diff of /contributions/modules/mlm/backend/mlm_ezmlm_idx.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.4, Sun Aug 23 23:06:28 2009 UTC revision 1.5, Wed Aug 26 23:03:36 2009 UTC
# Line 1  Line 1 
1  <?php // $Id: mlm_ezmlm_idx.inc,v 1.3 2009/08/10 01:09:32 vauxia Exp $  <?php // $Id: mlm_ezmlm_idx.inc,v 1.4 2009/08/23 23:06:28 vauxia Exp $
2    
3  /**  /**
4   * @file   * @file
# Line 11  class mlm_ezmlm_idx extends mlm_ezmlm { Line 11  class mlm_ezmlm_idx extends mlm_ezmlm {
11    var $autopost = NULL;    var $autopost = NULL;
12    var $autopost_key = NULL;    var $autopost_key = NULL;
13    
14      function autopost() {
15        return variable_get('mlm_ezmlm_idx_autopost', FALSE);
16      }
17    
18    function edit_form(&$form) {    function edit_form(&$form) {
19      $edit_form = parent::edit_form($form);      $edit_form = parent::edit_form($form);
20    
# Line 36  class mlm_ezmlm_idx extends mlm_ezmlm { Line 40  class mlm_ezmlm_idx extends mlm_ezmlm {
40      if (!preg_match('/^[a-z0-9_]*$/i', $values['troot'])) {      if (!preg_match('/^[a-z0-9_]*$/i', $values['troot'])) {
41        form_set_error('troot', t('Invalid format for table prefix'));        form_set_error('troot', t('Invalid format for table prefix'));
42      }      }
43      if ($values['mlm_ezmlm_idx_autopost']) {      if ($this->autopost()) {
44        if (!$values['key']) {        if (!$values['key']) {
45          form_set_error('key', t('List Key is required for auto-moderation'));          form_set_error('key', t('List Key is required for auto-moderation'));
46        }        }
# Line 44  class mlm_ezmlm_idx extends mlm_ezmlm { Line 48  class mlm_ezmlm_idx extends mlm_ezmlm {
48    }    }
49    
50    function edit_form_submit($form, &$form_state, &$values) {    function edit_form_submit($form, &$form_state, &$values) {
51      if ($this->autopost) {      if ($this->autopost()) {
52        $table   = $this->_table('post');        $table   = $this->_table('post');
53    
54        $this->_db(TRUE);        $this->_db(TRUE);
# Line 115  class mlm_ezmlm_idx extends mlm_ezmlm { Line 119  class mlm_ezmlm_idx extends mlm_ezmlm {
119    
120    function subscribe() {    function subscribe() {
121      $table =  $this->_table();      $table =  $this->_table();
122      $mail = $this->account->mail;      $mail  = $this->account->mail;
123      $this->_db(TRUE);      $this->_db(TRUE);
124    
125      db_query("INSERT INTO %s ( hash, address )      db_query("INSERT INTO %s ( hash, address )
# Line 129  class mlm_ezmlm_idx extends mlm_ezmlm { Line 133  class mlm_ezmlm_idx extends mlm_ezmlm {
133    
134    function unsubscribe() {    function unsubscribe() {
135      $mail = $this->account->mail;      $mail = $this->account->mail;
136        $table = $this->_table();
137      $this->_db(TRUE);      $this->_db(TRUE);
138    
139      db_query("DELETE FROM %s WHERE address = '%s'", $this->_table(), $mail);      db_query("DELETE FROM %s WHERE address = '%s'", $table, $mail);
140      if (db_affected_rows()) {      if (db_affected_rows()) {
141        db_query("INSERT INTO %s ( tai, address, fromline, edir) VALUES ( '%s', '%s', '%s', '-')"        db_query("INSERT INTO %s ( tai, address, fromline, edir) VALUES ( '%s', '%s', '%s', '-')"
142          , $this->_table('slog'), date('Y-m-d H:i:s', time()), $mail, $mail);          , $this->_table('slog'), date('Y-m-d H:i:s', time()), $mail, $mail);
# Line 141  class mlm_ezmlm_idx extends mlm_ezmlm { Line 146  class mlm_ezmlm_idx extends mlm_ezmlm {
146    }    }
147    
148    function count() {    function count() {
149        $table = $this->_table();
150      $this->_db(TRUE);      $this->_db(TRUE);
151      $count = db_result(db_query("SELECT COUNT(1) FROM %s", $this->_table()));      $count = db_result(db_query("SELECT COUNT(*) FROM $table"));
152      $this->_db();      $this->_db();
153      return $count;      return $count;
154    }    }
155    
156      function subscriber_fields() {
157        return array('mail' => t('E-mail'));
158      }
159    
160    function subscribers($limit = NULL) {    function subscribers($limit = NULL) {
161        $table = $this->_table();
162      $this->_db(TRUE);      $this->_db(TRUE);
163      // it would be cool to join against the users table, but it may be a different DSN      // it would be cool to join against the users table, but it may be a different DSN
164      $table = $this->_table();      $func = $limit ? 'pager_query' : 'db_query';
165      $res = pager_query("SELECT l.address AS mail FROM $table l      $res = $func("SELECT l.address AS mail FROM $table l
166                    ORDER BY l.address", $limit);                    ORDER BY l.address", $limit);
167      $this->_db();      $this->_db();
168      return $res;      return $res;
169    }    }
170    
171    function is_subscribed() {    function is_subscribed() {
172        $table = $this->_table();
173      $this->_db(TRUE);      $this->_db(TRUE);
174      $res = (boolean) db_result(db_query("SELECT 1 FROM %s      $res = (boolean) db_result(db_query("SELECT 1 FROM %s
175                  WHERE address = '%s' LIMIT 1", $this->_table(), $this->account->mail));                  WHERE address = '%s' LIMIT 1", $table, $this->account->mail));
176      $this->_db();      $this->_db();
177      return $res;      return $res;
178    }    }
179    
180    function post($message, $account = NULL) {    function post($message, $account = NULL) {
181      $address = $this->settings('address');      $address = $this->settings('address');
182      if ($this->autopost) {      if ($this->autopost()) {
183        global $base_url;        global $base_url;
184          global $user;
185        $table   = $this->_table('post');        $table   = $this->_table('post');
186        $key     = $this->settings('key');        $key     = $this->settings('key');
187        $created = time();        $created = db_result(db_query("SELECT UNIX_TIMESTAMP()"));
188        $hash    = sha1($id . $subject . $created . $key);        $hash    = sha1($base_url . $created . $key);
189        $address = str_replace('@', "-autopost-{$hash}@", $address);        $address = str_replace('@', "-autopost-{$hash}@", $address);
190    
191        $this->_db(TRUE);        $this->_db(TRUE);
192        db_query("INSERT INTO %s (uid, website, subject, created, sent)        db_query("INSERT INTO %s (uid, website, subject, created, sent)
193          VALUES (%d, %d, '%s', '%s', UNIX_TIMESTAMP(NOW()), 0)",          VALUES (%d, '%s', '%s', %d, 0)",
194          $table, $user->uid, $base_url, $subject);          $table, $user->uid, $base_url, $message['subject'], $created);
195        $this->_db();        $this->_db();
196      }      }
197      mimemail($account, $address, $message['subject'], $message['body']);      mimemail($account, $address, $message['subject'], $message['body']);
# Line 212  class mlm_ezmlm_idx extends mlm_ezmlm { Line 225  class mlm_ezmlm_idx extends mlm_ezmlm {
225      }      }
226    }    }
227    function _db($active = FALSE) {    function _db($active = FALSE) {
228      $db = $active ? $this->settings('dsn') : NULL;      $db = $active ? variable_get('mlm_ezmlm_idx_dsn', NULL) : NULL;
229      db_set_active($db);      db_set_active($db);
230    }    }
231  }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.2