PluginProbe
Image Source Control Lite – Show Image Credits and Captions / trunk
Image Source Control Lite – Show Image Credits and Captions vtrunk
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 trunk, at includes/isc.class.php

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