| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
* Weblog export function |
|---|
| 5 |
* @author Ben Werdmuller <ben@curverider.co.uk> |
|---|
| 6 |
*/ |
|---|
| 7 |
|
|---|
| 8 |
function export_pagesetup() { |
|---|
| 9 |
global $page_owner, $PAGE, $CFG; |
|---|
| 10 |
if (defined('context') && context == 'weblog') { |
|---|
| 11 |
if ($page_owner == $_SESSION['userid']) { |
|---|
| 12 |
$PAGE->menu_sub[]= array ( |
|---|
| 13 |
'name' => 'blog:export:html', |
|---|
| 14 |
'html' => "<a href=\"{$CFG->wwwroot}mod/export/blogashtml.php/export.html\">". __gettext("Download blog as HTML") ."</a>" |
|---|
| 15 |
); |
|---|
| 16 |
$PAGE->menu_sub[]= array ( |
|---|
| 17 |
'name' => 'blog:export:rss', |
|---|
| 18 |
'html' => "<a href=\"{$CFG->wwwroot}mod/export/blog.php/export.rss\">". __gettext("Download blog as RSS") ."</a>" |
|---|
| 19 |
); |
|---|
| 20 |
} |
|---|
| 21 |
} |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
function export_init() { |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
* Exports a weblog as RSS |
|---|
| 29 |
* |
|---|
| 30 |
* @param int $blog_id The ID of the blog to export |
|---|
| 31 |
* @return string The RSS feed |
|---|
| 32 |
*/ |
|---|
| 33 |
function export_blog_as_rss($blog_id = -1) { |
|---|
| 34 |
|
|---|
| 35 |
global $CFG; |
|---|
| 36 |
|
|---|
| 37 |
if ($blog_id < 0) { |
|---|
| 38 |
$blog_id = $_SESSION['id']; |
|---|
| 39 |
} |
|---|
| 40 |
$blog_id = (int) $blog_id; |
|---|
| 41 |
|
|---|
| 42 |
$name = user_info("name", $blog_id); |
|---|
| 43 |
$username = user_info("username", $blog_id); |
|---|
| 44 |
|
|---|
| 45 |
$rssweblog = __gettext("Weblog items"); |
|---|
| 46 |
$rssdescription = sprintf(__gettext("The weblog for %s, hosted on %s."),$name,$CFG->sitename); |
|---|
| 47 |
|
|---|
| 48 |
$output .= <<< END |
|---|
| 49 |
<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/'> |
|---|
| 50 |
<channel xml:base='{$CFG->wwwroot}'> |
|---|
| 51 |
<title><![CDATA[$name : $rssweblog]]></title> |
|---|
| 52 |
<description><![CDATA[$rssdescription]]></description> |
|---|
| 53 |
<link>{$CFG->wwwroot}{$username}/weblog/</link> |
|---|
| 54 |
END; |
|---|
| 55 |
|
|---|
| 56 |
$where = run("users:access_level_sql_where",$_SESSION['userid']); |
|---|
| 57 |
if ($posts = get_records_select('weblog_posts','('.$where.') AND weblog = '.$blog_id,null,'posted DESC','*')) { |
|---|
| 58 |
foreach($posts as $entry) { |
|---|
| 59 |
$title = (stripslashes($entry->title)); |
|---|
| 60 |
$link = url . $username . "/weblog/" . $entry->ident . ".html"; |
|---|
| 61 |
$body = (run("weblogs:text:process",stripslashes($entry->body))); |
|---|
| 62 |
$pubdate = gmdate("D, d M Y H:i:s T", $entry->posted); |
|---|
| 63 |
$keywordtags = ""; |
|---|
| 64 |
if ($keywords = get_records_select('tags','tagtype = ? AND ref = ?',array('weblog',$entry->ident))) { |
|---|
| 65 |
foreach($keywords as $keyword) { |
|---|
| 66 |
$keywordtags .= "\n\t\t<dc:subject><![CDATA[" . (stripslashes($keyword->tag)) . "]]></dc:subject>"; |
|---|
| 67 |
} |
|---|
| 68 |
} |
|---|
| 69 |
$output .= <<< END |
|---|
| 70 |
|
|---|
| 71 |
<item> |
|---|
| 72 |
<title><![CDATA[$title]]></title> |
|---|
| 73 |
<link>$link</link> |
|---|
| 74 |
<guid isPermaLink="true">$link</guid> |
|---|
| 75 |
<pubDate>$pubdate</pubDate>$keywordtags |
|---|
| 76 |
<description><![CDATA[$body]]></description> |
|---|
| 77 |
</item> |
|---|
| 78 |
|
|---|
| 79 |
END; |
|---|
| 80 |
} |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
$output .= <<< END |
|---|
| 86 |
|
|---|
| 87 |
</channel> |
|---|
| 88 |
</rss> |
|---|
| 89 |
END; |
|---|
| 90 |
return $output; |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
* Exports a blog as HTML |
|---|
| 95 |
* |
|---|
| 96 |
* @param int $blog_id The blog to export |
|---|
| 97 |
* @return string The HTML file |
|---|
| 98 |
*/ |
|---|
| 99 |
function export_blog_as_html($blog_id = -1) { |
|---|
| 100 |
|
|---|
| 101 |
global $CFG; |
|---|
| 102 |
|
|---|
| 103 |
if ($blog_id < 0) { |
|---|
| 104 |
$blog_id = $_SESSION['id']; |
|---|
| 105 |
} |
|---|
| 106 |
$blog_id = (int) $blog_id; |
|---|
| 107 |
|
|---|
| 108 |
$name = user_info("name", $blog_id); |
|---|
| 109 |
$username = user_info("username", $blog_id); |
|---|
| 110 |
|
|---|
| 111 |
$rssweblog = __gettext("Weblog items"); |
|---|
| 112 |
$rssdescription = sprintf(__gettext("The weblog for %s, hosted on %s."),$name,$CFG->sitename); |
|---|
| 113 |
|
|---|
| 114 |
$output .= <<< END |
|---|
| 115 |
<html> |
|---|
| 116 |
<head> |
|---|
| 117 |
<title>{$name}: {$rssweblog}</title> |
|---|
| 118 |
</head> |
|---|
| 119 |
<body> |
|---|
| 120 |
<h1>{$name}: {$rssweblog}</h1> |
|---|
| 121 |
<p><i>{$rssdescription}</i></p> |
|---|
| 122 |
<p> |
|---|
| 123 |
<a href="{$CFG->wwwroot}{$username}/weblog/">{$CFG->wwwroot}{$username}/weblog/</a> |
|---|
| 124 |
</p> |
|---|
| 125 |
END; |
|---|
| 126 |
|
|---|
| 127 |
$where = run("users:access_level_sql_where",$_SESSION['userid']); |
|---|
| 128 |
if ($posts = get_records_select('weblog_posts','('.$where.') AND weblog = '.$blog_id,null,'posted DESC','*')) { |
|---|
| 129 |
foreach($posts as $entry) { |
|---|
| 130 |
$title = (stripslashes($entry->title)); |
|---|
| 131 |
$link = url . $username . "/weblog/" . $entry->ident . ".html"; |
|---|
| 132 |
$body = (run("weblogs:text:process",stripslashes($entry->body))); |
|---|
| 133 |
$pubdate = gmdate("D, d M Y H:i:s T", $entry->posted); |
|---|
| 134 |
$keywordtags = ""; |
|---|
| 135 |
if ($keywords = get_records_select('tags','tagtype = ? AND ref = ?',array('weblog',$entry->ident))) { |
|---|
| 136 |
foreach($keywords as $keyword) { |
|---|
| 137 |
if (!empty($keywordtags)) |
|---|
| 138 |
$keywordtags .= ", "; |
|---|
| 139 |
$keywordtags .= stripslashes($keyword->tag); |
|---|
| 140 |
} |
|---|
| 141 |
} |
|---|
| 142 |
if (!empty($keywordtags)) { |
|---|
| 143 |
$keywordtags = "<p>Keywords: {$keywordtags}</p>"; |
|---|
| 144 |
} |
|---|
| 145 |
$output .= <<< END |
|---|
| 146 |
<div class="weblog-post"> |
|---|
| 147 |
<h2>{$title}</h2> |
|---|
| 148 |
<p>{$pubdate}</p> |
|---|
| 149 |
<p><i><a href="{$link}">{$link}</a></i></p> |
|---|
| 150 |
{$body} |
|---|
| 151 |
{$keywordtags} |
|---|
| 152 |
<p> </p> |
|---|
| 153 |
</div> |
|---|
| 154 |
END; |
|---|
| 155 |
} |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
$output .= <<< END |
|---|
| 161 |
|
|---|
| 162 |
</body> |
|---|
| 163 |
</html> |
|---|
| 164 |
|
|---|
| 165 |
END; |
|---|
| 166 |
return $output; |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
?> |
|---|