| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
function adv_truncate_text($string, $limit, $break = ".", $pad = "...") |
|---|
| 12 |
{ |
|---|
| 13 |
if (strlen($string) <= $limit) |
|---|
| 14 |
{ |
|---|
| 15 |
return $string; |
|---|
| 16 |
} |
|---|
| 17 |
|
|---|
| 18 |
if (false !== ($breakpoint = strpos($string, $break, $limit))) |
|---|
| 19 |
{ |
|---|
| 20 |
if ($breakpoint < strlen($string) - 1) |
|---|
| 21 |
{ |
|---|
| 22 |
$string = substr($string, 0, $breakpoint) . $pad; |
|---|
| 23 |
} |
|---|
| 24 |
} |
|---|
| 25 |
return $string; |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
function format_place($country_code, $city = null) |
|---|
| 36 |
{ |
|---|
| 37 |
if ($city) |
|---|
| 38 |
{ |
|---|
| 39 |
return sprintf('%s (%s)', $city, format_country($country_code)); |
|---|
| 40 |
} |
|---|
| 41 |
return format_country($country_code); |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
function format_relation($subject, $role, $start_date = null, $end_date = null) |
|---|
| 55 |
{ |
|---|
| 56 |
sfLoader::loadHelpers('I18N', 'Date'); |
|---|
| 57 |
$string = ''; |
|---|
| 58 |
|
|---|
| 59 |
if (is_null($start_date) && is_null($end_date)) |
|---|
| 60 |
{ |
|---|
| 61 |
$string = __('%subject% is or has been %role%', |
|---|
| 62 |
array('%subject%' => $subject, |
|---|
| 63 |
'%role%' => '<span>'.$role.'</span>')); |
|---|
| 64 |
} |
|---|
| 65 |
elseif (!is_null($start_date) && !is_null($end_date)) |
|---|
| 66 |
{ |
|---|
| 67 |
$string = __('%subject% has been %role% for %time% until %end_date%', |
|---|
| 68 |
array('%subject%' => $subject, |
|---|
| 69 |
'%role%' => '<span>'.$role.'</span>', |
|---|
| 70 |
'%time%' => distance_of_time_in_words(strtotime($start_date), |
|---|
| 71 |
strtotime($end_date)), |
|---|
| 72 |
'%end_date%' => strtolower($end_date))); |
|---|
| 73 |
} |
|---|
| 74 |
elseif (!is_null($start_date) && is_null($end_date)) |
|---|
| 75 |
{ |
|---|
| 76 |
$string = __('%subject% is %role% since %date%', |
|---|
| 77 |
array('%subject%' => $subject, |
|---|
| 78 |
'%role%' => '<span>'.$role.'</span>', |
|---|
| 79 |
'%date%' => $start_date)); |
|---|
| 80 |
} |
|---|
| 81 |
elseif (is_null($start_date)) |
|---|
| 82 |
{ |
|---|
| 83 |
$string = __('%subject% has been %role% until %date%', |
|---|
| 84 |
array('%subject%' => $subject, |
|---|
| 85 |
'%role%' => '<span>'.$role.'</span>', |
|---|
| 86 |
'%date%' => $end_date)); |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
if ($string != '') |
|---|
| 90 |
{ |
|---|
| 91 |
return content_tag('p', $string, 'class=relation'); |
|---|
| 92 |
} |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
function pagination_info($pager) |
|---|
| 102 |
{ |
|---|
| 103 |
sfLoader::loadHelpers('I18N'); |
|---|
| 104 |
$start = (($pager->getPage() - 1 )* $pager->getMaxPerPage()) + 1; |
|---|
| 105 |
$end = $start + count($pager->getResults()) - 1; |
|---|
| 106 |
return __('Showing results %1%-%2% out of %3%, page %4% on %5%', |
|---|
| 107 |
array('%1%' => $start, |
|---|
| 108 |
'%2%' => $end, |
|---|
| 109 |
'%3%' => $pager->getNbResults(), |
|---|
| 110 |
'%4%' => $pager->getPage(), |
|---|
| 111 |
'%5%' => $pager->getLastPage())); |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
function tags_string($tags_string, $separator = ',') |
|---|
| 122 |
{ |
|---|
| 123 |
sfLoader::loadHelpers('I18N'); |
|---|
| 124 |
$tags = explode(',', $tags_string); |
|---|
| 125 |
if (count($tags) < 2) |
|---|
| 126 |
{ |
|---|
| 127 |
return $tags_string; |
|---|
| 128 |
} |
|---|
| 129 |
$nb_tags = count($tags); |
|---|
| 130 |
$string = ''; |
|---|
| 131 |
for ($i = 0; $i < $nb_tags; $i++) |
|---|
| 132 |
{ |
|---|
| 133 |
$tag = $tags[$i]; |
|---|
| 134 |
switch ($nb_tags - $i) |
|---|
| 135 |
{ |
|---|
| 136 |
case 2: |
|---|
| 137 |
$string .= $tag.' '.__('and').' '; |
|---|
| 138 |
break; |
|---|
| 139 |
case 1; |
|---|
| 140 |
$string .= $tag; |
|---|
| 141 |
break; |
|---|
| 142 |
default: |
|---|
| 143 |
$string .= $tag.', '; |
|---|
| 144 |
break; |
|---|
| 145 |
} |
|---|
| 146 |
} |
|---|
| 147 |
return $string; |
|---|
| 148 |
} |
|---|