setCallback( self::$webhook ); $req->setMimeType( $mime_type ); $req->setNonce( $ID . self::NonceSeparator . md5( microtime() ) ); $req->setPg( $pg ); $req->setGeometry( $options['width'] . 'x' . $options['height'] ); if ( $dg_options['thumber-co']['direct_upload'] ) { $req->setDecodedData( file_get_contents( $url_or_path ) ); } else { $req->setUrl( $url_or_path ); } $resp = self::$client->sendThumbRequest( $req ); if ( $resp['http_code'] < 200 || $resp['http_code'] > 399 ) { DG_Logger::writeLog( DG_LogLevel::Error, 'Failed to transmit to server: ' . $resp['body'] ); } // always returns false -- we set the thumbnail later when webhook is hit return false; } /** * @return string[] The extensions supported by this thumber. */ protected function getThumberExtensions() { return self::$client->getMimeTypes(); } /** * @return int An integer from 0 to 100. Higher priorities will be attempted before lower priority thumbers. */ public function getPriority() { return 5; } /** * @return bool Whether Thumber.co may be used in thumbnail generation. */ public static function isThumberCoAvailable() { global $dg_options; return isset( $dg_options['thumber-co']['uid'] ) && isset( $dg_options['thumber-co']['secret'] ); } /** * TODO: This should be a configurable option and should include all Thumber types not default WP-supported. * @param $mimes string[] The MIME types WP knows about. * @return string[] Modified MIME types -- adding additional supported types. */ public static function customMimeTypes($mimes) { $mimes['pub'] = 'application/mspublisher'; return $mimes; } /** * WP by default will not handle POSTs from Thumber so add a special case for the action we want to handle. * @param $origin string Origin URL. If not provided, the value of get_http_origin() is used. * @param $origin_arg string Unused. * * @return string Origin URL if allowed, empty string if not. */ public static function allowThumberWebhooks($origin, $origin_arg) { if ( !$origin && isset( $_REQUEST['action'] ) && $_REQUEST['action'] === self::ThumberAction ) { $origin = get_http_origin(); } return $origin; } /** * @param string $filename File to be tested. * @return bool Whether file is acceptable to be sent to Thumber. */ private static function checkFileSize($filename ) { $ret = true; $size = @filesize( $filename ); if ( $size !== false ) { $sub = self::$client->getSubscription(); $ret = ( ! $sub || empty( $sub['file_size_limit'] ) ) || ( $size > 0 && $size <= $sub['file_size_limit'] ); } return $ret; } /** * @param $width int The requested thumb width. * @param $height int The requested thumb height. * @return bool Whether the requested geometry meets subscription limitations. */ private static function checkGeometry( $width, $height ) { $sub = self::$client->getSubscription(); return ( ! $sub || empty( $sub['thumb_size_limit'] ) ) || ( $width <= $sub['thumb_size_limit'] && $height <= $sub['thumb_size_limit'] ); } } add_action( 'admin_post_nopriv_' . DG_ThumberCoThumber::ThumberAction, array( DG_ThumberClient::getInstance(), 'receiveThumbResponse' ), 5, 0); DG_ThumberCoThumber::init();