if ( !function_exists( 'conf' ) )
{
function conf( $key )
{
$CI = &get_instance();
$configTable = table( 'configuration' );
$value = $CI->db->select( 'value' )->where( 'key', $key )->get( $configTable )->row();
if ( $value )
return $value->value;
else
return false;
}
}
if ( !function_exists( 'table' ) )
{
function table( $key )
{
$CI = &get_instance();
if ( is_numeric( $key ) )
$result = $CI->db->select( 'table_name' )->where( 'id', $key )->get( CMS_MAIN_TABLE )->row()->table_name;
else
$result = $CI->db->select( 'table_name' )->where( 'cms_key', $key )->get( CMS_MAIN_TABLE )->row()->table_name;
return $result;
}
}
if ( !function_exists( 'msg' ) )
{
function msg( $msg )
{
if ( $msg )
{
$CI = &get_instance();
return $CI->cms->msg( $msg );
}
}
}
if ( !function_exists( 'isYes' ) )
{
function isYes( $str )
{
if ( $str == 'yes' )
return true;
else
return false;
}
}
if ( !function_exists( 'userdata' ) )
{
function userdata( $key )
{
$CI = &get_instance();
return $CI->session->userdata( $key );
}
}
if ( !function_exists( 'menuActive' ) )
{
function menuActive()
{
$CI = &get_instance();
return 'active:' . $CI->data['params']['active'];
}
}
if ( !function_exists( 'text' ) )
{
function text( $str )
{
$str = htmlspecialchars_decode( $str, ENT_QUOTES );
$str = htmlspecialchars_decode( $str, ENT_QUOTES );
$str = htmlspecialchars_decode( $str, ENT_QUOTES );
return htmlspecialchars( $str, ENT_QUOTES );
}
}
if ( !function_exists( 'getMenu' ) )
{
function getMenu( $position )
{
$CI = &get_instance();
return $CI->shop->getMenu( $position );
}
}
if ( !function_exists( 'menuUrl' ) )
{
function menuUrl( $link )
{
if ( $link->permalink )
return site_url( 'page/' . $link->permalink );
return site_url( 'page/' . $link->id );
}
}
?>
if (!function_exists('_is_set'))
{
function _is_set($str)
{
if (strlen(trim($str)) > 0)
return true;
else
return false;
}
}
if (!function_exists('config'))
{
function config($key)
{
$CI = &get_instance();
$value = $CI->db->select('value')->where('key', $key)->get('configuration')->row();
if ($value)
return $value->value;
else
return false;
}
}
if (!function_exists('descr'))
{
function description($key)
{
$CI = &get_instance();
$value = $CI->db->select('text')->where('key', $key)->get('text_descriptions')->row();
return $value->text;
}
}
if (!function_exists('fieldError'))
{
function fieldError($field, $prefix = '', $sufix = '')
{
$CI = &get_instance();
return $CI->errors->showError($field, $prefix, $sufix);
}
}
if (!function_exists('deleteFile'))
{
function deleteFile($path)
{
return unlink($path);
}
}
if (!function_exists('bullet'))
{
function bullet()
{
return ' ';
}
}
if (!function_exists('formatNumber'))
{
function formatNumber($int)
{
return number_format($int, 0, '.', ' ');
}
}
if (!function_exists('formatPrice'))
{
function formatPrice($price, $lv = false)
{
$price_ = explode('.', $price);
if ($lv)
return number_format($price, 2, '.', ' ');
else
return number_format($price, 2, '.', ' ') . ' лв.';
}
}
if (!function_exists('imageSrc'))
{
function imageSrc($src, $prefix)
{
$CI = &get_instance();
if (!$src)
return base_url() . 'public/images/no-images/' . $prefix . 'image.png';
return $CI->images->path($src, $prefix);
}
}
if (!function_exists('avatarSrc'))
{
function avatarSrc($src, $prefix)
{
$CI = &get_instance();
if (!$src)
return base_url() . 'public/images/no-images/' . $prefix . 'image.png';
if ($prefix == '196x149_')
return $CI->users->avatar($src)->vipUrl;
else
return $CI->users->avatar($src)->hugeUrl;
}
}
if (!function_exists('maxText'))
{
function maxText($phrase, $len)
{
$phrase = strip_tags($phrase);
$phrase = trim(str_replace(' ', ' ', $phrase));
if (mb_strlen($phrase, 'utf-8') > $len)
$phrase = mb_substr($phrase, 0, $len, 'utf-8') . '...';
return text($phrase);
}
}
if (!function_exists('dateFormat'))
{
function dateFormat($date, $format = false)
{
if (!$format)
$format = 'H:i - d/m/Y ';
$date = strtotime($date);
return date($format, $date);
}
}
if (!function_exists('discountCredits'))
{
function discountCredits($credits)
{
$CI = &get_instance();
$credits = ceil($credits - $credits / 100 * $CI->data['user']->discount);
if ($credits < 0)
$credits = 0;
return $credits;
}
}
if (!function_exists('formatCredits'))
{
function formatCredits($credits, $discount = false)
{
$credits = (int)$credits;
if ($discount)
{
$credits_ = (int)discountCredits($credits);
if ($credits_ != $credits)
{
if ($credits_ == 1)
return '' . formatNumber($credits) . '' . formatNumber($credits_) . ' кредит';
else
return '' . formatNumber($credits) . '' . formatNumber($credits_) . ' кредита';
}
}
if ($credits == 1)
return $credits . ' кредит';
else
return formatNumber($credits) . ' кредита';
}
}
if (!function_exists('formatProducts'))
{
function formatProducts($num)
{
$num = (int)$num;
if ($num == 1)
return formatNumber($num) . ' обява';
else
return formatNumber($num) . ' обяви';
}
}
if (!function_exists('formatViews'))
{
function formatViews($views)
{
$views = (int)$views;
if ($views == 1)
return $views . ' път';
else
return $views . ' пъти';
}
}
if (!function_exists('rating'))
{
function rating($rating, $votes = false, $sum = true)
{
if ($votes)
$votesHtml = '
(' . $votes . ')
';
if ($sum)
$sumHtml = '' . round($rating, 1) . '
';
$width = round(58 / 5 * $rating);
$html = '
' . $sumHtml . '
' . $votesHtml . '
';
return $html;
}
}
if (!function_exists('productUrl'))
{
function productUrl($id)
{
$CI = &get_instance();
$title = $CI->db->select('title')->where('id', $id)->get('products')->row()->title;
$title = $CI->site->transliteration($title);
$title = preg_replace("/[^" . CMS_ALPHABET . "0-9]/i", "", $title);
$table = array(' ' => '-');
$title = mb_strtolower(strtr(trim($title), $table), 'utf8');
return site_url('product/' . $id . '/' . $title);
}
}
if (!function_exists('firmUrl'))
{
function firmUrl($id)
{
$CI = &get_instance();
$title = $CI->db->select('firm_name')->where('id', $id)->get('users')->row()->firm_name;
$title = $CI->site->transliteration($title);
$title = preg_replace("/[^" . CMS_ALPHABET . "0-9]/i", "", $title);
$table = array(' ' => '-');
$title = mb_strtolower(strtr(trim($title), $table), 'utf8');
return site_url('firms/' . $id . '/' . $title);
}
}
if (!function_exists('activity'))
{
function activity($timestamp)
{
/*
if ($timestamp + 300 < time())
return 'извън линия';
else
return 'в сайта';
*/
if (!($timestamp + 300 < time()))
return '
';
}
}
if (!function_exists('adStatus'))
{
function adStatus($status, $expireDate, $auction = false)
{
$expireDate = strtotime($expireDate);
if ($auction)
{
switch ($status)
{
case 'expiring':
case 'active':
$js = '
';
return $js . 'Търгът изтича след ';
break;
case 'expired':
return 'Търгът е приключил';
break;
}
} else
{
if ($status != 'active')
{
$expireDate = round(($expireDate - time()) / 86400);
if (!$expireDate)
$expireDate = 'днес в ' . date('H:i часа', $expireDate);
elseif ($expireDate == 1)
$expireDate = 'след ' . $expireDate . ' ден';
else
$expireDate = 'след ' . $expireDate . ' дни';
}
switch ($status)
{
case 'expiring':
return 'Обявата изтича ' . $expireDate;
break;
case 'expired':
return 'Обявата е изтекла';
break;
case 'active':
return 'Обявата изтича на ' . date('d.m.Yг. в H:i часа', $expireDate);
break;
}
}
}
}
if (!function_exists('searchUrl'))
{
function searchUrl($array = false)
{
if ($array)
$get = '?' . urldecode(http_build_query($array));
return site_url('search/' . $get);
}
}
if (!function_exists('searchModify'))
{
function searchModify($modifyArray = false, $unsetArray = false)
{
$CI = &get_instance();
$array = $CI->input->get();
foreach ($modifyArray as $key => $value)
$array[$key] = $value;
foreach ($unsetArray as $key => $value)
unset($array[$value]);
$get = '?' . urldecode(http_build_query($array));
return site_url('search/' . $get);
}
}
if (!function_exists('searchFirmsModify'))
{
function searchFirmsModify($modifyArray = false, $unsetArray = false)
{
$CI = &get_instance();
$array = $CI->input->get();
foreach ($modifyArray as $key => $value)
$array[$key] = $value;
foreach ($unsetArray as $key => $value)
unset($array[$value]);
$get = '?' . urldecode(http_build_query($array));
return site_url('firms/' . $get);
}
}
if (!function_exists('searchType'))
{
function searchType($type)
{
$CI = &get_instance();
$currentType = $CI->session->userdata('results_type');
if ($currentType == $type || ($type == 'listing' && !$currentType))
return ' active ';
}
}
if (!function_exists('productAdvertising'))
{
function productAdvertising($typesIds = false)
{
if (!$typesIds)
return ' normal ';
if (in_array(8, $typesIds))
$data[] = 'yellow';
return ' ' . implode(' ', $data) . ' ';
}
}
if (!function_exists('productAdvertisingIcons'))
{
function productAdvertisingIcons($typesIds = false, $trim = false)
{
if (!$typesIds)
return;
$CI = &get_instance();
foreach ($typesIds as $id)
{
$temp = $CI->services->adTypesFull($id);
if ($trim)
$data[] = '
';
else
$data[] = '
';
}
if ($trim)
return implode(' ', $data) . ' ';
else
return ' ' . implode(' ', $data) . ' ';
}
}
if (!function_exists('firmAdvertisingIcons'))
{
function firmAdvertisingIcons($typesIds = false, $trim = false)
{
if (!$typesIds)
return;
$CI = &get_instance();
$CI->load->model('firms_services');
foreach ($typesIds as $id)
{
$temp = $CI->firms_services->adTypesFull($id);
if ($trim)
$data[] = '
';
else
$data[] = '
';
}
if ($trim)
return implode(' ', $data) . ' ';
else
return ' ' . implode(' ', $data) . ' ';
}
}
if (!function_exists('refererUrl'))
{
function refererUrl($url)
{
return ($_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : $url);
}
}
if (!function_exists('tipsy'))
{
function tipsy($str)
{
preg_match_all('/\((.{3,})\)/iU', $str, $out, PREG_SET_ORDER);
if ($out[0])
{
$last = end($out);
$str = str_replace($last[0], '', $str);
$str = '' . $str . '
';
}
return $str;
}
}
function current_url_full()
{
$CI = &get_instance();
$url = $CI->config->site_url($CI->uri->uri_string());
return $_SERVER['QUERY_STRING'] ? $url . '?' . $_SERVER['QUERY_STRING'] : $url;
}
function userStatus($statusId)
{
$CI = &get_instance();
return $CI->users->getStatus($statusId);
}
/** CONVERT **/
function convert_number_to_words($number)
{
$hyphen = ' и ';
$conjunction = ' и ';
$separator = ' ';
$negative = 'negative ';
$decimal = ' цяло ';
$dictionary = array(0 => 'нула', 1 => '', 2 => 'две', 3 => 'три', 4 => 'четири', 5 => 'пет', 6 => 'шест', 7 => 'седем', 8 => 'осем', 9 => 'девет', 10 => 'десет', 11 => 'единадесет', 12 => 'дванадесет', 13 => 'тринадесет', 14 => 'четиринадесет', 15 => 'петнадесет', 16 => 'шестнадесет', 17 => 'седемнадесет', 18 => 'осемнадесет', 19 => 'деветнадесет', 20 => 'двадесет', 30 => 'тридесет', 40 => 'четиридесет', 50 => 'петдесет', 60 => 'шестдесет', 70 => 'седемдесет', 80 => 'осемдесет', 90 => 'деветдесет', 100 => 'сто', 1000 => 'хиляди', 1000000 => 'милиона');
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:
$dictionary[1] = 'един';
$string = $dictionary[$number];
break;
case $number < 100:
$dictionary[1] = 'един';
$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;
if ($hundreds == 1 || !$dictionary[$hundreds])
$string = 'сто';
else
{
$hundreds = reset(explode('.', $hundreds));
if ($hundreds == 2 || $hundreds == 3)
$string = $dictionary[$hundreds] . 'ста';
else
$string = $dictionary[$hundreds] . 'стотин';
}
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;
if ($numBaseUnits > 1)
$string = convert_number_to_words($numBaseUnits) . ' ' . $dictionary[$baseUnit];
else
$string = 'хиляда';
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);
}
$string = $explodedStr = explode(' ', $string);
foreach ($string as $key => &$temp)
if ($temp == 'и')
unset($string[$key]);
$string = implode(' ', $string);
return $string;
}
function no_orphans($TheParagraph, $convert = false)
{
$explode = explode(' ', $TheParagraph);
if (count($explode) == 2)
{
if (!preg_match('/хиля/', $explode[1]))
{
$lastspace = strrpos($TheParagraph, " ");
$TheParagraph = substr_replace($TheParagraph, " и ", $lastspace, 1);
}
} else
if (substr_count($TheParagraph, " ") > 1)
{
$lastspace = strrpos($TheParagraph, " ");
$TheParagraph = substr_replace($TheParagraph, " и ", $lastspace, 1);
}
$TheParagraph = explode(' ', $TheParagraph);
if ($convert)
{
if (end($TheParagraph) == 'две')
$TheParagraph[count($TheParagraph) - 1] = 'два';
} else
if (end($TheParagraph) == 'един')
$TheParagraph[count($TheParagraph) - 1] = 'една';
$TheParagraph = implode(' ', $TheParagraph);
return $TheParagraph;
}
function convertNumToWords($price)
{
$num = explode('.', $price);
if (count($num) == 2 && $num[1] > 0)
{
if (strlen($num[1]) == 1)
$num[1] .= '0';
$num[1] = substr($num[1], 0, 2);
return no_orphans(convert_number_to_words($num[0]), true) . ' лв. ' . no_orphans(convert_number_to_words($num[1])) . ' ст.';
} else
return no_orphans(convert_number_to_words($num[0]), true) . ' лв.';
}
if (!function_exists('t'))
{
function t($text)
{
if ($_SERVER['REMOTE_ADDR'] == '93.152.157.246')
{
$CI = &get_instance();
return $CI->translation_->translation($text, $array);
} else
return $text;
}
}
?>