PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/files/lib/acp/page/AdminToolsLostAndFoundPage.class.php

https://github.com/TacHawkes/net.hawkes.admintools
PHP | 314 lines | 240 code | 17 blank | 57 comment | 53 complexity | 76385c6b0bc32985e93522c9c8a4b21a MD5 | raw file
  1. <?php
  2. /**
  3. * This file is part of Admin Tools 2.
  4. *
  5. * Admin Tools 2 is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Admin Tools 2 is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Admin Tools 2. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. *
  19. */
  20. require_once(WCF_DIR.'lib/page/SortablePage.class.php');
  21. /**
  22. * The page for handling lost and found items. Backups, attachments and avatars are harcodet. Further functions can be used via event listeners
  23. *
  24. * @author Oliver Kliebisch
  25. * @copyright 2009 Oliver Kliebisch
  26. * @license GNU General Public License <http://www.gnu.org/licenses/>
  27. * @package net.hawkes.admintools
  28. * @subpackage acp.page
  29. * @category WCF
  30. */
  31. class AdminToolsLostAndFoundPage extends SortablePage {
  32. public $activeMenuItem = 'wcf.acp.menu.link.admintools.lostandfound';
  33. public $templateName = 'adminToolsLostAndFound';
  34. public $activeTabMenuItem = 'backup';
  35. public $activeSubTabMenuItem = 'database';
  36. public $markedItems = 0;
  37. public $itemsPerPage = 20;
  38. public $pageNo = 1;
  39. public $classname = '';
  40. public $count = 0;
  41. /**
  42. * The object array storing the lost and found items
  43. *
  44. * @var array<MarkableLostAndFoundItem>
  45. */
  46. public $itemData = array();
  47. /**
  48. * @see Page::readParameters()
  49. */
  50. public function readParameters() {
  51. parent::readParameters();
  52. if (isset($_GET['activeTabMenuItem'])) $this->activeTabMenuItem = StringUtil::trim($_GET['activeTabMenuItem']);
  53. if (isset($_GET['activeSubTabMenuItem'])) $this->activeSubTabMenuItem = StringUtil::trim($_GET['activeSubTabMenuItem']);
  54. }
  55. /**
  56. * @see Page::readData()
  57. */
  58. public function readData() {
  59. $functionName = 'read'.ucfirst($this->activeTabMenuItem);
  60. if (method_exists($this, $functionName)) {
  61. $this->{$functionName}();
  62. }
  63. parent::readData();
  64. }
  65. /**
  66. * Reads the backup items
  67. */
  68. protected function readBackup() {
  69. $this->activeSubTabMenuItem = 'filesystem';
  70. require_once(WCF_DIR.'lib/acp/admintools/lostandfound/BackupFilesystemLostAndFoundItem.class.php');
  71. BackupFilesystemLostAndFoundItem::createVirtualIDSpace();
  72. $this->markedItems = intval(count(BackupFilesystemLostAndFoundItem::getMarkedItems('backupFilesystem')));
  73. $this->classname = 'BackupFilesystemLostAndFoundItem';
  74. chdir(WCF_DIR.'acp/backup');
  75. $dh= opendir(WCF_DIR.'acp/backup');
  76. if (!$dh) {
  77. $this->count = 0;
  78. return;
  79. }
  80. $i=0;
  81. while ($file = readdir ($dh)) {
  82. if ($file != '.' && $file != '..' && $file != '.htaccess' && !is_dir($file)) {
  83. if (($i < ($this->pageNo-1)*$this->itemsPerPage) || ($i > $this->pageNo*$this->itemsPerPage)) {
  84. $i++;
  85. continue;
  86. }
  87. $backup = new BackupFilesystemLostAndFoundItem(BackupFilesystemLostAndFoundItem::getVirtualID('backupFilesystem', $file));
  88. $backup->filename = $file;
  89. $backup->filesize = round((filesize($file) / 1000),2).' kB';
  90. $backup->fileLastModTime = filemtime($file);
  91. $this->itemData[] = $backup;
  92. $i++;
  93. }
  94. }
  95. closedir($dh);
  96. $this->count = $i;
  97. }
  98. /**
  99. * Reads attachment items
  100. */
  101. public function readAttachments() {
  102. switch ($this->activeSubTabMenuItem) {
  103. case 'database' :
  104. require_once(WCF_DIR.'lib/acp/admintools/lostandfound/AttachmentsDatabaseLostAndFoundItem.class.php');
  105. $this->markedItems = intval(count(AttachmentsDatabaseLostAndFoundItem::getMarkedItems('attachmentsDatabase')));
  106. $this->classname = 'AttachmentsDatabaseLostAndFoundItem';
  107. $sql = "SELECT
  108. attachment.*, user.username
  109. FROM
  110. wcf".WCF_N."_attachment attachment
  111. LEFT JOIN
  112. wcf".WCF_N."_user user
  113. ON (user.userID = attachment.userID)";
  114. $result = WCF::getDB()->sendQuery($sql);
  115. $i = 0;
  116. while ($row = WCF::getDB()->fetchArray($result)) {
  117. if (!is_file(WCF_DIR.'attachments/attachment-'.$row['attachmentID'])) {
  118. if (($i < ($this->pageNo-1)*$this->itemsPerPage) || ($i > $this->pageNo*$this->itemsPerPage)) {
  119. $i++;
  120. continue;
  121. }
  122. $attachment = new AttachmentsDatabaseLostAndFoundItem($row['attachmentID']);
  123. $attachment->filename = $row['attachmentName'];
  124. $attachment->filesize = round((($row['attachmentSize']) / 1000),2).' kB';
  125. $attachment->fileLastModTime = $row['uploadTime'];
  126. $attachment->user = $row['username'];
  127. $this->itemData[] = $attachment;
  128. }
  129. }
  130. $this->count = $i;
  131. break;
  132. case 'filesystem' :
  133. require_once(WCF_DIR.'lib/acp/admintools/lostandfound/AttachmentsFilesystemLostAndFoundItem.class.php');
  134. AttachmentsFilesystemLostAndFoundItem::createVirtualIDSpace();
  135. $this->markedItems = intval(count(AttachmentsFilesystemLostAndFoundItem::getMarkedItems('attachmentsFilesystem')));
  136. $this->classname = 'AttachmentsFilesystemLostAndFoundItem';
  137. chdir(WCF_DIR.'attachments');
  138. $dh=opendir(WCF_DIR.'attachments');
  139. $attachmentIDs = array();
  140. while ($file = readdir ($dh)) {
  141. if (preg_match("/^(attachment|thumbnail).*/",$file) && $file != '.' && $file != '..' && $file != '.htaccess' && !preg_match("/^.*\.php$/",$file)) {
  142. $attachmentID = (int) preg_replace("/.*\-(\d+)$/", "$1", $file);
  143. if ($attachmentID > 0) {
  144. $attachmentIDs[] = $attachmentID;
  145. }
  146. }
  147. }
  148. if (count($attachmentIDs)) {
  149. $sql = "SELECT
  150. attachmentID
  151. FROM
  152. wcf".WCF_N."_attachment
  153. WHERE
  154. attachmentID IN (".implode(',', $attachmentIDs).")";
  155. $result = WCF::getDB()->sendQuery($sql);
  156. $physicalAttachments = array_flip($attachmentIDs);
  157. while ($row = WCF::getDB()->fetchArray($result)) {
  158. unset($physicalAttachments[$row['attachmentID']]);
  159. }
  160. $physicalAttachments = array_keys($physicalAttachments);
  161. $this->count = count($physicalAttachments);
  162. $i = 0;
  163. foreach($physicalAttachments as $attachmentID) {
  164. if (($i < ($this->pageNo-1)*$this->itemsPerPage) || ($i > $this->pageNo*$this->itemsPerPage)) {
  165. $i++;
  166. continue;
  167. }
  168. $file = WCF_DIR.'attachments/attachment-'.$attachmentID;
  169. $attachment = new AttachmentsFilesystemLostAndFoundItem(AttachmentsFilesystemLostAndFoundItem::getVirtualID('attachmentsFilesystem', $file));
  170. $attachment->filename = $file;
  171. $attachment->filesize = round((filesize($file) / 1000),2).' kB';
  172. $attachment->fileLastModTime = filemtime($file);
  173. $this->itemData[] = $attachment;
  174. $i++;
  175. }
  176. }
  177. closedir($dh);
  178. break;
  179. }
  180. }
  181. /**
  182. * Reads avatar items
  183. */
  184. public function readAvatars() {
  185. switch ($this->activeSubTabMenuItem) {
  186. case 'database' :
  187. require_once(WCF_DIR.'lib/acp/admintools/lostandfound/AvatarsDatabaseLostAndFoundItem.class.php');
  188. $this->markedItems = intval(count(AvatarsDatabaseLostAndFoundItem::getMarkedItems('avatarsDatabase')));
  189. $this->classname = 'AvatarsDatabaseLostAndFoundItem';
  190. $sql = "SELECT
  191. avatar.*,
  192. user.username
  193. FROM
  194. wcf".WCF_N."_avatar avatar
  195. LEFT JOIN
  196. wcf".WCF_N."_user user
  197. ON (user.userID = avatar.userID)";
  198. $result = WCF::getDB()->sendQuery($sql);
  199. $i = 0;
  200. while ($row = WCF::getDB()->fetchArray($result)) {
  201. if (!is_file(WCF_DIR.'images/avatars/avatar-'.$row['avatarID'].'.'.$row['avatarExtension'])) {
  202. if (($i < ($this->pageNo-1)*$this->itemsPerPage) || ($i > $this->pageNo*$this->itemsPerPage)) {
  203. $i++;
  204. continue;
  205. }
  206. $avatar = new AvatarsDatabaseLostAndFoundItem($row['avatarID']);
  207. $avatar->filename = $row['avatarName'];
  208. $avatar->user = $row['username'];
  209. $this->itemData[] = $avatar;
  210. $i++;
  211. }
  212. }
  213. $this->count = $i;
  214. break;
  215. case 'filesystem' :
  216. require_once(WCF_DIR.'lib/acp/admintools/lostandfound/AvatarsFilesystemLostAndFoundItem.class.php');
  217. AvatarsFilesystemLostAndFoundItem::createVirtualIDSpace();
  218. $this->markedItems = intval(count(AvatarsFilesystemLostAndFoundItem::getMarkedItems('avatarsFilesystem')));
  219. $this->classname = 'AvatarsFilesystemLostAndFoundItem';
  220. chdir(WCF_DIR.'images/avatars');
  221. $dh=opendir(WCF_DIR.'images/avatars');
  222. $avatarIDs = array();
  223. $avatars = array();
  224. while ($file = readdir ($dh)) {
  225. if (preg_match("/^(avatar).*/",$file) && $file != '.' && $file != '..' && $file != '.htaccess' && !preg_match("/^.*\.php$/",$file)) {
  226. $avatarID = (int) preg_replace("/.*\-(\d+).*/", "$1", $file);
  227. $avatars[$avatarID] = preg_replace("/.*\-(\d+)(.*)/", "$2", $file);
  228. if ($avatarID > 0) {
  229. $avatarIDs[] = $avatarID;
  230. }
  231. }
  232. }
  233. if (count($avatarIDs)) {
  234. $sql = "SELECT
  235. avatarID,
  236. avatarExtension
  237. FROM
  238. wcf".WCF_N."_avatar
  239. WHERE
  240. avatarID IN (".implode(',', $avatarIDs).")";
  241. $result = WCF::getDB()->sendQuery($sql);
  242. $physicalAvatars = array_flip($avatarIDs);
  243. while ($row = WCF::getDB()->fetchArray($result)) {
  244. unset($physicalAvatars[$row['avatarID']]);
  245. }
  246. $physicalAvatars = array_keys($physicalAvatars);
  247. $this->count = count($physicalAvatars);
  248. $i = 0;
  249. foreach($physicalAvatars as $avatarID) {
  250. if ($i <= ($this->pageNo-1)*$this->itemsPerPage) {
  251. $i++;
  252. continue;
  253. }
  254. else if ($i > $this->pageNo*$this->itemsPerPage) break;
  255. $file = WCF_DIR.'images/avatars/avatar-'.$avatarID.$avatars[$avatarID];
  256. $avatar = new AvatarsFilesystemLostAndFoundItem(AvatarsFilesystemLostAndFoundItem::getVirtualID('avatarsFilesystem', $file));
  257. $avatar->filename = $file;
  258. $avatar->filesize = round((filesize($file) / 1000),2).' kB';
  259. $avatar->fileLastModTime = filemtime($file);
  260. $this->itemData[] = $avatar;
  261. $i++;
  262. }
  263. }
  264. closedir($dh);
  265. break;
  266. }
  267. }
  268. /**
  269. * @see Page::assignVariables()
  270. */
  271. public function assignVariables() {
  272. parent::assignVariables();
  273. WCF::getTPL()->assign(array('activeTabMenuItem' => $this->activeTabMenuItem,
  274. 'activeSubTabMenuItem' => $this->activeSubTabMenuItem,
  275. 'markedItems' => $this->markedItems,
  276. 'defaultSortField' => $this->defaultSortField,
  277. 'defaultSortOrder' => $this->defaultSortOrder,
  278. 'classname' => $this->classname,
  279. 'itemData' => $this->itemData));
  280. }
  281. /**
  282. * @see Page::show()
  283. */
  284. public function show() {
  285. WCF::getUser()->checkPermission('admin.system.admintools.canView');
  286. WCFACP::getMenu()->setActiveMenuItem($this->activeMenuItem);
  287. parent::show();
  288. }
  289. /**
  290. * @see MultipleLinkPage::countItems()
  291. */
  292. public function countItems() {
  293. parent::countItems();
  294. return $this->count;
  295. }
  296. }
  297. ?>