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

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