2015-07-28 22:44:53 +02:00
|
|
|
|
# Copyright (C) 2011–2015 Alex Schroeder <alex@gnu.org>
|
2015-06-27 20:22:55 +02:00
|
|
|
|
#
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify it under
|
|
|
|
|
|
# the terms of the GNU General Public License as published by the Free Software
|
|
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
|
|
# version.
|
|
|
|
|
|
#
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
#
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
# use warnings;
|
|
|
|
|
|
use v5.10;
|
|
|
|
|
|
|
|
|
|
|
|
AddModuleDescription('google-plus-one.pl', 'Google Plus One Module');
|
|
|
|
|
|
|
PrintFooter relies on @MyFooters
We already called all the subs on @MyFooters and printed the result,
but this commit moves all the code from PrintFooters into subs and
puts those subs on @MyFooters. This allows us to write modules that
can better control where exactly their output should appear. In this
case the change was required in order to allow the Google +1 module to
coexist with code that maybe prints the comment form for all pages.
For example, knowing that the Google +1 sub is the first on one the
list because of unshift(@MyFooters, \&GooglePlusPrintFooter), we can
now write the following:
splice(@MyFooters, 1, 0, \&MyCommentsInTheFooter);
sub MyCommentsInTheFooter {
my ($id, $rev, $comment) = @_;
if (not $GooglePlusThisPagePrintedJournal
and (GetParam('action', 'browse') eq 'browse'
and $id and $CommentsPrefix
and $id ne $RCName
and $id !~ /^$CommentsPrefix(.*)/o)) {
my $target = $CommentsPrefix . $id;
my $page = '';
$page = PageHtml($target) if $IndexHash{$target};
return $q->div({-class=>'comment'},
$q->h2(T('Comments')),
$page)
. GetCommentForm("$CommentsPrefix$id", $rev, $comment);
}
}
The Google +1 extension was also fixed to not triger the EFF's Privacy
Badger. This is OK because we're using a two step button: The user
needs to click a button before we're loading the script from Google.
2015-08-17 13:39:34 +02:00
|
|
|
|
our ($q, $RCName, @MyFooters, @MyAdminCode, %Action, @MyInitVariables, $CommentsPrefix);
|
2015-06-27 20:22:55 +02:00
|
|
|
|
|
|
|
|
|
|
my $data_uri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEwAAAAYCAMAAABnVuv4AAAAhFBMVEUAAAD////MzMz5+fkWau+zs7Pg4OD39/fh4eHu7u7z8/Pk5OTm5ubX19fx8fHj4+N+fn5jY2Ojo6N/f3/r7Ov29vbq6ero6Oj19fUVau0XafC3zO3q6ulKie2dve89ge1yoexkmeyNsepZk+/T3u4weu4jcu7E1Ox9p+rExMTX4vLi6PBsAh6oAAAAAXRSTlMAQObYZgAAAWtJREFUOMvFldluwjAQRU24LgHTpAsEgglL2Nv//7/OeGLLqlTXD5V6HM/c2NJRMJGilClSGCW8DbwEXgPvA+QqRylKI66kLNiKUZri72X6OQOdKxtn8E+yCTMOjQdBhbvEbNkkA5EBoJKULdc0ltHksv447ZaM7JJMNO1PstLZ9Gw2W9PgSxJXe4V1QZZIxiIGI4AbWs5hso1lFY0BwLXzEcBnWK8qJ9uIDKxlMbjyKnex6SoCcO2CKy7xupxZG57GKSBBbsSmp56btYC1t+l5v9vhNI0QmZyZVC+DPKa4IlkHR8f5gD4hQyzb0AhntvAcuo5U3YHzvrWLCJZFmlZ+pp/Rv9k022a75do0ABWKHCTJ9e0923Bmn6ij92xOrAaA1YpvLPZzCrJO+yxLE2Rm7rnfpfc4UjV+x2TLzEBtAvURvYnIl9UDJU8qcsmSL9myMoNs2VMGWtVZHxT9+N310ErVRYpaCToD9QXtvTL0OWiBLQAAAABJRU5ErkJggg==';
|
|
|
|
|
|
|
PrintFooter relies on @MyFooters
We already called all the subs on @MyFooters and printed the result,
but this commit moves all the code from PrintFooters into subs and
puts those subs on @MyFooters. This allows us to write modules that
can better control where exactly their output should appear. In this
case the change was required in order to allow the Google +1 module to
coexist with code that maybe prints the comment form for all pages.
For example, knowing that the Google +1 sub is the first on one the
list because of unshift(@MyFooters, \&GooglePlusPrintFooter), we can
now write the following:
splice(@MyFooters, 1, 0, \&MyCommentsInTheFooter);
sub MyCommentsInTheFooter {
my ($id, $rev, $comment) = @_;
if (not $GooglePlusThisPagePrintedJournal
and (GetParam('action', 'browse') eq 'browse'
and $id and $CommentsPrefix
and $id ne $RCName
and $id !~ /^$CommentsPrefix(.*)/o)) {
my $target = $CommentsPrefix . $id;
my $page = '';
$page = PageHtml($target) if $IndexHash{$target};
return $q->div({-class=>'comment'},
$q->h2(T('Comments')),
$page)
. GetCommentForm("$CommentsPrefix$id", $rev, $comment);
}
}
The Google +1 extension was also fixed to not triger the EFF's Privacy
Badger. This is OK because we're using a two step button: The user
needs to click a button before we're loading the script from Google.
2015-08-17 13:39:34 +02:00
|
|
|
|
# Make sure journal pages set a global variable which we then use to
|
|
|
|
|
|
# hide the +1 button.
|
2015-06-27 20:22:55 +02:00
|
|
|
|
|
PrintFooter relies on @MyFooters
We already called all the subs on @MyFooters and printed the result,
but this commit moves all the code from PrintFooters into subs and
puts those subs on @MyFooters. This allows us to write modules that
can better control where exactly their output should appear. In this
case the change was required in order to allow the Google +1 module to
coexist with code that maybe prints the comment form for all pages.
For example, knowing that the Google +1 sub is the first on one the
list because of unshift(@MyFooters, \&GooglePlusPrintFooter), we can
now write the following:
splice(@MyFooters, 1, 0, \&MyCommentsInTheFooter);
sub MyCommentsInTheFooter {
my ($id, $rev, $comment) = @_;
if (not $GooglePlusThisPagePrintedJournal
and (GetParam('action', 'browse') eq 'browse'
and $id and $CommentsPrefix
and $id ne $RCName
and $id !~ /^$CommentsPrefix(.*)/o)) {
my $target = $CommentsPrefix . $id;
my $page = '';
$page = PageHtml($target) if $IndexHash{$target};
return $q->div({-class=>'comment'},
$q->h2(T('Comments')),
$page)
. GetCommentForm("$CommentsPrefix$id", $rev, $comment);
}
}
The Google +1 extension was also fixed to not triger the EFF's Privacy
Badger. This is OK because we're using a two step button: The user
needs to click a button before we're loading the script from Google.
2015-08-17 13:39:34 +02:00
|
|
|
|
*OldGooglePlusPrintJournal = \&PrintJournal;
|
|
|
|
|
|
*PrintJournal = \&NewGooglePlusPrintJournal;
|
2015-06-27 20:22:55 +02:00
|
|
|
|
|
PrintFooter relies on @MyFooters
We already called all the subs on @MyFooters and printed the result,
but this commit moves all the code from PrintFooters into subs and
puts those subs on @MyFooters. This allows us to write modules that
can better control where exactly their output should appear. In this
case the change was required in order to allow the Google +1 module to
coexist with code that maybe prints the comment form for all pages.
For example, knowing that the Google +1 sub is the first on one the
list because of unshift(@MyFooters, \&GooglePlusPrintFooter), we can
now write the following:
splice(@MyFooters, 1, 0, \&MyCommentsInTheFooter);
sub MyCommentsInTheFooter {
my ($id, $rev, $comment) = @_;
if (not $GooglePlusThisPagePrintedJournal
and (GetParam('action', 'browse') eq 'browse'
and $id and $CommentsPrefix
and $id ne $RCName
and $id !~ /^$CommentsPrefix(.*)/o)) {
my $target = $CommentsPrefix . $id;
my $page = '';
$page = PageHtml($target) if $IndexHash{$target};
return $q->div({-class=>'comment'},
$q->h2(T('Comments')),
$page)
. GetCommentForm("$CommentsPrefix$id", $rev, $comment);
}
}
The Google +1 extension was also fixed to not triger the EFF's Privacy
Badger. This is OK because we're using a two step button: The user
needs to click a button before we're loading the script from Google.
2015-08-17 13:39:34 +02:00
|
|
|
|
my $GooglePlusThisPagePrintedJournal;
|
|
|
|
|
|
|
|
|
|
|
|
push(@MyInitVariables, sub {
|
|
|
|
|
|
$GooglePlusThisPagePrintedJournal = 0;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
sub NewGooglePlusPrintJournal {
|
|
|
|
|
|
$GooglePlusThisPagePrintedJournal = 1;
|
|
|
|
|
|
return OldGooglePlusPrintJournal(@_);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Use a two step Google +1 button to protect your privacy: show this
|
|
|
|
|
|
# at the bottom of every page but not on comment pages, Recent
|
|
|
|
|
|
# changes, and pages that printed a journal.
|
|
|
|
|
|
|
|
|
|
|
|
unshift(@MyFooters, \&GooglePlusPrintFooter);
|
|
|
|
|
|
|
|
|
|
|
|
sub GooglePlusPrintFooter {
|
|
|
|
|
|
my ($id, $rev, $comment) = @_;
|
|
|
|
|
|
if (not $GooglePlusThisPagePrintedJournal
|
|
|
|
|
|
and (GetParam('action', 'browse') eq 'plusone'
|
|
|
|
|
|
or (GetParam('action', 'browse') eq 'browse'
|
|
|
|
|
|
and $id
|
|
|
|
|
|
and $id ne $RCName
|
|
|
|
|
|
and (not $CommentsPrefix or $id !~ /^$CommentsPrefix(.*)/)))) {
|
|
|
|
|
|
return q{
|
|
|
|
|
|
<!-- start of Google+ -->
|
2015-06-27 20:22:55 +02:00
|
|
|
|
<script type="text/javascript">
|
2015-09-04 14:00:44 +02:00
|
|
|
|
function loadScript(jssource) {
|
PrintFooter relies on @MyFooters
We already called all the subs on @MyFooters and printed the result,
but this commit moves all the code from PrintFooters into subs and
puts those subs on @MyFooters. This allows us to write modules that
can better control where exactly their output should appear. In this
case the change was required in order to allow the Google +1 module to
coexist with code that maybe prints the comment form for all pages.
For example, knowing that the Google +1 sub is the first on one the
list because of unshift(@MyFooters, \&GooglePlusPrintFooter), we can
now write the following:
splice(@MyFooters, 1, 0, \&MyCommentsInTheFooter);
sub MyCommentsInTheFooter {
my ($id, $rev, $comment) = @_;
if (not $GooglePlusThisPagePrintedJournal
and (GetParam('action', 'browse') eq 'browse'
and $id and $CommentsPrefix
and $id ne $RCName
and $id !~ /^$CommentsPrefix(.*)/o)) {
my $target = $CommentsPrefix . $id;
my $page = '';
$page = PageHtml($target) if $IndexHash{$target};
return $q->div({-class=>'comment'},
$q->h2(T('Comments')),
$page)
. GetCommentForm("$CommentsPrefix$id", $rev, $comment);
}
}
The Google +1 extension was also fixed to not triger the EFF's Privacy
Badger. This is OK because we're using a two step button: The user
needs to click a button before we're loading the script from Google.
2015-08-17 13:39:34 +02:00
|
|
|
|
// add javascript
|
2015-06-27 20:22:55 +02:00
|
|
|
|
var jsnode = document.createElement('script');
|
|
|
|
|
|
jsnode.setAttribute('type','text/javascript');
|
|
|
|
|
|
jsnode.setAttribute('src',jssource);
|
|
|
|
|
|
document.getElementsByTagName('head')[0].appendChild(jsnode);
|
PrintFooter relies on @MyFooters
We already called all the subs on @MyFooters and printed the result,
but this commit moves all the code from PrintFooters into subs and
puts those subs on @MyFooters. This allows us to write modules that
can better control where exactly their output should appear. In this
case the change was required in order to allow the Google +1 module to
coexist with code that maybe prints the comment form for all pages.
For example, knowing that the Google +1 sub is the first on one the
list because of unshift(@MyFooters, \&GooglePlusPrintFooter), we can
now write the following:
splice(@MyFooters, 1, 0, \&MyCommentsInTheFooter);
sub MyCommentsInTheFooter {
my ($id, $rev, $comment) = @_;
if (not $GooglePlusThisPagePrintedJournal
and (GetParam('action', 'browse') eq 'browse'
and $id and $CommentsPrefix
and $id ne $RCName
and $id !~ /^$CommentsPrefix(.*)/o)) {
my $target = $CommentsPrefix . $id;
my $page = '';
$page = PageHtml($target) if $IndexHash{$target};
return $q->div({-class=>'comment'},
$q->h2(T('Comments')),
$page)
. GetCommentForm("$CommentsPrefix$id", $rev, $comment);
}
}
The Google +1 extension was also fixed to not triger the EFF's Privacy
Badger. This is OK because we're using a two step button: The user
needs to click a button before we're loading the script from Google.
2015-08-17 13:39:34 +02:00
|
|
|
|
// add button
|
|
|
|
|
|
var butn = document.createElement('div');
|
|
|
|
|
|
butn.setAttribute('class', 'g-plusone');
|
|
|
|
|
|
butn.setAttribute('id', 'my_plusone');
|
2015-09-04 14:00:44 +02:00
|
|
|
|
var link = document.getElementById('plus1');
|
PrintFooter relies on @MyFooters
We already called all the subs on @MyFooters and printed the result,
but this commit moves all the code from PrintFooters into subs and
puts those subs on @MyFooters. This allows us to write modules that
can better control where exactly their output should appear. In this
case the change was required in order to allow the Google +1 module to
coexist with code that maybe prints the comment form for all pages.
For example, knowing that the Google +1 sub is the first on one the
list because of unshift(@MyFooters, \&GooglePlusPrintFooter), we can
now write the following:
splice(@MyFooters, 1, 0, \&MyCommentsInTheFooter);
sub MyCommentsInTheFooter {
my ($id, $rev, $comment) = @_;
if (not $GooglePlusThisPagePrintedJournal
and (GetParam('action', 'browse') eq 'browse'
and $id and $CommentsPrefix
and $id ne $RCName
and $id !~ /^$CommentsPrefix(.*)/o)) {
my $target = $CommentsPrefix . $id;
my $page = '';
$page = PageHtml($target) if $IndexHash{$target};
return $q->div({-class=>'comment'},
$q->h2(T('Comments')),
$page)
. GetCommentForm("$CommentsPrefix$id", $rev, $comment);
}
}
The Google +1 extension was also fixed to not triger the EFF's Privacy
Badger. This is OK because we're using a two step button: The user
needs to click a button before we're loading the script from Google.
2015-08-17 13:39:34 +02:00
|
|
|
|
link.parentNode.insertBefore(butn, link);
|
|
|
|
|
|
// hide the link
|
|
|
|
|
|
link.innerHTML = "";
|
2015-09-04 14:00:44 +02:00
|
|
|
|
// when looking at action=plusone
|
|
|
|
|
|
var ul = document.getElementById('plus1s');
|
|
|
|
|
|
var children = ul.children;
|
|
|
|
|
|
for (var i = 0; i < children.length; i++) {
|
|
|
|
|
|
var li = children[i];
|
|
|
|
|
|
butn = document.createElement('g:plusone');
|
|
|
|
|
|
butn.setAttribute('href', li.firstElementChild.getAttribute('href'));
|
|
|
|
|
|
butn.setAttribute('id', 'my_plusone' + i);
|
|
|
|
|
|
li.appendChild(butn);
|
|
|
|
|
|
}
|
2015-06-27 20:22:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
PrintFooter relies on @MyFooters
We already called all the subs on @MyFooters and printed the result,
but this commit moves all the code from PrintFooters into subs and
puts those subs on @MyFooters. This allows us to write modules that
can better control where exactly their output should appear. In this
case the change was required in order to allow the Google +1 module to
coexist with code that maybe prints the comment form for all pages.
For example, knowing that the Google +1 sub is the first on one the
list because of unshift(@MyFooters, \&GooglePlusPrintFooter), we can
now write the following:
splice(@MyFooters, 1, 0, \&MyCommentsInTheFooter);
sub MyCommentsInTheFooter {
my ($id, $rev, $comment) = @_;
if (not $GooglePlusThisPagePrintedJournal
and (GetParam('action', 'browse') eq 'browse'
and $id and $CommentsPrefix
and $id ne $RCName
and $id !~ /^$CommentsPrefix(.*)/o)) {
my $target = $CommentsPrefix . $id;
my $page = '';
$page = PageHtml($target) if $IndexHash{$target};
return $q->div({-class=>'comment'},
$q->h2(T('Comments')),
$page)
. GetCommentForm("$CommentsPrefix$id", $rev, $comment);
}
}
The Google +1 extension was also fixed to not triger the EFF's Privacy
Badger. This is OK because we're using a two step button: The user
needs to click a button before we're loading the script from Google.
2015-08-17 13:39:34 +02:00
|
|
|
|
<p id="plus1">
|
2015-09-04 14:00:44 +02:00
|
|
|
|
<a href="javascript:loadScript('https://apis.google.com/js/plusone.js')">
|
PrintFooter relies on @MyFooters
We already called all the subs on @MyFooters and printed the result,
but this commit moves all the code from PrintFooters into subs and
puts those subs on @MyFooters. This allows us to write modules that
can better control where exactly their output should appear. In this
case the change was required in order to allow the Google +1 module to
coexist with code that maybe prints the comment form for all pages.
For example, knowing that the Google +1 sub is the first on one the
list because of unshift(@MyFooters, \&GooglePlusPrintFooter), we can
now write the following:
splice(@MyFooters, 1, 0, \&MyCommentsInTheFooter);
sub MyCommentsInTheFooter {
my ($id, $rev, $comment) = @_;
if (not $GooglePlusThisPagePrintedJournal
and (GetParam('action', 'browse') eq 'browse'
and $id and $CommentsPrefix
and $id ne $RCName
and $id !~ /^$CommentsPrefix(.*)/o)) {
my $target = $CommentsPrefix . $id;
my $page = '';
$page = PageHtml($target) if $IndexHash{$target};
return $q->div({-class=>'comment'},
$q->h2(T('Comments')),
$page)
. GetCommentForm("$CommentsPrefix$id", $rev, $comment);
}
}
The Google +1 extension was also fixed to not triger the EFF's Privacy
Badger. This is OK because we're using a two step button: The user
needs to click a button before we're loading the script from Google.
2015-08-17 13:39:34 +02:00
|
|
|
|
<img src="/pics/plusone-h24.png" alt="Show Google +1" />
|
|
|
|
|
|
</a>
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<!-- end of Google+ -->
|
2015-06-27 20:22:55 +02:00
|
|
|
|
};
|
PrintFooter relies on @MyFooters
We already called all the subs on @MyFooters and printed the result,
but this commit moves all the code from PrintFooters into subs and
puts those subs on @MyFooters. This allows us to write modules that
can better control where exactly their output should appear. In this
case the change was required in order to allow the Google +1 module to
coexist with code that maybe prints the comment form for all pages.
For example, knowing that the Google +1 sub is the first on one the
list because of unshift(@MyFooters, \&GooglePlusPrintFooter), we can
now write the following:
splice(@MyFooters, 1, 0, \&MyCommentsInTheFooter);
sub MyCommentsInTheFooter {
my ($id, $rev, $comment) = @_;
if (not $GooglePlusThisPagePrintedJournal
and (GetParam('action', 'browse') eq 'browse'
and $id and $CommentsPrefix
and $id ne $RCName
and $id !~ /^$CommentsPrefix(.*)/o)) {
my $target = $CommentsPrefix . $id;
my $page = '';
$page = PageHtml($target) if $IndexHash{$target};
return $q->div({-class=>'comment'},
$q->h2(T('Comments')),
$page)
. GetCommentForm("$CommentsPrefix$id", $rev, $comment);
}
}
The Google +1 extension was also fixed to not triger the EFF's Privacy
Badger. This is OK because we're using a two step button: The user
needs to click a button before we're loading the script from Google.
2015-08-17 13:39:34 +02:00
|
|
|
|
}
|
2015-06-27 20:22:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-07-28 10:47:21 +02:00
|
|
|
|
# Google +1 list
|
2015-06-27 20:22:55 +02:00
|
|
|
|
|
|
|
|
|
|
push(@MyAdminCode, sub {
|
|
|
|
|
|
my ($id, $menuref, $restref) = @_;
|
|
|
|
|
|
push(@$menuref, ScriptLink('action=plusone',
|
|
|
|
|
|
T('Google +1 Buttons'),
|
|
|
|
|
|
'plusone'));
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$Action{plusone} = \&DoPlusOne;
|
|
|
|
|
|
|
|
|
|
|
|
sub DoPlusOne {
|
|
|
|
|
|
print GetHeader('', T('All Pages +1'), ''),
|
|
|
|
|
|
$q->start_div({-class=>'content plusone'});
|
|
|
|
|
|
print $q->p(T("This page lists the twenty last diary entries and their +1 buttons."));
|
|
|
|
|
|
my @pages;
|
|
|
|
|
|
foreach my $id (AllPagesList()) {
|
|
|
|
|
|
push(@pages, $id) if $id =~ /^\d\d\d\d-\d\d-\d\d/;
|
|
|
|
|
|
}
|
2015-07-28 10:47:21 +02:00
|
|
|
|
splice(@pages, 0, $#pages - 19); # last 20 items
|
2015-09-04 14:00:44 +02:00
|
|
|
|
print '<ul id="plus1s">';
|
2015-06-27 20:22:55 +02:00
|
|
|
|
foreach my $id (@pages) {
|
2015-09-04 14:00:44 +02:00
|
|
|
|
print $q->li(GetPageLink($id), ' ');
|
2015-06-27 20:22:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
print "</ul>";
|
|
|
|
|
|
print $q->end_div();
|
|
|
|
|
|
PrintFooter();
|
|
|
|
|
|
}
|