[ Index ]

MailPress 7.2

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-content/add-ons/ -> MailPress_tracking.php (source)

   1  <?php
   2  if ( class_exists( 'MailPress' ) && !class_exists( 'MailPress_tracking' ) )
   3  {
   4  /*
   5  Plugin Name: MailPress_tracking
   6  Plugin URI: http://blog.mailpress.org/tutorials/add-ons/tracking/
   7  Description: Tracking : mails &amp; users activity
   8  Version: 7.2
   9  */
  10  
  11  /** for admin plugin pages */
  12  define ( 'MailPress_page_tracking_m', MailPress_page_mails . '&file=tracking' );
  13  define ( 'MailPress_page_tracking_u', MailPress_page_users . '&file=tracking' );
  14  
  15  /** for admin plugin urls */
  16  $mp_file = 'admin.php';
  17  define ( 'MailPress_tracking_m',    add_query_arg( 'page', MailPress_page_tracking_m,     $mp_file ) );
  18  define ( 'MailPress_tracking_u',    add_query_arg( 'page', MailPress_page_tracking_u,     $mp_file ) );
  19  
  20  /** for mysql */ 
  21  global $wpdb;
  22  $wpdb->mp_tracks = $wpdb->prefix . 'mailpress_tracks';
  23  
  24  define ( 'MailPress_tracking_openedmail',     '_MailPress_mail_opened' );
  25  
  26  class MailPress_tracking
  27  {
  28      const option_name = 'MailPress_tracking';
  29  
  30  	function __construct()
  31      {
  32  // for wordpress hooks
  33          add_action( 'init',                      array( __CLASS__, 'init' ), 100 );
  34  // for mails list
  35          add_filter( 'MailPress_mails_actions',     array( __CLASS__, 'mails_actions' ),  8, 3 );
  36  // for users list
  37          add_filter( 'MailPress_users_actions',     array( __CLASS__, 'users_actions' ),  8, 3 );
  38  //        add_filter( 'MailPress_bulk_actions_'   . MailPress_page_users,    array( __CLASS__, 'bulk_actions_mailpress_users' ), 8, 1 );
  39  //        add_action( 'MailPress_do_bulk_action_' . MailPress_page_users,    array( __CLASS__, 'do_bulk_action_mailpress_users' ), 8, 2 );
  40  // for referential integrity
  41          add_action( 'MailPress_delete_mail',      array( __CLASS__, 'delete_mail' ), 1, 1 );
  42  //        add_action( 'MailPress_delete_user',      array( __CLASS__, 'delete_user' ), 1, 1 );
  43          add_action( 'MailPress_unsubscribe_user',    array( __CLASS__, 'unsubscribe_user' ), 1, 1 );
  44          add_action( 'MailPress_list_unsubscribe_user',    array( __CLASS__, 'list_unsubscribe_user' ), 1, 4 );
  45  // prepare mail
  46          add_filter( 'MailPress_is_tracking',      array( __CLASS__, 'is_tracking' ), 1, 1 );
  47          add_filter( 'MailPress_header_url',        array( __CLASS__, 'header_url' ), 8, 2 );
  48          add_filter( 'MailPress_mail',            array( __CLASS__, 'mail' ), 8, 2 );
  49  // process link
  50          add_action( 'mp_tracking_process',        array( __CLASS__, 'process' ), 8, 1 );
  51                  
  52          if ( is_admin() )
  53          {
  54          // install
  55              register_activation_hook( plugin_basename( __FILE__ ),     array( __CLASS__, 'install' ) );
  56          // for link on plugin page
  57              add_filter( 'plugin_action_links',         array( __CLASS__, 'plugin_action_links' ), 10, 2 );
  58          // for role & capabilities
  59              add_filter( 'MailPress_capabilities',      array( __CLASS__, 'capabilities' ), 1, 1 );
  60          // for load admin page
  61              add_filter( 'MailPress_load_admin_page',     array( __CLASS__, 'load_admin_page' ), 10, 1 );
  62          // for settings
  63              add_filter( 'MailPress_settings_tab',     array( __CLASS__, 'settings_tab' ), 40, 1 );
  64          // for autorefresh
  65              add_filter( 'MailPress_autorefresh_js',    array( __CLASS__, 'autorefresh_js' ), 8, 1 );
  66          }
  67      }
  68  
  69  	public static function init()
  70      {
  71      // for mails list
  72          if ( current_user_can( 'MailPress_tracking_mails' ) )
  73          {
  74              add_filter( 'MailPress_mails_columns',         array( __CLASS__, 'mails_columns' ), 8, 1 );
  75              add_filter( 'MailPress_mails_get_row',          array( __CLASS__, 'mails_get_row' ), 1, 4 );
  76          }
  77      }
  78  
  79  // for mails list
  80  	public static function mails_actions( $actions, $mail, $url_parms )
  81      {
  82          if ( !current_user_can( 'MailPress_tracking_mails' ) )    return $actions;
  83          if ( 'draft' == $mail->status )                    return $actions;
  84  
  85      // url
  86          $args = array();
  87          $args['id']     = $mail->id;
  88  
  89          $tracking_url     = esc_url( MP_::url( MailPress_tracking_m, array_merge( $args, $url_parms ) ) );
  90  
  91      // actions
  92          $actions['tracking'] = '<a href="' . $tracking_url . '" title="' . esc_attr( __( 'See tracking results', 'MailPress' ) ) . '">' . __( 'Tracking', 'MailPress' ) . '</a>';
  93  
  94          return $actions;
  95      }
  96  
  97  // for users list
  98  	public static function users_actions( $actions, $user, $url_parms )
  99      {
 100          if ( !current_user_can( 'MailPress_tracking_users' ) )    return $actions;
 101  
 102      // url
 103          $args = array();
 104          $args['id']     = $user->id;
 105  
 106          $tracking_url     = esc_url( MP_::url( MailPress_tracking_u, array_merge( $args, $url_parms ) ) );
 107  
 108      // actions
 109          $actions['tracking'] = '<a href="' . $tracking_url . '" title="' . esc_attr( __( 'See tracking results', 'MailPress' ) ) . '">' . __( 'Tracking', 'MailPress' ) . '</a>';
 110  
 111          return $actions;
 112      }
 113  
 114  	public static function bulk_actions_mailpress_users( $bulk_actions )
 115      {
 116          $bulk_actions['geolocate'] = __( 're-Geolocate', 'MailPress' );
 117          return $bulk_actions;
 118      }
 119  
 120  	public static function do_bulk_action_mailpress_users( $action, $checked )
 121      {
 122          if ( 'bulk-geolocate' != $action ) return false;
 123          $count = 0;
 124          foreach( $checked as $id ) if ( self::set_ip( $id ) ) $count++;
 125          return $count;
 126      }
 127  
 128  	public static function set_ip( $id )
 129      {
 130          global $wpdb;
 131  
 132          $ip = $wpdb->get_var( $wpdb->prepare( "SELECT ip FROM $wpdb->mp_tracks WHERE user_id = %d AND ip <> '' ORDER BY tmstp DESC LIMIT 1;", $id ) );
 133          if ( !$ip ) return false;
 134  
 135          return MP_User::set_ip( $id, $ip );
 136      }
 137  
 138  // for referential integrity
 139  	public static function delete_mail( $mail_id )
 140      {
 141          global $wpdb;
 142          $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->mp_usermeta WHERE meta_key = '_MailPress_mail_sent' AND meta_value = %d ; ", $mail_id ) );
 143          $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->mp_tracks   WHERE mail_id = %d ; ", $mail_id ) );
 144      }
 145  
 146  	public static function delete_by_mail_id( $mail_id )
 147      {
 148          global $wpdb;
 149          $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->mp_tracks   WHERE mail_id = %d ; ", $mail_id ) );
 150      }
 151  
 152  	public static function delete_user( $mp_user_id )
 153      {
 154          //self::delete_by_user_id( $mp_user_id );
 155      }
 156  
 157  	public static function delete_by_user_id( $mp_user_id )
 158      {
 159          global $wpdb;
 160          $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->mp_tracks WHERE user_id = %d ; ", $mp_user_id ) );
 161      }
 162  
 163  	public static function unsubscribe_user( $mp_user_id )
 164      {
 165          if ( !$mp_user_id ) return;
 166  
 167          $data = $format         = array();
 168  
 169          $REMOTE_ADDR         = filter_input( INPUT_SERVER, 'REMOTE_ADDR' );
 170          $HTTP_USER_AGENT     = filter_input( INPUT_SERVER, 'HTTP_USER_AGENT' );
 171          $HTTP_REFERER         = filter_input( INPUT_SERVER, 'HTTP_REFERER' );
 172  
 173          $data['user_id']     = $mp_user_id;                                            $format[] = '%d';
 174          $data['mail_id']     = 0;                                                    $format[] = '%d';
 175          $data['mmeta_id']     = 0;                                                    $format[] = '%d';
 176          $data['track']         = '!!unsubscribed!!';                                        $format[] = '%s';
 177          $data['context']     = '?';                                                $format[] = '%s';
 178          $data['ip']         = trim( $REMOTE_ADDR  );                                    $format[] = '%s';
 179          $data['agent']         = trim( $HTTP_USER_AGENT  );                                $format[] = '%s';
 180          $data['referrer']    = ( isset( $HTTP_REFERER ) ) ? trim( $HTTP_REFERER ) : '';            $format[] = '%s';
 181          $data['tmstp']        = current_time( 'mysql' );                                    $format[] = '%s';
 182  
 183          global $wpdb;
 184          $wpdb->insert( $wpdb->mp_tracks, $data, $format );
 185      }
 186  
 187  	public static function list_unsubscribe_user( $context, $mp_user, $list_id, $mail_id )
 188      {
 189          if ( !$mp_user ) return;
 190  
 191          $data = $format         = array();
 192  
 193          $REMOTE_ADDR         = filter_input( INPUT_SERVER, 'REMOTE_ADDR' );
 194          $HTTP_USER_AGENT     = filter_input( INPUT_SERVER, 'HTTP_USER_AGENT' );
 195          $HTTP_REFERER         = filter_input( INPUT_SERVER, 'HTTP_REFERER' );
 196  
 197          $data['user_id']     = $mp_user->id;                            $format[] = '%d';
 198          $data['mail_id']     = $mail_id;                            $format[] = '%d';
 199          $data['mmeta_id']     = 0;                                $format[] = '%d';
 200          $data['track']         = '!!list-unsubscribed!!';                    $format[] = '%s';
 201          $data['context']     = $context . '.' . $list_id;                    $format[] = '%s';
 202          $data['ip']         = trim( $REMOTE_ADDR  );                    $format[] = '%s';
 203          $data['agent']         = trim( $HTTP_USER_AGENT  );                    $format[] = '%s';
 204          $data['referrer']    = ( isset( $HTTP_REFERER ) ) ? trim( $HTTP_REFERER ) : '';    $format[] = '%s';
 205          $data['tmstp']        = current_time( 'mysql' );                    $format[] = '%s';
 206  
 207          global $wpdb;
 208          $wpdb->insert( $wpdb->mp_tracks, $data, $format );
 209      }
 210  // prepare mail
 211  	public static function is_tracking( $x )
 212      {
 213          return true;
 214      }
 215  
 216  	public static function header_url( $url, $mail )
 217      {
 218          $MP_Tracking_url = admin_url( 'admin-ajax.php' );
 219          $MP_Tracking_url_args = '?action=mp_tracking&tg=%1$s&mm=%2$s&co=%3$s&us={{_confkey}}';
 220  
 221          $meta_id = self::get_mmid( $mail->id, '_MailPress_mail_link', str_replace( '&amp;', '&', $url ) );
 222          $t_url = $MP_Tracking_url . sprintf( $MP_Tracking_url_args, 'l', $meta_id, 'h' );
 223          $t_url = apply_filters( 'MailPress_tracking_url', $t_url, $mail );
 224          return $t_url;
 225      }
 226  
 227  	public static function mail( $mail )
 228      {
 229          $MP_Tracking_url = admin_url( 'admin-ajax.php' );
 230          $MP_Tracking_url_args = '?action=mp_tracking&tg=%1$s&mm=%2$s&co=%3$s&us={{_confkey}}';
 231  
 232          foreach( $mail->recipients as $k => $v )
 233          {
 234              $toemail = ( MailPress::is_email( $k ) ) ? $k : $v;
 235              if ( isset( $mail->replacements[$toemail]['{{_confkey}}'] ) )
 236              {
 237                  MP_User_meta::add( MP_User::get_id_by_email( $toemail ), '_MailPress_mail_sent', $mail->id );
 238              }
 239          }
 240  
 241          $out = preg_match_all( '/<a [^>]*href=[\'"](.*?)[\'"]([^>]*)>/si', $mail->html, $matches, PREG_SET_ORDER );     /* was '/<a [^>]*href=[\'"]([^\'"]+)[\'"][^>]*>(.*?)<\/a>/is' */
 242  
 243          $hrefs_txt = array();
 244          if ( $matches )
 245          {
 246              foreach ( $matches as $match )
 247              {
 248                  if ( strpos( $match[1], 'mailto:' ) !== false ) continue;
 249                  if ( '#' == $match[1][1] ) continue;
 250                  if ( ( strpos( $match[1], get_home_url() ) === false ) && ( strpos( $match[1], '#' ) !== false ) ) continue;
 251  
 252                  $meta_id = self::get_mmid( $mail->id, '_MailPress_mail_link', str_replace( '&amp;', '&', $match[1] ) );
 253  
 254                  $t_url = $MP_Tracking_url . sprintf( $MP_Tracking_url_args, 'l', $meta_id, 'h' );
 255                  $t_url = apply_filters( 'MailPress_tracking_url', $t_url, $mail );
 256  
 257                  $link = self::str_replace_count( $match[1], $t_url, $match[0], 1 );
 258                  $mail->html = str_replace( $match[0], $link, $mail->html );
 259  
 260                  $t_url = 'ttrraacck_uurrll' . sprintf( $MP_Tracking_url_args, 'l', $meta_id, 'p' );
 261                  $t_url = apply_filters( 'MailPress_tracking_url', $t_url, $mail );
 262                  $hrefs_txt[$match[1]] = $t_url;
 263              }
 264          }
 265          $meta_id = self::get_mmid( $mail->id, MailPress_tracking_openedmail, MailPress_tracking_openedmail );
 266          $t_url = $MP_Tracking_url . sprintf( $MP_Tracking_url_args, 'o', $meta_id, 'h' );
 267          $t_url = apply_filters( 'MailPress_tracking_url', $t_url, $mail );
 268          $mail->html = str_ireplace( '</body>', "\n" . '<img src="' . $t_url . '" alt="" style="margin:0;padding:0;border:none;" /></body>', $mail->html );
 269  
 270          if ( !empty( $hrefs_txt ) )
 271          {
 272              uksort( $hrefs_txt, array( 'self', 'sort_hrefs_txt' ) );
 273              $hrefs_txt = array_reverse( $hrefs_txt );
 274              $t_url = apply_filters( 'MailPress_tracking_url', $MP_Tracking_url, $mail );
 275              $hrefs_txt['ttrraacck_uurrll'] = $t_url;
 276              $mail->plaintext = str_replace( array_keys( $hrefs_txt ), $hrefs_txt, $mail->plaintext );
 277          }
 278          return $mail;
 279      }
 280  
 281  	public static function sort_hrefs_txt( $a, $b ) 
 282      {
 283          return strcmp( strlen( $a ), strlen( $b ) );
 284      }
 285  
 286  	public static function str_replace_count( $search, $replace, $subject, $times=1 ) 
 287      {
 288          $subject_original=$subject;
 289  
 290          $len=strlen( $search );
 291          $pos=0;
 292          for ( $i=1;$i<=$times;$i++ ) 
 293          {
 294              $pos=strpos( $subject, $search, $pos );
 295              if( $pos!==false ) 
 296              {
 297                  $subject=substr( $subject_original, 0, $pos );
 298                  $subject.=$replace;
 299                  $subject.=substr( $subject_original, $pos+$len );
 300                  $subject_original=$subject;
 301              }
 302              else
 303              {
 304                  break;
 305              }
 306          }
 307          return( $subject );
 308      }
 309  
 310  	public static function get_mmid( $mail_id, $meta_key, $meta_value )
 311      {
 312          global $wpdb;
 313          $meta_id = $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM $wpdb->mp_mailmeta WHERE mp_mail_id = %d AND meta_key = %s AND meta_value = %s ;", $mail_id, $meta_key, $meta_value ) );
 314          if ( $meta_id ) return $meta_id;
 315          return MP_Mail_meta::add( $mail_id, $meta_key, $meta_value );
 316      }
 317  
 318  // process link
 319  
 320  	public static function process( $meta )
 321      {
 322          switch ( filter_input( INPUT_GET, 'tg' ) )
 323          {
 324              case ( 'l' ) :
 325                  self::save( $meta );
 326              break;
 327              case ( 'o' ) :
 328                  self::save( $meta );
 329              break;
 330              default :
 331                  $meta->meta_value = '404';
 332                  self::save( $meta );
 333              break;
 334          }
 335      }
 336  
 337  	public static function save( $meta )
 338      {
 339           if ( MailPress::is_bot() ) return;
 340  
 341          global $wpdb;
 342  
 343          $mp_user_id = MP_User::get_id( filter_input( INPUT_GET, 'us' ) );
 344  
 345          if ( !$mp_user_id ) return;
 346          if ( 0 == $mp_user_id ) return;
 347  
 348          $open_meta_id     = ( MailPress_tracking_openedmail == $meta->meta_value ) ? $meta->meta_id : self::get_mmid( $meta->mp_mail_id, MailPress_tracking_openedmail, MailPress_tracking_openedmail );
 349          $opened_mail    = $wpdb->get_var( $wpdb->prepare( "SELECT count( * ) FROM $wpdb->mp_tracks WHERE user_id = %d AND mail_id = %d AND mmeta_id = %d ;", $mp_user_id, $meta->mp_mail_id, $open_meta_id ) );
 350          if ( ( MailPress_tracking_openedmail == $meta->meta_value ) && ( $opened_mail ) ) return;
 351  
 352          $data = $format     = array();
 353  
 354          $REMOTE_ADDR         = filter_input( INPUT_SERVER, 'REMOTE_ADDR' );
 355          $HTTP_USER_AGENT     = filter_input( INPUT_SERVER, 'HTTP_USER_AGENT' );
 356          $HTTP_REFERER         = filter_input( INPUT_SERVER, 'HTTP_REFERER' );
 357  
 358          $data['user_id']     = $mp_user_id;                                                        $format[] = '%d';
 359          $data['mail_id']     = $meta->mp_mail_id;                                                    $format[] = '%d';
 360          $data['mmeta_id']     = $meta->meta_id;                                                    $format[] = '%d';
 361          $data['track']         = $wpdb->_real_escape( $meta->meta_value );                                $format[] = '%s';
 362          $data['context']     = ( 'h' == filter_input( INPUT_GET, 'co' ) ) ? 'html' : 'plaintext';                $format[] = '%s';
 363          $data['ip']         = $wpdb->_real_escape( trim( $REMOTE_ADDR ) );                                $format[] = '%s';
 364          $data['agent']         = $wpdb->_real_escape( trim( $HTTP_USER_AGENT ) );                            $format[] = '%s';
 365          $data['referrer']    = ( isset( $HTTP_REFERER ) ) ? $wpdb->_real_escape( trim( $HTTP_REFERER ) ) : '';    $format[] = '%s';
 366          $data['tmstp']        = current_time( 'mysql' );                                                $format[] = '%s';
 367  
 368          $wpdb->insert( $wpdb->mp_tracks, $data, $format );
 369  
 370          if ( MailPress_tracking_openedmail == $meta->meta_value ) $opened_mail = true;
 371          if ( $opened_mail ) return;
 372  
 373          $data['mmeta_id']     = $open_meta_id;
 374          $data['track']         = MailPress_tracking_openedmail;
 375  
 376          $wpdb->insert( $wpdb->mp_tracks, $data, $format );
 377      }
 378  
 379  ////  ADMIN  ////
 380  ////  ADMIN  ////
 381  ////  ADMIN  ////
 382  ////  ADMIN  ////
 383  
 384  // install
 385  	public static function install() 
 386      {
 387          include  ( MP_ABSPATH . 'mp-admin/includes/install/tracking.php' );
 388      }
 389      
 390  // for link on plugin page
 391  	public static function plugin_action_links( $links, $file )
 392      {
 393          return MailPress::plugin_links( $links, $file, plugin_basename( __FILE__ ), 'tracking' );
 394      }
 395  
 396  // for role & capabilities
 397  	public static function capabilities( $capabilities ) 
 398      {
 399          $capabilities['MailPress_tracking_mails'] = array(     'name'      => __( 'View tracking', 'MailPress' ), 
 400                                                  'group'     => 'mails'
 401                                               );
 402          $capabilities['MailPress_tracking_users'] = array(     'name'      => __( 'View tracking', 'MailPress' ), 
 403                                                  'group'     => 'users'
 404                                               );
 405          return $capabilities;
 406      }
 407  
 408  // for load admin page //
 409  	public static function load_admin_page( $hub )
 410      {
 411          $hub[MailPress_page_tracking_m] = 'tracking_m';
 412          $hub[MailPress_page_tracking_u] = 'tracking_u';
 413          return $hub;
 414      }
 415  
 416  // for settings
 417  	public static function settings_tab( $tabs )
 418      {
 419          $tabs['tracking'] = __( 'Tracking', 'MailPress' );
 420          return $tabs;
 421      }
 422  
 423  // for autorefresh
 424  	public static function autorefresh_js( $scripts )
 425      {
 426          return MP_WP_AutoRefresh_js::getInstance( $scripts );
 427      }
 428  
 429  // for mails list
 430  	public static function mails_columns( $x )
 431      {
 432          $date = array_pop( $x );
 433          $x['tracking_openrate']    =  __( 'Open rate', 'MailPress' );
 434          $x['tracking_clicks']    =  __( 'Clicks', 'MailPress' );
 435          $x['tracking_unsubscribe']    =  __( 'Unsubscribed', 'MailPress' );
 436          $x['date']        = $date;
 437          return $x;
 438      }
 439  
 440  	public static function mails_get_row( $out, $column_name, $mail, $url_parms )
 441      {
 442          global $wpdb;
 443          switch ( $column_name )
 444          {
 445              case 'tracking_openrate' :
 446                  if ( MailPress::is_email( $mail->toemail ) ) $total = 1;
 447                  elseif ( is_serialized( $mail->toemail ) ) $total = count( unserialize( $mail->toemail ) );
 448                  else break;
 449  
 450                  $result = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT user_id FROM $wpdb->mp_tracks WHERE mail_id = %d AND track = %s ;", $mail->id, MailPress_tracking_openedmail ) );
 451                  if ( $result ) if ( $total > 0 ) $out .= sprintf( "%01.2f %%", 100 * count( $result )/$total );
 452              break;
 453              case 'tracking_clicks' :
 454                  $exclude = array( MailPress_tracking_openedmail, '!!unsubscribed!!', '{{unsubscribe}}' );
 455  
 456                  $result = $wpdb->get_var( $wpdb->prepare( "SELECT count( * ) FROM $wpdb->mp_tracks WHERE mail_id = %d AND track NOT IN ( '" . join( "','", $exclude ) . "' ) ;", $mail->id ) );
 457                  if ( $result ) $out .= '<div class="num post-com-count-wrapper"><a class="post-com-count"><span class="comment-count">' . $result . '</span></a></div>';
 458              break;
 459              case 'tracking_unsubscribe' :
 460                  $exclude = array( '{{unsubscribe}}' );
 461  
 462                  $r  = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS DISTINCT user_id FROM $wpdb->mp_tracks WHERE mail_id = %d AND track = %s ;", $mail->id, '!!unsubscribed!!' ) );
 463                  $ud = $wpdb->get_var( "SELECT FOUND_ROWS()" );
 464  
 465                  $u  = $wpdb->get_var( $wpdb->prepare( "SELECT count( * ) FROM $wpdb->mp_tracks WHERE mail_id = %d AND track IN ( '" . join( "','", $exclude ) .  "' ) ;", $mail->id ) );
 466                  $title = ( !$u ) ? '' : esc_attr( sprintf( _n( __( '%d click on unsubscribe link',  'MailPress' ), __( '%d clicks on unsubscribe link',  'MailPress' ), $u ), $u ) );
 467  
 468                  $r = $ud;
 469                  if ( !$r ) break;
 470                  $out .= '<a class="post-com-count"><span class="comment-count"><abbr title="' . $title . '">' . $r . '</abbr></span></a>';
 471              break;
 472          }
 473          return $out;
 474      }
 475  
 476  // for reports
 477  
 478  	public static function translate_track( $track, $mail_id, $strlen = 20 )
 479      {
 480          switch ( $track )
 481          {
 482              case '{{subscribe}}' :
 483                  return __( 'subscribe', 'MailPress' );
 484              break;
 485              case '{{unsubscribe}}' :
 486                  return __( 'manage subscriptions', 'MailPress' );
 487              break;
 488              case '{{viewhtml}}' :
 489                  return __( 'view html', 'MailPress' );
 490              break;
 491              case MailPress_tracking_openedmail :
 492                  return __( 'mail opened', 'MailPress' );
 493              break;
 494              case '!!unsubscribed!!' :
 495                  return __( '<b>unsubscribed</b>', 'MailPress' );
 496              break;
 497              case '!!list-unsubscribed!!' :
 498                  return __( '<b>unsubscribed from list</b>', 'MailPress' );
 499              break;
 500              default :
 501                  $confkey = '#-$&$-#';
 502                  $url = MP_User::get_subscribe_url( $confkey );
 503                  $url = str_replace( $confkey, '', $url );
 504                  if ( stripos( $track, $url ) !== false ) {return __( 'subscribe', 'MailPress' );}
 505                  $url = MP_User::get_unsubscribe_url( $confkey );
 506                  $url = str_replace( $confkey, '', $url );
 507                  if ( stripos( $track, $url ) !== false ) {return __( 'unsubscribe', 'MailPress' );}
 508                  $url = MP_User::get_view_url( $confkey, $mail_id );
 509                  $url = str_replace( "{$confkey}&id={$mail_id}", '', $url );
 510                  if ( stripos( $track, $url ) !== false ) {return __( 'view html', 'MailPress' );}
 511              break;
 512          }
 513          global $wpdb;
 514          $title = $wpdb->get_var( "SELECT post_title FROM $wpdb->posts WHERE guid = '$track';" );
 515          $title = $display_title = ( $title ) ? $title : $track;
 516          $display_title = ( substr( $display_title, 0, 7 ) == 'http://' ) ? substr( $display_title, 7 ) : $display_title;
 517          $display_title = ( substr( $display_title, 0, 8 ) == 'https://' ) ? substr( $display_title, 8 ) : $display_title;
 518          $display_title = ( strlen( $display_title ) > $strlen ) ? substr( $display_title, 0, $strlen - 2 ) . '...' : $display_title;
 519          return '<a href="' . $track . '" title="' . esc_attr( $title ) . '" target="_blank">' . $display_title . '</a>';
 520      }
 521  }
 522  new MailPress_tracking();
 523  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1