Author Topic: Google tools  (Read 1369 times)

blueeyeddevil

  • Active Member
  • ***
  • Posts: 43
  • Karma: +3/-0
Google tools
« on: January 03, 2015, 03:57:30 AM »
Simple modification that gives ability to use Google Analytics, Google Webmaster tools, or Google reCaptcha. I would recommend to make it built in feature for future releases of Etano as today are those tools used by every website. I was trying to create package but always kept getting error "Unknown diff marker" so I am posting modifications I made to single files

First of all run following SQL against your database:
Code: [Select]
INSERT INTO `dsb_site_options3` (`config_option`,`config_value`,`config_diz`,`option_type`,`choices`,`fk_module_code`,`per_user`) VALUES
('google_sec_key','','Your Google reCaptcha secret key',2,'','core','0'),
('google_site_key','','Your Google reCaptcha site key',2,'','core','0'),
('google_webmaster','','Your Google webmaster code',2,'','core','0'),
('google_analytics','','Your Google analytics code',2,'','core','0');

Open file ROOT/frame.php
FIND:
Code: [Select]
$tpl->set_file('frame','frame.html');
BEFORE ADD:
Code: [Select]
if(get_site_option('google_webmaster','core')!=''){
$tpl->set_var('googleWebmaster',get_site_option('google_webmaster','core'));
}
if(get_site_option('google_analytics','core')!=''){
$tpl->set_var('googleAnalytics',get_site_option('google_analytics','core'));
}
Save & Close file ROOT/frame.php

Open file ROOT/index.php
FIND:
Code: [Select]
$tplvars['title']=$tplvars['sitename'];
BEFORE ADD:
Code: [Select]
if(get_site_option('google_webmaster','core')!=''){
$tpl->set_var('googleWebmaster',get_site_option('google_webmaster','core'));
}
if(get_site_option('google_analytics','core')!=''){
$tpl->set_var('googleAnalytics',get_site_option('google_analytics','core'));
}
Save & Close file ROOT/index.php

Open file ROOT/join.php
FIND:
Code: [Select]
require _BASEPATH_.'/includes/classes/sco_captcha.class.php';
$c=new sco_captcha(_BASEPATH_.'/includes/fonts',4);
$_SESSION['captcha_word']=$c->gen_rnd_string(4);
$output['rand']=make_seed();
REPLACE WITH:
Code: [Select]
$siteKey = get_site_option('google_site_key','core');
$tpl->set_var('siteKey',$siteKey);
Save & Close file ROOT/join.php

Open file ROOT/processors/join.php
FIND:
Code: [Select]
$captcha=sanitize_and_format_gpc($_POST,'captcha',TYPE_STRING,$__field2format[FIELD_TEXTFIELD],'');
if (!$error && (!isset($_SESSION['captcha_word']) || strcasecmp($captcha,$_SESSION['captcha_word'])!=0)) {
REPLACE WITH:
Code: [Select]
$captcha=sanitize_and_format_gpc($_POST,'g-recaptcha-response',TYPE_STRING,$__field2format[FIELD_TEXTFIELD],'');
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".get_site_option('google_sec_key','core')."&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
$response = json_decode($response);
if (!$error && (!$captcha || $response->{'success'}==false)) {
FIND & REMOVE:
Code: [Select]
unset($_SESSION['captcha_word']);
Save & Close file ROOT/processors/join.php

Open file ROOT/skins_site/def/frame.html
FIND:
Code: [Select]
<title>{tplvars.title} - {tplvars.sitename}</title>
BEFORE ADD:
Code: [Select]
<!--opt name="googleWebmaster"--><meta name="google-site-verification" content="{googleWebmaster}" /><!--/opt name="googleWebmaster"-->
FIND:
Code: [Select]
</body>
BEFORE ADD:
Code: [Select]
<!--opt name="googleAnalytics"-->
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', '{googleAnalytics}', 'auto');
  ga('send', 'pageview');

</script>
<!--/opt name="googleAnalytics"-->
Save & Close file ROOT/skins_site/def/frame.html

Open file ROOT/skins_site/def/index.html
FIND:
Code: [Select]
<title>{tplvars.title} - {tplvars.sitename}</title>
BEFORE ADD:
Code: [Select]
<!--opt name="googleWebmaster"--><meta name="google-site-verification" content="{googleWebmaster}" /><!--/opt name="googleWebmaster"-->
FIND:
Code: [Select]
</body>
BEFORE ADD:
Code: [Select]
<!--opt name="googleAnalytics"-->
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', '{googleAnalytics}', 'auto');
  ga('send', 'pageview');

</script>
<!--/opt name="googleAnalytics"-->
Save & Close file ROOT/skins_site/def/index.html

Open file ROOT/skins_site/def/join.html
FIND:
Code: [Select]
<dl class="required">
<dt>Verify registration:</dt>
<dd><img src="{tplvars.relative_url}show_captcha.php?{output.rand}" /></dd>
</dl>
<dl>
<dt>&nbsp;</dt>
<dd><input type="text" name="captcha" id="captcha" size="4" tabindex="50" /> <span class="field-help">Enter the characters from above.</span></dd>
</dl>
REPLACE WITH:
Code: [Select]
<div class="g-recaptcha" data-sitekey="{siteKey}"></div>
<script type="text/javascript"src="https://www.google.com/recaptcha/api.js?hl=en"></script>
Save & Close file ROOT/skins_site/def/join.html

Don't forget to register with google webmasters, analytics, and recaptcha and obtain Your site ID for Analytics, your site verification code from Google Webmasters and secret key and site ket from Google reCaptcha. All those identifiers fill in your Etano administration area under Features and Options.

Marble

  • Global Moderator
  • Veteran Member
  • *****
  • Posts: 1004
  • Karma: +56/-7
Re: Google tools
« Reply #1 on: January 11, 2015, 07:56:39 PM »
I tried this out and I certainly do like it as it's more evolved than the original captcha. I kept my bot trap active as another level of protection. Thanks for the contribution!
If you see that I'm logged in forever... it just means I turned the page on my browser and forgot to logout.

blueeyeddevil

  • Active Member
  • ***
  • Posts: 43
  • Karma: +3/-0
Re: Google tools
« Reply #2 on: January 11, 2015, 08:22:21 PM »
reCaptcha is live project it is always updated. the best thing about it is that you don't need to do anything to get the latest as latest version is automatically used in frame that is opened by .js file. There is also option to style it with css to match your template

Etenity63

  • Prime Member
  • ****
  • Posts: 119
  • Karma: +0/-0
Re: Google tools
« Reply #3 on: December 15, 2016, 11:51:52 AM »
I have followed the instructions but I still have this error message:

Code: [Select]
The verification code does not match. Please enter the new code.
I despair....

could you help me please?

I filled out

Quote
Your secret key reCaptcha Google: OK

Your Google Site Key ReCaptcha: OK

Except: Your code webmaster Google: google1dac38xxxxxx.html

Your Google Analytics code: OK (UA-8905xxxx-1)
I do not know if I got the right CaptCha code?
But each time he tells me that the code of "The verification code does not match, please enter the new code."

blueeyeddevil

  • Active Member
  • ***
  • Posts: 43
  • Karma: +3/-0
Re: Google tools
« Reply #4 on: February 04, 2017, 09:39:00 AM »
sorry for late reply. you probably put name of html file to field in administration. there are 3 ways how to verify website. Upload file, add meta tag or some more. to make it work just choose meta tag and put to field in administration only that code from content attribute