Oppaitime'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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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)?></h2>
  98. </div>
  99. <table width="100%" class="layout box">
  100. <tr class="colhead"><td id="sorting_head">Sorting</td></tr>
  101. <tr>
  102. <td id="drag_drop_textnote">
  103. <ul>
  104. <li>Click on the headings to organize columns automatically.</li>
  105. <li>Sort multiple columns simultaneously by holding down the shift key and clicking other column headers.</li>
  106. <li>Click and drag any row to change its order.</li>
  107. <li>Double-click on a row to check it.</li>
  108. </ul>
  109. </td>
  110. </tr>
  111. </table>
  112. <form action="bookmarks.php" method="post" id="drag_drop_collage_form">
  113. <?php $this->buttons(); ?>
  114. <table id="manage_collage_table" class="box">
  115. <thead>
  116. <tr class="colhead">
  117. <th style="width: 7%;" data-sorter="false">Order</th>
  118. <th style="width: 1%;"><span><abbr class="tooltip" title="Current order">#</abbr></span></th>
  119. <th style="width: 1%;"><span>Year</span></th>
  120. <th style="width: 15%;" data-sorter="ignoreArticles"><span>Artist</span></th>
  121. <th data-sorter="ignoreArticles"><span>Torrent</span></th>
  122. <th style="width: 5%;" data-sorter="relativeTime"><span>Bookmarked</span></th>
  123. <th style="width: 1%;" id="check_all" data-sorter="false"><span>Remove</span></th>
  124. </tr>
  125. </thead>
  126. <tbody>
  127. <?php
  128. }
  129. }
  130. /**
  131. * Closes header code
  132. */
  133. public function footer()
  134. {
  135. if ($this->HasTorrents) {
  136. ?>
  137. </tbody>
  138. </table>
  139. <?php $this->buttons(); ?>
  140. <div>
  141. <input type="hidden" name="action" value="mass_edit" />
  142. <input type="hidden" name="type" value="<?=display_str($this->EditType)?>" />
  143. <input type="hidden" name="auth" value="<?=G::$LoggedUser['AuthKey']?>" />
  144. </div>
  145. </form>
  146. </div>
  147. <?php
  148. }
  149. }
  150. /**
  151. * Formats data for use in row
  152. *
  153. */
  154. public function body()
  155. {
  156. if ($this->HasTorrents) {
  157. foreach ($this->TorrentList as $GroupID => $Group) {
  158. $Artists = [];
  159. extract($Group);
  160. extract($this->CollageDataList[$GroupID]);
  161. $this->NumGroups++;
  162. $DisplayName = self::display_name($ExtendedArtists, $Artists, $VanityHouse);
  163. $TorrentLink = '<a href="torrents.php?id='.$GroupID.'" class="tooltip" title="View torrent">'.$Name.'</a>';
  164. $Year = $Year > 0 ? $Year : '';
  165. $DateAdded = date($Time);
  166. $this->row($Sort, $GroupID, $Year, $DisplayName, $TorrentLink, $DateAdded);
  167. }
  168. }
  169. }
  170. /**
  171. * Outputs a single row
  172. *
  173. * @param string|int $Sort
  174. * @param string|int $GroupID
  175. * @param string|int $GroupYear
  176. * @param string $DisplayName
  177. * @param string $TorrentLink
  178. */
  179. public function row($Sort, $GroupID, $GroupYear, $DisplayName, $TorrentLink, $DateAdded)
  180. {
  181. ?>
  182. <tr class="drag row" id="li_<?=$GroupID?>">
  183. <td>
  184. <input class="sort_numbers" type="text" name="sort[<?=$GroupID?>]" value="<?=$Sort?>" id="sort_<?=$GroupID?>" size="4" />
  185. </td>
  186. <td><?=$this->NumGroups?></td>
  187. <td><?=$GroupYear ? trim($GroupYear) : ' '?></td>
  188. <td><?=$DisplayName ? trim($DisplayName) : ' '?></td>
  189. <td><?=$TorrentLink ? trim($TorrentLink) : ' '?></td>
  190. <td class="nobr tooltip" title="<?=$DateAdded?>"><?=$DateAdded ? time_diff($DateAdded) : ' '?></td>
  191. <td class="center"><input type="checkbox" name="remove[<?=$GroupID?>]" value="" /></td>
  192. </tr>
  193. <?php
  194. }
  195. /**
  196. * Parses a simple display name
  197. *
  198. * @param array $ExtendedArtists
  199. * @param array $Artists
  200. * @param string $VanityHouse
  201. * @return string $DisplayName
  202. */
  203. public static function display_name(array &$ExtendedArtists, array &$Artists, $VanityHouse)
  204. {
  205. $DisplayName = '';
  206. if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4])
  207. || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
  208. unset($ExtendedArtists[2], $ExtendedArtists[3]);
  209. $DisplayName = Artists::display_artists($ExtendedArtists, true, false);
  210. } elseif (count($Artists) > 0) {
  211. $DisplayName = Artists::display_artists(array('1'=>$Artists), true, false);
  212. }
  213. if ($VanityHouse) {
  214. $DisplayName .= ' [<abbr class="tooltip" title="This is a Vanity House release">VH</abbr>]';
  215. }
  216. return $DisplayName;
  217. }
  218. /**
  219. * Renders buttons used at the top and bottom of the table
  220. */
  221. public function buttons()
  222. {
  223. ?>
  224. <div class="drag_drop_save">
  225. <input type="submit" name="update" value="Update ranking" title="Save your rank" class="tooltip save_sortable_collage" />
  226. <input type="submit" name="delete" value="Delete checked" title="Remove items" class="tooltip save_sortable_collage" />
  227. </div>
  228. <?php
  229. }
  230. /**
  231. * @param string $EditType
  232. */
  233. public function set_edit_type($EditType)
  234. {
  235. $this->EditType = $EditType;
  236. }
  237. /**
  238. * Set's the current page's heading
  239. * @param string $Heading
  240. */
  241. public function set_heading($Heading)
  242. {
  243. $this->Heading = $Heading;
  244. }
  245. }