| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
/** |
| 5 |
* The global functions for this plugin |
| 6 |
* |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
|
| 11 |
/** |
| 12 |
* Sanitize a string |
| 13 |
*/ |
| 14 |
function quickwebp_sanitize_name( $name ) { |
| 15 |
|
| 16 |
$extension = pathinfo( $name, PATHINFO_EXTENSION ); |
| 17 |
$name = pathinfo( $name, PATHINFO_FILENAME ); |
| 18 |
$name = mb_convert_encoding( $name, "UTF-8" ); |
| 19 |
$char_not_clean = array('/\?/','/\’/','/\'/','/À/','/Á/','/Â/','/Ã/','/Ä/','/� |
| 20 |
/','/Ç/','/È/','/É/','/Ê/','/Ë/','/Ì/','/Í/','/Î/','/Ï/','/Ò/','/Ó/','/Ô/','/Õ/','/Ö/','/Ù/','/Ú/','/Û/','/Ü/','/Ý/','/à/','/á/','/â/','/ã/','/ä/','/å/','/ç/','/è/','/é/','/ê/','/ë/','/ì/','/í/','/î/','/ï/','/ð/','/ò/','/ó/','/ô/','/õ/','/ö/','/ù/','/ú/','/û/','/ü/','/ý/','/ÿ/', '/©/'); |
| 21 |
$clean = array('','-','-','a','a','a','a','a','a','c','e','e','e','e','i','i','i','i','o','o','o','o','o','u','u','u','u','y','a','a','a','a','a','a','c','e','e','e','e','i','i','i','i','o','o','o','o','o','o','u','u','u','u','y','y','copy'); |
| 22 |
$friendly_name = preg_replace($char_not_clean, $clean, $name); |
| 23 |
$friendly_name = sanitize_title($friendly_name); |
| 24 |
|
| 25 |
return $friendly_name . '.' . $extension; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Default values for the settings |
| 30 |
*/ |
| 31 |
function quickwebp_settings_default( $id ) { |
| 32 |
|
| 33 |
$settings_arr = array( |
| 34 |
'quickwebp_settings_conversion' => '1', |
| 35 |
'quickwebp_settings_conversion_quality' => 'high', |
| 36 |
'quickwebp_settings_conversion_ignore_webp' => array('checked'), |
| 37 |
'quickwebp_settings_conversion_save_original' => array(), |
| 38 |
'quickwebp_settings_conversion_display_webp_mode' => 'disabled', |
| 39 |
'quickwebp_settings_resize' => '1', |
| 40 |
'quickwebp_settings_resize_value' => 2000, |
| 41 |
'quickwebp_settings_completion' => '1', |
| 42 |
'quickwebp_settings_completion_options' => array( |
| 43 |
'title', |
| 44 |
'caption', |
| 45 |
'alt', |
| 46 |
'description' |
| 47 |
), |
| 48 |
'quickwebp_settings_cleanup' => '1', |
| 49 |
'quickwebp_settings_paste_image' => '0', |
| 50 |
); |
| 51 |
|
| 52 |
return isset($settings_arr[$id]) ? $settings_arr[$id] : ''; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Allowed tags for SVG files |
| 57 |
*/ |
| 58 |
function quickwebp_allowed_tags_for_svg_files() { |
| 59 |
$allowedtags = array( |
| 60 |
'svg' => array( |
| 61 |
'class' => true, |
| 62 |
'xmlns' => true, |
| 63 |
'width' => true, |
| 64 |
'height' => true, |
| 65 |
'viewbox' => true, |
| 66 |
'preserveaspectratio' => true, |
| 67 |
'fill' => true, |
| 68 |
'aria-hidden' => true, |
| 69 |
'focusable' => true, |
| 70 |
'role' => true, |
| 71 |
), |
| 72 |
'path' => array( |
| 73 |
'fill' => true, |
| 74 |
'fill-rule' => true, |
| 75 |
'd' => true, |
| 76 |
'transform' => true, |
| 77 |
'stroke' => true, |
| 78 |
'stroke-linecap' => true, |
| 79 |
'stroke-linejoin' => true, |
| 80 |
), |
| 81 |
'polygon' => array( |
| 82 |
'fill' => true, |
| 83 |
'fill-rule' => true, |
| 84 |
'points' => true, |
| 85 |
'transform' => true, |
| 86 |
'focusable' => true, |
| 87 |
), |
| 88 |
'rect' => array( |
| 89 |
'fill' => true, |
| 90 |
'fill-rule' => true, |
| 91 |
'height' => true, |
| 92 |
'width' => true, |
| 93 |
'x' => true, |
| 94 |
'y' => true, |
| 95 |
), |
| 96 |
'line' => array( |
| 97 |
'fill' => true, |
| 98 |
'fill-rule' => true, |
| 99 |
'x1' => true, |
| 100 |
'x2' => true, |
| 101 |
'y1' => true, |
| 102 |
'y2' => true, |
| 103 |
'stroke' => true, |
| 104 |
'stroke-width' => true, |
| 105 |
'transform' => true, |
| 106 |
), |
| 107 |
'defs' => array( |
| 108 |
'id' => true, |
| 109 |
), |
| 110 |
'clipPath' => array( |
| 111 |
'id' => true, |
| 112 |
), |
| 113 |
'g' => array( |
| 114 |
'clip-path' => true, |
| 115 |
'mask' => true, |
| 116 |
), |
| 117 |
'circle' => array( |
| 118 |
'cx' => true, |
| 119 |
'cy' => true, |
| 120 |
'r' => true, |
| 121 |
'fill' => true, |
| 122 |
'stroke' => true, |
| 123 |
'stroke-width' => true, |
| 124 |
'stroke-dasharray' => true, |
| 125 |
'stroke-linecap' => true, |
| 126 |
), |
| 127 |
'mask' => array( |
| 128 |
'id' => true, |
| 129 |
'fill' => true, |
| 130 |
'style' => true, |
| 131 |
'maskUnits' => true, |
| 132 |
'x' => true, |
| 133 |
'y' => true, |
| 134 |
'width' => true, |
| 135 |
'height' => true, |
| 136 |
), |
| 137 |
'image' => array( |
| 138 |
'id' => true, |
| 139 |
'href' => true, |
| 140 |
'x' => true, |
| 141 |
'y' => true, |
| 142 |
'width' => true, |
| 143 |
'height' => true, |
| 144 |
'clip' => true, |
| 145 |
'mask' => true, |
| 146 |
'opacity' => true, |
| 147 |
'xlink:href' => true, |
| 148 |
), |
| 149 |
'defs' => array( |
| 150 |
'id' => true, |
| 151 |
), |
| 152 |
'pattern' => array( |
| 153 |
'id' => true, |
| 154 |
'x' => true, |
| 155 |
'y' => true, |
| 156 |
'width' => true, |
| 157 |
'height' => true, |
| 158 |
'patternUnits' => true, |
| 159 |
'patternContentUnits' => true, |
| 160 |
), |
| 161 |
'use' => array( |
| 162 |
'id' => true, |
| 163 |
'x' => true, |
| 164 |
'y' => true, |
| 165 |
'xlink:href' => true, |
| 166 |
'transform' => true, |
| 167 |
), |
| 168 |
); |
| 169 |
return $allowedtags; |
| 170 |
} |
| 171 |
|
| 172 |
/** |
| 173 |
* Build a QuickWebP Pro URL with tracking parameters. |
| 174 |
* |
| 175 |
* @param string $context Stable location identifier for the CTA. |
| 176 |
* @param array $additional_args Optional additional query args. |
| 177 |
* |
| 178 |
* @return string |
| 179 |
*/ |
| 180 |
function quickwebp_get_pro_url( $context, $additional_args = array() ) { |
| 181 |
$base_url = 'https://solutions.leyoweb.com/products/quickwebp/'; |
| 182 |
|
| 183 |
if ( class_exists( 'Quickwebp_Settings' ) && defined( 'Quickwebp_Settings::QUICKWEBP_GET_LICENSE_URL' ) ) { |
| 184 |
$base_url = Quickwebp_Settings::QUICKWEBP_GET_LICENSE_URL; |
| 185 |
} |
| 186 |
|
| 187 |
return add_query_arg( |
| 188 |
array_merge( |
| 189 |
$additional_args, |
| 190 |
array( |
| 191 |
'utm_source' => 'quickwebp-plugin', |
| 192 |
'utm_medium' => 'plugin', |
| 193 |
'utm_campaign' => 'upgrade-pro', |
| 194 |
'utm_content' => sanitize_key( $context ), |
| 195 |
) |
| 196 |
), |
| 197 |
$base_url |
| 198 |
); |
| 199 |
} |
| 200 |
|