dashboard.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <?php
  2. class Meow_WR2X_Dashboard {
  3. public $core = null;
  4. public function __construct( $core ) {
  5. $this->core = $core;
  6. add_action( 'admin_menu', array( $this, 'admin_menu_dashboard' ) );
  7. }
  8. function admin_menu_dashboard () {
  9. $flagged = count( $this->core->get_issues() );
  10. $warning_title = __( "Retina images", 'wp-retina-2x' );
  11. $menu_label = sprintf( __( 'Retina %s' ), "<span class='update-plugins count-$flagged' title='$warning_title'><span class='update-count'>" . number_format_i18n( $flagged ) . "</span></span>" );
  12. add_media_page( 'Retina', $menu_label, 'manage_options', 'wp-retina-2x', array( $this, 'dashboard' ) );
  13. }
  14. function dashboard() {
  15. $refresh = isset ( $_GET[ 'refresh' ] ) ? sanitize_text_field( $_GET[ 'refresh' ] ) : 0;
  16. $clearlogs = isset ( $_GET[ 'clearlogs' ] ) ? sanitize_text_field( $_GET[ 'clearlogs' ] ) : 0;
  17. $ignore = isset ( $_GET[ 'ignore' ] ) ? sanitize_text_field( $_GET[ 'ignore' ] ) : false;
  18. if ( $ignore ) {
  19. if ( !$this->core->admin->is_registered() ) {
  20. echo "<div class='error' style='margin-top: 20px;'><p>";
  21. _e( "Ignore is a Pro feature.", 'wp-retina-2x' );
  22. echo "</p></div>";
  23. }
  24. else
  25. $this->core->add_ignore( $ignore );
  26. }
  27. if ( $refresh ) {
  28. $this->core->calculate_issues();
  29. }
  30. if ( $clearlogs ) {
  31. if ( file_exists( plugin_dir_path( __FILE__ ) . '/wp-retina-2x.log' ) ) {
  32. unlink( plugin_dir_path( __FILE__ ) . '/wp-retina-2x.log' );
  33. }
  34. }
  35. $hide_ads = get_option( 'meowapps_hide_ads', false );
  36. $view = isset( $_GET[ 'view' ] ) ? sanitize_text_field( $_GET[ 'view' ] ) : 'issues';
  37. $paged = isset( $_GET[ 'paged' ] ) ? sanitize_text_field( $_GET[ 'paged' ] ) : 1;
  38. $s = isset( $_GET[ 's' ] ) && !empty( $_GET[ 's' ] ) ? sanitize_text_field( $_GET[ 's' ] ) : null;
  39. $issues = $count = 0;
  40. $posts_per_page = get_user_meta( get_current_user_id(), 'upload_per_page', true );
  41. if ( empty( $posts_per_page ) )
  42. $posts_per_page = 20;
  43. $issues = $this->core->get_issues();
  44. $ignored = $this->core->get_ignores();
  45. echo '<div class="wrap">';
  46. echo $this->core->admin->display_title( "WP Retina 2x" );
  47. echo '<p></p>';
  48. if ( $this->core->admin->is_registered() && $view == 'issues' ) {
  49. global $wpdb;
  50. $totalcount = $wpdb->get_var( $wpdb->prepare( "
  51. SELECT COUNT(*)
  52. FROM $wpdb->posts p
  53. WHERE post_status = 'inherit'
  54. AND post_type = 'attachment'" . $this->core->create_sql_if_wpml_original() . "
  55. AND post_title LIKE %s
  56. AND ( post_mime_type = 'image/jpeg' OR
  57. post_mime_type = 'image/png' OR
  58. post_mime_type = 'image/gif' )
  59. ", '%' . $s . '%' ) );
  60. $postin = count( $issues ) < 1 ? array( -1 ) : $issues;
  61. $query = new WP_Query(
  62. array(
  63. 'post_status' => 'inherit',
  64. 'post_type' => 'attachment',
  65. 'post__in' => $postin,
  66. 'paged' => $paged,
  67. 'posts_per_page' => $posts_per_page,
  68. 's' => $s
  69. )
  70. );
  71. }
  72. else if ( $this->core->admin->is_registered() && $view == 'ignored' ) {
  73. global $wpdb;
  74. $totalcount = $wpdb->get_var( $wpdb->prepare( "
  75. SELECT COUNT(*)
  76. FROM $wpdb->posts p
  77. WHERE post_status = 'inherit'
  78. AND post_type = 'attachment'" . $this->core->create_sql_if_wpml_original() . "
  79. AND post_title LIKE %s
  80. AND ( post_mime_type = 'image/jpeg' OR
  81. post_mime_type = 'image/jpg' OR
  82. post_mime_type = 'image/png' OR
  83. post_mime_type = 'image/gif' )
  84. ", '%' . $s . '%' ) );
  85. $postin = count( $ignored ) < 1 ? array( -1 ) : $ignored;
  86. $query = new WP_Query(
  87. array(
  88. 'post_status' => 'inherit',
  89. 'post_type' => 'attachment',
  90. 'post__in' => $postin,
  91. 'paged' => $paged,
  92. 'posts_per_page' => $posts_per_page,
  93. 's' => $s
  94. )
  95. );
  96. }
  97. else {
  98. $query = new WP_Query(
  99. array(
  100. 'post_status' => 'inherit',
  101. 'post_type' => 'attachment',
  102. 'post_mime_type' => 'image/jpeg,image/gif,image/jpg,image/png',
  103. 'paged' => $paged,
  104. 'posts_per_page' => $posts_per_page,
  105. 's' => $s
  106. )
  107. );
  108. //$s
  109. $totalcount = $query->found_posts;
  110. }
  111. $issues_count = count( $issues );
  112. // If 'search', then we need to clean-up the issues count
  113. if ( $s && $issues_count > 0 ) {
  114. global $wpdb;
  115. $issues_count = $wpdb->get_var( $wpdb->prepare( "
  116. SELECT COUNT(*)
  117. FROM $wpdb->posts p
  118. WHERE id IN ( " . implode( ',', $issues ) . " )" . $this->core->create_sql_if_wpml_original() . "
  119. AND post_title LIKE %s
  120. ", '%' . $s . '%' ) );
  121. }
  122. $results = array();
  123. $count = $query->found_posts;
  124. $pagescount = $query->max_num_pages;
  125. foreach ( $query->posts as $post ) {
  126. $info = $this->core->retina_info( $post->ID );
  127. array_push( $results, array( 'post' => $post, 'info' => $info ) );
  128. }
  129. ?>
  130. <div style='background: #FFF; padding: 5px; border-radius: 4px; height: 28px; box-shadow: 0px 0px 6px #C2C2C2;'>
  131. <!-- REFRESH -->
  132. <a id='wr2x_refresh' href='?page=wp-retina-2x&view=issues&refresh=true' class='button' style='float: left;'><span style="top: 3px; position: relative; left: -5px;" class="dashicons dashicons-controls-repeat"></span><?php _e("Refresh", 'wp-retina-2x'); ?></a>
  133. <!-- SEARCH -->
  134. <form id="posts-filter" action="upload.php" method="get">
  135. <p class="search-box" style='margin-left: 5px; float: left;'>
  136. <input type="search" name="s" value="<?php echo $s ? $s : ""; ?>">
  137. <input type="hidden" name="page" value="wp-retina-2x">
  138. <input type="hidden" name="view" value="<?php echo $view; ?>">
  139. <input type="hidden" name="paged" value="<?php echo $paged; ?>">
  140. <input type="submit" class="button" value="Search">
  141. </p>
  142. </form>
  143. <!-- REMOVE BUTTON ALL -->
  144. <a id='wr2x_remove_button_all' onclick='wr2x_delete_all()' class='button button-red' style='float: right;'><span style="top: 3px; position: relative; left: -5px;" class="dashicons dashicons-trash"></span><?php _e("Bulk Delete (Retina Only)", 'wp-retina-2x'); ?></a>
  145. <!-- GENERATE ALL -->
  146. <a id='wr2x_generate_button_all' onclick='wr2x_generate_all()' class='button-primary' style='float: right; margin-right: 5px;'><span style="top: 3px; position: relative; left: -5px;" class="dashicons dashicons-controls-play"></span><?php _e("Bulk Generate (Thumbnails & Retina)", 'wp-retina-2x'); ?></a>
  147. <!-- PROGRESS -->
  148. <span style='margin-left: 12px; font-size: 13px; top: 5px; position: relative; color: #24547C; font-weight: bold;' id='wr2x_progression'></span>
  149. </div>
  150. <?php
  151. if (isset ( $_GET[ 'clearlogs' ] ) ? $_GET[ 'clearlogs' ] : 0) {
  152. echo "<div class='updated' style='margin-top: 20px;'><p>";
  153. _e( "The logs have been cleared.", 'wp-retina-2x' );
  154. echo "</p></div>";
  155. }
  156. $active_sizes = $this->core->get_active_image_sizes();
  157. $full_size_needed = get_option( "wr2x_full_size" );
  158. $max_width = 0;
  159. $max_height = 0;
  160. foreach ( $active_sizes as $name => $active_size ) {
  161. if ( $active_size['height'] != 9999 && $active_size['height'] > $max_height ) {
  162. $max_height = $active_size['height'];
  163. }
  164. if ( $active_size['width'] != 9999 && $active_size['width'] > $max_width ) {
  165. $max_width = $active_size['width'];
  166. }
  167. }
  168. $max_width = $max_width * 2;
  169. $max_height = $max_height * 2;
  170. $upload_max_size = $this->core->get_max_filesize();
  171. ?>
  172. <p>
  173. <?php printf( __( 'Based on your <i>image sizes</i> settings, the full-size images should be uploaded at a resolution of at least <b>%d×%d</b> for the plugin to be able generate the <b>%d retina images</b>. Please note that it vares depending on your needs for each image (you will need to discuss this with your developer).', 'wp-retina-2x' ), $max_width, $max_height, count( $active_sizes ) ); ?>
  174. <?php if ( $full_size_needed ) printf( __( "You <b>also need</b> to upload a retina image for the Full-Size image (might be <b>%d×%d</b>).", 'wp-retina-2x' ), $max_width * 2, $max_height * 2 ); ?>
  175. <?php _e("You can upload or replace the images by drag & drop.", 'wp-retina-2x' ); ?>
  176. <?php printf( __( "Your PHP configuration allows uploads of <b>%dMB</b> maximum.", 'wp-retina-2x'), $upload_max_size / 1000000 ); ?>
  177. <?php
  178. if ( file_exists( plugin_dir_path( __FILE__ ) . '/wp-retina-2x.log' ) ) {
  179. printf( __( 'The <a target="_blank" href="%s/wp-retina-2x.log">log file</a> is available. You can also <a href="?page=wp-retina-2x&view=issues&clearlogs=true">clear</a> it.', 'wp-retina-2x' ), plugin_dir_url( __FILE__ ) );
  180. }
  181. ?>
  182. </p>
  183. <?php
  184. $method = get_option( 'wr2x_method' );
  185. $cdn = get_option( 'wr2x_cdn_domain' );
  186. $disable_responsive = get_option( 'wr2x_disable_responsive', false );
  187. $keep_src = get_option( 'wr2x_picturefill_keep_src', false );
  188. if ( $method == 'HTML Rewrite' || $method == 'Retina-Images' || $disable_responsive || $keep_src ) {
  189. echo '<div class="error"><p>';
  190. echo __( '<b>WARNING</b>. You are using an option that will be removed in a future release. The plan is to remove two methods (HTML Rewrite and Retina-Images), Disable Responsive, and Keep IMG SRC. Those options are not necessary, and it is better to keep the plugin clean and focus. This warning message will go away if you avoid using those options (and will disappear in a future release). If you are using one of those options and really would like to keep it, please come here to talk about it: <a target= "_blank" href="https://meowapps.com/wp-retina-2x-faq/">Featured comment at this end of this page</a>. Thanks :)', 'wp-retina-2x' );
  191. echo '</p></div>';
  192. }
  193. ?>
  194. <?php
  195. if ( !$this->core->admin->is_registered() && !get_option( "wr2x_hide_pro", false ) ) {
  196. echo '<div class="updated"><p>';
  197. echo __( '<b>Only Pro users have access to the features of this dashboard.</b> As a standard user, the dashboard allow you to Bulk Generate, Bulk Delete and access the Retina Logs. If you wish to stay a standard user and never see this dashboard aver again, you can hide it in the settings.<br /><br />The Pro version of the plugin allows you to <b>replace directly an image already uploaded in the Media Library</b> by a simple drag & drop, upload a <b>retina image for a full-size image</b>, use <b>lazy-loading</b> to load your images (for better performance) and, more importantly, <b>supports the developer</b> :)<br /><br /><a class="button-primary" href="https://store.meowapps.com/wp-retina-2x/" target="_blank">Get WP Retina 2x Pro</a>', 'wp-retina-2x' );
  198. echo '</p></div>';
  199. }
  200. ?>
  201. <div id='wr2x-pages'>
  202. <?php
  203. echo paginate_links(array(
  204. 'base' => '?page=wp-retina-2x&s=' . urlencode($s) . '&view=' . $view . '%_%',
  205. 'current' => $paged,
  206. 'format' => '&paged=%#%',
  207. 'total' => $pagescount,
  208. 'prev_next' => false
  209. ));
  210. ?>
  211. </div>
  212. <ul class="subsubsub">
  213. <li class="all"><a <?php if ( $view == 'all' ) echo "class='current'"; ?> href='?page=wp-retina-2x&s=<?php echo $s; ?>&view=all'><?php _e( "All", 'wp-retina-2x' ); ?></a><span class="count">(<?php echo $totalcount; ?>)</span></li> |
  214. <?php if ( $this->core->admin->is_registered() ): ?>
  215. <li class="all"><a <?php if ( $view == 'issues' ) echo "class='current'"; ?> href='?page=wp-retina-2x&s=<?php echo $s; ?>&view=issues'><?php _e( "Issues", 'wp-retina-2x' ); ?></a><span class="count">(<?php echo $issues_count; ?>)</span></li> |
  216. <li class="all"><a <?php if ( $view == 'ignored' ) echo "class='current'"; ?> href='?page=wp-retina-2x&s=<?php echo $s; ?>&view=ignored'><?php _e( "Ignored", 'wp-retina-2x' ); ?></a><span class="count">(<?php echo count( $ignored ); ?>)</span></li>
  217. <?php else: ?>
  218. <li class="all"><span><?php _e( "Issues", 'wp-retina-2x' ); ?></span> <span class="count">(<?php echo $issues_count; ?>)</span></li> |
  219. <li class="all"><span><?php _e( "Ignored", 'wp-retina-2x' ); ?></span> <span class="count">(<?php echo count( $ignored ); ?>)</span></li>
  220. <?php endif; ?>
  221. </ul>
  222. <table class='wp-list-table widefat fixed media wr2x-table'>
  223. <thead><tr>
  224. <?php
  225. echo "<th style='width: 56px;'>Thumbnail</th>";
  226. echo "<th style=' width: 360px;'>" . __( "Base image", 'wp-retina-2x' ) . "</th>";
  227. echo "<th style=''>" . __( "Media Sizes<br />Retina-ized", 'wp-retina-2x' ) . "</th>";
  228. echo "<th style=''>" . __( "Full-Size<br/><b>Replace</b>", 'wp-retina-2x' ) . "</th>";
  229. echo "<th style=''>" . __( "Full-Size Retina", 'wp-retina-2x' ) . "</th>";
  230. echo "<th style=''>" . __( "Full-Size Retina<br/><b>Upload</b>", 'wp-retina-2x' ) . "</th>";
  231. ?>
  232. </tr></thead>
  233. <tbody>
  234. <?php
  235. foreach ($results as $index => $attr) {
  236. $post = $attr['post'];
  237. $info = $attr['info'];
  238. $meta = wp_get_attachment_metadata( $post->ID );
  239. // Let's clean the issues status
  240. if ( $view != 'issues' ) {
  241. $this->core->update_issue_status( $post->ID, $issues, $info );
  242. }
  243. $original_width = ( isset( $meta ) && isset( $meta['width'] ) ) ? $meta['width'] : null;
  244. $original_height = ( isset( $meta ) && isset( $meta['height'] ) ) ? $meta['height'] : null;
  245. $attachmentsrc = wp_get_attachment_image_src( $post->ID, 'thumbnail' );
  246. echo "<tr class='wr2x-file-row' postId='" . $post->ID . "'>";
  247. if ( !$original_width || !$original_height ) {
  248. echo "<td colspan='2' style='padding: 15px;'>The metadata for the <a href='media.php?attachment_id={$post->ID}&action=edit'>Media #{$post->ID}</a> is broken. You can try <b>Generate</b> for this media (in the Media Library), <b>Bulk Generate</b>, or a <b>Full-Size Replace</b>.</td>";
  249. }
  250. else {
  251. echo "<td class='wr2x-image wr2x-info-thumbnail'><img src='" . $attachmentsrc[0] . "' /></td>";
  252. echo "<td class='wr2x-title'><a href='media.php?attachment_id=" . $post->ID . "&action=edit'>" . ( $post->post_title ? $post->post_title : '<i>Untitled</i>' ) . '</a><br />' .
  253. "<span class='resolution'>Full-Size: <span class='" . ( $original_width < $max_width ? "red" : "" ) . "'>" . $original_width . "</span>×<span class='" . ( $original_height < $max_height ? "red" : "" ) . "'>" . $original_height . "</span></span>";
  254. echo "<div class='actions'>";
  255. echo "<a style='position: relative;' onclick='wr2x_generate(" . $post->ID . ", true)' id='wr2x_generate_button_" . $post->ID . "' class='wr2x-button'>" . __( "GENERATE", 'wp-retina-2x' ) . "</a>";
  256. if ( !$this->core->is_ignore( $post->ID ) )
  257. echo " <a href='?page=wp-retina-2x&view=" . $view . "&paged=" . $paged . "&ignore=" . $post->ID . "' id='wr2x_generate_button_" . $post->ID . "' class='wr2x-button wr2x-button-ignore'>" . __( "IGNORE", 'wp-retina-2x' ) . "</a>";
  258. echo " <a style='position: relative;' class='wr2x-button wr2x-button-view'>" . __( "DETAILS", 'wp-retina-2x' ) . "</a>";
  259. echo "</div></td>";
  260. }
  261. // Media Sizes Retina-ized
  262. echo '<td id="wr2x-info-' . $post->ID . '" style="padding-top: 10px;" class="wr2x-info">';
  263. if ( $original_width && $original_height )
  264. echo $this->core->html_get_basic_retina_info( $post, $info );
  265. echo "</td>";
  266. if ( $this->core->admin->is_registered() ) {
  267. // Full-Size Replace
  268. echo "<td class='wr2x-fullsize-replace'><div class='wr2x-dragdrop'></div>";
  269. echo "</td>";
  270. // Full-Size Retina
  271. echo '<td id="wr2x-info-full-' . $post->ID . '" class="wr2x-image wr2x-info-full">';
  272. echo $this->core->html_get_basic_retina_info_full( $post->ID, $info );
  273. echo "</td>";
  274. // Full-Size Retina Upload
  275. echo "<td class='wr2x-fullsize-retina-upload'>";
  276. echo "<div class='wr2x-dragdrop'></div>";
  277. echo "</td>";
  278. }
  279. else
  280. echo "<td colspan='3' style='text-align: center; background: #F9F9F9;'><small><br />PRO VERSION ONLY</small></td>";
  281. echo "</tr>";
  282. }
  283. ?>
  284. </tbody>
  285. </table>
  286. </div>
  287. <?php
  288. }
  289. }
  290. ?>