Created
March 31, 2016 17:28
-
-
Save mhamzas/43676f0fb37c0f459e068a1e331f3a83 to your computer and use it in GitHub Desktop.
Useful PHP functions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
// Function: array_to_json // | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
function array_to_json( $array ) | |
{ | |
if( !is_array( $array ) ) | |
{ | |
return false; | |
} | |
$associative = count( array_diff( array_keys($array), array_keys( array_keys( $array )) )); | |
if( $associative ) | |
{ | |
$construct = array(); | |
foreach( $array as $key => $value ) | |
{ | |
// We first copy each key/value pair into a staging array, | |
// formatting each key and value properly as we go. | |
// Format the key: | |
if( is_numeric($key) ) | |
{ | |
$key = "key_$key"; | |
} | |
$key = "\"".addslashes($key)."\""; | |
// Format the value: | |
if( is_array( $value )) | |
{ | |
$value = array_to_json( $value ); | |
} | |
else if( !is_numeric( $value ) || is_string( $value ) ) | |
{ | |
$value = "\"".addslashes($value)."\""; | |
} | |
// Add to staging array: | |
$construct[] = "$key: $value"; | |
} | |
// Then we collapse the staging array into the JSON form: | |
$result = "{ " . implode( ", ", $construct ) . " }"; | |
} | |
else | |
{ // If the array is a vector (not associative): | |
$construct = array(); | |
foreach( $array as $value ) | |
{ | |
// Format the value: | |
if( is_array( $value )) | |
{ | |
$value = array_to_json( $value ); | |
} | |
else if( !is_numeric( $value ) || is_string( $value ) ) | |
{ | |
$value = "'".addslashes($value)."'"; | |
} | |
// Add to staging array: | |
$construct[] = $value; | |
} | |
// Then we collapse the staging array into the JSON form: | |
$result = "[ " . implode( ", ", $construct ) . " ]"; | |
} | |
return $result; | |
}// End of array_to_json function. | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
// Function: GetCtrl // | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
function GetCtrl($ctrlDetail) | |
{ | |
//echo "<pre>";print_r($ctrlDetail); | |
// HTML: text. | |
if($ctrlDetail['type']=="text") | |
{ | |
$strValue=""; | |
if(isset($ctrlDetail['value'])) | |
$strValue =$ctrlDetail['value']; | |
return "<input type=text size=". $ctrlDetail['size'] ." name=".$ctrlDetail['name'] ." value='$strValue'>"; | |
}// End of HTML: text. | |
// HTML: Combo box. | |
if($ctrlDetail['type']=="cmb") | |
{ | |
$strValue=""; | |
$strJS=""; | |
if(isset($ctrlDetail['value'])) | |
{ | |
$strValue =$ctrlDetail['value']; | |
$arValues=explode(",",$strValue); | |
sort($arValues); | |
} | |
if(isset($ctrlDetail['js'])) | |
{ | |
$strJS =$ctrlDetail['js']; | |
} | |
else | |
{ | |
$strJS = ""; | |
} | |
if(isset($ctrlDetail['size'])) | |
{ | |
$nSize =$ctrlDetail['size']; | |
} | |
$strMulti =""; | |
if($nSize>1) | |
{ | |
$strMulti = "multiple='multiple'"; | |
} | |
if(isset($ctrlDetail['style'])) | |
{ | |
$strStyle = $ctrlDetail['style']; | |
} | |
else | |
{ | |
$strStyle = ""; | |
} | |
if(isset($ctrlDetail['class'])) | |
{ | |
$strClass = $ctrlDetail['class']; | |
} | |
if(isset($ctrlDetail['sText'])) | |
{ | |
$strSText = $ctrlDetail['sText']; | |
} | |
else | |
{ | |
$strSText = ""; | |
} | |
$strOption="<select class='$strClass' $strMulti size=$nSize tabindex='2' style='width:342px;' name=".$ctrlDetail['name']." id=".$ctrlDetail['name']." $strJS $strStyle >"; | |
if(isset($ctrlDetail['cData'])) | |
{ | |
if($nSize<=1) | |
{ | |
$strOption.="<option value='0'>$strSText</option>"; | |
} | |
$arrData=$ctrlDetail['cData']; | |
$cntAr=0; | |
foreach($arrData as $key=>$strCValue) | |
{ | |
//$strValue=$arrData[$cntItem]; | |
$strSelected=""; | |
if(isset($arValues[$cntAr]) && $strValue!=$arValues[$cntAr]) | |
{ | |
$strValue=$arValues[$cntAr]; | |
} | |
if($strValue==$key) | |
{ | |
$strSelected="selected='selected'"; | |
$cntAr++; | |
} | |
$strOption.="<option $strSelected value='$key'>$strCValue</option>"; | |
$strSelected=""; | |
} | |
} | |
else | |
{ | |
//$strOption.="<option value='-1'>Other</option>"; | |
} | |
$strOption.="</select>"; | |
return $strOption; | |
}// End of HTML: Combo box. | |
// MOS Product. | |
if($ctrlDetail['type']=="product") | |
{ | |
$strOption=""; | |
if(isset($ctrlDetail['isSession'])) | |
{ | |
$isSession = $ctrlDetail['isSession']; | |
} | |
else | |
{ | |
$isSession = false; | |
} | |
if(isset($ctrlDetail['cData']) && !empty($ctrlDetail['cData'])) | |
{ | |
foreach($ctrlDetail['cData'] as $row) | |
{ | |
if (trim($row['webstoredisplayurl']) == ""){$tmpCont = $row['webstoreId'];}else{$tmpCont = $row['webstoreId'];} | |
$strOption.="<div class='pin'><div class='holder'>"; | |
if($row['defaultimage'] != "" && file_exists(PATH_DIR."images/products/image160x190/".$row['defaultimage'])) | |
{ | |
list($width, $height) = getimagesize(PATH_DIR.'images/products/image160x190/'.$row['defaultimage']); | |
$strOption.="<a class='image ajax' href='".base_url()."product/".$row['id']."' title=''><img class='lazy' alt='".$row['title']."' src='".PHPIMGPATH."includes/images/blank.gif' data-original='".PHPIMGPATH."images/products/image160x190/".$row['defaultimage']."' width='".$width."' height='".$height."'><div class='prominprtagbx'><div class='prominprtag'>".$row['currency']." ".$row['price']."</div></div></a>"; | |
} | |
if($isSession) | |
{ | |
$strOption.="<a id='dawood_".$row['id']."' onclick='pl(".$row['id'].")' class='lkbtnonprdc'>"; | |
if(!empty($row['isILike']) && $row['isILike']) | |
{ | |
$strOption.="Unlike</a>"; | |
} | |
else | |
{ | |
$strOption.="Like</a>"; | |
} | |
} | |
else | |
{ | |
$strOption.="<a href='#login_form' class='lkbtnonprdc'>Like</a>"; | |
} | |
$strOption.="<a href='' class='lkbtnonprdc sha'>Share</a></div><p class='title'>".convertlang($row['title'])."</p><div class='break'></div><p class='info'>"; | |
if(isset($row['logo']) && $row['logo'] != "" && file_exists(PATH_DIR."images/webstores/iconForDeal/".$row['logo'])) | |
{ | |
list($width, $height) = getimagesize(PATH_DIR.'images/webstores/iconForDeal/'.$row['logo']); | |
$strOption.="<a href='".base_url()."store/".$tmpCont."' class='img'><img class='lazy' src='".PHPIMGPATH."includes/images/blank.gif' data-original='".PHPIMGPATH."images/webstores/iconForDeal/".$row['logo']."' width='".$width."' height='".$height."' /></a>"; | |
} | |
else | |
{ | |
list($width, $height) = getimagesize(PATH_DIR.'includes/images/store-ava-small.png'); | |
$strOption.="<a href='".base_url()."store/".$tmpCont."' class='img'><img class='lazy' src='".PHPIMGPATH."includes/images/blank.gif' data-original='".PHPIMGPATH."includes/images/store-ava-small.png' /></a>"; | |
} | |
$strOption.="<span><a href='".base_url()."store/".$tmpCont."'>".convertlang($row['name'])."</a><br />".timeDuration($row['postingDate'], $row['postingTime']); | |
/////////////////////////////////////////////////// | |
if($isSession) | |
{ | |
$tmp = $isSession; | |
if ( $row['userId'] != $tmp['id']) | |
{ | |
$strOption.="<a class='followbtnor' id='element".$row['webstoreId']."' onclick='followStore(".$row['webstoreId'].")'>"; | |
if(!empty($row['isIFollow']) && $row['isIFollow']) | |
{ | |
$strOption.="Following</a></span></p></div>"; | |
} | |
else | |
{ | |
$strOption.="Follow</a></span></p></div>"; | |
} | |
} | |
else | |
{ | |
$strOption.="<a class='followbtnor' onClick=\"javascript:alert('You can\'t follow your own Store.');\" title='follow'>Follow</a></span></p></div>"; | |
} | |
} | |
else | |
{ | |
$strOption.="<a class='followbtnor' onClick=\"javascript:location.href='#login_form'\" title='follow'>Follow</a></span></p></div>"; | |
} | |
////////////////////////////////////////////////////////// | |
} | |
} | |
return $strOption; | |
}// End of MOS Product. | |
// MOS Store. | |
if($ctrlDetail['type']=="store") | |
{ | |
$strOption=""; | |
if(isset($ctrlDetail['isSession'])) | |
{ | |
$isSession = $ctrlDetail['isSession']; | |
} | |
else | |
{ | |
$isSession = false; | |
} | |
if(isset($ctrlDetail['cData']) && !empty($ctrlDetail['cData'])) | |
{ | |
foreach($ctrlDetail['cData'] as $row) | |
{ | |
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
if (trim($row['webstoredisplayurl']) == ""){$tmpCont = $row['id'];}else{$tmpCont = $row['webstoredisplayurl'];} | |
$strName = $row['name'];$strName = (strlen($strName) > 25) ? substr($strName, 0, 22).'...' : $strName; | |
$strOption.="<div class='storebox-smaller pin'><div class='storebox-smaller-heading'><a href='".base_url()."store/".$tmpCont."'>".convertlang($strName)."</a></div><div class='cb'></div><div class='storebox-smaller-image'><a href='".base_url()."store/".$tmpCont."'>"; | |
if($row['logo'] != "" && file_exists(PATH_DIR."images/webstores/logo/".$row['logo'])) | |
{ | |
$strOption.="<img class='lazy' src='".PHPIMGPATH."includes/images/blank.gif' data-original='".base_url()."images/webstores/logo/".$row['logo']."'>"; | |
} | |
else | |
{ | |
$strOption.="<img class='lazy' src='".PHPIMGPATH."includes/images/blank.gif' data-original='".base_url()."includes/images/store-ava-big.png'>"; | |
} | |
$strOption.="</a></div><div class='storebox-smaller-four'><a href='#'><img class='lazy' src='".PHPIMGPATH."includes/images/blank.gif' data-original='".base_url(); | |
if(isset($row['defaultimage1']) && $row['defaultimage1'] != "" && file_exists(PATH_DIR."images/products/thumbnail/".$row['defaultimage1'])) | |
{ | |
$strOption.="images/products/thumbnail/".$row['defaultimage1']."' /></a><a href='#'><img class='lazy' src='".PHPIMGPATH."includes/images/blank.gif' data-original='".base_url(); | |
} | |
else | |
{ | |
$strOption.="includes/images/store-ava-small.png' /></a><a href='#'><img class='lazy' src='".PHPIMGPATH."includes/images/blank.gif' data-original='".base_url(); | |
} | |
if(isset($row['defaultimage2']) && $row['defaultimage2'] != "" && file_exists(PATH_DIR."images/products/thumbnail/".$row['defaultimage2'])) | |
{ | |
$strOption.="images/products/thumbnail/".$row['defaultimage2']."' /></a><a href='#'><img class='lazy' src='".PHPIMGPATH."includes/images/blank.gif' data-original='".base_url(); | |
} | |
else | |
{ | |
$strOption.="includes/images/store-ava-small.png' /></a><a href='#'><img class='lazy' src='".PHPIMGPATH."includes/images/blank.gif' data-original='".base_url(); | |
} | |
if(isset($row['defaultimage3']) && $row['defaultimage3'] != "" && file_exists(PATH_DIR."images/products/thumbnail/".$row['defaultimage3'])) | |
{ | |
$strOption.="images/products/thumbnail/".$row['defaultimage3']."' /></a><a href='#'><img class='lazy' src='".PHPIMGPATH."includes/images/blank.gif' data-original='".base_url(); | |
} | |
else | |
{ | |
$strOption.="includes/images/store-ava-small.png' /></a><a href='#'><img class='lazy' src='".PHPIMGPATH."includes/images/blank.gif' data-original='".base_url(); | |
} | |
if(isset($row['defaultimage4']) && $row['defaultimage4'] != "" && file_exists(PATH_DIR."images/products/thumbnail/".$row['defaultimage4'])) | |
{ | |
$strOption.="images/products/thumbnail/".$row['defaultimage4']."' /></a></div><div class='storebox-smaller-right'><div class='sharebox-smaller-buttons-box'>"; | |
} | |
else | |
{ | |
$strOption.="includes/images/store-ava-small.png' /></a></div><div class='storebox-smaller-right'><div class='sharebox-smaller-buttons-box'>"; | |
} | |
if($isSession) | |
{ | |
$tmp = $isSession; | |
if ( $row['userId'] != $tmp['id']) | |
{ | |
$strOption.="<div class='followbutton whitbtn' id='element".$row['id']."' onclick='followStore(".$row['id'].")' title='follow'>"; | |
if(!empty($row['isIFollow']) && $row['isIFollow']) | |
{ | |
$strOption.="Following</div>"; | |
} | |
else | |
{ | |
$strOption.="Follow</div>"; | |
} | |
} | |
else | |
{ | |
$strOption.="<div class='followbutton whitbtn' onClick=\"javascript:alert('You can\'t follow your own Store.');\" title='follow'>Follow</div>"; | |
} | |
} | |
else | |
{ | |
$strOption.="<div class='followbutton whitbtn' onClick=\"javascript:location.href='#login_form'\" title='follow'>Follow</div>"; | |
} | |
$strOption.="</div></div></div>"; | |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
} | |
} | |
return $strOption; | |
}// End of MOS Store. | |
}// End of GetCtrl function. | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
// Function: get_client_ip // | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
function get_client_ip() | |
{ | |
if (!empty($_SERVER['HTTP_CLIENT_IP'])) | |
{ //check ip from share internet | |
$ip = $_SERVER['HTTP_CLIENT_IP']; | |
} | |
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) | |
{ //to check ip is pass from proxy | |
$ip = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
} | |
else | |
{ | |
$ip = $_SERVER['REMOTE_ADDR']; | |
} | |
return $ip; | |
}// End of get_client_ip function. | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
// Function: isValidateURL // | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
function isValidateURL($stringUrl) | |
{ | |
if(preg_match('/[^a-z_\-0-9]/i', $stringUrl)) | |
{ | |
return false; | |
} | |
else | |
{ | |
return true; | |
} | |
}// End of isValidateURL function. | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
// Function: convert24HoursTo12Hours // | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
function convert24HoursTo12Hours ( $hour, $minute ) | |
{ | |
$ampm = ($hour >=12 && $hour <24) ? "PM" : "AM"; | |
$newhour = ($hour % 12 === 0) ? 12 : $hour % 12; | |
return $newhour .':'. $minute.' ' . $ampm; | |
}// End of convert24HoursTo12Hours function. | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
// Function: monthTextualRepresentation // | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
function monthTextualRepresentation($returnMonth) | |
{ | |
$month = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
return $month[$returnMonth]; | |
}// End of monthTextualRepresentation function. | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
// Function: timeDuration // | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
function timeDuration ($Date, $Time) | |
{ | |
if($Date == "" || $Time == "") | |
{ | |
return ""; | |
} | |
$timestamp = strtotime( $Date.' '.$Time ); | |
$difference = time() - $timestamp; | |
$periods = array("sec", "min", "hour", "day", "week", "month", "year", "decade"); | |
$lengths = array("60", "60", "24", "7", "4.35", "12", "10"); | |
if ($difference > 0) | |
{ | |
$ending = " ago"; | |
} | |
else | |
{ | |
//$difference = -$difference; | |
//$ending = " to go"; | |
$ending = $Date; | |
} | |
for($j = 0; $difference >= $lengths[$j]; $j++) | |
{ | |
$difference /= $lengths[$j]; | |
} | |
$difference = round($difference); | |
if($difference != 1) | |
{ | |
$periods[$j].= "s"; | |
} | |
if(($difference >= 2 && $periods[$j] =="days") || $periods[$j] =="weeks" || $periods[$j] =="months" || $periods[$j] =="years" || $periods[$j] =="decades" || $periods[$j] =="week" || $periods[$j] =="month" || $periods[$j] =="year" || $periods[$j] =="decade")//$periods[$j] !="sec" || $periods[$j] !="min" || $periods[$j] !="hour" || | |
{ | |
return $Date; | |
} | |
else return $difference .' '. $periods[$j] . $ending; | |
}// End of timeDuration function. | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
// Function: message_smiley // | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
function message_smiley($msg) | |
{ | |
$smilies = array( | |
':|' => 'mellow', | |
':-|' => 'mellow', | |
':-o' => 'ohmy', | |
':-O' => 'ohmy', | |
':o' => 'ohmy', | |
':O' => 'ohmy', | |
';)' => 'wink', | |
';-)' => 'wink', | |
':p' => 'tongue', | |
':-p' => 'tongue', | |
':P' => 'tongue', | |
':-P' => 'tongue', | |
':D' => 'biggrin', | |
':-D' => 'biggrin', | |
'8)' => 'cool', | |
'8-)' => 'cool', | |
':)' => 'smile', | |
':-)' => 'smile', | |
':(' => 'sad', | |
':-(' => 'sad', | |
); | |
$sizes = array( | |
'biggrin' => 18, | |
'cool' => 20, | |
'haha' => 20, | |
'mellow' => 20, | |
'ohmy' => 20, | |
'sad' => 20, | |
'smile' => 18, | |
'tongue' => 20, | |
'wink' => 20, | |
); | |
$replace = array(); | |
foreach ($smilies as $smiley => $imgName) | |
{ | |
$size = $sizes[$imgName]; | |
array_push($replace, '<img src="imgs/'.$imgName.'.gif" alt="'.$smiley.'" width="'.$size.'" height="'.$size.'" />'); | |
} | |
$subject = str_replace(array_keys($smilies), $replace, $msg); | |
echo $subject.'usman'; | |
}// End of message_smiley function. | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
// Function: timed // | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | |
function timed($Date, $Time) | |
{ | |
$to_time = strtotime($Date.' '.$Time); | |
$currenttime = strtotime(date('y-m-d').' '.date('H:i:s')); | |
return round(abs($currenttime - $to_time) / 60,2); | |
}// End of timed function. | |
function noOfDaysRemain($Date) | |
{ | |
$now = time(); | |
$your_date = strtotime($Date); | |
$datediff = $now - $your_date; | |
return floor($datediff/(60*60*24)); | |
} | |
function makeClickableLinks($s) { | |
// $productDescription=$productDetails=stripslashes($s); | |
//return $productDetails; | |
return preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" target="_blank">$1</a>', $s); | |
} | |
function showvideo($s) { | |
return preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a style="display:none" class="oembed" href="$1" target="_blank">$1</a>', $s); | |
} | |
function convertlang($s) | |
{ | |
$productDescription=$productDetails=strip_tags($s); | |
$productDetails=strip_tags($productDescription,"<br><br/><br />"); | |
$productDetails=str_ireplace("\n","<br/>",$productDetails); | |
$productDetails=str_ireplace("\n","<br />",$productDetails); | |
$productDetails=wordwrap($productDetails,56,"\n",TRUE); | |
return $productDetails; | |
} | |
function messageuserpic($id) | |
{ | |
$CI = get_instance(); | |
// You may need to load the model if it hasn't been pre-loaded | |
$CI->load->model('common_models'); | |
// Call a function of the model | |
// $CI->my_model->do_something(); | |
return $CI->common_models->select_where_lim('photo','personalprofile',array('profileId'=> $id),1); | |
} | |
function messagestorepic($id) | |
{ | |
$CI = get_instance(); | |
// You may need to load the model if it hasn't been pre-loaded | |
$CI->load->model('common_models'); | |
return $CI->common_models->select_where_lim('logo,name','webstores',array('id'=> $id),1); | |
} | |
function usernamemessage($id) | |
{ | |
$CI = get_instance(); | |
// You may need to load the model if it hasn't been pre-loaded | |
$CI->load->model('common_models'); | |
return $CI->common_models->select_where_lim('fullName','user',array('id'=> $id),1); | |
} | |
function store_messagescount($id) | |
{ | |
$CI = get_instance(); | |
// You may need to load the model if it hasn't been pre-loaded | |
$CI->load->model('header_model'); | |
return $CI->header_model->get_storemsgcount($id); | |
} | |
function getRemaining($future){ | |
$seconds = strtotime($future) - time(); | |
$days = floor($seconds / 86400); | |
$seconds %= 86400; | |
$hours = floor($seconds / 3600); | |
$seconds %= 3600; | |
$minutes = floor($seconds / 60); | |
$seconds %= 60; | |
if($days <0 && $minutes < 0 && $seconds <0 && $hours < 0) | |
{ | |
echo "Sold Out"; | |
} | |
else | |
{ | |
if($days < 2 ) | |
{ | |
$days='1 day'; | |
}elseif($days < 1 ) | |
{ | |
$days='0 days'; | |
} | |
else | |
{ | |
$days=$days.' days'; | |
} | |
if($hours < 1 ) | |
{ | |
$hours='0 :'; | |
} | |
else | |
{ | |
$hours=$hours.' :'; | |
} | |
if($minutes < 1 ) | |
{ | |
$minutes=''; | |
} | |
else | |
{ | |
$minutes = $minutes.' :'; | |
} | |
if($seconds < 1 ) | |
{ | |
$seconds=''; | |
} | |
else | |
{ | |
$seconds=$seconds.' :'; | |
} | |
if($days == '' && $hours == '' && $minutes == '' && $seconds == '') | |
{ | |
echo "Sold Out"; | |
} | |
else | |
{ | |
if($days=='0 days'){ | |
$days=$hours; | |
} | |
echo "$days Left"; | |
} | |
} | |
} | |
function getRemaining_deal($future){ | |
$seconds = strtotime($future) - time(); | |
$days = floor($seconds / 86400); | |
$seconds %= 86400; | |
$hours = floor($seconds / 3600); | |
$seconds %= 3600; | |
$minutes = floor($seconds / 60); | |
$seconds %= 60; | |
if($days <0 && $minutes < 0 && $seconds <0 && $hours < 0) | |
{ | |
echo "Sold Out"; | |
} | |
else | |
{ | |
if($days < 1 ) | |
{ | |
$days='0 days'; | |
} | |
else | |
{ | |
$days=$days.' days'; | |
} | |
if($hours < 1 ) | |
{ | |
$hours='0 :'; | |
} | |
else | |
{ | |
$hours=$hours.' :'; | |
} | |
if($minutes < 1 ) | |
{ | |
$minutes=''; | |
} | |
else | |
{ | |
$minutes = $minutes.' :'; | |
} | |
if($seconds < 1 ) | |
{ | |
$seconds=''; | |
} | |
else | |
{ | |
$seconds=$seconds.' :'; | |
} | |
if($days == '' && $hours == '' && $minutes == '' && $seconds == '') | |
{ | |
echo "Sold Out"; | |
} | |
else | |
{ | |
echo "$days $hours $minutes $seconds Left"; | |
} | |
} | |
} | |
function generateRandomCharacters($length, $lower = true, $upper = true, $nums = true, $special = false) | |
{ | |
$pool_lower = 'abcdefghijklmopqrstuvwxyz'; | |
$pool_upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
$pool_nums = '0123456789'; | |
$pool_special = ''; | |
$pool = ''; | |
$res = ''; | |
if ($lower === true) { | |
$pool .= $pool_lower; | |
} | |
if ($upper === true) { | |
$pool .= $pool_upper; | |
} | |
if ($nums === true) { | |
$pool .= $pool_nums; | |
} | |
if ($special === true) { | |
$pool .= $pool_special; | |
} | |
if (($length < 0) || ($length == 0)) { | |
return $res; | |
} | |
srand((double) microtime() * 1000000); | |
for ($i = 0; $i < $length; $i++) { | |
$charidx = rand() % strlen($pool); | |
$char = substr($pool, $charidx, 1); | |
$res .= $char; | |
} | |
return $res; | |
} | |
function removeSpecialCharacters($String) | |
{ | |
$tit= preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $String); | |
return $tit; | |
} | |
function stringlimit($string,$limit) | |
{ | |
if(strlen(strip_tags($string))>$limit) | |
{ | |
$str='...'; | |
return substr(strip_tags($string),0,$limit).$str; | |
} | |
return $string; | |
} | |
function makeClickableLinks1($text) { | |
//$text = str_replace("&bull", "101145", $text); | |
$text= preg_replace_callback('/[^\w\d ]/i','_dropAsciOver127', $text); | |
//$text=str_replace("8226;","",mb_convert_encoding($text, 'HTML-ENTITIES', 'UTF-8')); | |
$text = preg_replace('/(((f|ht){1}tp|tps:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i', | |
'<a target="blank" href="\\1">\\1</a>', $text); | |
$text = preg_replace('/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i', | |
'\\1<a target="blank" href="http://\\2">\\2</a>', $text); | |
$text = preg_replace('/([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})/i', | |
'<a target="blank" href="mailto:\\1">\\1</a>', $text); | |
//$text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "<li><b>working</b></li>", $text); | |
return $text; | |
} | |
function makeClickableLinks2($text) { | |
//$text = str_replace("&bull", "101145", $text); | |
$text= preg_replace_callback('/[^\w\d ]/i','_dropAsciOver127', $text); | |
//$text=str_replace("8226;","",mb_convert_encoding($text, 'HTML-ENTITIES', 'UTF-8')); | |
$text = preg_replace('/(((http\:\/\/|ftp\:\/\/|https\:\/\/))[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+(?=[^>]*(<|$)))/i', | |
'<a target="blank" href="\\1">\\1</a>', $text); | |
$text = preg_replace('/(((www\.))[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+(?=[^>]*(<|$)))/i', | |
'<a target="_blank" href="http://\\1">\\1</a>', $text); | |
$text = preg_replace('/([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})/i', | |
'<a target="blank" href="mailto:\\1">\\1</a>', $text); | |
//$text = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "<li><b>working</b></li>", $text); | |
return $text; | |
} | |
function _dropAsciOver127($entity){ | |
////////////////////// Code For Re Using ////// | |
/// | |
//if(($asciCode = ord($entity[0])) == 38) | |
//{ | |
// return 'usman'; | |
//} | |
//else | |
///////////////////////////////////////////////// | |
if(($asciCode = ord($entity[0])) > 127){ | |
return ''; | |
}else{ | |
return $entity[0]; | |
} | |
} | |
function getpercentage($actual,$selling) | |
{ | |
return round(100-(($selling/$actual)*100),2) ; | |
} | |
function get_deals_count($id) | |
{ | |
$CI = get_instance(); | |
// You may need to load the model if it hasn't been pre-loaded | |
$CI->load->model('deal_model'); | |
return $CI->deal_model->order_count($id); | |
} | |
function get_livedealscount($cityId,$category) | |
{ | |
$CI = get_instance(); | |
$CI->load->model('deal_model'); | |
$counts=$CI->deal_model->deals($cityId,500,0,'',$category); | |
return $counts->num_rows(); | |
} | |
function get_agentname($id) | |
{ | |
$CI = get_instance(); | |
$CI->load->model('deal_model'); | |
$dealinfo=$CI->deal_model->getdeal($id); | |
foreach($dealinfo->result() as $row) | |
{ | |
$agentId=$row->agentId; | |
} | |
$userinfo=$CI->deal_model->getuserinfo($agentId); | |
foreach($userinfo->result() as $row) | |
{ | |
$agentname=$row->name; | |
} | |
return $agentname; | |
} | |
function getstorenamefromdealId($id) | |
{ | |
$CI = get_instance(); | |
$CI->load->model('deal_model'); | |
$storeId=$CI->deal_model->get_storeId($id); | |
$storename=$CI->deal_model->get_storename($storeId); | |
return $storename; | |
} | |
function get_userordersbystatus($userId,$status) | |
{ | |
$CI = get_instance(); | |
// You may need to load the model if it hasn't been pre-loaded | |
$CI->load->model('manage_model'); | |
return $CI->manage_model->getuserordersbystatus($userId,$status); | |
} | |
function removespecialcharactersExceptDot($text) | |
{ | |
//$text=strtolower($text); | |
$code_entities_match = array('-',' ','--','"','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','/','*','+','~','`','='); | |
$code_entities_replace = array('','','','','','','','','','','','','','','','','','','','','','','','','','',''); | |
$text = str_replace($code_entities_match, $code_entities_replace, $text); | |
return $text; | |
} | |
function findExtension($fileName) | |
{ | |
$fileName = strtolower($fileName) ; | |
$extension = split("[/\\.]", $fileName) ; | |
$n = count($extension)-1; | |
$extension = $extension[$n]; | |
return $extension; | |
} | |
function get_shoutcomments($id) | |
{ | |
$CI = get_instance(); | |
// You may need to load the model if it hasn't been pre-loaded | |
$CI->load->model('deal_model'); | |
return $CI->deal_model->get_shoutcomments($id); | |
} | |
function time_stamp($session_time) | |
{ | |
$time_difference = time() - $session_time ; | |
$seconds = $time_difference ; | |
$minutes = round($time_difference / 60 ); | |
$hours = round($time_difference / 3600 ); | |
$days = round($time_difference / 86400 ); | |
$weeks = round($time_difference / 604800 ); | |
$months = round($time_difference / 2419200 ); | |
$years = round($time_difference / 29030400 ); | |
if($seconds <= 60) | |
{ | |
echo"$seconds seconds ago"; | |
} | |
else if($minutes <=60) | |
{ | |
if($minutes==1) | |
{ | |
echo"one minute ago"; | |
} | |
else | |
{ | |
echo"$minutes minutes ago"; | |
} | |
} | |
else if($hours <=24) | |
{ | |
if($hours==1) | |
{ | |
echo"one hour ago"; | |
} | |
else | |
{ | |
echo"$hours hours ago"; | |
} | |
} | |
else if($days <=7) | |
{ | |
if($days==1) | |
{ | |
echo"one day ago"; | |
} | |
else | |
{ | |
echo"$days days ago"; | |
} | |
} | |
else if($weeks <=4) | |
{ | |
if($weeks==1) | |
{ | |
echo"one week ago"; | |
} | |
else | |
{ | |
echo"$weeks weeks ago"; | |
} | |
} | |
else if($months <=12) | |
{ | |
if($months==1) | |
{ | |
echo"one month ago"; | |
} | |
else | |
{ | |
echo"$months months ago"; | |
} | |
} | |
else | |
{ | |
if($years==1) | |
{ | |
echo"one year ago"; | |
} | |
else | |
{ | |
echo"$years years ago"; | |
} | |
} | |
} | |
function getdealOptions($dealId) { | |
$deal_options_data = array(); | |
$q1="SELECT * FROM deal_options po LEFT JOIN `options` o ON (po.optionId = o.id) WHERE po.dealId = '$dealId' and o.status=1 order by o.id asc"; | |
//$deal_options_query = mysql_query("SELECT * FROM deal_options po LEFT JOIN `options` o ON (po.optionId = o.id) WHERE po.dealId = '" . (int)$dealId . "' and o.status=1 ORDER BY o.id asc"); | |
$deal_options_query = mysql_query($q1); | |
while($deal_options = mysql_fetch_array($deal_options_query)) { | |
if ($deal_options['type'] == 'select' || $deal_options['type'] == 'radio' || $deal_options['type'] == 'checkbox' || $deal_options['type'] == 'image') { | |
$deal_option_value_data = array(); | |
//$deal_option_value_query = mysql_query("SELECT * FROM deal_option_value pov LEFT JOIN option_value ov ON (pov.option_value_id = ov.option_value_id) WHERE pov.dealId = '" . (int)$dealId . "' AND pov.deal_optionId = '" . (int)$deal_options['deal_optionId'] . "' ORDER BY ov.id asc"); | |
$q2="SELECT * FROM deal_option_value pov LEFT JOIN option_value ov ON (pov.option_valueId = ov.id) WHERE pov.dealId = '$dealId' AND pov.deal_optionId = '" . $deal_options['optionId'] . "' ORDER BY pov.id asc"; | |
$deal_option_value_query = mysql_query($q2); | |
while($deal_option_value = mysql_fetch_array($deal_option_value_query)){ | |
$deal_option_value_data[] = array( | |
'deal_optionId' => $deal_option_value['deal_optionId'], | |
'option_valueId' => $deal_option_value['option_valueId'], | |
'name' => $deal_option_value['name'], | |
//'image' => $deal_option_value['image'], | |
'quantity' => $deal_option_value['quantity'], | |
'subtract' => $deal_option_value['subtract'], | |
'price' => $deal_option_value['price'], | |
'prefix' => $deal_option_value['prefix'], | |
//'type' => $deal_option_value['type'], | |
//'weight' => $deal_option_value['weight'], | |
//'weight_prefix' => $deal_option_value['weight_prefix'] | |
); | |
} | |
$deal_options_data[] = array( | |
'deal_optionId' => $deal_options['id'], | |
'optionId' => $deal_options['optionId'], | |
'name' => $deal_options['name'], | |
'type' => $deal_options['type'], | |
'option_value' => $deal_option_value_data, | |
'required' => $deal_options['required'] | |
); | |
} else { | |
$deal_options_data[] = array( | |
'deal_optionId' => $deal_options['id'], | |
'optionId' => $deal_options['optionId'], | |
'name' => $deal_options['name'], | |
'type' => $deal_options['type'], | |
'option_value' => $deal_options['value'], | |
'required' => $deal_options['required'] | |
); | |
} | |
} | |
return $deal_options_data; | |
} | |
function getfield($table,$getfield,$whereclause) | |
{ | |
$CI = get_instance(); | |
$CI->load->model('deal_model'); | |
$data=$CI->deal_model->getfield($table,$getfield,$whereclause); | |
return $data; | |
} | |
function getiframe($link) | |
{ | |
$CI = get_instance(); | |
$data=$CI->dembed->getiframe($link); | |
return $data; | |
} | |
function prioritycheck($userId) | |
{ | |
$CI = get_instance(); | |
$CI->load->model('deal_model'); | |
$data=$CI->deal_model->prioritycheck($userId); | |
return $data; | |
} | |
function priorityeligible($userId,$dealId) | |
{ | |
$CI = get_instance(); | |
$CI->load->model('deal_model'); | |
$data=$CI->deal_model->priorityeligible($userId,$dealId); | |
return $data; | |
} | |
function getrows($table,$whereclause) | |
{ | |
$CI = get_instance(); | |
$CI->load->model('deal_model'); | |
$data=$CI->deal_model->getrows($table,$whereclause); | |
return $data; | |
} | |
function fixedsizeimage($fileName,$extension,$desiredWidth,$desiredHeight,$tmp,$folder) | |
{ | |
$actualFileName=$fileName; | |
$desiredWidthActual=$desiredWidth; | |
if ($extension == "image/jpg" || $extension == "image/jpeg" || $extension == "image/pjpeg") { | |
$src = imagecreatefromjpeg($tmp.$fileName); | |
} | |
if ($extension == "image/gif") { | |
$src = imagecreatefromgif($tmp.$fileName); | |
} | |
if ($extension == "image/png" || $extension == "image/x-png") | |
{ | |
$src = imagecreatefrompng($tmp.$fileName); | |
} | |
list($width,$height)=getimagesize($tmp.$fileName); | |
$heightToUse=($height/$width)*$desiredWidth; | |
$widthToUse=($width/$height)*$desiredHeight; | |
if($heightToUse<$desiredHeight) | |
{ | |
//$desiredHeight=$heightToUse; | |
$desiredWidth=$widthToUse; | |
$heightToUseActual=$heightToUse; | |
$heightToUse=$desiredHeight; | |
} | |
$tmp = imagecreatetruecolor($desiredWidth,$desiredHeight) or die("Cannot Initialize new GD image stream"); | |
imagealphablending($tmp, false); | |
imagesavealpha($tmp,true); | |
imagecolortransparent($tmp, imagecolorallocate($tmp, 0, 0, 0)); | |
imagecopyresampled($tmp,$src,0,0,0,0,$desiredWidth,$heightToUse,$width,$height); | |
$fileName = $folder.$fileName; | |
if ($extension == "image/jpg" || $extension == "image/jpeg" || $extension == "image/pjpeg") { | |
imagejpeg($tmp,$fileName,100); | |
} | |
if ($extension == "image/gif") { | |
imagegif($tmp,$fileName,100); | |
} | |
if ($extension == "image/png" || $extension == "image/x-png") { | |
imagepng($tmp,$fileName,9); | |
} | |
if($heightToUse>$desiredHeight) | |
{ | |
} | |
elseif($heightToUseActual<$desiredHeight) | |
{ | |
cropImageFromLeftRight($actualFileName,$extension,$desiredWidthActual,$desiredHeight,$folder,$folder); | |
} | |
} | |
function cropImageFromTopBottom($fileName,$extension,$desiredWidth,$desiredHeight,$tmp,$folder) | |
{ | |
if ($extension == "image/jpg" || $extension == "image/jpeg" || $extension == "image/pjpeg") { | |
$src = imagecreatefromjpeg($tmp.$fileName); | |
} | |
if ($extension == "image/gif") { | |
$src = imagecreatefromgif($tmp.$fileName); | |
} | |
if ($extension == "image/png" || $extension == "image/x-png") | |
{ | |
$src = imagecreatefrompng($tmp.$fileName); | |
} | |
list($width,$height)=getimagesize($tmp.$fileName); | |
//$xcordinate=($width-$desiredWidth)/2; | |
$ycordinate=$height-$desiredHeight; | |
$tmp = imagecreatetruecolor($desiredWidth,$desiredHeight) or die("Cannot Initialize new GD image stream"); | |
imagealphablending($tmp, false); | |
imagesavealpha($tmp,true); | |
imagecolortransparent($tmp, imagecolorallocate($tmp, 0, 0, 0)); | |
imagecopyresampled($tmp,$src,0,0,0,$ycordinate,$desiredWidth,$desiredHeight,$desiredWidth,$desiredHeight); | |
$fileName = $folder.$fileName; | |
if ($extension == "image/jpg" || $extension == "image/jpeg" || $extension == "image/pjpeg") { | |
imagejpeg($tmp,$fileName,100); | |
} | |
if ($extension == "image/gif") { | |
imagegif($tmp,$fileName,100); | |
} | |
if ($extension == "image/png" || $extension == "image/x-png") { | |
imagepng($tmp,$fileName,9); | |
} | |
} | |
function cropImageFromLeftRight($fileName,$extension,$desiredWidth,$desiredHeight,$tmp,$folder) | |
{ | |
if ($extension == "image/jpg" || $extension == "image/jpeg" || $extension == "image/pjpeg") { | |
$src = imagecreatefromjpeg($tmp.$fileName); | |
} | |
if ($extension == "image/gif") { | |
$src = imagecreatefromgif($tmp.$fileName); | |
} | |
if ($extension == "image/png" || $extension == "image/x-png") | |
{ | |
$src = imagecreatefrompng($tmp.$fileName); | |
} | |
list($width,$height)=getimagesize($tmp.$fileName); | |
$xcordinate=($width-$desiredWidth)/2; | |
$tmp = imagecreatetruecolor($desiredWidth,$desiredHeight) or die("Cannot Initialize new GD image stream"); | |
imagealphablending($tmp, false); | |
imagesavealpha($tmp,true); | |
imagecolortransparent($tmp, imagecolorallocate($tmp, 0, 0, 0)); | |
imagecopyresampled($tmp,$src,0,0,$xcordinate,0,$desiredWidth,$desiredHeight,$desiredWidth,$desiredHeight); | |
$fileName = $folder.$fileName; | |
if ($extension == "image/jpg" || $extension == "image/jpeg" || $extension == "image/pjpeg") { | |
imagejpeg($tmp,$fileName,100); | |
} | |
if ($extension == "image/gif") { | |
imagegif($tmp,$fileName,100); | |
} | |
if ($extension == "image/png" || $extension == "image/x-png") { | |
imagepng($tmp,$fileName,9); | |
} | |
} | |
function imageresize($fileName,$extension,$desiredWidth,$desiredHeight,$tmp,$folder) | |
{ | |
if ($extension == "image/jpg" || $extension == "image/jpeg" || $extension == "image/pjpeg") { | |
$src = imagecreatefromjpeg($tmp.$fileName); | |
} | |
if ($extension == "image/gif") { | |
$src = imagecreatefromgif($tmp.$fileName); | |
} | |
if ($extension == "image/png" || $extension == "image/x-png") | |
{ | |
$src = imagecreatefrompng($tmp.$fileName); | |
} | |
list($width,$height)=getimagesize($tmp.$fileName); | |
if($width>$height){ | |
$modwidth=$desiredWidth; | |
$modheight=($height*$modwidth)/$width; | |
}else{ | |
$modheight=$desiredHeight; | |
$modwidth=($width*$modheight)/$height; | |
} | |
//checking the types of images | |
$tmp = imagecreatetruecolor($modwidth,$modheight) or die("Cannot Initialize new GD image stream"); | |
imagealphablending($tmp, false); | |
imagesavealpha($tmp,true); | |
imagecolortransparent($tmp, imagecolorallocate($tmp, 0, 0, 0)); | |
imagecopyresampled($tmp,$src,0,0,0,0,$modwidth,$modheight,$width,$height); | |
/* | |
$characterToReplace = array("'","/","\""," "); | |
$fileName=str_replace($characterToReplace,"",$fileName); | |
e | |
*/ | |
$fileName = $folder.$fileName; | |
if ($extension == "image/jpg" || $extension == "image/jpeg" || $extension == "image/pjpeg") { | |
imagejpeg($tmp,$fileName,100); | |
} | |
if ($extension == "image/gif") { | |
imagegif($tmp,$fileName,100); | |
} | |
if ($extension == "image/png" || $extension == "image/x-png") { | |
imagepng($tmp,$fileName,9); | |
} | |
} | |
function createdropdown($table,$fieldtopick,$fieldtoshow,$checkvalue,$whereclause,$orderbyfield='id',$ordertype='asc') | |
{ | |
$query="select * from $table where $whereclause order by $orderbyfield $ordertype"; | |
$execute=mysql_query($query); | |
$rows=mysql_num_rows($execute); | |
for($data=0;$data<$rows;$data++) | |
{ | |
$id=mysql_result($execute,$data,$fieldtopick); | |
$value=mysql_result($execute,$data,$fieldtoshow); | |
if($value==$checkvalue) | |
{ | |
echo ("<option value='$id' selected='selected'>".$value."</option>"); | |
} | |
else | |
{ | |
echo ("<option value='$id'>".$value."</option>"); | |
} | |
} | |
} | |
function listData($table,$name,$value,$orderBy='ASC') { | |
$items = array(); | |
$CI =& get_instance(); | |
if($orderBy) { | |
$CI->db->order_by($value,$orderBy); | |
} | |
$query = $CI->db->select("$name,$value")->from($table)->get(); | |
if ($query->num_rows() > 0) { | |
foreach($query->result() as $data) { | |
$items[$data->$name] = $data->$value; | |
} | |
$query->free_result(); | |
return $items; | |
} | |
} | |
function __cleanInput($string) { | |
$search = array( | |
'@<script[^>]*?>.*?</script>@si', /* strip out javascript */ | |
'@<[\/\!]*?[^<>]*?>@si', /* strip out HTML tags */ | |
'@<style[^>]*?>.*?</style>@siU', /* strip style tags properly */ | |
'@<![\s\S]*?--[ \t\n\r]*>@' /* strip multi-line comments */ | |
); | |
$output = preg_replace($search, '', $string); | |
return $output; | |
} | |
function object2array($object) { return @json_decode(@json_encode($object),1); } | |
function convert_number_to_words($number) { | |
$hyphen = '-'; | |
$conjunction = ' and '; | |
$separator = ', '; | |
$negative = 'negative '; | |
$decimal = ' point '; | |
$dictionary = array( | |
0 => 'Zero', | |
1 => 'One', | |
2 => 'Two', | |
3 => 'Three', | |
4 => 'Four', | |
5 => 'Five', | |
6 => 'Six', | |
7 => 'Seven', | |
8 => 'Eight', | |
9 => 'Nine', | |
10 => 'Ten', | |
11 => 'Eleven', | |
12 => 'Twelve', | |
13 => 'Thirteen', | |
14 => 'Fourteen', | |
15 => 'Fifteen', | |
16 => 'Sixteen', | |
17 => 'Seventeen', | |
18 => 'Eighteen', | |
19 => 'Nineteen', | |
20 => 'Twenty', | |
30 => 'Thirty', | |
40 => 'Fourty', | |
50 => 'Fifty', | |
60 => 'Sixty', | |
70 => 'Seventy', | |
80 => 'Eighty', | |
90 => 'Ninety', | |
100 => 'Hundred', | |
1000 => 'Thousand', | |
1000000 => 'Million', | |
1000000000 => 'Billion', | |
1000000000000 => 'Trillion', | |
1000000000000000 => 'Quadrillion', | |
1000000000000000000 => 'Quintillion' | |
); | |
if (!is_numeric($number)) { | |
return false; | |
} | |
if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) { | |
// overflow | |
trigger_error( | |
'convert_number_to_words only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX, | |
E_USER_WARNING | |
); | |
return false; | |
} | |
if ($number < 0) { | |
return $negative . convert_number_to_words(abs($number)); | |
} | |
$string = $fraction = null; | |
if (strpos($number, '.') !== false) { | |
list($number, $fraction) = explode('.', $number); | |
} | |
switch (true) { | |
case $number < 21: | |
$string = $dictionary[$number]; | |
break; | |
case $number < 100: | |
$tens = ((int) ($number / 10)) * 10; | |
$units = $number % 10; | |
$string = $dictionary[$tens]; | |
if ($units) { | |
$string .= $hyphen . $dictionary[$units]; | |
} | |
break; | |
case $number < 1000: | |
$hundreds = $number / 100; | |
$remainder = $number % 100; | |
$string = $dictionary[$hundreds] . ' ' . $dictionary[100]; | |
if ($remainder) { | |
$string .= $conjunction . convert_number_to_words($remainder); | |
} | |
break; | |
default: | |
$baseUnit = pow(1000, floor(log($number, 1000))); | |
$numBaseUnits = (int) ($number / $baseUnit); | |
$remainder = $number % $baseUnit; | |
$string = convert_number_to_words($numBaseUnits) . ' ' . $dictionary[$baseUnit]; | |
if ($remainder) { | |
$string .= $remainder < 100 ? $conjunction : $separator; | |
$string .= convert_number_to_words($remainder); | |
} | |
break; | |
} | |
if (null !== $fraction && is_numeric($fraction)) { | |
$string .= $decimal; | |
$words = array(); | |
foreach (str_split((string) $fraction) as $number) { | |
$words[] = $dictionary[$number]; | |
} | |
$string .= implode(' ', $words); | |
} | |
return $string; | |
} | |
function convert24HoursTo12HoursNew($time){ | |
return date("g:i a", strtotime($time)); | |
} | |
function time_ago($date,$time) | |
{ | |
if( empty($date) ) | |
{ | |
return "No date provided"; | |
} | |
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade"); | |
$lengths = array("60","60","24","7","4.35","12","10"); | |
$now = time(); | |
$unix_date = strtotime( $date.' '.$time); | |
// check validity of date | |
if( empty($unix_date) ) | |
{ | |
return "Bad date"; | |
} | |
// is it future date or past date | |
if( $now > $unix_date ) | |
{ | |
$difference = $now - $unix_date; | |
$tense = "ago"; | |
} | |
else | |
{ | |
$difference = $unix_date - $now; | |
$tense = "from now"; | |
} | |
for( $j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++ ) | |
{ | |
$difference /= $lengths[$j]; | |
} | |
$difference = round( $difference ); | |
if( $difference != 1 ) | |
{ | |
$periods[$j].= "s"; | |
} | |
return "$difference $periods[$j] {$tense}"; | |
} | |
function Generate_Request_CheckSum ($Secret_Key, $Merchant_ID, $Order_ID,$Order_Amount, $Date, $Time) | |
{ | |
$Concate_String=$Secret_Key."|".$Merchant_ID."|".$Order_ID."|".$Order_Amount."|".$Date."|".$Time; | |
$HMac_MD5=strtolower(hash_hmac('md5', $Concate_String, $Secret_Key)); | |
return $HMac_MD5; | |
} | |
function Generate_Response_CheckSum($Secret_Key, $Merchant_ID, $Order_ID, $Order_Amount, $Bank_Name, $Transaction_Status, $Date, $Time) | |
{ | |
$Concate_String=$Secret_Key."|".$Merchant_ID."|".$Order_ID."|".$Order_Amount."|".$Bank_Name."|".$Transaction_Status."|".$Date."|".$Time; | |
$HMac_MD5=strtolower(hash_hmac('md5', $Concate_String, $Secret_Key)); | |
return $HMac_MD5; | |
} | |
function Verify_CheckSum($Secret_Key, $Merchant_ID, $Order_ID, $Order_Amount, $Bank_Name, $Transaction_Status, $Date, $Time,$CheckSum) | |
{ | |
$New_CheckSum=Generate_Response_CheckSum($Secret_Key, $Merchant_ID, $Order_ID, $Order_Amount, $Bank_Name, $Transaction_Status, $Date, $Time); | |
if($CheckSum===$New_CheckSum) | |
return true; | |
else | |
return false; | |
} | |
function make_links($text, $class='', $target='_blank'){ | |
return preg_replace('!((http\:\/\/|ftp\:\/\/|https\:\/\/)|www\.)([-a-zA-Z?-??-?0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?!ism', | |
'<a class="'.$class.'" href="//$3" target="'.$target.'">$1$3</a>', | |
$text); | |
} | |
function stopWords($text, $stopwords) { | |
// Remove line breaks and spaces from stopwords | |
$stopwords = array_map(function($x){return trim(strtolower($x));}, $stopwords); | |
// Replace all non-word chars with comma | |
$pattern = '/[0-9\W]/'; | |
$text = preg_replace($pattern, ',', $text); | |
// Create an array from $text | |
$text_array = explode(",",$text); | |
// remove whitespace and lowercase words in $text | |
$text_array = array_map(function($x){return trim(strtolower($x));}, $text_array); | |
foreach ($text_array as $term) { | |
if (!in_array($term, $stopwords)) { | |
$keywords[] = $term; | |
} | |
}; | |
return array_filter($keywords); | |
} | |
function RequestLastSeen($username, $from, $msgid, $seconds) | |
{ | |
//echo "Received last seen seconds: '$seconds'"; | |
//$now = time(); | |
//$lastSeen = $now - $seconds; | |
$secondsInAMinute = 60; | |
$secondsInAnHour = 60 * $secondsInAMinute; | |
$secondsInADay = 24 * $secondsInAnHour; | |
// extract days | |
$days = floor($seconds / $secondsInADay); | |
// extract hours | |
$hourSeconds = $seconds % $secondsInADay; | |
$hours = floor($hourSeconds / $secondsInAnHour); | |
// extract minutes | |
$minuteSeconds = $hourSeconds % $secondsInAnHour; | |
$minutes = floor($minuteSeconds / $secondsInAMinute); | |
// extract the remaining seconds | |
$remainingSeconds = $minuteSeconds % $secondsInAMinute; | |
$seconds = ceil($remainingSeconds); | |
// return the value | |
if (($seconds==0) && ($minutes==0) && ($hours==0) && ($days==0)) | |
$ls="Now online"; | |
else | |
$ls="Last seen: " . $days . "d " . $hours . "h " . $minutes . "m " . $seconds . "s ago"; | |
//$ci=&get_instance(); | |
//$number=str_replace('@s.whatsapp.net','',$from); | |
//echo "<div style='width:100px;cursor:pointer;' tabindex=0 data-toggle='popover' data-content='".$ls."' data-trigger='focus'>".$number.$ci->whatsprot->sendGetStatuses($number)."</div>"; | |
//$ci->db->query("update numbers set lastseen='$ls' where number='$number'"); | |
echo $ls; | |
return $ls; | |
} | |
function GetStatus( $mynumber, $from, $requested, $id, $time, $data ){ | |
$number=str_replace('@s.whatsapp.net','',$from); | |
//$ci=&get_instance(); | |
$currentdatetime=date("Y-m-d h:i:sa"); | |
$status=addslashes($data); | |
//$ci->db->query("update numbers set status='$status',statusdate='$currentdatetime' where number='$number'"); | |
echo $data; | |
} | |
function onSyncResult($result) | |
{ | |
//print_r($result); | |
foreach ($result as $row): | |
$index=$result->index; | |
$syncId=$result->syncId; | |
$existingUsers=$result->existing; | |
$failedNumbers=$result->nonExisting; | |
endforeach; | |
/* $ci=&get_instance(); | |
echo "<div class='col-md-5 col-md-offset-3'><h4>Active (".count($existingUsers).")</h4><br><div class='myautoscroll' style='height: 200px;'>"; | |
foreach(array_reverse($existingUsers) as $number) | |
{ | |
$number1=str_replace('@s.whatsapp.net','',$number); | |
echo "<div style='width:100px;cursor:pointer;' tabindex=0 data-toggle='popover' data-trigger='focus' data-content='I am status'>".$number1."</div>"; | |
$ci->db->query("update numbers set active='1' where number='$number1'"); | |
} | |
echo "</div></div>"; | |
*/ | |
echo json_encode($existingUsers); | |
die();//to break out of the while(true) loop | |
} | |
function onSyncResultold($result) | |
{ | |
//print_r($result); | |
foreach ($result as $row): | |
$index=$result->index; | |
$syncId=$result->syncId; | |
$existingUsers=$result->existing; | |
$failedNumbers=$result->nonExisting; | |
endforeach; | |
$ci=&get_instance(); | |
echo "<div class='col-md-5 col-md-offset-3'><h4>Active (".count($existingUsers).")</h4><br><div class='myautoscroll' style='height: 200px;'>"; | |
foreach(array_reverse($existingUsers) as $number) | |
{ | |
$number1=str_replace('@s.whatsapp.net','',$number); | |
echo "<div style='width:100px;cursor:pointer;' tabindex=0 data-toggle='popover' data-trigger='focus' data-content='I am status'>".$number1."</div>"; | |
//$ci->whatsprot->SendPresenceSubscription($number1); | |
//$ci->whatsprot->pollMessage(); | |
//$ci->whatsprot->sendGetRequestLastSeen($number1); | |
$ci->db->query("update numbers set active='1' where number='$number1'"); | |
} | |
echo "</div></div>"; | |
echo "<div class='col-md-2'><h4>Invalid (".count($failedNumbers).")</h4><br><div class='myautoscroll' style='height: 200px;'>"; | |
foreach(array_reverse($failedNumbers) as $number) | |
{ | |
echo "<div>$number</div>"; | |
} | |
echo "</div></div>"; | |
die();//to break out of the while(true) loop | |
} | |
function PresenceReceived($mynumber, $from, $type) | |
{ | |
echo "\n\nReceived presence from $from. He/she is now $type\n\n"; | |
} | |
function onSendPresence($mynumber, $from, $type) | |
{ | |
echo "\n\nReceived presence from $from. He/she is now $type\n\n"; | |
} | |
function PresenceAvailable($username, $from) | |
{ | |
$ci=&get_instance(); | |
$dFrom = str_replace(array("@s.whatsapp.net","@g.us"), "", $from); | |
echo "$dFrom is online"; | |
//echo "<div style='width:100px;cursor:pointer;' tabindex=0 data-toggle='popover' data-content='Available' data-trigger='focus'>".$dFrom.$ci->whatsprot->sendGetStatuses($dFrom)."</div>"; | |
//$ci->db->query("update numbers set lastseen='0d 0h 0m 0s' where number='$dFrom'"); | |
} | |
function PresenceUnavailable( $mynumber, $from, $last ){ | |
$ci=&get_instance(); | |
$now = time(); | |
$seconds = $now - $last; | |
$secondsInAMinute = 60; | |
$secondsInAnHour = 60 * $secondsInAMinute; | |
$secondsInADay = 24 * $secondsInAnHour; | |
// extract days | |
$days = floor($seconds / $secondsInADay); | |
// extract hours | |
$hourSeconds = $seconds % $secondsInADay; | |
$hours = floor($hourSeconds / $secondsInAnHour); | |
// extract minutes | |
$minuteSeconds = $hourSeconds % $secondsInAnHour; | |
$minutes = floor($minuteSeconds / $secondsInAMinute); | |
// extract the remaining seconds | |
$remainingSeconds = $minuteSeconds % $secondsInAMinute; | |
$seconds = ceil($remainingSeconds); | |
// return the value | |
$ls="Last seen: " . $days . "d " . $hours . "h " . $minutes . "m " . $seconds . "s ago"; | |
$dFrom=$number=str_replace(array("@s.whatsapp.net","@g.us"), "", $from); | |
echo "\n\n $dFrom is offline. $ls"; | |
//echo "<div style='width:100px;cursor:pointer;' tabindex=0 data-toggle='popover' data-content='".$ls."' data-trigger='focus'>".$dFrom.$ci->whatsprot->sendGetStatuses($dFrom)."</div>"; | |
//$ci->db->query("update numbers set lastseen='$ls' where number='$dFrom'"); | |
} | |
function onConnect($mynumber, $socket) | |
{ | |
echo "<p>WooHoo!, Phone number $mynumber connected successfully!</p>"; | |
} | |
function onDisconnect($mynumber, $socket) | |
{ | |
echo "<p>Booo!, Phone number $mynumber is disconnected!</p>"; | |
} | |
function CredentialsBad($mynumber, $status, $reason) | |
{ | |
if ($reason == 'blocked') | |
echo "\n\nYour number is blocked \n"; | |
if ($reason == 'incorrect') | |
echo "\n\nWrong identity. \n"; | |
} | |
function CredentialsGood($mynumber, $login, $password, $type, $expiration, $kind, $price, $cost, $currency, $price_expiration) | |
{ | |
echo "\n\nYour number $mynumber with the following password $password is not blocked \n"; | |
} | |
function ProfilePicture( $mynumber, $from, $type, $data ) | |
{ | |
if ($type == "preview") { | |
$filename = "preview_" . $from . ".jpg"; | |
} else { | |
$filename = $from . ".jpg"; | |
} | |
$filenamet = "/home/pakdevs/public_html/whatsproj/" . $filename; | |
$fp = @fopen($filenamet, "w"); | |
if ($fp) { | |
fwrite($fp, $data); | |
fclose($fp); | |
} | |
echo '<a href="/'.$filename.'"><center><img src="/'.$filename.'"></center></a><br><br>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment