From e9903870bf7c89c1013a9502282a7b66b139b0e3 Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Thu, 1 Nov 2007 10:49:49 +0000 Subject: make text-shrinking function more general to be used elsewhere git-svn-id: file:///var/lib/svn/phpfspot/trunk@276 fa6a889d-dae6-447d-9e79-4ba9a3039384 --- phpfspot.class.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'phpfspot.class.php') diff --git a/phpfspot.class.php b/phpfspot.class.php index 723140f..a511648 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -226,15 +226,29 @@ class PHPFSPOT { public function getPhotoName($idx, $limit = 0) { if($details = $this->get_photo_details($idx)) { - $name = $details['name']; - if($limit != 0 && strlen($name) > $limit) { - $name = substr($name, 0, $limit-5) ."...". substr($name, -($limit-5)); - } + $name = $this->shrink_text($details['name'], $limit); return $name; } } // getPhotoName() + /** + * shrink text according provided limit + * + * If the length of the name exceeds $limit the + * text will be shortend and some content in between + * will be replaced with "..." + */ + private function shrink_text($text, $limit) + { + if($limit != 0 && strlen($text) > $limit) { + $text = substr($text, 0, $limit-5) ."...". substr($text, -($limit-5)); + } + + return $text; + + } // shrink_text(); + /** * translate f-spoth photo path * -- cgit v1.2.3-18-g5258