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.

torrent_form.class.php 33KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. <?php
  2. #declare(strict_types=1);
  3. // This class is used in upload.php to display the upload form, and the edit
  4. // section of torrents.php to display a shortened version of the same form
  5. class TorrentForm
  6. {
  7. public $UploadForm = '';
  8. public $Categories = [];
  9. /**
  10. * This kind of stuff will eventually go away.
  11. * The goal is to loop through multidimensional $ENV objects,
  12. * recursively copying parts to arrays in place as needed.
  13. */
  14. # Formats
  15. # See classes/config.php
  16. public $SeqFormats = [];
  17. public $ProtFormats = [];
  18. public $GraphXmlFormats = [];
  19. public $GraphTxtFormats = [];
  20. public $ImgFormats = [];
  21. public $MapVectorFormats = [];
  22. public $MapRasterFormats = [];
  23. public $BinDocFormats = [];
  24. public $CpuGenFormats = [];
  25. public $PlainFormats = [];
  26. public $Resolutions = [];
  27. # Gazelle
  28. public $NewTorrent = false;
  29. public $Torrent = [];
  30. public $Error = false;
  31. public $TorrentID = false;
  32. public $Disabled = '';
  33. public $DisabledFlag = false;
  34. public function __construct($Torrent = false, $Error = false, $NewTorrent = true)
  35. {
  36. # See classes/config.php
  37. global $UploadForm, $Categories, $TorrentID, $SeqFormats, $ProtFormats, $GraphXmlFormats, $GraphTxtFormats, $ImgFormats, $MapVectorFormats, $MapRasterFormats, $BinDocFormats, $CpuGenFormats, $PlainFormats, $Resolutions;
  38. #global $UploadForm, $Categories, $TorrentID, $SeqPlatforms, $GraphPlatforms, $ImgPlatforms, $DocPlatforms, $RawPlatforms, $SeqFormats, $ProtFormats, $GraphXmlFormats, $GraphTxtFormats, $ImgFormats, $MapVectorFormats, $MapRasterFormats, $BinDocFormats, $CpuGenFormats, $PlainFormats, $Codecs, $Archives, $Resolutions;
  39. #global $UploadForm, $Categories, $Formats, $Bitrates, $Media, $MediaManga, $TorrentID, $Containers, $ContainersGames, $Codecs, $Resolutions, $Platform, $Archives, $ArchivesManga;
  40. # Gazelle
  41. $this->NewTorrent = $NewTorrent;
  42. $this->Torrent = $Torrent;
  43. $this->Error = $Error;
  44. $this->UploadForm = $UploadForm;
  45. $this->Categories = $Categories;
  46. $this->TorrentID = $TorrentID;
  47. # Formats
  48. # See classes/config.php
  49. $this->SeqFormats = $SeqFormats;
  50. $this->ProtFormats = $ProtFormats;
  51. $this->GraphXmlFormats = $GraphXmlFormats;
  52. $this->GraphTxtFormats = $GraphTxtFormats;
  53. $this->ImgFormats = $ImgFormats;
  54. $this->MapVectorFormats = $MapVectorFormats;
  55. $this->MapRasterFormats = $MapRasterFormats;
  56. $this->BinDocFormats = $BinDocFormats;
  57. $this->CpuGenFormats = $CpuGenFormats;
  58. $this->PlainFormats = $PlainFormats;
  59. $this->Resolutions = $Resolutions;
  60. # Quick constructor test
  61. if ($this->Torrent && $this->Torrent['GroupID']) {
  62. $this->Disabled = ' readonly="readonly"';
  63. $this->DisabledFlag = true;
  64. }
  65. }
  66. /**
  67. * ====================
  68. * = Twig based class =
  69. * ====================
  70. */
  71. /**
  72. * render
  73. *
  74. * TorrentForm Twig wrapper.
  75. * Hopefully more pleasant.
  76. */
  77. public function render()
  78. {
  79. $ENV = ENV::go();
  80. $Twig = Twig::go();
  81. /**
  82. * Upload notice
  83. */
  84. if ($this->NewTorrent) {
  85. echo $Twig->render('torrent_form/notice.html');
  86. }
  87. /**
  88. * Announce and source
  89. */
  90. if ($this->NewTorrent) {
  91. $Announces = ANNOUNCE_URLS[0];
  92. #$Announces = call_user_func_array('array_merge', ANNOUNCE_URLS);
  93. $TorrentPass = G::$LoggedUser['torrent_pass'];
  94. $TorrentSource = Users::get_upload_sources()[0];
  95. echo $Twig->render(
  96. 'torrent_form/announce_source.html',
  97. [
  98. 'announces' => $Announces,
  99. 'torrent_pass' => $TorrentPass,
  100. 'torrent_source' => $TorrentSource,
  101. ]
  102. );
  103. }
  104. /**
  105. * Errors
  106. * (Twig unjustified)
  107. */
  108. if ($this->Error) {
  109. echo <<<HTML
  110. <aside class="upload_error">
  111. <p>$this->Error</p>
  112. </aside>
  113. HTML;
  114. }
  115. /**
  116. * head
  117. * IMPORTANT!
  118. */
  119. echo $this->head();
  120. /**
  121. * upload_form
  122. * Where the fields are.
  123. */
  124. echo $this->upload_form();
  125. /**
  126. * foot
  127. */
  128. echo $this->foot();
  129. } # End render()
  130. /**
  131. * head
  132. *
  133. * Everything up to the main form tag open:
  134. * <div id="dynamic_form">
  135. * Kept as an HTML function because it's simpler.
  136. */
  137. private function head()
  138. {
  139. $ENV = ENV::go();
  140. G::$DB->query(
  141. "
  142. SELECT
  143. COUNT(`ID`)
  144. FROM
  145. `torrents`
  146. WHERE
  147. `UserID` = ".G::$LoggedUser['ID']
  148. );
  149. list($Uploads) = G::$DB->next_record();
  150. # Torrent form hidden values
  151. $AuthKey = G::$LoggedUser['AuthKey'];
  152. $HTML = <<<HTML
  153. <form class="create_form box pad" name="torrent" action="" enctype="multipart/form-data" method="post"
  154. onsubmit="$('#post').raw().disabled = 'disabled';">
  155. <input type="hidden" name="submit" value="true" />
  156. <input type="hidden" name="auth" value="$AuthKey" />
  157. HTML;
  158. if (!$this->NewTorrent) {
  159. # Edit form hidden fields
  160. $TorrentID = display_str($this->TorrentID);
  161. $CategoryID = display_str($this->Torrent['CategoryID'] - 1);
  162. $HTML .= <<<HTML
  163. <input type="hidden" name="action" value="takeedit" />
  164. <input type="hidden" name="torrentid" value="$TorrentID" />
  165. <input type="hidden" name="type" value="$CategoryID" />
  166. HTML;
  167. } # fi !NewTorrent
  168. else {
  169. # Torrent upload hidden fields
  170. if ($this->Torrent && $this->Torrent['GroupID']) {
  171. $GroupID = display_str($this->Torrent['GroupID']);
  172. $CategoryID = display_str($this->Torrent['CategoryID'] - 1);
  173. $HTML .= <<<HTML
  174. <input type="hidden" name="groupid" value="$GroupID" />
  175. <input type="hidden" name="type" value="$CategoryID" />
  176. HTML;
  177. }
  178. # Request hidden fields (new or edit?)
  179. if ($this->Torrent && ($this->Torrent['RequestID'] ?? false)) {
  180. $RequestID = display_str($this->Torrent['RequestID']);
  181. $HTML .= <<<HTML
  182. <input type="hidden" name="requestid"value="$RequestID" />
  183. HTML;
  184. }
  185. } # else
  186. /**
  187. * Start printing the torrent form
  188. */
  189. $HTML .= '<table class="torrent_form">';
  190. /**
  191. * New torrent options:
  192. * file and category
  193. */
  194. if ($this->NewTorrent) {
  195. $HTML .= '<h2 class="header">Basic Info</h2>';
  196. $HTML .= <<<HTML
  197. <tr>
  198. <td>
  199. <label for="file_input" class="required">
  200. Torrent File
  201. </label>
  202. </td>
  203. <td>
  204. <input id="file" type="file" name="file_input" size="50" />
  205. <p>
  206. Set the private flag, e.g.,
  207. <code>mktorrent -p -a &lt;announce&gt; &lt;target folder&gt;</code>
  208. </p>
  209. </td>
  210. </tr>
  211. HTML;
  212. $DisabledFlag = ($this->DisabledFlag) ? ' disabled="disabled"' : '';
  213. $HTML .= <<<HTML
  214. <tr>
  215. <td>
  216. <label for="type" class="required">
  217. Category
  218. </label>
  219. </td>
  220. <td>
  221. <select id="categories" name="type" onchange="Categories()" $DisabledFlag>
  222. HTML;
  223. foreach ($ENV->CATS as $Cat) {
  224. $Minus1 = $Cat->ID - 1;
  225. $HTML .= "<option value='$Minus1'";
  226. if ($Cat->Name === $this->Torrent['CategoryName']) {
  227. $HTML .= ' selected="selected"';
  228. }
  229. $HTML .= ">$Cat->Name</option>";
  230. }
  231. $HTML .= <<<HTML
  232. </select>
  233. <p id="category_description" class="">
  234. <!-- $Cat->Description will live here -->
  235. Please see the
  236. <a href="/wiki.php?action=article&name=categories">Categories Wiki</a>
  237. for details
  238. </p>
  239. </td>
  240. </tr>
  241. </table>
  242. HTML;
  243. } # fi NewTorrent
  244. # Start the dynamic form
  245. $HTML .= '<div id="dynamic_form">';
  246. return $HTML;
  247. } # End head()
  248. /**
  249. * foot
  250. *
  251. * Make the endmatter.
  252. */
  253. private function foot()
  254. {
  255. $Torrent = $this->Torrent;
  256. echo '<table class="torrent_form>';
  257. /**
  258. * Freeleech type
  259. */
  260. if (!$this->NewTorrent) {
  261. if (check_perms('torrents_freeleech')) {
  262. echo <<<HTML
  263. <tr id="freetorrent">
  264. <td>
  265. <label for="freeleech">
  266. Freeleech
  267. </label>
  268. </td>
  269. <td>
  270. <select name="freeleech">
  271. HTML;
  272. $FL = ['Normal', 'Free', 'Neutral'];
  273. foreach ($FL as $Key => $Name) {
  274. $Selected = ($Key === $Torrent['FreeTorrent']) ? ' selected="selected"' : '';
  275. echo <<<HTML
  276. <option value="$Key" $Selected>
  277. $Name
  278. </option>
  279. HTML;
  280. }
  281. echo <<<HTML
  282. </select>
  283. because
  284. <select name="freeleechtype">
  285. HTML;
  286. /**
  287. * Freeleech reasons
  288. */
  289. $FL = array('N/A', 'Staff Pick', 'Perma-FL', 'Freeleechizer', 'Site-Wide FL');
  290. foreach ($FL as $Key => $Name) {
  291. $Selected = ($Key === $Torrent['FreeLeechType']) ? ' selected="selected"' : '';
  292. echo <<<HTML
  293. <option value="$Key?>" $Selected>
  294. $Name
  295. </option>
  296. HTML;
  297. }
  298. echo <<<HTML
  299. </select>
  300. </td>
  301. </tr>
  302. HTML;
  303. }
  304. } # fi !NewTorrent
  305. # For new torrents only
  306. if ($this->NewTorrent) {
  307. # Rules notice
  308. echo <<<HTML
  309. <tr>
  310. <td>
  311. <aside class="torrent_upload">
  312. <p>
  313. Be sure that your torrent is approved by the
  314. <a href="rules.php?p=upload" target="_blank">rules</a>.
  315. Not doing this will result in a
  316. <strong class="important_text">warning</strong> or
  317. <strong class="important_text">worse</strong>.
  318. </p>
  319. HTML;
  320. # Request fill notice
  321. echo <<<HTML
  322. <p>
  323. After uploading the torrent, you will have a one hour grace period.
  324. During this time only you can fill requests with this torrent.
  325. Make use of it wisely, and
  326. <a href="requests.php">search the list of requests</a>.
  327. </p>
  328. HTML;
  329. echo '</aside></td></tr>';
  330. }
  331. /**
  332. * Submit button
  333. */
  334. $Value = ($this->NewTorrent) ? 'Upload' : 'Edit';
  335. echo <<<HTML
  336. <tr>
  337. <td>
  338. <input id="post" type="submit" value="$Value" />
  339. </td>
  340. </tr>
  341. </table> <!-- torrent_form -->
  342. </form>
  343. </div> <!-- dynamic_form -->
  344. HTML;
  345. } # End foot()
  346. /**
  347. * upload_form
  348. *
  349. * Finally the "real" upload form.
  350. * Contains all the field you'd expect.
  351. *
  352. * This is currently one enormous function.
  353. * It has sub-functions, variables, and everything.
  354. * It continues to the end of the class.
  355. */
  356. private function upload_form()
  357. {
  358. $ENV = ENV::go();
  359. $Twig = Twig::go();
  360. $QueryID = G::$DB->get_query_id();
  361. $Torrent = $this->Torrent;
  362. # Start printing the form
  363. echo '<h2 class="header">Torrent Form</h2>';
  364. echo '<table class="torrent_form">';
  365. /**
  366. * Accession Number
  367. */
  368. $CatalogueNumber = display_str($Torrent['CatalogueNumber']);
  369. $Disabled = $this->Disabled;
  370. echo $Twig->render(
  371. 'torrent_form/identifier.html',
  372. [
  373. 'db' => $ENV->DB->identifier,
  374. 'identifier' => $CatalogueNumber,
  375. ]
  376. );
  377. /**
  378. * Semantic Version
  379. */
  380. $Version = display_str($Torrent['Version']);
  381. echo $Twig->render(
  382. 'torrent_form/version.html',
  383. [
  384. 'db' => $ENV->DB->version,
  385. 'version' => $Version,
  386. ]
  387. );
  388. /**
  389. * Title Fields
  390. */
  391. # New torrent upload
  392. if ($this->NewTorrent) {
  393. $Title1 = display_str($Torrent['Title']);
  394. $Title2 = display_str($Torrent['Title2']);
  395. $Title3 = display_str($Torrent['TitleJP']);
  396. #$Disabled = $this->Disabled;
  397. echo $Twig->render(
  398. 'torrent_form/titles.html',
  399. [
  400. 'db' => $ENV->DB,
  401. 'title' => $Title1,
  402. 'subject' => $Title2,
  403. 'object' => $Title3,
  404. ]
  405. );
  406. } # fi NewTorrent
  407. /**
  408. * Creator(s)
  409. * CURRENTLY BROKEN
  410. *
  411. * Gazelle supports multiple creators per torrent.
  412. * One day I want to integrate the creator DB to join:
  413. * - DOI publication info in `torrents_screenshots`
  414. * - Attributions listed on the creator pages
  415. * - Stats about creator vs. total DOI citations
  416. */
  417. if ($this->NewTorrent) {
  418. # Useful variables
  419. $Disabled = $this->Disabled;
  420. $AutocompleteOption = Users::has_autocomplete_enabled('other');
  421. $AddRemoveBrackets = <<<HTML
  422. <a class="add_artist_button brackets" onclick="AddArtistField()">+</a>
  423. <a class="remove_artist_button brackets" onclick="RemoveArtistField()">&minus;</a>
  424. HTML;
  425. echo <<<HTML
  426. <tr id="artists_tr">
  427. <td>
  428. <label for="artistfields" class="required">
  429. Authors(s)
  430. </label>
  431. </td>
  432. <td id="artistfields">
  433. <p>
  434. One per field, e.g., Robert K. Mortimer [+] David Schild
  435. </p>
  436. HTML;
  437. # If there are already creators listed
  438. if (!empty($Torrent['Artists'])) {
  439. foreach ($Torrent['Artists'] as $Num => $Artist) {
  440. $ArtistName = display_str($Artist['name']);
  441. $AddRemoveBrackets = ($Num === 0) ?: null;
  442. echo <<<HTML
  443. <input type="text" id="artist_$Num" name="artists[]" size="45"
  444. value="$ArtistName" $AutocompleteOption $Disabled />
  445. $AddRemoveBrackets
  446. HTML;
  447. }
  448. } else {
  449. echo <<<HTML
  450. <input type="text" id="artist_0" name="artists[]" size="45"
  451. value="" $AutocompleteOption $Disabled />
  452. $AddRemoveBrackets
  453. HTML;
  454. }
  455. echo '</td></tr>';
  456. } # fi $NewTorrent
  457. /**
  458. * Workgroup
  459. */
  460. if ($this->NewTorrent) {
  461. $Affiliation = display_str($Torrent['Studio']);
  462. echo $Twig->render(
  463. 'torrent_form/workgroup.html',
  464. [
  465. 'db' => $ENV->DB->workgroup,
  466. 'workgroup' => $Affiliation,
  467. ]
  468. );
  469. }
  470. /**
  471. * Location
  472. *
  473. * The location of the studio, lab, etc.
  474. * Currently not sanitized to a standard format.
  475. */
  476. if ($this->NewTorrent) {
  477. $TorrentLocation = display_str($Torrent['Series']);
  478. echo $Twig->render(
  479. 'torrent_form/location.html',
  480. [
  481. 'db' => $ENV->DB->location,
  482. 'location' => $TorrentLocation,
  483. ]
  484. );
  485. }
  486. /**
  487. * ============================
  488. * = End if NewTorrent fields =
  489. * ============================
  490. */
  491. /**
  492. * Year
  493. */
  494. $TorrentYear = display_str($Torrent['Year']);
  495. echo $Twig->render(
  496. 'torrent_form/year.html',
  497. [
  498. 'db' => $ENV->DB->year,
  499. 'year' => $TorrentYear,
  500. ]
  501. );
  502. /**
  503. * Misc meta
  504. *
  505. * Used in OT Gazelle as Codec.
  506. * Used in Bio Gazelle as License.
  507. *
  508. * Unsure what to call the final field.
  509. * Some essential, specific one-off info.
  510. */
  511. echo <<<HTML
  512. <tr id="codec_tr">
  513. <td>
  514. <label for="codec" class="required">
  515. License
  516. </label>
  517. </td>
  518. <td>
  519. <select name="codec">
  520. <option>---</option>
  521. HTML;
  522. foreach ($ENV->META->Licenses as $License) {
  523. echo "<option value='$License'";
  524. if ($License === ($Torrent['Codec'] ?? false)) {
  525. echo " selected";
  526. }
  527. echo ">$License</option>\n";
  528. }
  529. echo <<<HTML
  530. </select>
  531. <p>
  532. Please see
  533. <a href="http://www.dcc.ac.uk/resources/how-guides/license-research-data" target="_blank">How to License Research Data</a>
  534. </p>
  535. </td>
  536. </tr>
  537. HTML;
  538. /**
  539. * ====================================
  540. * = Begin if NewTorrent fields again =
  541. * ====================================
  542. */
  543. /**
  544. * Media
  545. *
  546. * The class of technology associated with the data.
  547. * Answers the question: "Where does the data come from?"
  548. *
  549. * This could be the data genesis platform or program,
  550. * or a genre of physical media (e.g., vinyl record).
  551. */
  552. /**
  553. * Make select element
  554. *
  555. * Takes an ID, label, torrent, and media list.
  556. * Returns a media select option as on upload.php.
  557. */
  558. function mediaSelect($trID = '', $Label = '', $Torrent = [], $Media = [], $Desc = '')
  559. {
  560. echo <<<HTML
  561. <tr id="$trID">
  562. <td>
  563. <label for="media" class="required">
  564. $Label
  565. </label>
  566. </td>
  567. <td>
  568. <select name="media">
  569. <option>---</option>
  570. HTML;
  571. foreach ($Media as $Media) {
  572. echo "<option value='$Media'";
  573. if ($Media === ($Torrent['Media'] ?? false)) {
  574. echo ' selected';
  575. }
  576. echo ">$Media</option>\n";
  577. }
  578. echo <<<HTML
  579. </select>
  580. <p>
  581. The class of technology used
  582. </p>
  583. </td>
  584. </tr>
  585. HTML;
  586. } # End mediaSelect()
  587. /**
  588. * Platform: Sequences
  589. */
  590. if ($this->NewTorrent) {
  591. mediaSelect(
  592. $trID = 'media_tr',
  593. $Label = 'Platform',
  594. $Torrent = $Torrent,
  595. $Media = $ENV->CATS->{1}->Platforms
  596. );
  597. /**
  598. * Platform: Graphs
  599. */
  600. mediaSelect(
  601. $trID = 'media_graphs_tr',
  602. $Label = 'Platform',
  603. $Torrent = $Torrent,
  604. $Media = $ENV->CATS->{2}->Platforms
  605. );
  606. /**
  607. * Platform: Scalars/Vectors
  608. */
  609. mediaSelect(
  610. $trID = 'media_scalars_vectors_tr',
  611. $Label = 'Platform',
  612. $Torrent = $Torrent,
  613. $Media = $ENV->CATS->{5}->Platforms
  614. );
  615. /**
  616. * Platform: Images
  617. */
  618. mediaSelect(
  619. $trID = 'media_images_tr',
  620. $Label = 'Platform',
  621. $Torrent = $Torrent,
  622. $Media = $ENV->CATS->{8}->Platforms
  623. );
  624. /**
  625. * Platform: Documents
  626. */
  627. mediaSelect(
  628. $trID = 'media_documents_tr',
  629. $Label = 'Platform',
  630. $Torrent = $Torrent,
  631. $Media = $ENV->CATS->{11}->Platforms
  632. );
  633. /**
  634. * Platform: Machine Data
  635. */
  636. mediaSelect(
  637. $trID = 'media_machine_data_tr',
  638. $Label = 'Platform',
  639. $Torrent = $Torrent,
  640. $Media = $ENV->CATS->{12}->Platforms
  641. );
  642. } # fi NewTorrent
  643. else {
  644. $TorrentMedia = $Torrent['Media'];
  645. echo <<<HTML
  646. <input type="hidden" name="media" value="$TorrentMedia" />
  647. HTML;
  648. }
  649. /**
  650. * Format
  651. *
  652. * Simple: the data's file format.
  653. * Called Container in OT Gazelle, same diff.
  654. * In the future, $ENV will automagically set this.
  655. */
  656. function formatSelect($trID = '', $Label = '', $Torrent = [], $FileTypes = [])
  657. {
  658. echo <<<HTML
  659. <tr id="$trID">
  660. <td>
  661. <label for="container" class="required">
  662. $Label
  663. <label>
  664. </td>
  665. <td>
  666. <select id="container" name="container">
  667. <option value="Autofill">Autofill</option>
  668. HTML;
  669. foreach ($FileTypes as $Type => $Extensions) {
  670. echo "<option value='$Type'";
  671. if ($Type === ($Torrent['Container'] ?? false)) {
  672. echo ' selected';
  673. }
  674. echo ">$Type</option>\n";
  675. }
  676. echo <<<HTML
  677. </select>
  678. <p>
  679. File format, or detect from file list
  680. <!--
  681. todo: Make work with config.php metadata
  682. Data file format, or detect from file list
  683. Compression algorithm, or detect from file list
  684. -->
  685. </p>
  686. </td>
  687. </tr>
  688. HTML;
  689. } # End formatSelect()
  690. /**
  691. * Format: Sequences
  692. */
  693. formatSelect(
  694. $trID = 'container_tr',
  695. $Label = 'Format',
  696. $Torrent = $Torrent,
  697. $FileTypes = $ENV->CATS->{1}->Formats
  698. );
  699. /**
  700. * Format: Graphs
  701. */
  702. formatSelect(
  703. $trID = 'container_graphs_tr',
  704. $Label = 'Format',
  705. $Torrent = $Torrent,
  706. #$FileTypes = array_column($ENV->META, $Formats)
  707. );
  708. /**
  709. * Format: Scalars/Vectors
  710. */
  711. formatSelect(
  712. $trID = 'container_scalars_vectors_tr',
  713. $Label = 'Format',
  714. $Torrent = $Torrent,
  715. $FileTypes = $ENV->flatten($ENV->CATS->{5}->Formats)
  716. );
  717. /**
  718. * Format: Images
  719. */
  720. formatSelect(
  721. $trID = 'container_images_tr',
  722. $Label = 'Format',
  723. $Torrent = $Torrent,
  724. $FileTypes = array_merge($this->ImgFormats, $this->PlainFormats)
  725. );
  726. /**
  727. * Format: Spatial
  728. */
  729. formatSelect(
  730. $trID = 'container_spatial_tr',
  731. $Label = 'Format',
  732. $Torrent = $Torrent,
  733. $FileTypes = array_merge($this->MapVectorFormats, $this->MapRasterFormats, $this->ImgFormats, $this->PlainFormats)
  734. );
  735. /**
  736. * Format: Documents
  737. */
  738. formatSelect(
  739. $trID = 'container_documents_tr',
  740. $Label = 'Format',
  741. $Torrent = $Torrent,
  742. $FileTypes = array_merge($this->BinDocFormats, $this->CpuGenFormats, $this->PlainFormats)
  743. );
  744. /**
  745. * Format: Compression
  746. */
  747. formatSelect(
  748. $trID = 'archive_tr',
  749. $Label = 'Archive',
  750. $Torrent = $Torrent,
  751. $FileTypes = $this->Archives
  752. );
  753. /**
  754. * Scope
  755. *
  756. * How complete the data are.
  757. * Relatively, how much information does it contain?
  758. */
  759. $TorrentResolution = ($Torrent['Resolution']) ?? '';
  760. echo <<<HTML
  761. <tr id="resolution_tr">
  762. <td>
  763. <label for="ressel" class="required">
  764. Scope
  765. </label>
  766. </td>
  767. <td>
  768. <select id="ressel" name="ressel" onchange="SetResolution()">
  769. <option>---</option>
  770. HTML;
  771. foreach ($this->Resolutions as $Res) {
  772. echo "<option value='$Res'";
  773. if ($Res === ($Torrent['Resolution'] ?? false)
  774. || (!isset($FoundRes) && ($Torrent['Resolution'] ?? false)
  775. && $Res === 'Other')) {
  776. echo " selected";
  777. $FoundRes = true;
  778. }
  779. echo ">$Res</option>\n";
  780. }
  781. echo <<<HTML
  782. </select>
  783. <!-- Enter your own -->
  784. <input type="text" id="resolution" name="resolution" size="15" maxlength="20"
  785. class="hidden" value="$TorrentResolution" readonly>
  786. </input>
  787. <script>
  788. if ($('#ressel').raw().value === 'Other') {
  789. $('#resolution').raw().readOnly = false
  790. $('#resolution').gshow()
  791. }
  792. </script>
  793. <p>
  794. How complete the data is, specifically or conceptually
  795. </p>
  796. </td>
  797. </tr>
  798. HTML;
  799. /**
  800. * ====================================
  801. * = Begin if NewTorrent fields again =
  802. * ====================================
  803. */
  804. /**
  805. * Tags
  806. *
  807. * Simple enough.
  808. * I won't rehash tag management.
  809. */
  810. if ($this->NewTorrent) {
  811. echo <<<HTML
  812. <tr id="tags_tr">
  813. <td>
  814. <label for="tags" class="required">
  815. Tags
  816. </label>
  817. </td>
  818. <td>
  819. HTML;
  820. $GenreTags = G::$Cache->get_value('genre_tags');
  821. if (!$GenreTags) {
  822. G::$DB->query("
  823. SELECT
  824. `Name`
  825. FROM
  826. `tags`
  827. WHERE
  828. `TagType` = 'genre'
  829. ORDER BY
  830. `Name`
  831. ");
  832. $GenreTags = G::$DB->collect('Name');
  833. G::$Cache->cache_value('genre_tags', $GenreTags, 3600*6);
  834. }
  835. # todo: Find a better place for these
  836. $Disabled = ($this->DisabledFlag) ? ' disabled="disabled"' : null;
  837. $TorrentTagList = display_str(implode(', ', explode(',', $Torrent['TagList'])));
  838. $AutocompleteOption = Users::has_autocomplete_enabled('other');
  839. echo <<<HTML
  840. <select id="genre_tags" name="genre_tags" onchange="add_tag(); return false;" $Disabled>
  841. <option>---</option>
  842. HTML;
  843. foreach (Misc::display_array($GenreTags) as $Genre) {
  844. echo <<<HTML
  845. <option value="$Genre">
  846. $Genre
  847. </option>
  848. HTML;
  849. }
  850. echo <<<HTML
  851. </select>
  852. <input type="text" id="tags" name="tags" size="60"
  853. placeholder="Comma-seperated list of at least 5 tags"
  854. value="$TorrentTagList" $AutocompleteOption />
  855. </td>
  856. </tr>
  857. HTML;
  858. } # fi NewTorrent
  859. /**
  860. * Picture
  861. *
  862. * Another obvious field.
  863. */
  864. if ($this->NewTorrent) {
  865. $TorrentImage = display_str($Torrent['Image']);
  866. $Disabled = $this->Disabled;
  867. echo $Twig->render(
  868. 'torrent_form/picture.html',
  869. [
  870. 'db' => $ENV->DB->picture,
  871. 'picture' => $TorrentImage,
  872. ]
  873. );
  874. }
  875. /**
  876. * Mirrors
  877. *
  878. * This should be in the `torrents` table not `torrents_group.`
  879. * The intended use is for web seeds, Dat mirrors, etc.
  880. */
  881. if (!$this->DisabledFlag && $this->NewTorrent) {
  882. $TorrentMirrors = display_str($Torrent['Mirrors']);
  883. echo $Twig->render(
  884. 'torrent_form/mirrors.html',
  885. [
  886. 'db' => $ENV->DB->mirrors,
  887. 'mirrors' => $TorrentMirrors,
  888. ]
  889. );
  890. }
  891. /**
  892. * Samples
  893. *
  894. * Called Screenshots in OT Gazelle.
  895. * Called Publication in Bio Gazelle.
  896. * Eventually this will be a proper database in itself,
  897. * pulling info from DOI to populate the schema.
  898. */
  899. if (!$this->DisabledFlag && $this->NewTorrent) {
  900. $TorrentSamples = display_str($Torrent['Screenshots']);
  901. echo <<<HTML
  902. <tr id="screenshots_tr">
  903. <td>
  904. <label for="screenshots">
  905. Publications
  906. </label>
  907. </td>
  908. <td>
  909. <!-- Needs to be all on one line -->
  910. <textarea rows="8" name="screenshots" id="screenshots"
  911. placeholder="Up to ten DOI numbers, one per line">$TorrentSamples</textarea>
  912. </td>
  913. </tr>
  914. HTML;
  915. }
  916. /**
  917. * Torrent group description
  918. *
  919. * The text on the main torrent pages,
  920. * between torrent info and torrent comments,
  921. * visible even if individual torrents are collapsed.
  922. */
  923. if ($this->NewTorrent) {
  924. echo <<<HTML
  925. <tr id="group_desc_tr">
  926. <td>
  927. <label for="album_desc" class="required">
  928. Torrent Group Description
  929. </label>
  930. </td>
  931. <td>
  932. HTML;
  933. new TEXTAREA_PREVIEW(
  934. $Name = 'album_desc',
  935. $ID = 'album_desc',
  936. $Value = display_str($Torrent['GroupDescription']) ?? '',
  937. $Placeholder = "General info about the torrent subject's function or significance",
  938. );
  939. echo '</td></tr>';
  940. } # fi NewTorrent
  941. /**
  942. * ============================
  943. * = End if NewTorrent fields =
  944. * ============================
  945. */
  946. /**
  947. * Torrent description
  948. *
  949. * The test displayed when torrent info is expanded.
  950. * It should describe the specific torrent, not the group.
  951. */
  952. echo <<<HTML
  953. <tr id="release_desc_tr">
  954. <td>
  955. <label for="release_desc">
  956. Torrent Description
  957. </label>
  958. </td>
  959. <td>
  960. HTML;
  961. new TEXTAREA_PREVIEW(
  962. $Name = 'release_desc',
  963. $ID = 'release_desc',
  964. $Value = display_str($Torrent['TorrentDescription'] ?? ''),
  965. $Placeholder = 'Specific info about the protocols and equipment used to produce the data',
  966. );
  967. echo '</td></tr>';
  968. /**
  969. * Boolean options
  970. *
  971. * Simple checkboxes that do stuff.
  972. * Currently checks for data annotations and anonymous uploads.
  973. * More fields could be created as the need arises.
  974. */
  975. /**
  976. * Aligned/Annontated
  977. *
  978. * Called Censored in OT Gazelle.
  979. */
  980. $TorrentAnnotated = ($Torrent['Censored'] ?? 0) ? ' checked' : '';
  981. echo <<<HTML
  982. <tr id="censored_tr">
  983. <td>
  984. <label for="censored">
  985. Aligned/Annotated
  986. </label>
  987. </td>
  988. <td>
  989. <input type="checkbox" name="censored" value="1" $TorrentAnnotated />
  990. &ensp;
  991. Whether the torrent contains alignments, annotations, or other structural metadata
  992. </td>
  993. </tr>
  994. HTML;
  995. /**
  996. * Upload Anonymously
  997. */
  998. $TorrentAnonymous = ($Torrent['Anonymous'] ?? false) ? ' checked' : '';
  999. echo <<<HTML
  1000. <tr id="anon_tr">
  1001. <td>
  1002. <label for="anonymous">
  1003. Upload Anonymously
  1004. </label>
  1005. </td>
  1006. <td>
  1007. <input type="checkbox" name="anonymous" value="1" $TorrentAnonymous />
  1008. &ensp;
  1009. Hide your username from other users on the torrent details page
  1010. </td>
  1011. </tr>
  1012. HTML;
  1013. # End the giant dynamic form table
  1014. echo '</table>';
  1015. # Drink a stiff one
  1016. G::$DB->set_query_id($QueryID);
  1017. } # End upload_form()
  1018. } # End TorrentForm()