-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathclass-url.php
More file actions
156 lines (136 loc) · 3.08 KB
/
class-url.php
File metadata and controls
156 lines (136 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* URL class for the Cloudinary plugin.
*
* @package Cloudinary
*/
namespace Cloudinary;
use Cloudinary\Component\Setup;
use Cloudinary\Traits\Relation_Trait;
use Cloudinary\URL\Cloudinary;
use Cloudinary\URL\WordPress;
use Cloudinary\Delivery;
/**
* Class URL
*/
class URL implements Setup {
use Relation_Trait;
/**
* Holds the plugin instance.
*
* @var Plugin Instance of the global plugin.
*/
public $plugin;
/**
* Holds the Global Image transformations.
*
* @var string
*/
protected $image_transformations;
/**
* Holds the Global Video transformations.
*
* @var string
*/
protected $video_transformations;
/**
* Holds a list of the Cloudinary URL objects.
*
* @var array
*/
protected $cloudinary_urls = array();
/**
* Holds a list of the WordPress URL objects.
*
* @var array
*/
protected $wordpress_urls = array();
/**
* URL constructor.
*
* @param Plugin $plugin Global instance of the main plugin.
*/
public function __construct( Plugin $plugin ) {
$this->plugin = $plugin;
$this->setup_relations();
add_action( 'cloudinary_init_settings', array( $this, 'init_settings' ) );
}
/**
* Init settings.
*/
public function init_settings() {
$this->image_transformations = $this->plugin->settings->get_value( 'image_format', 'image_quality', 'image_freeform' );
$this->video_transformations = $this->plugin->settings->get_value( 'video_format', 'video_quality', 'video_freeform' );
}
/**
* Set up the object.
*/
public function setup() {
}
/**
* Get a Cloudinary URL object.
*
* @param string $url The Cloudinary URL to break apart.
*
* @return array
*/
public function cloudinary_url( $url ) {
if ( ! isset( $this->cloudinary_urls[ $url ] ) ) {
$this->cloudinary_urls[ $url ] = new Cloudinary( $url );
}
return $this->cloudinary_urls[ $url ];
}
/**
* Init an array of cloudinary urls
*
* @param array $urls An array of cloudinary URLs.
*/
public function cloudinary_urls( $urls ) {
foreach ( $urls as $url ) {
$this->cloudinary_url( $url );
}
}
/**
* Get all the cloudinary URL objects.
*
* @return Cloudinary[]
*/
public function get_cloudinary_urls() {
return $this->cloudinary_urls;
}
/**
* Break apart a WordPress URL
*
* @param string $url The WordPress URL to break apart.
*
* @return array
*/
public function wordpress_url( $url ) {
if ( ! isset( $this->wordpress_urls[ $url ] ) ) {
$this->wordpress_urls[ $url ] = new WordPress( $url );
}
return $this->wordpress_urls[ $url ];
}
/**
* Init am array of WordPress URLs.
*
* @param array $urls Array of WordPress URLs.
*/
public function wordpress_urls( $urls ) {
$method = $this->query_relations;
$relations = $method( array(), $urls );
foreach ( $relations as $relation ) {
$wp_object = $this->wordpress_url( $relation['sized_url'] );
$wp_object->set_relation( $relation );
$wp_object->cloudinary_url();
}
}
/**
* Get all the WordPress URL objects.
*
* @return WordPress[]
*/
public function get_wordpress_urls() {
return $this->wordpress_urls;
}
}