From: Alexandros Couloumbis Date: Mon, 9 Dec 2019 10:29:33 +0000 (+0200) Subject: add a json export script X-Git-Url: http://git.ozo.com/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=lifetype%2F.git add a json export script --- diff --git a/export.php b/export.php new file mode 100644 index 0000000..58de426 --- /dev/null +++ b/export.php @@ -0,0 +1,101 @@ +. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + +// Configuration values: make any changes here! +define('EXPORT_BLOG_ID', 1); + + +// NO CHANGES SHOULD BE NECESSARY PAST THIS POINT! +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if (!defined( "PLOG_CLASS_PATH" )) { + define( "PLOG_CLASS_PATH", dirname(__FILE__)."/"); +} + +include 'class/object/loader.class.php'; +include 'class/dao/articles.class.php'; + + +function FormatCategory($categoryObject) { + /* + * Format a single category's data for JSON export + */ + return $categoryObject->getName(); +} + + +function FormatComment($commentObject) { + /* + * Format a single comment's data for JSON export + */ + $comment = array(); + + $comment['id'] = $commentObject->getId(); + $comment['title'] = $commentObject->getTopic(); + $comment['name'] = $commentObject->getUserName(); + $comment['url'] = $commentObject->getUserUrl(); + $comment['email'] = $commentObject->getUserEmail(); + $comment['date'] = $commentObject->getDate(); + $comment['text'] = $commentObject->getText(); + + return $comment; +} + + +function FormatArticle($articleObject) { + /* + * Format a single article's data for JSON export + */ + $article = array(); + + $article['id'] = $articleObject->getId(); + $article['title'] = $articleObject->getTopic(); + $article['body'] = $articleObject->getText(); + $article['date'] = $articleObject->getDate(); + $article['categories'] = array_map('FormatCategory', $articleObject->getCategories()); + $article['comments'] = array_map('FormatComment', $articleObject->getComments()); + + return $article; +} + + +// Get a collection of all published blog posts +// (For ALL posts, you need to specify POST_STATUS_ALL) +$articlesObject = new Articles(); +$articles = array_map('FormatArticle', $articlesObject->getBlogArticles(EXPORT_BLOG_ID)); +echo json_encode($articles); + +?>