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 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  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 class="center">
  338. <input id="post" type="submit" value="$Value" class="button-primary" />
  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 fields 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 skeleton-fix">';
  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. * 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. #var_dump($FileTypes);
  659. echo <<<HTML
  660. <tr id="$trID">
  661. <td>
  662. <label for="container" class="required">
  663. $Label
  664. <label>
  665. </td>
  666. <td>
  667. <select id="container" name="container">
  668. <option value="Autofill">Autofill</option>
  669. HTML;
  670. foreach ($FileTypes as $FileType) {
  671. foreach ($FileType as $Type => $Extensions) {
  672. echo "<option value='$Type'";
  673. if ($Type === ($Torrent['Container'] ?? false)) {
  674. echo ' selected';
  675. }
  676. echo ">$Type</option>\n";
  677. }
  678. }
  679. echo <<<HTML
  680. </select>
  681. <p>
  682. File format, or detect from file list
  683. <!--
  684. todo: Make work with config.php metadata
  685. Data file format, or detect from file list
  686. Compression algorithm, or detect from file list
  687. -->
  688. </p>
  689. </td>
  690. </tr>
  691. HTML;
  692. } # End formatSelect()
  693. /**
  694. * Format: Sequences
  695. */
  696. formatSelect(
  697. $trID = 'container_tr',
  698. $Label = 'Format',
  699. $Torrent = $Torrent,
  700. $FileTypes = $ENV->CATS->{1}->Formats
  701. );
  702. /**
  703. * Format: Graphs
  704. */
  705. formatSelect(
  706. $trID = 'container_graphs_tr',
  707. $Label = 'Format',
  708. $Torrent = $Torrent,
  709. #$FileTypes = array_column($ENV->META, $Formats)
  710. $FileTypes = $ENV->CATS->{2}->Formats
  711. );
  712. /**
  713. * Format: Scalars/Vectors
  714. */
  715. formatSelect(
  716. $trID = 'container_scalars_vectors_tr',
  717. $Label = 'Format',
  718. $Torrent = $Torrent,
  719. #$FileTypes = $ENV->flatten($ENV->CATS->{5}->Formats)
  720. $FileTypes = $ENV->CATS->{5}->Formats
  721. );
  722. /**
  723. * Format: Images
  724. */
  725. formatSelect(
  726. $trID = 'container_images_tr',
  727. $Label = 'Format',
  728. $Torrent = $Torrent,
  729. #$FileTypes = array_merge($this->ImgFormats)
  730. $FileTypes = $ENV->CATS->{8}->Formats
  731. );
  732. /**
  733. * Format: Spatial
  734. */
  735. formatSelect(
  736. $trID = 'container_spatial_tr',
  737. $Label = 'Format',
  738. $Torrent = $Torrent,
  739. #$FileTypes = array_merge($this->MapVectorFormats, $this->MapRasterFormats, $this->ImgFormats, $this->PlainFormats)
  740. $FileTypes = $ENV->CATS->{9}->Formats
  741. );
  742. /**
  743. * Format: Documents
  744. */
  745. formatSelect(
  746. $trID = 'container_documents_tr',
  747. $Label = 'Format',
  748. $Torrent = $Torrent,
  749. #$FileTypes = array_merge($this->BinDocFormats, $this->CpuGenFormats, $this->PlainFormats)
  750. $FileTypes = $ENV->CATS->{11}->Formats
  751. );
  752. /**
  753. * Format: Compression
  754. */
  755. formatSelect(
  756. $trID = 'archive_tr',
  757. $Label = 'Archive',
  758. $Torrent = $Torrent,
  759. # $ENV->Archives nests -1 deep
  760. $FileTypes = [$ENV->META->Formats->Archives]
  761. );
  762. /**
  763. * Scope
  764. *
  765. * How complete the data are.
  766. * Relatively, how much information does it contain?
  767. */
  768. $TorrentResolution = ($Torrent['Resolution']) ?? '';
  769. echo <<<HTML
  770. <tr id="resolution_tr">
  771. <td>
  772. <label for="ressel" class="required">
  773. Scope
  774. </label>
  775. </td>
  776. <td>
  777. <select id="ressel" name="ressel" onchange="SetResolution()">
  778. <option>---</option>
  779. HTML;
  780. foreach ($this->Resolutions as $Res) {
  781. echo "<option value='$Res'";
  782. if ($Res === ($Torrent['Resolution'] ?? false)
  783. || (!isset($FoundRes) && ($Torrent['Resolution'] ?? false)
  784. && $Res === 'Other')) {
  785. echo " selected";
  786. $FoundRes = true;
  787. }
  788. echo ">$Res</option>\n";
  789. }
  790. echo <<<HTML
  791. </select>
  792. <!-- Enter your own -->
  793. <input type="text" id="resolution" name="resolution" size="15" maxlength="20"
  794. class="hidden" value="$TorrentResolution" readonly>
  795. </input>
  796. <script>
  797. if ($('#ressel').raw().value === 'Other') {
  798. $('#resolution').raw().readOnly = false
  799. $('#resolution').gshow()
  800. }
  801. </script>
  802. <p>
  803. How complete the data is, specifically or conceptually
  804. </p>
  805. </td>
  806. </tr>
  807. HTML;
  808. /**
  809. * ====================================
  810. * = Begin if NewTorrent fields again =
  811. * ====================================
  812. */
  813. /**
  814. * Tags
  815. *
  816. * Simple enough.
  817. * I won't rehash tag management.
  818. */
  819. if ($this->NewTorrent) {
  820. echo <<<HTML
  821. <tr id="tags_tr">
  822. <td>
  823. <label for="tags" class="required">
  824. Tags
  825. </label>
  826. </td>
  827. <td>
  828. HTML;
  829. $GenreTags = G::$Cache->get_value('genre_tags');
  830. if (!$GenreTags) {
  831. G::$DB->query("
  832. SELECT
  833. `Name`
  834. FROM
  835. `tags`
  836. WHERE
  837. `TagType` = 'genre'
  838. ORDER BY
  839. `Name`
  840. ");
  841. $GenreTags = G::$DB->collect('Name');
  842. G::$Cache->cache_value('genre_tags', $GenreTags, 3600*6);
  843. }
  844. # todo: Find a better place for these
  845. $Disabled = ($this->DisabledFlag) ? ' disabled="disabled"' : null;
  846. $TorrentTagList = display_str(implode(', ', explode(',', $Torrent['TagList'])));
  847. $AutocompleteOption = Users::has_autocomplete_enabled('other');
  848. echo <<<HTML
  849. <select id="genre_tags" name="genre_tags" onchange="add_tag(); return false;" $Disabled>
  850. <option>---</option>
  851. HTML;
  852. foreach (Misc::display_array($GenreTags) as $Genre) {
  853. echo <<<HTML
  854. <option value="$Genre">
  855. $Genre
  856. </option>
  857. HTML;
  858. }
  859. echo <<<HTML
  860. </select>
  861. <input type="text" id="tags" name="tags" size="60"
  862. placeholder="Comma-seperated list of at least 5 tags"
  863. value="$TorrentTagList" $AutocompleteOption />
  864. </td>
  865. </tr>
  866. HTML;
  867. } # fi NewTorrent
  868. /**
  869. * Picture
  870. *
  871. * Another obvious field.
  872. */
  873. if ($this->NewTorrent) {
  874. $TorrentImage = display_str($Torrent['Image']);
  875. $Disabled = $this->Disabled;
  876. echo $Twig->render(
  877. 'torrent_form/picture.html',
  878. [
  879. 'db' => $ENV->DB->picture,
  880. 'picture' => $TorrentImage,
  881. ]
  882. );
  883. }
  884. /**
  885. * Mirrors
  886. *
  887. * This should be in the `torrents` table not `torrents_group.`
  888. * The intended use is for web seeds, Dat mirrors, etc.
  889. */
  890. if (!$this->DisabledFlag && $this->NewTorrent) {
  891. $TorrentMirrors = display_str($Torrent['Mirrors']);
  892. echo $Twig->render(
  893. 'torrent_form/mirrors.html',
  894. [
  895. 'db' => $ENV->DB->mirrors,
  896. 'mirrors' => $TorrentMirrors,
  897. ]
  898. );
  899. }
  900. /**
  901. * Samples
  902. *
  903. * Called Screenshots in OT Gazelle.
  904. * Called Publication in Bio Gazelle.
  905. * Eventually this will be a proper database in itself,
  906. * pulling info from DOI to populate the schema.
  907. */
  908. if (!$this->DisabledFlag && $this->NewTorrent) {
  909. $TorrentSamples = display_str($Torrent['Screenshots']);
  910. echo <<<HTML
  911. <tr id="screenshots_tr">
  912. <td>
  913. <label for="screenshots">
  914. Publications
  915. </label>
  916. </td>
  917. <td>
  918. <!-- Needs to be all on one line -->
  919. <textarea rows="8" name="screenshots" id="screenshots"
  920. placeholder="Up to ten DOI numbers, one per line">$TorrentSamples</textarea>
  921. </td>
  922. </tr>
  923. HTML;
  924. }
  925. /**
  926. * Seqhash
  927. */
  928. if ($ENV->FEATURE_BIOPHP && !$this->DisabledFlag && $this->NewTorrent) {
  929. $TorrentSeqhash = display_str($Torrent['Seqhash']);
  930. echo $Twig->render(
  931. 'torrent_form/seqhash.html',
  932. [
  933. 'db' => $ENV->DB->seqhash,
  934. 'seqhash' => $TorrentSeqhash,
  935. ]
  936. );
  937. }
  938. /**
  939. * Torrent group description
  940. *
  941. * The text on the main torrent pages,
  942. * between torrent info and torrent comments,
  943. * visible even if individual torrents are collapsed.
  944. */
  945. if ($this->NewTorrent) {
  946. echo <<<HTML
  947. <tr id="group_desc_tr">
  948. <td>
  949. <label for="album_desc" class="required">
  950. Torrent Group Description
  951. </label>
  952. </td>
  953. <td>
  954. HTML;
  955. new TEXTAREA_PREVIEW(
  956. $Name = 'album_desc',
  957. $ID = 'album_desc',
  958. $Value = display_str($Torrent['GroupDescription']) ?? '',
  959. $Placeholder = "General info about the torrent subject's function or significance",
  960. );
  961. echo '</td></tr>';
  962. } # fi NewTorrent
  963. /**
  964. * ============================
  965. * = End if NewTorrent fields =
  966. * ============================
  967. */
  968. /**
  969. * Torrent description
  970. *
  971. * The test displayed when torrent info is expanded.
  972. * It should describe the specific torrent, not the group.
  973. */
  974. echo <<<HTML
  975. <tr id="release_desc_tr">
  976. <td>
  977. <label for="release_desc">
  978. Torrent Description
  979. </label>
  980. </td>
  981. <td>
  982. HTML;
  983. new TEXTAREA_PREVIEW(
  984. $Name = 'release_desc',
  985. $ID = 'release_desc',
  986. $Value = display_str($Torrent['TorrentDescription'] ?? ''),
  987. $Placeholder = 'Specific info about the protocols and equipment used to produce the data',
  988. );
  989. echo '</td></tr>';
  990. /**
  991. * Boolean options
  992. *
  993. * Simple checkboxes that do stuff.
  994. * Currently checks for data annotations and anonymous uploads.
  995. * More fields could be created as the need arises.
  996. */
  997. /**
  998. * Aligned/Annontated
  999. *
  1000. * Called Censored in OT Gazelle.
  1001. */
  1002. $TorrentAnnotated = ($Torrent['Censored'] ?? 0) ? ' checked' : '';
  1003. echo <<<HTML
  1004. <tr id="censored_tr">
  1005. <td>
  1006. <label for="censored">
  1007. Aligned/Annotated
  1008. </label>
  1009. </td>
  1010. <td>
  1011. <input type="checkbox" name="censored" value="1" $TorrentAnnotated />
  1012. &ensp;
  1013. Whether the torrent contains alignments, annotations, or other structural metadata
  1014. </td>
  1015. </tr>
  1016. HTML;
  1017. /**
  1018. * Upload Anonymously
  1019. */
  1020. $TorrentAnonymous = ($Torrent['Anonymous'] ?? false) ? ' checked' : '';
  1021. echo <<<HTML
  1022. <tr id="anon_tr">
  1023. <td>
  1024. <label for="anonymous">
  1025. Upload Anonymously
  1026. </label>
  1027. </td>
  1028. <td>
  1029. <input type="checkbox" name="anonymous" value="1" $TorrentAnonymous />
  1030. &ensp;
  1031. Hide your username from other users on the torrent details page
  1032. </td>
  1033. </tr>
  1034. HTML;
  1035. # End the giant dynamic form table
  1036. echo '</table>';
  1037. # Drink a stiff one
  1038. G::$DB->set_query_id($QueryID);
  1039. } # End upload_form()
  1040. } # End TorrentForm()