From 50e315fe670bc09809c24e0a8fd1b5ad70c4755e Mon Sep 17 00:00:00 2001 From: PromInc Date: Wed, 2 Sep 2015 08:41:34 -0500 Subject: [PATCH] Improved settings - The sites list in the settings page is no longer manually created, rather it is pulled from Google Search Console. - A quick links file is added to the reporting page. - Fixed broken link on home page --- inc/code/dataCapture.php | 31 +++++++++++++++++- inc/html/reportQuickLinks.php | 0 index.php | 9 +++--- js/script.js | 4 +-- report.php | 2 ++ settings.php | 59 ++++++++++++++++------------------- 6 files changed, 65 insertions(+), 40 deletions(-) create mode 100644 inc/html/reportQuickLinks.php diff --git a/inc/code/dataCapture.php b/inc/code/dataCapture.php index c5fbd04..9cfd978 100644 --- a/inc/code/dataCapture.php +++ b/inc/code/dataCapture.php @@ -14,7 +14,36 @@ class DataCapture const GOOGLE_SEARCH_ANALYTICS_MAX_DATE_OFFSET = 4; const GOOGLE_SEARCH_ANALYTICS_MAX_DAYS = 90; - + + + /** + * Get authorized sites from Google Search Console + * + * @returns Array Site URL and permission level + */ + public function getSitesGoogleSearchConsole() { + /* Authorize Google via oAuth 2.0 */ + $gapiOauth = new GAPIoAuth(); + $client = $gapiOauth->LogIn(); + + /* Load Google Webmasters API */ + $webmasters = new Google_Service_Webmasters($client); + + /* Load sites functions */ + $siteServices = $webmasters->sites; + + /* Get list of sites */ + $gSites = $siteServices ->listSites(); + + $return = array(); + foreach( $gSites->getSiteEntry() as $site ) { + $return[] = array( 'url' => $site['siteUrl'], 'permission' => $site['permissionLevel'] ); + } + + return $return; + } + + /** * Query database. Retrun all values from a table * diff --git a/inc/html/reportQuickLinks.php b/inc/html/reportQuickLinks.php new file mode 100644 index 0000000..e69de29 diff --git a/index.php b/index.php index 316b568..33887e7 100644 --- a/index.php +++ b/index.php @@ -9,21 +9,20 @@

Data Capture and Import

Capture and import data from Organic Search Analytics resources.
Note: At this time only Google Search Analytics data is configured to work with this tool. In the future additional data from Google and Bing will be added, as well as reporting features.
-
Data Capture
+
Data Capture
- +
  • Settings

    Configure various settings for the Organic Search Analytics capture and import tool
    Configure Settings
  • - \ No newline at end of file diff --git a/js/script.js b/js/script.js index bc8242f..269a6b5 100644 --- a/js/script.js +++ b/js/script.js @@ -52,10 +52,10 @@ function importAllRun(catId) { $(".importAllButtons[category='"+catId+"'] .buttonImportAllStop").show(); /* Trigger the first import button */ - if( $("#"+catId+" .buttonImport").eq(0) ) { + if( $("#"+catId+" .buttonImport").length > 0 ) { $("#"+catId+" .buttonImport").eq(0).trigger("click"); } else { - console.log("No more data to import"); + importAllStop(); window.importAllProcessing = false; } } diff --git a/report.php b/report.php index c138b6f..250acf4 100644 --- a/report.php +++ b/report.php @@ -72,4 +72,6 @@

    + + \ No newline at end of file diff --git a/settings.php b/settings.php index bb66904..421ecf0 100644 --- a/settings.php +++ b/settings.php @@ -11,47 +11,46 @@ if( !$isConfigured ) { echo '

    Configuration file is missing

    '; } else { - echo '

    Configuration is set. No further action is needed at this time.

    '; + echo '

    The configuration file is set.

    '; } ?>
    -

    Google

    -

    Sites

    -

    The sites listed here directly correlate to the URL for the site you have configured in Google Search Console. Ensure they match what is entered in Google Search Console.

    -

    Use the checkbox to enable/disable this site from being available to the Data Capture tool.

    +

    Site Setup

    +

    Google Search Analytics

    +

    Choose which sites you wish to capture data from Google Search Console.

    +

    Not seeing the sites you expect?
    Ensure that you have enabled the Google Search Console API and added your Google API Service Account email address as a user to each of your sites in Google Search Console.
    Instruction on how to configure Google Search Analytics for API Access

    getSettings("sites_google"); + $siteSettings = $mysql->getSettings("sites_google"); + $sitesList = $dataCapture->getSitesGoogleSearchConsole(); if( count( $sitesList ) == 0 && !isset( $_POST['sites_google'] ) ) { echo '

    No sites are configured at this time. Add a site by typing it in the field below and choosing Save Settings.

    '; } - if( isset( $_POST['sites_google'] ) ) { - foreach( $sitesList as $site => $value ) { - if( in_array( $site, $_POST['sites_google'] ) ) { - /* Set to checked */ - $response = $mysql->qryDBupdate( $dbTable_settings, array('type'=>'sites_google', 'value'=>$site), array('data'=>1) ); - if( $response ) { - $sitesList[$site] = 1; + /* Update settings table */ + if( isset( $_POST['save'] ) && $_POST['save'] == "true" ) { + foreach( $sitesList as $key => $value ) { + $siteToAdd = addslashes( $value['url'] ); + if( isset( $_POST['sites_google'] ) && in_array( $value['url'], $_POST['sites_google'] ) ) { + if( in_array( $value['url'], $_POST['sites_google'] ) ) { + /* Set to checked */ + if( array_key_exists( $siteToAdd , $siteSettings ) ) { + $response = $mysql->qryDBupdate( $dbTable_settings, array('type'=>'sites_google', 'value'=>$siteToAdd), array('data'=>1) ); + } else { + $response = $mysql->qryDBinsert( $dbTable_settings, "NULL, 'sites_google', '".$siteToAdd."', 1" ); + } + if( $response ) { + $siteSettings[$value['url']] = 1; + } } } else { /* Set to unchecked */ - $response = $mysql->qryDBupdate( $dbTable_settings, array('type'=>'sites_google', 'value'=>$site), array('data'=>0) ); + $response = $mysql->qryDBupdate( $dbTable_settings, array('type'=>'sites_google', 'value'=>$siteToAdd), array('data'=>0) ); if( $response ) { - $sitesList[$site] = NULL; - } - } - } - - /* Add new sites */ - if( isset( $_POST['sites_google'] ) ) { - foreach( $_POST['sites_google'] as $site ) { - if( !$sitesList || !array_key_exists( $site, $sitesList ) ) { - $mysql->qryDBinsert($dbTable_settings,"NULL,'sites_google','".$site."',1"); - $sitesList[$site] = 1; + $siteSettings[$value['url']] = NULL; } } } @@ -60,16 +59,12 @@ - -

    Data/Reports to Capture from Google

    -

    Show a list of options the user can enable/disable here. NOTE: At this point the only option would be Search Analytics as I haven't built out any other features yet.

    - +