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.

mass_user_torrents_table_view.class.php 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?php
  2. declare(strict_types = 1);
  3. /**
  4. * This class outputs a table that can be used to sort torrents through a drag/drop
  5. * interface, an automatic column sorter, or manual imput.
  6. *
  7. * It places checkboxes to delete items.
  8. *
  9. * (It creates a div#thin.)
  10. *
  11. * It can be used for Bookmarks, Collages, or anywhere where torrents are managed.
  12. */
  13. class MASS_USER_TORRENTS_TABLE_VIEW
  14. {
  15. /**
  16. * Used to set text the page heading (h2 tag)
  17. * @var string $Heading
  18. */
  19. private $Heading = 'Manage Torrents';
  20. /**
  21. * Sets the value of the input name="type"
  22. * Later to be used as $_POST['type'] in a form processor
  23. * @var string $EditType
  24. */
  25. private $EditType;
  26. /**
  27. * Flag for empty $TorrentList
  28. * @var bool $HasTorrentList
  29. */
  30. private $HasTorrents;
  31. /**
  32. * Internal reference to the TorrentList
  33. * @var array $TorrentList
  34. */
  35. private $TorrentList;
  36. /**
  37. * Ref. to $CollageDataList
  38. * @var array $CollageDataList
  39. */
  40. private $CollageDataList;
  41. /**
  42. * Counter for number of groups
  43. * @var in $NumGroups
  44. */
  45. private $NumGroups = 0;
  46. /**
  47. * When creating a new instance of this class, TorrentList and
  48. * CollageDataList must be passed. Additionally, a heading can be added.
  49. *
  50. * @param array $TorrentList
  51. * @param array $CollageDataList
  52. * @param string $EditType
  53. * @param string $Heading
  54. */
  55. public function __construct(array &$TorrentList, array &$CollageDataList, $EditType, $Heading = null)
  56. {
  57. $this->set_heading($Heading);
  58. $this->set_edit_type($EditType);
  59. $this->TorrentList = $TorrentList;
  60. $this->CollageDataList = $CollageDataList;
  61. $this->HasTorrents = !empty($TorrentList);
  62. if (!$this->HasTorrents) {
  63. $this->no_torrents();
  64. }
  65. }
  66. private function no_torrents()
  67. { ?>
  68. <div>
  69. <div class="header">
  70. <h2>No torrents found</h2>
  71. </div>
  72. <div class="box pad" align="center">
  73. <p>Add some torrents and come back later</p>
  74. </div>
  75. </div>
  76. <?php
  77. }
  78. /**
  79. * Renders a complete page and table
  80. */
  81. public function render_all()
  82. {
  83. $this->header();
  84. $this->body();
  85. $this->footer();
  86. }
  87. /**
  88. * Renders a comptele page/table header: div#thin, h2, scripts, notes,
  89. * form, table, etc.
  90. */
  91. public function header()
  92. {
  93. if ($this->HasTorrents) { ?>
  94. <div>
  95. <div class="header">
  96. <h2><?=display_str($this->Heading)?>
  97. </h2>
  98. </div>
  99. <table width="100%" class="layout box">
  100. <tr class="colhead">
  101. <td id="sorting_head">Sorting</td>
  102. </tr>
  103. <tr>
  104. <td id="drag_drop_textnote">
  105. <ul>
  106. <li>Click on the headings to organize columns automatically.</li>
  107. <li>Sort multiple columns simultaneously by holding down the shift key and clicking other column headers.</li>
  108. <li>Click and drag any row to change its order.</li>
  109. <li>Double-click on a row to check it.</li>
  110. </ul>
  111. </td>
  112. </tr>
  113. </table>
  114. <form action="bookmarks.php" method="post" id="drag_drop_collage_form">
  115. <?php $this->buttons(); ?>
  116. <table id="manage_collage_table" class="box">
  117. <thead>
  118. <tr class="colhead">
  119. <th style="width: 7%;" data-sorter="false">Order</th>
  120. <th style="width: 1%;"><span><abbr class="tooltip" title="Current order">#</abbr></span></th>
  121. <th style="width: 1%;"><span>Year</span></th>
  122. <th style="width: 15%;" data-sorter="ignoreArticles"><span>Artist</span></th>
  123. <th data-sorter="ignoreArticles"><span>Torrent</span></th>
  124. <th style="width: 5%;" data-sorter="relativeTime"><span>Bookmarked</span></th>
  125. <th style="width: 1%;" id="check_all" data-sorter="false"><span>Remove</span></th>
  126. </tr>
  127. </thead>
  128. <tbody>
  129. <?php
  130. }
  131. }
  132. /**
  133. * Closes header code
  134. */
  135. public function footer()
  136. {
  137. if ($this->HasTorrents) { ?>
  138. </tbody>
  139. </table>
  140. <?php $this->buttons(); ?>
  141. <div>
  142. <input type="hidden" name="action" value="mass_edit" />
  143. <input type="hidden" name="type"
  144. value="<?=display_str($this->EditType)?>" />
  145. <input type="hidden" name="auth"
  146. value="<?=G::$LoggedUser['AuthKey']?>" />
  147. </div>
  148. </form>
  149. </div>
  150. <?php
  151. }
  152. }
  153. /**
  154. * Formats data for use in row
  155. *
  156. */
  157. public function body()
  158. {
  159. if ($this->HasTorrents) {
  160. foreach ($this->TorrentList as $GroupID => $Group) {
  161. $Artists = [];
  162. extract($Group);
  163. extract($this->CollageDataList[$GroupID]);
  164. $this->NumGroups++;
  165. $DisplayName = self::display_name($ExtendedArtists, $Artists, $VanityHouse);
  166. $TorrentLink = '<a href="torrents.php?id='.$GroupID.'" class="tooltip" title="View torrent">'.$Name.'</a>';
  167. $Year = $Year > 0 ? $Year : '';
  168. $DateAdded = date($Time);
  169. $this->row($Sort, $GroupID, $Year, $DisplayName, $TorrentLink, $DateAdded);
  170. }
  171. }
  172. }
  173. /**
  174. * Outputs a single row
  175. *
  176. * @param string|int $Sort
  177. * @param string|int $GroupID
  178. * @param string|int $GroupYear
  179. * @param string $DisplayName
  180. * @param string $TorrentLink
  181. */
  182. public function row($Sort, $GroupID, $GroupYear, $DisplayName, $TorrentLink, $DateAdded)
  183. { ?>
  184. <tr class="drag row" id="li_<?=$GroupID?>">
  185. <td>
  186. <input class="sort_numbers" type="text"
  187. name="sort[<?=$GroupID?>]"
  188. value="<?=$Sort?>"
  189. id="sort_<?=$GroupID?>" size="4" />
  190. </td>
  191. <td>
  192. <?=$this->NumGroups?>
  193. </td>
  194. <td>
  195. <?=$GroupYear ? trim($GroupYear) : ' '?>
  196. </td>
  197. <td>
  198. <?=$DisplayName ? trim($DisplayName) : ' '?>
  199. </td>
  200. <td>
  201. <?=$TorrentLink ? trim($TorrentLink) : ' '?>
  202. </td>
  203. <td class="nobr tooltip" title="<?=$DateAdded?>">
  204. <?=$DateAdded ? time_diff($DateAdded) : ' '?>
  205. </td>
  206. <td class="center">
  207. <input type="checkbox" name="remove[<?=$GroupID?>]" value="" />
  208. </td>
  209. </tr>
  210. <?php
  211. }
  212. /**
  213. * Parses a simple display name
  214. *
  215. * @param array $ExtendedArtists
  216. * @param array $Artists
  217. * @param string $VanityHouse
  218. * @return string $DisplayName
  219. */
  220. public static function display_name(array &$ExtendedArtists, array &$Artists, $VanityHouse)
  221. {
  222. $DisplayName = '';
  223. if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4])
  224. || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
  225. unset($ExtendedArtists[2], $ExtendedArtists[3]);
  226. $DisplayName = Artists::display_artists($ExtendedArtists, true, false);
  227. } elseif (count($Artists) > 0) {
  228. $DisplayName = Artists::display_artists(array('1'=>$Artists), true, false);
  229. }
  230. if ($VanityHouse) {
  231. $DisplayName .= ' [<abbr class="tooltip" title="This is a Vanity House release">VH</abbr>]';
  232. }
  233. return $DisplayName;
  234. }
  235. /**
  236. * Renders buttons used at the top and bottom of the table
  237. */
  238. public function buttons()
  239. { ?>
  240. <div class="drag_drop_save">
  241. <input type="submit" name="update" value="Update ranking" title="Save your rank"
  242. class="tooltip save_sortable_collage" />
  243. <input type="submit" name="delete" value="Delete checked" title="Remove items"
  244. class="tooltip save_sortable_collage" />
  245. </div>
  246. <?php
  247. }
  248. /**
  249. * @param string $EditType
  250. */
  251. public function set_edit_type($EditType)
  252. {
  253. $this->EditType = $EditType;
  254. }
  255. /**
  256. * Set's the current page's heading
  257. * @param string $Heading
  258. */
  259. public function set_heading($Heading)
  260. {
  261. $this->Heading = $Heading;
  262. }
  263. }