BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rerender_gallery.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. #declare(strict_types=1);
  3. /**
  4. * This page creates previews of all supported stylesheets
  5. * SERVER_ROOT . '/' . STATIC_SERVER . 'styles/preview' must exist and be writable
  6. * Dependencies are PhantomJS (http://phantomjs.org/) and
  7. * ImageMagick (http://www.imagemagick.org/script/index.php)
  8. */
  9. View::show_header('Rerender stylesheet gallery images');
  10. $DB->prepared_query('
  11. SELECT
  12. ID,
  13. LOWER(REPLACE(Name," ","_")) AS Name,
  14. Name AS ProperName
  15. FROM stylesheets');
  16. $Styles = $DB->to_array('ID', MYSQLI_BOTH);
  17. $ImagePath = SERVER_ROOT . '/' . STATIC_SERVER . 'styles/preview';
  18. ?>
  19. <div>
  20. <h2>Rerender stylesheet gallery images</h2>
  21. <div class="sidebar">
  22. <div class="box box_info">
  23. <div class="head colhead_dark">Rendering parameters</div>
  24. <ul class="stats nobullet">
  25. <li>Server root: <?= var_dump(SERVER_ROOT); ?>
  26. </li>
  27. <li>Static server: <?= var_dump(STATIC_SERVER); ?>
  28. </li>
  29. <li>Whoami: <?php echo(shell_exec('whoami')); ?>
  30. </li>
  31. <li>Path: <?php echo dirname(__FILE__); ?>
  32. </li>
  33. <li>Phantomjs ver: <?php echo(shell_exec('/usr/bin/phantomjs -v')); ?>
  34. </li>
  35. </ul>
  36. </div>
  37. </div>
  38. <div class="main_column">
  39. <div class="box">
  40. <div class="head">About rendering</div>
  41. <div class="pad">
  42. <p>You are now rendering stylesheet gallery images.</p>
  43. <p>The used parameters can be seen on the right, returned statuses are displayed below.</p>
  44. </div>
  45. </div>
  46. <div class="box">
  47. <div class="head">Rendering status</div>
  48. <div class="pad">
  49. <?php
  50. //set_time_limit(0);
  51. foreach ($Styles as $Style) {
  52. ?>
  53. <div class="box">
  54. <h6><?= $Style['Name'] ?>
  55. </h6>
  56. <p>Build preview:
  57. <?php
  58. $CmdLine = '/usr/bin/phantomjs "' . dirname(__FILE__) . '/render_build_preview.js" "' . SERVER_ROOT . '" "' . STATIC_SERVER . '" "' . $Style['Name'] . '" "' . dirname(__FILE__) . '"';
  59. $BuildResult = json_decode(shell_exec(escapeshellcmd($CmdLine)), true);
  60. switch ($BuildResult['status']) {
  61. case 0:
  62. echo 'Success.';
  63. break;
  64. case -1:
  65. echo 'Err -1: Incorrect paths, are they passed correctly?';
  66. break;
  67. case -2:
  68. echo 'Err -2: Rendering base does not exist. Who broke things?';
  69. break;
  70. case -3:
  71. echo 'Err -3: No permission to write to preview folder.';
  72. break;
  73. case -4:
  74. echo 'Err -4: Failed to store specific preview file.';
  75. break;
  76. default:
  77. echo 'Err: Unknown error returned';
  78. } ?>
  79. </p>
  80. <?php
  81. //If build was successful, snap a preview.
  82. if ($BuildResult['status'] === 0) {
  83. ?>
  84. <p>Snap preview:
  85. <?php
  86. $CmdLine = '/usr/bin/phantomjs "' . dirname(__FILE__) . '/render_snap_preview.js" "' . SERVER_ROOT . '" "' . STATIC_SERVER . '" "' . $Style['Name'] . '" "' . dirname(__FILE__) . '"';
  87. $SnapResult = json_decode(shell_exec(escapeshellcmd($CmdLine)), true);
  88. switch ($SnapResult['status']) {
  89. case 0:
  90. echo 'Success.';
  91. $CmdLine = '/usr/bin/convert "' . $ImagePath . '/full_' . $Style['Name'] . '.png" -filter Box -resize 40% -quality 94 "' . $ImagePath . '/thumb_' . $Style['Name'] . '.png"';
  92. $ResizeResult = shell_exec(escapeshellcmd($CmdLine));
  93. if ($ResizeResult !== null) {
  94. echo ' But failed to resize image';
  95. }
  96. break;
  97. case -1:
  98. echo 'Err -1: Incorrect paths. Are they passed correctly? Do all folders exist?';
  99. break;
  100. case -2:
  101. echo 'Err -2: Preview file does not exist; running things in the wrong order perhaps?';
  102. break;
  103. case -3:
  104. echo 'Err -3: Preview is empty; did it get created properly?';
  105. break;
  106. case -4:
  107. echo 'Err -4: No permission to write to preview folder.';
  108. break;
  109. case -5:
  110. echo 'Err -5: Failed to store full image.';
  111. break;
  112. case -6:
  113. echo 'Err -6: Cannot find temp file to remove; are the paths correct?';
  114. break;
  115. default:
  116. echo 'Err: Unknown error returned.';
  117. } ?>
  118. </p>
  119. <?php
  120. } ?>
  121. </div>
  122. <?php
  123. } ?>
  124. </div>
  125. </div>
  126. </div>
  127. </div>
  128. <?php
  129. View::show_footer();