/standard/tags/release-0.9.0/scripts/manual/docbook_to_wiki/convert_incubator.php

https://github.com/bhaumik25/zend-framework · PHP · 174 lines · 129 code · 45 blank · 0 comment · 8 complexity · a7e5a4a368d97844237490fef8559314 MD5 · raw file

  1. <?php
  2. error_reporting(E_ALL);
  3. require_once 'configuration.php';
  4. $language = $argv[1];
  5. $thisPath = '/home/virtual/andries.zfdev.com/home/andries/scripts/manual/';
  6. $manualPath = '/home/virtual/andries.zfdev.com/home/andries/scripts/trunk/documentation/manual/' . $language . '/';
  7. $manualIncPath = '/home/virtual/andries.zfdev.com/home/andries/scripts/trunk/incubator/documentation/manual/' . $language . '/';
  8. $confluenceWsdl = 'http://framework.zend.com/wiki/rpc/soap-axis/confluenceservice-v1?wsdl';
  9. $confluenceSpace = 'ZFDOC';
  10. require_once $thisPath . 'functions.php';
  11. $file = @file_get_contents($manualPath . 'manual.xml');
  12. $file = preg_replace_callback('/(&module_specs.)(.+)(;)/', 'processChapters', $file);
  13. $sxml = @simplexml_load_string($file);
  14. $soap = new SoapClient($confluenceWsdl);
  15. $ver = 0.1;
  16. $wikiPages = array();
  17. $oldwikiPages = array();
  18. $chapters = array();
  19. $incubatorChapters = array();
  20. $soap = new SoapClient($confluenceWsdl);
  21. $ver = 0.1;
  22. $chapters = array();
  23. $incubatorChapters = array();
  24. if ($language == 'en') {
  25. $incubatorFile = file_get_contents($manualIncPath . 'manual.xml');
  26. $incubatorFile = preg_replace('/(<!--.*-->)/isU', '', $incubatorFile);
  27. $incubatorFile = preg_replace_callback('/(&module_specs.)(.+)(;)/', 'processIncubatorChapters', $incubatorFile);
  28. $isxml = @simplexml_load_string($incubatorFile);
  29. foreach ($isxml->chapter as $key => $chapter) {
  30. array_push($incubatorChapters, $chapter);
  31. }
  32. }
  33. $token = $soap->login($confluenceUser, $confluencePass);
  34. $currentPages = $soap->getPages($token, $confluenceSpace);
  35. foreach ($currentPages as $key => $page) {
  36. array_push($oldwikiPages, $page->title);
  37. }
  38. if (count($incubatorChapters)) {
  39. $chapters = array_merge($chapters, $incubatorChapters);
  40. }
  41. $homePage = $soap->getPage($token, $confluenceSpace, 'Home');
  42. $autoId = 0;
  43. foreach ($chapters as $key => $chapter) {
  44. $autoId++;
  45. $filename = $chapter['id'];
  46. echo $autoId . '. ' . $chapter->title . "\n";
  47. $mytmp = $chapter->sect1[0]->asXML();
  48. $mytmp = cleanup($mytmp);
  49. $xml = new DOMDocument;
  50. $xsl = new DOMDocument();
  51. $xml->loadXML($mytmp);
  52. $xsl->load($thisPath . 'xsl/wiki.xsl');
  53. $proc = new XSLTProcessor;
  54. $proc->importStyleSheet($xsl);
  55. $temp = html_entity_decode($proc->transformToXML($xml));
  56. $temp = preg_replace('/^(\\s*)(\\|\\|[^\\r\\n]+?)(\\s+)(\\|[^\\|]+)/', "\\2||\r\n\\4", $temp);
  57. $temp = preg_replace('/^(\\s*)\\|([^|]+.+?)(\\s*)$/m', '|\\2|', $temp);
  58. $title = $autoId . '. ' . (string)$chapter->title;
  59. array_push($wikiPages, $title);
  60. try {
  61. $page = $soap->getPage($token, $confluenceSpace, $title);
  62. $page->version = $page->version + 0.1;
  63. $page->title = $chapter->title;
  64. $page->content = $temp;
  65. } catch (Exception $e) {
  66. $page = new stdClass;
  67. $page->id = false;
  68. $page->permissions = false;
  69. $page->parentId = false;
  70. $page->current = false;
  71. $page->homePage = false;
  72. $page->version = $ver;
  73. $page->space = $confluenceSpace;
  74. $page->title = $title;
  75. $page->content = $temp;
  76. $page->parentId = $homePage->id;
  77. }
  78. $soap->storePage($token, $page);
  79. $parentPage = $soap->getPage($token, $confluenceSpace, $title);
  80. for ($i = 1; $i < count($chapter->sect1); $i++) {
  81. $name = $chapter->sect1[$i]['id'];
  82. $parent = explode('.', $name);
  83. array_pop($parent);
  84. $parent = implode('.', $parent);
  85. $filename = $chapter->sect1[$i]->title;
  86. $mytmp = $chapter->sect1[$i]->asXML();
  87. $mytmp = cleanup($mytmp);
  88. $xml = new DOMDocument;
  89. $xsl = new DOMDocument();
  90. $xml->loadXML($mytmp);
  91. $xsl->load($thisPath . 'xsl/wiki.xsl');
  92. $proc = new XSLTProcessor;
  93. $proc->importStyleSheet($xsl);
  94. $temp = html_entity_decode($proc->transformToXML($xml));
  95. $temp = preg_replace('/^(\\s*)(\\|\\|[^\\r\\n]+?)(\\s+)(\\|[^\\|]+)/', "\\2||\r\n\\4", $temp);
  96. $temp = preg_replace('/^(\\s*)\\|([^|]+.+?)(\\s*)$/m', '|\\2|', $temp);
  97. $title = $autoId . '.' . $i . '. ' . $chapter->sect1[$i]->title;
  98. $title = str_replace('::', ' - ', $title);
  99. $title = str_replace(':', ' ', $title);
  100. array_push($wikiPages, $title);
  101. try {
  102. $page = $soap->getPage($token, $confluenceSpace, $title);
  103. $page->version = $page->version + 0.1;
  104. $page->title = $title;
  105. $page->content = $temp;
  106. } catch (Exception $e) {
  107. $page = new stdClass;
  108. $page->id = false;
  109. $page->permissions = false;
  110. $page->parentId = false;
  111. $page->current = false;
  112. $page->homePage = false;
  113. $page->version = false;
  114. $page->space = $confluenceSpace;
  115. $page->title = $title;
  116. $page->content = $temp;
  117. $page->parentId = $parentPage->id;
  118. }
  119. $soap->storePage($token, $page);
  120. }
  121. }
  122. $diff = array_diff($oldwikiPages, $wikiPages);
  123. foreach ($diff as $key => $pagename) {
  124. if ($pagename != 'Home' && $pagename != 'manual-template') {
  125. echo 'Removing ' . $pagename . "\n";
  126. $page = $soap->getPage($token, $confluenceSpace, $pagename);
  127. $soap->removePage($token, $page->id);
  128. }
  129. }