Skip to content

Commit

Permalink
Added easy share with Twitter and Facebook links to ur.ly result page…
Browse files Browse the repository at this point in the history
… and update bookmarklet to send document title

git-svn-id: https://urly.googlecode.com/svn/trunk@10 4bb6f403-2351-0410-a0e4-d75a30d34d26
  • Loading branch information
adam@stilesoft.com committed Oct 27, 2009
1 parent 706ab60 commit ee59342
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
11 changes: 7 additions & 4 deletions main.html
Expand Up @@ -12,21 +12,23 @@
<script type="text/javascript" src="static/urly.js"></script>
</head>
<body style="font-family: verdana, arial; font-size: 80%; text-align: center">
<div style="margin: 0 auto; width: 600px; border: 1px solid #cccccc; padding: 10px; text-align: left;">
<div style="margin: 0 auto; width: 600px; border: 1px solid #efefef; padding: 20px; text-align: left;">

<span style="float: right"><a href="http://code.google.com/appengine/"><img border="0" src="http://code.google.com/appengine/images/appengine-noborder-120x30.gif" /></a></span>
<a href="/"><img border="0" style="padding-top: 3px;" src="static/urly.gif" alt=" - dang short urls" /></a>

{% if error_404 or urly or error_href %}
<div style="margin-top: 5px; margin-bottom: 15px; padding: 10px; background-color: #e6e6ff; border: 1px dashed #cccccc;">
<div style="margin-top: 5px; margin-bottom: 15px; padding: 10px; background-color: #efefff; border: 1px dashed #cccccc;">
{% if error_404 %}Oops - we couldn't find that urly.{% endif %}
{% if error_href %}Oops - that address doesn't look right... we can't create a dang short url from it.{% endif %}
{% if urly %}
{{ urly.href }} is now dang short, and <b>its already on your clipboard</b>.<br />
<input id="href" name="href" type="text" style="margin-top: 5px; padding: 3px; width: 300px; border: 1px solid #cccccc;" value="http://ur.ly/{{ urly.code }}" />
<script type="text/javascript" language="javascript">window.onload = copy("http://ur.ly/{{ urly.code }}");</script>
<script type="text/javascript" language="javascript">window.onload = focus("href");</script>
&nbsp;&nbsp;<a href="http://ur.ly/{{ urly.code }}">Try It</a>
<div style="margin-top:5px">
<a href="http://ur.ly/{{ urly.code }}">Try your ur.ly</a> or share on <a href="http://twitter.com/home?status={{ title|urlencode }}+http%3A%2F%2Fur.ly%2F{{ urly.code }}">Twitter</a> or <a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fur.ly%2F{{ urly.code }}&t={{ title|urlencode }}">Facebook</a>
</div>
{% endif %}
</div>
{% endif %}
Expand All @@ -36,7 +38,8 @@
<textarea style="margin-bottom: 5px; width: 100%; border: 1px solid #cccccc;" name="href" id="href" rows="4">{{ default_href }}</textarea>
<input type="submit" value="Create" />
</form>
<div style="margin-top: 10px; padding-top: 5px; border-top: 1px solid #dddddd;"><span style="float: right"><a href="http://code.google.com/p/urly/">Project</a> <a href="http://code.google.com/p/urly/wiki/APIDocumentation">API</a></span>Drag this link to your browser toolbar: <a href="javascript:location.href='http://ur.ly/new.html?href='+encodeURIComponent(location.href)">ur.ly!</a></div>
<div style="margin-top: 10px; padding-top: 5px; border-top: 1px solid #f1f1f1;"><span style="float: right"><a href="http://code.google.com/p/urly/">Project</a> <a href="http://code.google.com/p/urly/wiki/APIDocumentation">API</a></span>Drag this link to your browser toolbar:&nbsp;
<a href="javascript:location.href='http://ur.ly/new.html?href='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title)">ur.ly!</a></div>
</div>
</div>
<script type="text/javascript">
Expand Down
5 changes: 3 additions & 2 deletions main.py
Expand Up @@ -44,12 +44,13 @@ def get(self, code, format):
MainView.render(self, 200, None, format)
return

href = self.request.get('href').strip()
href = self.request.get('href').strip().encode('utf-8')
title = self.request.get('title').strip().encode('utf-8')
if (code == 'new') and (href is not None):
try:
u = Urly.find_or_create_by_href(href)
if u is not None:
MainView.render(self, 200, u, format)
MainView.render(self, 200, u, format, href, title)
else:
logging.error("Error creating urly by href: %s", str(href))
MainView.render(self, 400, None, format, href)
Expand Down
4 changes: 2 additions & 2 deletions view.py
Expand Up @@ -13,7 +13,7 @@
class MainView():
"""Helper method for our one-and-only template. All display goes through here"""
@staticmethod
def render(handler, status, urly, format, href=None):
def render(handler, status, urly, format, href=None, title=None):
"""Lovin my delphi-like inner functions"""
def render_raw(handler, content_type, body):
handler.response.headers["Content-Type"] = content_type
Expand All @@ -34,7 +34,7 @@ def render_main(handler, values=None):
elif (format == '.txt'):
render_raw(handler, "text/plain", urly.to_text())
else:
render_main(handler, { 'urly': urly })
render_main(handler, { 'urly': urly, 'title': title })
elif (status == 400):
handler.error(status)
if (format != '.json') and (format != '.xml'):
Expand Down

0 comments on commit ee59342

Please sign in to comment.