Pages

Monday, September 30, 2019

PHPMailer SMTP Self Hosted Server

<?php
error_reporting(0);

// Download PHP mailer from github
// https://github.com/PHPMailer/PHPMailer/archive/master.zip

// Install PHP mailer composer using this command
// composer require phpmailer/phpmailer


/**
 * This example shows settings to use when sending via Google's Gmail servers.
 * This uses traditional id & password authentication - look at the gmail_xoauth.phps
 * example to see how to use XOAUTH2.
 * The IMAP section shows how to save this message to the 'Sent Mail' folder using IMAP commands.
 */
//Import PHPMailer classes into the global namespace

// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;

//Load composer's autoloader
require './vendor/autoload.php';
//Create a new PHPMailer instance


$mail = new PHPMailer;
//Tell PHPMailer to use SMTP


$mail->isSMTP();
//Enable SMTP debugging
// SMTP::DEBUG_OFF = off (for production use)
// SMTP::DEBUG_CLIENT = client messages
// SMTP::DEBUG_SERVER = client and server messages

// $mail->SMTPDebug = SMTP::DEBUG_SERVER;

//Set the hostname of the mail server
$mail->Host = 'domain.com';

// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
// $mail->Port = 587;
$mail->Port = 465;

//Set the encryption mechanism to use - STARTTLS or SMTPS
// $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPSecure = 'ssl';

//Whether to use SMTP authentication
$mail->SMTPAuth = 'true';
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "zahid@domain.com";
//Password to use for SMTP authentication
$mail->Password = "111111111111";

//Set who the message is to be sent from
$mail->setFrom('info@semgenius.com', 'Michael Grim');
//Set an alternative reply-to address
// $mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to

$mail->addAddress('zahid@domain.com', 'Michael Grim');
//Set the subject line

$message ='';
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$phone = $_POST['phone'];
$email_address = $_POST['email_address'];
$question_comment = (!empty($_POST['question_comment'])) ? $_POST['question_comment'] : 'Message';


$mail->Subject = 'New Message has been received!';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
// $mail->msgHTML(file_get_contents('contents.html'), __DIR__);

// Message HERE with Post Form Values
$message .= "<h4>A New Message has been received from: ".$first_name." ".$last_name." </h4>";

$message .= '<p>First Name: '.$first_name."</p>";
$message .= '<p>Last Name: '.$last_name."</p>";
$message .= '<p>Phone Number: '.$phone."</p>";
$message .= '<p>Email Address: '.$email_address."</p>";
$message .= '<p>Message: '.$question_comment."</p>";

$mail->msgHTML($message);


//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
// $mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;

} else {
    echo "Message sent!";
    header("Location: thank-you.html");
    die();
    //Section 2: IMAP
    //Uncomment these to save your message in the 'Sent Mail' folder.
    #if (save_mail($mail)) {
    #    echo "Message saved!";
    #}
}
//Section 2: IMAP
//IMAP commands requires the PHP IMAP Extension, found at: https://php.net/manual/en/imap.setup.php
//Function to call which uses the PHP imap_*() functions to save messages: https://php.net/manual/en/book.imap.php
//You can use imap_getmailboxes($imapStream, '/imap/ssl', '*' ) to get a list of available folders or labels, this can
//be useful if you are trying to get this working on a non-Gmail IMAP server.
// function save_mail($mail)
// {
//     //You can change 'Sent Mail' to any other folder or tag
//     $path = "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail";
//     //Tell your server to open an IMAP connection using the same username and password as you used for SMTP
//     $imapStream = imap_open($path, $mail->Username, $mail->Password);
//     $result = imap_append($imapStream, $path, $mail->getSentMIMEMessage());
//     imap_close($imapStream);
//     return $result;
// }

Saturday, September 21, 2019

Woocommerce Products Filter by Attribute Code

<?php
/**
 * Deasier.astra Theme functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package Deasier.astra
 * @since 1.0.0
 */

/**
 * Define Constants
 */
define( 'CHILD_THEME_DEASIER_ASTRA_VERSION', '1.0.0' );

/**
 * Enqueue styles
 */





//** filter **//
add_action( 'woocommerce_product_query', 'so_20990199_product_query' );

function so_20990199_product_query( $q ){
    if (isset($_POST['selected_attributes_data'])){
       
        echo "<div style='display:none;'><pre>";
        print_r($_POST);
        echo "</pre></div>";
        // exit();
        $living_room_size_x = $_POST['living_room_size_length'] * $_POST['living_room_size_width'];
        //echo $living_room_size_x;
        if ($living_room_size_x < 320.42) {
            $living_room_size_x = 'smalllength-x-width-˂32042';
        }else {
            $living_room_size_x = 'large-length-x-width-≥32042';
        }
        $height_of_nearest_sofa = $_POST['height-of-the-nearest-sofa'];
        if ($height_of_nearest_sofa >= '19'){
            $height_of_nearest_sofa = 'high-h-˃-19-inches';
        }else if ($height_of_nearest_sofa >= '17.5' && $height_of_nearest_sofa <= '19'){
            $height_of_nearest_sofa = 'meduim-175-≤-h-≤-19-inches';
        }else {
            $height_of_nearest_sofa = 'low-h-˂-175-inches';
        }
       
        $q->set('tax_query', array(
            'relation'=>'AND',
            array(
                'taxonomy' => 'pa_the-main-uses',
                'field'    => 'slug',
                'terms'    => array($_POST['pa_the-main-uses']), // Don't display products in this category on the shop page
                'operator' => 'IN',
            ),
            array(
              'taxonomy'        => 'pa_living-room-style',
              'field'           => 'slug',
              'terms'           => array($_POST['living-room-style']),
              'operator'        => 'IN'
            ),
            array(
              'taxonomy'        => 'pa_living-room-size',
              'field'           => 'slug',
              'terms'           => array($living_room_size_x),
              'operator'        => 'IN'
            ),
            array(
                  'taxonomy' => 'pa_height-of-the-nearest-sofa',
                  'field'    => 'slug',
                  'terms'    => array($height_of_nearest_sofa), // Don't display products in this category on the shop page
                  'operator' => 'IN',
              ),
            array(
              'taxonomy'        => 'pa_type-of-the-nearest-sofa',
              'field'           => 'slug',
              'terms'           => array($_POST['pa_type-of-the-nearest-sofa']),
              'operator'        => 'IN'
            )
        ));
    }

     $product_ids_on_sale = wc_get_product_ids_on_sale();

     $q->set( 'post__in', (array) $product_ids_on_sale );
    //  echo "<pre>";
    //     print_r($q);
    //     echo "</pre>";
    //     echo "hello";exit;
   

}

Tuesday, September 17, 2019

jSingature Js Library some functions and validation

<script src="js/jSignature.min.js"></script>

<script src="js/signhere/jSignature.SignHere.js"></script>

<div class="form-group clearfix">
                    <div class="sign-here">
                    <i class="fas fa-signature"></i> Sign Here
                    </div>
                        <a class="clear-signature-link" href="#"><i class="fas fa-times-circle"></i> Clear All</a>
                        <div  id="signatureparent" class="draw-area form-control">
                        </div>
                        <textarea class="type-area form-control"></textarea>
                         <div id="displayarea"></div>  
                    </div> 
                    <div class="text-center">
                        <button type="button" class="btn btn-disabled btn-primary" id="draw_sign">Apply Signature
<div class="error-tooltip bottom"><img src="images/cancel.svg" alt=""> Please provide your signature above</div>
                        </button>
                    </div>

<script>
var $sigdiv = $("#signatureparent").jSignature({
                UndoButton:false,
                // line color
                color:"#f00",
                // line width
                lineWidth:2,
                // width/height of signature pad
                width:454,
                height:142
            })
$("#signatureparent").bind("change", function(event){
                    // 'event.target' will refer to DOM element with id "#signature"
                    var d = $(event.target).jSignature("getData", "native")
                    // if there are more than 2 strokes in the signature
                    // or if there is just one stroke, but it has more than 20 points
                    if ( d.length > 0 || ( d.length === 1 && d[0].x.length > 20 ) ){
                        $('#draw_sign').removeClass('btn-disabled');
                        $('.error-tooltip.bottom').hide();
                    } else {
                        $('#draw_sign').addClass('btn-disabled');
                    }
                }
            )


            $("#draw_sign").on('click', function(e){
                e.preventDefault();

                if($(this).hasClass('btn-disabled')){ 
                    $('.error-tooltip.bottom').show();
                    return false;
                }

                if($('.draw-signature').hasClass('active')){
                
                    if($('#signatureparent').jSignature('getData', 'native').length == 0) {
                        $('.error-tooltip.bottom').show();
                    } else {
                        $('.error-tooltip.bottom').hide();
                        var data = $('#signatureparent').jSignature('getData','svgbase64');
                        // var data = datapair.jSignature("getData", "svgbase64");
                        var i = new Image();
                        i.src = "data:" + data[0] + "," + data[1];

                        $('#signature_area').html("<img src='"+i.src+"' width='100%' height='100%'>");
                        $('#signature').hide();
                        $('#signatureModal').modal('hide');
                    }

                } else if($('.type-signature').hasClass('active')){
                    var text_sign = $('.type-area').val();
                    if(text_sign !='') {
                        $('.error-tooltip.bottom').hide();
                        $('#signature_area').html(text_sign);
                        $('#signature').hide();
                        $('#signatureModal').modal('hide');                    
                    } else{
                        $('.error-tooltip.bottom').show();
                        return false;
                    }
                }
            });
</script>

Wednesday, June 26, 2019

Wordpress Pagination Function

$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;

                  $number_posts = 15;

                  $args = array(

                    'posts_per_page'   => $number_posts,

                    'orderby'          => 'date',

                    'order'            => 'DESC',

                    'post_type'        => 'post',

                    'post_status'      => 'publish',

                    'paged'           => $paged,

                  );

                 

                  $loop = new WP_Query( $args );

<?php
                  if (function_exists("pagination")) {
                      pagination($loop->max_num_pages);
                  }
                ?>

/*
* Pagination Function for blog page
*/

function pagination($pages = '', $range = 2)

{
     $showitems = ($range * 2)+1; 
     global $paged;
     if(empty($paged)) $paged = 1;

     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {

             $pages = 1;

         }
     } 

     if(1 != $pages)
     {
         echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";

         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";

         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
             }
         }
         if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
         echo "</div>\n";
     }
}

Tuesday, June 11, 2019

Youtube Responsive video Iframe Code






<div class="container_video">
   <iframe src="https://www.youtube.com/embed/bR0NCM639B8?controls=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
</div>
<style>

.section-video-container .container_video {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%;
}
.section-video-container .container_video iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
</style>

Tuesday, May 21, 2019

Countdown timer JS code


<section class="black-bar">
    <h4>Cash Game Fix enrollment ends in:</h4>
    <h2 class="countdown"><span class="days"></span> days <span class="line">|</span> <span class="hours"></span> hours <span class="line">|</span> <span class="minutes"></span> min <span class="line">|</span> <span class="seconds"></span> sec</h2>
</section>
<script type="text/javascript">
    /* STatic Date Timer start */

    function makeTimer() {

            // var endTime = new Date("29 April 2018 9:56:00 GMT+01:00"); 
            var endTime = new Date("24 May 2019 23:59:59 GMT-07:00");         
            endTime = (Date.parse(endTime) / 1000);

            var now = new Date();
            now = (Date.parse(now) / 1000);


            var timeLeft = endTime - now;


            var days = Math.floor(timeLeft / 86400);
            var hours = Math.floor((timeLeft - (days * 86400)) / 3600);
            var minutes = Math.floor((timeLeft - (days * 86400) - (hours * 3600 )) / 60);
            var seconds = Math.floor((timeLeft - (days * 86400) - (hours * 3600) - (minutes * 60)));


            $clock = $('h2.countdown');
            $days = $clock.find('.days');
            $hours = $clock.find('.hours');
            $minutes = $clock.find('.minutes');
            $seconds = $clock.find('.seconds');

            if(days < 0) days = 0;

            if(hours < 0) hours = 0;

            if(minutes < 0) minutes = 0;

            if(seconds < 0) seconds = 0;

            // If lower than 10, then add 0;
            if( days < 10 ) $days.html('0' + days);
            if( hours < 10 ) $hours.html('0' + hours);
            if( minutes < 10 ) $minutes.html('0' + minutes);
            if( seconds < 10 ) $seconds.html('0' + seconds);

            // If higher than don't add anything.
            if( days > 10 ) $days.html(days);
            if( hours > 10 ) $hours.html(hours);
            if( minutes > 10 ) $minutes.html(minutes);
            if( seconds > 10 ) $seconds.html(seconds);

            if (timeLeft <= 0) {
                clearInterval(makeTimer());
            }

    }
    $(document).ready(function(){
        setInterval(function() { makeTimer(); }, 1000);   
    })
   
</script>
    

Wednesday, March 27, 2019

Scroll inside of the div upto fixed height scroll





/**
* App Features Scroll JS
*/

// $('.sec-inner--appFeatures .left-col').bind('mousewheel DOMMouseScroll', function (event) {
//     event.preventDefault();
//     total = $(".sec-inner--appFeatures .left-col").find('.mediaObject').length;
//     h = $(".sec-inner--appFeatures .left-col").height();
//     scroll(event, h, total);
// });
<div class="left-col tabs">
                            <a class="tab mediaObject mediaObject--md mediaObject--purple">
                                <div class="mediaObject__body">
                                    <div class="mediaObject__body__copy">
                                        <h2 class="mediaObject__title">Chumash with Rashi</h2>
                                        <p class="mediaObject__para">The daily learning of Chumash with Rashi is one of
                                            the three daily
                                            regimens which make up the learning of Chitas.</p>
                                    </div>
                                    <div class="mediaObject__body__img">
                                        <img src="img/feldheim_blank_1.png" alt="">
                                    </div>
                                </div>
                            </a>
                            <!-- ./mediaObject -->
                            <a class="tab mediaObject mediaObject--md mediaObject--orange">
                                <div class="mediaObject__body">
                                    <div class="mediaObject__body__copy">
                                        <h2 class="mediaObject__title">Chumash with Rashi</h2>
                                        <p class="mediaObject__para">The daily learning of Chumash with Rashi is one of
                                            the three daily
                                            regimens which make up the learning of Chitas.</p>
                                    </div>
                                    <div class="mediaObject__body__img">
                                        <img src="img/feldheim_blank_1.png" alt="">
                                    </div>
                                </div>
                            </a>
                            <!-- ./mediaObject -->
                            <a class="tab mediaObject mediaObject--md mediaObject--seaBlue">
                                <div class="mediaObject__body">
                                    <div class="mediaObject__body__copy">
                                        <h2 class="mediaObject__title">Chumash with Rashi</h2>
                                        <p class="mediaObject__para">The daily learning of Chumash with Rashi is one of
                                            the three daily
                                            regimens which make up the learning of Chitas.</p>
                                    </div>
                                    <div class="mediaObject__body__img">
                                        <img src="img/Kehot.png" alt="">
                                    </div>
                                </div>
                            </a>
                            <!-- ./mediaObject -->
                            <a class="tab mediaObject mediaObject--md mediaObject--lightGreen">
                                <div class="mediaObject__body">
                                    <div class="mediaObject__body__copy">
                                        <h2 class="mediaObject__title">Chumash with Rashi</h2>
                                        <p class="mediaObject__para">The daily learning of Chumash with Rashi is one of
                                            the three daily
                                            regimens which make up the learning of Chitas.</p>
                                    </div>
                                    <div class="mediaObject__body__img">
                                        <img src="img/Kehot.png" alt="">
                                    </div>
                                </div>
                            </a>
                            <!-- ./mediaObject -->
                            <a class="tab mediaObject mediaObject--md mediaObject--darkGreen">
                                <div class="mediaObject__body">
                                    <div class="mediaObject__body__copy">
                                        <h2 class="mediaObject__title">Chumash with Rashi</h2>
                                        <p class="mediaObject__para">The daily learning of Chumash with Rashi is one of
                                            the three daily
                                            regimens which make up the learning of Chitas.</p>
                                    </div>
                                    <div class="mediaObject__body__img">
                                        <img src="img/Untitffled-3.png" alt="">
                                    </div>
                                </div>
                            </a>
                            <!-- ./mediaObject -->
                            <a class="tab mediaObject mediaObject--md mediaObject--seaGreen">
                                <div class="mediaObject__body">
                                    <div class="mediaObject__body__copy">
                                        <h2 class="mediaObject__title">Chumash with Rashi</h2>
                                        <p class="mediaObject__para">The daily learning of Chumash with Rashi is one of
                                            the three daily
                                            regimens which make up the learning of Chitas.</p>
                                    </div>
                                    <div class="mediaObject__body__img">
                                        <img src="img/Untitffled-3.png" alt="">
                                    </div>
                                </div>
                            </a>
                            <!-- ./mediaObject -->
                            <a class="tab mediaObject mediaObject--md mediaObject--yellow">
                                <div class="mediaObject__body">
                                    <div class="mediaObject__body__copy">
                                        <h2 class="mediaObject__title">Chumash with Rashi</h2>
                                        <p class="mediaObject__para">The daily learning of Chumash with Rashi is one of
                                            the three daily
                                            regimens which make up the learning of Chitas.</p>
                                    </div>
                                    <div class="mediaObject__body__img">
                                        <img src="img/artscrollbw1.png" alt="">
                                    </div>
                                </div>
                            </a>
                            <!-- ./mediaObject -->
                            <a class="tab mediaObject mediaObject--md mediaObject--royalBlue">
                                <div class="mediaObject__body">
                                    <div class="mediaObject__body__copy">
                                        <h2 class="mediaObject__title">Chumash with Rashi</h2>
                                        <p class="mediaObject__para">The daily learning of Chumash with Rashi is one of
                                            the three daily
                                            regimens which make up the learning of Chitas.</p>
                                    </div>
                                    <div class="mediaObject__body__img">
                                        <img src="img/artscrollbw1.png" alt="">
                                    </div>
                                </div>
                            </a>
                        </div>



// $('.sec-inner--appFeatures .left-col').on('scroll', function (event) {
//     $('.sec-inner--appFeatures .left-col').bind('mousewheel DOMMouseScroll', function (event) {
//         event.preventDefault();
//         total = $(".sec-inner--appFeatures .left-col").find('.mediaObject').length;
//         h = $(".sec-inner--appFeatures .left-col").height();
//         scroll(event, h, total);
//     });
// });

// var num = 0;
// var scrolling = false;

// function scroll(event, h, total) {
//     event.preventDefault();

//     // For 6 Items per block
//     count = Math.ceil(total / 6);

//     // For 4 Items per block
//     // count = Math.ceil(total / 4);

//     if (!scrolling) {
//         scrolling = true;

//         if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0) {
//             num--;
//             num = num < 1 ? 0 : num;
//             hight_offset = num < 1 ? 0 : h * num;
//         } else {
//             if (num < count - 1) { num++; } num = num >= count ? count : num;
//             hight_offset = num > count ? num * h : (h) * num;
//         }

//         // console.log("hight_offset: "+hight_offset +" height:"+ h +" count: "+count+" Total:"+total+" Num:"+num);

//         $('.sec-inner--appFeatures .left-col').animate({
//             scrollTop: (hight_offset)
//         }, 500, "linear", function () {
//             scrolling = false;

//         });

//         if (num == parseInt(count - 1)) {
//             $(".sec-inner--appFeatures .left-col").unbind("mousewheel");
//             $(".sec-inner--appFeatures .left-col").bind("mousewheel");

//         } else if (num == 0) {
//             $(".sec-inner--appFeatures .left-col").unbind("mousewheel");
//             $(".sec-inner--appFeatures .left-col").bind("mousewheel");

//         } else {
//             bindSection();

//         }
//     }
// }

// function bindSection() {
//     $('.sec-inner--appFeatures .left-col').bind('mousewheel DOMMouseScroll', function (event) {
//         event.preventDefault();
//         total = $(".sec-inner--appFeatures .left-col").find('.mediaObject').length;
//         h = $(".sec-inner--appFeatures .left-col").height();
//         scroll(event, h, total);
//     })
// };