PageRenderTime 735ms CodeModel.GetById 172ms app.highlight 242ms RepoModel.GetById 220ms app.codeStats 0ms

/halogy/application/helpers/halogy_helper.php

https://bitbucket.org/haloweb/halogy-1.0/
PHP | 778 lines | 692 code | 62 blank | 24 comment | 81 complexity | 6f7bb10c0be1de746aab69b2337f70f1 MD5 | raw file
  1<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2/**
  3 * Halogy
  4 *
  5 * A user friendly, modular content management system for PHP 5.0
  6 * Built on CodeIgniter - http://codeigniter.com
  7 *
  8 * @package		Halogy
  9 * @author		Haloweb Ltd.
 10 * @copyright	Copyright (c) 2008-2011, Haloweb Ltd.
 11 * @license		http://halogy.com/license
 12 * @link		http://halogy.com/
 13 * @since		Version 1.0
 14 * @filesource
 15 */
 16
 17// ------------------------------------------------------------------------
 18
 19// orderby helper (will be extended in time)
 20function order_link($link, $orderby, $text, $segment = 4)
 21{
 22	$CI =& get_instance();
 23	
 24	if (!$CI->uri->segment($segment) || $CI->uri->segment($segment) == 'orderdesc')
 25	{
 26		$order = 'orderasc';
 27	}
 28	else
 29	{
 30		$order = 'orderdesc';
 31	}
 32
 33	if ($CI->uri->segment(($segment+1)) == $orderby)
 34	{
 35		$class = 'class="'.$order.'"';
 36	}
 37	else
 38	{
 39		$class = '';
 40	}
 41	
 42	echo anchor($link.'/'.$order.'/'.$orderby, $text, $class); 
 43
 44}
 45
 46// get country codes
 47function get_country_codes($country = '')
 48{
 49	$countries = array(
 50		'AF'=>'AFGHANISTAN',
 51		'AX'=>'ALAND ISLANDS',
 52		'AL'=>'ALBANIA',
 53		'DZ'=>'ALGERIA',
 54		'AS'=>'AMERICAN SAMOA',
 55		'AD'=>'ANDORRA',
 56		'AO'=>'ANGOLA',
 57		'AI'=>'ANGUILLA',
 58		'AQ'=>'ANTARCTICA',
 59		'AG'=>'ANTIGUA AND BARBUDA',
 60		'AR'=>'ARGENTINA',
 61		'AM'=>'ARMENIA',
 62		'AW'=>'ARUBA',
 63		'AU'=>'AUSTRALIA',
 64		'AT'=>'AUSTRIA',
 65		'AZ'=>'AZERBAIJAN',
 66		'BS'=>'BAHAMAS',
 67		'BH'=>'BAHRAIN',
 68		'BD'=>'BANGLADESH',
 69		'BB'=>'BARBADOS',
 70		'BY'=>'BELARUS',
 71		'BE'=>'BELGIUM',
 72		'BZ'=>'BELIZE',
 73		'BJ'=>'BENIN',
 74		'BM'=>'BERMUDA',
 75		'BT'=>'BHUTAN',
 76		'BO'=>'BOLIVIA',
 77		'BA'=>'BOSNIA AND HERZEGOVINA',
 78		'BW'=>'BOTSWANA',
 79		'BV'=>'BOUVET ISLAND',
 80		'BR'=>'BRAZIL',
 81		'IO'=>'BRITISH INDIAN OCEAN TERRITORY',
 82		'BN'=>'BRUNEI DARUSSALAM',
 83		'BG'=>'BULGARIA',
 84		'BF'=>'BURKINA FASO',
 85		'BI'=>'BURUNDI',
 86		'KH'=>'CAMBODIA',
 87		'CM'=>'CAMEROON',
 88		'CA'=>'CANADA',
 89		'CV'=>'CAPE VERDE',
 90		'CI'=>'CâTE D\'IVOIRE',
 91		'KY'=>'CAYMAN ISLANDS',
 92		'CF'=>'CENTRAL AFRICAN REPUBLIC',
 93		'TD'=>'CHAD',
 94		'CL'=>'CHILE',
 95		'CN'=>'CHINA',
 96		'CX'=>'CHRISTMAS ISLAND',
 97		'CC'=>'COCOS (KEELING) ISLANDS',
 98		'CO'=>'COLOMBIA',
 99		'KM'=>'COMOROS',
100		'CG'=>'CONGO',
101		'CD'=>'CONGO, THE DEMOCRATIC REPUBLIC OF THE',
102		'CK'=>'COOK ISLANDS',
103		'CR'=>'COSTA RICA',
104		'HR'=>'CROATIA',
105		'CU'=>'CUBA',
106		'CY'=>'CYPRUS',
107		'CZ'=>'CZECH REPUBLIC',
108		'DK'=>'DENMARK',
109		'DJ'=>'DJIBOUTI',
110		'DM'=>'DOMINICA',
111		'DO'=>'DOMINICAN REPUBLIC',
112		'EC'=>'ECUADOR',
113		'EG'=>'EGYPT',
114		'SV'=>'EL SALVADOR',
115		'GQ'=>'EQUATORIAL GUINEA',
116		'ER'=>'ERITREA',
117		'EE'=>'ESTONIA',
118		'ET'=>'ETHIOPIA',
119		'FK'=>'FALKLAND ISLANDS (MALVINAS)',
120		'FO'=>'FAROE ISLANDS',
121		'FJ'=>'FIJI',
122		'FI'=>'FINLAND',
123		'FR'=>'FRANCE',
124		'GF'=>'FRENCH GUIANA',
125		'PF'=>'FRENCH POLYNESIA',
126		'TF'=>'FRENCH SOUTHERN TERRITORIES',
127		'GA'=>'GABON',
128		'GM'=>'GAMBIA',
129		'GE'=>'GEORGIA',
130		'DE'=>'GERMANY',
131		'GH'=>'GHANA',
132		'GI'=>'GIBRALTAR',
133		'GR'=>'GREECE',
134		'GL'=>'GREENLAND',
135		'GD'=>'GRENADA',
136		'GP'=>'GUADELOUPE',
137		'GU'=>'GUAM',
138		'GT'=>'GUATEMALA',
139		'GN'=>'GUINEA',
140		'GW'=>'GUINEA-BISSAU',
141		'GY'=>'GUYANA',
142		'HT'=>'HAITI',
143		'HM'=>'HEARD ISLAND AND MCDONALD ISLANDS',
144		'VA'=>'HOLY SEE (VATICAN CITY STATE)',
145		'HN'=>'HONDURAS',
146		'HK'=>'HONG KONG',
147		'HU'=>'HUNGARY',
148		'IS'=>'ICELAND',
149		'IN'=>'INDIA',
150		'ID'=>'INDONESIA',
151		'IR'=>'IRAN ISLAMIC REPUBLIC OF',
152		'IQ'=>'IRAQ',
153		'IE'=>'IRELAND',
154		'IL'=>'ISRAEL',
155		'IT'=>'ITALY',
156		'JM'=>'JAMAICA',
157		'JP'=>'JAPAN',
158		'JO'=>'JORDAN',
159		'KZ'=>'KAZAKHSTAN',
160		'KE'=>'KENYA',
161		'KI'=>'KIRIBATI',
162		'KP'=>'KOREA DEMOCRATIC PEOPLE\'S REPUBLIC OF',
163		'KR'=>'KOREA REPUBLIC OF',
164		'KW'=>'KUWAIT',
165		'KG'=>'KYRGYZSTAN',
166		'LA'=>'LAO PEOPLE\'S DEMOCRATIC REPUBLIC',
167		'LV'=>'LATVIA',
168		'LB'=>'LEBANON',
169		'LS'=>'LESOTHO',
170		'LR'=>'LIBERIA',
171		'LY'=>'LIBYAN ARAB JAMAHIRIYA',
172		'LI'=>'LIECHTENSTEIN',
173		'LT'=>'LITHUANIA',
174		'LU'=>'LUXEMBOURG',
175		'MO'=>'MACAO',
176		'MK'=>'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF',
177		'MG'=>'MADAGASCAR',
178		'MW'=>'MALAWI',
179		'MY'=>'MALAYSIA',
180		'MV'=>'MALDIVES',
181		'ML'=>'MALI',
182		'MT'=>'MALTA',
183		'MH'=>'MARSHALL ISLANDS',
184		'MQ'=>'MARTINIQUE',
185		'MR'=>'MAURITANIA',
186		'MU'=>'MAURITIUS',
187		'YT'=>'MAYOTTE',
188		'MX'=>'MEXICO',
189		'FM'=>'MICRONESIA, FEDERATED STATES OF',
190		'MD'=>'MOLDOVA, REPUBLIC OF',
191		'MC'=>'MONACO',
192		'MN'=>'MONGOLIA',
193		'MS'=>'MONTSERRAT',
194		'MA'=>'MOROCCO',
195		'MZ'=>'MOZAMBIQUE',
196		'MM'=>'MYANMAR',
197		'NA'=>'NAMIBIA',
198		'NR'=>'NAURU',
199		'NP'=>'NEPAL',
200		'NL'=>'NETHERLANDS',
201		'AN'=>'NETHERLANDS ANTILLES',
202		'NC'=>'NEW CALEDONIA',
203		'NZ'=>'NEW ZEALAND',
204		'NI'=>'NICARAGUA',
205		'NE'=>'NIGER',
206		'NG'=>'NIGERIA',
207		'NU'=>'NIUE',
208		'NF'=>'NORFOLK ISLAND',
209		'MP'=>'NORTHERN MARIANA ISLANDS',
210		'NO'=>'NORWAY',
211		'OM'=>'OMAN',
212		'PK'=>'PAKISTAN',
213		'PW'=>'PALAU',
214		'PS'=>'PALESTINIAN TERRITORY, OCCUPIED',
215		'PA'=>'PANAMA',
216		'PG'=>'PAPUA NEW GUINEA',
217		'PY'=>'PARAGUAY',
218		'PE'=>'PERU',
219		'PH'=>'PHILIPPINES',
220		'PN'=>'PITCAIRN',
221		'PL'=>'POLAND',
222		'PT'=>'PORTUGAL',
223		'PR'=>'PUERTO RICO',
224		'QA'=>'QATAR',
225		'RE'=>'REUNION',
226		'RO'=>'ROMANIA',
227		'RU'=>'RUSSIAN FEDERATION',
228		'RW'=>'RWANDA',
229		'SH'=>'SAINT HELENA',
230		'KN'=>'SAINT KITTS AND NEVIS',
231		'LC'=>'SAINT LUCIA',
232		'PM'=>'SAINT PIERRE AND MIQUELON',
233		'VC'=>'SAINT VINCENT AND THE GRENADINES',
234		'WS'=>'SAMOA',
235		'SM'=>'SAN MARINO',
236		'ST'=>'SAO TOME AND PRINCIPE',
237		'SA'=>'SAUDI ARABIA',
238		'SN'=>'SENEGAL',
239		'CS'=>'SERBIA AND MONTENEGRO',
240		'SC'=>'SEYCHELLES',
241		'SL'=>'SIERRA LEONE',
242		'SG'=>'SINGAPORE',
243		'SK'=>'SLOVAKIA',
244		'SI'=>'SLOVENIA',
245		'SB'=>'SOLOMON ISLANDS',
246		'SO'=>'SOMALIA',
247		'ZA'=>'SOUTH AFRICA',
248		'GS'=>'SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS',
249		'ES'=>'SPAIN',
250		'LK'=>'SRI LANKA',
251		'SD'=>'SUDAN',
252		'SR'=>'SURINAME',
253		'SJ'=>'SVALBARD AND JAN MAYEN',
254		'SZ'=>'SWAZILAND',
255		'SE'=>'SWEDEN',
256		'CH'=>'SWITZERLAND',
257		'SY'=>'SYRIAN ARAB REPUBLIC',
258		'TW'=>'TAIWAN PROVINCE OF CHINA',
259		'TJ'=>'TAJIKISTAN',
260		'TZ'=>'TANZANIA UNITED REPUBLIC OF',
261		'TH'=>'THAILAND',
262		'TL'=>'TIMOR-LESTE',
263		'TG'=>'TOGO',
264		'TK'=>'TOKELAU',
265		'TO'=>'TONGA',
266		'TT'=>'TRINIDAD AND TOBAGO',
267		'TN'=>'TUNISIA',
268		'TR'=>'TURKEY',
269		'TM'=>'TURKMENISTAN',
270		'TC'=>'TURKS AND CAICOS ISLANDS',
271		'TV'=>'TUVALU',
272		'UG'=>'UGANDA',
273		'UA'=>'UKRAINE',
274		'AE'=>'UNITED ARAB EMIRATES',
275		'GB'=>'UNITED KINGDOM',
276		'US'=>'UNITED STATES',
277		'UM'=>'UNITED STATES MINOR OUTLYING ISLANDS',
278		'UY'=>'URUGUAY',
279		'UZ'=>'UZBEKISTAN',
280		'VU'=>'VANUATU',
281		'VE'=>'VENEZUELA',
282		'VN'=>'VIETNAM',
283		'VG'=>'VIRGIN ISLANDS BRITISH',
284		'VI'=>'VIRGIN ISLANDS U.S.',
285		'WF'=>'WALLIS AND FUTUNA',
286		'EH'=>'WESTERN SAHARA',
287		'YE'=>'YEMEN',
288		'ZM'=>'ZAMBIA',
289		'ZW'=>'ZIMBABWE'
290	);
291
292	return $countries;
293}
294
295// get country
296function lookup_country($country)
297{
298	$countries = get_country_codes();
299
300	return ucwords(strtolower(@$countries[$country]));
301}
302
303// helper for displaying countries (no ID)
304function display_countries($name = 'country', $selected = '', $extras = '')
305{
306	$output = '';
307
308	$countries = get_country_codes();
309
310	$output .= '<select name="'.$name.'" '.$extras.'>'."\n";
311
312	foreach($countries as $country => $name)
313	{
314		$name = ucwords(strtolower($name));
315		
316		$output .= '<option value="'.$country.'"';
317		if ($country == $selected || ($selected == '' && $country == 'US'))
318		{
319			$output .= ' selected="selected"';
320		}
321		$output .= '>'.$name.'</option>'."\n";
322	}
323	$output .= '</select>'."\n";
324
325	return $output;
326}
327
328// get state codes
329function get_state_codes($state = '')
330{
331	$states = array(
332		''=>'',
333		'AL'=>'Alabama',
334		'AK'=>'Alaska', 
335		'AZ'=>'Arizona', 
336		'AR'=>'Arkansas', 
337		'CA'=>'California', 
338		'CO'=>'Colorado', 
339		'CT'=>'Connecticut', 
340		'DE'=>'Delaware', 
341		'DC'=>'District Of Columbia', 
342		'FL'=>'Florida', 
343		'GA'=>'Georgia', 
344		'HI'=>'Hawaii', 
345		'ID'=>'Idaho',
346		'IL'=>'Illinois',
347		'IN'=>'Indiana',
348		'IA'=>'Iowa',
349		'KS'=>'Kansas',
350		'KY'=>'Kentucky',
351		'LA'=>'Louisiana',
352		'ME'=>'Maine',
353		'MD'=>'Maryland',
354		'MA'=>'Massachusetts',
355		'MI'=>'Michigan',
356		'MN'=>'Minnesota',
357		'MS'=>'Mississippi',
358		'MO'=>'Missouri',
359		'MT'=>'Montana',
360		'NE'=>'Nebraska',
361		'NV'=>'Nevada',
362		'NH'=>'New Hampshire',
363		'NJ'=>'New Jersey',
364		'NM'=>'New Mexico',
365		'NY'=>'New York',
366		'NC'=>'North Carolina',
367		'ND'=>'North Dakota',
368		'OH'=>'Ohio',
369		'OK'=>'Oklahoma',
370		'OR'=>'Oregon',
371		'PA'=>'Pennsylvania',
372		'RI'=>'Rhode Island',
373		'SC'=>'South Carolina',
374		'SD'=>'South Dakota',
375		'TN'=>'Tennessee',
376		'TX'=>'Texas',
377		'UT'=>'Utah',
378		'VT'=>'Vermont',
379		'VA'=>'Virginia',
380		'WA'=>'Washington',
381		'WV'=>'West Virginia',
382		'WI'=>'Wisconsin',
383		'WY'=>'Wyoming'
384	);
385
386	return $states;
387}
388
389// get state
390function lookup_state($state)
391{
392	$states = get_state_codes();
393
394	return ucwords(strtolower(@$states[$state]));
395}
396
397// helper for displaying countries (no ID)
398function display_states($name = 'state', $selected = '', $extras = '')
399{
400	$output = '';
401
402	$states = get_state_codes();
403
404	$output .= '<select name="'.$name.'" '.$extras.'>'."\n";
405
406	foreach($states as $state => $name)
407	{
408		$name = ucwords(strtolower($name));
409		
410		$output .= '<option value="'.$state.'"';
411		if ($state == $selected || ($selected == '' && $state == 'US'))
412		{
413			$output .= ' selected="selected"';
414		}
415		$output .= '>'.$name.'</option>'."\n";
416	}
417	$output .= '</select>'."\n";
418
419	return $output;
420}
421
422// image loader (requires images model/lib)
423function load_image($image, $thumb = false, $product = false)
424{
425	$CI =& get_instance();
426
427	$imagePath = $CI->uploads->load_image($image, $thumb, $product);
428
429	return $imagePath['src'];
430	
431}
432
433function display_image($path, $alt, $size = '', $extras = '', $nopic = FALSE)
434{
435	if (!$imageSize = @getimagesize('.'.$path))
436	{
437		if ($nopic !== FALSE)
438		{
439			$imageHTML = '<img src="'.$nopic.'" alt="No Picture" ';
440		}
441		else
442		{
443			return FALSE;
444		}
445	}
446	else
447	{
448		$imageHTML = '<img src="'.$path.'" alt="'.$alt.'" ';
449	}
450
451	if ($size)
452	{
453		if (is_array($size))
454		{
455			$widthfactor = (isset($size['width'])) ? $imageSize[0] / $size['width'] : 0;
456			$heightfactor = (isset($size['height'])) ? $imageSize[1] / $size['height'] : 0;
457			
458			if ($imageSize[0] > $size['width'] && ($widthfactor > $heightfactor || $widthfactor == $heightfactor))
459			{
460				$factor = $imageSize[0] / $size['width'];
461				$imageHTML .= 'width="'.$size['width'].'" ';
462			}
463			elseif ($imageSize[1] > $size['height'] && $heightfactor > $widthfactor)
464			{
465				$imageHTML .= 'height="'.$size['height'].'" ';
466			}
467		}
468		elseif (intval($size) && $size > 0 && (($imageSize[0] > $size || $imageSize[1] > $size) || $nopic))
469		{
470			if (($imageSize[0] > $imageSize[1]) || $imageSize[0] == $imageSize[1])
471			{
472				$imageHTML .= 'width="'.$size.'" ';
473			}
474			elseif ($imageSize[1] > $imageSize[0])
475			{
476				$imageHTML .= 'height="'.$size.'" ';
477			}
478		}
479	}
480
481	if ($extras != '')
482	{
483		$imageHTML .= $extras.' ';
484	}
485
486	$imageHTML .= '/>';
487
488	return $imageHTML;
489}
490
491// date formatting for mysql dates
492function datefmt($date, $fmt = '', $timezone = '', $seconds = FALSE)
493{
494	$CI =& get_instance();
495
496	if ($CI->site->config['timezone'] && $timezone == '')
497	{
498		$timezone = $CI->site->config['timezone'];
499	}
500	
501	if (!$fmt)
502	{
503		if (@$CI->site->config['dateOrder'] == 'MD')
504		{
505			$fmt = 'M jS Y';
506		}
507		else
508		{
509			$fmt = 'jS M Y';
510		}
511	}
512	
513	if ($seconds)
514	{
515		$fmt .= ', H:i';
516	}
517	
518	if ($date && $date > 0)
519	{
520		$timestamp = local_to_gmt(strtotime($date));
521
522		if ($timezone)
523		{
524			$timestamp = gmt_to_local($timestamp, $timezone, FALSE);
525		}
526
527		return date($fmt, $timestamp);
528	}
529	else
530	{ 
531		return false;
532	}
533}
534
535function currency_symbol($html = TRUE, $currency = '')
536{
537	$CI =& get_instance();
538	
539	$currency = (!$currency) ? $CI->site->config['currency'] : $currency;
540
541	if ($currency == 'GBP')
542	{
543		return ($html) ? '&pound;' : '£';
544	}
545	elseif ($currency == 'JPY')
546	{
547		return ($html) ? '&yen;' : '¥';
548	}
549	elseif ($currency == 'EUR')
550	{
551		return ($html) ? '&euro;' : '€';
552	}
553	elseif ($currency == 'DKK' || $currency == 'SEK' || $currency == 'NOK')
554	{
555		return 'kr ';
556	}
557	elseif ($currency == 'IDR')
558	{
559		return 'Rp ';
560	}
561	elseif ($currency == 'INR')
562	{
563		return 'Rs ';
564	}
565	elseif ($currency == 'CHF')
566	{
567		return 'CHF ';
568	}
569	elseif ($currency == 'PLN')
570	{
571		return 'zl ';
572	}
573	elseif ($currency == 'RUB')
574	{
575		return 'P.';
576	}
577	elseif ($currency == 'SGD')
578	{
579		return 'S$';
580	}
581	elseif ($currency == 'ZAR')
582	{
583		return 'R ';
584	}
585	elseif ($currency == 'MYR')
586	{
587		return 'RM ';
588	}
589	elseif ($currency == 'BRL')
590	{
591		return 'R$';
592	}
593	elseif ($currency == 'LKR')
594	{
595		return 'Rs ';
596	}
597	elseif ($currency == 'VEF')
598	{
599		return 'Bs.F ';
600	}
601	elseif ($currency == 'LVL')
602	{
603		return 'Ls ';
604	}
605	elseif ($currency == 'ILS')
606	{
607		return ($html) ? '&#8362;' : '₪';
608	}
609	elseif ($currency == 'AED')
610	{
611		return 'AED ';
612	}
613	elseif ($currency == 'CZK')
614	{
615		return ($html) ? 'K&#269; ' : 'Kč ';
616	}
617	elseif ($currency == 'KES')
618	{
619		return 'KSh ';
620	}
621	else
622	{
623		return '$';
624	}
625}
626
627function currencies()
628{
629	$values = array(
630		'USD' => 'US Dollars (USD)',
631		'GBP' => 'UK Pounds (GBP)',	
632		'EUR' => 'Euro (EUR)',
633		'AED' => 'UAE Dirham (AED)',		
634		'ARS' => 'Argentina Pesos (ARS)',
635		'AUD' => 'Australia Dollars (AUD)',	
636		'BRL' => 'Brazil Real (BRL)',
637		'CAD' => 'Canada Dollars (CAD)',
638		'CHF' => 'Switzerland Francs (CHF)',
639		'CZK' => 'Czech Republic Koruny (CZK)',
640		'DKK' => 'Denmark Kroner (DKK)',
641		'DOP' => 'Dominican Republic Peso (DOP)',
642		'HKD' => 'Hong Kong Dollar (HKD)',
643		'IDR' => 'Indonesia Rupiah (IDR)',
644		'ILS' => 'Israel New Shekels (ILS)',
645		'INR' => 'India Rupees (INR)',
646		'JPY' => 'Japan Yen (JPY)',
647		'KES' => 'Kenya Shilling (KES)',		
648		'LKR' => 'Sri Lanka Rupees (LKR)',
649		'LVL' => 'Latvia Lat (LVL)',
650		'MXN' => 'Mexico Peso (MXN)',
651		'MYR' => 'Malaysia Ringgit (MYR)',
652		'NOK' => 'Norway Kroner (NOK)',
653		'NZD' => 'New Zealand Dollars (NZD)',		
654		'PLN' => 'Poland Zloty (PLN)',
655		'RUB' => 'Russian Federation Ruble (RUB)',
656		'SEK' => 'Sweden Kronor (SEK)',
657		'SGD' => 'Singapore Dollars (SGD)',		
658		'ZAR' => 'South Africa Rand (ZAR)',
659		'VEF' => 'Venezuela Bolivar Fuerte (VEF)'
660	);
661	return $values;
662}
663
664function languages()
665{
666	$values = array(
667		'english' => 'English',
668		'danish' => 'Danish',
669		'dutch' => 'Dutch',	
670		'finnish' => 'Finnish',	
671		'french' => 'French',
672		'german' => 'German',
673		'norweigan' => 'Norweigan',
674		'portugese' => 'Portugese',
675		'russian' => 'Russian',
676		'spanish' => 'Spanish'
677	);
678	return $values;
679}
680
681function fraction($int)
682{
683	$fraction = ($int - floor($int));
684	if ($fraction == '0.25')
685	{
686		return floor($int).' &frac14;';
687	}	
688	elseif ($fraction == '0.5')
689	{
690		return floor($int).' &frac12;';
691	}
692	elseif ($fraction == '0.75')
693	{
694		return floor($int).' &frac34;';
695	}	
696	else
697	{
698		return $int;
699	}
700}
701
702function order($by, $title, $desc = FALSE, $class = '', $extras = '')
703{
704	$CI =& get_instance();
705	
706	$segments = $CI->uri->segment_array();
707
708	if ($key = @array_search('orderby', $segments))
709	{
710		if ($segments[$key + 1] == $by)
711		{
712			if ($segments[$key + 2] == 'desc')
713			{
714				$segments[$key + 2] = 'asc';
715				$class = 'orderdesc '.$class;
716			}
717			else
718			{
719				$segments[$key + 2] = 'desc';
720				$class = 'orderasc '.$class;			
721			}
722		}
723		else
724		{
725			$segments[$key + 2] = ($desc) ? 'desc' : 'asc';
726		}
727
728		$segments[$key + 1] = $by;		
729	}
730	else
731	{
732		array_push($segments, 'orderby');
733		array_push($segments, $by);
734		array_push($segments, (($desc) ? 'desc' : 'asc'));
735	}
736
737	$href = '/'.implode('/', str_replace('_ajax', '', $segments));
738	
739	return anchor($href, $title, 'class="'.trim($class).'" '.$extras);
740}
741
742function expiry_months_dropdown($name, $selected = '', $html = '')
743{
744	return form_dropdown($name, array(
745		'01' => 'January',
746		'02' => 'February',
747		'03' => 'March',
748		'04' => 'April',
749		'05' => 'May',
750		'06' => 'June',
751		'07' => 'July',
752		'08' => 'August',
753		'09' => 'September',
754		'10' => 'October',
755		'11' => 'November',
756		'12' => 'December',
757	), $selected, $html);
758}
759
760function expiry_years_dropdown($name, $selected = '', $html = '')
761{
762	$options = array();
763	
764	for ($i=0; $i < 20; $i++) { 
765		$options[date('Y', time()+(60*60*24*365)*$i+1)] = date('Y', time()+(60*60*24*365)*$i+1);
766	}
767	
768	return form_dropdown($name, $options, $selected, $html);
769}
770
771function mkdn($text)
772{
773	$CI =& get_instance();
774
775	$CI->load->library('mkdn');
776			
777	return $CI->mkdn->translate($text);
778}