make text-shrinking function more general to be used elsewhere
authorAndreas Unterkircher <unki@netshadow.at>
Thu, 1 Nov 2007 10:49:49 +0000 (10:49 +0000)
committerAndreas Unterkircher <unki@netshadow.at>
Thu, 1 Nov 2007 10:49:49 +0000 (10:49 +0000)
git-svn-id: file:///var/lib/svn/phpfspot/trunk@276 fa6a889d-dae6-447d-9e79-4ba9a3039384

phpfspot.class.php

index 723140f0ef5ab4b5ee0e5b11e65fbc641812e074..a51164830fcff2de589a07bc6abd94c4cd973f9f 100644 (file)
@@ -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
     *