PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/bin/blog/twoday-to-bxb.php

https://github.com/chregu/fluxcms
PHP | 87 lines | 47 code | 23 blank | 17 comment | 4 complexity | 3ec00095c30de07019c887ab4784e8c7 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. The most simple twoday imported imaginable. It works like this:
  4. Log in to your twoday.net account and do a full export using the default template,
  5. so you'll get a file that's called like 2006-05-03-export-full-txt.txt. Upload this
  6. file to your Flux CMS server, adjust the variables right below and run it.
  7. Note that the importer doesn't handle comments, and it ignores categories as well.
  8. Timestamps aren't fully parsed, we use but the date. Adding those features is trivial,
  9. but I didn't need them.
  10. */
  11. # CONFIGURATION
  12. $exportFile = './2006-05-03-export-full-txt.txt';
  13. $dsn = 'mysql://user:password@localhost/database';
  14. $tablePrefix = 'fluxcms_';
  15. $idOffset = 1;
  16. $categoryId = 7;
  17. ##################################################################
  18. require_once('DB.php');
  19. $db = DB::connect($dsn);
  20. if (DB::isError($db)) {
  21. die($db->getMessage());
  22. }
  23. preg_match_all("#--------\nTITLE:([^\n]+)\n.+\nDATE: (.+)\n.*AUTHOR: (.+)\n.*\n-----\nBODY:\n(.*)\n-----\n#Usi", "--------\n" .file_get_contents($exportFile) , $matches);
  24. foreach ($matches[1] as $id => $title){
  25. $post = array('id' => $id + $idOffset);
  26. // title
  27. $title = html_entity_decode(trim($title));
  28. $post['post_title'] = $title;
  29. // uri
  30. $post['post_uri'] = makeUri($post['post_title']);
  31. // date - ignoring time, too lazy today
  32. preg_match('#(\d\d)/(\d\d)/(\d\d\d\d)#', $matches[2][$id], $parts);
  33. $post['post_date'] = $parts[3].'-'.$parts[1].'-'.$parts[2];
  34. // author
  35. $post['post_author'] = trim($matches[3][$id]);
  36. // content
  37. $post['post_content'] = tidy_repair_string($matches[4][$id], array('output-xhtml' => true, 'numeric-entities' => true, 'show-body-only' => true,));
  38. $in = $db->autoexecute($tablePrefix . 'blogposts', $post, DB_AUTOQUERY_INSERT);
  39. if ($in != DB_OK) {
  40. die("\n*".$in->getDebugInfo()."*\n");
  41. }
  42. else {
  43. echo $post['post_title'] . " -> ok ..\n";
  44. }
  45. $db->autoexecute($tablePrefix . 'blogposts2categories' , array('id' => $post['id'], 'blogposts_id' => $post['id'], 'blogcategories_id' => $categoryId), DB_AUTOQUERY_INSERT);
  46. }
  47. function makeUri($title) {
  48. $newValue= strtolower(utf8_encode(preg_replace("/[-;: \.!,?+'$£\"*ç%&\/\(\)=]/","-",$title)));
  49. $newValue= preg_replace("/-{2,}/","-",$newValue);
  50. $newValue= preg_replace("/[öÖ]/u","oe",$newValue);
  51. $newValue= preg_replace("/[üÜ]/u","ue",$newValue);
  52. $newValue= preg_replace("/[äÄ]/u","ae",$newValue);
  53. $newValue= preg_replace("/[éè]/u","e",$newValue);
  54. $newValue= preg_replace("/[ï]/u","i",$newValue);
  55. $newValue= preg_replace("/[ñ]/u","n",$newValue);
  56. $newValue= preg_replace("/[Ã ]/u","a",$newValue);
  57. //numbers at the end are nasty for bxcms
  58. $newValue= preg_replace("/—+$/","",$newValue);
  59. $newValue= preg_replace("/^-/","",$newValue);
  60. return $newValue;
  61. }