-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathMslsAdminIcon.php
265 lines (225 loc) · 4.33 KB
/
MslsAdminIcon.php
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
/**
* MslsAdminIcon
* @author Dennis Ploetner <[email protected]>
* @since 0.9.8
*/
namespace lloc\Msls;
use lloc\Msls\Component\Icon\IconSvg;
/**
* Handles the icon links in the backend
* @package Msls
*/
class MslsAdminIcon {
/**
* IconType
* @var string
*/
protected $iconType = 'action';
/**
* Language
* @var string
*/
protected $language;
/**
* Origin Language
* @var string
*/
public $origin_language;
/**
* Source
* @var string
*/
protected $src;
/**
* URL
* @var string
*/
protected $href;
/**
* Blog id
* @var int
*/
protected $blog_id;
/**
* Type
* @var string
*/
protected $type;
/**
* Path
* @var string
*/
protected $path = 'post-new.php';
/**
* The current object ID
* @var int
*/
protected $id;
/**
* Constructor
*
* @param string $type
*/
public function __construct( $type ) {
$this->type = esc_attr( $type );
$this->set_path();
}
/**
* @return string
*/
public function __toString() {
return $this->get_a();
}
/**
* @codeCoverageIgnore
*
* @return MslsAdminIcon
*/
public static function create() {
$obj = MslsContentTypes::create();
$type = $obj->get_request();
if ( $obj->is_taxonomy() ) {
return new MslsAdminIconTaxonomy( $type );
}
return new MslsAdminIcon( $type );
}
/**
* Set the icon path
*
* @return MslsAdminIcon
*/
public function set_icon_type( $iconType ) {
$this->iconType = $iconType;
return $this;
}
/**
* Set the path by type
*
* @return MslsAdminIcon
*/
public function set_path() {
if ( 'post' != $this->type ) {
$query_vars = [ 'post_type' => $this->type ];
$this->path = add_query_arg( $query_vars, $this->path );
}
return $this;
}
/**
* Set language
*
* @param string $language
*
* @return MslsAdminIcon
*/
public function set_language( $language ) {
$this->language = $language;
return $this;
}
/**
* Set src
*
* @param string $src
*
* @return MslsAdminIcon
*/
public function set_src( $src ) {
$this->src = $src;
return $this;
}
/**
* Set href
*
* @param int $id
*
* @return MslsAdminIcon
*/
public function set_href( $id ) {
//foreach ($id as $idx) {
$this->href = get_edit_post_link( $id );
//}
return $this;
}
/**
* Sets the id of the object this icon is for
*
* @param int $id
*
* @return MslsAdminIcon
*/
public function set_id( $id ) {
$this->id = $id;
return $this;
}
/**
* Sets the origin language for this icon
*
* @param string $origin_language
*
* @return MslsAdminIcon
*/
public function set_origin_language( $origin_language ) {
$this->origin_language = $origin_language;
return $this;
}
/**
* Get image as html-tag
*
* @return string
*/
public function get_img() {
return sprintf( '<img alt="%s" src="%s" />', $this->language, $this->src );
}
/**
* Get link as html-tag
*
* @return string
*/
public function get_a(): string {
if ( empty( $this->href ) ) {
$title = sprintf( __( 'Create a new translation in the %s-blog', 'multisite-language-switcher' ), $this->language );
$href = $this->get_edit_new();
} else {
$title = sprintf( __( 'Edit the translation in the %s-blog', 'multisite-language-switcher' ), $this->language );
$href = $this->href;
}
return sprintf( '<a title="%s" href="%s">%s</a> ', $title, $href, $this->get_icon() );
}
/**
* Get icon as html-tag
*
* @return string
*/
public function get_icon() {
if ( 'flag' === $this->iconType ) {
return sprintf( '<span class="flag-icon %s">%s</span>',
( new IconSvg() )->get( $this->language ),
$this->language
);
}
if ( empty( $this->href ) ) {
return '<span class="dashicons dashicons-plus"></span>';
}
return '<span class="dashicons dashicons-edit"></span>';
}
/**
* Creates new admin link
*
* @return string
*/
public function get_edit_new() {
$path = $this->path;
if ( null !== $this->id && null !== $this->origin_language ) {
$path = add_query_arg( [ 'msls_id' => implode(',', $this->id), 'msls_lang' => implode(',', $this->origin_language) ], $this->path );
}
/**
* Returns custom url of an admin icon link
*
* @param string $path
*
* @since 0.9.9
*/
$path = (string) apply_filters( 'msls_admin_icon_get_edit_new', $path );
return get_admin_url( get_current_blog_id(), $path );
}
}