diff --git a/pari/album/static/album/js/album_embed.js b/pari/album/static/album/js/album_embed.js
new file mode 100644
index 0000000..c888db6
--- /dev/null
+++ b/pari/album/static/album/js/album_embed.js
@@ -0,0 +1,13 @@
+(function() {
+ var sc = document.createElement("script");
+ function cb(data) {
+ var holder = document.getElementById(__pariAlbum.widgetId);
+ holder.innerHTML = data.html;
+ }
+ window.pariAlbumParseResponse = cb;
+ sc.src = "//www.ruralindiaonline.org/albums/talking/embed/?url=" + encodeURIComponent(__pariAlbum.url)
+ + "&width=" + __pariAlbum.widgetWidth
+ + "&height=" + __pariAlbum.widgetHeight
+ + "&callback=pariAlbumParseResponse";
+ document.body.appendChild(sc);
+})();
diff --git a/pari/album/templates/album/album_detail.html b/pari/album/templates/album/album_detail.html
index e50bf18..63d47cd 100644
--- a/pari/album/templates/album/album_detail.html
+++ b/pari/album/templates/album/album_detail.html
@@ -13,11 +13,24 @@
{% block extra_uncompressed_js %}
+ {% if embed %}
+
+ {% endif %}
{% endblock %}
{% block extra_css %}
+
{% endblock %}
{% block main %}
@@ -79,4 +92,4 @@
{{ album.title }}
{% endfor %}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/pari/album/urls.py b/pari/album/urls.py
index 759ab99..d7a1b6c 100644
--- a/pari/album/urls.py
+++ b/pari/album/urls.py
@@ -8,6 +8,8 @@
urlpatterns = patterns('pari.album.views',
url(r'^$', AlbumList.as_view(), {'albums': get_all_albums}, name='album-list'),
url(r'^talking/$', AlbumList.as_view(), {'albums': get_talking_albums}, name='talking-album-list'),
+ url(r'^talking/embed/$', 'embed_talking_album', name='embed-talking-album'),
+ url(r'^talking/embed/(?P\d+)/$', 'embed_talking_album_detail', name='embed-talking-album-detail'),
url(r'^other/$', AlbumList.as_view(), {'albums': get_other_albums}, name='other-album-list'),
url(r'^(?P.+)/$', AlbumDetail.as_view(), name='album-detail'),
diff --git a/pari/album/views.py b/pari/album/views.py
index 7017803..4b7ce5e 100644
--- a/pari/album/views.py
+++ b/pari/album/views.py
@@ -1,6 +1,14 @@
from django.views.generic import DetailView, ListView
from pari.album.models import Album, AlbumImage, ImageCollectionImage
+import json
+from django.http import HttpResponse
+from django.contrib.sites.models import RequestSite
+from django.core.urlresolvers import reverse
+from django.shortcuts import render, get_object_or_404
+
+from mezzanine.conf import settings
+
class AlbumList(ListView):
model = Album
@@ -32,3 +40,55 @@ class ImageCollectionImageList(DetailView):
def get_object(self, queryset=None):
album = Album.objects.get(slug=self.kwargs['slug'])
return album.image_collection.images
+
+
+def embed_talking_album(request):
+ url = request.GET.get("url")
+ # http://www.ruralindiaonline.org/albums/the-green-army/
+ slug = filter(lambda x: x, url.split("/"))[-1]
+ album = Album.objects.get(slug=slug)
+ is_request_secure = request.is_secure()
+ domain = RequestSite(request).domain
+ album_embed_url = "http{0}://{1}{2}".format(
+ "s" if is_request_secure else "",
+ domain,
+ reverse("embed-talking-album-detail", kwargs={"id": album.id})
+ )
+ author_url = "http{0}://{1}".format(
+ "s" if is_request_secure else "",
+ domain,
+ album.photographer.get_absolute_url()
+ )
+ width = request.GET.get("width", "1024")
+ height = request.GET.get("height", "768")
+ response = json.dumps({
+ "type": "rich",
+ "version": 1.0,
+ "title": album.title,
+ "author_name": album.photographer.title,
+ "author_url": author_url,
+ "provider_name": settings.SITE_FULL_TITLE,
+ "provider_url": "http{0}://{1}/".format(
+ "s" if is_request_secure else "",
+ domain
+ ),
+ "html": """""".format(
+ album_embed_url,
+ width, height
+ ),
+ "width": width,
+ "height": height
+ })
+ content_type = "application/json"
+ if request.GET.get("callback"):
+ response = "{0}({1})".format(request.GET["callback"], response)
+ content_type = "application/javascript"
+ return HttpResponse(response, content_type=content_type)
+
+
+def embed_talking_album_detail(request, id=None):
+ album = get_object_or_404(Album, id=id)
+ return render(request, "album/album_detail.html", {
+ "album": album,
+ "embed": True
+ })