| 1 |
<?php |
| 2 |
namespace epiphyt\Embed_Privacy; |
| 3 |
|
| 4 |
use epiphyt\Embed_Privacy\thumbnail\provider\SlideShare; |
| 5 |
use epiphyt\Embed_Privacy\thumbnail\provider\Vimeo; |
| 6 |
use epiphyt\Embed_Privacy\thumbnail\provider\YouTube; |
| 7 |
use epiphyt\Embed_Privacy\thumbnail\Thumbnail; |
| 8 |
|
| 9 |
/** |
| 10 |
* Thumbnails for Embed Privacy. |
| 11 |
* |
| 12 |
* @deprecated 1.9.0 Use the functionality of epiphyt\Embed_Privacy\thumbnail\Thumbnail instead |
| 13 |
* @since 1.5.0 |
| 14 |
* |
| 15 |
* @author Epiphyt |
| 16 |
* @license GPL2 |
| 17 |
* @package epiphyt\Embed_Privacy |
| 18 |
*/ |
| 19 |
class Thumbnails { |
| 20 |
// @deprecated: use Thumbnails::$directory instead |
| 21 |
const DIRECTORY = \WP_CONTENT_DIR . '/uploads/embed-privacy/thumbnails'; |
| 22 |
|
| 23 |
/** |
| 24 |
* @var array Fields to output |
| 25 |
*/ |
| 26 |
public $fields = []; |
| 27 |
|
| 28 |
/** |
| 29 |
* @var \epiphyt\Embed_Privacy\Thumbnails |
| 30 |
*/ |
| 31 |
private static $instance; |
| 32 |
|
| 33 |
/** |
| 34 |
* Thumbnails constructor. |
| 35 |
* |
| 36 |
* @deprecated 1.9.0 Use the functionality of epiphyt\Embed_Privacy\thumbnail\Thumbnail instead |
| 37 |
*/ |
| 38 |
public function __construct() { |
| 39 |
\_doing_it_wrong( |
| 40 |
__METHOD__, |
| 41 |
\sprintf( |
| 42 |
/* translators: alternative class */ |
| 43 |
\esc_html__( 'Use the functionality of %s instead.', 'embed-privacy' ), |
| 44 |
'epiphyt\Embed_Privacy\thumbnail\Thumbnail' |
| 45 |
), |
| 46 |
'1.9.0' |
| 47 |
); |
| 48 |
|
| 49 |
self::$instance = $this; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Initialize functions. |
| 54 |
* |
| 55 |
* @deprecated 1.9.0 Use the functionality of epiphyt\Embed_Privacy\thumbnail\Thumbnail instead |
| 56 |
*/ |
| 57 |
public function init() { |
| 58 |
\_doing_it_wrong( |
| 59 |
__METHOD__, |
| 60 |
\sprintf( |
| 61 |
/* translators: alternative class */ |
| 62 |
\esc_html__( 'Use the functionality of %s instead.', 'embed-privacy' ), |
| 63 |
'epiphyt\Embed_Privacy\thumbnail\Thumbnail' |
| 64 |
), |
| 65 |
'1.9.0' |
| 66 |
); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Check and delete orphaned thumbnails. |
| 71 |
* |
| 72 |
* @deprecated 1.9.0 Use epiphyt\Embed_Privacy\thumbnail\Thumbnail::delete_orphaned() instead |
| 73 |
* |
| 74 |
* @param int $post_id The post ID |
| 75 |
* @param \WP_Post $post The post object |
| 76 |
*/ |
| 77 |
public function check_orphaned( $post_id, $post ) { |
| 78 |
\_doing_it_wrong( |
| 79 |
__METHOD__, |
| 80 |
\sprintf( |
| 81 |
/* translators: alternative method */ |
| 82 |
\esc_html__( 'Use %s instead.', 'embed-privacy' ), |
| 83 |
'epiphyt\Embed_Privacy\thumbnail\Thumbnail::delete_orphaned()' |
| 84 |
), |
| 85 |
'1.9.0' |
| 86 |
); |
| 87 |
|
| 88 |
Embed_Privacy::get_instance()->thumbnail->delete_orphaned( $post_id, $post ); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Delete thumbnails for a given post ID. |
| 93 |
* |
| 94 |
* @deprecated 1.9.0 Use epiphyt\Embed_Privacy\thumbnail\Thumbnail::delete_thumbnails() instead |
| 95 |
* |
| 96 |
* @param int $post_id Post ID |
| 97 |
*/ |
| 98 |
public function delete_thumbnails( $post_id ) { |
| 99 |
\_doing_it_wrong( |
| 100 |
__METHOD__, |
| 101 |
\sprintf( |
| 102 |
/* translators: alternative method */ |
| 103 |
\esc_html__( 'Use %s instead.', 'embed-privacy' ), |
| 104 |
'epiphyt\Embed_Privacy\thumbnail\Thumbnail::delete_thumbnails()' |
| 105 |
), |
| 106 |
'1.9.0' |
| 107 |
); |
| 108 |
|
| 109 |
Thumbnail::delete_thumbnails( $post_id ); |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Get path and URL to an embed thumbnail. |
| 114 |
* |
| 115 |
* @deprecated 1.9.0 Use epiphyt\Embed_Privacy\thumbnail\Thumbnail::get_data() instead |
| 116 |
* |
| 117 |
* @param \WP_Post $post Post object |
| 118 |
* @param string $url Embedded URL |
| 119 |
* @return array Thumbnail path and URL |
| 120 |
*/ |
| 121 |
public function get_data( $post, $url ) { |
| 122 |
\_doing_it_wrong( |
| 123 |
__METHOD__, |
| 124 |
\sprintf( |
| 125 |
/* translators: alternative method */ |
| 126 |
\esc_html__( 'Use %s instead.', 'embed-privacy' ), |
| 127 |
'epiphyt\Embed_Privacy\thumbnail\Thumbnail::get_data()' |
| 128 |
), |
| 129 |
'1.9.0' |
| 130 |
); |
| 131 |
|
| 132 |
return Embed_Privacy::get_instance()->thumbnail->get_data( $post, $url ); |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Get the thumbnail directory and URL. |
| 137 |
* Since we don't want to have a directory per site in a network, we need to |
| 138 |
* get rid of the site ID in the path. |
| 139 |
* |
| 140 |
* @deprecated 1.9.0 Use epiphyt\Embed_Privacy\thumbnail\Thumbnail::get_directory() instead |
| 141 |
* @since 1.7.3 |
| 142 |
* |
| 143 |
* @return string[] Thumbnail directory and URL |
| 144 |
*/ |
| 145 |
public function get_directory() { |
| 146 |
\_doing_it_wrong( |
| 147 |
__METHOD__, |
| 148 |
\sprintf( |
| 149 |
/* translators: alternative method */ |
| 150 |
\esc_html__( 'Use %s instead.', 'embed-privacy' ), |
| 151 |
'epiphyt\Embed_Privacy\thumbnail\Thumbnail::get_directory()' |
| 152 |
), |
| 153 |
'1.9.0' |
| 154 |
); |
| 155 |
|
| 156 |
return Thumbnail::get_directory(); |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Get embed thumbnails from the embed provider. |
| 161 |
* |
| 162 |
* @deprecated 1.9.0 Use epiphyt\Embed_Privacy\thumbnail\Thumbnail::get_from_provider() instead |
| 163 |
* |
| 164 |
* @param string $output The returned oEmbed HTML |
| 165 |
* @param object $data A data object result from an oEmbed provider |
| 166 |
* @param string $url The URL of the content to be embedded |
| 167 |
* @return string The returned oEmbed HTML |
| 168 |
*/ |
| 169 |
public function get_from_provider( $output, $data, $url ) { |
| 170 |
\_doing_it_wrong( |
| 171 |
__METHOD__, |
| 172 |
\sprintf( |
| 173 |
/* translators: alternative method */ |
| 174 |
\esc_html__( 'Use %s instead.', 'embed-privacy' ), |
| 175 |
'epiphyt\Embed_Privacy\thumbnail\Thumbnail::get_from_provider()' |
| 176 |
), |
| 177 |
'1.9.0' |
| 178 |
); |
| 179 |
|
| 180 |
return Embed_Privacy::get_instance()->thumbnail->get_from_provider( $output, $data, $url ); |
| 181 |
} |
| 182 |
|
| 183 |
/** |
| 184 |
* Get a unique instance of the class. |
| 185 |
* |
| 186 |
* @return \epiphyt\Embed_Privacy\Thumbnails The single instance of this class |
| 187 |
*/ |
| 188 |
public static function get_instance() { |
| 189 |
if ( self::$instance === null ) { |
| 190 |
self::$instance = new self(); |
| 191 |
} |
| 192 |
|
| 193 |
return self::$instance; |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* Get a list of supported embed providers for thumbnails. |
| 198 |
* |
| 199 |
* @deprecated 1.9.0 |
| 200 |
* |
| 201 |
* @return array A list of supported embed providers |
| 202 |
*/ |
| 203 |
public function get_supported_providers() { |
| 204 |
\_doing_it_wrong( |
| 205 |
__METHOD__, |
| 206 |
\esc_html__( 'This method is outdated and will be removed in the future.', 'embed-privacy' ), |
| 207 |
'1.9.0' |
| 208 |
); |
| 209 |
|
| 210 |
$providers = Embed_Privacy::get_instance()->thumbnail->get_provider_titles(); |
| 211 |
|
| 212 |
/** |
| 213 |
* Filter the supported providers. |
| 214 |
* |
| 215 |
* @deprecated 1.9.0 |
| 216 |
* @since 1.7.0 |
| 217 |
* |
| 218 |
* @param array $supported_providers Current supported providers |
| 219 |
*/ |
| 220 |
$providers = \apply_filters_deprecated( 'embed_privacy_thumbnail_supported_providers', $providers, '1.9.0' ); |
| 221 |
|
| 222 |
return $providers; |
| 223 |
} |
| 224 |
|
| 225 |
/** |
| 226 |
* Download and save a SlideShare thumbnail. |
| 227 |
* |
| 228 |
* @deprecated 1.9.0 Use epiphyt\Embed_Privacy\thumbnail\provider\SlideShare::save() instead |
| 229 |
* @since 1.7.0 |
| 230 |
* |
| 231 |
* @param string $id SlideShare embed ID |
| 232 |
* @param string $url SlideShare deck URL |
| 233 |
* @param string $thumbnail_url SlideShare thumbnail URL |
| 234 |
*/ |
| 235 |
public function set_slideshare_thumbnail( $id, $url, $thumbnail_url ) { |
| 236 |
\_doing_it_wrong( |
| 237 |
__METHOD__, |
| 238 |
\sprintf( |
| 239 |
/* translators: alternative method */ |
| 240 |
\esc_html__( 'Use %s instead.', 'embed-privacy' ), |
| 241 |
'epiphyt\Embed_Privacy\thumbnail\provider\SlideShare::save()' |
| 242 |
), |
| 243 |
'1.9.0' |
| 244 |
); |
| 245 |
|
| 246 |
SlideShare::save( $id, $url, $thumbnail_url ); |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* Download and save a Vimeo thumbnail. |
| 251 |
* |
| 252 |
* @deprecated 1.9.0 Use epiphyt\Embed_Privacy\thumbnail\provider\Vimeo::save() instead |
| 253 |
* |
| 254 |
* @param string $id Vimeo video ID |
| 255 |
* @param string $url Vimeo video URL |
| 256 |
* @param string $thumbnail_url Vimeo thumbnail URL |
| 257 |
*/ |
| 258 |
public function set_vimeo_thumbnail( $id, $url, $thumbnail_url ) { |
| 259 |
\_doing_it_wrong( |
| 260 |
__METHOD__, |
| 261 |
\sprintf( |
| 262 |
/* translators: alternative method */ |
| 263 |
\esc_html__( 'Use %s instead.', 'embed-privacy' ), |
| 264 |
'epiphyt\Embed_Privacy\thumbnail\provider\Vimeo::save()' |
| 265 |
), |
| 266 |
'1.9.0' |
| 267 |
); |
| 268 |
|
| 269 |
Vimeo::save( $id, $url, $thumbnail_url ); |
| 270 |
} |
| 271 |
|
| 272 |
/** |
| 273 |
* Download and save a YouTube thumbnail. |
| 274 |
* |
| 275 |
* @deprecated 1.9.0 Use epiphyt\Embed_Privacy\thumbnail\provider\YouTube::save() instead |
| 276 |
* |
| 277 |
* @param string $id YouTube video ID |
| 278 |
* @param string $url YouTube video URL |
| 279 |
*/ |
| 280 |
public function set_youtube_thumbnail( $id, $url ) { |
| 281 |
\_doing_it_wrong( |
| 282 |
__METHOD__, |
| 283 |
\sprintf( |
| 284 |
/* translators: alternative method */ |
| 285 |
\esc_html__( 'Use %s instead.', 'embed-privacy' ), |
| 286 |
'epiphyt\Embed_Privacy\thumbnail\provider\YouTube::save()' |
| 287 |
), |
| 288 |
'1.9.0' |
| 289 |
); |
| 290 |
|
| 291 |
YouTube::save( $id, $url ); |
| 292 |
} |
| 293 |
} |
| 294 |
|