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

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