PageRenderTime 43ms CodeModel.GetById 72ms RepoModel.GetById 6ms app.codeStats 0ms

/concrete/tools/files/properties.php

https://github.com/markdev/markandkitty
PHP | 460 lines | 379 code | 79 blank | 2 comment | 67 complexity | eb3a9d2a9c9f98027289b917f063f8e2 MD5 | raw file
  1. <?php
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. $u = new User();
  4. $form = Loader::helper('form');
  5. Loader::model("file_attributes");
  6. $previewMode = false;
  7. $f = File::getByID($_REQUEST['fID']);
  8. $fp = new Permissions($f);
  9. if (!$fp->canRead()) {
  10. die(_("Access Denied."));
  11. }
  12. if (isset($_REQUEST['fvID'])) {
  13. $fv = $f->getVersion($_REQUEST['fvID']);
  14. } else {
  15. $fv = $f->getApprovedVersion();
  16. }
  17. if ($_REQUEST['task'] == 'preview_version') {
  18. $previewMode = true;
  19. }
  20. if ($_POST['task'] == 'approve_version' && $fp->canWrite() && (!$previewMode)) {
  21. $fv->approve();
  22. exit;
  23. }
  24. if ($_POST['task'] == 'delete_version' && $fp->canAdmin() && (!$previewMode)) {
  25. $fv->delete();
  26. exit;
  27. }
  28. if ($_POST['task'] == 'update_core' && $fp->canWrite() && (!$previewMode)) {
  29. $fv = $f->getVersionToModify();
  30. switch($_POST['attributeField']) {
  31. case 'fvTitle':
  32. $text = $_POST['fvTitle'];
  33. $fv->updateTitle($text);
  34. print $text;
  35. break;
  36. case 'fvDescription':
  37. $text = $_POST['fvDescription'];
  38. $fv->updateDescription($text);
  39. print $text;
  40. break;
  41. case 'fvTags':
  42. $text = $_POST['fvTags'];
  43. $fv->updateTags($text);
  44. print $text;
  45. break;
  46. }
  47. exit;
  48. }
  49. if ($_POST['task'] == 'update_extended_attribute' && $fp->canWrite() && (!$previewMode)) {
  50. $fv = $f->getVersionToModify();
  51. $fakID = $_REQUEST['fakID'];
  52. $value = '';
  53. $ak = FileAttributeKey::get($fakID);
  54. $ak->saveAttributeForm($fv);
  55. $val = $fv->getAttributeValueObject($ak);
  56. print $val->getValue('display');
  57. exit;
  58. }
  59. if ($_POST['task'] == 'clear_extended_attribute' && $fp->canWrite() && (!$previewMode)) {
  60. $fv = $f->getVersionToModify();
  61. $fakID = $_REQUEST['fakID'];
  62. $value = '';
  63. $ak = FileAttributeKey::get($fakID);
  64. $fv->clearAttribute($ak);
  65. $val = $fv->getAttributeValueObject($ak);
  66. print '<div class="ccm-attribute-field-none">' . t('None') . '</div>';
  67. exit;
  68. }
  69. function printCorePropertyRow($title, $field, $value, $formText) {
  70. global $previewMode, $f, $fp;
  71. if ($value == '') {
  72. $text = '<div class="ccm-attribute-field-none">' . t('None') . '</div>';
  73. } else {
  74. $text = htmlentities( $value, ENT_QUOTES, APP_CHARSET);
  75. }
  76. if ($fp->canWrite() && (!$previewMode)) {
  77. $html = '
  78. <tr class="ccm-attribute-editable-field">
  79. <th><a href="javascript:void(0)">' . $title . '</a></th>
  80. <td width="100%" class="ccm-attribute-editable-field-central"><div class="ccm-attribute-editable-field-text">' . $text . '</div>
  81. <form method="post" action="' . REL_DIR_FILES_TOOLS_REQUIRED . '/files/properties">
  82. <input type="hidden" name="attributeField" value="' . $field . '" />
  83. <input type="hidden" name="fID" value="' . $f->getFileID() . '" />
  84. <input type="hidden" name="task" value="update_core" />
  85. <div class="ccm-attribute-editable-field-form ccm-attribute-editable-field-type-text">
  86. ' . $formText . '
  87. </div>
  88. </form>
  89. </td>
  90. <td class="ccm-attribute-editable-field-save"><a href="javascript:void(0)"><img src="' . ASSETS_URL_IMAGES . '/icons/edit_small.png" width="16" height="16" class="ccm-attribute-editable-field-save-button" /></a>
  91. <img src="' . ASSETS_URL_IMAGES . '/throbber_white_16.gif" width="16" height="16" class="ccm-attribute-editable-field-loading" />
  92. </td>
  93. </tr>';
  94. } else {
  95. $html = '
  96. <tr>
  97. <th>' . $title . '</th>
  98. <td width="100%" colspan="2">' . $text . '</td>
  99. </tr>';
  100. }
  101. print $html;
  102. }
  103. function printFileAttributeRow($ak, $fv) {
  104. global $previewMode, $f, $fp;
  105. $vo = $fv->getAttributeValueObject($ak);
  106. $value = '';
  107. if (is_object($vo)) {
  108. $value = $vo->getValue('display');
  109. }
  110. if ($value == '') {
  111. $text = '<div class="ccm-attribute-field-none">' . t('None') . '</div>';
  112. } else {
  113. $text = $value;
  114. }
  115. if ($ak->isAttributeKeyEditable() && $fp->canWrite() && (!$previewMode)) {
  116. $type = $ak->getAttributeType();
  117. $html = '
  118. <tr class="ccm-attribute-editable-field">
  119. <th><a href="javascript:void(0)">' . $ak->getAttributeKeyName() . '</a></th>
  120. <td width="100%" class="ccm-attribute-editable-field-central"><div class="ccm-attribute-editable-field-text">' . $text . '</div>
  121. <form method="post" action="' . REL_DIR_FILES_TOOLS_REQUIRED . '/files/properties">
  122. <input type="hidden" name="fakID" value="' . $ak->getAttributeKeyID() . '" />
  123. <input type="hidden" name="fID" value="' . $f->getFileID() . '" />
  124. <input type="hidden" name="task" value="update_extended_attribute" />
  125. <div class="ccm-attribute-editable-field-form ccm-attribute-editable-field-type-' . strtolower($type->getAttributeTypeHandle()) . '">
  126. ' . $ak->render('form', $vo, true) . '
  127. </div>
  128. </form>
  129. </td>
  130. <td class="ccm-attribute-editable-field-save"><a href="javascript:void(0)"><img src="' . ASSETS_URL_IMAGES . '/icons/edit_small.png" width="16" height="16" class="ccm-attribute-editable-field-save-button" /></a>
  131. <a href="javascript:void(0)"><img src="' . ASSETS_URL_IMAGES . '/icons/close.png" width="16" height="16" class="ccm-attribute-editable-field-clear-button" /></a>
  132. <img src="' . ASSETS_URL_IMAGES . '/throbber_white_16.gif" width="16" height="16" class="ccm-attribute-editable-field-loading" />
  133. </td>
  134. </tr>';
  135. } else {
  136. $html = '
  137. <tr>
  138. <th>' . $ak->getAttributeKeyName() . '</th>
  139. <td width="100%" colspan="2">' . $text . '</td>
  140. </tr>';
  141. }
  142. print $html;
  143. }
  144. if (!isset($_REQUEST['reload'])) { ?>
  145. <div id="ccm-file-properties-wrapper">
  146. <?php } ?>
  147. <div class="ccm-file-properties-tabs" id="ccm-file-properties-tab-<?php echo $f->getFileID()?>-<?php echo $fv->getFileVersionID()?>">
  148. <ul class="ccm-dialog-tabs">
  149. <li class="ccm-nav-active"><a href="javascript:void(0)" id="ccm-file-properties-details-<?php echo $f->getFileID()?>-<?php echo $fv->getFileVersionID()?>"><?php echo t('Details')?></a></li>
  150. <?php if (!$previewMode) { ?>
  151. <li><a href="javascript:void(0)" id="ccm-file-properties-versions-<?php echo $f->getFileID()?>-<?php echo $fv->getFileVersionID()?>"><?php echo t('Versions')?></a></li>
  152. <?php } ?>
  153. <li><a href="javascript:void(0)" id="ccm-file-properties-statistics-<?php echo $f->getFileID()?>-<?php echo $fv->getFileVersionID()?>"><?php echo t('Statistics')?></a></li>
  154. </ul>
  155. <script type="text/javascript">
  156. //var ccm_fiActiveTab = "ccm-file-properties-details-<?php echo $f->getFileID()?>-<?php echo $fv->getFileVersionID()?>";
  157. $("#ccm-file-properties-tab-<?php echo $f->getFileID()?>-<?php echo $fv->getFileVersionID()?> ul a").click(function() {
  158. $("#ccm-file-properties-tab-<?php echo $f->getFileID()?>-<?php echo $fv->getFileVersionID()?> li").removeClass('ccm-nav-active');
  159. $("#ccm-file-properties-tab-<?php echo $f->getFileID()?>-<?php echo $fv->getFileVersionID()?> .ccm-file-properties-details-tab").hide();
  160. $(this).parent().addClass("ccm-nav-active");
  161. $('#' + $(this).attr('id') + '-tab').show();
  162. });
  163. </script>
  164. <div class="ccm-file-properties-details-tab" id="ccm-file-properties-details-<?php echo $f->getFileID()?>-<?php echo $fv->getFileVersionID()?>-tab">
  165. <?php
  166. if (!$previewMode) {
  167. $h = Loader::helper('concrete/interface');
  168. $b1 = $h->button_js(t('Rescan'), 'ccm_alRescanFiles(' . $f->getFileID() . ')');
  169. print $b1;
  170. }
  171. ?>
  172. <h1><?php echo t('File Details')?></h1>
  173. <div id="ccm-file-properties">
  174. <h2><?php echo t('Basic Properties')?></h2>
  175. <table border="0" cellspacing="0" cellpadding="0" class="ccm-grid">
  176. <tr>
  177. <th><?php echo t('ID')?></th>
  178. <td width="100%" colspan="2"><?php echo $fv->getFileID()?> <span style="color: #afafaf">(<?php echo t('Version')?> <?php echo $fv->getFileVersionID()?>)</span></td>
  179. </tr>
  180. <tr>
  181. <th><?php echo t('Filename')?></th>
  182. <td width="100%" colspan="2"><?php echo $fv->getFileName()?></td>
  183. </tr>
  184. <tr>
  185. <th><?php echo t('URL to File')?></th>
  186. <td width="100%" colspan="2"><?php echo $fv->getRelativePath(true)?></td>
  187. </tr>
  188. <?php
  189. $oc = $f->getOriginalPageObject();
  190. if (is_object($oc)) {
  191. $fileManager = Page::getByPath('/dashboard/files/search');
  192. $ocName = $oc->getCollectionName();
  193. if (is_object($fileManager) && !$fileManager->isError()) {
  194. if ($fileManager->getCollectionID() == $oc->getCollectionID()) {
  195. $ocName = t('Dashboard File Manager');
  196. }
  197. }
  198. ?>
  199. <tr>
  200. <th><?php echo t('Page Added To')?></th>
  201. <td width="100%" colspan="2"><a href="<?php echo Loader::helper('navigation')->getLinkToCollection($oc)?>" target="_blank"><?php echo $ocName?></a></td>
  202. </tr>
  203. <?php } ?>
  204. <tr>
  205. <th><?php echo t('Type')?></th>
  206. <td colspan="2"><?php echo $fv->getType()?></td>
  207. </tr>
  208. <tr>
  209. <th><?php echo t('Size')?></th>
  210. <td colspan="2"><?php echo $fv->getSize()?> (<?php echo number_format($fv->getFullSize())?> <?php echo t('bytes')?>)</td>
  211. </tr>
  212. <tr>
  213. <th><?php echo t('Date Added')?></th>
  214. <td colspan="2"><?php echo t('Added by <strong>%s</strong> on %s', $fv->getAuthorName(), date(DATE_APP_FILE_PROPERTIES, strtotime($f->getDateAdded())))?></td>
  215. </tr>
  216. <?php
  217. Loader::model("file_storage_location");
  218. $fsl = FileStorageLocation::getByID(FileStorageLocation::ALTERNATE_ID);
  219. if (is_object($fsl)) {
  220. if ($f->getStorageLocationID() > 0) {
  221. $sli = $fsl->getName() . ' <span style="color: #afafaf">(' . $fsl->getDirectory() . ')</span>';;
  222. }
  223. }
  224. if (!isset($sli)) {
  225. $sli = t('Default Location') . ' <span style="color: #afafaf">(' . DIR_FILES_UPLOADED . ')</span>';
  226. }
  227. ?>
  228. <tr>
  229. <th><?php echo t('Location')?></th>
  230. <td colspan="2"><?php echo $sli?></td>
  231. </tr>
  232. <?php
  233. printCorePropertyRow(t('Title'), 'fvTitle', $fv->getTitle(), $form->text('fvTitle', $fv->getTitle()));
  234. printCorePropertyRow(t('Description'), 'fvDescription', $fv->getDescription(), $form->textarea('fvDescription', $fv->getDescription()));
  235. printCorePropertyRow(t('Tags'), 'fvTags', $fv->getTags(), $form->textarea('fvTags', $fv->getTags()));
  236. ?>
  237. </table>
  238. <?php
  239. $attribs = FileAttributeKey::getImporterList($fv);
  240. $ft = $fv->getType();
  241. if (count($attribs) > 0) { ?>
  242. <br/>
  243. <h2><?php echo t('%s File Properties', $ft)?></h2>
  244. <table border="0" cellspacing="0" cellpadding="0" class="ccm-grid">
  245. <?php
  246. foreach($attribs as $at) {
  247. printFileAttributeRow($at, $fv);
  248. }
  249. ?>
  250. </table>
  251. <?php } ?>
  252. <?php
  253. $attribs = FileAttributeKey::getUserAddedList();
  254. if (count($attribs) > 0) { ?>
  255. <br/>
  256. <h2><?php echo t('Other Properties')?></h2>
  257. <table border="0" cellspacing="0" cellpadding="0" class="ccm-grid">
  258. <?php
  259. foreach($attribs as $at) {
  260. printFileAttributeRow($at, $fv);
  261. }
  262. ?>
  263. </table>
  264. <?php } ?>
  265. <br/>
  266. </div>
  267. <h2><?php echo t('File Preview')?></h2>
  268. <div style="text-align: center">
  269. <?php echo $fv->getThumbnail(2)?>
  270. </div>
  271. </div>
  272. <?php if (!$previewMode) { ?>
  273. <div class="ccm-file-properties-details-tab" id="ccm-file-properties-versions-<?php echo $f->getFileID()?>-<?php echo $fv->getFileVersionID()?>-tab" style="display: none">
  274. <h1><?php echo t('File Versions')?></h1>
  275. <table border="0" cellspacing="0" width="100%" id="ccm-file-versions-grid" class="ccm-grid" cellpadding="0">
  276. <tr>
  277. <th>&nbsp;</th>
  278. <th><?php echo t('Filename')?></th>
  279. <th><?php echo t('Title')?></th>
  280. <th><?php echo t('Comments')?></th>
  281. <th><?php echo t('Creator')?></th>
  282. <th><?php echo t('Added On')?></th>
  283. <?php if ($fp->canAdmin()) { ?>
  284. <th>&nbsp;</th>
  285. <?php } ?>
  286. </tr>
  287. <?php
  288. $versions = $f->getVersionList();
  289. foreach($versions as $fvv) { ?>
  290. <tr fID="<?php echo $f->getFileID()?>" fvID="<?php echo $fvv->getFileVersionID()?>" <?php if ($fvv->getFileVersionID() == $fv->getFileVersionID()) { ?> class="ccm-file-versions-grid-active" <?php } ?>>
  291. <td style="text-align: center">
  292. <?php echo $form->radio('vlfvID', $fvv->getFileVersionID(), $fvv->getFileVersionID() == $fv->getFileVersionID())?>
  293. </td>
  294. <td width="100">
  295. <div style="width: 150px; word-wrap: break-word">
  296. <a href="<?php echo REL_DIR_FILES_TOOLS_REQUIRED?>/files/properties?fID=<?php echo $f->getFileID()?>&fvID=<?php echo $fvv->getFileVersionID()?>&task=preview_version" dialog-modal="false" dialog-width="630" dialog-height="450" dialog-title="<?php echo t('Preview File')?>" class="dialog-launch">
  297. <?php echo $fvv->getFilename()?>
  298. </a>
  299. </div>
  300. </td>
  301. <td>
  302. <div style="width: 150px; word-wrap: break-word">
  303. <?php echo $fvv->getTitle()?>
  304. </div>
  305. </td>
  306. <td><?php
  307. $comments = $fvv->getVersionLogComments();
  308. if (count($comments) > 0) {
  309. print t('Updated ');
  310. for ($i = 0; $i < count($comments); $i++) {
  311. print $comments[$i];
  312. if (count($comments) > ($i + 1)) {
  313. print ', ';
  314. }
  315. }
  316. print '.';
  317. }
  318. ?>
  319. </td>
  320. <td><?php echo $fvv->getAuthorName()?></td>
  321. <td><?php echo date(DATE_APP_FILE_VERSIONS, strtotime($fvv->getDateAdded()))?></td>
  322. <?php if ($fp->canAdmin()) { ?>
  323. <?php if ($fvv->getFileVersionID() == $fv->getFileVersionID()) { ?>
  324. <td>&nbsp;</td>
  325. <?php } else { ?>
  326. <td><a class="ccm-file-versions-remove" href="javascript:void(0)"><?php echo t('Delete')?></a></td>
  327. <?php } ?>
  328. <?php } ?>
  329. </tr>
  330. <?php } ?>
  331. </table>
  332. </div>
  333. <?php } ?>
  334. <div class="ccm-file-properties-details-tab" id="ccm-file-properties-statistics-<?php echo $f->getFileID()?>-<?php echo $fv->getFileVersionID()?>-tab" style="display: none">
  335. <h1><?php echo t('Download Statistics')?></h1>
  336. <?php
  337. $downloadStatistics = $f->getDownloadStatistics();
  338. ?>
  339. <h2><?php echo count($downloadStatistics).' '.t('Downloads')?></h2>
  340. <table border="0" cellspacing="0" width="100%" id="ccm-file-versions-grid" class="ccm-grid" cellpadding="0">
  341. <tr>
  342. <th><?php echo t('User')?></th>
  343. <th><?php echo t('Download Time')?></th>
  344. <th><?php echo t('File Version ID')?></th>
  345. </tr>
  346. <?php
  347. $downloadStatsCounter=0;
  348. foreach($downloadStatistics as $download){
  349. $downloadStatsCounter++;
  350. if($downloadStatsCounter>20) break;
  351. ?>
  352. <tr>
  353. <td>
  354. <?php
  355. $uID=intval($download['uID']);
  356. if(!$uID){
  357. echo t('Anonymous');
  358. }else{
  359. $downloadUI = UserInfo::getById($uID);
  360. //echo get_class($downloadUI);
  361. echo $downloadUI->getUserName();
  362. }
  363. ?>
  364. </td>
  365. <td><?php echo date(DATE_APP_FILE_DOWNLOAD, strtotime($download['timestamp']))?></td>
  366. <td><?php echo intval($download['fvID'])?></td>
  367. </tr>
  368. <?php } ?>
  369. </table>
  370. </div>
  371. </div>
  372. <script type="text/javascript">
  373. $(function() {
  374. ccm_activateEditablePropertiesGrid();
  375. ccm_alSetupVersionSelector();
  376. });
  377. </script>
  378. <?php
  379. if (!isset($_REQUEST['reload'])) { ?>
  380. </div>
  381. <?php }