Пример #1
0
 /**
  * Recursively turn relative links into absolute links
  * @static
  */
 function FixLinks(&$content, $server, $offset)
 {
     $pos = SimpleBlogCommon::strpos($content, 'href="', $offset);
     if ($pos <= 0) {
         return;
     }
     $pos = $pos + 6;
     $pos2 = SimpleBlogCommon::strpos($content, '"', $pos);
     if ($pos2 <= 0) {
         return;
     }
     //well formed link
     $check = SimpleBlogCommon::strpos($content, '>', $pos);
     if ($check !== false && $check < $pos2) {
         SimpleBlogCommon::FixLinks($content, $server, $pos2);
         return;
     }
     $title = SimpleBlogCommon::substr($content, $pos, $pos2 - $pos);
     //internal link
     if (SimpleBlogCommon::strpos($title, 'mailto:') !== false) {
         SimpleBlogCommon::FixLinks($content, $server, $pos2);
         return;
     }
     if (SimpleBlogCommon::strpos($title, '://') !== false) {
         SimpleBlogCommon::FixLinks($content, $server, $pos2);
         return;
     }
     if (SimpleBlogCommon::strpos($title, '/') === 0) {
         $replacement = $server . $title;
     } else {
         $replacement = $server . common::GetUrl($title);
     }
     $content = SimpleBlogCommon::substr_replace($content, $replacement, $pos, $pos2 - $pos);
     SimpleBlogCommon::FixLinks($content, $server, $pos2);
 }