81 | );
82 | };
83 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## Security
4 |
5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
6 |
7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below.
8 |
9 | ## Reporting Security Issues
10 |
11 | **Please do not report security vulnerabilities through public GitHub issues.**
12 |
13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
14 |
15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
16 |
17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
18 |
19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20 |
21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22 | * Full paths of source file(s) related to the manifestation of the issue
23 | * The location of the affected source code (tag/branch/commit or direct URL)
24 | * Any special configuration required to reproduce the issue
25 | * Step-by-step instructions to reproduce the issue
26 | * Proof-of-concept or exploit code (if possible)
27 | * Impact of the issue, including how an attacker might exploit the issue
28 |
29 | This information will help us triage your report more quickly.
30 |
31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs.
32 |
33 | ## Preferred Languages
34 |
35 | We prefer all communications to be in English.
36 |
37 | ## Policy
38 |
39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).
40 |
41 |
--------------------------------------------------------------------------------
/src/components/StartPage.tsx:
--------------------------------------------------------------------------------
1 | import "../scss/StartPage.scss";
2 |
3 | import * as React from "react";
4 | import { useState } from "react";
5 | import { PrimaryButton } from "@fluentui/react/lib/Button";
6 | import { Icon } from "@fluentui/react/lib/Icon";
7 | import { TextField } from "@fluentui/react/lib/TextField";
8 | import { SetApiKey } from "./withDashboardData";
9 | import { ApiKeyRegex, StringConstants } from "../Constants";
10 |
11 | interface IStartPage {
12 | addBanner: (str: string) => void;
13 | setAPIKeyAdded: () => void;
14 | }
15 |
16 | export const StartPage: React.FunctionComponent = (props) => {
17 | const [apiKey, setApiKey] = useState("");
18 |
19 | const onSubmitApiKey = (): void => {
20 | Promise.resolve(SetApiKey(apiKey)).then((response) => {
21 | if (response?.data?.error_type.length === 0) {
22 | props.setAPIKeyAdded();
23 | } else {
24 | props.addBanner(`Adding API key failed: ${response.data?.error_type}`);
25 | }
26 | });
27 | };
28 |
29 | return (
30 |
31 |
32 |
What you can do with this plugin
33 |
34 |
35 |
36 |
37 |
Automate URL submissions
38 |
39 |
40 |
41 |
Manual URL submissions
42 |
43 |
44 |
45 |
View stats of submitted URLs
46 |
47 |
48 |
49 |
View recent submissions
50 |
51 |
52 |
53 |
Re-submit recent submissions
54 |
55 |
56 |
57 |
58 |
59 |
60 |
Add API Key To Get Started
61 |
62 | Add valid API key and automate URL submission by clicking on Start
63 | using this plugin. You can disable auto submission later from plugin
64 | if needed.
65 |
79 |
80 | >
81 | );
82 | };
83 |
--------------------------------------------------------------------------------
/src/scss/_variables.scss:
--------------------------------------------------------------------------------
1 | // Variables
2 | //
3 | // Variables should follow the `$shortansname-propertynameincamelcase` formula for
4 | // consistent naming. Ex: $bingtravel-linkDisabledColor and $bwt_contentBoxShadow.
5 |
6 | //
7 | // Color system
8 | //
9 |
10 | // Primary Colors
11 | $bwt_white: #ffffff;
12 | $bwt_primaryTealColor: #00809d;
13 | $bwt_darkTealColor: #006887;
14 |
15 | // Secondary Color
16 | $bwt_headerAccentColor: #0046ff;
17 | $bwt_attributionColor: #006d21;
18 | $bwt_warningColor: #be5a00;
19 | $bwt_errorColor: #c80000;
20 | $bwt_pendingColor: #797673;
21 | $bwt_successColor: #006d21;
22 |
23 | // Text colors
24 | $bwt_primaryTextColor: #444444;
25 | $bwt_standardTextColor: #666666;
26 | $bwt_secondaryTextColor: #767676;
27 | $bwt_optionalTextColor: #919191;
28 | $bwt_linkTextColor: #0078d7;
29 | $bwt_harmfulLinkIconColor: #e06f6a;
30 |
31 | // Gray Colors
32 | $bwt_lightGray10Color: #f7f9f8;
33 | $bwt_lightGray15Color: #f8f8f8;
34 | $bwt_lightGray20Color: #f9f9f9;
35 | $bwt_lightGray30Color: #f5f5f5;
36 | $bwt_lightGray40Color: #f3f3f3;
37 | $bwt_lightGray50Color: #ececec;
38 | $bwt_lightGray60Color: #dddddd;
39 | $bwt_lightGray70Color: #cccccc;
40 | $bwt_darkGray10Color: #919191;
41 | $bwt_darkGray20Color: #767676;
42 | $bwt_darkGray30Color: #666666;
43 | $bwt_darkGray40Color: #444444;
44 | $bwt_darkGray50Color: #111111;
45 | $bwt_whiteGrayBlack: #e1e1e1;
46 | $bwt_veryDarkGrayColor: #212121;
47 | $bwt_darkCyanColor: #0c8484;
48 | $bwt_veryDarkCyanColor: #0c6e6e;
49 | $bwt_buttonActiveColor: #0b5858;
50 | $bwt_filterBorderColor: #a19f9d;
51 | $bwt_paginationButtonColor: #eaeaea;
52 | $bwt_paginationButtonDisabledColor: #f4f4f4;
53 | $bwt_buttonHoverColor: #027c91;
54 | $bwt_cardTextColor: #333333;
55 | $bwt_textFiledBorderColor: #a19f9d;
56 | $bwt_buttonClassicPortalLinkBackgroundColor: #fff5d5;
57 | $bwt_buttonClassicPortalLinkBorderColor: #ba7b17;
58 |
59 | $bwt_headerLinkTextColor: #0078d4;
60 | $bwt_headerTitleSupTextBackGroundColor: #00b7c8;
61 | $bwt_headerElementsHoverBackGroundColor: #00748e;
62 | $bwt_filterButtonsHoverBackGroundColor: #edebe9;
63 | $bwt_attributionHoverBackGroundColor: #00631e;
64 | $bwt_errorHoverBackGroundColor: #b30000;
65 | $bwt_filterButtonHoverColor: #605e5c;
66 | $bwt_navHoverColor: rgba(0, 128, 150, 0.1);
67 | $bwt_navHoverAfterColor: rgba(0, 128, 150, 0.01);
68 | $bwt_navButtonHoverBackground: #f3f2f1;
69 | $bwt_rowHoverColor: rgb(243, 242, 241);
70 |
71 | // Font faces
72 | $bwt_scopeFontFamily: "Segoe UI", Arial, Helvetica, Sans-Serif;
73 | $bwt_semiboldFontFamily: "Segoe UI Semibold", "Segoe UI", Arial, Helvetica,
74 | Sans-Serif;
75 | $bwt_bodyFontFamily: Arial, Helvetica, Sans-Serif;
76 |
77 | // Font sizes
78 | $bwt_focusTitleMFontSize: 44px;
79 | $bwt_titleFontSize: 24px;
80 | $bwt_focusFontSize: 20px;
81 | $bwt_mediumFontSize: 16px;
82 | $bwt_standardFontSize: 14px;
83 | $bwt_secondaryFontSize: 12px;
84 |
85 | // Width
86 | $bwt_pageMinWidth: 1266px;
87 | $bwt_pageContentWidth: 960px;
88 |
89 | // Heights
90 | $bwt_topHeaderHeight: 54px;
91 |
92 | // Borders
93 | $bwt_lightGrayBorder: 1px solid $bwt_lightGray60Color;
94 | $bwt_whiteBorder: 1px solid $bwt_white;
95 | $bwt_filterBoxBorder: 1px solid $bwt_filterBorderColor;
96 | $bwt_transparentBorder: 1px solid transparent;
97 | $bwt_pageHeaderBorder: 1px solid $bwt_whiteGrayBlack;
98 | $bwt_pageTitleBorder: 1px solid $bwt_lightGray70Color;
99 | $bwt_filterButtonHoverBorder: 1px solid $bwt_filterButtonHoverColor;
100 |
101 | // Shadows
102 | $bwt_cardShadow: 0 0 0 1px rgba(0, 0, 0, 0.05), 0 2px 3px 0 rgba(0, 0, 0, 0.1);
103 | $bwt_hoverShadow: 0 0 0 1px rgba(0, 0, 0, 0.05), 0 2px 4px 0 rgba(0, 0, 0, 0.14);
104 | $bwt_btnhoverShadow: 0 1px 2px 0 rgba(0, 0, 0, 0.1);
105 | $bwt_messageCardShadow: rgba(0, 0, 0, 0.133) 0px 1.6px 3.6px 0px,
106 | rgba(0, 0, 0, 0.11) 0px 0.3px 0.9px 0px;
107 | $bwt_messageCardHoverShadow: rgba(0, 0, 0, 0.133) 0px 3.2px 7.2px 0px,
108 | rgba(0, 0, 0, 0.11) 0px 0.6px 1.8px 0px;
109 |
110 | // Transitions
111 | $bwt_shadowTransition: box-shadow 0.1s ease-in-out;
112 | $bwt_cardExpandTransition: all 0.3s ease-in-out;
113 |
114 | // Icon sizes
115 | $bwt_smallIconSize: 16px;
116 | $bwt_mediumIconSize: 20px;
117 | $bwt_largeIconSize: 24px;
118 | $bwt_xlargeIconSize: 32px;
119 |
--------------------------------------------------------------------------------
/src/components/withDashboardData.tsx:
--------------------------------------------------------------------------------
1 | import { IHttpResponse, useFetch, useSubmit } from "./APIHelper";
2 | import {
3 | ISetApiKeyRequest,
4 | IGetApiSettingsResponse,
5 | IGetStatsResponse,
6 | IGetAllSubmissionsResponse,
7 | ISubmitUrlResponse,
8 | ISubmitUrlRequest,
9 | IGetApiKeyResponse,
10 | ISetApiKeyResponse,
11 | IRetryFailedSubmissionsResponse,
12 | IRetryFailedSubmissionsRequest,
13 | ISetAutoSubmissionEnabledResponse,
14 | ISetAutoSubmissionEnabledRequest,
15 | ICheckApiKeyValidityResponse,
16 | UrlSubmission,
17 | } from "./Interfaces";
18 |
19 | export async function GetApiKey() {
20 | let response: IHttpResponse;
21 | const url = `apiKey`;
22 | response = await useFetch(url).catch((err) => {
23 | console.error("Error while fetching API key.");
24 | return err;
25 | });
26 | return response;
27 | }
28 |
29 | export async function SetApiKey(apiKey: string) {
30 | let response: IHttpResponse;
31 | const url = `apiKey`;
32 | const apiContent: ISetApiKeyRequest = {
33 | APIKey: apiKey,
34 | };
35 | response = await useSubmit(url, apiContent).catch(
36 | (err) => {
37 | console.error("Error while updating API key.");
38 | return err;
39 | }
40 | );
41 | return response;
42 | }
43 |
44 | export async function CheckApiKeyValidity() {
45 | let response: IHttpResponse;
46 | const url = `apiKeyValidity`;
47 | response = await useFetch(url).catch((err) => {
48 | console.error("Error while checking API key validity.");
49 | return err;
50 | });
51 | return response;
52 | }
53 |
54 | export async function GetApiSettings() {
55 | let response: IHttpResponse;
56 | const url = `apiSettings`;
57 | response = await useFetch(url).catch((err) => {
58 | console.error("Error while fetching plugin settings.");
59 | return err;
60 | });
61 | return response;
62 | }
63 |
64 | export async function GetStats() {
65 | let response: IHttpResponse;
66 | const url = `getStats`;
67 | response = await useFetch(url).catch((err) => {
68 | console.error("Error while fetching submission statistics.");
69 | return err;
70 | });
71 | return response;
72 | }
73 |
74 | export async function GetAllSubmissions() {
75 | let response: IHttpResponse;
76 | const url = `allSubmissions`;
77 | response = await useFetch(url).catch((err) => {
78 | console.error("Error while fetching submitted URLs list.");
79 | return err;
80 | });
81 | return response;
82 | }
83 |
84 | export async function RetryFailedSubmissions(
85 | failedSubmissions: UrlSubmission[]
86 | ) {
87 | const param: IRetryFailedSubmissionsRequest = {
88 | Submissions: failedSubmissions,
89 | };
90 | let response: IHttpResponse;
91 | const url = `allSubmissions`;
92 | response = await useSubmit(url, param).catch(
93 | (err) => {
94 | console.error("Error while retrying failed submissions.");
95 | return err;
96 | }
97 | );
98 | return response;
99 | }
100 |
101 | export async function UpdateAutoSubmissionsEnabled(isEnabled: boolean) {
102 | const param: ISetAutoSubmissionEnabledRequest = {
103 | AutoSubmissionEnabled: isEnabled,
104 | };
105 | let response: IHttpResponse;
106 | const url = `automaticSubmission`;
107 | response = await useSubmit(
108 | url,
109 | param
110 | ).catch((err) => {
111 | console.error("Error while updating automatic submission settings.");
112 | return err;
113 | });
114 | return response;
115 | }
116 |
117 | export async function SubmitUrl(url: string) {
118 | let response: IHttpResponse;
119 | const ep = `submitUrl`;
120 | const apiContent: ISubmitUrlRequest = {
121 | url: url,
122 | };
123 | response = await useSubmit(ep, apiContent).catch(
124 | (err) => {
125 | console.error("Error while submitting URL.");
126 | return err;
127 | }
128 | );
129 | return response;
130 | }
131 |
--------------------------------------------------------------------------------
/public/admin/utils/class-bing-url-submission-admin-utils.php:
--------------------------------------------------------------------------------
1 |
10 | */
11 | class Bing_Webmaster_Admin_Utils {
12 | /**
13 | * This function finds out the ocunt of submissions in last 48 hours.
14 | */
15 | public static function get_count( SubmissionCount $submission_count ) {
16 | $curr_time = time();
17 | self::set_last_date( $submission_count, $curr_time );
18 | $count = 0;
19 | for ( $i = 0; $i < 48; $i++ ) {
20 | $count += $submission_count->hourly_count[ $i ];
21 | }
22 | return $count;
23 | }
24 |
25 | /**
26 | * Increase the count by 1.
27 | */
28 | public static function increase_count( SubmissionCount $submission_count ) {
29 | $curr_time = time();
30 | self::set_last_date( $submission_count, $curr_time );
31 | $submission_count->hourly_count[ $submission_count->index ]++;
32 | }
33 |
34 | /**
35 | * Set the last date when count was accessed/increased.
36 | * We store the count in array of size 48, count per hour so that we don't need to store every submission.
37 | */
38 | private static function set_last_date( SubmissionCount $submission_count, $curr_time ) {
39 | $curr_hour = (int) ( $curr_time / 3600 );
40 | $last_hour = (int) ( $submission_count->last_count_date / 3600 );
41 | if ( $curr_hour - $last_hour <= 48 ) {
42 | $i = 0;
43 | for ( $i = ( $submission_count->index + 1 ) % 48; $last_hour < $curr_hour; $i = ( $i + 1 ) % 48, $last_hour++ ) {
44 | $submission_count->hourly_count[ $i ] = 0;
45 | }
46 | $submission_count->index = ( $i + 47 ) % 48;
47 | } else {
48 | for ( $i = 0; $i < 48; $i++ ) {
49 | $submission_count->hourly_count[ $i ] = 0;
50 | }
51 | $submission_count->index = $curr_hour % 24;
52 | }
53 | $submission_count->last_count_date = $curr_time;
54 | }
55 |
56 | /**
57 | * This function retrieves the latest submitted urls upto 20.
58 | * It deletes the older submitted urls from the table.
59 | */
60 | public static function get_submissions( $table ) {
61 | global $wpdb;
62 | $table_name = $wpdb->prefix . $table;
63 | $date = time() - 48 * 60 * 60;
64 | $results = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $table_name . ' WHERE submission_date > %d ORDER BY submission_date DESC LIMIT 21', $date ), OBJECT );
65 | if ( is_array( $results ) && count( $results ) === 21 ) {
66 | $ids = array();
67 | $results = array_slice( $results, 0, 20 );
68 | foreach ( $results as $result ) {
69 | array_push( $ids, $result->id );
70 | }
71 | $res = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $table_name . ' WHERE id not in ( %s )', implode( ',', $ids ) ) );
72 | }
73 | return $results;
74 | }
75 |
76 | public static function url_submitted_within_last_minute( $table, $url ) {
77 | global $wpdb;
78 | $table_name = $wpdb->prefix . $table;
79 | $date = time() - 60;
80 | $results = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $table_name . ' WHERE submission_date > %d AND url = %s LIMIT 1', array( $date, $url ) ), OBJECT );
81 | return is_array( $results ) && count( $results ) > 0;
82 | }
83 |
84 | public static function insert_submission( $table, Submissions $submission ) {
85 | global $wpdb;
86 | $table_name = $wpdb->prefix . $table;
87 | $results = $wpdb->insert(
88 | $table_name,
89 | array(
90 | 'url' => $submission->url,
91 | 'submission_type' => $submission->submission_type,
92 | 'submission_date' => $submission->submission_date,
93 | 'error' => $submission->error,
94 | 'type' => $submission->type,
95 | )
96 | );
97 | }
98 |
99 | public static function delete_submissions( $table ) {
100 | global $wpdb;
101 | $table_name = $wpdb->prefix . $table;
102 | //phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
103 | $results = $wpdb->query( 'DELETE FROM ' . $table_name );
104 | return $results;
105 | //phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
106 | }
107 |
108 | public static function is_localhost( $ip = array( '127.0.0.1', '::1' ) ) {
109 | return in_array( $_SERVER['REMOTE_ADDR'], $ip );
110 | }
111 | }
112 |
113 | class SubmissionCount {
114 |
115 | public function __construct() {
116 |
117 | $this->hourly_count = array();
118 | for ( $i = 0; $i < 48; $i++ ) {
119 | array_push( $this->hourly_count, 0 );
120 | }
121 | $this->last_count_date = time();
122 |
123 | }
124 |
125 | public $hourly_count;
126 | public $last_count_date;
127 | public $index;
128 | }
129 |
--------------------------------------------------------------------------------
/src/components/APIHelper.tsx:
--------------------------------------------------------------------------------
1 | import { ErrorConstants } from "./ErrorConstants";
2 |
3 | declare global {
4 | interface Window { wpr_object: any; }
5 | }
6 |
7 | const baseURL = `${window['wpr_object']['api_url']}`;
8 |
9 | export interface IHttpResponse extends Response {
10 | data?: T;
11 | error?: IAPIError;
12 | }
13 |
14 | export interface IAPIError {
15 | code: string;
16 | message: string;
17 | details?: IAPIErrorDetails[];
18 | }
19 |
20 | export interface IAPIErrorDetails {
21 | target: string;
22 | message: string;
23 | }
24 |
25 | const nonceHeader = {
26 | headers: {
27 | "X-WP-Nonce": `${window['wpr_object']['api_nonce']}`
28 | }
29 | };
30 |
31 | export async function useFetch(
32 | requestUrl: RequestInfo
33 | ): Promise> {
34 | return withTimeout(
35 | new Promise((resolve, reject) => {
36 | let response: IHttpResponse;
37 | fetch(`${baseURL}${requestUrl}`, nonceHeader)
38 | .then(res => {
39 | response = res;
40 | return res.json();
41 | })
42 | .then(body => {
43 | if (response.ok) {
44 | response.data = body;
45 | } else {
46 | response.error = body;
47 | }
48 | resolve(response);
49 | })
50 | .catch(err => {
51 | reject(err);
52 | });
53 | })
54 | );
55 | }
56 |
57 | export async function useSubmit(
58 | requestUrl: RequestInfo,
59 | requestData: any
60 | ): Promise> {
61 | return withTimeout(
62 | new Promise((resolve, reject) => {
63 | let response: IHttpResponse;
64 | fetch(`${baseURL}${requestUrl}`, {
65 | method: "POST",
66 | headers: {
67 | ...(nonceHeader.headers),
68 | "Accept": "application/json, text/javascript, */*; q=0.01",
69 | "Content-Type": "application/json;charset=UTF-8"
70 | },
71 | body: JSON.stringify(requestData)
72 | })
73 | .then(res => {
74 | response = res;
75 | return res.json();
76 | })
77 | .then(body => {
78 | if (response.ok) {
79 | response.data = body;
80 | } else {
81 | response.error = body;
82 | }
83 | resolve(response);
84 | })
85 | .catch(err => {
86 | reject(err);
87 | });
88 | })
89 | );
90 | }
91 |
92 | export function withTimeout(
93 | promise: Promise>,
94 | timeout = 60000
95 | ) {
96 | let timer: ReturnType;
97 | return Promise.race>([
98 | promise,
99 | new Promise>((resolve, _) => {
100 | let response: IHttpResponse;
101 | const timeoutInit: ResponseInit = {
102 | status: ErrorConstants.RequestTimedOut.HttpStatusCode
103 | };
104 | response = new Response(null, timeoutInit);
105 | timer = setTimeout(() => {
106 | response.error = {
107 | code: ErrorConstants.RequestTimedOut.Code,
108 | message: ErrorConstants.RequestTimedOut.Message
109 | };
110 | resolve(response);
111 | }, timeout);
112 | })
113 | ]).then(result => {
114 | clearTimeout(timer);
115 | return result;
116 | });
117 | }
118 |
119 | export async function useDownload(
120 | requestUrl: RequestInfo,
121 | requestData: any,
122 | callback?: () => void
123 | ): Promise> {
124 | return new Promise((resolve, reject) => {
125 | let response: any;
126 | fetch(`${baseURL}${requestUrl}`, {
127 | method: "POST",
128 | headers: {
129 | ...(nonceHeader.headers),
130 | "Accept": "application/json, text/javascript, */*; q=0.01",
131 | "Content-Type": "application/json;charset=UTF-8"
132 | },
133 | body: JSON.stringify(requestData)
134 | })
135 | .then(res => {
136 | response = res;
137 | return res.blob();
138 | })
139 | .then(blob => {
140 | const url: string = window.URL.createObjectURL(blob);
141 | const a: HTMLAnchorElement = document.createElement("a");
142 | a.href = url;
143 | a.download = response.headers
144 | .get("content-disposition")
145 | .split("filename=")[1];
146 | document.body.appendChild(a); // we need to append the element to the dom -> otherwise it will not work in firefox
147 | a.click();
148 | resolve(response);
149 | setTimeout(() => {
150 | a.remove(); // afterwards we remove the element again
151 | }, 100);
152 | if (callback) {
153 | callback();
154 | }
155 | })
156 | .catch(err => {
157 | reject(err);
158 | });
159 | });
160 | }
161 |
--------------------------------------------------------------------------------
/public/includes/class-bing-url-submission-loader.php:
--------------------------------------------------------------------------------
1 |
13 | */
14 | class Bing_Webmaster_Loader {
15 |
16 | /**
17 | * The array of actions registered with WordPress.
18 | *
19 | * @since 0.01.01
20 | * @access protected
21 | * @var array $actions The actions registered with WordPress to fire when the plugin loads.
22 | */
23 | protected $actions;
24 |
25 | /**
26 | * The array of filters registered with WordPress.
27 | *
28 | * @since 0.01.01
29 | * @access protected
30 | * @var array $filters The filters registered with WordPress to fire when the plugin loads.
31 | */
32 | protected $filters;
33 |
34 | /**
35 | * Initialize the collections used to maintain the actions and filters.
36 | *
37 | * @since 0.01.01
38 | */
39 | public function __construct() {
40 |
41 | $this->actions = array();
42 | $this->filters = array();
43 |
44 | }
45 |
46 | /**
47 | * Add a new action to the collection to be registered with WordPress.
48 | *
49 | * @since 0.01.01
50 | * @param string $hook The name of the WordPress action that is being registered.
51 | * @param object $component A reference to the instance of the object on which the action is defined.
52 | * @param string $callback The name of the function definition on the $component.
53 | * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
54 | * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
55 | */
56 | public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
57 | $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
58 | }
59 |
60 | /**
61 | * Add a new filter to the collection to be registered with WordPress.
62 | *
63 | * @since 0.01.01
64 | * @param string $hook The name of the WordPress filter that is being registered.
65 | * @param object $component A reference to the instance of the object on which the filter is defined.
66 | * @param string $callback The name of the function definition on the $component.
67 | * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
68 | * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
69 | */
70 | public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
71 | $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
72 | }
73 |
74 | /**
75 | * A utility function that is used to register the actions and hooks into a single
76 | * collection.
77 | *
78 | * @since 0.01.01
79 | * @access private
80 | * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
81 | * @param string $hook The name of the WordPress filter that is being registered.
82 | * @param object $component A reference to the instance of the object on which the filter is defined.
83 | * @param string $callback The name of the function definition on the $component.
84 | * @param int $priority The priority at which the function should be fired.
85 | * @param int $accepted_args The number of arguments that should be passed to the $callback.
86 | * @return array The collection of actions and filters registered with WordPress.
87 | */
88 | private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
89 |
90 | $hooks[] = array(
91 | 'hook' => $hook,
92 | 'component' => $component,
93 | 'callback' => $callback,
94 | 'priority' => $priority,
95 | 'accepted_args' => $accepted_args
96 | );
97 |
98 | return $hooks;
99 |
100 | }
101 |
102 | /**
103 | * Register the filters and actions with WordPress.
104 | *
105 | * @since 0.01.01
106 | */
107 | public function run() {
108 |
109 | foreach ( $this->filters as $hook ) {
110 | add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
111 | }
112 |
113 | foreach ( $this->actions as $hook ) {
114 | add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
115 | }
116 |
117 | }
118 |
119 | }
120 |
--------------------------------------------------------------------------------
/public/includes/class-bing-url-submission.php:
--------------------------------------------------------------------------------
1 |
15 | */
16 | class Bing_Webmaster {
17 |
18 | /**
19 | * The loader that's responsible for maintaining and registering all hooks that power
20 | * the plugin.
21 | *
22 | * @since 0.01.01
23 | * @access protected
24 | * @var Bing_Webmaster_Loader $loader Maintains and registers all hooks for the plugin.
25 | */
26 | protected $loader;
27 |
28 | /**
29 | * The unique identifier of this plugin.
30 | *
31 | * @since 0.01.01
32 | * @access protected
33 | * @var string $plugin_name The string used to uniquely identify this plugin.
34 | */
35 | protected $plugin_name;
36 |
37 | /**
38 | * The current version of the plugin.
39 | *
40 | * @since 0.01.01
41 | * @access protected
42 | * @var string $version The current version of the plugin.
43 | */
44 | protected $version;
45 |
46 | /**
47 | * Define the core functionality of the plugin.
48 | *
49 | * Set the plugin name and the plugin version that can be used throughout the plugin.
50 | * Load the dependencies and set the hooks for the admin area.
51 | *
52 | * @since 0.01.01
53 | */
54 | public function __construct($plugin_name) {
55 | if ( defined( 'BWT_URL_SUBMISSION_PLUGIN_VERSION' ) ) {
56 | $this->version = BWT_URL_SUBMISSION_PLUGIN_VERSION;
57 | } else {
58 | $this->version = '1.0.13';
59 | }
60 | $this->plugin_name = $plugin_name;
61 |
62 | $this->load_dependencies();
63 | $this->define_admin_hooks();
64 |
65 | }
66 |
67 | /**
68 | * Load the required dependencies for this plugin.
69 | *
70 | * Include the following files that make up the plugin:
71 | *
72 | * - Bing_Webmaster_Loader. Orchestrates the hooks of the plugin.
73 | * - Bing_Webmaster_Admin. Defines all hooks for the admin area.
74 | *
75 | * Create an instance of the loader which will be used to register the hooks
76 | * with WordPress.
77 | *
78 | * @since 0.01.01
79 | * @access private
80 | */
81 | private function load_dependencies() {
82 |
83 | /**
84 | * The class responsible for orchestrating the actions and filters of the
85 | * core plugin.
86 | */
87 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-bing-url-submission-loader.php';
88 |
89 | /**
90 | * The class responsible for defining all actions that occur in the admin area.
91 | */
92 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-bing-url-submission-admin.php';
93 |
94 | $this->loader = new Bing_Webmaster_Loader();
95 |
96 | }
97 |
98 | /**
99 | * Register all of the hooks related to the admin area functionality
100 | * of the plugin.
101 | *
102 | * @since 0.01.01
103 | * @access private
104 | */
105 | private function define_admin_hooks() {
106 |
107 | $plugin_admin = new Bing_Webmaster_Admin( $this->get_plugin_name(), $this->get_version() );
108 |
109 | $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
110 | $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
111 |
112 | // Save/Update our plugin options.
113 | $this->loader->add_action( 'admin_init', $plugin_admin, 'options_update');
114 |
115 | $this->loader->add_action( 'rest_api_init', $plugin_admin, 'register_routes');
116 |
117 | // Add a new admin menu.
118 | $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_admin_menu' );
119 |
120 | // Add Settings link to the plugin.
121 | $plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . '.php' );
122 | $this->loader->add_filter( 'plugin_action_links_' . $plugin_basename, $plugin_admin, 'add_action_links' );
123 |
124 | // Add url submit action & post publishing.
125 | $this->loader->add_action( 'transition_post_status', $plugin_admin, 'on_post_published', 10, 3 );
126 | }
127 |
128 | /**
129 | * Run the loader to execute all of the hooks with WordPress.
130 | *
131 | * @since 0.01.01
132 | */
133 | public function run() {
134 | $this->loader->run();
135 | }
136 |
137 | /**
138 | * The name of the plugin used to uniquely identify it within the context of
139 | * WordPress and to define internationalization functionality.
140 | *
141 | * @since 1.0.0
142 | * @return string The name of the plugin.
143 | */
144 | public function get_plugin_name() {
145 | return $this->plugin_name;
146 | }
147 |
148 | /**
149 | * The reference to the class that orchestrates the hooks with the plugin.
150 | *
151 | * @since 1.0.0
152 | * @return Bing_Webmaster_Loader Orchestrates the hooks of the plugin.
153 | */
154 | public function get_loader() {
155 | return $this->loader;
156 | }
157 |
158 | /**
159 | * Retrieve the version number of the plugin.
160 | *
161 | * @since 1.0.0
162 | * @return string The version number of the plugin.
163 | */
164 | public function get_version() {
165 | return $this->version;
166 | }
167 |
168 | }
169 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Bing URL Submissions Plugin
2 |
3 | Bing URL Submission Plugin for WordPress enables WordPress site owners to instantly and automatically submit their new and updated pages to the Bing index. Once setup, the plugin detects any page creation or update in WordPress and automatically submits the URL behind the scenes ensuring that the site content is always fresh in Bing index.
4 |
5 | Some other handy features included in the plugin:
6 |
7 | - Toggle automatic submission feature on or off.
8 | - Manually submit a site URL to Bing Index.
9 | - View list of recent URLs submitted by the plugin.
10 | - Retry any failed submissions from recent submission history.
11 | - Download recent submissions list.
12 |
13 | This plugin was developed with love and coffee by the Bing Webmaster team.
14 |
15 | ## Getting Started
16 |
17 | Follow instructions below to install the plugin and set up automatic submission of new pages in your WordPress site to the Bing index.
18 |
19 | ### VERIFYING YOUR WORDPRESS SITE ON BING WEBMASTER
20 |
21 | 1. Log in to [Bing Webmaster][bing-webmaster] (or sign up for an account).
22 | 1. Follow instructions [here][verify-wordpress] to verify your WordPress site with Bing Webmaster.
23 | 1. Once verified, you can access your API key by following the instructions [here][api-key-access].
24 |
25 | ### INSTALLING THE PLUGIN
26 |
27 | 1. Log in to the admin panel for your WordPress site. Click on `Plugins` > `Add New`.
28 | 1. Search for "Bing URL Submissions Plugin" and install.
29 | 1. Once installed, click on `Activate` to enable plugin.
30 |
31 | ### SETTING UP THE PLUGIN
32 |
33 | 1. Open Bing URL Submissions plugin settings page by clicking on `Settings` link for the plugin. (Or the `Bing Webmaster` link in the navigation menu).
34 | 1. Enter your Bing Webmaster API key into the API key prompt in the plugin page.
35 |
36 | Voila! Your WordPress site is now configured to automatically submit URLs to Bing.
37 |
38 | ## Frequently Asked Questions
39 |
40 | - Why should I install Bing URL Submission Plugin?
41 |
42 | Bing Webmaster enables quick indexing of your site URLs via the Submit URL API. Bing URL Submissions Plugin automates the submissions of your site URLs to this API by automatically submitting URLs for any page updated/created from WordPress.
43 |
44 | - Where do I find the API key?
45 |
46 | To automate Bing URL submissions using the Bing URL Submission Plugin, you need to have your WordPress site registered with Bing Webmaster. Once your site is verified at Bing Webmaster, you can access your API key by navigating to `Settings` > `API Access` > `API Key` within [Bing Webmaster portal][bing-webmaster].
47 |
48 | - I got an error "Adding API key failed: Invalid API Key" when I'm trying to log in to the plugin dashboard using API key. What do I do?
49 |
50 | "Invalid URL" error indicates that your API key is invalid for the WordPress site you're trying to configure the plugin against. Please verify that your WordPress site is added and verified against your Webmaster account.
51 |
52 | - "Automatic URL Submission" and "Manual URL Submission" cards are greyed out in plugin dashboard. How do I fix this?
53 |
54 | Automatic and manual URL submission cards are disabled if your API key is detected as invalid for submitting URLs against this WordPress site. Please ensure that your site is verified in your Bing Webmaster account and update the plugin with your new API key using 'Update key' option in the API key card.
55 |
56 | - I got an error "Invalid API key : Update API key to enable Automatic & Manual URL submission.". What do I do?
57 |
58 | See answer to `"Automatic URL Submission" and "Manual URL Submission" cards are greyed out in plugin dashboard. How do I fix this?` above.
59 |
60 | - How can I reset the plugin and delete any stored data from my WordPress database?
61 |
62 | You can go to 'Plugins' page from your WordPress side menu and click on `Deactivate` under Bing URL Submissions plugin listing. This will remove the API key integration as well as any locally stored data about submitted URLs. Reactivating the plugin will present you with a clean slate and ask for API key input.
63 |
64 | ## Changelog
65 |
66 | ### 1.0.13
67 | - Fix: Compatibility update with wordpress v5.8 and linting fixes.
68 |
69 | ### 1.0.12
70 | - Fix: Compatibility issue with older wordpress versions.
71 |
72 | ### 1.0.11
73 |
74 | - Fix: Non public URL subimssions.
75 | - Fix: Upgrade dependencies to fix vulnerabilities.
76 |
77 | ### 1.0.10
78 |
79 | - Upgrade dependencies to fix vulnerabilities.
80 |
81 | ### 1.0.9
82 |
83 | - Update readme to reflect support for WordPress v5.7.
84 |
85 | ### 1.0.8
86 |
87 | - Upgrade dependencies to fix vulnerabilities and update latest compatible wordpress version.
88 |
89 | ### 1.0.7
90 |
91 | - Fix console error being thrown by React when not in plugin page.
92 |
93 | ### 1.0.6
94 |
95 | - Upgrade dependencies to fix known vulnerabilities.
96 |
97 | ### 1.0.5
98 |
99 | - Filter out URLs containing specific post_types that aren't browsable.
100 |
101 | ### 1.0.4
102 |
103 | - Fix encoded URLs being displayed in URL Submissions table.
104 |
105 | ### 1.0.3
106 |
107 | - Update root element name. Fixes issue loading plugin settings page.
108 |
109 | ### 1.0.2
110 |
111 | - Rename root element of settings page to avoid conflicts with other plugins.
112 |
113 | ### 1.0.1
114 |
115 | - Update readme to reflect support for WordPress v5.5.
116 |
117 | ### 1.0.0
118 |
119 | - Initial release.
120 |
121 | [bing-webmaster]: https://bing.com/webmasters
122 | [verify-wordpress]: https://docs.microsoft.com/bingwebmaster/verifying-wordpress
123 | [api-key-access]: https://docs.microsoft.com/bingwebmaster/getting-access#using-api-key
124 |
--------------------------------------------------------------------------------
/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read https://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.0/8 are considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl, {
104 | headers: { 'Service-Worker': 'script' },
105 | })
106 | .then(response => {
107 | // Ensure service worker exists, and that we really are getting a JS file.
108 | const contentType = response.headers.get('content-type');
109 | if (
110 | response.status === 404 ||
111 | (contentType != null && contentType.indexOf('javascript') === -1)
112 | ) {
113 | // No service worker found. Probably a different app. Reload the page.
114 | navigator.serviceWorker.ready.then(registration => {
115 | registration.unregister().then(() => {
116 | window.location.reload();
117 | });
118 | });
119 | } else {
120 | // Service worker found. Proceed as normal.
121 | registerValidSW(swUrl, config);
122 | }
123 | })
124 | .catch(() => {
125 | console.log(
126 | 'No internet connection found. App is running in offline mode.'
127 | );
128 | });
129 | }
130 |
131 | export function unregister() {
132 | if ('serviceWorker' in navigator) {
133 | navigator.serviceWorker.ready
134 | .then(registration => {
135 | registration.unregister();
136 | })
137 | .catch(error => {
138 | console.error(error.message);
139 | });
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/public/readme.txt:
--------------------------------------------------------------------------------
1 | === Bing URL Submissions Plugin ===
2 | Contributors: bingwebmastertools
3 | Plugin link: https://bing.com/webmasters
4 | Tags: seo, crawling
5 | Requires at least: 5.3
6 | Tested up to: 5.8
7 | Stable tag: 1.0.13
8 | License: GPLv2 or later
9 | License URI: https://www.gnu.org/licenses/gpl-2.0.txt
10 | Requires PHP: 5.6.20
11 |
12 | Bing URL Submission Plugin for WordPress enables site owners to instantly and automatically submit their new/updated
13 | pages to the Bing index.
14 |
15 |
16 | == Description ==
17 |
18 | Bing URL Submission Plugin for WordPress enables automated submission of URLs from Wordpress sites to the Bing index. Once installed and configured with an API key obtained from Bing Webmaster portal, the plugin detects page creation/update in WordPress and automatically submits the URL behind the scenes ensuring that the site pages are always fresh in the Bing index.
19 |
20 | Some other handy features included in the plugin:
21 |
22 | * Toggle the automatic submission feature.
23 | * Manually submit a URL to Bing Index.
24 | * View list of recent URL submissions from the plugin.
25 | * Retry any failed submissions from the recent submissions list.
26 | * Download recent URL submissions for analysis.
27 |
28 | You can browse the code at the [GitHub repository](https://github.com/microsoft/bing-wordpress-url-submission-plugin).
29 |
30 | This plugin was developed with love and coffee by the Bing Webmaster team.
31 |
32 |
33 | == Installation ==
34 | Setting up Bing URL Submissions Plugin consists of two steps - installing the plugin and setting it up with your API key.
35 |
36 | ### INSTALLING THE PLUGIN
37 | 1. Log in to WordPress admin panel for your WordPress site. Click on 'Plugins > Add New'.
38 | 1. Search for 'Bing URL Submissions Plugin' and install.
39 | 1. Once installed, click on 'Activate' to enable plugin.
40 |
41 | ### SETTING UP WITH API KEY
42 | 1. Open Bing URL Submissions plugin settings page by clicking on "Settings" link for the plugin. (Or the 'Bing Webmaster' link in the navigation menu).
43 | 1. You should now be greeted with a prompt to enter API key.
44 | 1. Enter your Bing Webmaster API key into the prompt in the plugin page. (You can obtain API key by following the instructions [here](https://docs.microsoft.com/bingwebmaster/getting-access#using-api-key). Ensure that your WordPress site is verified with Bing Webmaster).
45 | 1. Voila! Your WordPress site is now configured to automatically submit URLs to Bing.
46 |
47 |
48 | == Frequently Asked Questions ==
49 |
50 | = Why should I install Bing URL Submission Plugin =
51 |
52 | Bing Webmaster enables quick indexing of your site URLs via the Submit URL API. Bing URL Submissions Plugin automates the submissions of your site URLs to this API by automatically submitting URLs for any page updated/created from WordPress.
53 |
54 | = Where do I get API key? =
55 |
56 | To automate Bing URL submissions using the Bing URL Submission Plugin, you need to have your WordPress site registered with Bing Webmaster. Once your site is verified at Bing Webmaster, you can access your API key by navigating to Settings > API Access > API Key within Bing Webmaster portal.
57 |
58 | = I got an error "Adding API key failed: Invalid API Key" when I'm trying to log in to the plugin dashboard using API key. What do I do? =
59 |
60 | "Invalid URL" error indicates that your API key is invalid for the WordPress site you're trying to configure the plugin against. Please verify that your WordPress site is added and verified against your Webmaster account.
61 |
62 | = "Automatic URL Submission" and "Manual URL Submission" cards are greyed out in plugin dashboard. How do I fix this? =
63 |
64 | Automatic and manual URL submission cards are disabled if your API key is detected as invalid for submitting URLs against this WordPress site. Please ensure that your site is verified in your Bing Webmaster account and update the plugin with your new API key using 'Update key' option in the API key card.
65 |
66 | = I got an error "Invalid API key : Update API key to enable Automatic & Manual URL submission.". What do I do? =
67 |
68 | See answer to '"Automatic URL Submission" and "Manual URL Submission" cards are greyed out in plugin dashboard. How do I fix this?' above.
69 |
70 | = How can I delete any stored data in my WordPress database? =
71 |
72 | You can go to 'Plugins' page from your WordPress sidebar and click on Deactivate under Bing URL Submissions plugin. This will remove the API key integration as well as any locally stored data about submitted URLs. Reactivating the plugin will present you with a clean slate and ask for API key input.
73 |
74 |
75 | == Changelog ==
76 |
77 | = 1.0.13 =
78 | - Fix: Compatibility update with wordpress v5.8 and linting fixes.
79 |
80 | = 1.0.12 =
81 | - Fix: Compatibility issue with older wordpress versions.
82 |
83 | = 1.0.11 =
84 | - Fix: Non public URL subimssions.
85 | - Fix: Upgrade dependencies to fix vulnerabilities.
86 |
87 | = 1.0.10 =
88 | - Upgrade dependencies to fix vulnerabilities.
89 |
90 | = 1.0.9 =
91 | * Update readme to reflect support for WordPress v5.7.
92 |
93 | = 1.0.8 =
94 | - Upgrade dependencies to fix vulnerabilities and update latest compatiable wordpress version.
95 |
96 | = 1.0.7 =
97 | - Fix console error being thrown by React when not in plugin page.
98 |
99 | = 1.0.6 =
100 | - Upgrade dependencies to fix known vulnerabilities.
101 |
102 | = 1.0.5 =
103 | - Filter out URLs containing specific post_types that aren't browsable.
104 |
105 | = 1.0.4 =
106 | * Fix encoded URLs being displayed in URL Submissions table.
107 |
108 | = 1.0.3 =
109 | * Update root element name. Fixes issue loading plugin settings page.
110 |
111 | = 1.0.2 =
112 | * Rename root element of settings page to avoid conflicts with other plugins.
113 |
114 | = 1.0.1 =
115 | * Update readme to reflect support for WordPress v5.5.
116 |
117 | = 1.0.0 =
118 | * Initial release.
119 |
--------------------------------------------------------------------------------
/src/scss/Dashboard.scss:
--------------------------------------------------------------------------------
1 | @import "./default";
2 |
3 | .bw-DashboardContent {
4 | margin-top: 25px;
5 |
6 | .sectionTitle {
7 | font-size: 16px;
8 | color: $bwt_cardTextColor;
9 | margin-top: 24px;
10 | }
11 |
12 | .sectionTitleContainer {
13 | display: flex;
14 | justify-content: space-between;
15 | margin-top: 24px;
16 |
17 | .sectionTitle {
18 | margin-top: 0;
19 | }
20 |
21 | button.buttonUrlSubmissionsDownload {
22 | margin-right: 24px;
23 | }
24 | }
25 |
26 | .bw-CardRow {
27 | margin: 8px 0;
28 | font-size: 16px;
29 | display: flex;
30 | flex-flow: row wrap;
31 | justify-content: space-between;
32 |
33 | .bw-CardColumn-1 {
34 | width: 100%;
35 | min-width: 320px;
36 | }
37 |
38 | .bw-CardColumn-2 {
39 | width: calc((100% - 8px) / 2);
40 | min-width: 320px;
41 | }
42 |
43 | .bw-CardColumn {
44 | background-color: $bwt_white;
45 | position: relative;
46 | box-shadow: 0px 0.6px 2px #0000001c;
47 | border-radius: 2px;
48 | display: flex;
49 |
50 | .bw-PopOverMenu {
51 | width: 10%;
52 | height: 100%;
53 | display: flex;
54 | flex-direction: column;
55 | align-items: center;
56 |
57 | &:hover {
58 | background-color: rgba(0, 0, 0, 0.1);
59 | cursor: pointer;
60 | }
61 |
62 | .moreIcon {
63 | margin-top: 18px;
64 | }
65 |
66 | .popOverContainer {
67 | position: relative;
68 |
69 | .popOverPanel {
70 | position: absolute;
71 | top: 0;
72 | right: 0;
73 | padding: 8px 10px;
74 | z-index: 100;
75 | box-shadow: 0px 1px 4px #0000001c;
76 | background-color: $bwt_white;
77 | border: 1px solid #eeeeee;
78 | border-radius: 2px;
79 | white-space: nowrap;
80 | display: none;
81 | }
82 |
83 | .openPopOverMenu {
84 | display: block;
85 | }
86 | }
87 | }
88 |
89 | .bw-Card-WithPopOver {
90 | width: 90%;
91 | }
92 |
93 | .bw-Disabled {
94 | filter: opacity(0.4);
95 | &:hover {
96 | background-color: inherit;
97 | cursor: inherit;
98 | }
99 | }
100 |
101 | .bw-Card {
102 | padding: 18px 24px;
103 | width: 100%;
104 |
105 | .cardTitle {
106 | font-size: 16px;
107 | color: $bwt_cardTextColor;
108 |
109 | .bw-CardTitleIcon {
110 | margin-right: 4px;
111 | }
112 |
113 | span {
114 | margin: 0 8px;
115 | }
116 |
117 | i.info {
118 | color: $bwt_optionalTextColor;
119 | cursor: pointer;
120 | vertical-align: middle;
121 | }
122 | }
123 |
124 | .cardDescription {
125 | font-size: 12px;
126 | color: $bwt_standardTextColor;
127 | margin-left: 25px;
128 | margin-top: 10px;
129 | }
130 | }
131 | }
132 |
133 | .bw-OverviewSection {
134 | display: flex;
135 | justify-content: space-between;
136 | width: 100%;
137 |
138 | .infoCards {
139 | background-color: $bwt_white;
140 | width: calc((100% - 16px) / 3);
141 | padding: 24px;
142 | box-shadow: 0px 0.6px 2px #0000001c;
143 | border-radius: 2px;
144 |
145 | h4 {
146 | font-size: 14px;
147 | }
148 | h2 {
149 | font-size: 24px;
150 | }
151 | p {
152 | font-size: 11px;
153 | color: $bwt_optionalTextColor;
154 | }
155 | }
156 | }
157 |
158 | .bw-ApiKeyCard {
159 | .cardDescription {
160 | color: $bwt_cardTextColor;
161 | }
162 | }
163 |
164 | .bw-ManualURLSubmissionCard {
165 | .bw-Card {
166 | .cardContent {
167 | display: flex;
168 | justify-content: space-between;
169 | }
170 | }
171 | }
172 |
173 | .bw-UrlSubmissions {
174 | padding: 0;
175 |
176 | > * {
177 | width: 100%;
178 | }
179 |
180 | .ms-DetailsHeader {
181 | padding-top: 0;
182 | }
183 |
184 | .ms-DetailsRow-cell {
185 | color: $bwt_cardTextColor;
186 | }
187 |
188 | i.retryIcon {
189 | cursor: pointer;
190 |
191 | &:hover {
192 | color: $bwt_primaryTealColor;
193 | font-weight: bolder;
194 | font-size: 16px;
195 | }
196 | }
197 | }
198 | }
199 |
200 | .footnotes {
201 | font-size: 12px;
202 | color: $bwt_secondaryTextColor;
203 | }
204 | }
205 |
206 | .bw-Modal {
207 | display: none;
208 | position: fixed;
209 | width: 40%;
210 | top: 30%;
211 | left: 30%;
212 | z-index: 1;
213 | box-shadow: -3px 6px 16px #00000029;
214 | border-radius: 2px;
215 |
216 | .modalContainer {
217 | display: flex;
218 | flex-direction: column;
219 | background-color: $bwt_white;
220 |
221 | .modalHeader {
222 | padding: 24px 32px;
223 | color: $bwt_cardTextColor;
224 | display: flex;
225 | justify-content: space-between;
226 |
227 | p {
228 | font-size: 21px;
229 | }
230 |
231 | .modalClose {
232 | cursor: pointer;
233 | }
234 | }
235 |
236 | .modalContent {
237 | padding: 24px 32px;
238 |
239 | .textField {
240 | input {
241 | border-radius: 0;
242 | border: none;
243 | }
244 | }
245 |
246 | p {
247 | font-size: 12px;
248 | color: $bwt_standardTextColor;
249 | }
250 | }
251 |
252 | .modalFooter {
253 | padding: 24px 32px;
254 | border-top: solid 1px rgba(0, 0, 0, 0.1);
255 |
256 | button.button {
257 | border-radius: 0;
258 | margin-right: 16px;
259 | }
260 |
261 | button.primaryButton {
262 | background-color: $bwt_primaryTealColor;
263 | color: $bwt_white;
264 | }
265 |
266 | button.secondaryButton {
267 | background-color: $bwt_white;
268 | }
269 | }
270 | }
271 | }
272 |
273 | .showModal {
274 | display: block;
275 | animation: animateIn 0.3s;
276 | }
277 |
278 | @keyframes animateIn {
279 | from {
280 | top: 100%;
281 | opacity: 0;
282 | }
283 | to {
284 | top: 30%;
285 | opacity: 1;
286 | }
287 | }
288 |
289 | .darken {
290 | filter: opacity(0.5);
291 | }
292 |
--------------------------------------------------------------------------------
/public/admin/class-bing-url-submission-admin.php:
--------------------------------------------------------------------------------
1 |
9 | */
10 | class Bing_Webmaster_Admin {
11 |
12 | /**
13 | * The ID of this plugin.
14 | *
15 | * @since 0.01.01
16 | * @access private
17 | * @var string $plugin_name The ID of this plugin.
18 | */
19 | private $plugin_name;
20 |
21 | /**
22 | * The version of this plugin.
23 | *
24 | * @since 0.01.01
25 | * @access private
26 | * @var string $version The current version of this plugin.
27 | */
28 | private $version;
29 |
30 | private $prefix = "bwt-";
31 |
32 | private $routes;
33 |
34 | /**
35 | * Initialize the class and set its properties.
36 | *
37 | * @since 0.01.01
38 | * @param string $plugin_name The name of this plugin.
39 | * @param string $version The version of this plugin.
40 | */
41 | public function __construct( $plugin_name, $version ) {
42 |
43 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/utils/class-bing-url-submission-admin-utils.php';
44 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/utils/class-bing-url-submission-admin-routes.php';
45 | $this->plugin_name = $plugin_name;
46 | $this->version = $version;
47 | $this->routes = new Bing_Webmaster_Admin_Routes($this->plugin_name, $this->version, $this->prefix);
48 |
49 | }
50 |
51 | /**
52 | * Register the stylesheets for the admin area.
53 | *
54 | * @since 0.01.01
55 | */
56 | public function enqueue_styles() {
57 |
58 | $CSSfiles = scandir(dirname(__FILE__) . '/../static/css/');
59 | foreach($CSSfiles as $filename) {
60 | if(strpos($filename,'.css')&&strpos($filename,'.css')+4 === strlen($filename)) {
61 | wp_enqueue_style( $filename, plugin_dir_url( __FILE__ ) . '../static/css/' . $filename, array(), mt_rand(10,1000), 'all' );
62 | }
63 | }
64 | }
65 |
66 | /**
67 | * Register the JavaScript for the admin area.
68 | *
69 | * @since 0.01.01
70 | */
71 | public function enqueue_scripts() {
72 |
73 | wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/bing-url-submission-admin.js', array( 'jquery' ), $this->version, false );
74 |
75 | $JSfiles = scandir(dirname(__FILE__) . '/../static/js/');
76 | $react_js_to_load = '';
77 | foreach($JSfiles as $filename) {
78 | if(strpos($filename,'.js')&&strpos($filename,'.js')+3 === strlen($filename)) {
79 | $react_js_to_load = plugin_dir_url( __FILE__ ) . '../static/js/' . $filename;
80 | wp_enqueue_script($filename, $react_js_to_load, '', mt_rand(10,1000), true);
81 | }
82 | }
83 |
84 | wp_localize_script( $this->plugin_name, 'wpr_object', array(
85 | 'api_nonce' => wp_create_nonce( 'wp_rest' ),
86 | 'api_url' => rest_url( $this->plugin_name . '/v_' . $this->version .'/' ),
87 | )
88 | );
89 |
90 | }
91 |
92 | public function register_routes()
93 | {
94 | $this->routes->register_routes();
95 | }
96 |
97 | /**
98 | * Register the administration menu for this plugin into the WordPress Dashboard menu.
99 | *
100 | * @since 0.01.01
101 | */
102 | public function add_plugin_admin_menu()
103 | {
104 | /*
105 | * Add a menu page for this plugin.
106 | */
107 | add_menu_page(
108 | __('Bing Webmaster Tools Url Submission', $this->plugin_name),
109 | __('Bing Webmaster', $this->plugin_name),
110 | 'manage_options',
111 | $this->plugin_name,
112 | array($this, 'display_plugin_admin_page'),
113 | 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNC45MiIgaGVpZ2h0PSIyMS4zMjgiIHZpZXdCb3g9IjAgMCAxNC45MiAyMS4zMjgiPg0KICAgIDxnIGZpbGw9IiNmZmYiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDMxMS41IC03OTYuMTY5KSI+DQogICAgICAgIDxwYXRoIGQ9Ik0tMzExLjUsNzk2LjE2OWw0LjI2MSwxLjV2MTVsNi0zLjQ2NC0yLjk0Mi0xLjM4LTEuODU2LTQuNjIsOS40NTYsMy4zMjJ2NC44M2wtMTAuNjU2LDYuMTQ2LTQuMjYzLTIuMzcxWiI+PC9wYXRoPg0KICAgIDwvZz4NCjwvc3ZnPg=='
114 | );
115 | }
116 |
117 | /**
118 | * Render the admin page for this plugin.
119 | *
120 | * @since 0.01.01
121 | */
122 | public function display_plugin_admin_page()
123 | {
124 | include_once('partials/bing-url-submission-admin-react.php');
125 | }
126 |
127 | /**
128 | * Add action link to the plugins page.
129 | *
130 | * @since 0.01.01
131 | */
132 | public function add_action_links($links)
133 | {
134 | /*
135 | * Documentation : https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)
136 | */
137 | $settings_link = array(
138 | '' . __('Settings', $this->plugin_name) . '',
139 | );
140 | return array_merge($settings_link, $links);
141 | }
142 |
143 | // This function checks the type of update on a page/post and accordingly calls the submit api if enabled
144 | public function on_post_published($new_status, $old_status, $post)
145 | {
146 | $admin_api_key = get_option( $this->prefix . "admin_api_key" );
147 | $is_valid_api_key = get_option( $this->prefix . "is_valid_api_key" );
148 | $auto_submission_enabled = get_option( $this->prefix . "auto_submission_enabled" );
149 | $is_change = false;
150 | $type = "add";
151 | if ($old_status === 'publish' && $new_status === 'publish') {
152 | $is_change = true;
153 | $type = "update";
154 | }
155 | else if ($old_status != 'publish' && $new_status === 'publish') {
156 | $is_change = true;
157 | $type = "add";
158 | }
159 | else if ($old_status === 'publish' && $new_status === 'trash') {
160 | $is_change = true;
161 | $type = "delete";
162 | }
163 | if ($is_change) {
164 | if (isset($is_valid_api_key) && $is_valid_api_key && $auto_submission_enabled && $auto_submission_enabled === "1") {
165 | $link = get_permalink($post);
166 | // remove __trashed from page url
167 | if (strpos($link, "__trashed") > 0) {
168 | $link = substr($link, 0, strlen($link) - 10) . "/";
169 | }
170 | if(empty($link)){
171 | if ( true === WP_DEBUG && true === WP_DEBUG_LOG) error_log(__METHOD__ . " link is empty");
172 | return;
173 | }
174 |
175 | if(function_exists('is_post_publicly_viewable')){
176 | $is_public_post = is_post_publicly_viewable($post);
177 |
178 | if ( true === WP_DEBUG && true === WP_DEBUG_LOG) {
179 | error_log(__METHOD__ . " is_public_post". (int)$is_public_post);
180 | error_log(__METHOD__ . " link ". $link);
181 | }
182 |
183 | if(!$is_public_post && $type != 'delete'){
184 | return;
185 | }
186 | }else{
187 | $http_response_header = wp_safe_remote_head($link);
188 | $res_code = wp_remote_retrieve_response_code($http_response_header);
189 |
190 | if (true === WP_DEBUG && true === WP_DEBUG_LOG) error_log(__METHOD__ . " link ". $link." ".$res_code);
191 |
192 | if(empty($res_code) || ($res_code != 200 && $type != 'delete')){
193 | return;
194 | }
195 | }
196 |
197 | $siteUrl = get_home_url();
198 |
199 | // check if same url was submitted recently(within a minute)
200 | if ($new_status != 'trash' && Bing_Webmaster_Admin_Utils::url_submitted_within_last_minute(Bing_Webmaster_Admin_Routes::$passed_submissions_table, $link)) {
201 | return;
202 | }
203 | $api_key = base64_decode($admin_api_key);
204 | $output = $this->routes->submit_url_to_bwt($siteUrl, $link, $api_key, $type, false);
205 | $this->routes->update_submission_output($output, $link);
206 | }
207 | }
208 | }
209 |
210 | public function options_update()
211 | {
212 | register_setting($this->plugin_name, $this->plugin_name, array($this, 'validate'));
213 | }
214 |
215 | public function validate($input)
216 | {
217 | return $input;
218 | }
219 |
220 | }
221 |
--------------------------------------------------------------------------------
/src/scss/headerPanel.scss:
--------------------------------------------------------------------------------
1 | @import "./default";
2 |
3 | .rightHeaderPanel {
4 | margin: 24px -16px;
5 |
6 | .panelView {
7 | padding: 0 16px;
8 | }
9 |
10 | .contentLabel {
11 | @include font-type($bwt_scopeFontFamily, $bwt_standardFontSize);
12 | }
13 | .contentLabelActive {
14 | @include font-type($bwt_semiboldFontFamily, $bwt_standardFontSize);
15 | }
16 | .showContent {
17 | height: auto;
18 | overflow: hidden;
19 | }
20 |
21 | .chevronIcon {
22 | cursor: pointer;
23 | padding-right: 10px;
24 | }
25 |
26 | .contentLabelInfo {
27 | @include font-type($bwt_semiboldFontFamily, $bwt_secondaryFontSize);
28 | padding-top: 8px;
29 | }
30 |
31 | .profileInfo {
32 | margin: 24px 16px 0;
33 | }
34 | .accountUserInfo {
35 | width: calc(100% - 72px);
36 | }
37 | .profileDetails {
38 | margin: 24px 0;
39 | }
40 |
41 | .accountDeleteButton {
42 | @include font-type($bwt_semiboldFontFamily, $bwt_standardFontSize);
43 | @include border-radius(2px);
44 | background: transparent;
45 | border: 1px solid $bwt_errorColor;
46 | color: $bwt_errorColor;
47 | cursor: pointer;
48 | &:hover {
49 | color: $bwt_white;
50 | background: $bwt_errorHoverBackGroundColor;
51 | border: 1px solid $bwt_errorHoverBackGroundColor;
52 | }
53 | }
54 | .contentInfo {
55 | padding-top: 16px;
56 | }
57 | .contentLabelDesc {
58 | margin: 12px 0 16px;
59 | @include font-type($bwt_scopeFontFamily, $bwt_secondaryFontSize);
60 | }
61 |
62 | .contentTextField {
63 | margin-top: 16px;
64 | }
65 | .contentTextFieldPhone {
66 | div {
67 | border-top-left-radius: 0px;
68 | border-bottom-left-radius: 0px;
69 | }
70 | }
71 |
72 | .countryCode {
73 | width: 60px;
74 | height: 32px;
75 | border: 1px solid rgb(96, 94, 92);
76 | border-top-left-radius: 2px;
77 | border-bottom-left-radius: 2px;
78 | border-right: none;
79 | text-align: center;
80 | line-height: 30px;
81 | }
82 |
83 | .phoneTextField {
84 | width: 248px;
85 | }
86 | .panelFormButtons {
87 | margin-top: 24px;
88 | }
89 |
90 | .bwtAccordion {
91 | > ul > li {
92 | padding: 16px;
93 | border-top: $bwt_lightGrayBorder;
94 |
95 | &:last-child {
96 | border-bottom: $bwt_lightGrayBorder;
97 | }
98 |
99 | &.expandItem {
100 | .contentLabel {
101 | @include font-type($bwt_semiboldFontFamily, $bwt_standardFontSize);
102 | }
103 | }
104 | }
105 |
106 | .accordionLabel {
107 | cursor: pointer;
108 | }
109 |
110 | .bwtAccordionContent {
111 | transform-origin: top;
112 | }
113 | }
114 |
115 | .toggleButton {
116 | > label {
117 | width: calc(100% - 56px);
118 | color: $bwt_primaryTextColor;
119 | }
120 |
121 | > div {
122 | label {
123 | width: 0;
124 | margin: 0;
125 | }
126 | }
127 | }
128 |
129 | .secondaryText {
130 | @include font-type($bwt_scopeFontFamily, $bwt_secondaryFontSize);
131 | color: $bwt_standardTextColor;
132 | padding-bottom: 12px;
133 | }
134 |
135 | .chevronRotate > i {
136 | transform: rotate(-180deg);
137 | }
138 |
139 | .padding0 {
140 | padding: 0;
141 | }
142 |
143 | .commentTextFiled {
144 | margin-bottom: 20px;
145 | }
146 |
147 | .ratingComponent {
148 | margin: 12px 0 20px;
149 |
150 | .ratingNumbers {
151 | list-style-type: none;
152 | display: flex;
153 | }
154 |
155 | .feedbackRatingCount {
156 | margin: 16px 0 8px;
157 | }
158 |
159 | li {
160 | @include border-radius(2px);
161 | @include font-type($bwt_semiboldFontFamily, $bwt_secondaryFontSize);
162 | margin-right: 3px;
163 | color: $bwt_primaryTextColor;
164 | background: $bwt_lightGray50Color;
165 | height: 28px;
166 | width: 24px;
167 | text-align: center;
168 | line-height: 28px;
169 | cursor: pointer;
170 | flex: 1;
171 | &:hover {
172 | background: $bwt_lightGray60Color;
173 | }
174 |
175 | &.activeClass {
176 | background: $bwt_primaryTealColor;
177 | color: $bwt_white;
178 | &:hover {
179 | background: $bwt_headerElementsHoverBackGroundColor;
180 | }
181 | }
182 | }
183 | }
184 |
185 | .feedbackComment {
186 | margin-top: 12px;
187 |
188 | h3 {
189 | @include font-type($bwt_semiboldFontFamily, $bwt_standardFontSize);
190 | margin-bottom: 4px;
191 | }
192 |
193 | p {
194 | @include font-type($bwt_scopeFontFamily, $bwt_secondaryFontSize);
195 | padding-bottom: 4px;
196 | }
197 | }
198 |
199 | .settingsModule {
200 | padding: 10px 0 24px;
201 | border-bottom: $bwt_lightGrayBorder;
202 | position: relative;
203 |
204 | &:last-child {
205 | border: 0;
206 | padding-bottom: 0;
207 | }
208 |
209 | h4 {
210 | font-weight: 600;
211 | padding-bottom: 8px;
212 | }
213 |
214 | &.disabled {
215 | opacity: 0.5;
216 |
217 | &::after {
218 | width: 100%;
219 | height: 100%;
220 | position: absolute;
221 | top: 0;
222 | left: 0;
223 | content: " ";
224 | }
225 | }
226 | }
227 | }
228 |
229 | .leftHeaderPanel {
230 | .headerTitle {
231 | font-weight: 600;
232 | margin-bottom: 20px;
233 | }
234 |
235 | .bingToolsLinks {
236 | margin: 12px 0;
237 | }
238 | }
239 |
240 | .leftPanelIcon {
241 | line-height: 54px;
242 | cursor: pointer;
243 | }
244 |
245 | .noNotification {
246 | width: 70%;
247 | margin: auto;
248 | text-align: center;
249 | padding: 50px 0;
250 |
251 | h2 {
252 | font-weight: 600;
253 | }
254 |
255 | p {
256 | padding-top: 20px;
257 | color: $bwt_optionalTextColor;
258 | }
259 | }
260 | .notificationsFilter {
261 | top: 0;
262 | position: sticky;
263 | z-index: 10;
264 | background: $bwt_lightGray10Color;
265 | padding: 0 16px 12px;
266 | margin: -24px -16px 5px;
267 | .notificationFilterDropdown {
268 | width: 135px;
269 | margin-top: 12px;
270 | margin-right: 8px;
271 | display: inline-block;
272 |
273 | * {
274 | border-color: $bwt_filterBorderColor;
275 | }
276 | }
277 | .toggleButton {
278 | width: 140px;
279 | margin-bottom: 0px;
280 | margin-top: 14px;
281 | }
282 | }
283 |
284 | .messageCard {
285 | @include box-shadow($bwt_messageCardShadow, $bwt_messageCardHoverShadow);
286 | @include border-radius(2px);
287 | background: $bwt_white;
288 | cursor: pointer;
289 | min-width: 300px;
290 | border-radius: 2px;
291 | transition: box-shadow 0.5s ease 0s;
292 | position: relative;
293 | padding: 16px;
294 | margin-bottom: 10px;
295 |
296 | .messageTime {
297 | position: absolute;
298 | right: 16px;
299 | top: 16px;
300 | @include font-type($bwt_scopeFontFamily, 12px);
301 | color: $bwt_darkGray40Color;
302 | }
303 |
304 | .messageSiteUrl {
305 | margin-bottom: 15px;
306 | span {
307 | @include singleLineEllipsis();
308 | @include font-type($bwt_scopeFontFamily, 12px);
309 | width: calc(100% - 120px);
310 | color: $bwt_darkGray40Color;
311 | }
312 | }
313 |
314 | .messageTitle {
315 | span {
316 | @include singleLineEllipsis();
317 | @include font-type($bwt_semiboldFontFamily, 14px);
318 | width: calc(100% - 120px);
319 | }
320 | }
321 |
322 | .messageSubject {
323 | margin-top: 8px;
324 | @include singleLineEllipsis();
325 | }
326 | .messageDescription {
327 | max-height: 0;
328 | height: auto;
329 | overflow: hidden;
330 | transition: max-height 0.2s cubic-bezier(0, 1, 0, 1);
331 | cursor: auto;
332 | .descriptionHeader {
333 | margin-top: 12px;
334 | @include font-type($bwt_semiboldFontFamily, 14px);
335 | }
336 | .description {
337 | margin-top: 8px;
338 | }
339 |
340 | &.showDesc {
341 | max-height: 100vh;
342 | transition: max-height 0.2s ease-in-out;
343 | }
344 | a {
345 | color: $bwt_primaryTealColor;
346 | cursor: pointer;
347 | }
348 | }
349 |
350 | .messageActions {
351 | position: absolute;
352 | right: 16px;
353 | bottom: 8px;
354 | background: $bwt_white;
355 | display: none;
356 |
357 | > i {
358 | @include displayIB();
359 | padding: 8px;
360 | color: $bwt_darkGray30Color;
361 | font-size: $bwt_smallIconSize;
362 |
363 | &:hover {
364 | background: $bwt_lightGray40Color;
365 | }
366 | }
367 | }
368 |
369 | .showActions {
370 | position: static;
371 | float: right;
372 | display: block;
373 | }
374 |
375 | &.messageRead {
376 | &:before {
377 | content: " ";
378 | position: absolute;
379 | width: 3px;
380 | height: 100%;
381 | top: 0;
382 | left: 0;
383 | background: $bwt_primaryTealColor;
384 | border-radius: 2px 0 0 2px;
385 | }
386 | .messageActions {
387 | .messageUnreadIcon,
388 | .messageReadIcon,
389 | .messageDeleteIcon {
390 | z-index: 10000000;
391 | }
392 | }
393 | }
394 |
395 | &:hover {
396 | .messageSubject {
397 | width: calc(100% - 74px);
398 | }
399 |
400 | .messageActions {
401 | display: inline-block;
402 | }
403 | }
404 | }
405 |
406 | .rightSidePanelHeader {
407 | padding: 16px 16px 0;
408 | display: flex;
409 | justify-content: space-between;
410 |
411 | .panelHeaderTitle {
412 | @include font-type($bwt_semiboldFontFamily, $bwt_mediumIconSize);
413 | }
414 | }
415 |
416 | .profileBottomLinks {
417 | .linkButton {
418 | height: 16px;
419 | line-height: 10px;
420 | margin-bottom: 10px;
421 | display: block;
422 | }
423 | a {
424 | height: 16px;
425 | display: block;
426 | line-height: 10px;
427 | }
428 | }
429 |
430 | .accountList {
431 | margin-top: 10px;
432 | width: 100%;
433 | position: relative;
434 | .personaCard {
435 | width: 100%;
436 | position: relative;
437 | }
438 | .accountPersona {
439 | @include singleLineEllipsis;
440 | padding: 4px 0;
441 | height: 44px;
442 | float: left;
443 | width: 264px;
444 | }
445 | .accountOverFlow {
446 | position: absolute;
447 | right: 0;
448 | top: 8px;
449 | width: 40px;
450 | }
451 | .accountMenu {
452 | .ms-CommandBar {
453 | padding: 0px;
454 | i {
455 | transform: rotate(90deg);
456 | }
457 | }
458 | }
459 | }
460 |
461 | .noGscAccounts {
462 | @include font-type($bwt_scopeFontFamily, $bwt_secondaryFontSize);
463 | margin-top: 10px;
464 | color: $bwt_secondaryTextColor;
465 | }
466 |
467 | .bwtAccordionAnim-enter {
468 | max-height: 0;
469 | }
470 |
471 | .bwtAccordionAnim-enter.bwtAccordionAnim-enter-active {
472 | max-height: 550px;
473 | transition: max-height 500ms cubic-bezier(0.4, 0, 0.2, 1);
474 | }
475 |
476 | .bwtAccordionAnim-leave {
477 | max-height: 550px;
478 | }
479 |
480 | .bwtAccordionAnim-leave.bwtAccordionAnim-leave-active {
481 | max-height: 0;
482 | transition: max-height 300ms cubic-bezier(0.4, 0, 0.2, 1);
483 | }
484 |
485 | @media (max-width: 639px) {
486 | .notificationsFilter {
487 | .notificationFilterDropdown {
488 | width: 100%;
489 | }
490 |
491 | .toggleButton {
492 | float: left;
493 | }
494 | }
495 |
496 | .messageCard {
497 | .messageSubject {
498 | width: calc(100% - 74px);
499 | }
500 |
501 | .messageActions {
502 | display: inline-block;
503 | }
504 | }
505 | }
506 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
--------------------------------------------------------------------------------
/src/components/Dashboard.tsx:
--------------------------------------------------------------------------------
1 | import "../scss/Dashboard.scss";
2 |
3 | import * as React from "react";
4 | import { useState, useEffect } from "react";
5 | import { DefaultButton, PrimaryButton } from "@fluentui/react/lib/Button";
6 | import { Icon } from "@fluentui/react/lib/Icon";
7 | import {
8 | GetApiSettings,
9 | GetStats,
10 | GetAllSubmissions,
11 | RetryFailedSubmissions,
12 | SubmitUrl,
13 | UpdateAutoSubmissionsEnabled,
14 | SetApiKey,
15 | CheckApiKeyValidity,
16 | } from "./withDashboardData";
17 | import { ShimmeredDetailsList } from "@fluentui/react/lib/ShimmeredDetailsList";
18 | import {
19 | IColumn,
20 | SelectionMode,
21 | IChoiceGroupOption,
22 | ChoiceGroup,
23 | TextField,
24 | } from "@fluentui/react/lib/index";
25 | import { format, formatISO } from "date-fns";
26 | import {
27 | IGetStatsResponse,
28 | IGetApiSettingsResponse,
29 | IGetAllSubmissionsResponse,
30 | UrlSubmission,
31 | } from "./Interfaces";
32 | import { Card } from "./Card";
33 | import { StringConstants, ApiKeyRegex, SubmitUrlRegex } from "../Constants";
34 |
35 | interface IDashboardProps {
36 | addBanner: (str: string) => void;
37 | }
38 |
39 | export const Dashboard: React.FunctionComponent = (props) => {
40 | enum DashboardModalState {
41 | Hidden = 0,
42 | UpdateApiKeyModal = 1,
43 | EditPrefAutoSubmissionModal = 2,
44 | SubmitUrlModal = 3,
45 | }
46 |
47 | const [apiKeyInvalid, setApiKeyInvalid] = useState(false);
48 | const [apiSettings, setAPISettings] = useState();
49 | const [submissionStats, setSubmissionStats] = useState();
50 | const [submissionsList, setSubmissionsList] = useState<
51 | IGetAllSubmissionsResponse
52 | >();
53 |
54 | // variables to store flyout menu states
55 | const [showApiKeyPopOverMenu, setShowApiKeyPopOverMenu] = useState(
56 | false
57 | );
58 | const [
59 | showAutoSubmissionsPopOverMenu,
60 | setShowAutoSubmissionsPopOverMenu,
61 | ] = useState();
62 |
63 | // variable to control modal display state
64 | const [modalState, setModalState] = useState(
65 | DashboardModalState.Hidden
66 | );
67 |
68 | // variables storing modal UI controls state
69 | const [
70 | selectedOptionAutoSubmissions,
71 | setSelectedOptionAutoSubmissions,
72 | ] = useState("enable");
73 | const [textFieldValueUrlSubmit, setTextFieldValueUrlSubmit] = useState<
74 | string
75 | >("");
76 | const [textFieldValueApiKey, setTextFieldValueApiKey] = useState("");
77 |
78 | // variables to trigger UI data refresh
79 | const [urlSubmitted, setUrlSubmitted] = useState(0);
80 | const [apiSettingsUpdated, setApiSettingsUpdated] = useState(0);
81 | const [apiKeyUpdated, setApiKeyUpdated] = useState(0);
82 |
83 | // Check if API key is valid
84 | useEffect(() => {
85 | Promise.resolve(CheckApiKeyValidity()).then((response) => {
86 | if (response && response.data) {
87 | if (response.data.error_type.length !== 0) {
88 | props.addBanner(
89 | "API Key Validation Error: Please check if site is verified or API key is valid to enable Automatic & Manual URL submission."
90 | );
91 | setApiKeyInvalid(true);
92 | }
93 | }
94 | });
95 | }, []);
96 |
97 | // Get API settings
98 | useEffect(() => {
99 | Promise.resolve(GetApiSettings()).then((response) => {
100 | if (response && response.data && response.data.error_type.length === 0) {
101 | setAPISettings(response.data);
102 | setSelectedOptionAutoSubmissions(
103 | response.data.AutoSubmissionEnabled ? "enable" : "disable"
104 | );
105 | }
106 | });
107 | }, [apiKeyUpdated, apiSettingsUpdated]);
108 |
109 | // Get submissions statistics
110 | useEffect(() => {
111 | Promise.resolve(GetStats()).then((response) => {
112 | if (response && response.data && response.data.error_type.length === 0) {
113 | setSubmissionStats(response.data);
114 | }
115 | });
116 | }, [apiKeyUpdated, urlSubmitted]);
117 |
118 | // Get submissions list
119 | useEffect(() => {
120 | Promise.resolve(GetAllSubmissions()).then((response) => {
121 | if (response && response.data && response.data.error_type.length === 0) {
122 | response.data.Submissions.sort((a, b) =>
123 | a.submission_date > b.submission_date ? -1 : 1
124 | );
125 | setSubmissionsList(response.data);
126 | }
127 | });
128 | }, [apiKeyUpdated, urlSubmitted]);
129 |
130 | // constants
131 | const autoSubmissionOptions: IChoiceGroupOption[] = [
132 | { key: "enable", text: "Enable (recommended)" },
133 | { key: "disable", text: "Disable" },
134 | ];
135 | const urlSubmissionTableColumns: IColumn[] = [
136 | {
137 | key: "url",
138 | name: "URL",
139 | fieldName: "url",
140 | onRender: (item: UrlSubmission): JSX.Element => {
141 | return (
142 |
143 | {decodeURI(item.url)}
144 |
145 | );
146 | },
147 | minWidth: 250,
148 | },
149 | {
150 | key: "submittedOn",
151 | name: "Submitted On",
152 | fieldName: "submission_date",
153 | onRender: (item: UrlSubmission): string => {
154 | let time: Date = new Date(0);
155 | time.setUTCSeconds(item.submission_date);
156 | let dateString: string =
157 | time.getFullYear === new Date().getFullYear
158 | ? format(time, "d MMM 'at' HH':'mm", {})
159 | : format(time, "d MMM yyyy'at' HH':'mm", {});
160 | return dateString;
161 | },
162 | minWidth: 150,
163 | },
164 | {
165 | key: "status",
166 | name: "Status",
167 | fieldName: "error",
168 | onRender: (item: UrlSubmission): string => {
169 | return item.error === "Success" ? item.error : `Failed - ${item.error}`;
170 | },
171 | minWidth: 200,
172 | },
173 | {
174 | key: "resubmit",
175 | name: "",
176 | onRender: (item: UrlSubmission) => {
177 | return (
178 |
184 | );
185 | },
186 | minWidth: 40,
187 | maxWidth: 70,
188 | className: "retryColumn",
189 | },
190 | ];
191 |
192 | // Function handler for URL submission retries
193 | const resubmitOnClick = (
194 | event: React.MouseEvent
195 | ) => {
196 | const submissionItemString: string =
197 | (event.target as HTMLInputElement).dataset.submission ?? "";
198 | const submissionItem: UrlSubmission = JSON.parse(submissionItemString);
199 | Promise.resolve(RetryFailedSubmissions([submissionItem])).then(
200 | (response) => {
201 | if (response && response.data) {
202 | setUrlSubmitted(urlSubmitted + 1);
203 | if (
204 | !response.data.hasError &&
205 | response.data.error_type.length === 0 &&
206 | response.data.SubmissionErrors.length >= 1 &&
207 | response.data.SubmissionErrors[0].isSubmitted
208 | ) {
209 | // add new success banner
210 | props.addBanner("Success : URL submitted successfully.");
211 | } else {
212 | // set failed banner
213 | props.addBanner(
214 | `Error : Submission failed for URL - ${submissionItem.url}`
215 | );
216 | }
217 | }
218 | }
219 | );
220 | };
221 |
222 | const onClickUpdateApiKey = (
223 | event: React.MouseEvent
224 | ) => {
225 | setModalState(DashboardModalState.Hidden);
226 | Promise.resolve(SetApiKey(textFieldValueApiKey)).then((response) => {
227 | if (response && response.data) {
228 | setApiKeyUpdated(apiKeyUpdated + 1);
229 | if (response.data.error_type.length === 0) {
230 | props.addBanner("Success : API key is updated successfully.");
231 | } else {
232 | props.addBanner("Error : Unable to update API key.");
233 | }
234 | }
235 | });
236 | };
237 |
238 | const onClickUpdateAutoSubmissions = (
239 | event: React.MouseEvent
240 | ) => {
241 | setModalState(DashboardModalState.Hidden);
242 | Promise.resolve(
243 | UpdateAutoSubmissionsEnabled(selectedOptionAutoSubmissions === "enable")
244 | ).then((response) => {
245 | if (response && response.data) {
246 | setApiSettingsUpdated(apiSettingsUpdated + 1);
247 | if (response.data.error_type.length === 0) {
248 | props.addBanner(
249 | "Success : Automatic URL submission preferences updated."
250 | );
251 | } else {
252 | props.addBanner(
253 | "Error : Automatic URL submission preferences not updated."
254 | );
255 | }
256 | }
257 | });
258 | };
259 |
260 | const onClickModalSubmitUrl = (
261 | event: React.MouseEvent
262 | ) => {
263 | // hide modal and submit Url
264 | setModalState(DashboardModalState.Hidden);
265 | Promise.resolve(SubmitUrl(textFieldValueUrlSubmit)).then((response) => {
266 | if (response && response.data) {
267 | setUrlSubmitted(urlSubmitted + 1);
268 | if (response.data.error.length === 0) {
269 | // add new success banner
270 | props.addBanner("Success : URL submitted successfully.");
271 | } else {
272 | // set failed banner
273 | props.addBanner(
274 | `Error : Submission failed for URL - ${textFieldValueUrlSubmit}`
275 | );
276 | }
277 | }
278 | });
279 | };
280 |
281 | const downloadUrls = () => {
282 | let data = submissionsList?.Submissions?.map((item) => {
283 | let timestamp: Date = new Date(0);
284 | timestamp.setUTCSeconds(item.submission_date);
285 | return {
286 | url: item.url,
287 | timestamp: formatISO(timestamp),
288 | submitted: item.error === "Success",
289 | status: item.error,
290 | };
291 | });
292 | const json = JSON.stringify(data);
293 | const blob = new Blob([json], { type: "application/json" });
294 | const link = document.createElement("a");
295 | link.href = URL.createObjectURL(blob);
296 | link.download = "submissionslist.json";
297 | link.click();
298 | };
299 |
300 | return (
301 | <>
302 |