PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/templates/filebox-group-display.php

https://github.com/klandestino/filebox
PHP | 165 lines | 155 code | 10 blank | 0 comment | 35 complexity | dbeaeeeb5b1ea5fcfc478ff4ec7da279 MD5 | raw file
  1. <?php
  2. global $bp, $filebox;
  3. function get_file_size( $id ) {
  4. return get_nice_size( filesize( get_attached_file( $id ) ) );
  5. }
  6. function get_nice_size( $bytes ) {
  7. if( $bytes < 1024 ) {
  8. return $bytes . ' B';
  9. } elseif( $bytes < 1048576 ) {
  10. return round( $bytes / 1024, 1 ) . ' KB';
  11. } elseif( $bytes < 1073741824 ) {
  12. return round( ( $bytes / 1024 ) / 1024, 1 ) . ' MB';
  13. } else {
  14. return round( ( ( $bytes / 1024 ) / 1024 ) / 1024, 1 ) . ' GB';
  15. }
  16. }
  17. $args = array( 'group_id' => $bp->groups->current_group->id );
  18. if( preg_match_all( '/(?:\/([^\/]+))/', $_SERVER[ 'REQUEST_URI' ], $match ) ) {
  19. $args[ 'folder_slug' ] = array_slice( $match[ 1 ], array_search( 'filebox', $match[ 1 ], true ) + 1 );
  20. }
  21. $documents = $filebox->list_files_and_folders( $args, ARRAY_A );
  22. $trash_count = $filebox->trash_count( $bp->groups->current_group->id );
  23. ?>
  24. <?php if( $filebox->is_allowed( $documents[ 'meta' ][ 'current' ]->term_id, null, true ) ): ?>
  25. <script language="javascript" type="text/javascript">
  26. var _filebox_nonces = {
  27. delete_folder: '<?php echo wp_create_nonce( 'delete_folder' ); ?>',
  28. trash_file: '<?php echo wp_create_nonce( 'trash_file' ); ?>',
  29. delete_file: '<?php echo wp_create_nonce( 'delete_file' ); ?>',
  30. reset_file: '<?php echo wp_create_nonce( 'reset_file' ); ?>'
  31. };
  32. </script>
  33. <?php endif; ?>
  34. <ul class="filebox-breadcrumbs">
  35. <li class="title"><?php echo $filebox->options[ 'group-tab' ]; ?></li>
  36. <?php if( array_key_exists( 'breadcrumbs', $documents[ 'meta' ] ) ): ?>
  37. <?php foreach( $documents[ 'meta' ][ 'breadcrumbs' ] as $folder ): ?>
  38. <li class="folder">Âť <a href="<?php echo esc_url( $filebox->get_folder_url( $folder->term_id ) ); ?>"><?php echo esc_attr( $folder->name ); ?></a></li>
  39. <?php endforeach; ?>
  40. <?php endif; ?>
  41. <li class="folder<?php echo $documents[ 'meta' ][ 'id' ] ? ' current' : ''; ?>">Âť <a href="<?php echo esc_url( $filebox->get_folder_url( $documents[ 'meta' ][ 'current' ]->term_id ) ); ?>"><?php echo esc_attr( $documents[ 'meta' ][ 'current' ]->name ); ?></a></li>
  42. <?php if( $trash_count || array_key_exists( 'trash', $documents[ 'meta' ] ) ): ?>
  43. <li class="trash<?php echo array_key_exists( 'trash', $documents[ 'meta' ] ) ? ' current' : ''; ?>"> | <a href="<?php echo esc_url( bp_get_group_permalink( $bp->groups->current_group ) . 'filebox/trash' ); ?>"><?php echo sprintf( __( 'Trash (%d)', 'filebox' ), $trash_count ); ?></a></li>
  44. <?php endif; ?>
  45. </ul>
  46. <?php if( ! array_key_exists( 'trash', $documents[ 'meta' ] ) ): ?>
  47. <ul class="filebox-buttons">
  48. <?php if( $documents[ 'meta' ][ 'current' ]->zip ): ?>
  49. <li class="download">
  50. <a href="<?php echo $documents[ 'meta' ][ 'current' ]->zip->url; ?>" class="button" title="<?php esc_attr_e( 'Download folder as a zip', 'filebox' ) ?>">
  51. <?php printf( __( 'Download (zip, %s)', 'filebox' ), get_nice_size( $documents[ 'meta' ][ 'current' ]->zip->size ) ); ?>
  52. </a>
  53. </li>
  54. <?php endif; ?>
  55. <?php if( $filebox->is_allowed( $documents[ 'meta' ][ 'id' ], null, true ) ) : ?>
  56. <li class="upload">
  57. <a href="<?php echo FILEBOX_PLUGIN_URL; ?>form.php?form=upload&folder_id=<?php echo $documents[ 'meta' ][ 'id' ]; ?>" class="thickbox add_media button" title="<?php esc_attr_e( 'Add files', 'filebox' ) ?>" onclick="return false;" >
  58. <?php _e( 'Add files', 'filebox' ); ?>
  59. </a>
  60. </li>
  61. <li class="folder">
  62. <a href="<?php echo FILEBOX_PLUGIN_URL; ?>form.php?form=folder&folder_parent=<?php echo $documents[ 'meta' ][ 'id' ]; ?>" class="thickbox add_media button" title="<?php esc_attr_e( 'Add folder', 'filebox' ) ?>" onclick="return false;" >
  63. <?php _e( 'Add folder', 'filebox' ); ?>
  64. </a>
  65. </li>
  66. <?php endif; ?>
  67. </ul>
  68. <?php endif; ?>
  69. <table class="filebox-folder-file-list" cellspacing="0">
  70. <thead>
  71. <tr>
  72. <th class="filebox-checkall"></th>
  73. <th class="filebox-title"><?php _e( 'Title', 'filebox' ); ?></th>
  74. <th class="filebox-changed"><?php _e( 'Changed', 'filebox' ); ?></th>
  75. <th class="filebox-owner"><?php _e( 'Latest change by', 'filebox' ); ?></th>
  76. <th class="filebox-size"><?php _e( 'Size', 'filebox' ); ?></th>
  77. </tr>
  78. </thead>
  79. <tbody>
  80. <?php $even = true;
  81. foreach( array( 'folders', 'files' ) as $type ): ?>
  82. <?php foreach( $documents[ $type ] as $doc ): $even = ! $even; ?>
  83. <tr class="filebox-<?php echo $type; ?> <?php echo $even ? 'even' : 'odd'; ?> filebox-title filebox-<?php echo $type == 'folders' ? $doc->term_id : $doc->ID; ?>">
  84. <td rowspan="3" class="filebox-icon">
  85. <?php if( $type == 'folders' ): ?>
  86. <img src="<?php echo FILEBOX_PLUGIN_URL . 'images/folder-' . ( $doc->count || $doc->childs ? 'files' : 'empty' ); ?>.png" width="46" height="60" />
  87. <?php else: $attachment = reset( $doc->attachments ); ?>
  88. <?php echo wp_get_attachment_image( $attachment->ID, 'filebox-thumbnail', ! wp_attachment_is_image( $attachment->ID ) ); ?>
  89. <?php endif; ?>
  90. </td>
  91. <th class="filebox-title">
  92. <?php if( $type == 'folders' ): ?>
  93. <a href="<?php echo esc_url( $filebox->get_folder_url( $doc->term_id ) ); ?>"><?php echo esc_attr( $doc->name ); ?></a>
  94. <?php else: ?>
  95. <a href="<?php echo esc_url( get_permalink( $doc->ID ) ); ?>"><?php echo esc_attr( $doc->post_title ); ?></a>
  96. <?php endif; ?>
  97. </th>
  98. <td class="filebox-changed"><?php echo $type == 'folders' ? '' :
  99. date_i18n( get_option( 'date_format' ), strtotime( $doc->post_modified ) ) .
  100. ' - ' .
  101. date_i18n( get_option( 'time_format' ), strtotime( $doc->post_modified ) );
  102. ?></td>
  103. <td class="filebox-owner"><?php echo $type == 'folders' ? '' : $doc->user->display_name; ?></td>
  104. <td class="filebox-size"><?php if( $type == 'folders' ) {
  105. if( $doc->count && $doc->childs ) {
  106. printf( __( '%1$d files / %2$d folders', 'filebox' ), $doc->count, $doc->childs );
  107. } elseif( $doc->count ) {
  108. printf( __( '%1$d files', 'filebox' ), $doc->count );
  109. } elseif( $doc->childs ) {
  110. printf( __( '%1$d folders', 'filebox' ), $doc->childs );
  111. } else {
  112. _e( 'Empty', 'filebox' );
  113. }
  114. } else {
  115. echo get_file_size( reset( $doc->attachments )->ID );
  116. } ?></td>
  117. </tr>
  118. <tr class="filebox-<?php echo $type; ?> <?php echo $even ? 'even' : 'odd'; ?> filebox-desc filebox-<?php echo $type == 'folders' ? $doc->term_id : $doc->ID; ?>">
  119. <td colspan="4"><?php echo $type == 'folders' ? $doc->description : $doc->post_excerpt; ?></td>
  120. </tr>
  121. <tr class="filebox-<?php echo $type; ?> <?php echo $even ? 'even' : 'odd'; ?> filebox-actions filebox-<?php echo $type == 'folders' ? $doc->term_id : $doc->ID; ?>">
  122. <td colspan="4">
  123. <ul class="actions">
  124. <?php if( $type == 'files' ): ?>
  125. <?php if( $doc->post_status == 'trash' ): ?>
  126. <?php if( $filebox->is_allowed( $documents[ 'meta' ][ 'current' ]->term_id, null, true ) ): ?>
  127. <li><a class="filebox-action-reset" href="javascript://"><?php _e( 'Reset', 'filebox' ); ?></a></li>
  128. <li><a class="filebox-action-delete" href="javascript://"><?php _e( 'Delete permanently', 'filebox' ); ?></a></li>
  129. <?php endif; ?>
  130. <?php else: ?>
  131. <li><a class="filebox-action-history thickbox" href="<?php echo FILEBOX_PLUGIN_URL; ?>form.php?form=history&file_id=<?php echo $doc->ID; ?>" title="<?php esc_attr_e( 'File history', 'filebox' ); ?>" onclick="return false;"><?php _e( 'Show history', 'filebox' ); ?></a></li>
  132. <?php if( $filebox->is_allowed( $documents[ 'meta' ][ 'id' ], null, true ) ): ?>
  133. <li><a class="filebox-action-edit thickbox" href="<?php echo FILEBOX_PLUGIN_URL; ?>form.php?form=file&folder_id=<?php echo $documents[ 'meta' ][ 'id' ]; ?>&file_id=<?php echo $doc->ID; ?>" title="<?php _e( 'Edit', 'filebox' ); ?>" onclick="return false;"><?php _e( 'Edit', 'filebox' ); ?></a></li>
  134. <li><a class="filebox-action-upload thickbox" href="<?php echo FILEBOX_PLUGIN_URL; ?>form.php?form=upload&folder_id=<?php echo $documents[ 'meta' ][ 'id' ]; ?>&file_id=<?php echo $doc->ID; ?>" title="<?php esc_attr_e( 'Upload new version', 'filebox' ); ?>" onclick="return false;"><?php _e( 'Upload new version', 'filebox' ); ?></a></li>
  135. <li><a class="filebox-action-move thickbox" href="<?php echo FILEBOX_PLUGIN_URL; ?>form.php?form=move&folder_id=<?php echo $documents[ 'meta' ][ 'id' ]; ?>&file_id=<?php echo $doc->ID; ?>" title="<?php esc_attr_e( 'Move file', 'filebox' ); ?>" onclick="return false;"><?php _e( 'Move', 'filebox' ); ?></a></li>
  136. <li><a class="filebox-action-trash" href="javascript://"><?php _e( 'Trash', 'filebox' ); ?></a></li>
  137. <?php endif; ?>
  138. <?php endif; ?>
  139. <?php else: ?>
  140. <?php if( $filebox->is_allowed( $documents[ 'meta' ][ 'id' ], null, true ) ): ?>
  141. <li><a class="filebox-action-edit thickbox" href="<?php echo FILEBOX_PLUGIN_URL; ?>form.php?form=folder&folder_id=<?php echo $doc->term_id; ?>" title="<?php esc_attr_e( 'Edit folder', 'filebox' ); ?>" onclick="return false;"><?php _e( 'Edit', 'filebox' ); ?></a></li>
  142. <li><a class="filebox-action-move thickbox" href="<?php echo FILEBOX_PLUGIN_URL; ?>form.php?form=move&folder_id=<?php echo $doc->term_id; ?>" title="<?php esc_attr_e( 'Move folder', 'filebox' ); ?>" onclick="return false;"><?php _e( 'Move', 'filebox' ); ?></a></li>
  143. <?php if( $doc->zip ): ?>
  144. <li><a class="filebox-action-download " href="<?php echo $doc->zip->url; ?>" title="<?php esc_attr_e( 'Download folder as a zip', 'filebox' ); ?>"><?php printf( __( 'Download (zip, %s)', 'filebox' ), get_nice_size( $doc->zip->size ) ); ?></a></li>
  145. <?php endif; ?>
  146. <li><a class="filebox-action-trash" href="javascript://"><?php _e( 'Delete', 'filebox' ); ?></a></li>
  147. <?php endif; ?>
  148. <?php endif; ?>
  149. </ul>
  150. </td>
  151. </tr>
  152. <?php endforeach; ?>
  153. <?php endforeach; ?>
  154. </tbody>
  155. </table>