Pages

Thursday, January 12, 2017

Add Twitter Widget in HTML Website

Add Twitter Widget in HTML Website


<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
                                <a class="twitter-timeline" href="https://twitter.com/zakeerio">Tweets by Zahid Ali Keerio</a>
                                <script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

Example: 

Tuesday, January 3, 2017

Create Helper function in CodeIgniter

Create Helper function in Codeigniter
------------------------------------------------------------------------
if(!function_exists('sqlRecordsCount')){
function sqlRecordsCount(){
$ci1 =& get_instance();

           // Get Connection of Another Database Defined

   $db2 = $ci1->load->database('otherdb', TRUE);
 

            $query = "SELECT book_id from books";
$query = $db2->query($query);

// echo $db2->last_query();
$result = $query->result_array();
return $result;

}

}

print_r($sqlRecordsCount());

Wednesday, December 7, 2016

Convert 10 OR 9 Digit ISBN Number to 13 Digit ISBN Number in PHP

$isbn = '178629298X';

/**
* Function accepts either 12 or 13 digit number, and either provides or checks the validity of the 13th checksum digit
*    Optionally converts to ISBN 10 as well.
*/
function isbn13checker($input, $convert = FALSE){
$output = FALSE;
if (strlen($input) < 12){
$output = array('error'=>'ISBN too short.');
}
if (strlen($input) > 13){
$output = array('error'=>'ISBN too long.');
}
if (!$output){
$runningTotal = 0;
$r = 1;
$multiplier = 1;
for ($i = 0; $i < 13 ; $i++){
$nums[$r] = substr($input, $i, 1);
$r++;
}
$inputChecksum = array_pop($nums);
foreach($nums as $key => $value){
$runningTotal += $value * $multiplier;
$multiplier = $multiplier == 3 ? 1 : 3;
}
$div = $runningTotal / 10;
$remainder = $runningTotal % 10;

$checksum = $remainder == 0 ? 0 : 10 - substr($div, -1);

$output = array('checksum'=>$checksum);
$output['isbn13'] = substr($input, 0, 12) . $checksum;
if ($convert){
$output['isbn10'] = isbn13to10($output['isbn13']);
}
if (is_numeric($inputChecksum) && $inputChecksum != $checksum){
$output['error'] = 'Input checksum digit incorrect: ISBN not valid';
$output['input_checksum'] = $inputChecksum;
}
}
return $output;
}

/**
* Function accepts either 10 or 9 digit number, and either provides or checks the validity of the 10th checksum digit
*    Optionally converts to ISBN 13 as well.
*/
function isbn10checker($input, $convert = FALSE){
$output = FALSE;
if (strlen($input) < 9){
$output = array('error'=>'ISBN too short.');
}
if (strlen($input) > 10){
$output = array('error'=>'ISBN too long.');
}
if (!$output){
$runningTotal = 0;
$r = 1;
$multiplier = 10;
for ($i = 0; $i < 10 ; $i++){
$nums[$r] = substr($input, $i, 1);
$r++;
}
$inputChecksum = array_pop($nums);
foreach($nums as $key => $value){
$runningTotal += $value * $multiplier;
//echo $value . 'x' . $multiplier . ' + ';
$multiplier --;
if ($multiplier === 1){
break;
}
}
//echo ' = ' . $runningTotal;
$remainder = $runningTotal % 11;
$checksum = $remainder == 1 ? 'X' : 11 - $remainder;
$checksum = $checksum == 11 ? 0 : $checksum;
$output = array('checksum'=>$checksum);
$output['isbn10'] = substr($input, 0, 9) . $checksum;
if ($convert){
$output['isbn13'] = isbn10to13($output['isbn10']);
}
if ((is_numeric($inputChecksum) || $inputChecksum == 'X') && $inputChecksum != $checksum){
$output['error'] = 'Input checksum digit incorrect: ISBN not valid';
$output['input_checksum'] = $inputChecksum;
}
}
return $output;
}

function isbn10to13($isbn10){

$isbnStem = strlen($isbn10) == 10 ? substr($isbn10, 0,9) : $isbn10;
$isbn13data = isbn13checker('978' . $isbnStem);
return $isbn13data['isbn13'];

}

function isbn13to10($isbn13){

$isbnStem = strlen($isbn13) == 13 ? substr($isbn13, 12) : $isbn13;
$isbnStem = substr($isbn13, -10);
$isbn10data = isbn10checker($isbnStem);
return $isbn10data['isbn10'];
}
echo isbn10to13($isbn);

Tuesday, December 6, 2016

Decent CSS Spin Loader

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<script type="text/javascript">
  $(document).ready(function(){
    // alert();
    setTimeout(function() {
                $('#divLoader').fadeOut('slow');
                $('#loader_container').fadeOut('slow');
            }, 100);
  });


</script>

 <style type="text/css">

/* CSS LOADER*/

#loader {
    border: 16px solid #f3f3f3;
    border-radius: 50%;
    border-top: 16px solid #3498db;
    width: 120px;
    height: 120px;
    -webkit-animation: spin 2s linear infinite;
    animation: spin 2s linear infinite;
}

#divLoader {
    position: absolute;
    top: 40%;
    left: 45%;
    z-index: 99999;
}

@-webkit-keyframes spin {
    0% {
        -webkit-transform: rotate(0deg);
    }
    100% {
        -webkit-transform: rotate(360deg);
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

  #loader_container {
    width: 100%;
    height: 100%;
    /* border: 5px solid blue; */
    display: inline-block;
    position: absolute;
    background-color: rgba(70, 67, 67, 0.84);
    z-index: 9998;
    /*display: none;*/
}

.pleasewait {
    font-size: 19px;
    color: #3498db !important;
    margin-top: 10px;
    text-align: center;
}
</style>

<div id="loader_container" stylle=""><div id="divLoader" style=""><div id="loader" class="loader">&nbsp;</div><p class="pleasewait">Loading <br> Please wait... </p></div></div>

Wednesday, October 26, 2016

Read CSV file in PHP

CODE HERE

<?php
$csv = array();

// LOAD CSV FILE HERE

$lines = file('files/Flyers.csv', FILE_IGNORE_NEW_LINES);
//$lines = array_filter($lines);
//$lines = array_unique($lines);

foreach($lines as $line)
{
$lines = explode(",",$line);
//echo '<pre>';print_r($lines);

// Columns AND ROWS HERE

$title = mysql_real_escape_string($lines[0]);
$isbn = mysql_real_escape_string($lines[1]);
$exp  = $lines[2];
$price = $lines[3];

echo $title."<br>";
echo $isbn."<br>";
echo         $exp."<br>";
echo         $price.'<br>';
}

?>

Check All checkboxes with single Checkbox

<input type="checkbox" id="checkAll">Check All
<hr />
<input type="checkbox" class="checkboxes">Item 1
<input type="checkbox" class="checkboxes">Item 2
<input type="checkbox" class="checkboxes">Item3


<script type="text/javascript">
$('#checkAll').on('click',function(){
$('.checkboxes').not(this).prop('checked', this.checked);
});
</script>

Thursday, June 9, 2016

PHP Wordpress Pagination Function


function pagination($table,$adjacent,$limit,$targetUrl,$query_section){
global $wpdb;
$tbl_name= $table; //your table name
// How many adjacent pages should be shown on each side?
$adjacents = $adjacent;
// echo $query_section;

/*
  First get total number of rows in data table.
  If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = $query_section;

$total_rec = $wpdb->get_results($query);
foreach($total_rec as $nums){
$total_pages =  $nums->num;
}

/* Setup vars for query. */
$targetpage = $targetUrl; //your file name  (the name of this file)
$limit = $limit; //how many items to show per page
$page = get_query_var( 'page', 1 );
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 0; //if no page var is given, set start to 0

/* Get data. */
$sql = "SELECT * FROM $tbl_name LIMIT $start, $limit";
$result = $wpdb->get_results($sql);

/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1

/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
$pagination .="

<style>
div.pagination {
padding: 3px;
margin: 3px;
}

div.pagination a {
padding: 2px 5px 2px 5px;
margin: 2px;
border: 1px solid #AAAADD;
text-decoration: none; /* no underline */
color: #000099;
}
div.pagination a:hover, div.pagination a:active {
border: 1px solid #000099;
color: #000;
}
div.pagination span.current {
padding: 2px 5px 2px 5px;
z-index: 3;
   color: #fff;
   background-color: #337ab7;
   border-color: #337ab7;
   cursor: default;
}
div.pagination span.disabled {
padding: 2px 5px 2px 5px;
margin: 2px;
border: 1px solid #EEE;
color: #DDD;
}

</style>";
if($lastpage > 1)
{
if($start+$limit <= $total_pages){
$max_rec = $start+$limit;
} else {
$max_rec = $total_pages;
}

$pagination .="<div class='pull-left'>Showing $start to $max_rec of $total_pages records</div>";
$pagination .="<div class=\"dataTables_paginate paging_bootstrap_full_number pull-right\">";
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?page=$prev\"><i class=\"fa fa-angle-double-left\" ></i> Previous</a>";
else
$pagination.= "<span class=\"disabled\"><i class=\"fa fa-angle-double-left\" ></i> Previous</span>";

//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
}


// <li class="active"><a href="#">1</a></li>

//next button
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?page=$next\">Next <i class=\"fa fa-angle-double-right\" ></i></a>";
else
$pagination.= "<span class=\"disabled\">Next <i class=\"fa fa-angle-double-right\" ></i></span>";
$pagination.= "</di></div>\n";
}
return $pagination;
}
pagination('login',3,20,site_url().'/senders/',$query);