| 1 |
<?php |
| 2 |
|
| 3 |
namespace ISC; |
| 4 |
|
| 5 |
/** |
| 6 |
* Admin Utils |
| 7 |
*/ |
| 8 |
class Admin_Utils { |
| 9 |
/** |
| 10 |
* Get the ISC pages |
| 11 |
* |
| 12 |
* @return array |
| 13 |
*/ |
| 14 |
public static function get_isc_pages(): array { |
| 15 |
return apply_filters( |
| 16 |
'isc_admin_pages', |
| 17 |
[ |
| 18 |
'settings_page_isc-settings', |
| 19 |
'media_page_isc-sources', |
| 20 |
] |
| 21 |
); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Check if the current WP Admin page belongs to ISC |
| 26 |
* |
| 27 |
* @return bool true if this is an ISC-related page |
| 28 |
*/ |
| 29 |
public static function is_isc_page(): bool { |
| 30 |
$screen = get_current_screen(); |
| 31 |
|
| 32 |
return isset( $screen->id ) && in_array( $screen->id, self::get_isc_pages(), true ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Return true if we are on the media library page in list view |
| 37 |
* |
| 38 |
* @return bool |
| 39 |
*/ |
| 40 |
public static function is_media_library_list_view_page(): bool { |
| 41 |
if ( ! is_admin() || ! function_exists( 'get_current_screen' ) ) { |
| 42 |
return false; |
| 43 |
} |
| 44 |
|
| 45 |
$screen = get_current_screen(); |
| 46 |
if ( ! isset( $screen->id ) || $screen->id !== 'upload' ) { |
| 47 |
return false; |
| 48 |
} |
| 49 |
|
| 50 |
// don’t show this in grid mode |
| 51 |
if ( 'list' !== get_user_option( 'media_library_mode' ) ) { |
| 52 |
return false; |
| 53 |
} |
| 54 |
|
| 55 |
return true; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Get URL to the ISC website by site language |
| 60 |
* If the URL param contains an anchor, the anchor will be added after the UTM part |
| 61 |
* |
| 62 |
* @param string $url_param Default parameter added to the main URL, leading to https://imagesourcecontrol.com/. |
| 63 |
* @param string $url_param_de Parameter added to the main URL for German backends, leading to https://imagesourcecontrol.de/. |
| 64 |
* @param string $utm_campaign Position of the link for the campaign link. |
| 65 |
* |
| 66 |
* @return string website URL |
| 67 |
*/ |
| 68 |
public static function get_isc_localized_website_url( string $url_param, string $url_param_de, string $utm_campaign ) { |
| 69 |
if ( User::has_german_backend() ) { |
| 70 |
if ( strpos( $url_param_de, '#' ) !== false ) { |
| 71 |
$anchor = substr( $url_param_de, strpos( $url_param_de, '#' ) ); |
| 72 |
$url_param_de = substr( $url_param_de, 0, strpos( $url_param_de, '#' ) ); |
| 73 |
} |
| 74 |
$url = 'https://imagesourcecontrol.de/' . $url_param_de; |
| 75 |
} else { |
| 76 |
if ( strpos( $url_param, '#' ) !== false ) { |
| 77 |
$anchor = substr( $url_param, strpos( $url_param, '#' ) ); |
| 78 |
$url_param = substr( $url_param, 0, strpos( $url_param, '#' ) ); |
| 79 |
} |
| 80 |
$url = 'https://imagesourcecontrol.com/' . $url_param; |
| 81 |
} |
| 82 |
|
| 83 |
$url .= '?utm_source=isc-plugin&utm_medium=link&utm_campaign=' . $utm_campaign; |
| 84 |
|
| 85 |
// add the anchor to the URL |
| 86 |
if ( isset( $anchor ) ) { |
| 87 |
$url .= $anchor; |
| 88 |
} |
| 89 |
|
| 90 |
return esc_url( $url ); |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Get link to ISC Pro |
| 95 |
* |
| 96 |
* @param string $utm_campaign Position of the link for the campaign link. |
| 97 |
* |
| 98 |
* @return string |
| 99 |
*/ |
| 100 |
public static function get_pro_link( $utm_campaign = 'upsell-link' ) { |
| 101 |
return '<a href="' . self::get_isc_localized_website_url( 'pricing/', 'preise/', $utm_campaign ) . '" class="isc-get-pro" target="_blank">' . esc_html__( 'Get ISC Pro', 'image-source-control-isc' ) . '</a>'; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Get link to the ISC manual |
| 106 |
* |
| 107 |
* @param string $utm_campaign Position of the link for the campaign link. |
| 108 |
*/ |
| 109 |
public static function get_manual_url( $utm_campaign = 'manual' ) { |
| 110 |
// check if the locale starts with "de_" |
| 111 |
if ( User::has_german_backend() ) { |
| 112 |
$base_url = 'https://imagesourcecontrol.de/dokumentation/'; |
| 113 |
} else { |
| 114 |
$base_url = 'https://imagesourcecontrol.com/documentation/'; |
| 115 |
} |
| 116 |
|
| 117 |
return $base_url . '?utm_source=isc-plugin&utm_medium=link&utm_campaign=' . $utm_campaign; |
| 118 |
} |
| 119 |
} |
| 120 |
|