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

/wp-content/plugins/memphis-documents-library/includes/mdocs-post-page.php

https://bitbucket.org/sokvistweb/npld
PHP | 168 lines | 159 code | 6 blank | 3 comment | 57 complexity | 56c5dfde54bdf0356a595d89c2c639d3 MD5 | raw file
Possible License(s): GPL-2.0, MIT, BSD-3-Clause, 0BSD
  1. <?php
  2. /**
  3. * Creates the Memphis Documents Library post type.
  4. */
  5. function mdocs_init_post_pages() {
  6. $labels = array(
  7. 'name' => __( 'Memphis Documents Posts', 'mdocs' ),
  8. 'singular_name' => _x( 'mdocs', 'mdocs' ),
  9. 'add_new' => __( 'Add New', 'mdocs' ),
  10. 'add_new_item' => __( 'Add New Documents', 'mdocs' ),
  11. 'edit_item' => __( 'Edit Documents', 'mdocs' ),
  12. 'new_item' => __( 'New Documents', 'mdocs' ),
  13. 'all_items' => __( 'All Documents', 'mdocs' ),
  14. 'view_item' => __( 'View Documents', 'mdocs' ),
  15. 'search_items' => __( 'Search Documents', 'mdocs' ),
  16. 'not_found' => __( 'No documents found', 'mdocs' ),
  17. 'not_found_in_trash' => __( 'No documents found in the Trash', 'mdocs' ),
  18. 'parent_item_colon' => '',
  19. 'menu_name' => 'mDocs Posts'
  20. );
  21. $show_mdocs_post_menu = get_option('mdocs-show-post-menu');
  22. $supports = array( 'title', 'editor','author','comments','revisions','page-attributes','post-formats', 'excerpt', 'trackbacks', 'custom-fields', 'thumbnail' );
  23. $args = array(
  24. 'labels' => $labels,
  25. 'public' => true,
  26. 'publicly_queryable' => true,
  27. 'show_ui' => $show_mdocs_post_menu,
  28. 'show_in_menu' => true,
  29. 'query_var' => true,
  30. 'rewrite' => array( 'slug' => 'mdocs-posts' ),
  31. 'capability_type' => 'page',
  32. 'has_archive' => true,
  33. 'hierarchical' => false,
  34. 'menu_position' => 5,
  35. 'taxonomies' => array('post_tag'),
  36. 'supports' => $supports,
  37. );
  38. register_post_type( 'mdocs-posts', $args );
  39. }
  40. function mdocs_post_page($att=null) {
  41. global $post;
  42. if(@$post->post_type = 'mdocs-posts') {
  43. ob_start();
  44. $the_mdoc = get_the_mdoc_by($post->ID, 'parent');
  45. $the_page = '<div class="mdocs mdocs-post mdocs-post-current-file">';
  46. $the_page .= mdocs_display_file_info_large($the_mdoc, $att);
  47. $the_page .= '<div class="mdocs-clear-both"></div>';
  48. $the_page .= mdocs_social($the_mdoc);
  49. $the_page .= '</div>';
  50. $the_page .= '<div class="mdocs-clear-both"></div>';
  51. $the_page .= mdocs_display_tabs($the_mdoc);
  52. $the_page .= '<div class="mdocs-clear-both"></div>';
  53. $the_page .= '</div>';
  54. $the_page .= ob_get_clean();
  55. if(mdocs_check_post_rights($the_mdoc)) return $the_page;
  56. else return '<p class="alert alert-info text-center clearfix">'.__('Sorry you can\'t see this Memphis Documents file you don\'t have the proper permission.','memphis-documents-library').'</p>';
  57. }
  58. }
  59. function mdocs_display_file_info_large($the_mdoc, $att=null) {
  60. global $post;
  61. ob_start();
  62. $the_mdoc_permalink = mdocs_sanitize_string(get_permalink($the_mdoc['parent']));
  63. $the_post = get_post($the_mdoc['parent']);
  64. if(isset($att['new']) && $att['new']) $is_new = true;
  65. else $is_new = false;
  66. $date_format = get_option('mdocs-date-format');
  67. $the_date = mdocs_format_unix_epoch($the_mdoc['modified']);
  68. $user_logged_in = is_user_logged_in();
  69. $mdocs_show_non_members = $the_mdoc['non_members'];
  70. $mdocs_hide_all_files = get_option( 'mdocs-hide-all-files' );
  71. $mdocs_hide_all_posts = get_option( 'mdocs-hide-all-posts' );
  72. $mdocs_hide_all_files_non_members = get_option( 'mdocs-hide-all-files-non-members' );
  73. $sa = mdocs_get_table_atts();
  74. if($sa['show-downloads']['show']) {
  75. $the_array = get_option('mdocs-displayed-file-info');
  76. $mdocs_show_downloads = $the_array['show-downloads']['show'];
  77. } else $mdocs_show_downloads = '';
  78. if($sa['show-author']['show']) {
  79. $the_array = get_option('mdocs-displayed-file-info');
  80. $mdocs_show_author = $the_array['show-author']['show'];
  81. } else $mdocs_show_author = '';
  82. if($sa['show-version']['show']) {
  83. $the_array = get_option('mdocs-displayed-file-info');
  84. $mdocs_show_version = $the_array['show-version']['show'];
  85. } else $mdocs_show_version = '';
  86. if($sa['show-modified']['show']) {
  87. $the_array = get_option('mdocs-displayed-file-info');
  88. $mdocs_show_update = $the_array['show-modified']['show'];
  89. } else $mdocs_show_update = '';
  90. if($sa['show-rating']['show']) {
  91. $the_array = get_option('mdocs-displayed-file-info');
  92. $mdocs_show_ratings = $the_array['show-rating']['show'];
  93. } else $mdocs_show_ratings = '';
  94. $mdocs_show_new_banners = get_option('mdocs-show-new-banners');
  95. $mdocs_time_to_display_banners = get_option('mdocs-time-to-display-banners');
  96. $post_status = $the_post->post_status;
  97. $permalink = mdocs_get_permalink($post);
  98. if($the_mdoc['show_social'] ==='on' && get_option('mdocs-show-social') ) mdocs_social_scripts();
  99. $the_rating = mdocs_get_rating($the_mdoc);
  100. $modified = floor($the_mdoc['modified']/86400)*86400;
  101. $today = floor(time()/86400)*86400;
  102. $days = (($today-$modified)/86400);
  103. $new_or_updated = '';
  104. if($mdocs_time_to_display_banners > $days) {
  105. if($is_new == true) {
  106. if($mdocs_show_new_banners) echo '<div class="alert alert-success clearfix"><p class="text-center">'.__('New','memphis-documents-library').'</p></div>';
  107. if(get_option('mdocs-hide-new-update-label')) $new_or_updated = '';
  108. else $new_or_updated = '<small class="label label-success">'.__('New', 'memphis-documents-library').'</small> ';
  109. } else {
  110. if($mdocs_show_new_banners) echo '<div class="alert alert-info clearfix"><p class="text-center">'.__('Updated','memphis-documents-library').'</p></div>';
  111. if(get_option('mdocs-hide-new-update-label')) $new_or_updated = '';
  112. else $new_or_updated = '<small class="label label-info">'.__('Updated', 'memphis-documents-library').'</small> ';
  113. }
  114. } else $status_class = 'mdocs-normal';
  115. ?>
  116. <div class="mdocs-development-warning"></div>
  117. <div class="mdocs-post-header" data-mdocs-id="<?php echo $the_mdoc['id']; ?>">
  118. <div class="mdocs-post-button-box">
  119. <?php
  120. echo $new_or_updated;
  121. if(mdocs_check_file_rights($the_mdoc) == false && $user_logged_in) { ?><a class="mdocs-login-msg btn btn-primary"><small><?php _e('This file can not<br>be downloaded.','memphis-documents-library'); ?></small></a><?php }
  122. else if($mdocs_show_non_members == 'off' && $user_logged_in == false || $user_logged_in == false && $mdocs_hide_all_files_non_members) { ?>
  123. <a class="mdocs-download-btn mdocs-float-right btn btn-primary" href="<?php echo wp_login_url($permalink); ?>" ><small><?php echo __('Please Login to download this file','memphis-documents-library'); ?></small></a>
  124. <?php } elseif($the_mdoc['non_members'] == 'on' || $user_logged_in ) { ?>
  125. <a onclick="mdocs_download_file('<?php echo $the_mdoc['id']; ?>','<?php echo $the_post->ID; ?>');" class="mdocs-download-btn mdocs-float-right btn btn-primary" value=""><?php echo __('Download','memphis-documents-library'); ?></a>
  126. <?php } else { ?>
  127. <a class="mdocs-download-btn mdocs-float-right btn btn-primary" href="<?php echo wp_login_url($permalink); ?>" ><small><?php echo __('Please Login to download this file','memphis-documents-library'); ?></small></a>
  128. <?php } ?>
  129. </div>
  130. <?php
  131. if($user_logged_in && $mdocs_show_ratings) {
  132. if($the_rating['your_rating'] == 0) $text = __("Rate Me!");
  133. else $text = __("Your Rating");
  134. echo '<div class="mdocs-rating-container-small">';
  135. echo '<div class="mdocs-green">'.$text.'</div><div id="mdocs-star-container">';
  136. echo '<div class="mdocs-ratings-stars" data-my-rating="'.$the_rating['your_rating'].'">';
  137. for($i=1;$i<=5;$i++) {
  138. if($the_rating['your_rating'] >= $i) echo '<i class="fas fa-star fa-xs mdocs-gold mdocs-my-rating" id="'.$i.'" aria-hidden="true"></i>';
  139. else echo '<i class="far fa-star fa-xs mdocs-my-rating" id="'.$i.'" aria-hidden="true"></i>';
  140. }
  141. echo '</div></div></div>';
  142. }
  143. ?>
  144. <div class="mdocs-post-file-info">
  145. <!--<p><i class="fa fa-arrow-circle-left" aria-hidden="true"></i> Back to Document Library</p>-->
  146. <?php if($mdocs_show_ratings) { ?><p><i class="fas fa-star fa-xs" aria-hidden="true"></i> <?php echo $the_rating['average']; ?> <?php _e('Stars', 'memphis-documents-library'); ?> (<?php echo $the_rating['total']; ?>)</p> <?php } ?>
  147. <?php if($mdocs_show_downloads) { ?><p class="mdocs-file-info"><i class="fas fa-cloud-download-alt" aria-hidden="true"></i> <em class="mdocs-orange"><?php echo $the_mdoc['downloads'].' '.__('Downloads','memphis-documents-library'); ?></em></p> <?php } ?>
  148. <?php if($mdocs_show_author) { ?><p><i class="fa fa-pencil-alt" aria-hidden="true"></i> <?php _e('Owner','memphis-documents-library'); ?>: <i class="mdocs-green"><?php echo get_user_by('login', $the_mdoc['owner'])->display_name; ?></i></p> <?php } ?>
  149. <?php if($mdocs_show_version) { ?><p><i class="fa fa-history" aria-hidden="true"></i> <?php _e('Version','memphis-documents-library') ?>: <em class="mdocs-blue"><?php echo $the_mdoc['version']; ?></em>
  150. </p><?php } ?>
  151. <?php if($mdocs_show_update) { ?><p><i class="fa fa-calendar" aria-hidden="true"></i> <?php _e('Last Updated','memphis-documents-library'); ?>: <em class="mdocs-red"><?php echo date($date_format, $the_date['date']); ?></em></p><?php } ?>
  152. <?php if(is_admin()) { ?>
  153. <p><i class="fa fa-file " aria-hidden="true"></i> <?php echo __('File Status','memphis-documents-library').': <em class="mdocs-olive">'.strtoupper($the_mdoc['file_status']).'</em>'; ?></p>
  154. <p><i class="fa fa-file-text" aria-hidden="true"></i> <?php echo __('Post Status','memphis-documents-library').': <em class="mdocs-salmon">'.strtoupper($post_status).'</em>'; ?></p>
  155. <?php } ?>
  156. </div>
  157. </div>
  158. <?php
  159. $the_page = ob_get_clean();
  160. return $the_page;
  161. }
  162. ?>