Changeset 2376518
- Timestamp:
- 09/07/2020 12:50:39 PM (5 years ago)
- Location:
- ping-news/trunk
- Files:
-
- 3 edited
-
pingnews.php (modified) (1 diff)
-
push.php (modified) (54 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ping-news/trunk/pingnews.php
r2321727 r2376518 5 5 /* 6 6 Plugin Name: Ping News 7 Description: The Ping! WordPress plugin allows hyperlocal journalists to submit their news stories to the Ping! system and rec ieve approval/feedback on their stories.8 Version: 1.0. 47 Description: The Ping! WordPress plugin allows hyperlocal journalists to submit their news stories to the Ping! system and receive approval/feedback on their stories. 8 Version: 1.0.5 9 9 License: GPLv2 or later 10 10 */ 11 11 12 define("PINGNEWS_PLUGIN_VERSION", "1.0. 4");12 define("PINGNEWS_PLUGIN_VERSION", "1.0.5"); 13 13 14 14 // Include all functions related to pushing packages to ingest 15 15 include 'push.php'; 16 17 /**18 * Initialise the plugin19 *20 * @return void21 */22 function pingnews_initialise() {23 // initialise the plugin here24 // TODO remove this if it does not get used25 }26 27 register_activation_hook(__FILE__, "pingnews_initialise");28 16 29 17 add_action("init", "pingnews_pusher_role", 100); -
ping-news/trunk/push.php
r2321706 r2376518 1 1 <?php 2 // One thing to consider is that we do not have control of the server environmental variables on 3 // the WordPress instances used by real users, this means that if we can't find a variable with 4 // `getenv` then we should set a defaults that uses the values we want to have in production 5 6 // NOTE: All constants and function names should be prefixed with `PINGNEWS` or `pingnews`, 7 // as applicable, as otherwise there could be conflicts with constants and functions in other 8 // plugins as all of these are defined globally in php 9 2 10 // Get vmn ingest url from environmental variable and if does not exist use default 3 11 $pingnews_vmn_ingest_url = getenv("VMN_INGEST_URL"); … … 5 13 $pingnews_vmn_ingest_url = "https://ingest.vmn.production.omni-digital.co.uk"; 6 14 } 7 // Get vmn ingesturl from environmental variable and if does not exist use default15 // Get vmn central url from environmental variable and if does not exist use default 8 16 $pingnews_vmn_central_url = getenv("VMN_CENTRAL_URL"); 9 17 if (!$pingnews_vmn_central_url) { 10 18 $pingnews_vmn_central_url = "https://central.vmn.production.omni-digital.co.uk"; 11 19 } 12 // This variable is used in push.phpfor JS error reporting13 define( "PINGNEWS_SENTRY_DSN", getenv("WP_SENTRY_DSN"));20 // This variable is used in `push.php` for JS error reporting 21 define("PINGNEWS_SENTRY_DSN", getenv("WP_SENTRY_DSN")); 14 22 define("PINGNEWS_VMN_INGEST_URL", $pingnews_vmn_ingest_url); 15 23 define("PINGNEWS_VMN_CENTRAL_URL", $pingnews_vmn_central_url); … … 22 30 // The interval for which package data from Ingest to polled (in milliseconds) 23 31 define("PINGNEWS_POLL_INTERVAL", "5000"); 24 // constant for the key to store package token in a posts meta data32 // Constant for the key to store package token in a posts meta data 25 33 define("PINGNEWS_PACKAGE_DATA", "pingnews_package_data"); 26 // constant for taxonomy select tags34 // Constant for taxonomy select tags 27 35 define("PINGNEWS_LOCATION", "pingnews_location"); 28 36 define("PINGNEWS_STORY_FOCUS", "pingnews_story_focus"); 29 // constant for outer div around the package token html37 // Constant for outer div around the package token html 30 38 define("PINGNEWS_PACKAGE_DATA_OUTER", "pingnews_package_data_outer"); 31 // constants for spans to display package data39 // Constants for spans to display package data 32 40 define("PINGNEWS_PACKAGE_TOKEN", "pingnews_package_token"); 33 41 define("PINGNEWS_PACKAGE_DATE_CREATED", "pingnews_date_created"); … … 36 44 define("PINGNEWS_PACKAGE_FEEDBACK_OUTER", "pingnews_package_feedback_outer"); 37 45 define("PINGNEWS_PACKAGE_TAGS", "pingnews_package_tags"); 38 // constant for push to ping button anchor46 // Constant for push to ping button anchor 39 47 define("PINGNEWS_PUSH_TO_PING_ANCHOR", "pingnews_push_to_ping_anchor"); 40 // boolean for whether Trends features are applied48 // Boolean for whether Trends features are applied 41 49 // NOTE: We would usually set this from ansible but we do not have control of environmental 42 50 // variables on external WordPress instances 43 51 define("PINGNEWS_TRENDS_FEATURE_FLAG", true ); 44 52 define("PINGNEWS_EXISTING_TAGS", "pingnews_existing_tags"); 53 45 54 /** 46 55 * Define a custom role for pushing to VMN … … 56 65 ] 57 66 ); 58 // add the capability to the administrator role as well 67 68 // Add the capability to the administrator role as well 59 69 $admin_role = get_role("administrator"); 60 70 $admin_role->add_cap(PINGNEWS_PUSH_CAP, true); 61 71 } 72 62 73 /** 63 74 * Function which returns whether the current user has the push to ping capability … … 66 77 */ 67 78 function pingnews_has_push_caps() { 68 $current_user = wp_get_current_user(); 69 return user_can($current_user, PINGNEWS_PUSH_CAP); 70 } 79 $current_user = wp_get_current_user(); 80 return user_can($current_user, PINGNEWS_PUSH_CAP); 81 } 82 71 83 /** 72 84 * Renders the HTML page for the Ping News push interface … … 78 90 return; 79 91 } ?> 92 80 93 <style type="text/css"> 81 94 .vmn_ping__ping_logo { … … 187 200 <script type="text/javascript"> 188 201 document.getElementById("submit").addEventListener("click", function(){ 189 document.getElementById("submit").value = "Saved!";202 document.getElementById("submit").value = "Saved!"; 190 203 }); 191 204 </script> … … 194 207 <?php 195 208 } 209 210 /** 211 * Saves `PINGNEWS_AUTH_TOKEN` to Ping News settings 212 * 213 * @return void 214 */ 196 215 function pingnews_update_auth_token() { 197 register_setting( PINGNEWS_AUTH_TOKEN_SETTINGS, PINGNEWS_AUTH_TOKEN ); 198 } 216 register_setting(PINGNEWS_AUTH_TOKEN_SETTINGS, PINGNEWS_AUTH_TOKEN); 217 } 218 199 219 /** 200 220 * Adds the menu button if the user has push capability … … 211 231 ); 212 232 } 233 213 234 /** 214 235 * The html to render in metabox and send AJAX request on clicking button … … 219 240 // Add thickbox for claiming access rights to photos 220 241 add_thickbox(); 242 221 243 $post_id = get_the_id(); 222 244 $package_data = False; … … 224 246 $package_data = end(get_post_meta($post_id, PINGNEWS_PACKAGE_DATA)); 225 247 } 226 // TODO When it comes to applying css use class toggling rather than inline styles 248 249 // TODO: When it comes to applying css use class toggling rather than inline styles 227 250 $display = "none"; 228 251 $display_feedback = "none"; … … 235 258 } 236 259 } 260 237 261 try { 238 262 $taxonomies = pingnews_get_taxonomies(); … … 242 266 return; 243 267 } 268 244 269 if ( PINGNEWS_TRENDS_FEATURE_FLAG ) { 245 270 $existing_tags = pingnews_get_existing_tags(); 246 271 } 247 // Display package data if package already pushed to ingest 272 248 273 ?> 249 274 <style type="text/css"> … … 377 402 } 378 403 .vmn_ping__button.vmn_ping__button--reductive_action { 379 -webkit-box-shadow: inset 0 -3px 0 #ffebec;380 box-shadow: inset 0 -3px 0 #ffebec;381 border-color: #fb0e16;382 background-color: #fff;383 text-shadow: none;384 color: #fb0e16;404 -webkit-box-shadow: inset 0 -3px 0 #ffebec; 405 box-shadow: inset 0 -3px 0 #ffebec; 406 border-color: #fb0e16; 407 background-color: #fff; 408 text-shadow: none; 409 color: #fb0e16; 385 410 } 386 411 .vmn_ping__button.vmn_ping__button--reductive_action:active, 387 412 .vmn_ping__button.vmn_ping__button--reductive_action:focus, 388 413 .vmn_ping__button.vmn_ping__button--reductive_action:hover { 389 -webkit-box-shadow: inset 0 -1px 0 #ffebec;390 box-shadow: inset 0 -1px 0 #ffebec;391 border-color: #d3030a;392 color: #d3030a;414 -webkit-box-shadow: inset 0 -1px 0 #ffebec; 415 box-shadow: inset 0 -1px 0 #ffebec; 416 border-color: #d3030a; 417 color: #d3030a; 393 418 } 394 419 #TB_ajaxContent p:first-of-type { … … 396 421 } 397 422 .chosen-container { 398 position: relative;399 z-index: 10;400 display: inline-block;401 vertical-align: middle;402 -webkit-user-select: none;403 -moz-user-select: none;404 -ms-user-select: none;405 user-select: none;406 padding-bottom: 2px;423 position: relative; 424 z-index: 10; 425 display: inline-block; 426 vertical-align: middle; 427 -webkit-user-select: none; 428 -moz-user-select: none; 429 -ms-user-select: none; 430 user-select: none; 431 padding-bottom: 2px; 407 432 } 408 433 * + .chosen-container { 409 margin-top: .8em;434 margin-top: .8em; 410 435 } 411 436 .chosen-container .chosen-drop { 412 clip: rect(0, 0, 0, 0);413 -webkit-clip-path: inset(100% 100%);414 clip-path: inset(100% 100%);415 position: absolute;416 z-index: auto;417 top: 100%;418 left: 0;419 border: 1px solid #650df2;420 border-radius: 0 0 3px 3px;421 width: 100%;422 background-color: #fff;437 clip: rect(0, 0, 0, 0); 438 -webkit-clip-path: inset(100% 100%); 439 clip-path: inset(100% 100%); 440 position: absolute; 441 z-index: auto; 442 top: 100%; 443 left: 0; 444 border: 1px solid #650df2; 445 border-radius: 0 0 3px 3px; 446 width: 100%; 447 background-color: #fff; 423 448 } 424 449 .chosen-container.chosen-with-drop .chosen-drop { 425 clip: auto;426 -webkit-clip-path: none;427 clip-path: none;450 clip: auto; 451 -webkit-clip-path: none; 452 clip-path: none; 428 453 } 429 454 .chosen-container .chosen-results { 430 position: relative;431 overflow-x: hidden;432 overflow-y: auto;433 max-height: 14rem;434 background-color: #fff;455 position: relative; 456 overflow-x: hidden; 457 overflow-y: auto; 458 max-height: 14rem; 459 background-color: #fff; 435 460 } 436 461 .chosen-container .chosen-results li { 437 will-change: background-color, color;438 -webkit-transition-property: background-color, color;439 transition-property: background-color, color;440 -webkit-transition-duration: 0.14s;441 transition-duration: 0.14s;442 -webkit-transition-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75);443 transition-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75);444 display: none;445 word-wrap: break-word;446 padding: 0.539333333333333rem 2.427rem 0.539333333333333rem 0.6472rem;462 will-change: background-color, color; 463 -webkit-transition-property: background-color, color; 464 transition-property: background-color, color; 465 -webkit-transition-duration: 0.14s; 466 transition-duration: 0.14s; 467 -webkit-transition-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75); 468 transition-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75); 469 display: none; 470 word-wrap: break-word; 471 padding: 0.539333333333333rem 2.427rem 0.539333333333333rem 0.6472rem; 447 472 } 448 473 .chosen-container .chosen-results li.active-result,.chosen-container .chosen-results li.disabled-result,.chosen-container .chosen-results li.no-results { 449 display: list-item;474 display: list-item; 450 475 } 451 476 .chosen-container .chosen-results li.disabled-result { 452 color: #cccace;477 color: #cccace; 453 478 } 454 479 .chosen-container .chosen-results li.no-results { 455 color: #fc4046;480 color: #fc4046; 456 481 } 457 482 .chosen-container .chosen-results li.active-result { 458 cursor: pointer;483 cursor: pointer; 459 484 } 460 485 .chosen-container .chosen-results li.disabled-result { 461 cursor: default;462 color: #e5e4e7;486 cursor: default; 487 color: #e5e4e7; 463 488 } 464 489 .chosen-container .chosen-results li.highlighted { 465 background-color: #e9e0ff;466 color: #19191a;490 background-color: #e9e0ff; 491 color: #19191a; 467 492 } 468 493 .chosen-container-multi .chosen-choices-outer { 469 overflow-x: hidden;470 overflow-y: auto;471 height: 100%;494 overflow-x: hidden; 495 overflow-y: auto; 496 height: 100%; 472 497 } 473 498 .chosen-container-multi .chosen-choices { 474 cursor: text;475 position: relative;476 display: -webkit-box;477 display: -ms-flexbox;478 display: flex;479 -webkit-box-orient: horizontal;480 -webkit-box-direction: normal;481 -ms-flex-direction: row;482 flex-direction: row;483 -ms-flex-wrap: wrap;484 flex-wrap: wrap;485 -webkit-box-align: center;486 -ms-flex-align: center;487 align-items: center;488 -webkit-box-pack: start;489 -ms-flex-pack: start;490 justify-content: flex-start;491 margin: 0;492 width: 100%;493 border-radius: 3px 3px 0 0;494 background-color: #fff;495 padding: 1em;499 cursor: text; 500 position: relative; 501 display: -webkit-box; 502 display: -ms-flexbox; 503 display: flex; 504 -webkit-box-orient: horizontal; 505 -webkit-box-direction: normal; 506 -ms-flex-direction: row; 507 flex-direction: row; 508 -ms-flex-wrap: wrap; 509 flex-wrap: wrap; 510 -webkit-box-align: center; 511 -ms-flex-align: center; 512 align-items: center; 513 -webkit-box-pack: start; 514 -ms-flex-pack: start; 515 justify-content: flex-start; 516 margin: 0; 517 width: 100%; 518 border-radius: 3px 3px 0 0; 519 background-color: #fff; 520 padding: 1em; 496 521 } 497 522 .chosen-container-multi .chosen-choices li.search-field:not(:first-child), 498 523 .chosen-container-multi .chosen-choices li.search-field:not(:first-child) input { 499 -webkit-box-flex: 0;500 -ms-flex: 0 0 1px;501 flex: 0 0 1px;524 -webkit-box-flex: 0; 525 -ms-flex: 0 0 1px; 526 flex: 0 0 1px; 502 527 } 503 528 .chosen-container-multi .chosen-choices li.search-field { 504 display: -webkit-box;505 display: -ms-flexbox;506 display: flex;507 margin: 0.3236rem 0 0;508 padding: 0;509 white-space: nowrap;529 display: -webkit-box; 530 display: -ms-flexbox; 531 display: flex; 532 margin: 0.3236rem 0 0; 533 padding: 0; 534 white-space: nowrap; 510 535 } 511 536 .chosen-container-multi .chosen-choices li.search-field input { 512 padding: 0;537 padding: 0; 513 538 } 514 539 .chosen-container-multi .chosen-choices li.search-choice { 515 cursor: default;516 -webkit-box-flex: 0;517 -ms-flex: 0 0 auto;518 flex: 0 0 auto;519 position: relative;520 display: -webkit-box;521 display: -ms-flexbox;522 display: flex;523 -webkit-box-align: center;524 -ms-flex-align: center;525 align-items: center;526 -webkit-box-pack: center;527 -ms-flex-pack: center;528 justify-content: center;529 margin: 0.3236rem 0.3236rem 0 0;530 border: 1px solid #00ffb7;531 max-width: 100%;532 background-color: #fff;533 padding: .25rem .5em .25rem .375rem;534 line-height: 1.4;535 font-size: 14px;540 cursor: default; 541 -webkit-box-flex: 0; 542 -ms-flex: 0 0 auto; 543 flex: 0 0 auto; 544 position: relative; 545 display: -webkit-box; 546 display: -ms-flexbox; 547 display: flex; 548 -webkit-box-align: center; 549 -ms-flex-align: center; 550 align-items: center; 551 -webkit-box-pack: center; 552 -ms-flex-pack: center; 553 justify-content: center; 554 margin: 0.3236rem 0.3236rem 0 0; 555 border: 1px solid #00ffb7; 556 max-width: 100%; 557 background-color: #fff; 558 padding: .25rem .5em .25rem .375rem; 559 line-height: 1.4; 560 font-size: 14px; 536 561 } 537 562 .chosen-container-multi .chosen-choices li.search-choice span { 538 display: inline-block;539 word-wrap: break-word;563 display: inline-block; 564 word-wrap: break-word; 540 565 } 541 566 .chosen-container-multi .chosen-choices li.search-choice .search-choice-close { 542 display: inline-block;543 margin-left: 0.3236rem;544 height: 1.25em;545 width: 0.539333333333333rem;546 background-image: url("<?php echo plugin_dir_url( __FILE__ ) . "images/chosen_cross.svg"; ?>");547 background-position: center;548 background-repeat: no-repeat;549 background-size: contain;567 display: inline-block; 568 margin-left: 0.3236rem; 569 height: 1.25em; 570 width: 0.539333333333333rem; 571 background-image: url("<?php echo plugin_dir_url( __FILE__ ) . "images/chosen_cross.svg"; ?>"); 572 background-position: center; 573 background-repeat: no-repeat; 574 background-size: contain; 550 575 } 551 576 .edit-post-sidebar input.chosen-search-input[type="text"] { … … 555 580 } 556 581 .chosen-container-multi .chosen-results { 557 margin: 0;558 padding: 0;582 margin: 0; 583 padding: 0; 559 584 } 560 585 .chosen-container-multi .chosen-drop .result-selected { 561 display: list-item;562 cursor: default;563 color: #b2afb6;586 display: list-item; 587 cursor: default; 588 color: #b2afb6; 564 589 } 565 590 .chosen-container { 566 will-change: border-color, box-shadow;567 -webkit-transition-property: border-color, -webkit-box-shadow;568 transition-property: border-color, -webkit-box-shadow;569 transition-property: border-color, box-shadow;570 transition-property: border-color, box-shadow, -webkit-box-shadow;571 -webkit-transition-duration: 0.14s;572 transition-duration: 0.14s;573 -webkit-transition-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75);574 transition-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75);575 cursor: pointer;576 -webkit-appearance: none;577 -moz-appearance: none;578 appearance: none;579 width: 100%;580 border-radius: 3px;581 border: 1px solid #650df2;582 border-left-width: 3px;583 background-color: #fff;584 background-position: right 0.809rem top 50%;585 background-repeat: no-repeat;586 background-size: 1.2135rem;587 color: #3a393c;591 will-change: border-color, box-shadow; 592 -webkit-transition-property: border-color, -webkit-box-shadow; 593 transition-property: border-color, -webkit-box-shadow; 594 transition-property: border-color, box-shadow; 595 transition-property: border-color, box-shadow, -webkit-box-shadow; 596 -webkit-transition-duration: 0.14s; 597 transition-duration: 0.14s; 598 -webkit-transition-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75); 599 transition-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75); 600 cursor: pointer; 601 -webkit-appearance: none; 602 -moz-appearance: none; 603 appearance: none; 604 width: 100%; 605 border-radius: 3px; 606 border: 1px solid #650df2; 607 border-left-width: 3px; 608 background-color: #fff; 609 background-position: right 0.809rem top 50%; 610 background-repeat: no-repeat; 611 background-size: 1.2135rem; 612 color: #3a393c; 588 613 } 589 614 .chosen-container:active, … … 591 616 .vmn_ping__form_component__select:hover, 592 617 .chosen-container:hover { 593 outline: 0;594 -webkit-box-shadow: inset 0 -1px 0 #e9e0ff;595 box-shadow: inset 0 -1px 0 #e9e0ff;596 border-color: #520ab8;618 outline: 0; 619 -webkit-box-shadow: inset 0 -1px 0 #e9e0ff; 620 box-shadow: inset 0 -1px 0 #e9e0ff; 621 border-color: #520ab8; 597 622 } 598 623 .chosen-container { 599 -webkit-box-shadow: inset 0 -2px 0 #e9e0ff;600 box-shadow: inset 0 -2px 0 #e9e0ff;624 -webkit-box-shadow: inset 0 -2px 0 #e9e0ff; 625 box-shadow: inset 0 -2px 0 #e9e0ff; 601 626 } 602 627 .vmn_ping__form_options .vmn_ping__form_component .vmn_ping__form_component__text { 603 will-change: border-color, box-shadow;604 -webkit-transition-property: border-color, -webkit-box-shadow;605 transition-property: border-color, -webkit-box-shadow;606 transition-property: border-color, box-shadow;607 transition-property: border-color, box-shadow, -webkit-box-shadow;608 -webkit-transition-duration: 0.14s;609 transition-duration: 0.14s;610 -webkit-transition-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75);611 transition-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75);612 width: 100%;613 max-width: 100%;614 -webkit-box-shadow: inset 0 -3px 0 #e9e0ff;615 box-shadow: inset 0 -3px 0 #e9e0ff;616 border-radius: 3px;617 border: 1px solid #650df2;618 border-left-width: 3px;619 background-color: #fff;620 padding: 1em;621 line-height: 1.5em;622 font-size: 14px;628 will-change: border-color, box-shadow; 629 -webkit-transition-property: border-color, -webkit-box-shadow; 630 transition-property: border-color, -webkit-box-shadow; 631 transition-property: border-color, box-shadow; 632 transition-property: border-color, box-shadow, -webkit-box-shadow; 633 -webkit-transition-duration: 0.14s; 634 transition-duration: 0.14s; 635 -webkit-transition-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75); 636 transition-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75); 637 width: 100%; 638 max-width: 100%; 639 -webkit-box-shadow: inset 0 -3px 0 #e9e0ff; 640 box-shadow: inset 0 -3px 0 #e9e0ff; 641 border-radius: 3px; 642 border: 1px solid #650df2; 643 border-left-width: 3px; 644 background-color: #fff; 645 padding: 1em; 646 line-height: 1.5em; 647 font-size: 14px; 623 648 } 624 649 .vmn_ping__form_options .vmn_ping__form_component .vmn_ping__form_component__text::-webkit-input-placeholder { 625 color: #b2afb6;626 opacity: 1;650 color: #b2afb6; 651 opacity: 1; 627 652 } 628 653 .vmn_ping__form_options .vmn_ping__form_component .vmn_ping__form_component__text:-moz-placeholder { 629 color: #b2afb6;630 opacity: 1;654 color: #b2afb6; 655 opacity: 1; 631 656 } 632 657 .vmn_ping__form_options .vmn_ping__form_component .vmn_ping__form_component__text::-moz-placeholder { 633 color: #b2afb6;634 opacity: 1;658 color: #b2afb6; 659 opacity: 1; 635 660 } 636 661 .vmn_ping__form_options .vmn_ping__form_component .vmn_ping__form_component__text:-ms-input-placeholder { 637 color: #b2afb6;638 opacity: 1;662 color: #b2afb6; 663 opacity: 1; 639 664 } 640 665 .vmn_ping__form_options .vmn_ping__form_component .vmn_ping__form_component__text:active, 641 666 .vmn_ping__form_options .vmn_ping__form_component .vmn_ping__form_component__text:focus, 642 667 .vmn_ping__form_options .vmn_ping__form_component .vmn_ping__form_component__text:hover { 643 outline: 0;644 -webkit-box-shadow: inset 0 -1px 0 #e9e0ff;645 box-shadow: inset 0 -1px 0 #e9e0ff;646 border-color: #520ab8;668 outline: 0; 669 -webkit-box-shadow: inset 0 -1px 0 #e9e0ff; 670 box-shadow: inset 0 -1px 0 #e9e0ff; 671 border-color: #520ab8; 647 672 } 648 673 label + .vmn_ping__form_component__text, 649 674 * + .vmn_ping__form_component__help_text { 650 margin-top: .8em;675 margin-top: .8em; 651 676 } 652 677 .vmn_ping__form_component__help_text { 653 display: block;678 display: block; 654 679 } 655 680 </style> … … 749 774 class="vmn_ping__button thickbox" 750 775 href="#TB_inline?width=600&height=550&inlineId=pingnews-thickbox"><?php if ( $package_json ): ?>Push again!<?php else: ?>Push to Ping!<?php endif; ?></a> 776 751 777 <?php if ( PINGNEWS_SENTRY_DSN ) : ?> 752 778 <script src="https://browser.sentry-cdn.com/5.11.1/bundle.min.js" integrity="sha384-r7/ZcDRYpWjCNXLUKk3iuyyyEcDJ+o+3M5CqXP5GUGODYbolXewNHAZLYSJ3ZHcV" crossorigin="anonymous"></script> 753 779 <?php endif; ?> 780 754 781 <?php if ( PINGNEWS_TRENDS_FEATURE_FLAG ) : ?> 755 782 <script src="https://cdn.jsdelivr.net/npm/[email protected]/chosen.jquery.min.js"></script> 756 783 <script>jQuery(".chosen-select").chosen({width: "100%"});</script> 757 784 <?php endif; ?> 785 758 786 <script type="text/javascript"> 759 787 <?php if ( PINGNEWS_SENTRY_DSN ) : ?> … … 767 795 document.getElementById("<?php echo PINGNEWS_PUSH_TO_PING_ANCHOR; ?>").innerHTML = "Push again!"; 768 796 } 797 769 798 feedback_outer_element = document.getElementById("<?php echo PINGNEWS_PACKAGE_FEEDBACK_OUTER; ?>"); 770 799 if ( package_data["feedback"] ) { … … 774 803 feedback_outer_element.style.display = "none"; 775 804 } 805 776 806 if (<?php echo PINGNEWS_TRENDS_FEATURE_FLAG; ?>) { 777 807 tags_element = document.getElementById("<?php echo PINGNEWS_PACKAGE_TAGS; ?>") … … 779 809 if ( tags && update_tags) { 780 810 let existing_tags_element = document.getElementById("<?php echo PINGNEWS_EXISTING_TAGS; ?>"); 811 781 812 if (existing_tags_element) { 782 813 tags = tags.split(", "); 783 814 let existing_tags = []; 815 784 816 // Remove items from tags array if they appear in existing_tags array 785 817 for (let i = 0; i < existing_tags_element.options.length; i++) { … … 791 823 } 792 824 } 825 793 826 // Populate contents of tags text area 794 827 tags_element.value = tags.join(", "); … … 812 845 'nonce': '<?php echo wp_create_nonce('pingnews_post_package'); ?>', 813 846 }; 847 814 848 if (<?php echo PINGNEWS_TRENDS_FEATURE_FLAG; ?>) { 815 849 let existing_tags_element = document.getElementById("<?php echo PINGNEWS_EXISTING_TAGS; ?>"); … … 825 859 } 826 860 } 861 827 862 jQuery.ajax({ 828 863 type: 'POST', … … 835 870 package_data = response["package_data"]; 836 871 document.getElementById("<?php echo PINGNEWS_PACKAGE_DATA_OUTER; ?>").style.display = "inline"; 872 837 873 if ( package_data["package_token"] ) { 838 874 document.getElementById("<?php echo PINGNEWS_PACKAGE_TOKEN; ?>").innerHTML = package_data["package_token"]; 839 875 } 876 840 877 if ( package_data["date_created"] ) { 841 878 document.getElementById("<?php echo PINGNEWS_PACKAGE_DATE_CREATED; ?>").innerHTML = package_data["date_created"]; 842 879 } 880 843 881 updateDynamicInfo(package_data, true); 844 882 } … … 848 886 }); 849 887 } 888 850 889 function pollIngest(update_tags) { 851 890 jQuery.ajax({ … … 865 904 } 866 905 }); 906 867 907 setTimeout(pollIngest.bind(null, false), <?php echo PINGNEWS_POLL_INTERVAL; ?>); 868 908 } 909 869 910 pollIngest(true); 870 911 </script> 871 912 <?php 872 913 } 914 873 915 /** 874 916 * Function to echo option tags of the available taxonomy items … … 879 921 foreach ($taxonomy_list as $taxonomy_item) { 880 922 $selected = ""; 881 // Set the initially selected taxonomy by adding `selected` to option tag923 // Set the initially selected taxonomy by adding `selected` to option tag 882 924 if ($taxonomy_item[0] == $selected_taxonomy) { 883 925 $selected = "selected"; … … 886 928 } 887 929 } 930 888 931 /** 889 932 * Function to echo option tags of the available taxonomy items … … 893 936 function pingnews_get_tag_options($tag_list, $selected_tags_string) { 894 937 $selected_tags_list = explode(", ", $selected_tags_string); 938 895 939 foreach ($tag_list as $key => $tag_item) { 896 940 $selected = ""; … … 902 946 } 903 947 } 948 904 949 /** 905 950 * The html to show when user has not entered authorization token in ping settings … … 908 953 */ 909 954 function pingnews_metabox_no_auth_token_html() { 910 ?> 911 <p>Please enter your authorization token <a href="<?php menu_page_url(PINGNEWS_SETTINGS); ?>">here</a></p> 912 <?php 913 } 955 ?> 956 <p>Please enter your authorization token <a href="<?php menu_page_url(PINGNEWS_SETTINGS); ?>">here</a></p> 957 <?php 958 } 959 914 960 /** 915 961 * The php to render the pingnews metabox … … 919 965 function pingnews_metabox_php() { 920 966 $auth_token = get_option( PINGNEWS_AUTH_TOKEN ); 967 921 968 // Refer user to settings page if authorization token not set 922 969 if ( $auth_token ) { … … 926 973 } 927 974 } 975 928 976 /** 929 977 * Function which adds a metabox to all screen types defined in $screens … … 934 982 if ( pingnews_has_push_caps() ) { 935 983 $screens = ['post']; 984 936 985 foreach ($screens as $screen) { 937 986 add_meta_box( … … 945 994 } 946 995 } 996 947 997 /** 948 998 * Function to return an array of the categories associated with the post … … 951 1001 */ 952 1002 function pingnews_get_categories_array($id) { 953 $categories = get_the_category($id); 954 $categories_array = []; 955 foreach ($categories as $category) { 956 array_push($categories_array, $category->name); 957 } 958 return $categories_array; 959 } 1003 $categories = get_the_category($id); 1004 $categories_array = []; 1005 1006 foreach ($categories as $category) { 1007 array_push($categories_array, $category->name); 1008 } 1009 1010 return $categories_array; 1011 } 1012 960 1013 /** 961 1014 * Function to send a post request using WordPress HTTP API … … 964 1017 */ 965 1018 function pingnews_post_request($url, $body) { 966 $args = array( 967 "body" => $body, 968 "timeout" => "5", 969 "redirection" => "5", 970 "httpversion" => "1.0", 971 "headers" => array( 972 "Authorization" => "Token " . get_option( PINGNEWS_AUTH_TOKEN ), 973 "Content-Type" => "application/json", 974 "Content-Length" => strlen($body) 975 ), 976 ); 977 // Send post request 978 $response = wp_remote_post($url, $args); 979 // Get http status from response 980 $http_status = wp_remote_retrieve_response_code($response); 981 // Get body content of response 982 $body = wp_remote_retrieve_body($response); 983 return [$body, $http_status]; 984 } 1019 $args = array( 1020 "body" => $body, 1021 "timeout" => "5", 1022 "redirection" => "5", 1023 "httpversion" => "1.0", 1024 "headers" => array( 1025 "Authorization" => "Token " . get_option( PINGNEWS_AUTH_TOKEN ), 1026 "Content-Type" => "application/json", 1027 "Content-Length" => strlen($body) 1028 ), 1029 ); 1030 1031 // Send post request 1032 $response = wp_remote_post($url, $args); 1033 // Get http status from response 1034 $http_status = wp_remote_retrieve_response_code($response); 1035 // Get body content of response 1036 $body = wp_remote_retrieve_body($response); 1037 1038 return [$body, $http_status]; 1039 } 1040 985 1041 /** 986 1042 * Function to send a get request using WordPress HTTP API … … 989 1045 */ 990 1046 function pingnews_get_request($url, $package_token) { 991 $http_headers = array( 992 "Authorization" => "Token " . get_option( PINGNEWS_AUTH_TOKEN ), 993 ); 994 if ( $package_token ) { 995 $http_headers["X-Package-Token"] = $package_token; 996 } 997 $args = array( 998 "timeout" => "5", 999 "redirection" => "5", 1000 "httpversion" => "1.0", 1001 "headers" => $http_headers, 1002 ); 1003 // Send get request 1004 $response = wp_remote_get($url, $args); 1005 // Get http status from response 1006 $http_status = wp_remote_retrieve_response_code($response); 1007 // Get body content of response 1008 $body = wp_remote_retrieve_body($response); 1009 return [$body, $http_status]; 1010 } 1047 $http_headers = array( 1048 "Authorization" => "Token " . get_option( PINGNEWS_AUTH_TOKEN ), 1049 ); 1050 1051 if ( $package_token ) { 1052 $http_headers["X-Package-Token"] = $package_token; 1053 } 1054 1055 $args = array( 1056 "timeout" => "5", 1057 "redirection" => "5", 1058 "httpversion" => "1.0", 1059 "headers" => $http_headers, 1060 ); 1061 1062 // Send get request 1063 $response = wp_remote_get($url, $args); 1064 // Get http status from response 1065 $http_status = wp_remote_retrieve_response_code($response); 1066 // Get body content of response 1067 $body = wp_remote_retrieve_body($response); 1068 1069 return [$body, $http_status]; 1070 } 1071 1011 1072 /** 1012 1073 * Function to return which a http_status code is considered valid … … 1015 1076 */ 1016 1077 function pingnews_is_http_status_valid($http_status) { 1017 // Check if http status code is succes ful (2xx)1078 // Check if http status code is successful (2xx) 1018 1079 return strval($http_status)[0] == '2'; 1019 1080 } 1081 1020 1082 /** 1021 1083 * Function to return the most recently saved post information and send this to Ingest in a … … 1026 1088 function pingnews_post_package_ajax_handler() { 1027 1089 $unsuccessful_message = "Unfortunately your push to ping was unsuccessful, please try again!"; 1090 1028 1091 if ( pingnews_has_push_caps() && 1029 1092 isset($_POST["action"]) && … … 1036 1099 // verify there is a post with such a number 1037 1100 $post = get_post((int)$post_id); 1101 1038 1102 if (empty($post)) { 1039 1103 echo json_encode([ … … 1043 1107 wp_die(); 1044 1108 } 1109 1045 1110 global $wp_version; 1046 1111 // Find all urls for oEmbeds and replace with generated iframe … … 1048 1113 // Remove newlines otherwise regex does not match 1049 1114 $striped_content = str_replace(array("\n", "\r"), '', $content); 1050 // Find all occur ances of strings between div's with class "wp-block-embed__wrapper"1115 // Find all occurrences of strings between div's with class "wp-block-embed__wrapper" 1051 1116 preg_match_all('/<div class="wp-block-embed__wrapper">(.*?)<\/div>/', $striped_content, $matches); 1117 1052 1118 foreach ($matches[1] as $url) { 1053 1119 // Generate oEmbed url … … 1055 1121 $content = str_replace("\n".$url."\n", $iframe_embed, $content); 1056 1122 } 1123 1057 1124 // Construct data to send in post request to ingest 1058 1125 $post_data = [ … … 1075 1142 "tags" => sanitize_text_field($_POST["tags"]), 1076 1143 ]; 1144 1077 1145 $post_json = json_encode($post_data); 1078 1146 list($package_data, $http_status) = pingnews_post_request(PINGNEWS_VMN_INGEST_URL . "/api/v1/package/", $post_json); 1147 1079 1148 if (pingnews_is_http_status_valid($http_status) && $package_data) { 1080 // When posting new story feedback can be cleared if rec ieved for a previous version of the post1149 // When posting new story feedback can be cleared if received for a previous version of the post 1081 1150 $package_data["feedback"] = ""; 1082 1151 add_post_meta($post_id, PINGNEWS_PACKAGE_DATA, $package_data); 1083 1152 $message = "You have successfully pushed to Ping!"; 1084 1153 $package_json = json_decode($package_data); 1154 1085 1155 // Convert date times to UTC and r format 1086 1156 $date_provider_published = new DateTime($package_json->package_data->date_provider_published, new DateTimeZone("UTC")); … … 1097 1167 $package_json = False; 1098 1168 } 1169 1099 1170 echo json_encode([ 1100 1171 "message" => $message, 1101 1172 "package_data" => $package_json 1102 1173 ]); 1174 1103 1175 wp_die(); 1104 1176 } … … 1109 1181 wp_die(); 1110 1182 } 1183 1111 1184 /** 1112 1185 * Function to get most recent version of the last sent package to Ingest, to be able to e.g. … … 1125 1198 if ( $post_id ) { 1126 1199 $last_package_data = end(get_post_meta($post_id, PINGNEWS_PACKAGE_DATA)); 1200 1127 1201 if ( $last_package_data ) { 1128 1202 $last_package_json = json_decode($last_package_data); … … 1130 1204 list($package_data, $http_status) = pingnews_get_request(PINGNEWS_VMN_INGEST_URL . "/api/v1/package/", $last_package_json->package_token); 1131 1205 $package_json = json_decode($package_data); 1206 1132 1207 // Check whether data has changed since the last time the metadata was saved to WordPress 1133 1208 // Otherwise can duplicate data needlessly … … 1143 1218 wp_die(); 1144 1219 } 1220 1145 1221 /** 1146 1222 * Function to get the lists of possible taxonomies … … 1150 1226 function pingnews_get_taxonomies() { 1151 1227 list($taxonomies, $http_status) = pingnews_get_request(PINGNEWS_VMN_INGEST_URL . "/api/v1/taxonomies/", False); 1228 1152 1229 // Raise exception if failed to get taxonomies 1153 1230 if (!pingnews_is_http_status_valid($http_status) || !$taxonomies) { 1154 1231 throw new Exception("Unable to reach Ping! please refresh the page to try again or check your authorization token is correct."); 1155 1232 } 1233 1156 1234 return json_decode($taxonomies); 1157 1235 } 1236 1158 1237 /** 1159 1238 * Function to get the lists of current tags … … 1163 1242 function pingnews_get_existing_tags() { 1164 1243 list($tags, $http_status) = pingnews_get_request(PINGNEWS_VMN_CENTRAL_URL . "/api/v1/tags/", False); 1244 1165 1245 if (!$tags) { 1166 1246 $tags = False; 1167 1247 } 1248 1168 1249 return json_decode($tags); 1169 1250 } -
ping-news/trunk/readme.txt
r2321727 r2376518 3 3 Tags: Ping!, News, Ping News, ValueMyNews, Hyperlocal journalism, Journalism 4 4 Requires at least: 4.0 5 Stable tag: 1.0. 45 Stable tag: 1.0.5 6 6 Tested up to: 5.2.6 7 7 License: GPLv2 or later … … 19 19 20 20 == Changelog == 21 22 = 1.0.5 = 23 *Release Date - 7 September 2020* 24 25 * Fix minor bug where red cross isn't visible in selected tags list 21 26 22 27 = 1.0.4 = … … 53 58 * Fix bug causing undefined variable error to show in plugin 54 59 * Fix bug where stories could not be pushed to Ping! system in WordPress 5.3 55 * Provide feedback when user saves auth entication token by showing 'Saved!'60 * Provide feedback when user saves authorization token by showing 'Saved!' 56 61 57 62 = 0.1.5 =
Note: See TracChangeset
for help on using the changeset viewer.