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

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