| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: DMCA Website Protection Badge |
| 4 |
Plugin URI : https://www.dmca.com/WordPress/default.aspx?r=wpd1 |
| 5 |
Description: Protect your content with a DMCA.com Website Protection Badge. Our badges deter content theft, provide tracking of unauthorized usage (with account), and make takedowns easier and more effective. Visit the plugin site to learn more about DMCA Website Protection Badges, or to register. |
| 6 |
Version: 2.3.0 |
| 7 |
Tested up to: 7.0 |
| 8 |
Author: DMCA.com |
| 9 |
Text Domain: dmca-badge |
| 10 |
Author URI: https://wordpress.org/plugins/dmca-badge/ |
| 11 |
Plugin URI: https://www.dmca.com/WordPress/default.aspx?r=wpd |
| 12 |
License: GPLv2 or later |
| 13 |
*/ |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
require_once __DIR__ . '/libraries/imperative/imperative.php'; |
| 20 |
|
| 21 |
require_library( |
| 22 |
'restian', |
| 23 |
'0.4.1', |
| 24 |
__FILE__, |
| 25 |
__DIR__ . '/libraries/restian/restian.php' |
| 26 |
); |
| 27 |
|
| 28 |
require_library( |
| 29 |
'sidecar', |
| 30 |
'0.5.1', |
| 31 |
__FILE__, |
| 32 |
__DIR__ . '/libraries/sidecar/sidecar.php' |
| 33 |
); |
| 34 |
|
| 35 |
require_library( |
| 36 |
'dmca-api-client', |
| 37 |
'0.1.0', |
| 38 |
__FILE__, |
| 39 |
__DIR__ . '/libraries/dmca-api-client/dmca-api-client.php' |
| 40 |
); |
| 41 |
|
| 42 |
register_plugin_loader( __FILE__ ); |
| 43 |
|
| 44 |
define( 'DMCA_PLUGIN_URL', plugins_url( '/', __FILE__ ) ); |
| 45 |
define( 'DMCA_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 46 |
|
| 47 |
|
| 48 |
add_filter( 'dmca_badge_html_raw', 'dmca_badge_override_html_raw', 10, 3 ); |
| 49 |
add_filter( 'dmca_filters_get_form_field_html', 'dmca_add_wrapper_in_field_html', 10, 2 ); |
| 50 |
add_action( 'dmca_badge_after_field', 'dmca_add_custom_badge_section', 10, 2 ); |
| 51 |
add_action( 'admin_footer', 'dmca_custom_scripts_addition' ); |
| 52 |
add_action( 'wp_ajax_dmca_sync_page', 'dmca_sync_page' ); |
| 53 |
add_action( 'wp_enqueue_scripts', 'dmca_enqueue_scripts' ); |
| 54 |
add_action( 'wp_footer', 'dmca_pass_token_to_widget' ); |
| 55 |
|
| 56 |
|
| 57 |
if ( ! function_exists( 'dmca_pass_token_to_widget' ) ) { |
| 58 |
/** |
| 59 |
* Pass token to dmca widget |
| 60 |
*/ |
| 61 |
function dmca_pass_token_to_widget() { |
| 62 |
$error_path = plugin_dir_url(__FILE__) ; |
| 63 |
try { |
| 64 |
if ( is_user_logged_in() && current_user_can( 'manage_options' ) && ! empty( $token = dmca_get_login_token() ) ) { |
| 65 |
?> |
| 66 |
<script> |
| 67 |
document.cookie = "dmca_token" + "=" + "<?php echo esc_attr( $token ); ?>" + ";path=/"; |
| 68 |
</script> |
| 69 |
<?php |
| 70 |
} |
| 71 |
} |
| 72 |
//catch block |
| 73 |
|
| 74 |
|
| 75 |
catch (Exception $e) |
| 76 |
{ |
| 77 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 78 |
|
| 79 |
if ($e->getSeverity() === E_ERROR) { |
| 80 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 81 |
} else if ($e->getSeverity() === E_WARNING) { |
| 82 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 83 |
} |
| 84 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 85 |
} |
| 86 |
catch (ErrorException $er) |
| 87 |
{ |
| 88 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 89 |
|
| 90 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 91 |
} |
| 92 |
catch ( Throwable $th){ |
| 93 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 94 |
|
| 95 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 96 |
} |
| 97 |
|
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
if ( ! function_exists( 'dmca_enqueue_scripts' ) ) { |
| 103 |
function dmca_enqueue_scripts() { |
| 104 |
$error_path = plugin_dir_url(__FILE__) ; |
| 105 |
try { |
| 106 |
$badge_settings = dmca_get_option( 'dmca_badge_settings' ); |
| 107 |
$settings = isset( $badge_settings->values ) ? $badge_settings->values : array(); |
| 108 |
|
| 109 |
if ( isset( $settings['badge']['dmca_widget_enable'] ) && |
| 110 |
$settings['badge']['dmca_widget_enable'] && |
| 111 |
isset( $settings['badge']['badge_selection'] ) && |
| 112 |
$settings['badge']['badge_selection'] == 'widget' ) { |
| 113 |
$live_url = 'https://dmca-services.github.io/widget/widget.js'; |
| 114 |
// phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter |
| 115 |
wp_enqueue_script( 'dmca-widget', $live_url, array(), '1.0.0' ); |
| 116 |
} |
| 117 |
else{ |
| 118 |
//echo '<p>Please Contact your developer.</p>'; |
| 119 |
} |
| 120 |
} |
| 121 |
catch (Exception $e) |
| 122 |
{ |
| 123 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 124 |
|
| 125 |
if ($e->getSeverity() === E_ERROR) { |
| 126 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 127 |
} else if ($e->getSeverity() === E_WARNING) { |
| 128 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 129 |
} |
| 130 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 131 |
} |
| 132 |
catch (ErrorException $er) |
| 133 |
{ |
| 134 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 135 |
|
| 136 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 137 |
} |
| 138 |
catch ( Throwable $th){ |
| 139 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 140 |
|
| 141 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 142 |
} |
| 143 |
//finally block |
| 144 |
|
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
if ( ! function_exists( 'dmca_custom_scripts_addition' ) ) { |
| 150 |
function dmca_custom_scripts_addition() { |
| 151 |
|
| 152 |
$error_path = plugin_dir_url(__FILE__) ; |
| 153 |
try { |
| 154 |
$screen = get_current_screen(); |
| 155 |
|
| 156 |
if ( $screen->id != 'settings_page_dmca-badge-settings' ) { |
| 157 |
return; |
| 158 |
} |
| 159 |
|
| 160 |
} |
| 161 |
catch (Exception $e) |
| 162 |
{ |
| 163 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 164 |
|
| 165 |
if ($e->getSeverity() === E_ERROR) { |
| 166 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 167 |
} else if ($e->getSeverity() === E_WARNING) { |
| 168 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 169 |
} |
| 170 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 171 |
} |
| 172 |
catch (ErrorException $er) |
| 173 |
{ |
| 174 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 175 |
|
| 176 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 177 |
} |
| 178 |
catch ( Throwable $th){ |
| 179 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 180 |
|
| 181 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 182 |
} |
| 183 |
//finally block |
| 184 |
|
| 185 |
?> |
| 186 |
|
| 187 |
<script>window.intercomSettings = {app_id: "ypgdx31r", messengerLocation: "wp-plugin"};</script> |
| 188 |
<script>(function () { |
| 189 |
var w = window; |
| 190 |
var ic = w.Intercom; |
| 191 |
if (typeof ic === "function") { |
| 192 |
ic('reattach_activator'); |
| 193 |
ic('update', intercomSettings); |
| 194 |
} else { |
| 195 |
var d = document; |
| 196 |
var i = function () { |
| 197 |
i.c(arguments) |
| 198 |
}; |
| 199 |
i.q = []; |
| 200 |
i.c = function (args) { |
| 201 |
i.q.push(args) |
| 202 |
}; |
| 203 |
w.Intercom = i; |
| 204 |
|
| 205 |
function l() { |
| 206 |
var s = d.createElement('script'); |
| 207 |
s.type = 'text/javascript'; |
| 208 |
s.async = true; |
| 209 |
s.src = 'https://widget.intercom.io/widget/ypgdx31r'; |
| 210 |
var x = d.getElementsByTagName('script')[0]; |
| 211 |
x.parentNode.insertBefore(s, x); |
| 212 |
} |
| 213 |
|
| 214 |
if (w.attachEvent) { |
| 215 |
w.attachEvent('onload', l); |
| 216 |
} else { |
| 217 |
w.addEventListener('load', l, false); |
| 218 |
} |
| 219 |
} |
| 220 |
})()</script> |
| 221 |
|
| 222 |
|
| 223 |
<?php |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
if ( ! function_exists( 'dmca_sync_page' ) ) { |
| 229 |
function dmca_sync_page() { |
| 230 |
$error_path = plugin_dir_url(__FILE__) ; |
| 231 |
try { |
| 232 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Read-only admin filter. |
| 233 |
$page_id = isset( $_POST['page_id'] ) ? sanitize_text_field( wp_unslash( $_POST['page_id'] ) ) : ''; |
| 234 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Read-only admin filter. |
| 235 |
$login_token = isset( $_POST['login_token'] ) ? sanitize_text_field( wp_unslash( $_POST['login_token'] ) ) : ''; |
| 236 |
|
| 237 |
if ( ! $page_id || empty( $page_id ) ) { |
| 238 |
wp_send_json_error(); |
| 239 |
} |
| 240 |
|
| 241 |
wp_send_json_success( dmca_add_protected_item( $page_id, $login_token ) ); |
| 242 |
} |
| 243 |
|
| 244 |
catch (Exception $e) |
| 245 |
{ |
| 246 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 247 |
|
| 248 |
if ($e->getSeverity() === E_ERROR) { |
| 249 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 250 |
} else if ($e->getSeverity() === E_WARNING) { |
| 251 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 252 |
} |
| 253 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 254 |
} |
| 255 |
catch (ErrorException $er) |
| 256 |
{ |
| 257 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 258 |
|
| 259 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 260 |
} |
| 261 |
catch ( Throwable $th){ |
| 262 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 263 |
|
| 264 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 265 |
} |
| 266 |
//finally block |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
if ( ! function_exists( 'dmca_get_login_token' ) ) { |
| 272 |
/** |
| 273 |
* Return login token for api |
| 274 |
* |
| 275 |
* @return mixed|void |
| 276 |
*/ |
| 277 |
function dmca_get_login_token() { |
| 278 |
$error_path = plugin_dir_url(__FILE__) ; |
| 279 |
try { |
| 280 |
$dmca_login_token = get_transient( 'dmca_login_token' ); |
| 281 |
|
| 282 |
if ( empty( $dmca_login_token ) ) { |
| 283 |
$settings = get_option( 'dmca_badge_settings' ); |
| 284 |
$settings = isset( $settings->values ) ? $settings->values : array(); |
| 285 |
$email = isset( $settings['authenticate']['email'] ) ? $settings['authenticate']['email'] : ''; |
| 286 |
$password = isset( $settings['authenticate']['password'] ) ? $settings['authenticate']['password'] : ''; |
| 287 |
$base_url = esc_url_raw( 'https://api.dmca.com', array( 'https' ) ); |
| 288 |
|
| 289 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_init -- cURL is required for this API integration. |
| 290 |
$curl = curl_init(); |
| 291 |
$login_data = array( 'email' => $email, 'password' => $password ); |
| 292 |
|
| 293 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_setopt_array -- cURL is required for this API integration. |
| 294 |
curl_setopt_array( $curl, array( |
| 295 |
CURLOPT_URL => sprintf( '%s/login', $base_url ), |
| 296 |
CURLOPT_RETURNTRANSFER => true, |
| 297 |
CURLOPT_ENCODING => "", |
| 298 |
CURLOPT_MAXREDIRS => 10, |
| 299 |
CURLOPT_TIMEOUT => 30, |
| 300 |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
| 301 |
CURLOPT_CUSTOMREQUEST => "POST", |
| 302 |
CURLOPT_POSTFIELDS => json_encode( $login_data ), |
| 303 |
CURLOPT_HTTPHEADER => array( |
| 304 |
"Content-Type: application/json", |
| 305 |
), |
| 306 |
) ); |
| 307 |
|
| 308 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_exec -- cURL is required for this API integration. |
| 309 |
$response = curl_exec( $curl ); |
| 310 |
|
| 311 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_error -- cURL is required for this API integration. |
| 312 |
$err = curl_error( $curl ); |
| 313 |
|
| 314 |
$dmca_login_token = ! $err ? str_replace( '"', '', $response ) : ''; |
| 315 |
set_transient( 'dmca_login_token', $dmca_login_token ); |
| 316 |
} |
| 317 |
else{ |
| 318 |
//echo '<p>Issue in token.</p>'; |
| 319 |
} |
| 320 |
|
| 321 |
return apply_filters( 'dmca_login_token', $dmca_login_token ); |
| 322 |
} |
| 323 |
|
| 324 |
catch (Exception $e) |
| 325 |
{ |
| 326 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 327 |
|
| 328 |
if ($e->getSeverity() === E_ERROR) { |
| 329 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 330 |
} else if ($e->getSeverity() === E_WARNING) { |
| 331 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 332 |
} |
| 333 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 334 |
} |
| 335 |
catch (ErrorException $er) |
| 336 |
{ |
| 337 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 338 |
|
| 339 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 340 |
} |
| 341 |
catch ( Throwable $th){ |
| 342 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 343 |
|
| 344 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 345 |
} |
| 346 |
//finally block |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
if ( ! function_exists( 'dmca_add_protected_item' ) ) { |
| 352 |
/** |
| 353 |
* Add protected Item |
| 354 |
* |
| 355 |
* @param bool $post_id |
| 356 |
* @param string $token |
| 357 |
* @param string $item_type |
| 358 |
* |
| 359 |
* @return bool|mixed|void |
| 360 |
*/ |
| 361 |
function dmca_add_protected_item( $post_id = false, $token = '', $item_type = '' ) { |
| 362 |
$error_path = plugin_dir_url(__FILE__) ; |
| 363 |
try { |
| 364 |
if ( ! $post_id || empty( $post_id ) ) { |
| 365 |
return false; |
| 366 |
} |
| 367 |
|
| 368 |
$settings = get_option( 'dmca_badge_settings' ); |
| 369 |
$settings = isset( $settings->values ) ? $settings->values : array(); |
| 370 |
$account_id = isset( $settings['authenticate']['AccountID'] ) ? $settings['authenticate']['AccountID'] : ''; |
| 371 |
$account_id = empty( $account_id ) ? get_user_meta( get_current_user_id(), 'dmca_account_id', true ) : $account_id; |
| 372 |
$token = empty( $token ) ? dmca_get_login_token() : $token; |
| 373 |
$item_type = empty( $item_type ) ? __( 'Web Page', 'dmca-badge' ) : $item_type; |
| 374 |
$item_post = get_post( $post_id ); |
| 375 |
$item_data = array( |
| 376 |
'badgeid' => $account_id, |
| 377 |
'title' => $item_post->post_title, |
| 378 |
'url' => get_the_permalink( $item_post ), |
| 379 |
'description' => wp_trim_words( $item_post->post_content, 10 ), |
| 380 |
'status' => $item_post->post_status, |
| 381 |
'source' => site_url(), |
| 382 |
'type' => $item_type, |
| 383 |
); |
| 384 |
$base_url = esc_url_raw( 'https://api.dmca.com', array( 'https' ) ); |
| 385 |
|
| 386 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_init -- cURL is required for this API integration. |
| 387 |
$curl = curl_init(); |
| 388 |
|
| 389 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_setopt_array -- cURL is required for this API integration. |
| 390 |
curl_setopt_array( $curl, array( |
| 391 |
CURLOPT_URL => sprintf( '%s/addProtectedItem', $base_url ), |
| 392 |
CURLOPT_RETURNTRANSFER => true, |
| 393 |
CURLOPT_ENCODING => "", |
| 394 |
CURLOPT_MAXREDIRS => 10, |
| 395 |
CURLOPT_TIMEOUT => 30, |
| 396 |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
| 397 |
CURLOPT_CUSTOMREQUEST => 'POST', |
| 398 |
CURLOPT_POSTFIELDS => json_encode( $item_data ), |
| 399 |
CURLOPT_HTTPHEADER => array( |
| 400 |
"Content-Type: application/json", |
| 401 |
"Token: $token", |
| 402 |
), |
| 403 |
) ); |
| 404 |
|
| 405 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_exec -- cURL is required for this API integration. |
| 406 |
$response = curl_exec( $curl ); |
| 407 |
|
| 408 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_error -- cURL is required for this API integration. |
| 409 |
$err = curl_error( $curl ); |
| 410 |
|
| 411 |
if ( $err ) { |
| 412 |
return $err; |
| 413 |
} |
| 414 |
|
| 415 |
update_post_meta( $post_id, 'dmca_submission_status', 'sent' ); |
| 416 |
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Debug logging during development. |
| 417 |
error_log( $response ); |
| 418 |
|
| 419 |
return apply_filters( 'dmca_add_protected_item', $response ); |
| 420 |
} |
| 421 |
|
| 422 |
catch (Exception $e) |
| 423 |
{ |
| 424 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 425 |
|
| 426 |
if ($e->getSeverity() === E_ERROR) { |
| 427 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 428 |
} else if ($e->getSeverity() === E_WARNING) { |
| 429 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 430 |
} |
| 431 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 432 |
} |
| 433 |
catch (ErrorException $er) |
| 434 |
{ |
| 435 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 436 |
|
| 437 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 438 |
} |
| 439 |
catch ( Throwable $th){ |
| 440 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 441 |
|
| 442 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 443 |
} |
| 444 |
//finally block |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
if ( ! function_exists( 'dmca_get_option' ) ) { |
| 450 |
/** |
| 451 |
* Return option value |
| 452 |
* |
| 453 |
* @param string $option_key |
| 454 |
* @param string $default_val |
| 455 |
* |
| 456 |
* @return mixed|string|void |
| 457 |
*/ |
| 458 |
function dmca_get_option( $option_key = '', $default_val = '' ) { |
| 459 |
$error_path = plugin_dir_url(__FILE__) ; |
| 460 |
try { |
| 461 |
if ( empty( $option_key ) ) { |
| 462 |
return ''; |
| 463 |
} |
| 464 |
|
| 465 |
$option_val = get_option( $option_key, $default_val ); |
| 466 |
$option_val = empty( $option_val ) ? $default_val : $option_val; |
| 467 |
|
| 468 |
// echo '<pre>'; print_r( $option_key ); echo '</pre>'; |
| 469 |
|
| 470 |
return apply_filters( 'dmca_filters_option_' . $option_key, $option_val ); |
| 471 |
} |
| 472 |
|
| 473 |
catch (Exception $e) |
| 474 |
{ |
| 475 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 476 |
|
| 477 |
if ($e->getSeverity() === E_ERROR) { |
| 478 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 479 |
} else if ($e->getSeverity() === E_WARNING) { |
| 480 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 481 |
} |
| 482 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 483 |
} |
| 484 |
catch (ErrorException $er) |
| 485 |
{ |
| 486 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 487 |
|
| 488 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 489 |
} |
| 490 |
catch ( Throwable $th){ |
| 491 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 492 |
|
| 493 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 494 |
} |
| 495 |
//finally block |
| 496 |
} |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
if ( ! function_exists( 'dmca_get_meta' ) ) { |
| 501 |
/** |
| 502 |
* Return Post Meta Value |
| 503 |
* |
| 504 |
* @param bool $meta_key |
| 505 |
* @param bool $post_id |
| 506 |
* @param string $default |
| 507 |
* |
| 508 |
* @return mixed|string|void |
| 509 |
*/ |
| 510 |
function dmca_get_meta( $meta_key = false, $post_id = false, $default = '' ) { |
| 511 |
$error_path = plugin_dir_url(__FILE__) ; |
| 512 |
try { |
| 513 |
if ( ! $meta_key ) { |
| 514 |
return ''; |
| 515 |
} |
| 516 |
|
| 517 |
$post_id = ! $post_id ? get_the_ID() : $post_id; |
| 518 |
$meta_value = get_post_meta( $post_id, $meta_key, true ); |
| 519 |
$meta_value = empty( $meta_value ) ? $default : $meta_value; |
| 520 |
|
| 521 |
return apply_filters( 'dmca_filters_get_meta', $meta_value, $meta_key, $post_id, $default ); |
| 522 |
} |
| 523 |
|
| 524 |
catch (Exception $e) |
| 525 |
{ |
| 526 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 527 |
|
| 528 |
if ($e->getSeverity() === E_ERROR) { |
| 529 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 530 |
} else if ($e->getSeverity() === E_WARNING) { |
| 531 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 532 |
} |
| 533 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 534 |
} |
| 535 |
catch (ErrorException $er) |
| 536 |
{ |
| 537 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 538 |
|
| 539 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 540 |
} |
| 541 |
catch ( Throwable $th){ |
| 542 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 543 |
|
| 544 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 545 |
} |
| 546 |
//finally block |
| 547 |
} |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
if ( ! function_exists( 'get_dmca_submission_status' ) ) { |
| 552 |
/** |
| 553 |
* Return html submission status |
| 554 |
* |
| 555 |
* @param bool $post_id |
| 556 |
* |
| 557 |
* @return mixed|void |
| 558 |
*/ |
| 559 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 560 |
function get_dmca_submission_status( $post_id = false ) { |
| 561 |
$error_path = plugin_dir_url(__FILE__) ; |
| 562 |
try { |
| 563 |
$submission_status_r = get_dmca_submission_status_raw( $post_id ); |
| 564 |
$submission_status_e = $submission_status_r === 'sent' ? esc_html( 'Sent' ) : esc_html( 'Not Sent' ); |
| 565 |
|
| 566 |
return apply_filters( 'dmca_filters_get_dmca_submission_status', $submission_status_e, $post_id, $submission_status_r ); |
| 567 |
} |
| 568 |
|
| 569 |
catch (Exception $e) |
| 570 |
{ |
| 571 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 572 |
|
| 573 |
if ($e->getSeverity() === E_ERROR) { |
| 574 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 575 |
} else if ($e->getSeverity() === E_WARNING) { |
| 576 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 577 |
} |
| 578 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 579 |
} |
| 580 |
catch (ErrorException $er) |
| 581 |
{ |
| 582 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 583 |
|
| 584 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 585 |
} |
| 586 |
catch ( Throwable $th){ |
| 587 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 588 |
|
| 589 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 590 |
} |
| 591 |
//finally block |
| 592 |
} |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
if ( ! function_exists( 'get_dmca_submission_status_raw' ) ) { |
| 597 |
/** |
| 598 |
* Return html submission raw status |
| 599 |
* |
| 600 |
* @param bool $post_id |
| 601 |
* |
| 602 |
* @return mixed|void |
| 603 |
*/ |
| 604 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 605 |
function get_dmca_submission_status_raw( $post_id = false ) { |
| 606 |
$error_path = plugin_dir_url(__FILE__) ; |
| 607 |
try { |
| 608 |
$post_id = ! $post_id || empty( $post_id ) ? get_the_ID() : $post_id; |
| 609 |
$submission_status_r = dmca_get_meta( 'dmca_submission_status', $post_id, 'pending' ); |
| 610 |
|
| 611 |
return apply_filters( 'dmca_filters_get_dmca_submission_status_raw', $submission_status_r, $post_id ); |
| 612 |
} |
| 613 |
|
| 614 |
catch (Exception $e) |
| 615 |
{ |
| 616 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 617 |
|
| 618 |
if ($e->getSeverity() === E_ERROR) { |
| 619 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 620 |
} else if ($e->getSeverity() === E_WARNING) { |
| 621 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 622 |
} |
| 623 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 624 |
} |
| 625 |
catch (ErrorException $er) |
| 626 |
{ |
| 627 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 628 |
|
| 629 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 630 |
} |
| 631 |
catch ( Throwable $th){ |
| 632 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 633 |
|
| 634 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 635 |
} |
| 636 |
//finally block |
| 637 |
} |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
if ( ! function_exists( 'dmca_add_custom_badge_section' ) ) { |
| 642 |
/** |
| 643 |
* @param $field_name |
| 644 |
* @param $form |
| 645 |
*/ |
| 646 |
function dmca_add_custom_badge_section( $field_name, $form ) { |
| 647 |
$error_path = plugin_dir_url(__FILE__) ; |
| 648 |
try { |
| 649 |
if ( $field_name == 'html' ) { |
| 650 |
include DMCA_PLUGIN_DIR . 'templates/badge-regular.php'; |
| 651 |
} |
| 652 |
|
| 653 |
if ( $field_name == 'badge_custom_field' ) { |
| 654 |
include DMCA_PLUGIN_DIR . 'templates/badge-custom.php'; |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
catch (Exception $e) |
| 659 |
{ |
| 660 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 661 |
|
| 662 |
if ($e->getSeverity() === E_ERROR) { |
| 663 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 664 |
} else if ($e->getSeverity() === E_WARNING) { |
| 665 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 666 |
} |
| 667 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 668 |
} |
| 669 |
catch (ErrorException $er) |
| 670 |
{ |
| 671 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 672 |
|
| 673 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 674 |
} |
| 675 |
catch ( Throwable $th){ |
| 676 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 677 |
|
| 678 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 679 |
} |
| 680 |
//finally block |
| 681 |
} |
| 682 |
} |
| 683 |
|
| 684 |
|
| 685 |
if ( ! function_exists( 'dmca_add_wrapper_in_field_html' ) ) { |
| 686 |
function dmca_add_wrapper_in_field_html( $html, $field_name ) { |
| 687 |
$error_path = plugin_dir_url(__FILE__) ; |
| 688 |
try { |
| 689 |
if ( $field_name == 'html' ) { |
| 690 |
$html .= '</div>'; |
| 691 |
} |
| 692 |
|
| 693 |
return $html; |
| 694 |
} |
| 695 |
|
| 696 |
catch (Exception $e) |
| 697 |
{ |
| 698 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 699 |
|
| 700 |
if ($e->getSeverity() === E_ERROR) { |
| 701 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 702 |
} else if ($e->getSeverity() === E_WARNING) { |
| 703 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 704 |
} |
| 705 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 706 |
} |
| 707 |
catch (ErrorException $er) |
| 708 |
{ |
| 709 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 710 |
|
| 711 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 712 |
} |
| 713 |
catch ( Throwable $th){ |
| 714 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 715 |
|
| 716 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 717 |
} |
| 718 |
//finally block |
| 719 |
} |
| 720 |
} |
| 721 |
|
| 722 |
|
| 723 |
if ( ! function_exists( 'dmca_badge_override_html_raw' ) ) { |
| 724 |
function dmca_badge_override_html_raw( $badge_html, $class, $settings ) { |
| 725 |
$error_path = plugin_dir_url(__FILE__) ; |
| 726 |
try { |
| 727 |
$badge_settings = isset( $settings['badge'] ) ? $settings['badge'] : array(); |
| 728 |
$badge_selection = isset( $badge_settings['badge_selection'] ) ? $badge_settings['badge_selection'] : 'regular'; |
| 729 |
|
| 730 |
if ( $badge_selection === 'custom' && isset( $badge_settings['custom_badge'] ) ) { |
| 731 |
return $badge_settings['custom_badge']; |
| 732 |
} |
| 733 |
|
| 734 |
return $badge_html; |
| 735 |
} |
| 736 |
|
| 737 |
catch (Exception $e) |
| 738 |
{ |
| 739 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 740 |
|
| 741 |
if ($e->getSeverity() === E_ERROR) { |
| 742 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 743 |
} else if ($e->getSeverity() === E_WARNING) { |
| 744 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 745 |
} |
| 746 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 747 |
} |
| 748 |
catch (ErrorException $er) |
| 749 |
{ |
| 750 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 751 |
|
| 752 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 753 |
} |
| 754 |
catch ( Throwable $th){ |
| 755 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 756 |
|
| 757 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 758 |
} |
| 759 |
//finally block |
| 760 |
} |
| 761 |
} |
| 762 |
|
| 763 |
|
| 764 |
if ( ! function_exists( 'dmca_badge_get_account_id' ) ) { |
| 765 |
/** |
| 766 |
* Return account ID |
| 767 |
* |
| 768 |
* @return mixed |
| 769 |
*/ |
| 770 |
function dmca_badge_get_account_id() { |
| 771 |
$error_path = plugin_dir_url(__FILE__) ; |
| 772 |
try { |
| 773 |
$settings = dmca_get_option( 'dmca_badge_settings' ); |
| 774 |
$settings = isset( $settings->values ) ? $settings->values : array(); |
| 775 |
$account_id = @$settings['authenticate']['AccountID']; |
| 776 |
$account_id = empty( $account_id ) ? get_user_meta( get_current_user_id(), 'dmca_account_id', true ) : $account_id; |
| 777 |
|
| 778 |
return $account_id; |
| 779 |
} |
| 780 |
|
| 781 |
catch (Exception $e) |
| 782 |
{ |
| 783 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 784 |
|
| 785 |
if ($e->getSeverity() === E_ERROR) { |
| 786 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 787 |
} else if ($e->getSeverity() === E_WARNING) { |
| 788 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 789 |
} |
| 790 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 791 |
} |
| 792 |
catch (ErrorException $er) |
| 793 |
{ |
| 794 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 795 |
|
| 796 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 797 |
} |
| 798 |
catch ( Throwable $th){ |
| 799 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 800 |
|
| 801 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 802 |
} |
| 803 |
//finally block |
| 804 |
} |
| 805 |
} |
| 806 |
|
| 807 |
|
| 808 |
if ( ! function_exists( 'dmca_badge_get_status_url' ) ) |
| 809 |
{ |
| 810 |
/** |
| 811 |
* Return badge status url |
| 812 |
* |
| 813 |
* @param array $append_args |
| 814 |
* |
| 815 |
* @return string |
| 816 |
*/ |
| 817 |
function dmca_badge_get_status_url( $append_args = array() ) { |
| 818 |
$error_path = plugin_dir_url(__FILE__) ; |
| 819 |
try { |
| 820 |
$status_url = sprintf( '%s?ID=%s', esc_url( 'https://www.dmca.com/Protection/Status.aspx' ), dmca_badge_get_account_id() ); |
| 821 |
|
| 822 |
if ( is_array( $append_args ) ) { |
| 823 |
foreach ( $append_args as $k => $v ) { |
| 824 |
$status_url .= sprintf( '&%s=%s', $k, $v ); |
| 825 |
} |
| 826 |
} |
| 827 |
|
| 828 |
return $status_url; |
| 829 |
} |
| 830 |
|
| 831 |
catch (Exception $e) |
| 832 |
{ |
| 833 |
echo esc_html('Exception Message: ' . $e->getMessage()); |
| 834 |
|
| 835 |
if ($e->getSeverity() === E_ERROR) { |
| 836 |
echo esc_html("E_ERROR triggered." . PHP_EOL); |
| 837 |
} else if ($e->getSeverity() === E_WARNING) { |
| 838 |
echo esc_html("E_WARNING triggered." . PHP_EOL); |
| 839 |
} |
| 840 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 841 |
} |
| 842 |
catch (ErrorException $er) |
| 843 |
{ |
| 844 |
echo esc_html('ErrorException Message: ' . $er->getMessage()); |
| 845 |
|
| 846 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 847 |
} |
| 848 |
catch ( Throwable $th){ |
| 849 |
echo esc_html('ErrorException Message: ' . $th->getMessage()); |
| 850 |
|
| 851 |
echo wp_kses_post("<br> " . esc_url($error_path)); |
| 852 |
} |
| 853 |
|
| 854 |
} |
| 855 |
} |