Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Integrate AddThis on blog. Centralize addthis and google analytics co…

…nfiguration
  • Loading branch information...
commit 587f2ac97d3161e051dc962f0c4176e752b10e5b 1 parent 6e9dbaa
@benoitg benoitg authored
View
6 apps/forum/templates/forum/base.html
@@ -130,11 +130,11 @@
{{ include_django("sites_specs.html", request) }}
- {% if not debug %}
+ {% if GOOGLE_ANALYTICS_ACCOUNT and not debug %}
<script type="text/javascript">
var _gaq = _gaq || [];
- _gaq.push(["_setAccount", "UA-21778007-2"]);
- _gaq.push(["_setDomainName", "imaginationforpeople.org"]);
+ _gaq.push(["_setAccount", "{{GOOGLE_ANALYTICS_ACCOUNT}}"]);
+ _gaq.push(["_setDomainName", "{{ site.domain }}"]);
_gaq.push(["_trackPageview"]);
(function() {
View
16 apps/i4p_base/context_processors.py
@@ -18,6 +18,7 @@
from haystack.forms import SearchForm
from apps.project_sheet.utils import get_project_translations_from_parents, build_filters_and_context
+from site_settings import *
def search_form(request):
additions = {
@@ -28,7 +29,20 @@ def search_form(request):
additions.update(filter_forms)
return additions
-
+def settings(request):
+ additions = {}
+
+ try:
+ additions['ADDTHIS_USERNAME'] = ADDTHIS_USERNAME
+ except NameError:
+ additions['ADDTHIS_USERNAME'] = None
+
+ try:
+ additions['GOOGLE_ANALYTICS_ACCOUNT'] = GOOGLE_ANALYTICS_ACCOUNT
+ except NameError:
+ additions['GOOGLE_ANALYTICS_ACCOUNT'] = None
+
+ return additions
View
32 apps/i4p_base/templates/addthis.html
@@ -0,0 +1,32 @@
+{% load i18n %}
+{% load sekizai_tags %}
+
+{% addtoblock "js" strip %}
+<script type="text/javascript">
+var addthis_config =
+{
+ {% if ADDTHIS_USERNAME %}
+ username: '{{ADDTHIS_USERNAME}}',
+ {% endif %}
+ {% if GOOGLE_ANALYTICS_ACCOUNT %}
+ data_ga_property: '{{GOOGLE_ANALYTICS_ACCOUNT}}',
+ {% endif %}
+ {% get_current_language as LANGUAGE_CODE %}
+ ui_language: '{{LANGUAGE_CODE|truncatechars:2 }}'
+}
+</script>
+{% endaddtoblock %}
+
+{% addtoblock "footer_js" strip %}
+<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#async=1"></script>
+{% endaddtoblock %}
+
+{% addtoblock "footer_js" strip %}
+<script type="text/javascript">
+// load only when all assets are ready
+$(window).load(function() {
+// Addthis
+addthis.init();
+});
+</script>
+{% endaddtoblock %}
View
6 apps/i4p_base/templates/base.html
@@ -152,11 +152,11 @@
{% include "sites_specs.html" %}
- {% if not debug %}
+ {% if GOOGLE_ANALYTICS_ACCOUNT and not debug %}
<script type="text/javascript">
var _gaq = _gaq || [];
- _gaq.push(["_setAccount", "UA-21778007-2"]);
- _gaq.push(["_setDomainName", "imaginationforpeople.org"]);
+ _gaq.push(["_setAccount", "{{GOOGLE_ANALYTICS_ACCOUNT}}"]);
+ _gaq.push(["_setDomainName", "{{ site.domain }}"]);
_gaq.push(["_trackPageview"]);
(function() {
View
9 apps/project_sheet/templates/project_sheet/layout/project_base.html
@@ -26,7 +26,7 @@
{% block content %}
{% addtoblock "js" strip %}
{% endaddtoblock %}
-
+{% include "addthis.html" %}
{% addtoblock "js" strip %}
{% if project_translation %}
<script>
@@ -36,12 +36,6 @@
twitter : "{{ project_translation.title }} : {{ project_translation.baseline }} | Imagination for People : http://imaginationforpeople.org{% language project_translation.language_code %}{% url project_sheet-show project_translation.slug %}{% endlanguage %} (via @ipvoices)"
}
}
-
- // load only when all assets are ready
- $(window).load(function() {
- // Addthis
- addthis.init();
- });
</script>
{% endif %}
@@ -65,5 +59,4 @@
{% block project_content %}{% endblock %}
</div>
-<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#async=1"></script>
{% endblock %}
View
1  settings.py
@@ -174,6 +174,7 @@
'django.core.context_processors.static',
'apps.i4p_base.context_processors.search_form',
+ 'apps.i4p_base.context_processors.settings',
'apps.member.context_processors.member_forms',
'cms.context_processors.media',
View
7 site_settings.py.sample
@@ -24,9 +24,16 @@ DATABASES = {
# If you're using a dev server, just use '/site_media/'
MEDIA_URL = 'http://imaginationforpeople.org/site_media/'
+#Optional, leave None if you don't have/don't want to use a AddThis account.
+#Addthis will still work without it
+ADDTHIS_USERNAME = None
+
FACEBOOK_APP_ID = "TO_COMPLETE"
FACEBOOK_API_SECRET = "TO_COMPLETE"
+# Optional, leave None if you don't have a google analytics account
+GOOGLE_ANALYTICS_ACCOUNT = None #Example: UA-21778007-2
+
GOOGLE_OAUTH2_CLIENT_ID = "TO_COMPLETE"
GOOGLE_OAUTH2_CLIENT_SECRET = "TO_COMPLETE"
View
21 static/sass/zinnia-i4p.scss
@@ -67,7 +67,7 @@ body .zinnia {
}
.entry-body {
img {
- max-width: 35%;
+ max-width: 35%;
}
.entry-excerpt {
display: none;
@@ -81,6 +81,12 @@ body .zinnia {
display: none;
}
}
+ .entry-footer {
+ .addthis_toolbox {
+ margin-top: 1.5em;
+ margin-bottom: 1em;
+ }
+ }
form legend {
@include i4p-font-base($sizeTextZinnia);
@@ -93,6 +99,16 @@ body.entry-list {
max-height: 120px;
}
}
+ .entry-footer {
+ .entry-addthis {
+ text-align: right;
+ .addthis_toolbox {
+ display: inline-block;
+ margin-top: 0em;
+ margin-bottom: 0em;
+ }
+ }
+ }
.continue-reading {
text-align: right;
margin-top: -6px;
@@ -124,6 +140,9 @@ body.zinniai4p {
#trackbacks{
display: none;
}
+ .entry-shorturl {
+ display: none;
+ }
.entry-next, .entry-previous {
display: none;
}
View
22 templates/zinnia/_entry_detail.html
@@ -0,0 +1,22 @@
+{% extends "zinnia/_entry_detail_base.html" %}
+
+ {% block entry-tags %}
+ {% include "addthis.html" %}
+ {% comment %}We extend entry-tags because it's the first footer block {% endcomment %}
+ <div class="entry-addthis">
+ <div class="addthis_toolbox addthis_default_style"
+ addthis:url="http://{{ site.domain }}{{ object.get_absolute_url }}"
+ addthis:title="{{ object.title }}"
+ {% if object.excerpt != "..." %}
+ addthis:description="{{ object.excerpt }}"
+ {% endif %}
+ >
+ <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
+ <a class="addthis_button_tweet"></a>
+ <a class="addthis_button_google_plusone" g:plusone:size="medium"></a>
+ <a class="addthis_counter addthis_pill_style" style="cursor:pointer"></a>
+ </div>
+ </div>
+ {{ block.super }}
+
+ {% endblock %}
Please sign in to comment.
Something went wrong with that request. Please try again.