So I get these errors on a custom made website. I am not the developer of it but I have to fix these errors.
Notice: Undefined index: user in /var/server/pages/home.php on line 13
Notice: Undefined variable: customFunctions in /var/server/templates/header.tpl on line 44
Here's the code of home.php and below that I will attack the header.tpl
<?php
session_start();
$cart = $_SESSION['cart'];
if(!is_object($cart)) {
$cart = new ShoppingCart();
}
$user = $_SESSION['user'];
if(!is_object($user)) {
$user = new User();
}
$mobileDetect = new MobileDetect();
$deviceType = ($mobileDetect->isMobile() ? ($mobileDetect->isTablet() ? 'tablet' : 'phone') : 'computer');
$bodyClass = '';
if('computer' == $deviceType) {
$bodyClass = 'body-computer';
}
else {
$bodyClass = 'home';
}
$collectionDb = new CollectionDB();
$collection = array();
$collection = $collectionDb->getLastCollection();
if(!empty($collection)) {
$collectionTitle = $collection[0]['collection_title_'.$language];
$collectionImage = $collection[0]['collection_image'];
}
require_once('templates/home.tpl');
?>
Here's header.tpl code
<?php
$homeLang = '';
// if('en' == $language) {
// $homeLang = $language;
// }
$defaultUrl = '';
$urlVariables = '';
if(isset($_GET['p'])) {
$urlVariables .= '/'.$_GET['p'];
}
if(isset($_GET['id'])) {
$urlVariables .= '/'.$_GET['id'];
}
if(isset($_GET['title'])) {
$urlVariables .= '/'.$_GET['title'];
}
if(isset($_GET['t'])) {
$urlVariables .= '?t='.$_GET['t'];
}
// if(isset($_GET['ord'])) {
// $urlVariables .= '&ord='.$_GET['ord'];
// }
if(isset($_GET['pg']) && isset($_GET['t'])) {
$urlVariables .= '&pg='.$_GET['pg'];
}
if(isset($_GET['pg']) && !isset($_GET['t'])) {
$urlVariables .= '?pg='.$_GET['pg'];
}
//if(!is_object($productCategoryDb)) {
// $productCategoryDb = new ProductCategoryDB();
// }
if(!is_object($customFunctions)) {
$customFunctions = new CustomFunctions();
}
// $headerProductCategories = $productCategoryDb->getAllProductCategories();
?>
<header <?php if('' == $p) { ?>class="home-header"<?php } ?>>
<div class="row">
<div class="col-sm-4 col-md-3 hidden-xs">
<div class="main-menu clearfix">
<button type="button" id="toggle-menu" class="button-toggle clearfix">
<div class="pull-left clearfix">
<span class="custom-icon-bar"></span>
<span class="custom-icon-bar"></span>
<span class="custom-icon-bar"></span>
</div>
<span class="menu-lbl pull-left"><?php echo HEADER_MENU; ?></span>
</button>
</div>
</div>
<div class="col-sm-4 col-md-6">
<button type="button" id="toggle-menu-xs" class="button-toggle visible-xs">
<div>
<span class="custom-icon-bar"></span>
<span class="custom-icon-bar"></span>
<span class="custom-icon-bar"></span>
</div>
</button>
<div class="logo">
<a href="<?php echo SITE_URL.$homeLang; ?>">
<?php if('' == $p) { ?>
<img src="<?php echo SITE_ICONS_PATH.'logo.png'; ?>" alt="<?php echo SITE_NAME; ?>">
<?php }
else {
?>
<img src="<?php echo SITE_ICONS_PATH.'logo.png'; ?>" alt="<?php echo SITE_NAME; ?>">
<?php } ?>
</a>
</div>
</div>
<div class="col-sm-4 col-md-3">
<div class="header-account-menu">
<ul>
<li class="login">
<?php if($user->getIsLoggedIn()) { ?>
<div class="dropdown">
<button type="button" class="btn btn-link login-toggle"><?php echo HEADER_PROFILE; ?></button>
<div class="dropdown-menu login-dropdown account-dropdown">
<ul>
<li><a href="<?php echo $language.'/profile'; ?>"><span class="glyphicon glyphicon-home"></span> <?php echo HEADER_ACCOUNT; ?></a></li>
<li><a href="<?php echo $language.'/logout'; ?>"><span class="glyphicon glyphicon-log-out"></span> <?php echo HEADER_SIGN_OUT; ?></a></li>
</ul>
</div>
</div>
<?php }
else {
?>
<div class="dropdown">
<button type="button" class="btn btn-link login-toggle"><?php echo HEADER_SIGN_IN; ?></button>
<div class="dropdown-menu login-dropdown">
<!-- <div class="arrow"></div> -->
<div class="drop-header">
<span class="text-size16"><?php echo HEADER_SIGN_IN; ?></span>
</div>
<div class="drop-body">
<form id="login-form">
<label for="login-email" class="control-label"><?php echo LOGIN_EMAIL; ?></label>
<input type="email" name="login_email" id="login-email" class="form-control" maxlength="80" placeholder="<?php echo LOGIN_EMAIL; ?>...">
<label for="login-password" class="control-label"><?php echo LOGIN_PASSWORD; ?></label>
<input type="password" name="login_password" id="login-password" class="form-control" maxlength="30" placeholder="<?php echo LOGIN_PASSWORD; ?>...">
<div id="login-error-msg" class="error-msg"><?php echo LOGIN_ERROR; ?></div>
</form>
</div>
<div class="drop-footer">
<div class="clearfix">
<ul class="pull-left">
<li><a href="<?php echo $language.'/register'; ?>"><?php echo LOGIN_REGISTER; ?></a></li>
<li><a href="<?php echo $language.'/passrequest'; ?>"><?php echo LOGIN_FORGOT_PASSWORD; ?></a></li>
</ul>
<button type="button" id="login-btn" class="submit-btn btn btn-default pull-right" name="login_btn" data-loading-text="<?php echo LOGIN_LOADING; ?>..."><?php echo LOGIN_SIGN_IN_BTN; ?></button>
</div>
</div>
</div>
</div> <!-- end of .dropdown -->
<?php } ?>
</li>
<li class="separator">|</li>
<li class="header-cart">
<div class="dropdown">
<a class="cart-toggle" href="<?php echo $language.'/cart'; ?>">
<?php echo HEADER_CART; ?> <span id="header-cart-items"><?php if(0 != count($cart)) { echo '('.count($cart).')'; } ?></span>
</a>
<div class="dropdown-menu cart-dropdown">
<div class="arrow"></div>
<div class="drop-body"><?php echo PRODUCT_ADDED; ?></div>
</div>
</div> <!-- end of .dropdown -->
</li>
<li class="separator">|</li>
<li class="header-wishlist">
<?php if(!$user->getIsLoggedIn()) { ?>
<button id="header-wishlist-popover-btn" type="button" class="btn btn-link" data-container="body" data-toggle="popover" data-placement="bottom" data-content="<?php echo PRODUCT_ADD_WISHLIST_WARNING; ?>"><?php echo HEADER_WISHLIST; ?></button>
<?php }
else {
?>
<div class="dropdown">
<a class="wishlist-toggle" href="<?php echo $language.'/wishlist'; ?>"><?php echo HEADER_WISHLIST; ?></a>
<div class="dropdown-menu wishlist-dropdown">
<div class="arrow"></div>
<div class="drop-body"><span><?php echo PRODUCT_ITEM_ADDED; ?></span></div>
</div>
</div> <!-- end of .dropdown -->
<?php } ?>
</li>
</ul>
</div>
</div>
<!-- Smartphone -->
<div class="hidden" id="mobile-menu">
<ul>
<li>
<?php if('products' == $p && 2 == $_GET['id']) { ?>
<span class="active"><?php echo MENU_NEW_ARRIVALS; ?></span>
<?php }
else {
?>
<a href="<?php echo $language.'/products/2/new-arrivals'; ?>"><?php echo MENU_NEW_ARRIVALS; ?></a>
<?php } ?>
</li>
<li>
<?php if('products' == $p && 2 != $_GET['id']) { ?>
<span class="active"><?php echo MENU_SHOP; ?></span>
<?php }
else {
?>
<a href="<?php echo $language.'/products/2/new-arrivals'; ?>"><?php echo MENU_SHOP; ?></a>
<?php } ?>
</li>
<li>
<?php if('whats-up' == $p) { ?>
<span class="active"><?php echo MENU_WHATS_UP; ?></span>
<?php }
else {
?>
<a href="<?php echo $language.'/whats-up'; ?>"><?php echo MENU_WHATS_UP; ?></a>
<?php } ?>
</li>
<li>
<?php if('what-to-wear' == $p) { ?>
<span class="active"><?php echo MENU_WHAT_TO_WEAR; ?></span>
<?php }
else {
?>
<a href="<?php echo $language.'/what-to-wear'; ?>"><?php echo MENU_WHAT_TO_WEAR; ?></a>
<?php } ?>
</li>
<li>
<?php if('about' == $p) { ?>
<span class="active"><?php echo MENU_STORY; ?></span>
<?php }
else {
?>
<a href="<?php echo $language.'/about'; ?>"><?php echo MENU_STORY; ?></a>
<?php } ?>
</li>
</ul>
<div class="search-form">
<h3><?php echo MENU_SEARCH; ?></h3>
<div class="input-group">
<input type="text" id="searchbox" class="searchbox form-control" maxlength="30" placeholder="enter keywords...">
<span class="input-group-btn">
<button class="btn btn-default" type="button" id="search-btn"><span class="glyphicon glyphicon-search"></span></button>
</span>
</div>
</div> <!-- end of .search-form -->
<div class="subscribe-link">
<a href="<?php echo $language.'/subscribe'; ?>"><?php echo MENU_SUBSCRIBE; ?></a>
</div> <!-- end of .subscribe-form -->
</div> <!-- end of #mobile-menu -->
</header>
Can anyone guide me to the right direction? I checked out all the posts with this kind of errors on Stackoverflow but i can't find the solution.
Thanks in advance.
UPDATE: Adde custom functions class.
<?php
class CustomFunctions {
public function greekToGreeklish($string) {
return strtr($string, array(
'Α' => 'A', 'Β' => 'V', 'Γ' => 'G', 'Δ' => 'D', 'Ε' => 'E', 'Ζ' => 'Z', 'Η' => 'I', 'Θ' => 'TH', 'Ι' => 'I', 'Κ' => 'K', 'Λ' => 'L',
'Μ' => 'M', 'Ν' => 'N', 'Ξ' => 'KS', 'Ο' => 'O', 'Π' => 'P', 'Ρ' => 'R', 'Σ' => 'S', 'Τ' => 'T', 'Υ' => 'Y', 'Φ' => 'F', 'Χ' => 'X',
'Ψ' => 'PS', 'Ω' => 'O',
'α' => 'a', 'β' => 'v', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'ζ' => 'z', 'η' => 'i', 'θ' => 'th', 'ι' => 'i', 'κ' => 'k', 'λ' => 'l',
'μ' => 'm', 'ν' => 'n', 'ξ' => 'ks', 'ο' => 'o', 'π' => 'p', 'ρ' => 'r', 'σ' => 's', 'τ' => 't', 'υ' => 'y', 'φ' => 'f', 'χ' => 'x',
'ψ' => 'ps', 'ω' => 'o', 'ς' => 's', 'ά' => 'a', 'έ' => 'e', 'ή' => 'i', 'ί' => 'i', 'ό' => 'o', 'ύ' => 'y', 'ώ' => 'o', 'ϊ' => 'i',
'ϋ' => 'y', 'ΐ' => 'i', 'ΰ' => 'y'
));
}
public function greekLowerToUpper($string) {
return strtr($string, array(
'α' => 'Α', 'ά' => 'Α', 'Ά' => 'Α', 'ε' => 'Ε', 'έ' => 'Ε', 'Έ' => 'Ε', 'η' => 'Η', 'ή' => 'Η', 'Ή' => 'Η', 'ι' => 'Ι', 'ί' => 'Ι', 'Ί' => 'Ι', 'ϊ' => 'Ι',
'ΐ' => 'Ι', 'ο' => 'Ο', 'ό' => 'Ο', 'Ό' => 'Ο', 'υ' => 'Υ', 'ύ' => 'Υ', 'Ύ' => 'Υ', 'ϋ' => 'Υ', 'ΰ' => 'Υ', 'ω' => 'Ω', 'ώ' => 'Ω', 'Ώ' => 'Ω'
));
}
public function greekToGreekWithoutIntonation($string) {
return strtr($string, array(
'Ά' => 'Α', 'ά' => 'α', 'Έ' => 'Ε', 'έ' => 'ε', 'Ή' => 'Η', 'ή' => 'η', 'Ί' => 'Ι', 'ί' => 'ι', 'Ϊ' => 'Ι', 'ϊ' => 'ι', 'ΐ' => 'ι', 'Ό' => 'Ο',
'ό' => 'ο', 'Ύ' => 'Υ', 'ύ' => 'υ', 'Ϋ' => 'Υ', 'ϋ' => 'υ', 'ΰ' => 'υ', 'Ώ' => 'Ω', 'ώ' => 'ω'
));
}
public function utf8Urldecode($string) {
$string = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;", urldecode($string));
return html_entity_decode($string, null, 'UTF-8');;
}
// Generating a seo friendly title
public function seoUrl($string, $seperator = '-') {
$url = str_replace("'", '', $string);
$url = str_replace('%20', ' ', $url);
//$url = preg_replace('~[^\\pL0-9_.]+~u', $seperator, $url); // substitutes anything but letters, numbers, '_' and '.' with separator
$url = preg_replace('~[^\\pL0-9]+~u', $seperator, $url); // substitutes anything but letters, numbers with separator
$url = trim($url, "-");
$url = strtolower($url);
//$url = preg_replace('~[^-a-z0-9_.]+~', '', $url); // keep only letters, numbers, '_', '.' and separator
$url = preg_replace('~[^-a-z0-9]+~', '', $url); // keep only letters, numbers and separator
return $url;
}
/**
* Create a web friendly URL slug from a string.
*
* Although supported, transliteration is discouraged because
* 1) most web browsers support UTF-8 characters in URLs
* 2) transliteration causes a loss of information
*
* @author Sean Murphy <sean@iamseanmurphy.com>
* @copyright Copyright 2012 Sean Murphy. All rights reserved.
* @license http://creativecommons.org/publicdomain/zero/1.0/
**/
function url_slug($str, $options = array()) {
// Make sure string is in UTF-8 and strip invalid UTF-8 characters
$str = mb_convert_encoding((string)$str, 'UTF-8', mb_list_encodings());
$defaults = array('delimiter' => '-', 'limit' => null, 'lowercase' => true, 'replacements' => array(), 'transliterate' => false);
// Merge options
$options = array_merge($defaults, $options);
$char_map = array(
// Latin
'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'AE', 'Ç' => 'C',
'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I',
'Ð' => 'D', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ő' => 'O',
'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ű' => 'U', 'Ý' => 'Y', 'Þ' => 'TH',
'ß' => 'ss',
'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'ae', 'ç' => 'c',
'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i',
'ð' => 'd', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ő' => 'o',
'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ű' => 'u', 'ý' => 'y', 'þ' => 'th',
'ÿ' => 'y',
// Latin symbols
'©' => '(c)',
// Greek
'Α' => 'A', 'Β' => 'B', 'Γ' => 'G', 'Δ' => 'D', 'Ε' => 'E', 'Ζ' => 'Z', 'Η' => 'H', 'Θ' => '8',
'Ι' => 'I', 'Κ' => 'K', 'Λ' => 'L', 'Μ' => 'M', 'Ν' => 'N', 'Ξ' => '3', 'Ο' => 'O', 'Π' => 'P',
'Ρ' => 'R', 'Σ' => 'S', 'Τ' => 'T', 'Υ' => 'Y', 'Φ' => 'F', 'Χ' => 'X', 'Ψ' => 'PS', 'Ω' => 'W',
'Ά' => 'A', 'Έ' => 'E', 'Ί' => 'I', 'Ό' => 'O', 'Ύ' => 'Y', 'Ή' => 'H', 'Ώ' => 'W', 'Ϊ' => 'I',
'Ϋ' => 'Y',
'α' => 'a', 'β' => 'b', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'ζ' => 'z', 'η' => 'h', 'θ' => '8',
'ι' => 'i', 'κ' => 'k', 'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => '3', 'ο' => 'o', 'π' => 'p',
'ρ' => 'r', 'σ' => 's', 'τ' => 't', 'υ' => 'y', 'φ' => 'f', 'χ' => 'x', 'ψ' => 'ps', 'ω' => 'w',
'ά' => 'a', 'έ' => 'e', 'ί' => 'i', 'ό' => 'o', 'ύ' => 'y', 'ή' => 'h', 'ώ' => 'w', 'ς' => 's',
'ϊ' => 'i', 'ΰ' => 'y', 'ϋ' => 'y', 'ΐ' => 'i',
// Turkish
'Ş' => 'S', 'İ' => 'I', 'Ç' => 'C', 'Ü' => 'U', 'Ö' => 'O', 'Ğ' => 'G',
'ş' => 's', 'ı' => 'i', 'ç' => 'c', 'ü' => 'u', 'ö' => 'o', 'ğ' => 'g',
// Russian
'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'Yo', 'Ж' => 'Zh',
'З' => 'Z', 'И' => 'I', 'Й' => 'J', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O',
'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C',
'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sh', 'Ъ' => '', 'Ы' => 'Y', 'Ь' => '', 'Э' => 'E', 'Ю' => 'Yu',
'Я' => 'Ya',
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'yo', 'ж' => 'zh',
'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o',
'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c',
'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sh', 'ъ' => '', 'ы' => 'y', 'ь' => '', 'э' => 'e', 'ю' => 'yu',
'я' => 'ya',
// Ukrainian
'Є' => 'Ye', 'І' => 'I', 'Ї' => 'Yi', 'Ґ' => 'G',
'є' => 'ye', 'і' => 'i', 'ї' => 'yi', 'ґ' => 'g',
// Czech
'Č' => 'C', 'Ď' => 'D', 'Ě' => 'E', 'Ň' => 'N', 'Ř' => 'R', 'Š' => 'S', 'Ť' => 'T', 'Ů' => 'U',
'Ž' => 'Z',
'č' => 'c', 'ď' => 'd', 'ě' => 'e', 'ň' => 'n', 'ř' => 'r', 'š' => 's', 'ť' => 't', 'ů' => 'u',
'ž' => 'z',
// Polish
'Ą' => 'A', 'Ć' => 'C', 'Ę' => 'e', 'Ł' => 'L', 'Ń' => 'N', 'Ó' => 'o', 'Ś' => 'S', 'Ź' => 'Z',
'Ż' => 'Z',
'ą' => 'a', 'ć' => 'c', 'ę' => 'e', 'ł' => 'l', 'ń' => 'n', 'ó' => 'o', 'ś' => 's', 'ź' => 'z',
'ż' => 'z',
// Latvian
'Ā' => 'A', 'Č' => 'C', 'Ē' => 'E', 'Ģ' => 'G', 'Ī' => 'i', 'Ķ' => 'k', 'Ļ' => 'L', 'Ņ' => 'N',
'Š' => 'S', 'Ū' => 'u', 'Ž' => 'Z',
'ā' => 'a', 'č' => 'c', 'ē' => 'e', 'ģ' => 'g', 'ī' => 'i', 'ķ' => 'k', 'ļ' => 'l', 'ņ' => 'n',
'š' => 's', 'ū' => 'u', 'ž' => 'z'
);
// Make custom replacements
$str = preg_replace(array_keys($options['replacements']), $options['replacements'], $str);
// Transliterate characters to ASCII
if ($options['transliterate']) {
$str = str_replace(array_keys($char_map), $char_map, $str);
}
// Replace non-alphanumeric characters with our delimiter
$str = preg_replace('/[^\p{L}\p{Nd}]+/u', $options['delimiter'], $str);
// Remove duplicate delimiters
$str = preg_replace('/(' . preg_quote($options['delimiter'], '/') . '){2,}/', '$1', $str);
// Truncate slug to max. characters
$str = mb_substr($str, 0, ($options['limit'] ? $options['limit'] : mb_strlen($str, 'UTF-8')), 'UTF-8');
// Remove delimiter from ends
$str = trim($str, $options['delimiter']);
return $options['lowercase'] ? mb_strtolower($str, 'UTF-8') : $str;
}
/* Validate an email address. */
function emailValidate($sToEmail, $sFromDomain = "yourdomain.com", $sFromEmail = "sample@yourdomain.com", $bIsDebug = false) {
$bIsValid = true; // assume the address is valid by default..
$aEmailParts = explode("@", $sToEmail); // extract the user/domain..
getmxrr($aEmailParts[1], $aMatches); // get the mx records..
if(sizeof($aMatches) == 0) {
return false; // no mx records..
}
foreach ($aMatches as $oValue) {
if($bIsValid && !isset($sResponseCode)) {
// open the connection..
$oConnection = @fsockopen($oValue, 25, $errno, $errstr, 30);
$oResponse = @fgets($oConnection);
if(!$oConnection) {
$aConnectionLog['Connection'] = "ERROR";
$aConnectionLog['ConnectionResponse'] = $errstr;
$bIsValid = false; // unable to connect..
}
else {
$aConnectionLog['Connection'] = "SUCCESS";
$aConnectionLog['ConnectionResponse'] = $errstr;
$bIsValid = true; // so far so good..
}
if(!$bIsValid) {
if($bIsDebug) print_r($aConnectionLog);
return false;
}
// say hello to the server..
fputs($oConnection, "HELO $sFromDomain
");
$oResponse = fgets($oConnection);
$aConnectionLog['HELO'] = $oResponse;
// send the email from..
fputs($oConnection, "MAIL FROM: <$sFromEmail>
");
$oResponse = fgets($oConnection);
$aConnectionLog['MailFromResponse'] = $oResponse;
// send the email to..
fputs($oConnection, "RCPT TO: <$sToEmail>
");
$oResponse = fgets($oConnection);
$aConnectionLog['MailToResponse'] = $oResponse;
// get the response code..
$sResponseCode = substr($aConnectionLog['MailToResponse'], 0, 3);
$sBaseResponseCode = substr($sResponseCode, 0, 1);
// say goodbye..
fputs($oConnection,"QUIT
");
$oResponse = fgets($oConnection);
// get the quit code and response..
$aConnectionLog['QuitResponse'] = $oResponse;
$aConnectionLog['QuitCode'] = substr($oResponse, 0, 3);
if($sBaseResponseCode == "5") {
$bIsValid = false; // the address is not valid..
}
// close the connection..
@fclose($oConnection);
}
}
if ($bIsDebug) {
print_r($aConnectionLog); // output debug info..
}
return $bIsValid;
}
// Limit the words of display
public function limitWords($string, $limit) {
$words = explode(" ", $string);
return implode(" ", array_splice($words, 0, $limit));
}
public function rrmdir($directory, $empty=false) {
// if the path has a slash at the end we remove it here
if(substr($directory,-1) == '/') {
$directory = substr($directory,0,-1);
}
// if the path is not valid or is not a directory ...
if(!file_exists($directory) || !is_dir($directory)) {
// ... we return false and exit the function
return false;
// ... if the path is not readable
}
else if(!is_readable($directory)) {
// ... we return false and exit the function
return false;
// ... else if the path is readable
}
else {
// we open the directory
$handle = opendir($directory);
// and scan through the items inside
while (false !== ($item = readdir($handle))) {
// if the filepointer is not the current directory
// or the parent directory
if($item != '.' && $item != '..') {
// we build the new path to delete
$path = $directory.'/'.$item;
// if the new path is a directory
if(is_dir($path)) {
// we call this function with the new path
rrmdir($path);
// if the new path is a file
}
else {
// we remove the file
unlink($path);
}
}
}
// close the directory
closedir($handle);
// if the option to empty is not set to true
if($empty == false) {
// try to delete the now empty directory
if(!rmdir($directory)) {
// return false if not possible
return false;
}
}
// return success
return true;
}
}
public function stringReplaceChar($string, $character, $newCharacter) {
$newString = str_replace($character, $newCharacter, $string);
return $newString;
}
public function randomString($length) {
//$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$str = '';
$size = strlen($chars);
for($i = 0; $i < $length; $i++) {
$str .= $chars[rand(0, $size - 1)];
}
return $str;
}
public function array_values_recursive($array) {
$flat = array();
foreach ($array as $value) {
if (is_array($value)) {
$flat = array_merge($flat, $this->array_values_recursive($value));
}
else {
$flat[] = $value;
}
}
return $flat;
}
public function searchByKeyValue($array, $key, $value) {
$results = array();
if(is_array($array)) {
if(isset($array[$key]) && $array[$key] == $value) {
$results[] = $array;
}
foreach($array as $subarray) {
$results = array_merge($results, $this->searchByKeyValue($subarray, $key, $value));
}
}
return $results;
}
// Email format validation
public function emailValidation($email) {
$isValid = true;
if(empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$isValid = false;
}
return $isValid;
}
public function fixHttpUrl($url) {
$newUrl = "";
$urlPrefix = "http://";
$pos = strpos($url, $urlPrefix);
if ($pos === false) {
$newUrl = $urlPrefix.$url;
} else {
$newUrl = $url;
}
return $newUrl;
}
public function get_ip_address() {
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (explode(',', $_SERVER[$key]) as $ip) {
if (filter_var($ip, FILTER_VALIDATE_IP) !== false) {
return $ip;
}
}
}
}
}
// Get video image thumbnail
public function getVideoThumbUrl($url) {
$videoThumbUrl = '';
if (strpos($url, 'youtube') !== false) {
$tempArray = explode('v=', $url);
$tempArray = explode('&', $tempArray[1]);
$videoThumbUrl = 'http://img.youtube.com/vi/'.$tempArray[0].'/0.jpg';
}
if (strpos($url, 'vimeo') !== false) {
$tempArray = explode('.com/', $url);
$hash = unserialize(file_get_contents('http://vimeo.com/api/v2/video/'.$tempArray[1].'.php'));
$videoThumbUrl = $hash[0]['thumbnail_large'];
}
if (strpos($url, 'dailymotion') !== false) {
$tempArray = explode('video/', $url);
$videoThumbUrl = 'http://www.dailymotion.com/thumbnail/video/'.$tempArray[1];
}
return $videoThumbUrl;
}
// Change the date format
public function formatDate($date) {
$newDate = date('j.n.Y', strtotime($date));
return $newDate;
}
public function formatDateWithHour($date) {
$newDate = date('j M Y H:i:s', strtotime($date));
return $newDate;
}
public function formatDateToString($date) {
$newDate = date('l, j F Y', strtotime($date));
return $newDate;
}
public function formatDateMonthYear($date) {
$newDate = date('M Y', strtotime($date));
return $newDate;
}
public function mysqlFormatDate($date) {
$newDate = date('Y-m-d '.date(" H:i:s", time()), strtotime($date));
return $newDate;
}
public function reverseMysqlFormatDate($date) {
$newDate = date('d-m-Y', strtotime($date));
return $newDate;
}
public function getAgeFromBirthdate($date) {
$givenDate = new DateTime($date);
$currentDate = new DateTime(date('Y-m-d'));
$age = $givenDate->diff($currentDate);
return $age->format('%y');
}
public function __destruct() {
}
}
?>