/**
  * Adds the meta items_per_page default value.
  * Paginate & skip options were added.
  * Moving cached thumbs into postmeta table.
  *
  * @param mixed[][] $options The options to be modified.
  */
 private static function fourPointZero(&$options)
 {
     if (version_compare($options['meta']['version'], '4.0', '<')) {
         $options['gallery']['paginate'] = true;
         $options['gallery']['skip'] = 0;
         $options['meta']['items_per_page'] = 10;
         $upload_dir = wp_upload_dir();
         $upload_len = strlen($upload_dir['basedir']);
         $dimensions = $options['thumber']['width'] . 'x' . $options['thumber']['height'];
         foreach ($options['thumber']['thumbs'] as $id => $thumb) {
             $thumb_obj = new DG_Thumb();
             $thumb_obj->setPostId($id);
             $thumb_obj->setTimestamp($thumb['timestamp']);
             $thumb_obj->setDimensions($dimensions);
             if (isset($thumb['thumb_path'])) {
                 $thumb_obj->setRelativePath(substr($thumb['thumb_path'], $upload_len + 1));
                 $thumb_obj->setGenerator(DG_Util::callableToString($thumb['thumber']));
             }
             $thumb_obj->save();
         }
         unset($options['thumber']['thumbs']);
     }
 }
 /**
  * Template that handles generating a thumbnail.
  *
  * If image has already been generated through other means, $pg may be set to the system path where the
  * thumbnail is located. In this case, $generator will not be invoked, but *will* be kept for historical purposes.
  *
  * @param DG_AbstractThumber|string $generator Takes ID and pg and returns path to temp file or false.
  * @param int $ID ID for the attachment that we need a thumbnail for.
  * @param int|string $pg Page number of the attachment to get a thumbnail for or the system path to the image to be used.
  *
  * @return DG_Thumb|bool The generated thumbnail or false on failure.
  */
 private static function thumbnailGenerationHarness($generator, $ID, $pg = 1)
 {
     // handle system page in $pg variable
     if (is_string($pg) && !is_numeric($pg)) {
         $temp_path = $pg;
     } elseif (is_a($generator, 'DG_AbstractThumber')) {
         // delegate thumbnail generation to $generator
         if (false === ($temp_path = $generator->getThumbnail($ID, $pg))) {
             return false;
         }
         // NOTE: get string representation to be stored with thumb in DB
         $generator = get_class($generator);
     } else {
         DG_Logger::writeLog(DG_LogLevel::Error, 'Attempted to call thumbnailGenerationHarness with invalid generator: ' . print_r($generator, true));
         return false;
     }
     // get some useful stuff
     $doc_path = get_attached_file($ID);
     $dirname = dirname($doc_path);
     $basename = basename($doc_path);
     if (false === ($len = strrpos($basename, '.'))) {
         $len = strlen($basename);
     }
     $extless = substr($basename, 0, $len);
     $ext = self::getExt($temp_path);
     $thumb_name = self::getUniqueThumbName($dirname, $extless, $ext);
     $thumb_path = "{$dirname}/{$thumb_name}";
     // scale generated image down
     $img = wp_get_image_editor($temp_path);
     if (is_wp_error($img)) {
         DG_Logger::writeLog(DG_LogLevel::Error, __('Failed to get image editor: ', 'document-gallery') . $img->get_error_message());
         return false;
     }
     $options = self::getOptions();
     $img->resize($options['width'], $options['height'], false);
     $err = $img->save($thumb_path);
     if (is_wp_error($err)) {
         DG_Logger::writeLog(DG_LogLevel::Error, __('Failed to save image: ', 'document-gallery') . $err->get_error_message());
         return false;
     }
     // do some cleanup
     @unlink($temp_path);
     // save new thumb
     DG_Logger::writeLog(DG_LogLevel::Detail, 'Creating thumb object.');
     $upload = wp_upload_dir();
     $thumb = new DG_Thumb();
     $thumb->setPostId($ID);
     $thumb->setDimensions($options['width'] . 'x' . $options['height']);
     $thumb->setTimestamp(time());
     $thumb->setRelativePath(substr($thumb_path, strlen($upload['basedir']) + 1));
     $thumb->setGenerator($generator);
     $thumb->save();
     return $thumb;
 }