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.NEW.2020-12-10.php 41KB

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