PluginProbe
Image Source Control Lite – Show Image Credits and Captions / 3.11.0
Image Source Control Lite – Show Image Credits and Captions v3.11.0
3.12.0 3.11.0 trunk 1.1 1.1.1 1.1.2 1.1.2.1 1.1.3 1.10 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.2 1.2.0.1 1.2.0.2 1.2.0.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.4.1 1.3.5 All 110 releases
image-source-control-isc / includes / isc.class.php

isc.class.php in Image Source Control Lite – Show Image Credits and Captions 3.11.0, at includes/isc.class.php

247 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use ISC\Image_Sources\Analyze_HTML;
4
5 /**
6 * Main controller of ISC
7 *
8 * @deprecated since 3.0.0 Use ISC\Image_Sources\Image_Sources or ISC\Plugin instead
9 */
10 class ISC_Class {
11
12 /**
13 * Define default meta fields
14 *
15 * @var array option fields.
16 */
17 protected $fields = [
18 'image_source' => [
19 'id' => 'isc_image_source',
20 'default' => '',
21 ],
22 'image_source_url' => [
23 'id' => 'isc_image_source_url',
24 'default' => '',
25 ],
26 'image_source_own' => [
27 'id' => 'isc_image_source_own',
28 'default' => '',
29 ],
30 'image_posts' => [
31 'id' => 'isc_image_posts',
32 'default' => [],
33 ],
34 'image_licence' => [
35 'id' => 'isc_image_licence',
36 'default' => '',
37 ],
38 ];
39
40 /**
41 * Allowed image file types/extensions
42 *
43 * @var array allowed image extensions.
44 */
45 public $allowed_extensions = [
46 'jpg',
47 'png',
48 'gif',
49 'jpeg',
50 'webp',
51 ];
52
53 /**
54 * Thumbnail size in list of all images.
55 *
56 * @var array available thumbnail sizes.
57 */
58 protected $thumbnail_size = [ 'thumbnail', 'medium', 'large', 'custom' ];
59
60 /**
61 * Options saved in the db
62 *
63 * @var array plugin options.
64 */
65 protected $options = [];
66
67 /**
68 * Instance of ISC_Class.
69 *
70 * @var ISC_Class
71 */
72 protected static $instance;
73
74 /**
75 * Instance of ISC_Model.
76 *
77 * @var ISC_Model
78 */
79 protected $model;
80
81 /**
82 * Get instance of ISC_Class
83 *
84 * @return ISC_Class
85 */
86 public static function get_instance() {
87 return self::$instance;
88 }
89
90 /**
91 * Helper to extract information from HTML
92 *
93 * @var Analyze_HTML
94 */
95 public $html_analyzer;
96
97 /**
98 * Setup registers filters and actions.
99 */
100 public function __construct() {
101 self::$instance = $this;
102 $this->model = new ISC_Model();
103 $this->html_analyzer = new Analyze_HTML();
104 }
105
106 /**
107 * Returns default options
108 *
109 * @return string[]
110 */
111 public function default_options() {
112 _deprecated_function( __METHOD__, '3.0.0', 'ISC\Options::default_options' );
113
114 return ISC\Plugin::default_options();
115 }
116
117 /**
118 * Returns isc_options if it exists, returns the default options otherwise.
119 *
120 * @return string[]
121 */
122 public function get_isc_options() {
123 _deprecated_function( __METHOD__, '3.0.0', 'ISC\Options::get_options' );
124
125 $this->options = get_option( 'isc_options', $this->default_options() );
126
127 return $this->options;
128 }
129
130 /**
131 * Transform the licenses from the options textfield into an array
132 *
133 * @param string $licences text with licenses.
134 * @return array|bool $new_licences array with licenses and license information or false if no array created.
135 * @since 1.3.5
136 */
137 public function licences_text_to_array( $licences = '' ) {
138 _deprecated_function( __METHOD__, '3.0.0', 'ISC\Image_Sources\Image_Sources::license_text_to_array' );
139
140 if ( $licences === '' ) {
141 return false;
142 }
143 // split the text by line
144 $licences_array = preg_split( '/\r?\n/', trim( $licences ) );
145 if ( count( $licences_array ) === 0 ) {
146 return false;
147 }
148 // create the array with licence => url
149 $new_licences = [];
150 foreach ( $licences_array as $_licence ) {
151 if ( trim( $_licence ) !== '' ) {
152 $temp = explode( '|', $_licence );
153 $new_licences[ $temp[0] ] = [];
154 if ( isset( $temp[1] ) ) {
155 $new_licences[ $temp[0] ]['url'] = esc_url( $temp[1] );
156 }
157 }
158 }
159
160 if ( $new_licences === [] ) {
161 return false;
162 } else {
163 return $new_licences;
164 }
165 }
166
167 /**
168 * Control if we are dynamically checking if sources are missing each time attachments are updated
169 * using the "updated_{$meta_type}_meta" hook
170 *
171 * @param int $meta_id ID of updated metadata entry.
172 * @param int $object_id ID of the object metadata is for.
173 * @param string $meta_key Metadata key.
174 */
175 public function maybe_update_attachment_post_meta( $meta_id, $object_id, $meta_key ) {
176 _deprecated_function( __METHOD__, '3.0.0', 'ISC\Image_Sources\Image_Sources::maybe_update_attachment_post_meta' );
177
178 if ( in_array( $meta_key, [ 'isc_image_source_own', 'isc_image_source' ], true ) ) {
179 ISC_Model::update_missing_sources_transient();
180 }
181 }
182
183 /**
184 * Get image source string before it was filtered for output
185 *
186 * @param int $attachment_id attachment ID.
187 * @return string
188 */
189 public static function get_image_source_text( $attachment_id ) {
190 _deprecated_function( __METHOD__, '3.0.0', 'ISC\Image_Sources\Image_Sources::get_image_source_text' );
191
192 return apply_filters(
193 'isc_raw_attachment_get_source',
194 get_post_meta( $attachment_id, 'isc_image_source', true ),
195 $attachment_id
196 );
197 }
198
199 /**
200 * Get image source URL before it was filtered for output
201 *
202 * @param int $attachment_id attachment ID.
203 * @return string
204 */
205 public static function get_image_source_url( $attachment_id ) {
206 _deprecated_function( __METHOD__, '3.0.0', 'ISC\Image_Sources\Image_Sources::get_image_source_url' );
207
208 return apply_filters(
209 'isc_raw_attachment_get_source_url',
210 get_post_meta( $attachment_id, 'isc_image_source_url', true ),
211 $attachment_id
212 );
213 }
214
215 /**
216 * Get image license value before it was filtered for output
217 *
218 * @param int $attachment_id attachment ID.
219 * @return string
220 */
221 public static function get_image_license( $attachment_id ) {
222 _deprecated_function( __METHOD__, '3.0.0', 'ISC\Image_Sources\Image_Sources::get_image_license' );
223
224 return apply_filters(
225 'isc_raw_attachment_get_license',
226 get_post_meta( $attachment_id, 'isc_image_licence', true ),
227 $attachment_id
228 );
229 }
230
231 /**
232 * Get image title
233 *
234 * @param integer|string $attachment_id attachment ID.
235 * @return string
236 */
237 public static function get_image_title( $attachment_id ) {
238 _deprecated_function( __METHOD__, '3.0.0', 'ISC\Image_Sources\Image_Sources::get_image_title' );
239
240 return apply_filters(
241 'isc_raw_attachment_title',
242 get_the_title( $attachment_id ),
243 $attachment_id
244 );
245 }
246 }
247