[ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Link Template Functions 4 * 5 * @package GlotPress 6 * @subpackage Template 7 */ 8 9 /** 10 * Creates a HTML link. 11 * 12 * @since 1.0.0 13 * 14 * @param string $url The URL to link to. 15 * @param string $text The text to use for the link. 16 * @param array $attrs Optional. Additional attributes to use 17 * to determine the classes for the link. 18 * @return string The HTML link. 19 */ 20 function gp_link_get( $url, $text, $attrs = array() ) { 21 $before = ''; 22 $after = ''; 23 foreach ( array( 'before', 'after' ) as $key ) { 24 if ( isset( $attrs[ $key ] ) ) { 25 $$key = $attrs[ $key ]; 26 unset( $attrs[ $key ] ); 27 } 28 } 29 $attributes = gp_html_attributes( $attrs ); 30 $attributes = $attributes ? " $attributes" : ''; 31 32 return sprintf( 33 '%1$s<a href="%2$s"%3$s>%4$s</a>%5$s', 34 $before, 35 esc_url( $url ), 36 $attributes, 37 $text, 38 $after 39 ); 40 } 41 42 /** 43 * Creates a HTML link. 44 * 45 * @since 1.0.0 46 * 47 * @see gp_link_get() 48 * 49 * @param string $url The URL to link to. 50 * @param string $text The text to use for the link. 51 * @param array $attrs Optional. Additional attributes to use 52 * to determine the classes for the link. 53 */ 54 function gp_link( $url, $text, $attrs = array() ) { 55 echo gp_link_get( $url, $text, $attrs ); 56 } 57 58 /** 59 * Creates a HTML link with a confirmation request. 60 * 61 * Uses the `window.confirm()` method to display a modal dialog for confirmation. 62 * 63 * @since 1.0.0 64 * 65 * @param string $url The URL to link to. 66 * @param string $text The text to use for the link. 67 * @param array $attrs Optional. Additional attributes to use 68 * to determine the classes for the link. 69 * @return string The HTML link. 70 */ 71 function gp_link_with_ays_get( $url, $text, $attrs = array() ) { 72 $ays_text = $attrs['ays-text']; 73 unset( $attrs['ays-text'] ); 74 $attrs['onclick'] = "return confirm('" . esc_js( $ays_text ) . "');"; 75 return gp_link_get( $url, $text, $attrs ); 76 } 77 78 /** 79 * Creates a HTML link with a confirmation request. 80 * 81 * Uses the `window.confirm()` method to display a modal dialog for confirmation. 82 * 83 * @since 1.0.0 84 * 85 * @see gp_link_with_ays_get() 86 * 87 * @param string $url The URL to link to. 88 * @param string $text The text to use for the link. 89 * @param array $attrs Optional. Additional attributes to use 90 * to determine the classes for the link. 91 */ 92 function gp_link_with_ays( $url, $text, $attrs = array() ) { 93 echo gp_link_with_ays_get( $url, $text, $attrs ); 94 } 95 96 /** 97 * Creates a HTML link to the page of a project. 98 * 99 * @since 1.0.0 100 * 101 * @param GP_Project|string $project_or_path The project to link to. 102 * @param string $text The text to use for the link. 103 * @param array $attrs Optional. Additional attributes to use 104 * to determine the classes for the link. 105 * @return string The HTML link. 106 */ 107 function gp_link_project_get( $project_or_path, $text, $attrs = array() ) { 108 return gp_link_get( gp_url_project( $project_or_path ), $text, $attrs ); 109 } 110 111 /** 112 * Outputs a HTML link to the page of a project. 113 * 114 * @since 1.0.0 115 * 116 * @see gp_link_project_get() 117 * 118 * @param GP_Project|string $project_or_path The project to link to. 119 * @param string $text The text to use for the link. 120 * @param array $attrs Optional. Additional attributes to use 121 * to determine the classes for the link. 122 */ 123 function gp_link_project( $project_or_path, $text, $attrs = array() ) { 124 echo gp_link_project_get( $project_or_path, $text, $attrs ); 125 } 126 127 /** 128 * Creates a HTML link to the edit page for projects. 129 * 130 * @since 1.0.0 131 * 132 * @param GP_Project $project The project to link to. 133 * @param string $text Optional. The text to use for the link. Default 'Edit'. 134 * @param array $attrs Optional. Additional attributes to use to determine the classes for the link. 135 * @return string The HTML link. 136 */ 137 function gp_link_project_edit_get( $project, $text = '', $attrs = array() ) { 138 if ( ! GP::$permission->current_user_can( 'write', 'project', $project->id ) ) { 139 return ''; 140 } 141 $text = $text ? $text : __( 'Edit', 'glotpress' ); 142 return gp_link_get( gp_url_project( $project, '-edit' ), $text, gp_attrs_add_class( $attrs, 'action edit' ) ); 143 } 144 145 /** 146 * Outputs a HTML link to the edit page for projects. 147 * 148 * @since 1.0.0 149 * 150 * @see gp_link_project_edit_get() 151 * 152 * @param GP_Project $project The project to link to. 153 * @param string $text Optional. The text to use for the link. Default 'Edit'. 154 * @param array $attrs Optional. Additional attributes to use to determine the classes for the link. 155 */ 156 function gp_link_project_edit( $project, $text = '', $attrs = array() ) { 157 echo gp_link_project_edit_get( $project, $text, $attrs ); 158 } 159 160 /** 161 * Creates a HTML link to the delete page for projects. 162 * 163 * @since 1.0.0 164 * 165 * @param GP_Project $project The project to link to. 166 * @param string $text Optional. The text to use for the link. Default 'Delete'. 167 * @param array $attrs Optional. Additional attributes to use to determine the classes for the link. 168 * @return string The HTML link. 169 */ 170 function gp_link_project_delete_get( $project, $text = '', $attrs = array() ) { 171 if ( ! GP::$permission->current_user_can( 'delete', 'project', $project->id ) ) { 172 return ''; 173 } 174 $text = $text ? $text : __( 'Delete', 'glotpress' ); 175 return gp_link_get( gp_url_project( $project, '-delete' ), $text, gp_attrs_add_class( $attrs, 'action edit' ) ); 176 } 177 178 /** 179 * Outputs a HTML link to the delete page for projects. 180 * 181 * @since 1.0.0 182 * 183 * @see gp_link_project_delete_get() 184 * 185 * @param GP_Project $project The project to link to. 186 * @param string $text Optional. The text to use for the link. 187 * @param array $attrs Optional. Additional attributes to use to determine the classes for the link. 188 */ 189 function gp_link_project_delete( $project, $text = '', $attrs = array() ) { 190 echo gp_link_project_delete_get( $project, $text, $attrs ); 191 } 192 193 /** 194 * Creates a HTML link to the home page of GlotPress. 195 * 196 * @since 1.0.0 197 * 198 * @return string The HTML link. 199 */ 200 function gp_link_home_get() { 201 return gp_link_get( gp_url( '/' ), __( 'Home', 'glotpress' ) ); 202 } 203 204 /** 205 * Outputs a HTML link to the home page of GlotPress. 206 * 207 * @since 1.0.0 208 * 209 * @see gp_link_home_get() 210 */ 211 function gp_link_home() { 212 echo gp_link_home_get(); 213 } 214 215 /** 216 * Creates a HTML link to the delete page for translations sets. 217 * 218 * @since 1.0.0 219 * 220 * @param GP_Translation_Set $set The translation set to link to. 221 * @param GP_Project $project The project the translation set belongs to. 222 * @param string $text Optional. The text to use for the link. Default 'Edit'. 223 * @param array $attrs Optional. Additional attributes to use to determine the classes for the link. 224 * @return string The HTML link. 225 */ 226 function gp_link_set_edit_get( $set, $project, $text = '', $attrs = array() ) { 227 if ( ! GP::$permission->current_user_can( 'write', 'project', $project->id ) ) { 228 return ''; 229 } 230 231 $text = $text ? $text : __( 'Edit', 'glotpress' ); 232 return gp_link_get( gp_url( gp_url_join( '/sets', $set->id, '-edit' ) ), $text, gp_attrs_add_class( $attrs, 'action edit' ) ); 233 } 234 235 /** 236 * Outputs a HTML link to the edit page for translations sets. 237 * 238 * @since 1.0.0 239 * 240 * @see gp_link_set_edit_get() 241 * 242 * @param GP_Translation_Set $set The translation set to link to. 243 * @param GP_Project $project The project the translation set belongs to. 244 * @param string $text Optional. The text to use for the link. Default 'Edit'. 245 * @param array $attrs Optional. Additional attributes to use to determine the classes for the link. 246 */ 247 function gp_link_set_edit( $set, $project, $text = '', $attrs = array() ) { 248 echo gp_link_set_edit_get( $set, $project, $text, $attrs ); 249 } 250 251 /** 252 * Creates a HTML link to the delete page for translations sets. 253 * 254 * @since 2.0.0 255 * 256 * @param GP_Translation_Set $set The translation set to link to. 257 * @param GP_Project $project The project the translation set belongs to. 258 * @param string $text Optional. The text to use for the link. Default 'Delete'. 259 * @param array $attrs Optional. Additional attributes to use to determine the classes for the link. 260 * @return string The HTML link. 261 */ 262 function gp_link_set_delete_get( $set, $project, $text = '', $attrs = array() ) { 263 if ( ! GP::$permission->current_user_can( 'delete', 'project', $project->id ) ) { 264 return ''; 265 } 266 267 $text = $text ? $text : __( 'Delete', 'glotpress' ); 268 return gp_link_get( gp_url( gp_url_join( '/sets', $set->id, '-delete' ) ), $text, gp_attrs_add_class( $attrs, 'action edit' ) ); 269 } 270 271 /** 272 * Outputs a HTML link to the delete page for translations sets. 273 * 274 * @since 2.0.0 275 * 276 * @see gp_link_set_delete_get() 277 * 278 * @param GP_Translation_Set $set The translation set to link to. 279 * @param GP_Project $project The project the translation set belongs to. 280 * @param string $text Optional. The text to use for the link. Default 'Delete'. 281 * @param array $attrs Optional. Additional attributes to use to determine the classes for the link. 282 */ 283 function gp_link_set_delete( $set, $project, $text = '', $attrs = array() ) { 284 echo gp_link_set_delete_get( $set, $project, $text, $attrs ); 285 } 286 287 /** 288 * Creates a HTML link to the edit page for glossaries. 289 * 290 * @since 1.0.0 291 * 292 * @param GP_Glossary $glossary The glossary to link to. 293 * @param GP_Translation_Set $set The translation set the glossary is for. 294 * @param string $text Optional. The text to use for the link. Default 'Edit'. 295 * @param array $attrs Optional. Additional attributes to use to determine the classes for the link. 296 * @return string The HTML link. 297 */ 298 function gp_link_glossary_edit_get( $glossary, $set, $text = '', $attrs = array() ) { 299 if ( ! GP::$permission->current_user_can( 'approve', 'translation-set', $set->id ) ) { 300 return ''; 301 } 302 303 $text = $text ? $text : __( 'Edit', 'glotpress' ); 304 return gp_link_get( gp_url( gp_url_join( '/glossaries', $glossary->id, '-edit' ) ), $text, gp_attrs_add_class( $attrs, 'action edit' ) ); 305 } 306 307 /** 308 * Outputs a HTML link to the edit page for glossaries. 309 * 310 * @since 1.0.0 311 * 312 * @see gp_link_glossary_edit_get() 313 * 314 * @param GP_Glossary $glossary The glossary to link to. 315 * @param GP_Translation_Set $set The translation set the glossary is for. 316 * @param string $text Optional. The text to use for the link. Default 'Edit'. 317 * @param array $attrs Optional. Additional attributes to use to determine the classes for the link. 318 */ 319 function gp_link_glossary_edit( $glossary, $set, $text = '', $attrs = array() ) { 320 echo gp_link_glossary_edit_get( $glossary, $set, $text, $attrs ); 321 } 322 323 /** 324 * Creates a HTML link to the delete page for glossaries. 325 * 326 * @since 2.0.0 327 * 328 * @param GP_Glossary $glossary The glossary to link to. 329 * @param GP_Translation_Set $set The translation set the glossary is for. 330 * @param string $text Optional. The text to use for the link. Default 'Delete'. 331 * @param array $attrs Optional. Additional attributes to use to determine the classes for the link. 332 * @return string The HTML link. 333 */ 334 function gp_link_glossary_delete_get( $glossary, $set, $text = '', $attrs = array() ) { 335 if ( ! GP::$permission->current_user_can( 'delete', 'translation-set', $set->id ) ) { 336 return ''; 337 } 338 339 $text = $text ? $text : __( 'Delete', 'glotpress' ); 340 return gp_link_get( gp_url( gp_url_join( '/glossaries', $glossary->id, '-delete' ) ), $text, gp_attrs_add_class( $attrs, 'action edit' ) ); 341 } 342 343 /** 344 * Outputs a HTML link to the delete page for glossaries. 345 * 346 * @since 2.0.0 347 * 348 * @see gp_link_glossary_delete_get() 349 * 350 * @param GP_Glossary $glossary The glossary to link to. 351 * @param GP_Translation_Set $set The translation set the glossary is for. 352 * @param string $text Optional. The text to use for the link. Default 'Delete'. 353 * @param array $attrs Optional. Additional attributes to use to determine the classes for the link. 354 */ 355 function gp_link_glossary_delete( $glossary, $set, $text = '', $attrs = array() ) { 356 echo gp_link_glossary_delete_get( $glossary, $set, $text, $attrs ); 357 } 358 359 /** 360 * Outputs a HTML link to a user profile page. 361 * 362 * @since 2.1.0 363 * 364 * @param WP_User $user A WP_User user object. 365 */ 366 function gp_link_user( $user ) { 367 if ( $user->display_name && $user->display_name !== $user->user_login ) { 368 printf( 369 '<a href="%s" tabindex="-1">%s (%s)</a>', 370 esc_url( gp_url_profile( $user->user_nicename ) ), 371 esc_html( $user->display_name ), 372 esc_html( $user->user_login ) 373 ); 374 } else { 375 printf( 376 '<a href="%s" tabindex="-1">%s</a>', 377 esc_url( gp_url_profile( $user->user_nicename ) ), 378 esc_attr( $user->user_login ) 379 ); 380 } 381 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:01:04 2024 | Cross-referenced by PHPXref 0.7.1 |