Example #1
0
 /**
  * Formats plain text as HTML, links will be detected, paragraphs will be inserted
  *
  * @param string $var The data to cleanup.
  * @return string
  */
 public static function cleanupPlainText($var)
 {
     $var = (string) $var;
     // detect links
     $var = \SpoonFilter::replaceURLsWithAnchors($var);
     // replace newlines
     $var = str_replace("\r", '', $var);
     $var = preg_replace('/(?<!.)(\\r\\n|\\r|\\n){3,}$/m', '', $var);
     // replace br's into p's
     $var = '<p>' . str_replace("\n", '</p><p>', $var) . '</p>';
     // cleanup
     $var = str_replace("\n", '', $var);
     $var = str_replace('<p></p>', '', $var);
     return $var;
 }
Example #2
0
 /**
  * Formats plain text as HTML, links will be detected, paragraphs will be inserted
  *    syntax: {$var|cleanupPlainText}
  *
  * @param string $var The text to cleanup.
  * @return string
  */
 public static function cleanupPlainText($var)
 {
     // redefine
     $var = (string) $var;
     // detect links
     $var = \SpoonFilter::replaceURLsWithAnchors($var, Model::get('fork.settings')->get('Core', 'seo_nofollow_in_comments', false));
     // replace newlines
     $var = str_replace("\r", '', $var);
     $var = preg_replace('/(?<!.)(\\r\\n|\\r|\\n){3,}$/m', '', $var);
     // replace br's into p's
     $var = '<p>' . str_replace("\n", '</p><p>', $var) . '</p>';
     // cleanup
     $var = str_replace("\n", '', $var);
     $var = str_replace('<p></p>', '', $var);
     // return
     return $var;
 }
 public function testReplaceURLsWithAnchors()
 {
     $tlds = array('ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'arpa', 'as', 'asia', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb', 'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'biz', 'bj', 'bm', 'bn', 'bo', 'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cat', 'cc', 'cd', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'com', 'coop', 'cr', 'cu', 'cv', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do', 'dz', 'ec', 'edu', 'ee', 'eg', 'er', 'es', 'et', 'eu', 'fi', 'fj', 'fk', 'fm', 'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg', 'gh', 'gi', 'gl', 'gm', 'gn', 'gov', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu', 'gw', 'gy', 'hk', 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'im', 'in', 'info', 'int', 'io', 'iq', 'ir', 'is', 'it', 'je', 'jm', 'jo', 'jobs', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp', 'kr', 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'local', 'lr', 'ls', 'lt', 'lu', 'lv', 'ly', 'ma', 'mc', 'md', 'me', 'mg', 'mh', 'mil', 'mk', 'ml', 'mm', 'mn', 'mo', 'mobi', 'mp', 'mq', 'mr', 'ms', 'mt', 'mu', 'museum', 'mv', 'mw', 'mx', 'my', 'mz', 'na', 'name', 'nc', 'ne', 'net', 'nf', 'ng', 'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', 'org', 'pa', 'pe', 'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'pro', 'ps', 'pt', 'pw', 'py', 'qa', 're', 'ro', 'rs', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl', 'sm', 'sn', 'so', 'sr', 'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tel', 'tf', 'tg', 'th', 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'travel', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'ye', 'yt', 'yu', 'za', 'zm', 'zw');
     foreach ($tlds as $tld) {
         $this->assertEquals('verkeerde link: www.link.' . $tld . 'l', SpoonFilter::replaceURLsWithAnchors('verkeerde link: www.link.' . $tld . 'l', false));
         $this->assertEquals('zonder http: <a href="http://www.link.' . $tld . '">www.link.' . $tld . '</a>', SpoonFilter::replaceURLsWithAnchors('zonder http: www.link.' . $tld, false));
         $this->assertEquals('met http: <a href="http://www.link.' . $tld . '">http://www.link.' . $tld . '</a>', SpoonFilter::replaceURLsWithAnchors('met http: http://www.link.' . $tld, false));
         // port
         $this->assertEquals('verkeerde link: www.link.' . $tld . 'l:80', SpoonFilter::replaceURLsWithAnchors('verkeerde link: www.link.' . $tld . 'l:80', false));
         $this->assertEquals('zonder http: <a href="http://www.link.' . $tld . ':80">www.link.' . $tld . ':80</a>', SpoonFilter::replaceURLsWithAnchors('zonder http: www.link.' . $tld . ':80', false));
         $this->assertEquals('met http: <a href="http://www.link.' . $tld . ':80">http://www.link.' . $tld . ':80</a>', SpoonFilter::replaceURLsWithAnchors('met http: http://www.link.' . $tld . ':80', false));
         // querystring
         $this->assertEquals('verkeerde link: www.link.' . $tld . 'l?m=12&b=0%20d', SpoonFilter::replaceURLsWithAnchors('verkeerde link: www.link.' . $tld . 'l?m=12&b=0%20d', false));
         $this->assertEquals('zonder http: <a href="http://www.link.' . $tld . '?m=12&b=0%20d">www.link.' . $tld . '?m=12&b=0%20d</a>', SpoonFilter::replaceURLsWithAnchors('zonder http: www.link.' . $tld . '?m=12&b=0%20d', false));
         $this->assertEquals('met http: <a href="http://www.link.' . $tld . '?m=12&b=0%20d">http://www.link.' . $tld . '?m=12&b=0%20d</a>', SpoonFilter::replaceURLsWithAnchors('met http: http://www.link.' . $tld . '?m=12&b=0%20d', false));
         // folder
         $this->assertEquals('verkeerde link: www.link.' . $tld . 'l/mekker', SpoonFilter::replaceURLsWithAnchors('verkeerde link: www.link.' . $tld . 'l/mekker', false));
         $this->assertEquals('zonder http: <a href="http://www.link.' . $tld . '/mekker">www.link.' . $tld . '/mekker</a>', SpoonFilter::replaceURLsWithAnchors('zonder http: www.link.' . $tld . '/mekker', false));
         $this->assertEquals('met http: <a href="http://www.link.' . $tld . '/mekker">http://www.link.' . $tld . '/mekker</a>', SpoonFilter::replaceURLsWithAnchors('met http: http://www.link.' . $tld . '/mekker', false));
     }
     // no follow
     foreach ($tlds as $tld) {
         $this->assertEquals('verkeerde link: www.link.' . $tld . 'l', SpoonFilter::replaceURLsWithAnchors('verkeerde link: www.link.' . $tld . 'l'));
         $this->assertEquals('zonder http: <a rel="nofollow" href="http://www.link.' . $tld . '">www.link.' . $tld . '</a>', SpoonFilter::replaceURLsWithAnchors('zonder http: www.link.' . $tld));
         $this->assertEquals('met http: <a rel="nofollow" href="http://www.link.' . $tld . '">http://www.link.' . $tld . '</a>', SpoonFilter::replaceURLsWithAnchors('met http: http://www.link.' . $tld));
         // port
         $this->assertEquals('verkeerde link: www.link.' . $tld . 'l:80', SpoonFilter::replaceURLsWithAnchors('verkeerde link: www.link.' . $tld . 'l:80'));
         $this->assertEquals('zonder http: <a rel="nofollow" href="http://www.link.' . $tld . ':80">www.link.' . $tld . ':80</a>', SpoonFilter::replaceURLsWithAnchors('zonder http: www.link.' . $tld . ':80'));
         $this->assertEquals('met http: <a rel="nofollow" href="http://www.link.' . $tld . ':80">http://www.link.' . $tld . ':80</a>', SpoonFilter::replaceURLsWithAnchors('met http: http://www.link.' . $tld . ':80'));
         // querystring
         $this->assertEquals('verkeerde link: www.link.' . $tld . 'l?m=12&b=0%20d', SpoonFilter::replaceURLsWithAnchors('verkeerde link: www.link.' . $tld . 'l?m=12&b=0%20d'));
         $this->assertEquals('zonder http: <a rel="nofollow" href="http://www.link.' . $tld . '?m=12&b=0%20d">www.link.' . $tld . '?m=12&b=0%20d</a>', SpoonFilter::replaceURLsWithAnchors('zonder http: www.link.' . $tld . '?m=12&b=0%20d'));
         $this->assertEquals('met http: <a rel="nofollow" href="http://www.link.' . $tld . '?m=12&b=0%20d">http://www.link.' . $tld . '?m=12&b=0%20d</a>', SpoonFilter::replaceURLsWithAnchors('met http: http://www.link.' . $tld . '?m=12&b=0%20d'));
         // folder
         $this->assertEquals('verkeerde link: www.link.' . $tld . 'l/mekker', SpoonFilter::replaceURLsWithAnchors('verkeerde link: www.link.' . $tld . 'l/mekker'));
         $this->assertEquals('zonder http: <a rel="nofollow" href="http://www.link.' . $tld . '/mekker">www.link.' . $tld . '/mekker</a>', SpoonFilter::replaceURLsWithAnchors('zonder http: www.link.' . $tld . '/mekker'));
         $this->assertEquals('met http: <a rel="nofollow" href="http://www.link.' . $tld . '/mekker">http://www.link.' . $tld . '/mekker</a>', SpoonFilter::replaceURLsWithAnchors('met http: http://www.link.' . $tld . '/mekker'));
     }
 }
Example #4
0
 /**
  * Converts links to HTML links (only to be used with cleartext).
  *
  * @return	string			The text containing the parsed html links.
  * @param	string $text	The cleartext that may contain urls that need to be transformed to html links.
  */
 public static function createHTMLLinks($text)
 {
     return SpoonFilter::replaceURLsWithAnchors($text, false);
 }