WordPress.org

Plugin Directory

Changeset 428424


Ignore:
Timestamp:
08/25/11 00:12:24 (3 years ago)
Author:
wojtek.szkutnik
Message:

Introducing recent changes plus adding Aaron and Justin as contributors

Location:
enhanced-emails/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • enhanced-emails/trunk/enhancedemails.php

    r422932 r428424  
    44Plugin URI: http://wojtekszkutnik.com 
    55Description: The Enhanced Emails plugin adds e-mail themes, HTML versions for custom and default e-mails and easier use of enriched e-mails out of the box. 
    6 Version: 0.2 
     6Version: 0.2.1 
    77Author: Wojtek Szkutnik 
    88Author URI: http://wojtekszkutnik.com 
     
    1313 
    1414    This program is free software; you can redistribute it and/or modify 
    15     it under the terms of the GNU General Public License, version 2, as  
     15    it under the terms of the GNU General Public License, version 2, as 
    1616    published by the Free Software Foundation. 
    1717 
     
    2828include('pluggable.php'); 
    2929 
    30 define( 'EEMAILS_PATH', dirname( __FILE__ ) ); 
    31 define( 'EEMAILS_FOLDER_NAME', '/templates/' ); 
    32 define( 'EEMAILS_TEMPLATES_PATH', EEMAILS_PATH . EEMAILS_FOLDER_NAME ); 
    33 define( 'EEMAILS_FOLDER', dirname( plugin_basename( __FILE__ ) ) ); 
    34 define( 'EEMAILS_URL', plugins_url( EEMAILS_FOLDER ) ); 
    3530define( 'EEMAILS_DESCENDING_HIERARCHY', true ); // Descending hierarchy means that for emails-function-name emails-function-name.php, emails-function.php, emails.php will be tried. 
    3631                                                // Otherwise, only the first and last option will be tried (emails-function-name.php and after that, emails.php) 
     
    7974} 
    8075 
    81 /* 
    82     Template hierarchy 
    83 */ 
     76function eemails_get_template( $slug, $event = null , $name = null ) { 
     77        do_action( "get_email_template_{$slug}", $slug, $event, $name ); 
     78        $directories = apply_filters( 'email-template-directories', array( 
     79                '', // Blank is the template directories, which we want to check first 
     80                dirname( __FILE__ ) . '/templates/', // The templates included with the plugin 
     81        ) ); 
    8482 
    85 function eemails_get_template( $template_name ) { 
    86      
    87     // Try the theme template dirs 
    88     $template_file = eemails_get_template_from_dir( $template_name ); 
    89     // Then the wp content dir 
    90     if ( '' == $template_file ) 
    91         $template_file = eemails_get_template_from_dir( $template_name, WP_CONTENT_DIR ); 
    92          
    93     // Then the default plugin templates folder 
    94     if ( '' == $template_file ) 
    95         $template_file = eemails_get_template_from_dir( $template_name, EEMAILS_TEMPLATES_PATH ); 
    96          
    97     return $template_file; 
     83        $templates = array(); 
     84        foreach ( $directories as $dir ) { 
     85                $dir_slug = empty( $dir )? $slug : path_join( $dir, $slug ); 
     86 
     87                if ( isset( $event ) && isset( $name ) ) 
     88                        $templates[] = "{$dir_slug}-{$event}-{$name}.php"; 
     89 
     90                if ( isset( $event ) ) 
     91                        $templates[] = "{$dir_slug}-{$event}.php"; 
     92 
     93                $templates[] = "{$dir_slug}.php"; 
     94        } 
     95 
     96        return locate_email_template( $templates ); 
    9897} 
    9998 
    100 function eemails_get_template_from_dir( $template_name, $dir = false ) { 
    101      
    102     // Split the template name into module names 
    103     $name_parts = explode( '-', $template_name ); 
    104     $name_parts_index  = count( $name_parts )-1; 
    105     $template_match = ''; 
    106      
    107     // Look for the best match 
    108     while ( $name_parts_index >= 0 ) { 
    109          
    110         $template_file_name =  implode( '-', $name_parts ) . '.php'; 
    111         $template_name_temp = trailingslashit( $dir ) . $template_file_name; 
     99function locate_email_template( $template_names ) { 
     100        $located = ''; 
     101        foreach ( (array) $template_names as $template_name ) { 
     102                if ( !$template_name ) 
     103                        continue; 
     104                if ( file_exists( get_stylesheet_directory() . '/' . $template_name ) ) { 
     105                        $located = get_stylesheet_directory() . '/' . $template_name; 
     106                        break; 
     107                } else if ( file_exists( get_template_directory() . '/' . $template_name ) ) { 
     108                        $located = get_template_directory() . '/' . $template_name; 
     109                        break; 
     110                } else if ( file_exists( $template_name ) ) { 
     111                        $located = $template_name; 
     112                        break; 
     113                } 
     114        } 
    112115 
    113         // If the directory name is not set, search via locate_template 
    114         if ( false === $dir ) { 
    115             $template_match = locate_template( $template_file_name ); 
    116             if ( $template_match ) 
    117                 break; 
    118         } 
    119          
    120         // If the template file exists - it is the best match 
    121         if( file_exists( $template_name_temp ) ) { 
    122             $template_match = $template_name_temp; 
    123             break; 
    124         } 
    125          
    126         // If the template does not exist, search for a more generic template 
    127         unset( $name_parts[$name_parts_index] ); 
    128         $name_parts_index--; 
    129           
    130         if ( ( ! EEMAILS_DESCENDING_HIERARCHY ) && ( $name_parts_index > 0 ) ) { 
    131             $name_parts = Array($name_parts[0]); 
    132             $name_parts_index = 0; 
    133         } 
    134     } 
    135      
    136     return $template_match; 
     116        return $located; 
    137117} 
    138118 
     
    143123function eemails_charset( $charset = '' ) { 
    144124    // If the charset is not set (most of the times) get the global blog setting 
    145     if ( '' == $charset )  
     125    if ( '' == $charset ) 
    146126        $charset = get_option('blog_charset'); 
    147          
     127 
    148128    return "Content-Type: text/html; charset=\"{$charset}\"\n"; 
    149129} 
     
    160140    ); 
    161141    $args = wp_parse_args( $args, $defaults ); 
    162      
     142 
    163143    if ( ! $content_title ) 
    164144        $content_title = $subject; 
    165          
     145 
    166146    extract( $args, EXTR_SKIP ); 
    167147    extract( $template_args, EXTR_SKIP ); 
    168      
     148 
    169149    $template = eemails_get_template($template); 
    170150    $html_email = ''; 
    171151    include( 'templates/layout.php' ); 
    172     $message = array(  
     152    $message = array( 
    173153                     'text/plain' => $message, 
    174154                     'text/html' => $html_email 
    175155                    ); 
    176      
     156 
    177157    return wp_mail( $to, $subject, $message ); 
    178158} 
     
    183163 
    184164function eemails_get_image_url( $image_name ) { 
    185     return EEMAILS_URL . EEMAILS_FOLDER_NAME . 'images/' . $image_name; 
     165    return plugins_url( '/templates/images/' . $image_name, __FILE__ ); 
    186166} 
    187167 
     
    191171} 
    192172 
    193 function eemails_get_gravatar( $email, $size = 50 ) { 
    194     $gravatar = get_avatar( $email, $size ); 
    195     return $gravatar; 
    196 } 
    197  
    198  
    199 function eemails_blogname( ) { 
    200     echo wp_specialchars_decode( get_option('blogname'), ENT_QUOTES ); 
    201 } 
    202  
    203173function eemails_get_action_links( $action_links = array(), $label = 'Take action:' ) { 
    204174    $links = array(); 
    205      
     175 
    206176    foreach ($action_links as $link) { 
    207177        $links[] = '<a href="' . $link['link'] . '" style="color:#' . $link['color'] . ';text-decoration:none;margin: 0 10px;font-weight:bold; font-size: 14px">' . $link['text'] . '</a>'; 
    208178    } 
    209      
     179 
    210180    if ( ! empty ( $links ) ) 
    211181        $links = $label . implode(' | ',$links); 
    212      
     182 
    213183    return $links; 
    214 } 
    215  
    216 function eemails_action_links( $action_links = array(), $label = '' ) { 
    217     echo eemails_get_action_links( $action_links, $label ); 
    218184} 
    219185 
     
    222188    wp_notify_moderator(2); 
    223189    wp_new_user_notification(1, 'mysecretpassword'); 
    224     wp_password_change_notification(new WP_User(1));     
     190    wp_password_change_notification(new WP_User(1)); 
    225191} 
    226192?> 
  • enhanced-emails/trunk/pluggable.php

    r422932 r428424  
    347347    // we want to reverse this for the plain text arena of emails. 
    348348    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); 
    349     $eemails_args = array(); 
     349    $eemail_args = array(); 
    350350    if ( empty( $comment_type ) ) $comment_type = 'comment'; 
    351351 
    352     $eemails_args['template_args'] = array( 
    353                                            'comment' => $comment, 
    354                                           'comment_type' => $comment_type 
    355                                            ); 
     352    $eemail_args['template_args'] = array( 
     353        'comment' => $comment, 
     354        'comment_type' => $comment_type 
     355    ); 
    356356     
    357357    if ('comment' == $comment_type) { 
     
    364364        $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; 
    365365        $notify_message .= __('You can see all comments on this post here: ') . "\r\n"; 
    366         $eemails_args['content_title'] = sprintf( __( '"%s" - new comment' ), $post->post_title ); 
     366        $eemail_args['content_title'] = sprintf( __( '"%s" - new comment' ), $post->post_title ); 
    367367        /* translators: 1: blog name, 2: post title */ 
    368368        $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title ); 
     
    374374        $notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; 
    375375        $notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n"; 
    376         $eemails_args['content_title'] = sprintf( __( '"%s" - new traceback' ), $post->post_title ); 
     376        $eemail_args['content_title'] = sprintf( __( '"%s" - new trackback' ), $post->post_title ); 
    377377        /* translators: 1: blog name, 2: post title */ 
    378378        $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title ); 
     
    384384        $notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n"; 
    385385        $notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n"; 
    386         $eemails_args['content_title'] = sprintf( __( '"%s" - new pingback' ), $post->post_title ); 
     386        $eemail_args['content_title'] = sprintf( __( '"%s" - new pingback' ), $post->post_title ); 
    387387        /* translators: 1: blog name, 2: post title */ 
    388388        $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title ); 
     
    391391    $notify_message .= sprintf( __('Permalink: %s'), get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id ) . "\r\n"; 
    392392     
    393     $eemails_args['action_links'] = array(); 
     393    $eemail_args['action_links'] = array(); 
    394394    if ( EMPTY_TRASH_DAYS ) { 
    395395        $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; 
    396         $eemails_args['action_links'][] = array('link'=>admin_url("comment.php?action=trash&c=$comment_id"),'color'=>'c23031','text'=>__('Trash it')); 
     396        $eemail_args['action_links'][] = array('link'=>admin_url("comment.php?action=trash&c=$comment_id"),'color'=>'c23031','text'=>__('Trash it')); 
    397397    } 
    398398    else { 
    399399        $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; 
    400         $eemails_args['action_links'][] = array('link'=>admin_url("comment.php?action=delete&c=$comment_id"),'color'=>'c23031','text'=>__('Delete it')); 
     400        $eemail_args['action_links'][] = array('link'=>admin_url("comment.php?action=delete&c=$comment_id"),'color'=>'c23031','text'=>__('Delete it')); 
    401401    } 
    402402    $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n"; 
    403     $eemails_args['action_links'][] = array('link'=>admin_url("comment.php?action=spam&c=$comment_id"),'color'=>'d2b12e','text'=>__('Mark as spam')); 
     403    $eemail_args['action_links'][] = array('link'=>admin_url("comment.php?action=spam&c=$comment_id"),'color'=>'d2b12e','text'=>__('Mark as spam')); 
    404404 
    405405    $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); 
     
    424424    $subject = apply_filters('comment_notification_subject', $subject, $comment_id); 
    425425    $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id); 
    426     $eemails_args['template'] = 'email-comment-notify'; 
    427     @eemails_wp_mail( $author->user_email, $subject, $notify_message, $message_headers, array(), $eemails_args ); 
     426    $eemail_args['template-slug'] = 'email';  
     427    $eemail_args['template-event'] = 'comment';  
     428    $eemail_args['template-name'] = 'notify';  
     429    @eemails_wp_mail( $author->user_email, $subject, $notify_message, $message_headers, array(), $eemail_args ); 
    428430    return true; 
    429431} 
     
    461463    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); 
    462464     
    463     $eemails_args = array(); 
     465    $eemail_args = array(); 
    464466 
    465467    $comment_type = $comment->comment_type; 
    466468    if ( empty( $comment_type ) ) $comment_type = 'comment'; 
    467469 
    468     $eemails_args['template_args'] = array( 
    469                                            'comment' => $comment, 
    470                                            'comment_type' => $comment_type 
    471                                            ); 
     470    $eemail_args['template_args'] = array( 
     471        'comment' => $comment, 
     472        'comment_type' => $comment_type 
     473    ); 
    472474    switch ($comment->comment_type) 
    473475    { 
     
    478480            $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n"; 
    479481            $notify_message .= __('Trackback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; 
    480             $eemails_args['content_title'] = sprintf( __( '"%s" - new traceback awaiting approval' ), $post->post_title ); 
     482            $eemail_args['content_title'] = sprintf( __( '"%s" - new trackback awaiting approval' ), $post->post_title ); 
    481483            break; 
    482484        case 'pingback': 
     
    486488            $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n"; 
    487489            $notify_message .= __('Pingback excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; 
    488             $eemails_args['content_title'] = sprintf( __( '"%s" - new pingback awaiting approval' ), $post->post_title ); 
     490            $eemail_args['content_title'] = sprintf( __( '"%s" - new pingback awaiting approval' ), $post->post_title ); 
    489491            break; 
    490492        default: //Comments 
     
    496498            $notify_message .= sprintf( __('Whois  : http://whois.arin.net/rest/ip/%s'), $comment->comment_author_IP ) . "\r\n"; 
    497499            $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n"; 
    498             $eemails_args['content_title'] = sprintf( __( '"%s" - new comment awaiting approval' ), $post->post_title ); 
     500            $eemail_args['content_title'] = sprintf( __( '"%s" - new comment awaiting approval' ), $post->post_title ); 
    499501            break; 
    500502    } 
    501503 
    502     $eemails_args['action_links'] = array(array('link'=>admin_url("comment.php?action=approve&c=$comment_id"),'color'=>'3ca757','text'=>__('Approve it'))); 
     504    $eemail_args['action_links'] = array(array('link'=>admin_url("comment.php?action=approve&c=$comment_id"),'color'=>'3ca757','text'=>__('Approve it'))); 
    503505                                                                                                                                            
    504506    $notify_message .= sprintf( __('Approve it: %s'),  admin_url("comment.php?action=approve&c=$comment_id") ) . "\r\n"; 
    505507    if ( EMPTY_TRASH_DAYS ) { 
    506508        $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; 
    507         $eemails_args['action_links'][] = array('link'=>admin_url("comment.php?action=trash&c=$comment_id"),'color'=>'c23031','text'=>__('Trash it')); 
     509        $eemail_args['action_links'][] = array('link'=>admin_url("comment.php?action=trash&c=$comment_id"),'color'=>'c23031','text'=>__('Trash it')); 
    508510    } 
    509511    else { 
    510512        $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; 
    511         $eemails_args['action_links'][] = array('link'=>admin_url("comment.php?action=delete&c=$comment_id"),'color'=>'c23031','text'=>__('Delete it')); 
     513        $eemail_args['action_links'][] = array('link'=>admin_url("comment.php?action=delete&c=$comment_id"),'color'=>'c23031','text'=>__('Delete it')); 
    512514    } 
    513515         
    514516    $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n"; 
    515     $eemails_args['action_links'][] = array('link'=>admin_url("comment.php?action=spam&c=$comment_id"),'color'=>'d2b12e','text'=>__('Mark as spam')); 
     517    $eemail_args['action_links'][] = array('link'=>admin_url("comment.php?action=spam&c=$comment_id"),'color'=>'d2b12e','text'=>__('Mark as spam')); 
    516518     
    517     $eemails_args['template_args']['moderation_message'] = sprintf( _n('Currently %s comment is waiting for approval. ', 
     519    $eemail_args['template_args']['moderation_message'] = sprintf( _n('Currently %s comment is waiting for approval. ', 
    518520        'Currently %s comments are waiting for approval.', $comments_waiting), number_format_i18n($comments_waiting) ) . ' <a href="' . admin_url("edit-comments.php?comment_status=moderated") . '" style="color:#21759b;text-decoration:none;">Please visit the moderation panel.</a>'; 
    519521    $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:', 
     
    528530    $message_headers = apply_filters('comment_moderation_headers', $message_headers); 
    529531     
    530     $eemails_args['template'] = 'email-comment-notify'; 
     532    $eemail_args['template-slug'] = 'email'; 
     533    $eemail_args['template-event'] = 'comment'; 
     534    $eemail_args['template-name'] = 'notify'; 
    531535    foreach ( $email_to as $email ) 
    532         @eemails_wp_mail($email, $subject, $notify_message, $message_headers, array(), $eemails_args); 
     536        @eemails_wp_mail($email, $subject, $notify_message, $message_headers, array(), $eemail_args); 
    533537 
    534538    return true; 
     
    555559        $eemail_args['template'] = 'email-passwordchange-admin'; 
    556560        $eemail_args['template_args'] = array('user' => $user); 
    557         $eemails_args['action_links'] = array( 
     561        $eemail_args['action_links'] = array( 
    558562                                              array('link'=>admin_url("user-edit.php?user_id=".$user->ID),'color'=>'d2b12e','text'=>__('Edit user')), 
    559563                                              array('link'=>admin_url("users.php"),'color'=>'3ca757','text'=>__('See all users')) 
     
    587591    $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n"; 
    588592 
    589     $eemail_args['template'] = 'email-newuser-admin'; 
     593    $eemail_args['template-slug'] = 'email'; 
     594    $eemail_args['template-event'] = 'newuser'; 
     595    $eemail_args['template-name'] = 'admin'; 
    590596    $eemail_args['template_args'] = array('user' => $user); 
    591597    $eemail_args['action_links'] = array( 
     
    600606    $eemail_args['template_args']["user_password"] = $plaintext_pass; 
    601607    $eemail_args['action_links'] = array(); 
    602     $eemail_args['template'] = 'email-newuser-user'; 
     608    $eemail_args['template-slug'] = 'email'; 
     609    $eemail_args['template-event'] = 'newuser'; 
     610    $eemail_args['template-name'] = 'user';  
    603611    $message  = sprintf(__('Username: %s'), $user_login) . "\r\n"; 
    604612    $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n"; 
  • enhanced-emails/trunk/readme.txt

    r422938 r428424  
    11=== Enhanced Emails === 
    2 Contributors: wojtek.szkutnik 
     2Contributors: wojtek.szkutnik, jshreve, aaroncampbell 
    33Tags: emails, html 
    44Requires at least: 2.7 
     
    1010== Description == 
    1111 
    12 This plugin is in early development stage. Expect bugs. 
     12This plugin is in very early development stage. It is meant for testing purposes only and it is not recommended to use it on production sites. 
    1313 
    1414== Installation == 
     
    2323This is highly unlikely to happen. The plugin enhances the way WordPress handles e-mail notifications, but it does it in a unobtrusive way. Basically, it provides a wrapper for wp_mail, which can be used for e-mail notifications. If you did override any pluggable email notification functions, make sure to use eemails_wp_mail instead of wp_mail in order to make use of the plugin functionality.  
    2424 
    25 = How can I create my own e-mail theme? = 
     25= How can I create my own e-mail theme? - 
    2626 
    2727It's easy - just put your email.php theme file inside your current WP theme directory (if you put it inside wp-content it should work as well, but it's bad practice).  
  • enhanced-emails/trunk/templates/email-comment-notify.php

    r422932 r428424  
    55                    <td style="width:75px;" width="75" rowspan="3"> 
    66                    <div style="width:60px;height:60px;background-color: #ffffff; border: 1px solid #ececec; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px;"> 
    7                         <a style="margin:5px 0 0 5px;display:block;">' . eemails_get_gravatar($comment->comment_author_email) . '</a> 
     7                        <a style="margin:5px 0 0 5px;display:block;">' . get_avatar( $comment->comment_author_email, 50 ) . '</a> 
    88                    </div></td> 
    99                    <td height="12" style="height:12px;padding-top:2px;">Author: <strong>' . $comment->comment_author . '</strong></td> 
Note: See TracChangeset for help on using the changeset viewer.