/** * Regenerate the atom.feed file * */ static function GenFeed() { global $config, $addonFolderName, $dirPrefix; ob_start(); $atomFormat = 'Y-m-d\\TH:i:s\\Z'; $show_posts = SimpleBlogCommon::WhichPosts(0, SimpleBlogCommon::$data['feed_entries']); if (isset($_SERVER['HTTP_HOST'])) { $server = 'http://' . $_SERVER['HTTP_HOST']; } else { $server = 'http://' . $_SERVER['SERVER_NAME']; } $serverWithDir = $server . $dirPrefix; echo '<?xml version="1.0" encoding="utf-8"?>' . "\n"; echo '<feed xmlns="http://www.w3.org/2005/Atom">' . "\n"; echo '<title>' . $config['title'] . '</title>' . "\n"; echo '<link href="' . $serverWithDir . '/data/_addondata/' . str_replace(' ', '%20', $addonFolderName) . '/feed.atom" rel="self" />' . "\n"; echo '<link href="' . $server . common::GetUrl('Special_Blog') . '" />' . "\n"; echo '<id>urn:uuid:' . self::uuid($serverWithDir) . '</id>' . "\n"; echo '<updated>' . date($atomFormat, time()) . '</updated>' . "\n"; echo '<author><name>' . $config['title'] . '</name></author>' . "\n"; foreach ($show_posts as $post_index) { $post = SimpleBlogCommon::GetPostContent($post_index); if (!$post) { continue; } echo '<entry>' . "\n"; echo '<title>' . SimpleBlogCommon::Underscores($post['title']) . '</title>' . "\n"; echo '<link href="' . $server . SimpleBlogCommon::PostUrl($post_index) . '"></link>' . "\n"; echo '<id>urn:uuid:' . self::uuid($post_index) . '</id>' . "\n"; echo '<updated>' . date($atomFormat, $post['time']) . '</updated>' . "\n"; $content =& $post['content']; if (SimpleBlogCommon::$data['feed_abbrev'] > 0 && mb_strlen($content) > SimpleBlogCommon::$data['feed_abbrev']) { $content = mb_substr($content, 0, SimpleBlogCommon::$data['feed_abbrev']) . ' ... '; $label = gpOutput::SelectText('Read More'); $content .= '<a href="' . $server . SimpleBlogCommon::PostUrl($post_index, $label) . '">' . $label . '</a>'; } //old images $replacement = $server . '/'; $content = str_replace('src="/', 'src="' . $replacement, $content); //new images $content = str_replace('src="../', 'src="' . $serverWithDir, $content); //images without /index.php/ $content = str_replace('src="./', 'src="' . $serverWithDir, $content); //href SimpleBlogCommon::FixLinks($content, $server, 0); echo '<summary type="html"><![CDATA[' . $content . ']]></summary>' . "\n"; echo '</entry>' . "\n"; } echo '</feed>' . "\n"; $feed = ob_get_clean(); $feedFile = SimpleBlogCommon::$data_dir . '/feed.atom'; gpFiles::Save($feedFile, $feed); }
/** * Recursively turn relative links into absolute links * @static */ function FixLinks(&$content, $server, $offset) { //php4 strpos $temp = substr($content, $offset); $pos = strpos($temp, 'href="') + $offset; //$pos = strpos($content,'href="',$offset); if ($pos <= 0) { return; } $pos = $pos + 6; //php4 strpos //$pos2 = strpos($content,'"',$pos); $temp = substr($content, $pos); $pos2 = strpos($temp, '"') + $pos; if ($pos2 <= 0) { return; } //well formed link //php4 strpos //$check = strpos($content,'>',$pos); $temp = substr($content, $pos); $check = strpos($temp, '>') + $pos; if ($check !== false && $check < $pos2) { SimpleBlogCommon::FixLinks($content, $server, $pos2); return; } $title = substr($content, $pos, $pos2 - $pos); //internal link if (strpos($title, 'mailto:') !== false) { SimpleBlogCommon::FixLinks($content, $server, $pos2); return; } if (strpos($title, '://') !== false) { SimpleBlogCommon::FixLinks($content, $server, $pos2); return; } if (strpos($title, '/') === 0) { $replacement = $server . $title; } else { $replacement = $server . common::GetUrl($title); } $content = substr_replace($content, $replacement, $pos, $pos2 - $pos); SimpleBlogCommon::FixLinks($content, $server, $pos2); }