/**
 * 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;
    } elseif (isset($values['title']) && $ID != -1) {
        $attachment = array('ID' => $ID, 'post_title' => rawurldecode(addslashes($values['title'])));
        if (wp_update_post($attachment)) {
            $responseArr['result'] = true;
        }
    } elseif (isset($values['description']) && $ID != -1) {
        $attachment = array('ID' => $ID, 'post_content' => rawurldecode(addslashes($values['description'])));
        if (wp_update_post($attachment)) {
            $responseArr['result'] = true;
        }
    } 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;
}
 /**
  * Sets the thumbnail for the given attachment ID.
  *
  * @param int $ID Document ID.
  * @param string $path System path to thumbnail.
  * @param string $generator Descriptor for generation method -- usually method name.
  *
  * @return bool Whether set was successful.
  */
 public static function setThumbnail($ID, $path, $generator = 'unknown')
 {
     include_once DG_PATH . 'inc/class-thumber.php';
     return DG_Thumber::setThumbnail($ID, $path, $generator);
 }
 /**
  * Processes the POST request, generating a ThumberResponse, validating, and passing the result to $callback.
  * If not using client.php as the webhook, whoever receives webhook response should first invoke this method to
  * validate response.
  */
 public function receiveThumbResponse()
 {
     $resp = parent::receiveThumbResponse();
     if (is_null($resp)) {
         return;
     }
     $nonce = $resp->getNonce();
     $split = explode(DG_ThumberCoThumber::NonceSeparator, $nonce);
     if ($resp->getSuccess() && count($split) === 2) {
         $ID = absint($split[0]);
         $tmpfile = DG_Util::getTempFile();
         file_put_contents($tmpfile, $resp->getDecodedData());
         DG_Thumber::setThumbnail($ID, $tmpfile, array(__CLASS__, 'getThumberThumbnail'));
         DG_Logger::writeLog(DG_LogLevel::Detail, "Received thumbnail from Thumber for attachment #{$split[0]}.");
     } else {
         $ID = count($split) > 0 ? $split[0] : $nonce;
         DG_Logger::writeLog(DG_LogLevel::Warning, "Thumber was unable to process attachment #{$ID}: " . $resp->getError());
     }
 }
예제 #4
0
 /**
  * Save a Meta Box.
  */
 public static function saveMetaBox($post_id)
 {
     // Check if our nonce is set.
     // Verify that the nonce is valid.
     // If this is an autosave, our form has not been submitted, so we don't want to do anything.
     if (!isset($_POST[DG_OPTION_NAME . '_meta_box_nonce']) || !wp_verify_nonce($_POST[DG_OPTION_NAME . '_meta_box_nonce'], DG_OPTION_NAME . '_meta_box') || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     global $dg_options;
     $responseArr = array('result' => false);
     if (isset($_POST[DG_OPTION_NAME]['entry'])) {
         $ID = intval($_POST[DG_OPTION_NAME]['entry']);
     } else {
         $ID = -1;
     }
     if (isset($_POST[DG_OPTION_NAME]['upload']) && isset($_FILES['file']) && isset($dg_options['thumber']['thumbs'][$ID])) {
         $old_path = $dg_options['thumber']['thumbs'][$ID]['thumb_path'];
         $uploaded_filename = self::validateUploadedFile();
         if ($uploaded_filename && DG_Thumber::setThumbnail($ID, $uploaded_filename)) {
             if ($dg_options['thumber']['thumbs'][$ID]['thumb_path'] !== $old_path) {
                 @unlink($old_path);
             }
             $responseArr['result'] = true;
             $responseArr['url'] = $dg_options['thumber']['thumbs'][$ID]['thumb_url'];
         }
     }
     if (isset($_POST[DG_OPTION_NAME]['ajax'])) {
         wp_send_json($responseArr);
     }
 }