Browse files

Issue #495: Instagr.am support

* Added instagr.am support to the URLProcessor class
* Modified base.css to define max image height of 150px
* Added tests
  • Loading branch information...
1 parent 4923da4 commit 287f945715bd39007c1ddc9fef13aaf5c2b3377e @amygdala amygdala committed with ginatrapani Dec 22, 2010
View
1 webapp/assets/css/base.css
@@ -301,6 +301,7 @@ img.service-icon2 {left: 32px;}
/* .pic {border: 1px solid #CCC;padding: 5px 0px 0px 5px;} */
/*.pic {float:right;margin:10px 0 10px 10px;border:1px solid #CCC;padding:5px 5px 0 5px;}*/
+.pic img {max-height: 150px; }
.promo-thumb {float:left;width:113px;height:150px;margin-top: 13px;margin-left:15px;}
.promo-thumb .pic img {height:100px;width:100px;}
View
18 webapp/plugins/twitter/model/class.URLProcessor.php
@@ -58,6 +58,10 @@ public static function processTweetURLs($logger, $tweet, $urls = null) {
$is_image = 1;
} elseif (substr($u, 0, strlen('http://flic.kr/')) == 'http://flic.kr/') {
$is_image = 1;
+ } elseif (substr($u, 0, strlen('http://instagr.am/')) == 'http://instagr.am/') {
+ $logger->logInfo("processing instagram url: $u", __METHOD__.','.__LINE__);
+ $html = (string) Utils::getURLContents($u);
+ list($eurl, $is_image) = self::extractInstagramImageURL($logger, $html);
}
if ($link_dao->insert($u, $eurl, $title, $tweet['post_id'], 'twitter', $is_image)) {
$logger->logSuccess("Inserted ".$u." (".$eurl.", ".$is_image."), into links table",
@@ -67,4 +71,18 @@ public static function processTweetURLs($logger, $tweet, $urls = null) {
}
}
}
+
+ public static function extractInstagramImageURL($logger, $html) {
+ $eurl = '';
+ $is_image = 0;
+ if ($html) {
+ preg_match('/<meta property="og:image" content="[^"]+"\/>/i', $html, $matches);
+ if (isset($matches[0])) {
+ $eurl = substr($matches[0], 35, -3);
+ $logger->logDebug("got instagram eurl: $eurl", __METHOD__.','.__LINE__);
+ $is_image = 1;
+ }
+ }
+ return array($eurl, $is_image);
+ }
}
View
55 webapp/plugins/twitter/tests/TestOfURLProcessor.php
@@ -3,7 +3,7 @@
*
* ThinkUp/webapp/plugins/twitter/tests/TestOfURLProcessor.php
*
- * Copyright (c) 2009-2010
+ * Copyright (c) 2009-2010 Gina Trapani, Amy Unruh
*
* LICENSE:
*
@@ -21,7 +21,9 @@
* <http://www.gnu.org/licenses/>.
*
* @license http://www.gnu.org/licenses/gpl.html
- * @copyright 2009-2010
+ * @copyright 2009-2010 Gina Trapani
+ * @author Gina Trapani
+ * @author Amy Unruh
*/
if ( !isset($RUNNING_ALL_TESTS) || !$RUNNING_ALL_TESTS ) {
require_once '../../../../tests/init.tests.php';
@@ -32,14 +34,22 @@
require_once THINKUP_ROOT_PATH.'webapp/plugins/twitter/model/class.URLProcessor.php';
class TestOfURLProcessor extends ThinkUpUnitTestCase {
+ /**
+ * @var Logger
+ */
var $logger;
+ /**
+ * @var str
+ */
+ var $faux_data_path;
public function __construct() {
$this->UnitTestCase('URLProcessor class test');
}
public function setUp() {
$this->logger = Logger::getInstance();
+ $this->faux_data_path = THINKUP_ROOT_PATH. 'webapp/plugins/twitter/tests/testdata/URLProcessor';
parent::setUp();
}
@@ -124,4 +134,43 @@ public function testProcessTweetURLs() {
$this->assertEqual($result->network, 'twitter');
$this->assertTrue($result->is_image);
}
-}
+
+ public function testProcessTweetInstagramURLs() {
+ //instagr.am
+ $tweet["post_id"] = 105;
+ $tweet['post_text'] = "This is an Instagram post: http://instagr.am/p/oyQ6/ :)";
+ URLProcessor::processTweetURLs($this->logger, $tweet);
+ $link_dao = new LinkMySQLDAO();
+ $result = $link_dao->getLinkByUrl('http://instagr.am/p/oyQ6/');
+ $this->assertIsA($result, "Link");
+ $this->assertEqual($result->url, 'http://instagr.am/p/oyQ6/');
+ $this->assertEqual($result->expanded_url,
+ 'http://distillery.s3.amazonaws.com/media/2010/12/20/f0f411210cc54353be07cf74ceb79f3b_7.jpg');
+ $this->assertEqual($result->title, '');
+ $this->assertEqual($result->post_id, 105);
+ $this->assertEqual($result->network, 'twitter');
+ $this->assertTrue($result->is_image);
+
+ // bad instagr.am URL
+ $tweet["post_id"] = 106;
+ $tweet['post_text'] = "This is an Instagram post with a bad URL: http://instagr.am/p/oyQ5/ :(";
+ URLProcessor::processTweetURLs($this->logger, $tweet);
+ $link_dao = new LinkMySQLDAO();
+ $result = $link_dao->getLinkByUrl('http://instagr.am/p/oyQ5/');
+ $this->assertIsA($result, "Link");
+ $this->assertEqual($result->url, 'http://instagr.am/p/oyQ5/');
+ $this->assertEqual($result->expanded_url, '');
+ $this->assertEqual($result->title, '');
+ $this->assertEqual($result->post_id, 106);
+ $this->assertEqual($result->network, 'twitter');
+ $this->assertFalse($result->is_image);
+
+ // test regexp extraction of image link from html
+ $api_call = $this->faux_data_path . "/instagr_am_p_oyQ6";
+ $resp = file_get_contents($api_call);
+ list($eurl, $is_image) = URLProcessor::extractInstagramImageURL($this->logger, $resp);
+ $this->assertEqual($eurl,
+ 'http://distillery.s3.amazonaws.com/media/2010/12/20/f0f411210cc54353be07cf74ceb79f3b_7.jpg');
+ $this->assertTrue($is_image);
+ }
+}
View
128 webapp/plugins/twitter/tests/testdata/URLProcessor/instagr_am_p_oyQ6
@@ -0,0 +1,128 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+
+<html lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta name = "viewport" content = "width = 480">
+ <title>instagr.am</title>
+ <link rel="shortcut icon" href="/static/images/favicon.ico">
+ <link rel="stylesheet" href="/static/styles/reset.css" type="text/css" media="screen" title="no title" charset="utf-8">
+ <link rel="stylesheet" href="/static/styles/master.css?r=1" type="text/css" media="screen" title="no title" charset="utf-8">
+
+
+ <link rel="stylesheet" href="/static/styles/waitlist.css" type="text/css" media="screen" title="no title" charset="utf-8">
+ <link rel="stylesheet" href="/static/media/styles/detail.css?v=2" type="text/css" media="screen" title="no title" charset="utf-8">
+
+ <script src="/static/scripts/jquery.js" type="text/javascript" charset="utf-8"></script>
+ <script type="text/javascript">
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', 'UA-18105282-1']);
+ _gaq.push(['_trackPageview']);
+ (function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ })();
+ </script>
+
+ <script type="text/javascript" charset="utf-8">
+ $(document).ready(function(){
+ var agent = navigator.userAgent.toLowerCase();
+ var is_iphone = agent.indexOf('iphone') != -1;
+ if (is_iphone) {
+ $('#download-banner').show();
+ window.scrollTo(0, 0);
+ }
+ });
+ </script>
+
+
+ <meta property="og:title" content="thespambot's photo"/>
+ <meta property="og:image" content="http://distillery.s3.amazonaws.com/media/2010/12/20/f0f411210cc54353be07cf74ceb79f3b_7.jpg"/>
+ <meta property="og:site_name" content="Instagram">
+
+ <meta property="og:description" content="Railroad Crossing"/>
+
+
+</head>
+<body>
+
+ <div id="download-banner">
+ <p>Want to take pictures like this? <a href="http://itunes.com/apps/instagram/">Try the free app</a></p>
+ </div>
+
+ <div id="wrap" class="group">
+ <div id="content">
+
+ <div id="photo" >
+ <div class="group frame">
+ <img src="http://distillery.s3.amazonaws.com/media/2010/12/20/f0f411210cc54353be07cf74ceb79f3b_7.jpg" class="photo" />
+ <div class="photo-info">
+ <img src="http://distillery.s3.amazonaws.com/profiles/profile_626603_75sq_1289545248.jpg" class="profile-photo"/>
+ <div class="profile-info">
+ <h1>thespambot</h1>
+ <span class="number-statistic">31</span> photos
+ &middot;
+ <span class="number-statistic">7</span> followers
+ </div>
+ </div>
+ </div>
+ </div>
+ <div id="promo">
+ <img src="http://distillery.s3.amazonaws.com/static/images/logoCamera.png" class="logo-camera"/>
+ <table class="promo-table">
+ <tr class="top-spacer-row">
+ <td><!-- not empty --></td>
+ </tr>
+ <tr class="bottom-spacer-row">
+ <td><!-- not empty --></td>
+ </tr>
+ <tr>
+ <td>
+ <p class="description">
+ Jonah is using Instagram - a fun &amp; quirky way to share your life with friends through a series of pictures. Snap a photo, then choose a filter to transform the look and feel of the shot into a memory to keep around forever.
+ <span style="font-weight:bold;">It's free!</span>
+ </p>
+ </td>
+ </tr>
+ <tr>
+ <td style="text-align:center;">
+ <a href="http://itunes.com/apps/instagram/"><img src="/static/images/appStoreBadge.png" alt="Available on the App Store"/></a>
+ </td>
+ </tr>
+ <tr>
+ <td style="text-align:center;">
+ <!-- AddThis Button BEGIN -->
+ <div class="addthis_toolbox addthis_default_style" style="padding-left:4em; padding-top:3em;">
+ <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
+ <a class="addthis_button_tweet"></a>
+ <a class="addthis_counter addthis_pill_style"></a>
+ </div>
+ <script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
+ <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=burbn"></script>
+ <!-- AddThis Button END -->
+ </td>
+ </tr>
+ </table>
+ </div>
+
+ </div>
+ </div>
+
+ <div id="footer" class="group">
+
+ <p style="color:#999; margin:1em 0; text-align:center; font-size:1.2em;">
+ <a href="/accounts/edit/">Edit Account</a>
+ </p>
+
+ <span id="footer-links">
+ <a href="/about/">About us</a> | <a href="/blog/">Blog</a> | <a href="/about/faq">FAQ</a> | <a href="/about/jobs/">Jobs</a> <br/>
+ </span>
+ Copyright 2010, Burbn, Inc. contact@instagr.am
+ </div>
+
+
+
+</body>
+</html>

0 comments on commit 287f945

Please sign in to comment.