DG_OPTION_NAME, 'tab' => 'thumbnail-management-tab' ); /** * Register settings for the tab. */ function dg_register_settings() { add_settings_section( 'thumbnail_table', '', 'dg_render_thumbnail_section', DG_OPTION_NAME ); } /** * Validate settings for the tab. */ function dg_validate_settings( $values ) { global $dg_options; $ret = $dg_options; $responseArr = array( 'result' => false ); if ( isset( $values['entry'] ) ) { $ID = intval( $values['entry'] ); } else { $ID = - 1; } // Thumbnail(s) cleanup; // cleanup value is a marker if ( isset( $values['cleanup'] ) && isset( $values['ids'] ) ) { $deleted = array_values( array_intersect( array_keys( DG_Thumb::getThumbs() ), $values['ids'] ) ); DG_Thumb::purgeThumbs( $deleted ); $responseArr['result'] = true; $responseArr['deleted'] = $deleted; } // Attachment title update // title value is a marker elseif ( isset( $values['title'] ) && $ID != - 1 ) { $attachment = array( 'ID' => $ID, 'post_title' => rawurldecode( addslashes( $values['title'] ) ) ); if ( wp_update_post( $attachment ) ) { $responseArr['result'] = true; } } // Attachment description update // description value is a marker elseif ( isset( $values['description'] ) && $ID != - 1 ) { $attachment = array( 'ID' => $ID, 'post_content' => rawurldecode( addslashes( $values['description'] ) ) ); if ( wp_update_post( $attachment ) ) { $responseArr['result'] = true; } } // Thumbnail file manual refresh (one at a time) // upload value is a marker elseif ( isset( $values['upload'] ) && isset( $_FILES['file'] ) && array_key_exists( $ID, DG_Thumb::getThumbs() ) ) { $uploaded_filename = DG_Admin::validateUploadedFile(); if ( $uploaded_filename && ( $thumb = DG_Thumber::setThumbnail( $ID, $uploaded_filename ) ) ) { $responseArr['result'] = true; $responseArr['url'] = $thumb->getUrl(); } } if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); echo wp_json_encode( $responseArr ); add_filter( 'wp_redirect', 'dg_exit', 1, 0 ); } return $ret; } /** * Render the Thumbnail table. */ function dg_render_thumbnail_section() { global $dg_url_params; include_once DG_PATH . 'inc/class-thumber.php'; static $limit_options = array( 10, 25, 75 ); static $order_options = array( 'asc', 'desc' ); static $orderby_options = array( 'date', 'title' ); $options = DG_Thumber::getOptions(); // find subset of thumbs to be included $orderby = $dg_url_params['orderby'] = dg_get_orderby_param( $orderby_options ); $order = $dg_url_params['order'] = dg_get_order_param( $order_options ); $limit = $dg_url_params['limit'] = dg_get_limit_param(); /** @var DG_Thumb[] $thumbs */ $thumbs = DG_Thumb::getThumbs( $options['width'] . 'x' . $options['height'] ); uasort( $thumbs, 'dg_cmp_thumb' ); $thumbs_number = count( $thumbs ); $lastsheet = ceil( $thumbs_number / $limit ); $sheet = isset( $_REQUEST['sheet'] ) ? absint( $_REQUEST['sheet'] ) : 1; if ( $sheet === 0 || $sheet > $lastsheet ) { $sheet = 1; } $offset = ( $sheet - 1 ) * $limit; $thumbs = array_slice( $thumbs, $offset, $limit, true ); // https://core.trac.wordpress.org/ticket/12212 $posts = array(); if ( ! empty( $thumbs ) ) { $posts = get_posts( array( 'post_type' => 'any', 'post_status' => 'any', 'numberposts' => - 1, 'post__in' => array_keys( $thumbs ), 'orderby' => 'post__in' ) ); } foreach ( $posts as $post ) { $path_parts = pathinfo( $post->guid ); $thumb = $thumbs[$post->ID]; $thumbs[$post->ID] = array(); $t = &$thumbs[$post->ID]; $t['timestamp'] = $thumb->getTimestamp(); $t['title'] = dg_get_thumb_title( $post ); $t['ext'] = isset( $path_parts['extension'] ) ? $path_parts['extension'] : ''; $t['description'] = $post->post_content; $t['icon'] = $thumb->isSuccess() ? $thumb->getUrl() : DG_DefaultThumber::getInstance()->getThumbnail( $post->ID ); } unset( $posts ); $select_limit = ''; foreach ( $limit_options as $l_o ) { $select_limit .= '' . PHP_EOL; } $thead = '
| "> |
Drop file here or
|