Skip to content

Commit

Permalink
Configuration and alerts
Browse files Browse the repository at this point in the history
- Configuration can be set within the tool as opposed to manually
editing the config.php file
- Alert boxes added for various messaging throughout the site.
  • Loading branch information
PromInc committed Sep 3, 2015
1 parent cf1ef38 commit 28e551d
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 56 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.4.0 - 2015-09-03
### Changed
- Configuration settings can be set via the website under the Settings page as opposed manually creating/editing a file on the server.
- README has been updated to reflect these changes.

### Added
- Alert boxes were added for messages upon saving, etc.

## 1.3.0 - 2015-09-02
### Changed
- Instead of manually adding sites in the Settings page, it now pulls in the list of sites that have API access from Google Search Console.
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ Import organic search analytics from Google Search Console (Google Webmaster Too
13. Choose **P12** and click the **Create** button. Click the **Ok** button to close the popup.
14. A file should have downloaed automatically - copy that file to your webserver to the **/config** directory.
15. Copy the **Email address** from the **Service accounts** section and keep this handy - it's needed for a later step.
6. Setup config file. Open **/config/config.php** in a text editor and fill in your credentials.
1. DB_CONNECTION_DOMAIN = the domain name of the MySQL database connection. If you are using XAMPP or MAMP this will be *localhost*.
2. DB_CONNECTION_USER = the username to connect to the MySQL database. If you are using XAMPP or MAMP this will be *root*.
3. DB_CONNECTION_PASSWORD = the password to connect to the MySQL database. If you are using XAMPP or MAMP this will be *root*.
4. DB_CONNECTION_DATABASE = the MySQL database name as defined in step 3.
5. OAUTH_CREDENTIALS_EMAIL = the Google API Access email address from step 5.xv.
6. OAUTH_CREDENTIALS_PRIVATE_KEY_FILE_NAME = The file name of the P12 file from step 5.xiv.
7. [Grant access to Google Search Console](http://promincproductions.com/blog/google-api-access-google-search-analytics-from-google-search-console/).
6. [Grant access to Google Search Console](http://promincproductions.com/blog/google-api-access-google-search-analytics-from-google-search-console/).
1. Log into [Google Search Console](https://www.google.com/webmasters/)
2. For each site you wish to access data from, choose **Manage property -> Add or remove users**.
3. Click **ADD A NEW USER**
4. Enter the email address from ste 5.xv in the **User email** field.
5. Set the **Permision** dropdown to **Full**.
6. Click the **Add** button.
7. To grant access to other sites, click **Search Console** in the top left and repeat steps iii through vi, using the same email address in each step.
7. Set configuration. Access the site on your web server and choose **Settings -> Create Configuration File**. Fill in the following fields and click **Save Configuration**.
- Database Host = the domain name of the MySQL database connection. If you are using XAMPP or MAMP this will be *localhost*.
- Database Username = the username to connect to the MySQL database. If you are using XAMPP or MAMP this will be *root*.
- Database Password = the password to connect to the MySQL database. If you are using XAMPP or MAMP this will be *root*.
- Database Name = the MySQL database name as defined in step 3.
- OOAuth 2.0 Email Address = the Google API Access email address from step 5.xv.
- OAuth 2.0 P12 File Name = The file name of the P12 file from step 5.xiv.
12 changes: 0 additions & 12 deletions config/config.php.template

This file was deleted.

16 changes: 15 additions & 1 deletion css/gwt.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,18 @@ header > span:not(:last-child):after {
.clear { clear:both; }


footer { margin-top: 50px; padding: 20px 20px 15px; background-color:#DDDDDD; }
footer { margin-top: 50px; padding: 20px 20px 15px; background-color:#DDDDDD; }


/* Alert Box */
.alert { margin-top: .5%; padding: .5%; }
.alert a, .alert a:hover, .alert a:visited, .alert a:active { color: inherit; }

#siteContent div.alert.warning {
background-color: #F00;
color: #FF0;
}
#siteContent div.alert.success {
background-color: #008813;
color: #FFF;
}
1 change: 1 addition & 0 deletions data-capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<?php include_once('inc/html/_head.php'); ?>

<?php include_once('inc/html/_alert.php'); ?>
<h1>Organic Search Analytics | Capture Data</h1>

<h2>Google Search Console</h2>
Expand Down
2 changes: 2 additions & 0 deletions inc/code/globalIncludes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@
$dataCapture = new DataCapture(); //Load Data Capturing tools

$GLOBALS['db'] = $core->mysql_connect_db(); // Connect to DB
} else {
$alert = array("type"=>"warning", "message"=>"Please set your configuration settings before procedding. <a href=\"settings-configure.php\">Configure Now</a>");
}
?>
3 changes: 3 additions & 0 deletions inc/html/_alert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php if( isset( $alert ) ) { ?>
<div class="alert <?php echo $alert['type'] ?>"><?php echo $alert['message'] ?></div>
<?php } ?>
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<?php include_once('inc/html/_head.php'); ?>

<?php include_once('inc/html/_alert.php'); ?>
<h1>Organic Search Analytics | Capture and Import</h1>
<div>The below tools expedite grabbing data from Google Webmaster Tools</div>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion report-custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}
?>


<?php include_once('inc/html/_alert.php'); ?>
<h1>Search Analytics Reporting | Results</h1>
<h2><?php echo implode( ", ", $pageHeadingItems ); ?></h2>

Expand Down
1 change: 1 addition & 0 deletions report.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<?php include_once('inc/html/_head.php'); ?>

<?php include_once('inc/html/_alert.php'); ?>
<h1>Search Analytics Reporting</h1>

<h2>Generate Report</h2>
Expand Down
100 changes: 100 additions & 0 deletions settings-configure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
/* Write saved settings to configuration file */
if( isset( $_POST['save'] ) ) {
$basedir = preg_replace( '/\\\/', '/', realpath(dirname(__FILE__).'/').'/' );

$nl = "\n";
$t = "\t";

/* File contents */
$writeToConfigFile = "<?php".$nl;
$writeToConfigFile .= $t."class Config".$nl;
$writeToConfigFile .= $t."{".$nl;
$writeToConfigFile .= $t.$t."const DB_CONNECTION_DOMAIN = '".$_POST['DB_CONNECTION_DOMAIN']."';".$nl;
$writeToConfigFile .= $t.$t."const DB_CONNECTION_USER = '".$_POST['DB_CONNECTION_USER']."';".$nl;
$writeToConfigFile .= $t.$t."const DB_CONNECTION_PASSWORD = '".$_POST['DB_CONNECTION_PASSWORD']."';".$nl;
$writeToConfigFile .= $t.$t."const DB_CONNECTION_DATABASE = '".$_POST['DB_CONNECTION_DATABASE']."';".$nl;
$writeToConfigFile .= "".$nl;
$writeToConfigFile .= $t.$t."const OAUTH_CREDENTIALS_EMAIL = '".$_POST['OAUTH_CREDENTIALS_EMAIL']."';".$nl;
$writeToConfigFile .= $t.$t."const OAUTH_CREDENTIALS_PRIVATE_KEY_FILE_NAME = '".$_POST['OAUTH_CREDENTIALS_PRIVATE_KEY_FILE_NAME']."';".$nl;
$writeToConfigFile .= $t."}".$nl;
$writeToConfigFile .= "?>";

/* Write to file */
$myfile = fopen($basedir."config/config.php", "w") or die("Unable to open file!");
fwrite($myfile, $writeToConfigFile);
fclose($myfile);

$alert = array("type"=>"success", "message"=>"Configuration Succesfully Saved");
}
?>

<?php $titleTag = "Settings Configuration | Organic Search Analytics"; ?>
<?php $dbTable_settings = 'settings'; ?>

<?php include_once('inc/html/_head.php'); ?>

<?php include_once('inc/html/_alert.php'); ?>
<h1>Organic Search Analytics | Settings Configuration</h1>

<h2>Configuration</h2>
<form action="<?PHP echo $_SERVER['SCRIPT_NAME'] ?>" method="post">

<?php
if( $isConfigured ) {
$db_connection_host = config::DB_CONNECTION_DOMAIN;
$db_connection_user = config::DB_CONNECTION_USER;
$db_connection_password = config::DB_CONNECTION_PASSWORD;
$db_connection_database = config::DB_CONNECTION_DATABASE;

$oauth_credentials_email = config::OAUTH_CREDENTIALS_EMAIL;
$oauth_credentials_private_key_file_name = config::OAUTH_CREDENTIALS_PRIVATE_KEY_FILE_NAME;

} else {
$db_connection_host = $db_connection_user = $db_connection_password = $db_connection_database = $oauth_credentials_private_key_file_name = $oauth_credentials_email = "";
}
?>

<hr>
<h3>Database</h3>

<p>
<label for="DB_CONNECTION_DOMAIN">Database Host</label>
<input type="text" id="DB_CONNECTION_DOMAIN" name="DB_CONNECTION_DOMAIN" value="<?php echo $db_connection_host ?>">
</p>

<p>
<label for="DB_CONNECTION_USER">Database Username</label>
<input type="text" id="DB_CONNECTION_USER" name="DB_CONNECTION_USER" value="<?php echo $db_connection_user ?>">
</p>

<p>
<label for="DB_CONNECTION_PASSWORD">Database Password</label>
<input type="password" id="DB_CONNECTION_PASSWORD" name="DB_CONNECTION_PASSWORD" value="<?php echo $db_connection_password ?>">
</p>

<p>
<label for="DB_CONNECTION_DATABASE ">Database Name</label>
<input type="text" id="DB_CONNECTION_DATABASE " name="DB_CONNECTION_DATABASE" value="<?php echo $db_connection_database ?>">
</p>

<hr>
<h3>Google OAuth2.0</h3>

<p>
<label for="OAUTH_CREDENTIALS_EMAIL">OAuth 2.0 Email Address</label>
<input type="text" id="OAUTH_CREDENTIALS_EMAIL" name="OAUTH_CREDENTIALS_EMAIL" value="<?php echo $oauth_credentials_email ?>">
</p>

<p>
<label for="OAUTH_CREDENTIALS_PRIVATE_KEY_FILE_NAME">OAuth 2.0 P12 File Name</label>
<input type="text" id="OAUTH_CREDENTIALS_PRIVATE_KEY_FILE_NAME" name="OAUTH_CREDENTIALS_PRIVATE_KEY_FILE_NAME" value="<?php echo $oauth_credentials_private_key_file_name ?>">
</p>

<hr>

<input type="submit" name="save" id="save" value="Save Configuration">

</form>

<?php include_once('inc/html/_foot.php'); ?>
75 changes: 41 additions & 34 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,53 @@

<?php include_once('inc/html/_head.php'); ?>

<?php
if( $isConfigured ) {
/* Get list of sites */
$siteSettings = $mysql->getSettings("sites_google");
$sitesList = $dataCapture->getSitesGoogleSearchConsole();

/* Update settings table */
if( isset( $_POST['sites_google'] ) ) {
foreach( $sitesList as $key => $value ) {
if( in_array( $value['url'], $_POST['sites_google'] ) ) {
/* Set to checked */
$siteToAdd = addslashes( $value['url'] );

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'=>$value['url']), array('data'=>0) );
if( $response ) {
$siteSettings[$value['url']] = NULL;
}
}
$alert = array("type"=>"success", "message"=>"Configuration Succesfully Updated");
}
}
}
?>

<?php include_once('inc/html/_alert.php'); ?>
<h1>Organic Search Analytics | Settings</h1>

<h2>Configuration</h2>
<p>Settings for connecting to MySQL and Google OAuth 2.0.</p>
<?php

if( !$isConfigured ) {
echo '<p>Configuration file is missing</p>';
echo '<p><b>Status</b>: Configuration file is missing</p>';
echo '<p><a href="settings-configure.php">Create Configuration File</a></p>';
} else {
echo '<p>The configuration file is set.</p>';
echo '<p><b>Status</b>: The configuration file is set.</p>';
echo '<p><a href="settings-configure.php">Change Configuration</a></p>';
}
?>
<hr>
Expand All @@ -22,49 +60,18 @@

<form action="<?PHP echo $_SERVER['SCRIPT_NAME'] ?>" method="post">
<?php
/* Get list of sites */
$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>';
}

/* 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'=>$siteToAdd), array('data'=>0) );
if( $response ) {
$siteSettings[$value['url']] = NULL;
}
}
}
}
?>

<ul id="sites_google">
<?php if( $sitesList ) { ?>
<?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>
<li><input type="checkbox" name="sites_google[]" value="<?php echo $value['url'] ?>" <?php if($siteSettings[$value['url']]==1){echo " checked";}?> /><?php echo $value['url'] ?></li>
<?php } ?>
<?php } ?>
</ul>
<input type="hidden" id="save" name="save" value="true" />
<input type="submit" value="Save Settings">

</form>
Expand Down

0 comments on commit 28e551d

Please sign in to comment.