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

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