]> git.andy128k.dev Git - ipf.git/commitdiff
detect static methods in IPF::loadFunction
authorAndrey Kutejko <andy128k@gmail.com>
Fri, 17 May 2013 07:10:25 +0000 (10:10 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Fri, 17 May 2013 07:10:25 +0000 (10:10 +0300)
ipf.php
ipf/utils.php

diff --git a/ipf.php b/ipf.php
index 6dde361de573d5f1b29005f62234537d38542cd1..68a127086a81cee3cc510b53491ec191ed319f5d 100644 (file)
--- a/ipf.php
+++ b/ipf.php
@@ -139,6 +139,10 @@ final class IPF
     {
         if (function_exists($function))
             return;
+        if (preg_match('/^(\w+)::\w+$/', $function, $m)) {
+            IPF_Autoload($m[1]);
+            return;
+        }
         $elts = explode('_', $function);
         array_pop($elts);
         $file = strtolower(implode(DIRECTORY_SEPARATOR, $elts)).'.php';
index bda6deb591099dcf0ed690e2813bdcde09d1ffb6..30649a6fbee95671aa8dade16489b9128e12a2aa 100644 (file)
@@ -281,5 +281,56 @@ class IPF_Utils
             return strtolower(preg_replace('/[^A-Z^a-z^0-9^\/\_]+/', '-', $slug));
         return $slug;
     }
+
+    /**
+     * Word Limiter
+     *
+     * Limits a string to X number of words.
+     *
+     * @param  string
+     * @param  integer
+     * @param  string  the end character. Usually an ellipsis
+     * @return string
+     */
+    public static function limitWords($str, $limit=100, $end_char='&#8230;')
+    {
+        if (trim($str) == '')
+            return $str;
+        preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches);
+        if (strlen($str) == strlen($matches[0]))
+            $end_char = '';
+        return rtrim($matches[0]).$end_char;
+    }
+
+    /**
+     * Character Limiter
+     *
+     * Limits the string based on the character count.  Preserves complete words
+     * so the character count may not be exactly as specified.
+     *
+     * @param  string
+     * @param  integer
+     * @param  string  the end character. Usually an ellipsis
+     * @return string
+     */
+    function limitCharacters($str, $n=500, $end_char='&#8230;')
+    {
+        if (strlen($str) < $n)
+            return $str;
+
+        $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str));
+
+        if (strlen($str) <= $n)
+            return $str;
+
+        $out = "";
+        foreach (explode(' ', trim($str)) as $val) {
+            $out .= $val.' ';
+            if (strlen($out) >= $n) {
+                $out = trim($out);
+                return (strlen($out) == strlen($str)) ? $out : $out.$end_char;
+            }
+        }
+    }
 }