Plugin Directory

Changeset 933680


Ignore:
Timestamp:
06/17/2014 01:09:29 PM (12 years ago)
Author:
marisp
Message:
  • Fixed unsubscribes analytics with double opt-out option enabled.
  • Fixed processing of analytics enabled links on sites installed in sub-directories.
  • Fixed false-positive SPAM detection during form submission in Internet Explorer.
Location:
wpnewsman-newsletters/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • wpnewsman-newsletters/trunk/api.php

    r929655 r933680  
    1313        $loc = "UTF-8";
    1414        putenv("LANG=$loc");
     15
    1516        $loc = setlocale(LC_ALL, $loc);
    1617
    17         if ( function_exists('ob_gzhandler') ) {
    18             function ob_gz_handler_no_errors($buffer)
    19             {
    20                 @ob_gzhandler($buffer);
    21             }
    22             ob_start('ob_gzhandler');
    23         }
     18        // UNCOMMENT IN PRODUCTION
     19
     20        // if ( function_exists('ob_gzhandler') ) {
     21        //  function ob_gz_handler_no_errors($buffer)
     22        //  {
     23        //      ob_gzhandler($buffer);
     24        //  }
     25        //  ob_start('ob_gzhandler');
     26        // }
    2427
    2528        $o = newsmanOptions::getInstance();
     
    4346        }
    4447
    45         call_user_method($method, $this);
     48        call_user_func(array($this, $method));
    4649    }
    4750
     
    6568
    6669        header("Content-type: application/json");
     70
     71        //ob_end_clean();
    6772       
    6873        echo json_encode( $u->utf8_encode_all($msg) );
     74
     75        //ob_flush();       
    6976           
    7077        if ($db) $db->close(); 
     
    149156
    150157    public function ajGetLists() {
     158        global $newsman_current_subscriber;
     159        global $newsman_current_list;
     160
     161        $newsman_current_subscriber = array( 'ucode' => '' );
     162
    151163        $r = array();
    152164
    153         $lists = newsmanList::findALL();
     165        $n = newsman::getInstance();
     166
     167        $lists = newsmanList::findALL();       
    154168
    155169        foreach ($lists as $list) {
     170            $newsman_current_list = $list;
    156171            $r[] = array(
    157172                'id' => $list->id,
    158173                'uid' => $list->uid,
    159                 'name' => $list->name
     174                'name' => $list->name,
     175                'confirmed' => $list->countSubs(NEWSMAN_SS_CONFIRMED),
     176                'unsubscribeURL' => $n->getActionLink('unsubscribe', false, false, 'DROP_EMAIL_IDENTIFIER')
    160177            );
    161178        }
    162179
    163180        $this->respond(true, $r);
     181    }
     182
     183    private function buildExtraQuery() {
     184        global $wpdb;
     185
     186        $validTimeUnits = array('MICROSECOND', 'SECOND', 'MINUTE', 'HOUR', 'DAY', 'WEEK', 'MONTH', 'QUARTER', 'YEAR');
     187       
     188        $extraQuery = array();
     189
     190        $timeInList = $this->param('timeInList', false);       
     191        if ( $timeInList ) {
     192            $til = explode(',', $timeInList);
     193            $tilNum = intval($til[0]);
     194            $tilUnit = isset($til[1]) ? strtoupper($til[1]) : 'DAY';
     195            if ( in_array($tilUnit, $validTimeUnits) ) {
     196                // no need to use wpdb->prepare here becuase all vars are checked
     197                $extraQuery[] = "TIMESTAMPDIFF($tilUnit, NOW(), ts) >= $tilNum";
     198            }           
     199        }
     200
     201        //view-source:blog.dev/wp-content/plugins/wpnewsman/api.php?method=downloadList&key=575d037167f77f3b1c01c7fff7b9d31282009867&listId=18
     202
     203        $emailIn = $this->param('emailIn', false);     
     204
     205        if ( $emailIn ) {
     206            $args = explode(',', $emailIn);
     207            $placeholders = array();
     208            foreach ($args as $email) {
     209                $placeholders[] = '%s';
     210            }
     211
     212            $set = 'email in ('.implode(',', $placeholders).')'; // (%s, %s, ...)
     213
     214            array_unshift($args, $set); // placeing set SQL part before the emails
     215           
     216            $set = call_user_func_array(array($wpdb, 'prepare'), $args);
     217            $extraQuery[] = $set;
     218        }
     219
     220        if ( !empty($extraQuery) ) {
     221            define('newsman_csv_export_query', implode(' AND ', $extraQuery));
     222        }
     223        $u = newsmanUtils::getInstance();
     224        $u->log('[buildExtraQuery] %s', newsman_csv_export_query);
    164225    }
    165226
     
    169230        $limit = $this->param('limit', false);
    170231        $offset = $this->param('offset', false);
     232        $map = $this->param('map', '');
     233
     234        $nofile = $this->param('nofile', false);
     235
     236        if ( is_string($nofile)  ) {
     237            $nofile = ( $nofile === '1' || strtolower($nofile) == 'true' );
     238        }
     239
     240        global $newsman_export_fields_map;
     241
     242        if ( $map ) {
     243            $map = explode(',', $map);
     244            $newsman_export_fields_map = array();
     245            foreach ($map as $pair) {
     246                $p = explode(':', $pair);
     247                $newsman_export_fields_map[ $p[0] ] = $p[1];
     248            }
     249        }
    171250
    172251        if ( $limit ) {
     
    177256            define('newsman_csv_export_offset', $offset);
    178257        }
     258
     259        $this->buildExtraQuery();
    179260
    180261        $list = newsmanList::findOne('id = %d', array($listId));
     
    204285        // 'confirmation-link', 'resend-confirmation-link', 'unsubscribe-link'
    205286
    206         $list->exportToCSV($fileName, 'all', $linkTypes);
     287        $list->exportToCSV($fileName, 'all', $linkTypes, !$nofile);
     288    }
     289
     290    public function ajGetListFields() {
     291        $listId = $this->param('listId');
     292
     293        $list = newsmanList::findOne('id = %d', array($listId));
     294
     295        if ( !$list ) {
     296            $this->respond(false, sprintf( __( 'List with id "%s" is not found.', NEWSMAN), $listId), array(), '404 Not found');
     297        }
     298
     299        $fields = $list->getAllFields();
     300
     301        $this->respond(true, array(
     302            'fields' => $fields
     303        ));
    207304    }
    208305}
  • wpnewsman-newsletters/trunk/class.analytics.php

    r929655 r933680  
    4848        // /c/{emailId}/{listId}/{subId}/{linkId}
    4949        // http://blog.dev/c/3d-a-oo-go
    50         if ( preg_match('#^\/(o|c)\/((?:[a-z0-9]+\-){2,3}(?:[a-z0-9]+))#', strtolower($_SERVER['REQUEST_URI']), $matches ) ) {
     50        if ( preg_match('#\/(o|c)\/((?:[a-z0-9]+\-){2,3}(?:[a-z0-9]+))#', strtolower($_SERVER['REQUEST_URI']), $matches ) ) {
    5151            $op = $matches[1];
    5252            $args = $this->decodeIdsArray(explode('-', $matches[2]));
  • wpnewsman-newsletters/trunk/class.emails.php

    r930191 r933680  
    6363        $this->embedStyles();
    6464        $this->addAnalytics();
     65
    6566
    6667        return parent::save();
     
    169170        $url = $matches[3];
    170171
     172        $u = newsmanUtils::getInstance();
     173        $u->log('wrapping URL: %s', $url);
     174
    171175        // if not unsubscribe or "view online" link
    172176        if ( strpos($url, 'newsman=unsubscribe') === false &&
     
    193197                base_convert($link->id, 10, 36)
    194198            );         
     199            $u->log('wrapped: %s', $url);
    195200        }
    196201
  • wpnewsman-newsletters/trunk/class.list.php

    r929655 r933680  
    168168    }
    169169
     170
     171    public function countSubs($stat) {
     172        global $wpdb;
     173
     174        $u = newsmanUtils::getInstance();
     175        $sql = "SELECT COUNT(id) as cnt FROM $this->tblSubscribers WHERE status = %d";
     176        return intval($wpdb->get_var($wpdb->prepare($sql, $stat)));;
     177    }
     178
    170179    public function setStatus($ids, $status) {
    171180        global $wpdb;
     
    343352    }   
    344353
    345     public function getSubscribers($offset = 0, $limit = 100, $type = 'all', $q = false) {
     354    public function getSubscribers($offset = 0, $limit = 100, $type = 'all', $q = false, $rawQuery = false) {
    346355        global $wpdb;
    347356
     
    371380
    372381        if ( $q ) {
    373             $word = empty($sel) ? ' WHERE' : ' AND';
    374             $sel .= $word.' email regexp %s';
    375             $sel = $wpdb->prepare($sel, $u->preg_quote($q));
    376         }
     382            if ( $rawQuery ) {
     383                $word = empty($sel) ? ' WHERE' : ' AND';
     384                $sel .= $word.' '.$q;
     385            } else {
     386                $word = empty($sel) ? ' WHERE' : ' AND';
     387                $sel .= $word.' email regexp %s';
     388                $sel = $wpdb->prepare($sel, $u->preg_quote($q));               
     389            }
     390        }       
    377391
    378392        $sql = "SELECT * FROM $this->tblSubscribers ".$sel." ORDER BY `ts` DESC LIMIT %d, %d";
     393
    379394        $sql = $wpdb->prepare($sql, $offset, $limit);
    380395
     
    601616    private function subsToCSV($file, $fields, $type = 'all') {
    602617
    603         if ( defined('newsman_csv_export_limit') || defined('newsman_csv_export_offset') ) {
     618        if (
     619            defined('newsman_csv_export_limit') ||
     620            defined('newsman_csv_export_offset') ||
     621            defined('newsman_csv_export_query')
     622        ) {
    604623            $offset = defined('newsman_csv_export_offset') ? newsman_csv_export_offset : 0;
    605624            $limit  = defined('newsman_csv_export_limit') ? newsman_csv_export_limit : 100;
    606 
    607             $res = $this->getSubscribers($offset, $limit, $type);
     625            $query  = defined('newsman_csv_export_query') ? newsman_csv_export_query : false;
     626
     627            $res = $this->getSubscribers($offset, $limit, $type, $query, 'RAW_SQL_QUERY');
    608628            if ( is_array($res) && !empty($res)  ) {
    609629                foreach ($res as $sub) {
     
    631651    }
    632652
    633     public function exportToCSV($filename, $type = 'all', $linksFields = array()) {
    634         header( 'Content-Type: text/csv' );
    635         header( 'Content-Disposition: attachment;filename='.$filename);
     653    public function exportToCSV($filename, $type = 'all', $linksFields = array(), $forceFileOutput = true) {
     654        global $newsman_export_fields_map;
     655        if ( $forceFileOutput ) {
     656            header( 'Content-Type: text/csv' );
     657            header( 'Content-Disposition: attachment;filename='.$filename);         
     658        }
     659
     660        //var_dump($newsman_export_fields_map);
     661
     662        if ( isset($_REQUEST['debug']) ) {
     663            echo '<pre>'; // FOR DEBUG ONLY
     664        }       
    636665
    637666        $out = fopen('php://output', 'w');
     
    640669
    641670            $fields = array_merge($fields, $linksFields);
    642 
    643             fputcsv($out, $fields, ',', '"');
     671            $mappedFields = array();
     672
     673            if ( isset($newsman_export_fields_map) ) {
     674                foreach ($fields as &$field) {
     675                    $mappedFields[] = isset($newsman_export_fields_map[$field]) ? $newsman_export_fields_map[$field] : $field;
     676                }
     677            } else {
     678                $mappedFields = $fields;
     679            }
     680
     681            fputcsv($out, $mappedFields, ',', '"');
    644682            $this->subsToCSV($out, $fields, $type);
    645683            @fclose($out);         
     684        }
     685
     686        if ( isset($_REQUEST['debug']) ) {
     687            echo '</pre>'; // FOR DEBUG ONLY
    646688        }
    647689    }
  • wpnewsman-newsletters/trunk/class.utils.php

    r929655 r933680  
    750750
    751751    public function linkNormalizationCallback($matches) {
    752         return $matches[1].urldecode(html_entity_decode($matches[4])).$matches[5];
     752        $url = $matches[4];
     753        if ( preg_match('/^(\[|%5B)/i', $url) ) {
     754            $url = urldecode(html_entity_decode($url));
     755        }
     756        return $matches[1].$url.$matches[5];
    753757    }
    754758   
  • wpnewsman-newsletters/trunk/core.php

    r930191 r933680  
    406406                return $newsman_loop_post_nr;
    407407            } else if ( $post == "permalink" ) {
    408                 $this->utils->log('[newsmanShortCode] post = permalink');
    409                 $this->utils->log('[newsmanShortCode] newsman_current_email->emailAnalytics: %d', $newsman_current_email->emailAnalytics);
    410 
    411                 if ( $newsman_current_email->emailAnalytics ) {
    412                     return home_url('?p=' . $newsman_loop_post->ID);
    413                 } else {
    414                     return get_permalink( $newsman_loop_post->ID );     
    415                 }               
     408                return get_permalink( $newsman_loop_post->ID );     
    416409            } else if ( $post == "fancy_excerpt" ) {
    417410                if ( !isset($words) ) {
     
    557550    // links
    558551
    559     public function getActionLink($type, $only_code = false, $externalForm = false) {
     552    public function getActionLink($type, $only_code = false, $externalForm = false, $dropEmailPart = false) {
    560553        global $newsman_current_subscriber;
    561554        global $newsman_current_email;
     
    574567            $link = "$blogurl/?newsman=$type&code=".$newsman_current_list->uid.':'.$ucode;
    575568
    576             if ( in_array($type, array('email', 'unsubscribe')) ) {
     569            if ( in_array($type, array('email', 'unsubscribe', 'unsubscribe-confirmation')) && !$dropEmailPart ) {
    577570                $link.='&email='.$newsman_current_email->ucode;
    578571            }
     
    599592        global $newsman_current_email;
    600593        global $newsman_current_list;
     594
     595        if ( !isset($newsman_current_email) ) { return; }
    601596
    602597        $sd = new newsmanAnSubDetails();
     
    20362031            'query_var' => "subscription", // This goes to the WP_Query schema
    20372032            'supports' => array('title', 'excerpt', 'editor' /*,'custom-fields'*/), // Let's use custom fields for debugging purposes only
    2038             'register_meta_box_cb' => array($this, 'add_shortcode_metabox')
     2033            'register_meta_box_cb' => array($this, 'add_shortcode_metabox'),
     2034            'exclude_from_search' => true
    20392035        ));
    20402036
     
    22652261                $sub = $list->findSubscriber("id = %s", 1);
    22662262                $c = $eml->renderMessage($sub->toJSON());
    2267                 $c = $c['html'];
    2268 
     2263                echo $c['html'];
     2264
     2265            } elseif ( isset($_REQUEST['processed2']) ) {
     2266                echo $eml->p_html;
    22692267            } else {
    2270                 $c = $eml->html;
    2271             }
    2272             echo $eml->html; //echo $this->utils->processAssetsURLs($c, $eml->assetsURL);
     2268                echo $eml->html;
     2269            }
     2270            //echo $eml->html; //echo $this->utils->processAssetsURLs($c, $eml->assetsURL);
    22732271        }
    22742272        die();
  • wpnewsman-newsletters/trunk/js/jquery.placeholder.js

    r703446 r933680  
    11/*! http://mths.be/placeholder v2.0.7 by @mathias */
    22;(function(f,h,$){var a='placeholder' in h.createElement('input'),d='placeholder' in h.createElement('textarea'),i=$.fn,c=$.valHooks,k,j;if(a&&d){j=i.placeholder=function(){return this};j.input=j.textarea=true}else{j=i.placeholder=function(){var l=this;l.filter((a?'textarea':':input')+'[placeholder]').not('.placeholder').bind({'focus.placeholder':b,'blur.placeholder':e}).data('placeholder-enabled',true).trigger('blur.placeholder');return l};j.input=a;j.textarea=d;k={get:function(m){var l=$(m);return l.data('placeholder-enabled')&&l.hasClass('placeholder')?'':m.value},set:function(m,n){var l=$(m);if(!l.data('placeholder-enabled')){return m.value=n}if(n==''){m.value=n;if(m!=h.activeElement){e.call(m)}}else{if(l.hasClass('placeholder')){b.call(m,true,n)||(m.value=n)}else{m.value=n}}return l}};a||(c.input=k);d||(c.textarea=k);$(function(){$(h).delegate('form','submit.placeholder',function(){var l=$('.placeholder',this).each(b);setTimeout(function(){l.each(e)},10)})});$(f).bind('beforeunload.placeholder',function(){$('.placeholder').each(function(){this.value=''})})}function g(m){var l={},n=/^jQuery\d+$/;$.each(m.attributes,function(p,o){if(o.specified&&!n.test(o.name)){l[o.name]=o.value}});return l}function b(m,n){var l=this,o=$(l);if(l.value==o.attr('placeholder')&&o.hasClass('placeholder')){if(o.data('placeholder-password')){o=o.hide().next().show().attr('id',o.removeAttr('id').data('placeholder-id'));if(m===true){return o[0].value=n}o.focus()}else{l.value='';o.removeClass('placeholder');l==h.activeElement&&l.select()}}}function e(){var q,l=this,p=$(l),m=p,o=this.id;if(l.value==''){if(l.type=='password'){if(!p.data('placeholder-textinput')){try{q=p.clone().attr({type:'text'})}catch(n){q=$('<input>').attr($.extend(g(this),{type:'text'}))}q.removeAttr('name').data({'placeholder-password':true,'placeholder-id':o}).bind('focus.placeholder',b);p.data({'placeholder-textinput':q,'placeholder-id':o}).before(q)}p=p.removeAttr('id').hide().prev().attr('id',o).show()}p.addClass('placeholder');p[0].value=p.attr('placeholder')}else{p.removeClass('placeholder')}}}(this,document,jQuery));
    3 jQuery(function($){ $('input, textarea').placeholder(); });
     3jQuery(function($){
     4    $('.newsman-form input:visible, .newsman-form textarea:visible').not('[type="hidden"]').placeholder();
     5});
     6
     7
     8//TODO: unfinished. check the code above
     9// var oldJQuery = jQuery;
     10// jQuery = function(fn){   
     11//  if ( fn.toString().indexOf("$('input, textarea').placeholder()") >= 0 ) {
     12//      return oldJQuery.apply(oldJQuery, arguments);
     13//  }
     14// };
  • wpnewsman-newsletters/trunk/readme.txt

    r930191 r933680  
    55Requires at least: 3.5
    66Tested up to: 4.0
    7 Stable tag: 1.7.1
     7Stable tag: 1.7.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5858* French (completed)
    5959* Russian (completed)
    60 * German (Germany) (99%)
     60* German (Germany) (completed)
    6161* Polish (99%)
    6262* Italian (Italy) (50%)
     
    124124
    125125== Changelog ==
     126
     127= 1.7.2 =
     128
     129* Fixed unsubscribes analytics with double opt-out option enabled.
     130* Fixed processing of analytics enabled links on sites installed in sub-directories.
     131* Fixed false-positive SPAM detection during form submission in Internet Explorer.
    126132
    127133= 1.7.1 =
  • wpnewsman-newsletters/trunk/views/welcome.php

    r930191 r933680  
    88        <?php else: ?>
    99            <div class="about-text">You updated and have better newsletter gadget!</div>
     10
     11           
    1012        <?php endif; ?>
    1113       
  • wpnewsman-newsletters/trunk/workers/class.mailer.php

    r930191 r933680  
    6666        $sl = newsmanSentlog::getInstance();
    6767
     68        $u->log("[launchSender] p_html 1 \n%s", $email->p_html);
     69
    6870        $tStreamer = new newsmanTransmissionStreamer($email);
    6971
     
    112114
    113115        $email->p_html = $u->processAssetsURLs($email->p_html, $email->assetsURL);
    114         $email->p_html = $u->compileThumbnails($email->p_html); 
     116        $email->p_html = $u->compileThumbnails($email->p_html);
    115117
    116118        $this->processMessages();
  • wpnewsman-newsletters/trunk/wpnewsman.php

    r930191 r933680  
    44Plugin URI: http://wpnewsman.com
    55Description: You get simple yet powerful newsletter solution for WordPress. Now you can easily add double optin subscription forms in widgets, articles and pages, import and manage your lists, create and send beautiful newsletters directly from your WordPress site. You get complete freedom and a lower cost compared to Email Service Providers. Free yourself from paying for expensive email campaigns. WPNewsman plugin updated regularly with new features.
    6 Version: 1.7.1
     6Version: 1.7.2
    77Author: Alex Ladyga - G-Lock Software
    88Author URI: http://www.glocksoft.com
     
    3232
    3333define('NEWSMAN', 'wpnewsman');
    34 define('NEWSMAN_VERSION', '1.7.1');
     34define('NEWSMAN_VERSION', '1.7.2');
    3535
    3636if ( preg_match('/.*?\.dev$/i', $_SERVER['HTTP_HOST']) ) {
Note: See TracChangeset for help on using the changeset viewer.