PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/tool/digest-intro.php

https://github.com/dannyakakong/Enzyme
PHP | 163 lines | 89 code | 47 blank | 27 comment | 40 complexity | 66fa926f784e0ddcc017bd5e60862019 MD5 | raw file
  1. <?php
  2. /*-------------------------------------------------------+
  3. | Enzyme
  4. | Copyright 2010-2011 Danny Allen <danny@enzyme-project.org>
  5. | http://www.enzyme-project.org/
  6. +--------------------------------------------------------+
  7. | This program is released as free software under the
  8. | Affero GPL license. You can redistribute it and/or
  9. | modify it under the terms of this license which you
  10. | can read by viewing the included agpl.txt or online
  11. | at www.gnu.org/licenses/agpl.html. Removal of this
  12. | copyright header is strictly prohibited without
  13. | written permission from the original author(s).
  14. +--------------------------------------------------------*/
  15. include($_SERVER['DOCUMENT_ROOT'] . '/autoload.php');
  16. // check authentication
  17. $user = new User();
  18. if (empty($user->auth)) {
  19. echo _('Must be logged in!');
  20. exit;
  21. }
  22. set_time_limit(3500);
  23. ob_start();
  24. // draw html page start
  25. echo Ui::drawHtmlPageStart(null, array('/css/includes/common.css'), array('/js/prototype.js'));
  26. // look in directory for files
  27. if ($_REQUEST['type'] == 'issue') {
  28. $issueType = 'issue';
  29. $author = 'dannya';
  30. $dirName = Config::getSetting('legacy', 'EXISTING_ISSUES');
  31. } else if ($_REQUEST['type'] == 'archive') {
  32. $issueType = 'archive';
  33. $author = 'dkite';
  34. $dirName = Config::getSetting('legacy', 'EXISTING_ARCHIVE');
  35. } else {
  36. echo _('Invalid import type (needs to be "issue" or "archive")');
  37. exit;
  38. }
  39. $target = 'introduction.txt';
  40. // get next valid ID (auto-increment doesn't work on our db server!)
  41. $id = Db::getNextId('digests');
  42. // get sorted dir structure for iterating
  43. $dirs = App::getDirs($dirName);
  44. // iterate
  45. foreach ($dirs as $dir) {
  46. // load file
  47. @$file = file($dir . '/' . $target);
  48. // iterate through lines, extracting elements
  49. $order = 0;
  50. $numLines = count($file);
  51. for ($i = 0; $i < $numLines; $i++) {
  52. $line = trim($file[$i]);
  53. if (empty($line)) {
  54. continue;
  55. }
  56. if ($line[0] == '[') {
  57. $section = trim($line, '][');
  58. if ($section == 'digest') {
  59. $digest['date'] = trim($file[++$i]);
  60. $digest['type'] = $issueType;
  61. $digest['version'] = 1;
  62. $digest['published'] = 1;
  63. } else if ($section == 'translation') {
  64. $digest['language'] = trim($file[++$i]);
  65. if ($digest['language'] == 'en') {
  66. $digest['language'] = 'en_US';
  67. }
  68. } else if ($section == 'synopsis') {
  69. $digest['synopsis'] = Enzyme::formatMsg(trim($file[++$i]));
  70. } else if (($section == 'message') || ($section == 'comment')) {
  71. // extract intro sections
  72. unset($tmp);
  73. $tmp['date'] = $digest['date'];
  74. $tmp['number'] = ++$order;
  75. $tmp['type'] = $section;
  76. $tmp['author'] = $author;
  77. $tmp['intro'] = Enzyme::formatMsg(trim($file[++$i]));
  78. if (($section == 'message')) {
  79. $tmp['body'] = Enzyme::formatMsg(trim($file[++$i]));
  80. }
  81. // insert into database
  82. Db::insert('digest_intro_sections', $tmp, true);
  83. } else if ($section == 'people_references') {
  84. $personOrder = 0;
  85. while (!empty($file[$i + 1]) && (trim($file[$i + 1]) != '')) {
  86. $person['date'] = $digest['date'];
  87. $person['number'] = ++$personOrder;
  88. $person['name'] = trim($file[++$i]);
  89. $person['account'] = trim($file[++$i]);
  90. Db::insert('digest_intro_people', $person, true);
  91. }
  92. } else if ($section == 'video_references') {
  93. $videoOrder = 0;
  94. while (!empty($file[$i + 1]) && (trim($file[$i + 1]) != '')) {
  95. $video['date'] = $digest['date'];
  96. $video['number'] = ++$videoOrder;
  97. $video['name'] = trim($file[++$i]);
  98. $video['file'] = trim($file[++$i]);
  99. $video['youtube'] = trim($file[++$i]);
  100. ++$i;
  101. // insert into database
  102. Db::insert('digest_intro_videos', $video, true);
  103. }
  104. }
  105. }
  106. }
  107. // insert into database
  108. $digest['id'] = ++$id;
  109. $digest['author'] = $author;
  110. Db::insert('digests', $digest, true);
  111. // report success
  112. Ui::displayMsg(sprintf(_('Processed %s'), $digest['date']), 'msg_skip');
  113. }
  114. // draw html page end
  115. echo Ui::drawHtmlPageEnd();
  116. ?>