Browse Source

smtp comments

windhamdavid 10 years ago
parent
commit
fc745466ec
6 changed files with 171 additions and 60 deletions
  1. 1 0
      .tm_properties
  2. 1 0
      functions.php
  3. 109 0
      inc/smtp.php
  4. 36 2
      inc/template.php
  5. 0 4
      js/init.js
  6. 24 54
      style.css

+ 1 - 0
.tm_properties

@@ -0,0 +1 @@
+excludeInFolderSearch = "{$excludeInFolderSearch,node_modules}"

+ 1 - 0
functions.php

@@ -4,6 +4,7 @@ if ( ! function_exists( 'dw_setup' ) ):
 function dw_setup() {
 	require( get_template_directory() . '/inc/template.php' );
 	require( get_template_directory() . '/inc/tweaks.php' );
+	require( get_template_directory() . '/inc/smtp.php' );
 	require get_template_directory() . '/inc/utils.php';
 }
 endif; 

+ 109 - 0
inc/smtp.php

@@ -0,0 +1,109 @@
+<?php
+/*Thanks https://github.com/rohmann/wp-multisite-smtp */
+
+class DW_SMTP {
+
+    protected static $instance;
+    protected $validations;
+	
+    function __construct() {
+
+        $this->prepare_settings();
+        $check = $this->validate();
+
+        if( is_wp_error( $check ) ) {
+            trigger_error($check->get_error_message(), E_USER_WARNING);
+        } else {
+            add_action( 'phpmailer_init', array( $this, 'mailer') );
+        }
+
+        unset($this->validations);
+    }
+
+    public static function launch() {
+        self::$instance = (defined('GLOBAL_SMTP_DISABLE') && GLOBAL_SMTP_DISABLE ) ? null : new self();
+    }
+
+    protected function prepare_settings() {
+        $this->validations = new stdClass;
+        $this->validations->required = array('GLOBAL_SMTP_HOST','GLOBAL_SMTP_USER','GLOBAL_SMTP_PASSWORD');
+        $this->validations->is_email = array('GLOBAL_SMTP_RETURN_PATH','GLOBAL_SMTP_FROM','GLOBAL_SMTP_REPLYTO_FROM');
+        $this->validations->not_empty = array('GLOBAL_SMTP_FROM','GLOBAL_SMTP_FROM_NAME');
+        $this->validations->is_int = array('GLOBAL_SMTP_PORT','GLOBAL_SMTP_TIMEOUT');
+        $this->validations->should_be = array('GLOBAL_SMTP_SECURE' => array('ssl','tls','none'),
+            'GLOBAL_SMTP_AUTH_TYPE' => array('LOGIN','PLAIN','NTLM') );
+
+        $assume = array(
+            'GLOBAL_SMTP_PORT'=> 465,
+            'GLOBAL_SMTP_SECURE' => 'ssl',
+            'GLOBAL_SMTP_TIMEOUT' => 10,
+            'GLOBAL_SMTP_FROM' => get_site_option('admin_email','',true),
+            'GLOBAL_SMTP_FROM_NAME' => get_site_option('site_name','WordPress',true),
+            'GLOBAL_SMTP_AUTH_TYPE' => 'LOGIN',
+        );
+
+        foreach ($assume as $setting => $default) {
+            if(!defined($setting)) {
+                define($setting, $default);
+            }
+        }
+    }
+
+    protected function validate() {
+
+        foreach ($this->validations->required as $setting) {
+            if(!defined($setting)) {
+                return new WP_Error( 'multisite-smtp', sprintf( __( '%s is required for Multisite SMTP. Please define this in wp-config.php.', 'multisite-smtp' ), $setting ) );
+            }
+        }
+
+        foreach ($this->validations->is_email as $setting) {
+            if (defined($setting) && !is_email(constant($setting))) {
+                return new WP_Error( 'multisite-smtp', sprintf( __( 'Value of %s is not a valid email address. Check wp-config.php, or ensure a valid fallback is available.', 'multisite-smtp' ), $setting ) );
+            }
+        }
+
+        foreach ($this->validations->not_empty as $setting) {
+            if(defined($setting) && constant($setting)=="") {
+                return new WP_Error( 'multisite-smtp', sprintf( __( '%s  is empty. Check wp-config.php, or ensure a valid fallback is available.', 'multisite-smtp' ), $setting ) );
+            }
+        }
+
+        foreach ($this->validations->is_int as $setting) {
+            if(defined($setting) && !is_int(constant($setting)) ) {
+                return new WP_Error( 'multisite-smtp', sprintf( __( '%s should be an integer. The force is not so strong with this one...', 'multisite-smtp' ), $setting ) );
+            }
+        }
+
+        foreach ($this->validations->should_be as $setting => $allowed) {
+            if(defined($setting) && !in_array(constant($setting), $allowed)) {
+                return new WP_Error( 'multisite-smtp', sprintf( __( '%s is invalid. It should be one of these values: "%s"', 'multisite-smtp' ), $setting, implode('" , "',$allowed) ) );
+            }
+        }
+
+        return true;
+    }
+
+    public function mailer( $phpmailer ) {
+
+        if(defined('GLOBAL_SMTP_DEBUG') && GLOBAL_SMTP_DEBUG ) $phpmailer->SMTPDebug = true;
+
+        $phpmailer->Mailer = "smtp";
+        $phpmailer->SMTPAuth = true;
+        $phpmailer->Host = GLOBAL_SMTP_HOST;
+        $phpmailer->Username = GLOBAL_SMTP_USER;
+        $phpmailer->Password = GLOBAL_SMTP_PASSWORD;
+        $phpmailer->From = GLOBAL_SMTP_FROM;
+        $phpmailer->FromName = GLOBAL_SMTP_FROM_NAME;
+        $phpmailer->Port = GLOBAL_SMTP_PORT;
+        $phpmailer->SMTPSecure = GLOBAL_SMTP_SECURE;
+        $phpmailer->AuthType = GLOBAL_SMTP_AUTH_TYPE;
+        $phpmailer->Sender = defined('GLOBAL_SMTP_RETURN_PATH') ? GLOBAL_SMTP_RETURN_PATH : GLOBAL_SMTP_FROM;
+
+        if(defined('GLOBAL_SMTP_REPLYTO_FROM')) {
+            $phpmailer->AddReplyTo(GLOBAL_SMTP_REPLYTO_FROM, defined('GLOBAL_SMTP_REPLYTO_FROM_NAME') ? GLOBAL_SMTP_REPLYTO_FROM_NAME : GLOBAL_SMTP_FROM_NAME);
+        }
+    }
+}
+
+DW_SMTP::launch();

+ 36 - 2
inc/template.php

@@ -198,7 +198,7 @@ function dw_comment( $comment, $args, $depth ) {
 	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
 		<div id="comment-<?php comment_ID(); ?>">
 		<div class="comment-author vcard">
-			<?php echo get_avatar( $comment, 16 ); ?>
+			<?php echo get_avatar( $comment, 64 ); ?>
 			<?php printf( __( '<cite class="fn">%s</cite><span class="says">:</span>', 'daw' ), get_comment_author_link() ); ?>
 		</div>
 		<?php if ( $comment->comment_approved == '0' ) : ?>
@@ -221,4 +221,38 @@ function dw_comment( $comment, $args, $depth ) {
 		<p><?php _e( 'Pingback: ', 'daw' ); ?><?php comment_author_link(); ?><?php edit_comment_link ( __('edit', 'daw'), '&nbsp;&nbsp;', '' ); ?></p>
 	<?php endif;
 }
-endif;
+endif;
+
+add_filter( 'comment_form_default_fields', 'dw_comment_form_fields' );
+function dw_comment_form_fields( $fields ) {
+    $commenter = wp_get_current_commenter();
+    
+    $req = get_option( 'require_name_email' );
+    $aria_req = ( $req ? " aria-required='true'" : '' );
+    $html5 = current_theme_supports( 'html5', 'comment-form' ) ? 1 : 0;
+    
+    $fields   =  array(
+        'author' => '<div class="form-group comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
+                    '<input class="form-control" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></div>',
+        'email'  => '<div class="form-group comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
+                    '<input class="form-control" id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></div>',
+        'url'    => '<div class="form-group comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
+                    '<input class="form-control" id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></div>',
+    );
+    
+    return $fields;
+}
+
+add_filter( 'comment_form_defaults', 'dw_comment_form' );
+function dw_comment_form( $args ) {
+    $args['comment_field'] = '<div class="form-group comment-form-comment">
+            <label for="comment">' . _x( 'Comment', 'noun' ) . '</label> 
+            <textarea class="form-control" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>
+        </div>';
+    return $args;
+}
+
+add_action('comment_form', 'dw_comment_button' );
+function dw_comment_button() {
+    echo '<button class="btn btn-default" type="submit">' . __( 'Submit' ) . '</button>';
+}

+ 0 - 4
js/init.js

@@ -160,10 +160,6 @@ $('.nav-toggle').on('touchstart click', function(e) {
 $('#nav').affix({
 	//offset: {top: $('.intro').height()-$('.navbar').height()}
 });	
-$('.about').affix({
-	top: 0,
-	bottom: 0
-});	
 
 $(function dw_hidenav() {
 	var headerHeight = $('.navbar').height();

+ 24 - 54
style.css

@@ -33,7 +33,7 @@ a img {border: 0;}
 
 
 /*============================================
-										Body 
+					Body 
 ==============================================*/
 
 body { 
@@ -42,7 +42,7 @@ body {
 
 
 /*============================================
-										Typography 
+					Typography 
 ==============================================*/
 
 
@@ -173,7 +173,7 @@ h1.super {
 }
 
 /*============================================
-										Grid 
+					Grid 
 ==============================================*/
 .container {
   padding-right: 15px;
@@ -230,7 +230,7 @@ h1.super {
 
 
 /*============================================
-						Loader / Transit
+				Loader / Transit
 ==============================================*/
 
 #loader {
@@ -430,7 +430,7 @@ h1.super {
 
 
 /*============================================
-										Intro 
+					Intro 
 ==============================================*/
 
 .screen-reader {
@@ -590,12 +590,6 @@ h1.super {
 .about {
 	padding: 30px 0;
 }
-.about.affix {
- 
-	z-index: 3333;
-	width: 100%;
-}
-
 .carousel-fade .carousel-inner .item {
   left: 0 !important;
   opacity: 0;
@@ -709,7 +703,7 @@ h1.super {
 
 
 /*============================================
-										Navbar 
+					Navbar 
 ==============================================*/
 
 .navbar {
@@ -765,7 +759,7 @@ h1.super {
 }
 
 /*============================================
-										NavMenu 
+					NavMenu 
 ==============================================*/
 
 .offcanvas.in {
@@ -857,7 +851,7 @@ ul.social li {
 
 
 /*============================================
-										Header 
+					Header 
 ==============================================*/
 .site-title {
 	float: right;
@@ -888,7 +882,7 @@ img.dw {
 
 
 /*============================================
-										Content 
+					Content 
 ==============================================*/
 
 /*===== Structure =====*/
@@ -1213,7 +1207,7 @@ h2.entry-title {
 	padding: 0 24px;
 }
 .entry-content input {
-	margin: 0 0 24px 0;
+	margin: 0 0 20px 0;
 }
 .entry-content input.file,
 .entry-content input.button {
@@ -1269,34 +1263,6 @@ body.page .edit-link {
 	clear: both;
 	display: block;
 }
-#entry-author-info {
-	background: #f2f7fc;
-	border-top: 4px solid #000;
-	clear: both;
-	font-size: 14px;
-	line-height: 20px;
-	margin: 24px 0;
-	overflow: hidden;
-	padding: 18px 20px;
-}
-#entry-author-info #author-avatar {
-	background: #fff;
-	border: 1px solid #e7e7e7;
-	float: left;
-	height: 60px;
-	margin: 0 -104px 0 0;
-	padding: 11px;
-}
-#entry-author-info #author-description {
-	float: left;
-	margin: 0 0 0 104px;
-}
-#entry-author-info h2 {
-	color: #000;
-	font-size: 100%;
-	font-weight: bold;
-	margin-bottom: 0;
-}
 .entry-utility {
 	clear: both;
 	color: #888;
@@ -1329,7 +1295,7 @@ body.page .edit-link {
 
 
 /*============================================
-										Meta 
+				  Meta 
 ==============================================*/
 
 .meta {
@@ -1357,7 +1323,7 @@ span.fb  {
 	}
 	
 /*============================================
-										Comments 
+				Comments 
 ==============================================*/
 
 #commentform input.error, 
@@ -1366,8 +1332,6 @@ span.fb  {
 	color:#000000; 
 }
 #commentform .error  { 
-	font-size: 16px; 
-	padding: 0 0 5px 0; 
 	color: #FF0000; 
 }
 .commentbubble {
@@ -1532,7 +1496,6 @@ li.comment.thread-odd {
 #respond form textarea {
 	-moz-box-sizing: border-box;
 	box-sizing: border-box;
-	font: 0.857142857rem "Courier New", Courier, mono;
 	line-height: 1.714285714;
 	padding: 10px;
 	padding: 0.714285714rem;
@@ -1548,12 +1511,19 @@ li.comment.thread-odd {
 .required {
 	color: red;
 }
-
+.form-submit {
+    display: none;
+}
+.comment-form-author,
+.comment-form-email,
+.comment-form-url {
+    width: 50%;
+}
 
 
 
 /*============================================
-										Media 
+					Media 
 ==============================================*/
 
 .video-container {
@@ -1752,7 +1722,7 @@ img.me {
 
 
 /*============================================
-										Pagination 
+					Pagination 
 ==============================================*/
 
 .navigation {
@@ -1835,7 +1805,7 @@ img.me {
 
 
 /*============================================
-										Footer 
+					Footer 
 ==============================================*/
 
 
@@ -1843,7 +1813,7 @@ img.me {
 
 
 /*============================================
-										Forms
+					Forms
 ==============================================*/
 
 .text-field {