/**
  * Returns HTML representing this Document.
  * @filter dg_icon_template Filters the DG icon HTML. Passes a single
  *    bool value indicating whether the gallery is using descriptions or not.
  * @return string The gallery HTML.
  */
 public function __toString()
 {
     include_once DG_PATH . 'inc/class-thumber.php';
     $data = '';
     $description = '';
     $target = $this->gallery->openLinkInNewWindow() ? '_blank' : '_self';
     if ($this->gallery->useFancyThumbs()) {
         $thumb_obj = DG_Thumb::getThumb($this->ID);
         if (!is_null($thumb_obj)) {
             if ($thumb_obj->isSuccess()) {
                 // icon has already been generated so include it in generated gallery
                 $thumb = $thumb_obj->getUrl();
             }
         } else {
             // include a data-* attribute for client side to asynchronously request icon after gallery load
             $data = 'data-id="' . $this->ID . '"';
         }
     }
     if (!isset($thumb)) {
         $thumb = DG_DefaultThumber::init()->getThumbnail($this->ID);
     }
     $repl = array($this->link, $thumb, $this->title_attribute, $this->title, $target, $this->extension, $this->size, $this->path, $data);
     $find = array('%link%', '%img%', '%title_attribute%', '%title%', '%target%', '%extension%', '%size%', '%path%', '%data%');
     // if descriptions then add filterable tag and value to replaced tag
     if ($this->gallery->useDescriptions()) {
         $repl[] = $this->description;
         $find[] = '%description%';
         $description = '   <p>%description%</p>';
     }
     $doc_icon = '   <div class="document-icon">' . PHP_EOL . '      <a href="%link%" target="%target%">' . PHP_EOL . '         <img src="%img%" title="%title_attribute%" alt="%title_attribute%" %data%/>' . PHP_EOL . '         <span class="title">%title%</span>' . PHP_EOL . '      </a>' . PHP_EOL . '   </div>' . PHP_EOL . $description;
     // allow developers to filter icon output
     $doc_icon = apply_filters('dg_icon_template', $doc_icon, $this->gallery->useDescriptions(), $this->ID);
     return str_replace($find, $repl, $doc_icon);
 }
 /**
  * Wraps generation of thumbnails for various attachment filetypes.
  *
  * @param int $ID Document ID
  * @param int $pg Page number to get thumb from.
  * @param bool $generate_if_missing Whether to attempt generating the thumbnail if missing.
  * @param bool|null &$is_default Whether the returned URL points to a default icon.
  *
  * @return string URL to the thumbnail.
  */
 public function getThumbnail($ID, $pg = 1, $generate_if_missing = true, &$is_default = null)
 {
     $options = self::getOptions();
     $dimensions = $options['width'] . 'x' . $options['height'];
     // if we haven't saved a thumb, generate one
     if (!DG_Thumb::thumbExists($ID, $dimensions, false)) {
         // short-circuit generation if not required
         if (!$generate_if_missing) {
             return null;
         }
         foreach (self::getThumbers() as $thumber) {
             if ($thumber->supportsAttachment($ID)) {
                 if (DG_Logger::logEnabled()) {
                     $toLog = sprintf(__('Attempting to generate thumbnail for attachment #%d with (%s)', 'document-gallery'), $ID, get_class($thumber));
                     DG_Logger::writeLog(DG_LogLevel::Detail, $toLog);
                 }
                 if ($generated = self::thumbnailGenerationHarness($thumber, $ID, $pg)) {
                     break;
                 }
             }
         }
     }
     $thumb = isset($generated) ? $generated : DG_Thumb::getThumb($ID, $dimensions);
     $is_thumb = is_a($thumb, 'DG_Thumb');
     $is_default = !$is_thumb || !$thumb->isSuccess();
     if (!$is_thumb) {
         $thumb = self::setThumbnailFailed($ID);
     }
     return $thumb->isSuccess() ? $thumb->getUrl() : DG_DefaultThumber::getInstance()->getThumbnail($ID, $pg);
 }
 /**
  * Render a Meta Box.
  * @param $post WP_Post The post.
  */
 public static function renderMetaBox($post)
 {
     // Disabling scripts that have nothing to do with Edit Media pages
     wp_dequeue_script('dg-media-manager');
     remove_filter('mce_external_plugins', array(__CLASS__, 'mce_external_plugins'));
     remove_filter('mce_css', array(__CLASS__, 'dg_plugin_mce_css'));
     wp_nonce_field(DG_OPTION_NAME . '_meta_box', DG_OPTION_NAME . '_meta_box_nonce');
     $ID = $post->ID;
     $options = DG_Thumber::getOptions();
     $thumb = DG_Thumb::getThumb($ID, $options['width'] . 'x' . $options['height']);
     $icon = !is_null($thumb) && $thumb->isSuccess() ? $thumb->getUrl() : DG_DefaultThumber::getInstance()->getThumbnail($ID);
     echo '<table id="ThumbsTable" class="wp-list-table widefat fixed media" cellpadding="0" cellspacing="0">' . '<tbody><tr data-entry="' . $ID . '"><td class="column-icon media-icon"><img src="' . $icon . '" />' . '</td><td class="column-thumbupload">' . '<span class="manual-download">' . '<span class="dashicons dashicons-upload"></span>' . '<span class="html5dndmarker">Drop file here<span> or </span></span>' . '<span class="buttons-area">' . '<input id="upload-button' . $ID . '" type="file" />' . '<input id="trigger-button' . $ID . '" type="button" value="Select File" class="button" />' . '</span>' . '</span>' . '</td></tr></tbody></table>' . (is_null($thumb) ? '<span class="dashicons dashicons-info"></span><span class="">Please note this attachment hasn&#39;t been used in any Document Gallery instance and so there is no autogenerated thumbnail, in the meantime default one is used instead.</span>' : '') . PHP_EOL;
 }