| 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 |
use WP_Post; |
| 9 |
|
| 10 |
/** |
| 11 |
* Thumbnails for Embed Privacy. |
| 12 |
* |
| 13 |
* @deprecated 1.9.0 |
| 14 |
* @since 1.5.0 |
| 15 |
* |
| 16 |
* @author Epiphyt |
| 17 |
* @license GPL2 |
| 18 |
* @package epiphyt\Embed_Privacy |
| 19 |
*/ |
| 20 |
class Thumbnails { |
| 21 |
// @deprecated: use Thumbnails::$directory instead |
| 22 |
const DIRECTORY = \WP_CONTENT_DIR . '/uploads/embed-privacy/thumbnails'; |
| 23 |
|
| 24 |
/** |
| 25 |
* @var array Fields to output |
| 26 |
*/ |
| 27 |
public $fields = []; |
| 28 |
|
| 29 |
/** |
| 30 |
* @var \epiphyt\Embed_Privacy\Thumbnails |
| 31 |
*/ |
| 32 |
private static $instance; |
| 33 |
|
| 34 |
/** |
| 35 |
* Post Type constructor. |
| 36 |
* |
| 37 |
* @deprecated 1.9.0 |
| 38 |
*/ |
| 39 |
public function __construct() { |
| 40 |
self::$instance = $this; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Initialize functions. |
| 45 |
* |
| 46 |
* @deprecated 1.9.0 |
| 47 |
*/ |
| 48 |
public function init() { } |
| 49 |
|
| 50 |
/** |
| 51 |
* Check and delete orphaned thumbnails. |
| 52 |
* |
| 53 |
* @deprecated 1.9.0 |
| 54 |
* |
| 55 |
* @param int $post_id The post ID |
| 56 |
* @param \WP_Post $post The post object |
| 57 |
*/ |
| 58 |
public function check_orphaned( $post_id, $post ) { |
| 59 |
Embed_Privacy::get_instance()->thumbnail->delete_orphaned( $post_id, $post ); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Delete thumbnails for a given post ID. |
| 64 |
* |
| 65 |
* @deprecated 1.9.0 |
| 66 |
* |
| 67 |
* @param int $post_id Post ID |
| 68 |
*/ |
| 69 |
public function delete_thumbnails( $post_id ) { |
| 70 |
Thumbnail::delete_thumbnails( $post_id ); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Get path and URL to an embed thumbnail. |
| 75 |
* |
| 76 |
* @deprecated 1.9.0 |
| 77 |
* |
| 78 |
* @param \WP_Post $post Post object |
| 79 |
* @param string $url Embedded URL |
| 80 |
* @return array Thumbnail path and URL |
| 81 |
*/ |
| 82 |
public function get_data( $post, $url ) { |
| 83 |
return Embed_Privacy::get_instance()->thumbnail->get_data( $post, $url ); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Get the thumbnail directory and URL. |
| 88 |
* Since we don't want to have a directory per site in a network, we need to |
| 89 |
* get rid of the site ID in the path. |
| 90 |
* |
| 91 |
* @deprecated 1.9.0 |
| 92 |
* @since 1.7.3 |
| 93 |
* |
| 94 |
* @return string[] Thumbnail directory and URL |
| 95 |
*/ |
| 96 |
public function get_directory() { |
| 97 |
return Thumbnail::get_directory(); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Get embed thumbnails from the embed provider. |
| 102 |
* |
| 103 |
* @deprecated 1.9.0 |
| 104 |
* |
| 105 |
* @param string $return The returned oEmbed HTML |
| 106 |
* @param object $data A data object result from an oEmbed provider |
| 107 |
* @param string $url The URL of the content to be embedded |
| 108 |
* @return string The returned oEmbed HTML |
| 109 |
*/ |
| 110 |
public function get_from_provider( $return, $data, $url ) { |
| 111 |
return Embed_Privacy::get_instance()->thumbnail->get_from_provider( $return, $data, $url ); |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Get a unique instance of the class. |
| 116 |
* |
| 117 |
* @return \epiphyt\Embed_Privacy\Thumbnails The single instance of this class |
| 118 |
*/ |
| 119 |
public static function get_instance() { |
| 120 |
if ( self::$instance === null ) { |
| 121 |
self::$instance = new self(); |
| 122 |
} |
| 123 |
|
| 124 |
return self::$instance; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Get a list of supported embed providers for thumbnails. |
| 129 |
* |
| 130 |
* @deprecated 1.9.0 |
| 131 |
* |
| 132 |
* @return array A list of supported embed providers |
| 133 |
*/ |
| 134 |
public function get_supported_providers() { |
| 135 |
$providers = Embed_Privacy::get_instance()->thumbnail->get_provider_titles(); |
| 136 |
|
| 137 |
/** |
| 138 |
* Filter the supported providers. |
| 139 |
* |
| 140 |
* @since 1.7.0 |
| 141 |
* @deprecated 1.9.0 |
| 142 |
* |
| 143 |
* @param array $supported_providers Current supported providers |
| 144 |
*/ |
| 145 |
$providers = \apply_filters_deprecated( 'embed_privacy_thumbnail_supported_providers', $providers, '1.9.0' ); |
| 146 |
|
| 147 |
return $providers; |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Download and save a SlideShare thumbnail. |
| 152 |
* |
| 153 |
* @deprecated 1.9.0 |
| 154 |
* @since 1.7.0 |
| 155 |
* |
| 156 |
* @param string $id SlideShare embed ID |
| 157 |
* @param string $url SlideShare deck URL |
| 158 |
* @param string $thumbnail_url SlideShare thumbnail URL |
| 159 |
*/ |
| 160 |
public function set_slideshare_thumbnail( $id, $url, $thumbnail_url ) { |
| 161 |
SlideShare::save( $id, $url, $thumbnail_url ); |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Download and save a Vimeo thumbnail. |
| 166 |
* |
| 167 |
* @deprecated 1.9.0 |
| 168 |
* |
| 169 |
* @param string $id Vimeo video ID |
| 170 |
* @param string $url Vimeo video URL |
| 171 |
* @param string $thumbnail_url Vimeo thumbnail URL |
| 172 |
*/ |
| 173 |
public function set_vimeo_thumbnail( $id, $url, $thumbnail_url ) { |
| 174 |
Vimeo::save( $id, $url, $thumbnail_url ); |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* Download and save a YouTube thumbnail. |
| 179 |
* |
| 180 |
* @deprecated 1.9.0 |
| 181 |
* |
| 182 |
* @param string $id YouTube video ID |
| 183 |
* @param string $url YouTube video URL |
| 184 |
*/ |
| 185 |
public function set_youtube_thumbnail( $id, $url ) { |
| 186 |
YouTube::save( $id, $url ); |
| 187 |
} |
| 188 |
} |
| 189 |
|