';
$lines[] = ' '.$post->getCreatedAt().'';
foreach ($post->getsfSimpleBlogTags() as $tag)
{
$lines[] = ' '.$tag->getTag().'';
}
$lines[] = '
'.$post->getTitle().'';
$lines[] = ' '._blog_export_clean_content($post->getContent()).'';
foreach ($post->getsfSimpleBlogComments() as $comment)
{
$lines[] = ' ';
$lines[] = ' '.$comment->getAuthorName().'';
$lines[] = ' '.$comment->getAuthorEmail().'';
$lines[] = ' '.$comment->getAuthorUrl().'';
$lines[] = ' '.$comment->getCreatedAt().'';
$lines[] = ' '._blog_export_clean_content($comment->getContent()).'';
$lines[] = ' '.$comment->getIsModerated().'';
$lines[] = ' ';
}
$lines[] = '';
}
$handle = fopen("simple_blog_dump.xml", "w");
foreach($lines as $line)
{
fwrite($handle, $line."\n");
}
fclose($handle);
}
function _blog_export_get_connection($app, $env)
{
// define constants
define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
define('SF_APP', $app);
define('SF_ENVIRONMENT', $env);
define('SF_DEBUG', false);
require_once SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php';
$connection = sfContext::getInstance()->getDatabaseConnection('propel');
return $connection;
}
function _blog_export_clean_content($string)
{
// check if the string contains html
if (strlen($string) != strlen(strip_tags($string)))
{
// it does, remove newlines as the wordpress importer will automatically convert them (again) to tags
$string = str_replace("\r\n",'',$string);
$string = str_replace("\n",'',$string);
$string = str_replace("\r",'',$string);
}
// Note: I'm not removing newlines from posts that *don't* contain html since we want wordpress to add
tags in that case
return $string;
}