Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 4ccea65f66cb5d407a1e91d201444f8cbddf47b5 0 parents
Benjamin Trott authored
115 bin/app.psgi
@@ -0,0 +1,115 @@
+#!/usr/bin/perl -w
+use strict;
+
+use lib '/Users/btrott/Documents/devel/faved-tp';
+use lib '/Users/btrott/Documents/devel/WWW-TypePad/lib';
+
+use Faved::Util;
+use List::Util qw( first );
+use Plack::App::File;
+use Plack::App::URLMap;
+use Plack::Builder;
+use Template;
+use WWW::TypePad;
+
+my $tt = Template->new( INCLUDE_PATH => 'templates' );
+my $tp = WWW::TypePad->new;
+
+my $error = sub {
+ my( $code, $html ) = @_;
+ return [
+ $code,
+ [ 'Content-Type', 'text/html' ],
+ [ $html ],
+ ];
+};
+
+sub is_verb {
+ my( $event, $verb ) = @_;
+ my $found = first { $_ eq $verb } @{ $event->{verbs} };
+ return $found ? 1 : 0;
+}
+
+sub is_type {
+ my( $asset, $type ) = @_;
+ my $found = first { $_ eq $type } @{ $asset->{objectTypes} };
+ return $found ? 1 : 0;
+}
+
+sub get_notifications {
+ my( $limit ) = @_;
+ my @events;
+ my $total;
+ do {
+ my $res = $tp->users->notifications(
+ '6p00d83455876069e2',
+ { 'start-index' => @events + 1 }
+ );
+ $total = $res->{totalResults};
+ push @events, @{ $res->{entries} };
+ } while ( @events < $limit && $total > @events );
+ return \@events;
+}
+
+my $dashboard = sub {
+ my $env = shift;
+
+ my $events = get_notifications( 100 );
+
+ my @assets;
+ my $dur = DateTime::Format::Human::Duration->new;
+ my $now = DateTime->now( time_zone => 'America/Los_Angeles' );
+ for my $event ( @$events ) {
+ next unless is_verb( $event, 'tag:api.typepad.com,2009:NewAsset' );
+
+ my $asset = $event->{object};
+ next unless
+ is_type( $asset, 'tag:api.typepad.com,2009:Post' ) ||
+ $asset->{groups} && @{ $asset->{groups} };
+
+ next if $asset->{source} && $asset->{source}{provider};
+
+ $asset->{author}{avatar_uri} =
+ Faved::Util->get_best_avatar_uri( $asset->{author}{links} );
+
+ my $dt = DateTime::Format::ISO8601->parse_datetime( $asset->{published} );
+
+ my( $type ) = $asset->{objectTypes}[0] =~ /(\w+)$/;
+ my $permalink_rel_type = $type eq 'Link' ? 'target' : 'alternate';
+ my $link = first { $_->{rel} eq $permalink_rel_type } @{ $asset->{links} };
+
+ my $data = Faved::Util->get_content_data( $type, $asset->{content}, $asset->{links} );
+
+ push @assets, {
+ author => $asset->{author},
+ content => $data,
+ permalink => $link->{href},
+ published => $dur->format_duration_between( $now, $dt ),
+ };
+ }
+
+ my $param = $env->{QUERY_STRING} ?
+ CGI::Deurl::XS::parse_query_string( $env->{QUERY_STRING} ) :
+ {};
+ $tt->process( 'assets.tt', { param => $param, assets => \@assets }, \my( $out ) )
+ or return $error->( 500, $tt->error );
+
+ return [
+ 200,
+ [ 'Content-Type', 'text/html' ],
+ [ $out ],
+ ];
+};
+
+builder {
+ mount '/css' => builder {
+ Plack::App::File->new( { root => './css' } );
+ };
+
+ mount '/img' => builder {
+ Plack::App::File->new( { root => './img' } );
+ };
+
+ mount '/' => $dashboard;
+ mount '/favicon.ico' => sub { return $error->( 404, "not found" ) };
+};
52 css/styles.css
@@ -0,0 +1,52 @@
+body { font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; background-color: #f0f5f8; }
+
+a:link, a:visited { color: #287098; text-decoration: none; }
+a:hover, a:active { text-decoration: underline; outline: none; }
+
+h1 { font-size: 300%; line-height: 100%; color: #c30; margin-bottom: 50px; font-weight: 300; }
+
+#doc3 { margin: 0; }
+.container { margin:auto; text-align:left; width:61.54em; min-width: 800px; }
+
+#hd .brand { background: #82a365 url(/img/green.png) repeat-x scroll bottom right; overflow: hidden; padding: 5px 0; text-align: center; }
+#hd .brand, #hd .brand a { color: #fff; }
+
+.navigation { height: 51px; background: #578ec1 url(/img/blue.png) repeat-x scroll; overflow: hidden; }
+.navigation, .navigation a { color: #fff; }
+.navigation ul { font-size: 1.1em; margin: 0; list-style: none; padding: 15px 0 0; }
+.navigation li { float: left; }
+.navigation a { background: transparent url(/img/button-right.png) no-repeat scroll -9999px 0; display: block; float: left; height: 26px; margin-right: 3px; padding-right: 10px; text-decoration: none; outline: none; }
+.navigation a:hover { color: #416a91; background-position: right -64px; }
+.navigation a:active { color: #fff; background-position: top right; }
+body.home .navigation li.home a,
+body.leaders-today .navigation li.leaders-today a,
+body.leaders-yesterday .navigation li.leaders-yesterday a { color: #fff; background-position: top right; }
+.navigation a span { background: transparent url(/img/button-left.png) no-repeat -9999px 0; display: block; line-height: 14px; padding: 4px 0 8px 10px; }
+.navigation a:hover span { background-position: 0 -64px; }
+.navigation a:active span { background-position: 0 0; }
+body.home .navigation li.home a span,
+body.leaders-today .navigation li.leaders-today a span,
+body.leaders-yesterday .navigation li.leaders-yesterday a span { background-position: 0 0; }
+
+#bd { margin: 30px 0; }
+.yui-gf { margin-bottom: 45px; }
+
+.box { border-width: 1px; border-style: solid; border-color: #eee #ccc #ccc #eee; padding: 19px; background: #fff; -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.25); overflow: hidden; }
+
+.details a { text-decoration: none; color: #6E6E6E;}
+.details .screenname { font-size: 108%; }
+.details .created { font-size: 77%; }
+.details p.favoriters { margin-top: 15px; }
+.details .favorite-count { font-size: 85%; }
+
+.content { font-size: 100%; line-height: 182%; }
+.content h2 { font-size: 131%; }
+.content p { margin-bottom: 10px; }
+.content blockquote { margin: 0 25px; border-top: 1px dotted #ddd; border-bottom: 1px dotted #ddd; font-style: italic; padding: 5px 10px 5px 10px; }
+.content .photo-thumb { float: right; width: 150px; margin: 0 10px; }
+.content .photo-medium { width: 350px; }
+.content span.meta { display: block; margin-top: -10px; font-size: 85%; }
+.content span.meta a { color: #BBB; }
+
+#ft { background: #5c93c7; height: 30px; padding: 10px 0;}
+#ft, #ft a { color: #fff; }
9 img/banner-left.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 img/banner-right.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  img/blue.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  img/button-left.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  img/button-right.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  img/green.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  img/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 templates/assets.tt
@@ -0,0 +1,87 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.0r4/build/reset-fonts-grids/reset-fonts-grids.css">
+ <link rel="stylesheet" type="text/css" href="/css/styles.css" />
+ <title>Dashboard</title>
+ <meta http-equiv="Content-Language" content="en-us" />
+ <meta http-equiv="imagetoolbar" content="false" />
+</head>
+<body class="home">
+ <div id="doc3">
+
+ <div id="hd">
+[%- USE today = DateTime( today = 1 );
+ yesterday = today.subtract( days => 1 ) -%]
+ <div class="brand">
+ <div class="container">
+ <strong><a href="http://www.typepad.com/">TypePad</a></strong> /
+ Dashboard
+ </div>
+ </div>
+ </div>
+
+ <div id="bd">
+ <div class="container">
+ <div class="box">
+[%- FOR asset IN assets %]
+ [%- IF param.debug %]<pre>[% USE Dumper; Dumper.dump( asset.content ) %]</pre>[%- END %]
+ <div class="yui-gf">
+ <div class="details yui-u first">
+ <p class="creator">
+ <a href="http://profile.typepad.com/[% asset.author.urlId | html %]"><img src="[% asset.author.avatar_uri | html %]" alt="[% asset.author.displayName | html %]" height="50" width="50" /></a><br />
+ <span class="screenname"><a href="http://profile.typepad.com/[% asset.author.urlId | html %]" title="Go to [% asset.author.displayName | html %]’s page at typepad.com">[% asset.author.displayName | html %]</a></span>
+ </p>
+ </div>
+ <div class="content yui-u">
+ [%- IF param.full %]
+ [% INCLUDE full %]
+ [%- ELSE %]
+ [% INCLUDE short %]
+ [%- END %]
+ </div>
+ </div>
+[%- END %]
+
+ </div>
+ </div>
+ </div>
+
+ <div id="ft">
+ <div class="container">
+ <p>Powered by <a href="http://www.typepad.com/">TypePad</a></p>
+ </div>
+ </div>
+
+ </div>
+</body>
+</html>
+
+
+[% BLOCK short %]
+[%- IF asset.content.media.size;
+ photo = asset.content.media.0;
+ END; %]
+ [%- IF asset.title && asset.title != asset.content.excerpt %]
+ <h2><a href="[% asset.permalink %]">[% asset.title %]</a></h2>
+ [%- END %]
+[%- IF asset.content.excerpt %]
+ [%- IF photo %]
+ <img class="photo-thumb" src="[% IF photo.server && photo.id %]http://[% photo.server | html %]/[% photo.id | html %]-150wi[% ELSE %][% photo.uri | html %][% END %]" />
+ [%- END %]
+ <p>[% asset.content.excerpt %]</p>
+[%- ELSIF photo; %]
+ <p><img class="photo-medium" src="[% IF photo.server && photo.id %]http://[% photo.server | html %]/[% photo.id | html %]-350wi[% ELSE %][% photo.uri | html %][% END %]" />
+[%- END %]
+ <span class="meta"><a href="[% asset.permalink | html %]" title="View individual post">about [% asset.published | html %] ago</a></span>
+[%- END %]
+
+[%- BLOCK full %]
+ [%- IF asset.title %]
+ <h2><a href="[% asset.permalink %]">[% asset.title %]</a></h2>
+ [%- END %]
+ [% asset.content %]
+ <span class="meta"><a href="[% asset.permalink | html %]" title="View individual post">about [% asset.published | html %] ago</a></span>
+[%- END %]
Please sign in to comment.
Something went wrong with that request. Please try again.