Skip to content

Commit

Permalink
Improved settings
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
PromInc committed Sep 2, 2015
1 parent 1724982 commit 50e315f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 40 deletions.
31 changes: 30 additions & 1 deletion inc/code/dataCapture.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Empty file added inc/html/reportQuickLinks.php
Empty file.
9 changes: 4 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@
<h2>Data Capture and Import</h2>
<div>Capture and import data from Organic Search Analytics resources.</div>
<div>Note: <i>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.</i></div>
<div><a href="search.php">Data Capture</a></div>
<div><a href="data-capture.php">Data Capture</a></div>
</li>

<li>
<h2>Settings</h2>
<div>Configure various settings for the Organic Search Analytics capture and import tool</div>
<div><a href="settings.php">Configure Settings</a></div>
</li>
<!--

<li>
<h2>Reports</h2>
<div>View reports of the imported Webmaster Tools Data.</div>
<div>View reports of imported Data.</div>
<div><a href="report.php">View Reports</a></div>
</li>
-->
</ul>

<?php include_once('inc/html/_foot.php'); ?>
4 changes: 2 additions & 2 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 2 additions & 0 deletions report.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@
</p>
</form>

<?php include ('inc/html/reportQuickLinks.php'); ?>

<?php include_once('inc/html/_foot.php'); ?>
59 changes: 27 additions & 32 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,46 @@
if( !$isConfigured ) {
echo '<p>Configuration file is missing</p>';
} else {
echo '<p>Configuration is set. No further action is needed at this time.</p>';
echo '<p>The configuration file is set.</p>';
}
?>
<hr>
<h3>Google</h3>
<h4>Sites</h4>
<p>The sites listed here directly correlate to the URL for the site you have configured in <b>Google Search Console</b>. Ensure they match what is entered in <b>Google Search Console</b>.</p>
<p>Use the checkbox to enable/disable this site from being available to the <b>Data Capture</b> tool.</p>
<h2>Site Setup</h2>
<h3>Google Search Analytics</h3>
<p>Choose which sites you wish to capture data from Google Search Console.</p>
<p><i>Not seeing the sites you expect?</i><br>Ensure that you have enabled the <b>Google Search Console API</b> and added your Google API Service Account email address as a user to each of your sites in Google Search Console.<br><a href="http://promincproductions.com/blog/google-api-access-google-search-analytics-from-google-search-console/" target="blank">Instruction on how to configure Google Search Analytics for API Access</a></p>

<form action="<?PHP echo $_SERVER['SCRIPT_NAME'] ?>" method="post">
<?php
/* Get list of sites */
$sitesList = $mysql->getSettings("sites_google");
$siteSettings = $mysql->getSettings("sites_google");
$sitesList = $dataCapture->getSitesGoogleSearchConsole();

if( count( $sitesList ) == 0 && !isset( $_POST['sites_google'] ) ) {
echo '<p><b><i>No sites are configured at this time. Add a site by typing it in the field below and choosing Save Settings.</i></b></p>';
}

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;
}
}
}
Expand All @@ -60,16 +59,12 @@

<ul id="sites_google">
<?php if( $sitesList ) { ?>
<?php foreach( $sitesList as $site => $value ) { ?>
<li><input type="checkbox" name="sites_google[]" value="<?php echo $site ?>" <?php if($value==1){echo " checked";}?> /><?php echo $site ?></li>
<?php foreach( $sitesList as $value ) { ?>
<li><input type="checkbox" name="sites_google[]" value="<?php echo $value['url'] ?>" <?php echo ( isset( $siteSettings[$value['url']] ) && $siteSettings[$value['url']] == 1 ? " checked" : "" )?> /><?php echo $value['url'] ?></li>
<?php } ?>
<?php } ?>
<li><input id="sites_google_new_check" type="checkbox" name="sites_google[]" value="" /><input id="sites_google_new_text" type="text"><i>Add new site here</i></li>
</ul>

<h4>Data/Reports to Capture from Google</h4>
<p>Show a list of options the user can enable/disable here. NOTE: At this point the only option would be <b>Search Analytics</b> as I haven't built out any other features yet.</p>

<input type="hidden" id="save" name="save" value="true" />
<input type="submit" value="Save Settings">

</form>
Expand Down

0 comments on commit 50e315f

Please sign in to comment.