Plugin Directory

Changeset 2376518


Ignore:
Timestamp:
09/07/2020 12:50:39 PM (5 years ago)
Author:
omnideveloper
Message:

Updated to version 1.0.5

Location:
ping-news/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ping-news/trunk/pingnews.php

    r2321727 r2376518  
    55/*
    66 Plugin Name: Ping News
    7  Description: The Ping! WordPress plugin allows hyperlocal journalists to submit their news stories to the Ping! system and recieve approval/feedback on their stories.
    8  Version: 1.0.4
     7 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
    99 License: GPLv2 or later
    1010 */
    1111
    12 define("PINGNEWS_PLUGIN_VERSION", "1.0.4");
     12define("PINGNEWS_PLUGIN_VERSION", "1.0.5");
    1313
    1414// Include all functions related to pushing packages to ingest
    1515include 'push.php';
    16 
    17 /**
    18  * Initialise the plugin
    19  *
    20  * @return void
    21  */
    22 function pingnews_initialise() {
    23     // initialise the plugin here
    24     // TODO remove this if it does not get used
    25 }
    26 
    27 register_activation_hook(__FILE__, "pingnews_initialise");
    2816
    2917add_action("init", "pingnews_pusher_role", 100);
  • ping-news/trunk/push.php

    r2321706 r2376518  
    11<?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
    210// Get vmn ingest url from environmental variable and if does not exist use default
    311$pingnews_vmn_ingest_url = getenv("VMN_INGEST_URL");
     
    513    $pingnews_vmn_ingest_url = "https://ingest.vmn.production.omni-digital.co.uk";
    614}
    7 // Get vmn ingest url from environmental variable and if does not exist use default
     15// Get vmn central url from environmental variable and if does not exist use default
    816$pingnews_vmn_central_url = getenv("VMN_CENTRAL_URL");
    917if (!$pingnews_vmn_central_url) {
    1018    $pingnews_vmn_central_url = "https://central.vmn.production.omni-digital.co.uk";
    1119}
    12 // This variable is used in push.php for JS error reporting
    13 define( "PINGNEWS_SENTRY_DSN", getenv("WP_SENTRY_DSN") );
     20// This variable is used in `push.php` for JS error reporting
     21define("PINGNEWS_SENTRY_DSN", getenv("WP_SENTRY_DSN"));
    1422define("PINGNEWS_VMN_INGEST_URL", $pingnews_vmn_ingest_url);
    1523define("PINGNEWS_VMN_CENTRAL_URL", $pingnews_vmn_central_url);
     
    2230// The interval for which package data from Ingest to polled (in milliseconds)
    2331define("PINGNEWS_POLL_INTERVAL", "5000");
    24 // constant for the key to store package token in a posts meta data
     32// Constant for the key to store package token in a posts meta data
    2533define("PINGNEWS_PACKAGE_DATA", "pingnews_package_data");
    26 // constant for taxonomy select tags
     34// Constant for taxonomy select tags
    2735define("PINGNEWS_LOCATION", "pingnews_location");
    2836define("PINGNEWS_STORY_FOCUS", "pingnews_story_focus");
    29 // constant for outer div around the package token html
     37// Constant for outer div around the package token html
    3038define("PINGNEWS_PACKAGE_DATA_OUTER", "pingnews_package_data_outer");
    31 // constants for spans to display package data
     39// Constants for spans to display package data
    3240define("PINGNEWS_PACKAGE_TOKEN", "pingnews_package_token");
    3341define("PINGNEWS_PACKAGE_DATE_CREATED", "pingnews_date_created");
     
    3644define("PINGNEWS_PACKAGE_FEEDBACK_OUTER", "pingnews_package_feedback_outer");
    3745define("PINGNEWS_PACKAGE_TAGS", "pingnews_package_tags");
    38 // constant for push to ping button anchor
     46// Constant for push to ping button anchor
    3947define("PINGNEWS_PUSH_TO_PING_ANCHOR", "pingnews_push_to_ping_anchor");
    40 // boolean for whether Trends features are applied
     48// Boolean for whether Trends features are applied
    4149// NOTE: We would usually set this from ansible but we do not have control of environmental
    4250// variables on external WordPress instances
    4351define("PINGNEWS_TRENDS_FEATURE_FLAG", true );
    4452define("PINGNEWS_EXISTING_TAGS", "pingnews_existing_tags");
     53
    4554/**
    4655 * Define a custom role for pushing to VMN
     
    5665        ]
    5766    );
    58     // add the capability to the administrator role as well
     67
     68    // Add the capability to the administrator role as well
    5969    $admin_role = get_role("administrator");
    6070    $admin_role->add_cap(PINGNEWS_PUSH_CAP, true);
    6171}
     72
    6273/**
    6374 * Function which returns whether the current user has the push to ping capability
     
    6677 */
    6778function 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
    7183/**
    7284 * Renders the HTML page for the Ping News push interface
     
    7890        return;
    7991    } ?>
     92
    8093    <style type="text/css">
    8194        .vmn_ping__ping_logo {
     
    187200            <script type="text/javascript">
    188201                document.getElementById("submit").addEventListener("click", function(){
    189                   document.getElementById("submit").value = "Saved!";
     202                    document.getElementById("submit").value = "Saved!";
    190203                });
    191204            </script>
     
    194207    <?php
    195208}
     209
     210/**
     211 * Saves `PINGNEWS_AUTH_TOKEN` to Ping News settings
     212 *
     213 * @return void
     214 */
    196215function 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
    199219/**
    200220 * Adds the menu button if the user has push capability
     
    211231    );
    212232}
     233
    213234/**
    214235 * The html to render in metabox and send AJAX request on clicking button
     
    219240    // Add thickbox for claiming access rights to photos
    220241    add_thickbox();
     242
    221243    $post_id = get_the_id();
    222244    $package_data = False;
     
    224246        $package_data = end(get_post_meta($post_id, PINGNEWS_PACKAGE_DATA));
    225247    }
    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
    227250    $display = "none";
    228251    $display_feedback = "none";
     
    235258        }
    236259    }
     260
    237261    try {
    238262        $taxonomies = pingnews_get_taxonomies();
     
    242266        return;
    243267    }
     268
    244269    if ( PINGNEWS_TRENDS_FEATURE_FLAG ) {
    245270        $existing_tags = pingnews_get_existing_tags();
    246271    }
    247     // Display package data if package already pushed to ingest
     272
    248273    ?>
    249274    <style type="text/css">
     
    377402        }
    378403        .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;
    385410        }
    386411        .vmn_ping__button.vmn_ping__button--reductive_action:active,
    387412        .vmn_ping__button.vmn_ping__button--reductive_action:focus,
    388413        .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;
    393418        }
    394419        #TB_ajaxContent p:first-of-type {
     
    396421        }
    397422        .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;
    407432        }
    408433        * + .chosen-container {
    409           margin-top: .8em;
     434            margin-top: .8em;
    410435        }
    411436        .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;
    423448        }
    424449        .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;
    428453        }
    429454        .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;
    435460        }
    436461        .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;
    447472        }
    448473        .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;
    450475        }
    451476        .chosen-container .chosen-results li.disabled-result {
    452           color: #cccace;
     477            color: #cccace;
    453478        }
    454479        .chosen-container .chosen-results li.no-results {
    455           color: #fc4046;
     480            color: #fc4046;
    456481        }
    457482        .chosen-container .chosen-results li.active-result {
    458           cursor: pointer;
     483            cursor: pointer;
    459484        }
    460485        .chosen-container .chosen-results li.disabled-result {
    461           cursor: default;
    462           color: #e5e4e7;
     486            cursor: default;
     487             color: #e5e4e7;
    463488        }
    464489        .chosen-container .chosen-results li.highlighted {
    465           background-color: #e9e0ff;
    466           color: #19191a;
     490            background-color: #e9e0ff;
     491            color: #19191a;
    467492        }
    468493        .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%;
    472497        }
    473498        .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;
    496521        }
    497522        .chosen-container-multi .chosen-choices li.search-field:not(:first-child),
    498523        .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;
    502527        }
    503528        .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;
    510535        }
    511536        .chosen-container-multi .chosen-choices li.search-field input {
    512           padding: 0;
     537            padding: 0;
    513538        }
    514539        .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;
    536561        }
    537562        .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;
    540565        }
    541566        .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;
    550575        }
    551576        .edit-post-sidebar input.chosen-search-input[type="text"] {
     
    555580        }
    556581        .chosen-container-multi .chosen-results {
    557           margin: 0;
    558           padding: 0;
     582            margin: 0;
     583            padding: 0;
    559584        }
    560585        .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;
    564589        }
    565590        .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;
    588613        }
    589614        .chosen-container:active,
     
    591616        .vmn_ping__form_component__select:hover,
    592617        .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;
    597622        }
    598623        .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;
    601626        }
    602627        .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;
    623648        }
    624649        .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;
    627652        }
    628653        .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;
    631656        }
    632657        .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;
    635660        }
    636661        .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;
    639664        }
    640665        .vmn_ping__form_options .vmn_ping__form_component .vmn_ping__form_component__text:active,
    641666        .vmn_ping__form_options .vmn_ping__form_component .vmn_ping__form_component__text:focus,
    642667        .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;
    647672        }
    648673        label + .vmn_ping__form_component__text,
    649674        * + .vmn_ping__form_component__help_text {
    650           margin-top: .8em;
     675            margin-top: .8em;
    651676        }
    652677        .vmn_ping__form_component__help_text {
    653           display: block;
     678            display: block;
    654679        }
    655680    </style>
     
    749774    class="vmn_ping__button thickbox"
    750775    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
    751777    <?php if ( PINGNEWS_SENTRY_DSN ) : ?>
    752778        <script src="https://browser.sentry-cdn.com/5.11.1/bundle.min.js" integrity="sha384-r7/ZcDRYpWjCNXLUKk3iuyyyEcDJ+o+3M5CqXP5GUGODYbolXewNHAZLYSJ3ZHcV" crossorigin="anonymous"></script>
    753779    <?php endif; ?>
     780
    754781    <?php if ( PINGNEWS_TRENDS_FEATURE_FLAG ) : ?>
    755782        <script src="https://cdn.jsdelivr.net/npm/[email protected]/chosen.jquery.min.js"></script>
    756783        <script>jQuery(".chosen-select").chosen({width: "100%"});</script>
    757784    <?php endif; ?>
     785
    758786    <script type="text/javascript">
    759787        <?php if ( PINGNEWS_SENTRY_DSN ) : ?>
     
    767795                document.getElementById("<?php echo PINGNEWS_PUSH_TO_PING_ANCHOR; ?>").innerHTML = "Push again!";
    768796            }
     797
    769798            feedback_outer_element = document.getElementById("<?php echo PINGNEWS_PACKAGE_FEEDBACK_OUTER; ?>");
    770799            if ( package_data["feedback"] ) {
     
    774803                feedback_outer_element.style.display = "none";
    775804            }
     805
    776806            if (<?php echo PINGNEWS_TRENDS_FEATURE_FLAG; ?>) {
    777807                tags_element = document.getElementById("<?php echo PINGNEWS_PACKAGE_TAGS; ?>")
     
    779809                if ( tags && update_tags) {
    780810                    let existing_tags_element = document.getElementById("<?php echo PINGNEWS_EXISTING_TAGS; ?>");
     811
    781812                    if (existing_tags_element) {
    782813                        tags = tags.split(", ");
    783814                        let existing_tags = [];
     815
    784816                        // Remove items from tags array if they appear in existing_tags array
    785817                        for (let i = 0; i < existing_tags_element.options.length; i++) {
     
    791823                            }
    792824                        }
     825
    793826                        // Populate contents of tags text area
    794827                        tags_element.value = tags.join(", ");
     
    812845                'nonce': '<?php echo wp_create_nonce('pingnews_post_package'); ?>',
    813846            };
     847
    814848            if (<?php echo PINGNEWS_TRENDS_FEATURE_FLAG; ?>) {
    815849                let existing_tags_element = document.getElementById("<?php echo PINGNEWS_EXISTING_TAGS; ?>");
     
    825859                }
    826860            }
     861
    827862            jQuery.ajax({
    828863                type: 'POST',
     
    835870                        package_data = response["package_data"];
    836871                        document.getElementById("<?php echo PINGNEWS_PACKAGE_DATA_OUTER; ?>").style.display = "inline";
     872
    837873                        if ( package_data["package_token"] ) {
    838874                            document.getElementById("<?php echo PINGNEWS_PACKAGE_TOKEN; ?>").innerHTML = package_data["package_token"];
    839875                        }
     876
    840877                        if ( package_data["date_created"] ) {
    841878                            document.getElementById("<?php echo PINGNEWS_PACKAGE_DATE_CREATED; ?>").innerHTML = package_data["date_created"];
    842879                        }
     880
    843881                        updateDynamicInfo(package_data, true);
    844882                    }
     
    848886            });
    849887        }
     888
    850889        function pollIngest(update_tags) {
    851890            jQuery.ajax({
     
    865904                }
    866905            });
     906
    867907            setTimeout(pollIngest.bind(null, false), <?php echo PINGNEWS_POLL_INTERVAL; ?>);
    868908        }
     909   
    869910        pollIngest(true);
    870911    </script>
    871912    <?php
    872913}
     914
    873915/**
    874916 * Function to echo option tags of the available taxonomy items
     
    879921    foreach ($taxonomy_list as $taxonomy_item) {
    880922        $selected = "";
    881         // Set the initially selected taxonomy  by adding `selected` to option tag
     923        // Set the initially selected taxonomy by adding `selected` to option tag
    882924        if ($taxonomy_item[0] == $selected_taxonomy) {
    883925            $selected = "selected";
     
    886928    }
    887929}
     930
    888931/**
    889932 * Function to echo option tags of the available taxonomy items
     
    893936function pingnews_get_tag_options($tag_list, $selected_tags_string) {
    894937    $selected_tags_list = explode(", ", $selected_tags_string);
     938
    895939    foreach ($tag_list as $key => $tag_item) {
    896940        $selected = "";
     
    902946    }
    903947}
     948
    904949/**
    905950 * The html to show when user has not entered authorization token in ping settings
     
    908953 */
    909954function 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
    914960/**
    915961 * The php to render the pingnews metabox
     
    919965function pingnews_metabox_php() {
    920966    $auth_token = get_option( PINGNEWS_AUTH_TOKEN );
     967
    921968    // Refer user to settings page if authorization token not set
    922969    if ( $auth_token ) {
     
    926973    }
    927974}
     975
    928976/**
    929977 * Function which adds a metabox to all screen types defined in  $screens
     
    934982    if ( pingnews_has_push_caps() ) {
    935983        $screens = ['post'];
     984
    936985        foreach ($screens as $screen) {
    937986            add_meta_box(
     
    945994    }
    946995}
     996
    947997/**
    948998 * Function to return an array of the categories associated with the post
     
    9511001 */
    9521002function 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
    9601013/**
    9611014 * Function to send a post request using WordPress HTTP API
     
    9641017 */
    9651018function 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
    9851041/**
    9861042 * Function to send a get request using WordPress HTTP API
     
    9891045 */
    9901046function 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
    10111072/**
    10121073 * Function to return which a http_status code is considered valid
     
    10151076 */
    10161077function pingnews_is_http_status_valid($http_status) {
    1017     // Check if http status code is succesful (2xx)
     1078    // Check if http status code is successful (2xx)
    10181079    return strval($http_status)[0] == '2';
    10191080}
     1081
    10201082/**
    10211083 * Function to return the most recently saved post information and send this to Ingest in a
     
    10261088function pingnews_post_package_ajax_handler() {
    10271089   $unsuccessful_message = "Unfortunately your push to ping was unsuccessful, please try again!";
     1090
    10281091   if ( pingnews_has_push_caps() &&
    10291092        isset($_POST["action"]) &&
     
    10361099     // verify there is a post with such a number
    10371100     $post = get_post((int)$post_id);
     1101
    10381102     if (empty($post)) {
    10391103         echo json_encode([
     
    10431107         wp_die();
    10441108     }
     1109
    10451110     global $wp_version;
    10461111     // Find all urls for oEmbeds and replace with generated iframe
     
    10481113     // Remove newlines otherwise regex does not match
    10491114     $striped_content = str_replace(array("\n", "\r"), '', $content);
    1050      // Find all occurances 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"
    10511116     preg_match_all('/<div class="wp-block-embed__wrapper">(.*?)<\/div>/', $striped_content, $matches);
     1117
    10521118     foreach ($matches[1] as $url) {
    10531119         // Generate oEmbed url
     
    10551121         $content = str_replace("\n".$url."\n", $iframe_embed, $content);
    10561122     }
     1123
    10571124     // Construct data to send in post request to ingest
    10581125     $post_data = [
     
    10751142         "tags" => sanitize_text_field($_POST["tags"]),
    10761143     ];
     1144
    10771145     $post_json = json_encode($post_data);
    10781146     list($package_data, $http_status) = pingnews_post_request(PINGNEWS_VMN_INGEST_URL . "/api/v1/package/", $post_json);
     1147
    10791148     if (pingnews_is_http_status_valid($http_status) && $package_data) {
    1080          // When posting new story feedback can be cleared if recieved for a previous version of the post
     1149         // When posting new story feedback can be cleared if received for a previous version of the post
    10811150         $package_data["feedback"] = "";
    10821151         add_post_meta($post_id, PINGNEWS_PACKAGE_DATA, $package_data);
    10831152         $message = "You have successfully pushed to Ping!";
    10841153         $package_json = json_decode($package_data);
     1154
    10851155         // Convert date times to UTC and r format
    10861156         $date_provider_published = new DateTime($package_json->package_data->date_provider_published, new DateTimeZone("UTC"));
     
    10971167         $package_json = False;
    10981168     }
     1169
    10991170     echo json_encode([
    11001171         "message" => $message,
    11011172         "package_data" => $package_json
    11021173     ]);
     1174
    11031175     wp_die();
    11041176   }
     
    11091181   wp_die();
    11101182}
     1183
    11111184/**
    11121185 * Function to get most recent version of the last sent package to Ingest, to be able to e.g.
     
    11251198     if ( $post_id ) {
    11261199         $last_package_data = end(get_post_meta($post_id, PINGNEWS_PACKAGE_DATA));
     1200
    11271201         if ( $last_package_data ) {
    11281202             $last_package_json = json_decode($last_package_data);
     
    11301204             list($package_data, $http_status) = pingnews_get_request(PINGNEWS_VMN_INGEST_URL . "/api/v1/package/", $last_package_json->package_token);
    11311205             $package_json = json_decode($package_data);
     1206
    11321207             // Check whether data has changed since the last time the metadata was saved to WordPress
    11331208             // Otherwise can duplicate data needlessly
     
    11431218   wp_die();
    11441219}
     1220
    11451221/**
    11461222 * Function to get the lists of possible taxonomies
     
    11501226function pingnews_get_taxonomies() {
    11511227   list($taxonomies, $http_status) = pingnews_get_request(PINGNEWS_VMN_INGEST_URL . "/api/v1/taxonomies/", False);
     1228
    11521229   // Raise exception if failed to get taxonomies
    11531230   if (!pingnews_is_http_status_valid($http_status) || !$taxonomies) {
    11541231       throw new Exception("Unable to reach Ping! please refresh the page to try again or check your authorization token is correct.");
    11551232   }
     1233
    11561234   return json_decode($taxonomies);
    11571235}
     1236
    11581237/**
    11591238 * Function to get the lists of current tags
     
    11631242function pingnews_get_existing_tags() {
    11641243   list($tags, $http_status) = pingnews_get_request(PINGNEWS_VMN_CENTRAL_URL . "/api/v1/tags/", False);
     1244
    11651245   if (!$tags) {
    11661246       $tags = False;
    11671247   }
     1248
    11681249   return json_decode($tags);
    11691250}
  • ping-news/trunk/readme.txt

    r2321727 r2376518  
    33Tags: Ping!, News, Ping News, ValueMyNews, Hyperlocal journalism, Journalism
    44Requires at least: 4.0
    5 Stable tag: 1.0.4
     5Stable tag: 1.0.5
    66Tested up to: 5.2.6
    77License: GPLv2 or later
     
    1919
    2020== 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
    2126
    2227= 1.0.4 =
     
    5358* Fix bug causing undefined variable error to show in plugin
    5459* Fix bug where stories could not be pushed to Ping! system in WordPress 5.3
    55 * Provide feedback when user saves authentication token by showing 'Saved!'
     60* Provide feedback when user saves authorization token by showing 'Saved!'
    5661
    5762= 0.1.5 =
Note: See TracChangeset for help on using the changeset viewer.