<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>tests/database_test.php</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,7 @@
 common/config.inc.php
 webapp/config.webapp.inc.php
 crawler/config.crawler.inc.php
+tests/config.tests.inc.php
 webapp/templates_c/*.php
 webapp/templates_c/cache/*.tpl
 crawler/logs/crawl.log</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -1,58 +1,61 @@
 &lt;?php 
 class Crawler {
     var $instance;
+	var $logger;
+	var $api;
     var $owner_object;
     var $ud;
     
-    function Crawler($instance) {
+    function Crawler($instance, $logger, $api) {
         $this-&gt;instance = $instance;
-        $this-&gt;ud = new UserDao();
+        $this-&gt;ud = new UserDAO($this-&gt;logger);
+		$this-&gt;api = $api;
+		$this-&gt;logger = $logger;
     }
     
-    function fetchInstanceUserInfo($cfg, $api, $logger) {
+    function fetchInstanceUserInfo() {
         // Get owner user details and save them to DB
         $status_message = &quot;&quot;;
-        $owner_profile = str_replace(&quot;[id]&quot;, $cfg-&gt;twitter_username, $api-&gt;cURL_source['show_user']);
-        list($cURL_status, $twitter_data) = $api-&gt;apiRequest($owner_profile, $logger);
+        $owner_profile = str_replace(&quot;[id]&quot;, $this-&gt;instance-&gt;twitter_username, $this-&gt;api-&gt;cURL_source['show_user']);
+        list($cURL_status, $twitter_data) = $this-&gt;api-&gt;apiRequest($owner_profile, $this-&gt;logger);
         
         if ($cURL_status == 200) {
             try {
-                $users = $api-&gt;parseXML($twitter_data);
+                $users = $this-&gt;api-&gt;parseXML($twitter_data);
                 foreach ($users as $user)
                     $this-&gt;owner_object = new User($user, 'Owner Status');
                     
                 if (isset($this-&gt;owner_object)) {
                     $status_message = 'Owner info set.';
-                    $this-&gt;ud-&gt;updateUser($this-&gt;owner_object, $logger);
+                    $this-&gt;ud-&gt;updateUser($this-&gt;owner_object, $this-&gt;logger);
                 } else {
                     $status_message = 'Owner was not set.';
                 }
             }
             catch(Exception $e) {
-                $status_message = 'Could not parse profile XML for $cfg-&gt;twitter_username';
+                $status_message = 'Could not parse profile XML for $this-&gt;owner_object-&gt;username';
             }
         } else {
             $status_message = 'cURL status is not 200';
         }
-        $logger-&gt;logStatus($status_message, get_class($this));
-        $status_message = &quot;&quot;;
+        $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
     }
     
-    function fetchInstanceUserTweets($cfg, $api, $logger) {
+    function fetchInstanceUserTweets($lurl, $fa) {
         // Get owner's tweets
         $status_message = &quot;&quot;;
         $got_latest_page_of_tweets = false;
         $continue_fetching = true;
         
-        while ($api-&gt;available &amp;&amp; $api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $this-&gt;owner_object-&gt;tweet_count &gt; $this-&gt;instance-&gt;total_tweets_in_system &amp;&amp; $continue_fetching) {
+        while ($this-&gt;api-&gt;available &amp;&amp; $this-&gt;api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $this-&gt;owner_object-&gt;tweet_count &gt; $this-&gt;instance-&gt;total_tweets_in_system &amp;&amp; $continue_fetching) {
         
-            $recent_tweets = str_replace(&quot;[id]&quot;, $cfg-&gt;twitter_username, $api-&gt;cURL_source['user_timeline']);
+            $recent_tweets = str_replace(&quot;[id]&quot;, $this-&gt;owner_object-&gt;username, $this-&gt;api-&gt;cURL_source['user_timeline']);
             $args = array();
             $args[&quot;count&quot;] = 200;
-            $last_page_of_tweets = round($cfg-&gt;archive_limit / 200) + 1;
+            $last_page_of_tweets = round($this-&gt;api-&gt;archive_limit / 200) + 1;
             
             //set page and since_id params for API call
-            if ($got_latest_page_of_tweets &amp;&amp; $this-&gt;owner_object-&gt;tweet_count != $this-&gt;instance-&gt;total_tweets_in_system &amp;&amp; $this-&gt;instance-&gt;total_tweets_in_system &lt; $cfg-&gt;archive_limit) {
+            if ($got_latest_page_of_tweets &amp;&amp; $this-&gt;owner_object-&gt;tweet_count != $this-&gt;instance-&gt;total_tweets_in_system &amp;&amp; $this-&gt;instance-&gt;total_tweets_in_system &lt; $this-&gt;api-&gt;archive_limit) {
                 if ($this-&gt;instance-&gt;last_page_fetched_tweets &lt; $last_page_of_tweets)
                     $this-&gt;instance-&gt;last_page_fetched_tweets = $this-&gt;instance-&gt;last_page_fetched_tweets + 1;
                 else {
@@ -66,22 +69,22 @@ class Crawler {
                     $args[&quot;since_id&quot;] = $this-&gt;instance-&gt;last_status_id;
             }
             
-            list($cURL_status, $twitter_data) = $api-&gt;apiRequest($recent_tweets, $logger, $args);
+            list($cURL_status, $twitter_data) = $this-&gt;api-&gt;apiRequest($recent_tweets, $this-&gt;logger, $args);
             if ($cURL_status == 200) {
                 # Parse the XML file
                 try {
                     $count = 0;
-                    $tweets = $api-&gt;parseXML($twitter_data);
+                    $tweets = $this-&gt;api-&gt;parseXML($twitter_data);
                     
                     $td = new TweetDAO;
                     foreach ($tweets as $tweet) {
                     
-                        if ($td-&gt;addTweet($tweet, $this-&gt;owner_object, $logger) &gt; 0) {
+                        if ($td-&gt;addTweet($tweet, $this-&gt;owner_object, $this-&gt;logger) &gt; 0) {
                             $count = $count + 1;
                             $this-&gt;instance-&gt;total_tweets_in_system = $this-&gt;instance-&gt;total_tweets_in_system + 1;
                             
                             //expand and insert links contained in tweet
-                            $this-&gt;processTweetURLs($tweet, $cfg, $logger);
+                            $this-&gt;processTweetURLs($tweet, $lurl, $fa);
                             
                         }
                         if ($tweet['status_id'] &gt; $this-&gt;instance-&gt;last_status_id)
@@ -89,15 +92,15 @@ class Crawler {
                             
                     }
                     $status_message .= count($tweets).&quot; tweet(s) found and $count saved&quot;;
-                    $logger-&gt;logStatus($status_message, get_class($this));
+                    $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
                     $status_message = &quot;&quot;;
                     
                     //if you've got more than the Twitter API archive limit, stop looking for more tweets
-                    if ($this-&gt;instance-&gt;total_tweets_in_system &gt;= $cfg-&gt;archive_limit) {
+                    if ($this-&gt;instance-&gt;total_tweets_in_system &gt;= $this-&gt;api-&gt;archive_limit) {
                         $this-&gt;instance-&gt;last_page_fetched_tweets = 1;
                         $continue_fetching = false;
-                        $status_message = &quot;More than Twitter cap of &quot;.$cfg-&gt;archive_limit.&quot; already in system, moving on.&quot;;
-                        $logger-&gt;logStatus($status_message, get_class($this));
+                        $status_message = &quot;More than Twitter cap of &quot;.$this-&gt;api-&gt;archive_limit.&quot; already in system, moving on.&quot;;
+                        $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
                         $status_message = &quot;&quot;;
                     }
 
@@ -106,13 +109,13 @@ class Crawler {
                         $this-&gt;instance-&gt;is_archive_loaded_tweets = true;
                         
                     $status_message .= $this-&gt;instance-&gt;total_tweets_in_system.&quot; in system; &quot;.$this-&gt;owner_object-&gt;tweet_count.&quot; by owner&quot;;
-                    $logger-&gt;logStatus($status_message, get_class($this));
+                    $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
                     $status_message = &quot;&quot;;
                     
                 }
                 catch(Exception $e) {
                     $status_message = 'Could not parse tweet XML for $this-&gt;twitter_username';
-                    $logger-&gt;logStatus($status_message, get_class($this));
+                    $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
                     $status_message = &quot;&quot;;
                     
                 }
@@ -125,16 +128,14 @@ class Crawler {
             $status_message .= &quot;All of &quot;.$this-&gt;owner_object-&gt;user_name.&quot;'s tweets are in the system; Stopping tweet fetch.&quot;;
 
             
-        $logger-&gt;logStatus($status_message, get_class($this));
+        $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
         $status_message = &quot;&quot;;
         
     }
     
-    private function processTweetURLs($tweet, $cfg, $logger) {
+    private function processTweetURLs($tweet, $lurl, $fa) {
     
         $ld = new LinkDAO;
-        $lurl = new LongUrlAPIAccessor($cfg);
-        $fa = new FlickrAPIAccessor($cfg);
         
         $urls = Tweet::extractURLs($tweet['tweet_text']);
         foreach ($urls as $u) {
@@ -147,12 +148,12 @@ class Crawler {
                 $eurl = 'http://twitpic.com/show/thumb/'.substr($u, strlen('http://twitpic.com/'));
                 $is_image = 1;
             } elseif ( substr($u, 0, strlen('http://yfrog.com/')) == 'http://yfrog.com/' ) {
-            	$eurl = $u.'th.jpg';
+            	$eurl = $u.'.th.jpg';
 				$is_image = 1;	 
 			} elseif (substr($u, 0, strlen('http://twitgoo.com/')) == 'http://twitgoo.com/') {
                 $eurl = 'http://twitgoo.com/show/thumb/'.substr($u, strlen('http://twitgoo.com/'));
                 $is_image = 1;
-            } elseif ($cfg-&gt;flickr_api_key != null &amp;&amp; substr($u, 0, strlen('http://flic.kr/p/')) == 'http://flic.kr/p/') {
+            } elseif ($fa-&gt;api_key != null &amp;&amp; substr($u, 0, strlen('http://flic.kr/p/')) == 'http://flic.kr/p/') {
                 $eurl = $fa-&gt;getFlickrPhotoSource($u);
                 if ($eurl != '')
                     $is_image = 1;
@@ -166,28 +167,28 @@ class Crawler {
             }
             
             if ($ld-&gt;insert($u, $eurl, $title, $tweet['status_id'], $is_image))
-                $logger-&gt;logStatus(&quot;Inserted &quot;.$u.&quot; (&quot;.$eurl.&quot;) into links table&quot;, get_class($this));
+                $this-&gt;logger-&gt;logStatus(&quot;Inserted &quot;.$u.&quot; (&quot;.$eurl.&quot;) into links table&quot;, get_class($this));
             else
-                $logger-&gt;logStatus(&quot;Did NOT insert &quot;.$u.&quot; (&quot;.$eurl.&quot;) into links table&quot;, get_class($this));
+                $this-&gt;logger-&gt;logStatus(&quot;Did NOT insert &quot;.$u.&quot; (&quot;.$eurl.&quot;) into links table&quot;, get_class($this));
                 
         }
         
     }
     
-    private function fetchAndAddTweetRepliedTo($tid, $td, $api, $logger, $cfg) {
+    private function fetchAndAddTweetRepliedTo($tid, $td, $lurl, $fa) {
         //fetch tweet from Twitter and add to DB
         $status_message = &quot;&quot;;
-        $tweet_deets = str_replace(&quot;[id]&quot;, $tid, $api-&gt;cURL_source['show_tweet']);
-        list($cURL_status, $twitter_data) = $api-&gt;apiRequest($tweet_deets, $logger);
+        $tweet_deets = str_replace(&quot;[id]&quot;, $tid, $this-&gt;api-&gt;cURL_source['show_tweet']);
+        list($cURL_status, $twitter_data) = $this-&gt;api-&gt;apiRequest($tweet_deets, $this-&gt;logger);
         
         if ($cURL_status == 200) {
             try {
-                $tweets = $api-&gt;parseXML($twitter_data);
+                $tweets = $this-&gt;api-&gt;parseXML($twitter_data);
                 foreach ($tweets as $tweet) {
-                    if ($td-&gt;addTweet($tweet, $this-&gt;owner_object, $logger) &gt; 0) {
+                    if ($td-&gt;addTweet($tweet, $this-&gt;owner_object, $this-&gt;logger) &gt; 0) {
                         $status_message = 'Added replied to tweet ID '.$tid.&quot; to database.&quot;;
                         //expand and insert links contained in tweet
-                        $this-&gt;processTweetURLs($tweet, $cfg, $logger);
+                        $this-&gt;processTweetURLs($tweet, $lurl, $fa);
                     }
                 }
             }
@@ -196,7 +197,7 @@ class Crawler {
             }
         } elseif ($cURL_status == 404 || $cURL_status == 403) {
             try {
-                $e = $api-&gt;parseError($twitter_data);
+                $e = $this-&gt;api-&gt;parseError($twitter_data);
                 $td = new TweetErrorDAO();
                 $td-&gt;insertError($tid, $cURL_status, $e['error'], $this-&gt;owner_object-&gt;id);
                 $status_message = 'Error saved to tweets.';
@@ -205,20 +206,20 @@ class Crawler {
                 $status_message = 'Could not parse tweet XML for $tid';
             }
         }
-        $logger-&gt;logStatus($status_message, get_class($this));
+        $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
         $status_message = &quot;&quot;;
     }
     
-    function fetchInstanceUserReplies($cfg, $api, $logger) {
+    function fetchInstanceUserReplies($lurl, $fa) {
         $status_message = &quot;&quot;;
         // Get owner's replies
-        if ($api-&gt;available_api_calls_for_crawler &gt; 0) {
+        if ($this-&gt;api-&gt;available_api_calls_for_crawler &gt; 0) {
             $got_newest_replies = false;
             $continue_fetching = true;
             
-            while ($api-&gt;available &amp;&amp; $api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $continue_fetching) {
+            while ($this-&gt;api-&gt;available &amp;&amp; $this-&gt;api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $continue_fetching) {
                 # Get the most recent replies
-                $replies = str_replace(&quot;[id]&quot;, $cfg-&gt;twitter_username, $api-&gt;cURL_source['replies']);
+                $replies = str_replace(&quot;[id]&quot;, $this-&gt;owner_object-&gt;username, $this-&gt;api-&gt;cURL_source['replies']);
                 $args = array();
                 $args['count'] = 200;
                 
@@ -227,19 +228,19 @@ class Crawler {
                     $args['page'] = $this-&gt;last_page_fetched_replies;
                 }
                 
-                list($cURL_status, $twitter_data) = $api-&gt;apiRequest($replies, $logger, $args);
+                list($cURL_status, $twitter_data) = $this-&gt;api-&gt;apiRequest($replies, $this-&gt;logger, $args);
                 if ($cURL_status &gt; 200) {
                     $continue_fetching = false;
                 } else {
                     try {
                         $count = 0;
-                        $tweets = $api-&gt;parseXML($twitter_data);
+                        $tweets = $this-&gt;api-&gt;parseXML($twitter_data);
                         if (count($tweets) == 0 &amp;&amp; $got_newest_replies) {# you're paged back and no new tweets
                             $this-&gt;last_page_fetched_replies = 1;
                             $continue_fetching = false;
                             $this-&gt;instance-&gt;is_archive_loaded_replies = true;
                             $status_message = 'Paged back but not finding new replies; moving on.';
-                            $logger-&gt;logStatus($status_message, get_class($this));
+                            $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
                             $status_message = &quot;&quot;;
                         }
 
@@ -247,38 +248,38 @@ class Crawler {
                         $td = new TweetDAO;
                         $count = 0;
                         foreach ($tweets as $tweet) {
-                            if ($td-&gt;addTweet($tweet, $this-&gt;owner_object, $logger) &gt; 0) {
+                            if ($td-&gt;addTweet($tweet, $this-&gt;owner_object, $this-&gt;logger) &gt; 0) {
                                 $count++;
                                 //expand and insert links contained in tweet
-                                $this-&gt;processTweetURLs($tweet, $cfg, $logger);
-                                if ($tweet['user_id'] != $cfg-&gt;twitter_user_id) { //don't update owner info from reply
+                                $this-&gt;processTweetURLs($tweet, $lurl, $fa);
+                                if ($tweet['user_id'] != $this-&gt;owner_object-&gt;id) { //don't update owner info from reply
                                     $u = new User($tweet, 'Replies');
-                                    $this-&gt;ud-&gt;updateUser($u, $logger);
+                                    $this-&gt;ud-&gt;updateUser($u, $this-&gt;logger);
                                 }
                                 
                             }
                             
                         }
                         $status_message .= count($tweets).&quot; replies found and $count saved&quot;;
-                        $logger-&gt;logStatus($status_message, get_class($this));
+                        $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
                         $status_message = &quot;&quot;;
                         
                         $got_newest_replies = true;
                         
-                        $logger-&gt;logStatus($status_message, get_class($this));
+                        $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
                         $status_message = &quot;&quot;;
                         
                         if ($got_newest_replies &amp;&amp; $this-&gt;instance-&gt;is_archive_loaded_replies) {
                             $continue_fetching = false;
                             $status_message .= 'Retrieved newest replies; Reply archive loaded; Stopping reply fetch.';
-                            $logger-&gt;logStatus($status_message, get_class($this));
+                            $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
                             $status_message = &quot;&quot;;
                         }
                         
                     }
                     catch(Exception $e) {
-                        $status_message = 'Could not parse replies XML for $cfg-&gt;twitter_username';
-                        $logger-&gt;logStatus($status_message, get_class($this));
+                        $status_message = 'Could not parse replies XML for $this-&gt;owner_object-&gt;username';
+                        $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
                         $status_message = &quot;&quot;;
                     }
                 }
@@ -288,24 +289,24 @@ class Crawler {
             $status_message = 'Crawler API call limit exceeded.';
         }
         
-        $logger-&gt;logStatus($status_message, get_class($this));
+        $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
         $status_message = &quot;&quot;;
     }
     
-    private function fetchInstanceUserFollowersByIDs($cfg, $api, $logger) {
+    private function fetchInstanceUserFollowersByIDs() {
         $continue_fetching = true;
         $last_page_fetched_follower_ids = $this-&gt;instance-&gt;last_page_fetched_followers;
         $status_message = &quot;&quot;;
         
-        while ($api-&gt;available &amp;&amp; $api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $continue_fetching) {
+        while ($this-&gt;api-&gt;available &amp;&amp; $this-&gt;api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $continue_fetching) {
         
             $last_page_fetched_follower_ids = $last_page_fetched_follower_ids + 1;
             
             $args = array();
-            $follower_ids = str_replace(&quot;[id]&quot;, $cfg-&gt;twitter_username, $api-&gt;cURL_source['followers_ids']);
+            $follower_ids = str_replace(&quot;[id]&quot;, $this-&gt;owner_object-&gt;username, $this-&gt;api-&gt;cURL_source['followers_ids']);
             $args['page'] = $last_page_fetched_follower_ids;
             
-            list($cURL_status, $twitter_data) = $api-&gt;apiRequest($follower_ids, $logger, $args);
+            list($cURL_status, $twitter_data) = $this-&gt;api-&gt;apiRequest($follower_ids, $this-&gt;logger, $args);
             
             if ($cURL_status &gt; 200) {
                 $continue_fetching = false;
@@ -313,7 +314,7 @@ class Crawler {
                 $fd = new FollowDAO();
                 
                 try {
-                    $ids = $api-&gt;parseXML($twitter_data);
+                    $ids = $this-&gt;api-&gt;parseXML($twitter_data);
                     $status_message = &quot;Page &quot;.$last_page_fetched_follower_ids.&quot; has &quot;.count($ids).&quot; follower IDs. &quot;;
                     
                     if (count($ids) == 0) {
@@ -343,12 +344,12 @@ class Crawler {
                 catch(Exception $e) {
                     $status_message = 'Could not parse follower ID XML for $crawler_twitter_username';
                 }
-                $logger-&gt;logStatus($status_message, get_class($this));
+                $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
                 $status_message = &quot;&quot;;
                 
             }
             
-            $logger-&gt;logStatus($status_message, get_class($this));
+            $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
             $status_message = &quot;&quot;;
             
         }
@@ -356,38 +357,38 @@ class Crawler {
         $this-&gt;instance-&gt;last_page_fetched_followers = $last_page_fetched_follower_ids;
     }
     
-    function fetchInstanceUserFollowers($cfg, $api, $logger) {
+    function fetchInstanceUserFollowers() {
         $status_message = &quot;&quot;;
         // Get owner's followers: Page back only if more than 2% of follows are missing from database
         // See how many are missing from last run
         if ($this-&gt;instance-&gt;is_archive_loaded_follows) { //all pages have been loaded
-            $logger-&gt;logStatus(&quot;Follower archive marked as loaded&quot;, get_class($this));
+            $this-&gt;logger-&gt;logStatus(&quot;Follower archive marked as loaded&quot;, get_class($this));
             
             //find out how many new follows owner has compared to what's in db
             $new_follower_count = $this-&gt;owner_object-&gt;follower_count - $this-&gt;instance-&gt;total_follows_in_system;
             $status_message = &quot;New follower count is &quot;.$this-&gt;owner_object-&gt;follower_count.&quot; and system has &quot;.$this-&gt;instance-&gt;total_follows_in_system.&quot;; &quot;.$new_follower_count.&quot; new follows to load&quot;;
-            $logger-&gt;logStatus($status_message, get_class($this));
+            $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
             
             if ($new_follower_count &gt; 0) {
-                $logger-&gt;logStatus(&quot;Fetching follows via IDs&quot;, get_class($this));
-                $this-&gt;fetchInstanceUserFollowersByIDs($cfg, $api, $logger);
+                $this-&gt;logger-&gt;logStatus(&quot;Fetching follows via IDs&quot;, get_class($this));
+                $this-&gt;fetchInstanceUserFollowersByIDs();
             }
         } else {
-            $logger-&gt;logStatus(&quot;Follower archive is not loaded; fetch should begin.&quot;, get_class($this));
+            $this-&gt;logger-&gt;logStatus(&quot;Follower archive is not loaded; fetch should begin.&quot;, get_class($this));
         }
 
         
         # Fetch follower pages
         $continue_fetching = true;
-        while ($api-&gt;available &amp;&amp; $api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $continue_fetching &amp;&amp; !$this-&gt;instance-&gt;is_archive_loaded_follows) {
+        while ($this-&gt;api-&gt;available &amp;&amp; $this-&gt;api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $continue_fetching &amp;&amp; !$this-&gt;instance-&gt;is_archive_loaded_follows) {
         
             $this-&gt;instance-&gt;last_page_fetched_followers = $this-&gt;instance-&gt;last_page_fetched_followers + 1;
             
-            $follower_ids = str_replace(&quot;[id]&quot;, $cfg-&gt;twitter_username, $api-&gt;cURL_source['followers']);
+            $follower_ids = str_replace(&quot;[id]&quot;, $this-&gt;owner_object-&gt;username, $this-&gt;api-&gt;cURL_source['followers']);
             $args = array();
             $args['page'] = $this-&gt;instance-&gt;last_page_fetched_followers;
             
-            list($cURL_status, $twitter_data) = $api-&gt;apiRequest($follower_ids, $logger, $args);
+            list($cURL_status, $twitter_data) = $this-&gt;api-&gt;apiRequest($follower_ids, $this-&gt;logger, $args);
             
             if ($cURL_status &gt; 200) {
                 $continue_fetching = false;
@@ -395,7 +396,7 @@ class Crawler {
                 $fd = new FollowDAO();
                 
                 try {
-                    $users = $api-&gt;parseXML($twitter_data);
+                    $users = $this-&gt;api-&gt;parseXML($twitter_data);
                     $status_message .= &quot;Page &quot;.$this-&gt;instance-&gt;last_page_fetched_followers.&quot;: &quot;.count($users).&quot; follows ready to update. &quot;;
                     
                     if (count($users) == 0) {
@@ -407,7 +408,7 @@ class Crawler {
                     $inserted_follow_count = 0;
                     foreach ($users as $u) {
                         $utu = new User($u, 'Follows');
-                        $this-&gt;ud-&gt;updateUser($utu, $logger);
+                        $this-&gt;ud-&gt;updateUser($utu, $this-&gt;logger);
                         
                         # add/update follow relationship
                         if ($fd-&gt;followExists($this-&gt;instance-&gt;twitter_user_id, $utu-&gt;user_id)) {
@@ -426,43 +427,43 @@ class Crawler {
                 catch(Exception $e) {
                     $status_message = 'Could not parse followers XML for $crawler_twitter_username';
                 }
-                $logger-&gt;logStatus($status_message, get_class($this));
+                $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
                 $status_message = &quot;&quot;;
                 
             }
             
-            $logger-&gt;logStatus($status_message, get_class($this));
+            $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
             $status_message = &quot;&quot;;
             
         }
         
     }
     
-    function fetchInstanceUserFriends($cfg, $api, $logger) {
+    function fetchInstanceUserFriends() {
         $fd = new FollowDAO();
-        $this-&gt;instance-&gt;total_friends_in_system = $fd-&gt;getTotalFriends($cfg-&gt;twitter_user_id);
+        $this-&gt;instance-&gt;total_friends_in_system = $fd-&gt;getTotalFriends($this-&gt;owner_object-&gt;id);
         
         if ($this-&gt;instance-&gt;total_friends_in_system &lt; $this-&gt;owner_object-&gt;friend_count) {
             $this-&gt;instance-&gt;is_archive_loaded_friends = false;
-            $logger-&gt;logStatus($this-&gt;instance-&gt;total_friends_in_system.&quot; friends in system, &quot;.$this-&gt;owner_object-&gt;friend_count.&quot; friends according to Twitter; Friend archive is not loaded&quot;, get_class($this));
+            $this-&gt;logger-&gt;logStatus($this-&gt;instance-&gt;total_friends_in_system.&quot; friends in system, &quot;.$this-&gt;owner_object-&gt;friend_count.&quot; friends according to Twitter; Friend archive is not loaded&quot;, get_class($this));
         } else {
             $this-&gt;instance-&gt;is_archive_loaded_friends = true;
-            $logger-&gt;logStatus(&quot;Friend archive loaded&quot;, get_class($this));
+            $this-&gt;logger-&gt;logStatus(&quot;Friend archive loaded&quot;, get_class($this));
         }
         
         $status_message = &quot;&quot;;
         $this-&gt;instance-&gt;last_page_fetched_friends = 0;
         # Fetch friend pages
         $continue_fetching = true;
-        while ($api-&gt;available &amp;&amp; $api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $continue_fetching &amp;&amp; !$this-&gt;instance-&gt;is_archive_loaded_friends) {
+        while ($this-&gt;api-&gt;available &amp;&amp; $this-&gt;api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $continue_fetching &amp;&amp; !$this-&gt;instance-&gt;is_archive_loaded_friends) {
         
             $this-&gt;instance-&gt;last_page_fetched_friends = $this-&gt;instance-&gt;last_page_fetched_friends + 1;
             
-            $friend_ids = str_replace(&quot;[id]&quot;, $cfg-&gt;twitter_username, $api-&gt;cURL_source['following']);
+            $friend_ids = str_replace(&quot;[id]&quot;, $this-&gt;owner_object-&gt;username, $this-&gt;api-&gt;cURL_source['following']);
             $args = array();
             $args['page'] = $this-&gt;instance-&gt;last_page_fetched_friends;
             
-            list($cURL_status, $twitter_data) = $api-&gt;apiRequest($friend_ids, $logger, $args);
+            list($cURL_status, $twitter_data) = $this-&gt;api-&gt;apiRequest($friend_ids, $this-&gt;logger, $args);
             
             if ($cURL_status &gt; 200) {
                 $continue_fetching = false;
@@ -470,7 +471,7 @@ class Crawler {
             
                 try {
                     $status_message = &quot;Parsing XML. &quot;;
-                    $users = $api-&gt;parseXML($twitter_data);
+                    $users = $this-&gt;api-&gt;parseXML($twitter_data);
                     $status_message .= &quot;Page &quot;.$this-&gt;instance-&gt;last_page_fetched_friends.&quot;: &quot;.count($users).&quot; friends queued to update. &quot;;
                     
                     $updated_follow_count = 0;
@@ -483,7 +484,7 @@ class Crawler {
                     
                     foreach ($users as $u) {
                         $utu = new User($u, 'Friends');
-                        $this-&gt;ud-&gt;updateUser($utu, $logger);
+                        $this-&gt;ud-&gt;updateUser($utu, $this-&gt;logger);
                         
                         # add/update follow relationship
                         if ($fd-&gt;followExists($utu-&gt;user_id, $this-&gt;instance-&gt;twitter_user_id)) {
@@ -503,29 +504,29 @@ class Crawler {
                 catch(Exception $e) {
                     $status_message = 'Could not parse friends XML for $crawler_twitter_username';
                 }
-                $logger-&gt;logStatus($status_message, get_class($this));
+                $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
                 $status_message = &quot;&quot;;
                 
             }
             
-            $logger-&gt;logStatus($status_message, get_class($this));
+            $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
             $status_message = &quot;&quot;;
             
         }
         
     }
     
-    function fetchFriendTweetsAndFriends($cfg, $api, $logger) {
+    function fetchFriendTweetsAndFriends($lurl, $fa) {
         $fd = new FollowDAO();
         $td = new TweetDAO();
         $ud = new UserDAO();
         
         $continue_fetching = true;
-        while ($api-&gt;available &amp;&amp; $api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $continue_fetching) {
-            $stale_friend = $fd-&gt;getStalestFriend($cfg-&gt;twitter_user_id);
+        while ($this-&gt;api-&gt;available &amp;&amp; $this-&gt;api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $continue_fetching) {
+            $stale_friend = $fd-&gt;getStalestFriend($this-&gt;owner_object-&gt;id);
             if ($stale_friend != null) {
-                $logger-&gt;logStatus($stale_friend-&gt;user_name.&quot; is friend most need of update&quot;, get_class($this));
-                $stale_friend_tweets = str_replace(&quot;[id]&quot;, $stale_friend-&gt;user_name, $api-&gt;cURL_source['user_timeline']);
+                $this-&gt;logger-&gt;logStatus($stale_friend-&gt;user_name.&quot; is friend most need of update&quot;, get_class($this));
+                $stale_friend_tweets = str_replace(&quot;[id]&quot;, $stale_friend-&gt;user_name, $this-&gt;api-&gt;cURL_source['user_timeline']);
                 $args = array();
                 $args[&quot;count&quot;] = 200;
                 
@@ -533,20 +534,20 @@ class Crawler {
                     $args['since_id'] = $stale_friend-&gt;last_status_id;
                 }
                 
-                list($cURL_status, $twitter_data) = $api-&gt;apiRequest($stale_friend_tweets, $logger, $args);
+                list($cURL_status, $twitter_data) = $this-&gt;api-&gt;apiRequest($stale_friend_tweets, $this-&gt;logger, $args);
                 
                 if ($cURL_status == 200) {
                     try {
                         $count = 0;
-                        $tweets = $api-&gt;parseXML($twitter_data);
+                        $tweets = $this-&gt;api-&gt;parseXML($twitter_data);
                         
                         if (count($tweets) &gt; 0) {
                             foreach ($tweets as $tweet) {
                             
-                                if ($td-&gt;addTweet($tweet, $stale_friend, $logger) &gt; 0) {
+                                if ($td-&gt;addTweet($tweet, $stale_friend, $this-&gt;logger) &gt; 0) {
                                     $count++;
                                     //expand and insert links contained in tweet
-                                    $this-&gt;processTweetURLs($tweet, $cfg, $logger);
+                                    $this-&gt;processTweetURLs($tweet, $lurl, $fa);
                                 }
                                 //Update stale_friend values here
                                 $stale_friend-&gt;full_name = $tweet['full_name'];
@@ -563,82 +564,82 @@ class Crawler {
                                 if ($tweet['status_id'] &gt; $stale_friend-&gt;last_status_id) {
                                     $stale_friend-&gt;last_status_id = $tweet['status_id'];
                                 }
-                                $ud-&gt;updateUser($stale_friend, $logger);
+                                $ud-&gt;updateUser($stale_friend, $this-&gt;logger);
                             }
                         } else {
-                            $this-&gt;fetchAndAddUser($stale_friend-&gt;id, $api, $logger, $cfg, &quot;Friends&quot;);
+                            $this-&gt;fetchAndAddUser($stale_friend-&gt;id, &quot;Friends&quot;);
                         }
                         
-                        $logger-&gt;logStatus(count($tweets).&quot; tweet(s) found for &quot;.$stale_friend-&gt;username.&quot; and $count saved&quot;, get_class($this));
+                        $this-&gt;logger-&gt;logStatus(count($tweets).&quot; tweet(s) found for &quot;.$stale_friend-&gt;username.&quot; and $count saved&quot;, get_class($this));
                     }
                     catch(Exception $e) {
-                        $logger-&gt;logStatus('Could not parse friends XML for $stale_friend-&gt;username', get_class($this));
+                        $this-&gt;logger-&gt;logStatus('Could not parse friends XML for $stale_friend-&gt;username', get_class($this));
                     }
-                    $this-&gt;fetchUserFriends($stale_friend-&gt;id, $api, $logger, $fd);
+                    $this-&gt;fetchUserFriends($stale_friend-&gt;id, $fd);
                 } elseif ($cURL_status == 401 || $cURL_status == 404) {
                     try {
-                        $e = $api-&gt;parseError($twitter_data);
+                        $e = $this-&gt;api-&gt;parseError($twitter_data);
                         $ued = new UserErrorDAO();
-                        $ued-&gt;insertError($stale_friend-&gt;id, $cURL_status, $e['error'], $cfg-&gt;twitter_user_id);
-                        $logger-&gt;logStatus('User error saved', get_class($this));
+                        $ued-&gt;insertError($stale_friend-&gt;id, $cURL_status, $e['error'], $this-&gt;owner_object-&gt;id);
+                        $this-&gt;logger-&gt;logStatus('User error saved', get_class($this));
                     }
                     catch(Exception $e) {
-                        $logger-&gt;logStatus('Could not parse timeline error for $stale_friend-&gt;username', get_class($this));
+                        $this-&gt;logger-&gt;logStatus('Could not parse timeline error for $stale_friend-&gt;username', get_class($this));
                     }
                 }
             } else {
-                $logger-&gt;logStatus('No friend staler than 1 day', get_class($this));
+                $this-&gt;logger-&gt;logStatus('No friend staler than 1 day', get_class($this));
                 $continue_fetching = false;
             }
             
         }
     }
     
-    function fetchStrayRepliedToTweets($cfg, $api, $logger) {
+    function fetchStrayRepliedToTweets($lurl, $fa) {
         $td = new TweetDAO();
-        $strays = $td-&gt;getStrayRepliedToTweets($cfg-&gt;twitter_user_id);
+        $strays = $td-&gt;getStrayRepliedToTweets($this-&gt;owner_object-&gt;id);
         $status_message = count($strays).' stray replied-to tweets to load.';
-        $logger-&gt;logStatus($status_message, get_class($this));
+        $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
         
         foreach ($strays as $s) {
-            if ($api-&gt;available &amp;&amp; $api-&gt;available_api_calls_for_crawler &gt; 0)
-                $this-&gt;fetchAndAddTweetRepliedTo($s['in_reply_to_status_id'], $td, $api, $logger, $cfg);
+            if ($this-&gt;api-&gt;available &amp;&amp; $this-&gt;api-&gt;available_api_calls_for_crawler &gt; 0)
+                $this-&gt;fetchAndAddTweetRepliedTo($s['in_reply_to_status_id'], $td, $lurl, $fa);
         }
     }
     
-    function fetchUnloadedFollowerDetails($cfg, $api, $logger) {
+    function fetchUnloadedFollowerDetails() {
         $fd = new FollowDAO();
-        $strays = $fd-&gt;getUnloadedFollowerDetails($cfg-&gt;twitter_user_id);
+        $strays = $fd-&gt;getUnloadedFollowerDetails($this-&gt;owner_object-&gt;id);
         $status_message = count($strays).' unloaded follower details to load.';
-        $logger-&gt;logStatus($status_message, get_class($this));
+        $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
         
         foreach ($strays as $s) {
-            if ($api-&gt;available &amp;&amp; $api-&gt;available_api_calls_for_crawler &gt; 0)
-                $this-&gt;fetchAndAddUser($s['follower_id'], $api, $logger, $cfg, &quot;Follower IDs&quot;);
+            if ($this-&gt;api-&gt;available &amp;&amp; $this-&gt;api-&gt;available_api_calls_for_crawler &gt; 0)
+                $this-&gt;fetchAndAddUser($s['follower_id'], &quot;Follower IDs&quot;);
         }
     }
     
-    private function fetchUserFriends($uid, $api, $logger, $fd) {
+    private function fetchUserFriends($uid, $fd) {
         $continue_fetching = true;
         $last_page_fetched_friend_ids = 0;
         $status_message = &quot;&quot;;
         
-        while ($api-&gt;available &amp;&amp; $api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $continue_fetching) {
+        while ($this-&gt;api-&gt;available &amp;&amp; $this-&gt;api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $continue_fetching) {
         
             $last_page_fetched_friend_ids = $last_page_fetched_friend_ids + 1;
             
             $args = array();
-            $friend_ids = str_replace(&quot;[id]&quot;, $uid, $api-&gt;cURL_source['following_ids']);
+            $friend_ids = str_replace(&quot;[id]&quot;, $uid, $this-&gt;api-&gt;cURL_source['following_ids']);
             $args['page'] = $last_page_fetched_friend_ids;
             
-            list($cURL_status, $twitter_data) = $api-&gt;apiRequest($friend_ids, $logger, $args);
+            list($cURL_status, $twitter_data) = $this-&gt;api-&gt;apiRequest($friend_ids, $this-&gt;logger, $args);
             
             if ($cURL_status &gt; 200) {
                 $continue_fetching = false;
             } else {
             
                 try {
-                    $ids = $api-&gt;parseXML($twitter_data);
+                    $ids = $this-&gt;api-&gt;parseXML($twitter_data);
                     $status_message = &quot;Page &quot;.$last_page_fetched_friend_ids.&quot; has &quot;.count($ids).&quot; friend IDs. &quot;;
                     
                     if (count($ids) == 0)
@@ -665,29 +666,29 @@ class Crawler {
                 catch(Exception $e) {
                     $status_message = 'Could not parse follower ID XML for $uid';
                 }
-                $logger-&gt;logStatus($status_message, get_class($this));
+                $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
                 $status_message = &quot;&quot;;
                 
             }
             
-            $logger-&gt;logStatus($status_message, get_class($this));
+            $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
             $status_message = &quot;&quot;;
             
         }
         
     }
     
-    private function fetchAndAddUser($fid, $api, $logger, $cfg, $source) {
+    private function fetchAndAddUser($fid, $source) {
         //fetch user from Twitter and add to DB
         $status_message = &quot;&quot;;
-        $u_deets = str_replace(&quot;[id]&quot;, $fid, $api-&gt;cURL_source['show_user']);
-        list($cURL_status, $twitter_data) = $api-&gt;apiRequest($u_deets, $logger);
+        $u_deets = str_replace(&quot;[id]&quot;, $fid, $this-&gt;api-&gt;cURL_source['show_user']);
+        list($cURL_status, $twitter_data) = $this-&gt;api-&gt;apiRequest($u_deets, $this-&gt;logger);
         
         if ($cURL_status == 200) {
             try {
-                $user_arr = $api-&gt;parseXML($twitter_data);
+                $user_arr = $this-&gt;api-&gt;parseXML($twitter_data);
                 $user = new User($user_arr[0], $source);
-                $this-&gt;ud-&gt;updateUser($user, $logger);
+                $this-&gt;ud-&gt;updateUser($user, $this-&gt;logger);
                 $status_message = 'Added/updated user '.$user-&gt;username.&quot; in database&quot;;
             }
             catch(Exception $e) {
@@ -695,9 +696,9 @@ class Crawler {
             }
         } elseif ($cURL_status == 404) {
             try {
-                $e = $api-&gt;parseError($twitter_data);
+                $e = $this-&gt;api-&gt;parseError($twitter_data);
                 $ued = new UserErrorDAO();
-                $ued-&gt;insertError($fid, $cURL_status, $e['error'], $cfg-&gt;twitter_user_id);
+                $ued-&gt;insertError($fid, $cURL_status, $e['error'], $this-&gt;owner_object-&gt;id);
                 $status_message = 'User error saved.';
                 
             }
@@ -706,29 +707,29 @@ class Crawler {
             }
             
         }
-        $logger-&gt;logStatus($status_message, get_class($this));
+        $this-&gt;logger-&gt;logStatus($status_message, get_class($this));
         $status_message = &quot;&quot;;
         
     }
     
     // For each API call left, grab oldest follow relationship, check if it exists, and update table
-    function cleanUpFollows($cfg, $api, $logger) {
+    function cleanUpFollows() {
         $fd = new FollowDAO();
         $continue_fetching = true;
-        while ($api-&gt;available &amp;&amp; $api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $continue_fetching) {
+        while ($this-&gt;api-&gt;available &amp;&amp; $this-&gt;api-&gt;available_api_calls_for_crawler &gt; 0 &amp;&amp; $continue_fetching) {
         
             $oldfollow = $fd-&gt;getOldestFollow();
             
-            $friendship_call = $api-&gt;cURL_source['show_friendship'];
+            $friendship_call = $this-&gt;api-&gt;cURL_source['show_friendship'];
             $args = array();
             $args[&quot;source_id&quot;] = $oldfollow[&quot;followee_id&quot;];
             $args[&quot;target_id&quot;] = $oldfollow[&quot;follower_id&quot;];
             
-            list($cURL_status, $twitter_data) = $api-&gt;apiRequest($friendship_call, $logger, $args);
+            list($cURL_status, $twitter_data) = $this-&gt;api-&gt;apiRequest($friendship_call, $this-&gt;logger, $args);
             
             if ($cURL_status == 200) {
                 try {
-                    $friendship = $api-&gt;parseXML($twitter_data);
+                    $friendship = $this-&gt;api-&gt;parseXML($twitter_data);
                     if ($friendship['source_follows_target'] == 'true')
                         $fd-&gt;update($oldfollow[&quot;followee_id&quot;], $oldfollow[&quot;follower_id&quot;]);
                     else</diff>
      <filename>common/class.Crawler.php</filename>
    </modified>
    <modified>
      <diff>@@ -4,23 +4,25 @@ class Database {
     var $db_name;
     var $db_user;
     var $db_password;
-
+    var $logger = null;
     
-    function Database() {
-        global $TWITALYTIC_CFG;
+    function Database($TWITALYTIC_CFG) {
         $this-&gt;db_host = $TWITALYTIC_CFG['db_host'];
         $this-&gt;db_name = $TWITALYTIC_CFG['db_name'];
         $this-&gt;db_user = $TWITALYTIC_CFG['db_user'];
         $this-&gt;db_password = $TWITALYTIC_CFG['db_password'];
+		//TODO: Get optional table name prefix from CFG array and set it here
+		//TODO: Get GMT server offset here
     }
     
     function getConnection() {
-        $conn = mysql_connect($this-&gt;db_host, $this-&gt;db_user, $this-&gt;db_password) or die(&quot;DIE: &quot;.mysql_error().$this-&gt;db_host.$this-&gt;db_user.$this-&gt;db_password);
-        
-        //echo &quot;select this db: &quot; .$this-&gt;db_name.&quot;&lt;br /&gt;&quot;;
-        
-        mysql_select_db($this-&gt;db_name, $conn) or die(mysql_errno().&quot; &quot;.mysql_error());
-        
+        $fail = false;
+        $conn = mysql_connect($this-&gt;db_host, $this-&gt;db_user, $this-&gt;db_password) or $fail = true;
+        if ($fail)
+            throw new Exception(&quot;ERROR: &quot;.mysql_error().$this-&gt;db_host.$this-&gt;db_user.$this-&gt;db_password);
+        mysql_select_db($this-&gt;db_name, $conn) or $fail = true;
+        if ($fail)
+            throw new Exception(&quot;ERROR: &quot;.mysql_errno().&quot; &quot;.mysql_error());
         return $conn;
     }
     
@@ -29,8 +31,20 @@ class Database {
     }
     
     public static function exec($q) {
+    	//TODO: Process the table prefix--replace table name with prefix_tablename
+		//TOOD: Process GMT offset in query
+    	//TODO: On failure throw an exception here, catch and log inside DAO's with mysql error
         $r = mysql_query($q) or die(&quot;Query failed:&lt;br /&gt; $q &lt;br /&gt;&lt;br /&gt;Error details:&lt;br /&gt;&quot;.mysql_error());
         return $r;
     }
+    
+	/*
+    function logOrDie($s) {
+        if ($this-&gt;logger != null)
+            $this-&gt;logger-&gt;logStatus($s, get_class($this));
+        else
+            die($s);
+    }
+    */
 }
 ?&gt;</diff>
      <filename>common/class.Database.php</filename>
    </modified>
    <modified>
      <diff>@@ -5,8 +5,8 @@ class FlickrAPIAccessor {
     var $method = &quot;flickr.photos.getSizes&quot;;
     var $api_key;
     
-    function FlickrAPIAccessor($cfg) {
-        $this-&gt;api_key = $cfg-&gt;flickr_api_key;
+    function FlickrAPIAccessor($flickr_api_key) {
+        $this-&gt;api_key = $flickr_api_key;
     }
     
     function getFlickrPhotoSource($u) {</diff>
      <filename>common/class.FlickrAPIAccessor.php</filename>
    </modified>
    <modified>
      <diff>@@ -3,13 +3,14 @@ class Logger {
     var $log;
     var $twitter_username;
     
-    function Logger($username, $location) {
-        $this-&gt;twitter_username = $username;
-        $log_file = $location; # Where will you keep the log
-        $this-&gt;log = $this-&gt;openFile($log_file, 'a'); # Append to any prior file
+    function Logger($location) {
+        $this-&gt;log = $this-&gt;openFile($location, 'a'); # Append to any prior file
     }
-
     
+    function setUsername($uname) {
+        $this-&gt;twitter_username = $uname;
+    }
+	
     function logStatus($status_message, $classname) {
         $status_signature = date(&quot;Y-m-d H:i:s&quot;, time()).&quot; | &quot;.(string) number_format(round(memory_get_usage() / 1024000, 2), 2).&quot; MB | $this-&gt;twitter_username | $classname:&quot;;
         if (strlen($status_message) &gt; 0) {</diff>
      <filename>common/class.Logger.php</filename>
    </modified>
    <modified>
      <diff>@@ -6,8 +6,8 @@ class LongUrlAPIAccessor {
     var $response_code = 1;
     var $title = 1;
     
-    function LongUrlAPIAccessor($cfg) {
-        $this-&gt;user_agent = $cfg-&gt;app_title;
+    function LongUrlAPIAccessor($app_title) {
+        $this-&gt;user_agent = $app_title;
     }
     
     function expandUrl($u) {</diff>
      <filename>common/class.LongUrlAPIAccessor.php</filename>
    </modified>
    <modified>
      <diff>@@ -7,11 +7,11 @@ class TwitterAPIAccessorOAuth {
     var $oauth_access_token;
     var $oauth_access_token_secret;
     
-    function TwitterAPIAccessorOAuth($oauth_access_token, $oauth_access_token_secret, $cfg) {
+    function TwitterAPIAccessorOAuth($oauth_access_token, $oauth_access_token_secret, $oauth_consumer_key, $oauth_consumer_secret) {
         $this-&gt;$oauth_access_token = $oauth_access_token;
         $this-&gt;$oauth_access_token_secret = $oauth_access_token_secret;
         
-        $this-&gt;to = new TwitterOAuth($cfg-&gt;oauth_consumer_key, $cfg-&gt;oauth_consumer_secret, $this-&gt;$oauth_access_token, $this-&gt;$oauth_access_token_secret);
+        $this-&gt;to = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret, $this-&gt;$oauth_access_token, $this-&gt;$oauth_access_token_secret);
         $this-&gt;cURL_source = $this-&gt;prepAPI();
     }
     
@@ -262,10 +262,12 @@ class CrawlerTwitterAPIAccessorOAuth extends TwitterAPIAccessorOAuth {
     var $available_api_calls_for_crawler = null;
     var $available_api_calls_for_twitter = null;
     var $api_hourly_limit = null;
-    
-    function CrawlerTwitterAPIAccessorOAuth($oauth_token, $oauth_token_secret, $cfg, $instance) {
-        parent::TwitterAPIAccessorOAuth($oauth_token, $oauth_token_secret, $cfg);
+    var $archive_limit;
+	
+    function CrawlerTwitterAPIAccessorOAuth($oauth_token, $oauth_token_secret, $oauth_consumer_key, $oauth_consumer_secret, $instance, $archive_limit) {
+        parent::TwitterAPIAccessorOAuth($oauth_token, $oauth_token_secret, $oauth_consumer_key, $oauth_consumer_secret);
         $this-&gt;api_calls_to_leave_unmade_per_minute = $instance-&gt;api_calls_to_leave_unmade_per_minute;
+		$this-&gt;archive_limit = $archive_limit;
     }
     
     function init($logger) {</diff>
      <filename>common/class.TwitterAPIAccessorOAuth.php</filename>
    </modified>
    <modified>
      <diff>@@ -3,51 +3,57 @@ require_once('config.crawler.inc.php');
 ini_set(&quot;include_path&quot;, ini_get(&quot;include_path&quot;).PATH_SEPARATOR.$INCLUDE_PATH);
 require_once(&quot;init.php&quot;);
 
-// Instantiate and initialize needed objects
-$db = new Database();
+$db = new Database($TWITALYTIC_CFG);
 $conn = $db-&gt;getConnection();
+
+$logger = new Logger($TWITALYTIC_CFG['log_location']);
 $id = new InstanceDAO();
 $oid = new OwnerInstanceDAO();
+$lurlapi = new LongUrlAPIAccessor($TWITALYTIC_CFG['app_title']);
+$flickrapi = new FlickrAPIAccessor($TWITALYTIC_CFG['flickr_api_key']);
+
 
 $instances = $id-&gt;getAllInstancesStalestFirst();
 foreach ($instances as $i) {
-	$crawler = new Crawler($i);
-	$cfg = new Config($i-&gt;twitter_username, $i-&gt;twitter_user_id);
-	$logger = new Logger($i-&gt;twitter_username, $cfg-&gt;log_location);
+	$logger-&gt;setUsername($i-&gt;twitter_username);
 	$tokens = $oid-&gt;getOAuthTokens($i-&gt;id);
-	$api = new CrawlerTwitterAPIAccessorOAuth($tokens['oauth_access_token'], $tokens['oauth_access_token_secret'], $cfg, $i);
-	$api -&gt; init($logger);
+	$api = new CrawlerTwitterAPIAccessorOAuth($tokens['oauth_access_token'], $tokens['oauth_access_token_secret'], $TWITALYTIC_CFG['oauth_consumer_key'], $TWITALYTIC_CFG['oauth_consumer_secret'], $i, $TWITALYTIC_CFG['archive_limit']);
+	$crawler = new Crawler($i, $logger, $api);
+	$cfg = new Config($i-&gt;twitter_username, $i-&gt;twitter_user_id);
+	
+	$api-&gt;init($logger);
 
 	if ( $api-&gt;available_api_calls_for_crawler &gt; 0 ) {
 
 		$id-&gt;updateLastRun($i-&gt;id);
 		
-		$crawler-&gt;fetchInstanceUserInfo($cfg, $api, $logger);
+		$crawler-&gt;fetchInstanceUserInfo();
 
-		$crawler-&gt;fetchInstanceUserTweets($cfg, $api, $logger);
+		$crawler-&gt;fetchInstanceUserTweets($lurlapi, $flickrapi);
 
-		$crawler-&gt;fetchInstanceUserReplies($cfg, $api, $logger);
+		$crawler-&gt;fetchInstanceUserReplies($lurlapi, $flickrapi);
 
-		$crawler-&gt;fetchInstanceUserFriends($cfg, $api, $logger);
+		$crawler-&gt;fetchInstanceUserFriends();
 
-		$crawler-&gt;fetchInstanceUserFollowers($cfg, $api, $logger);
+		$crawler-&gt;fetchInstanceUserFollowers();
 
-		$crawler-&gt;fetchStrayRepliedToTweets($cfg, $api, $logger);
+		$crawler-&gt;fetchStrayRepliedToTweets($lurlapi, $flickrapi);
 
-		$crawler-&gt;fetchUnloadedFollowerDetails($cfg, $api, $logger);
+		$crawler-&gt;fetchUnloadedFollowerDetails();
 
-		$crawler-&gt;fetchFriendTweetsAndFriends($cfg, $api, $logger);
+		$crawler-&gt;fetchFriendTweetsAndFriends($lurlapi, $flickrapi);
 
 		// TODO: Get direct messages
 		// TODO: Gather favorites data
 
-		$crawler-&gt;cleanUpFollows($cfg, $api, $logger);
+		$crawler-&gt;cleanUpFollows();
 	
 		// Save instance
 		$id-&gt;save($crawler-&gt;instance,  $crawler-&gt;owner_object-&gt;tweet_count, $logger, $api);
 	} 
-	$logger-&gt;close();			# Close logging
 }
 
+$logger-&gt;close();			# Close logging
+
 if ( isset($conn) ) $db-&gt;closeConnection($conn); // Clean up
 ?&gt;
\ No newline at end of file</diff>
      <filename>crawler/crawl.php</filename>
    </modified>
    <modified>
      <diff>@@ -9,12 +9,14 @@ require_once(dirname(__FILE__) . '/simpletest/mock_objects.php');
 
 require_once('log_test.php');
 require_once('config_test.php');
+require_once('database_test.php');
 require_once('twitteroauth_test.php');
 
 $test = &amp;new GroupTest('All tests');
 $test-&gt;addTestCase(new TestOfConfig());
 $test-&gt;addTestCase(new TestOfLogging());
 $test-&gt;addTestCase(new TestOfTwitterOAuth());
+$test-&gt;addTestCase(new TestOfDatabase());
 
 //$test-&gt;run(new HtmlReporter());
 $test-&gt;run(new TextReporter());</diff>
      <filename>tests/all_tests.php</filename>
    </modified>
    <modified>
      <diff>@@ -22,12 +22,17 @@ class TestOfLogging extends UnitTestCase {
     
     function testCreatingNewLogger() {
         global $TWITALYTIC_CFG;
-        $logger = new Logger('ginatrapani', $TWITALYTIC_CFG['log_location']);
+        $logger = new Logger($TWITALYTIC_CFG['log_location']);
         $logger-&gt;logStatus('Should write this to the log', get_class($this));
         $this-&gt;assertTrue(file_exists($TWITALYTIC_CFG['log_location']), 'File created');
         
         $messages = file($TWITALYTIC_CFG['log_location']);
         $this-&gt;assertWantedPattern('/Should write this to the log/', $messages[sizeof($messages) - 1]);
+		
+		$logger-&gt;setUsername('ginatrapani');
+        $logger-&gt;logStatus('Should write this to the log with a username', get_class($this));
+        $this-&gt;assertWantedPattern('/ginatrapani | TestOfLogging:Should write this to the log/', $messages[sizeof($messages) - 1]);
+		
         $logger-&gt;close();
         
     }</diff>
      <filename>tests/log_test.php</filename>
    </modified>
    <modified>
      <diff>@@ -24,7 +24,7 @@ else
 $tu = $_POST['twitter_username'];
 $tp = $_POST['twitter_password'];
 
-$db = new Database();
+$db = new Database($TWITALYTIC_CFG);
 $conn = $db-&gt;getConnection();
 $od = new OwnerDAO();
 </diff>
      <filename>webapp/account/add.php</filename>
    </modified>
    <modified>
      <diff>@@ -8,7 +8,7 @@ require_once('config.webapp.inc.php');
 ini_set(&quot;include_path&quot;, ini_get(&quot;include_path&quot;).PATH_SEPARATOR.$INCLUDE_PATH);
 require_once(&quot;init.php&quot;);
 
-$db = new Database();
+$db = new Database($TWITALYTIC_CFG);
 $conn = $db-&gt;getConnection();
 
 $id = new InstanceDAO();</diff>
      <filename>webapp/account/index.php</filename>
    </modified>
    <modified>
      <diff>@@ -29,7 +29,7 @@ if ( isset( $tok['oauth_token'] ) &amp;&amp; isset($tok['oauth_token_secret']) ) {
 	$twitter_id = $u['user_id'];
 	$tu = $u['user_name']; 
 	
-	$db = new Database();
+	$db = new Database($TWITALYTIC_CFG);
 	$conn = $db-&gt;getConnection();
 	$od = new OwnerDAO();
 </diff>
      <filename>webapp/account/oauth.php</filename>
    </modified>
    <modified>
      <diff>@@ -13,7 +13,7 @@ ini_set(&quot;include_path&quot;, ini_get(&quot;include_path&quot;).PATH_SEPARATOR.$INCLUDE_PATH);
 require_once(&quot;init.php&quot;);
 
 $cfg = new Config();
-$db = new Database();
+$db = new Database($TWITALYTIC_CFG);
 $conn = $db-&gt;getConnection();
 
 $id = new InstanceDAO();</diff>
      <filename>webapp/account/toggle-public.php</filename>
    </modified>
    <modified>
      <diff>@@ -13,7 +13,7 @@ ini_set(&quot;include_path&quot;, ini_get(&quot;include_path&quot;).PATH_SEPARATOR.$INCLUDE_PATH);
 require_once(&quot;init.php&quot;);
 
 
-$db = new Database();
+$db = new Database($TWITALYTIC_CFG);
 $conn = $db-&gt;getConnection();
 
 $od = new OwnerDAO();</diff>
      <filename>webapp/index.php</filename>
    </modified>
    <modified>
      <diff>@@ -9,7 +9,7 @@ require_once(&quot;init.php&quot;);
 
 
 
-$db = new Database();
+$db = new Database($TWITALYTIC_CFG);
 $conn = $db-&gt;getConnection();
 
 $od = new OwnerDAO();</diff>
      <filename>webapp/inline.view.php</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ require_once('config.webapp.inc.php');
 ini_set(&quot;include_path&quot;, ini_get(&quot;include_path&quot;). PATH_SEPARATOR .$INCLUDE_PATH);
 require_once(&quot;init.php&quot;);
 
-$db = new Database();
+$db = new Database($TWITALYTIC_CFG);
 $conn = $db-&gt;getConnection();
 
 $td = new TweetDAO();</diff>
      <filename>webapp/public.php</filename>
    </modified>
    <modified>
      <diff>@@ -8,7 +8,7 @@ require_once('config.webapp.inc.php');
 ini_set(&quot;include_path&quot;, ini_get(&quot;include_path&quot;).PATH_SEPARATOR.$INCLUDE_PATH);
 require_once(&quot;init.php&quot;);
 
-$db = new Database();
+$db = new Database($TWITALYTIC_CFG);
 $conn = $db-&gt;getConnection();
 
 $od = new OwnerDAO();</diff>
      <filename>webapp/status/export.php</filename>
    </modified>
    <modified>
      <diff>@@ -8,7 +8,7 @@ require_once('config.webapp.inc.php');
 ini_set(&quot;include_path&quot;, ini_get(&quot;include_path&quot;).PATH_SEPARATOR.$INCLUDE_PATH);
 require_once(&quot;init.php&quot;);
 
-$db = new Database();
+$db = new Database($TWITALYTIC_CFG);
 $conn = $db-&gt;getConnection();
 
 $td = new TweetDAO();</diff>
      <filename>webapp/status/index.php</filename>
    </modified>
    <modified>
      <diff>@@ -27,7 +27,7 @@ ini_set(&quot;include_path&quot;, ini_get(&quot;include_path&quot;).PATH_SEPARATOR.$INCLUDE_PATH);
 require_once(&quot;init.php&quot;);
 
 $cfg = new Config();
-$db = new Database();
+$db = new Database($TWITALYTIC_CFG);
 $conn = $db-&gt;getConnection();
 
 $td = new TweetDAO();</diff>
      <filename>webapp/status/mark-parent.php</filename>
    </modified>
    <modified>
      <diff>@@ -6,7 +6,7 @@ ini_set(&quot;include_path&quot;, ini_get(&quot;include_path&quot;).PATH_SEPARATOR.$INCLUDE_PATH);
 require_once(&quot;init.php&quot;);
 
 $cfg = new Config();
-$db = new Database();
+$db = new Database($TWITALYTIC_CFG);
 $s = new SmartyTwitalytic();
 $c = new Crawler();
 </diff>
      <filename>webapp/status/public.php</filename>
    </modified>
    <modified>
      <diff>@@ -3,14 +3,14 @@
 			&lt;div class=&quot;person-info&quot;&gt;
 				&lt;a href=&quot;{$cfg-&gt;site_root_path}user/?u={$r.questioner}&amp;i={$i-&gt;twitter_username}&quot;&gt;&lt;img src=&quot;{$r.questioner_avatar}&quot; width=&quot;48&quot; height=&quot;48&quot; class=&quot;avatar&quot;&gt;&lt;/a&gt;
 				&lt;h3 class=&quot;username&quot;&gt;&lt;a href=&quot;{$cfg-&gt;site_root_path}user/?u={$r.questioner}&amp;i={$i-&gt;twitter_username}&quot;&gt;{if $r.questioner eq $instance-&gt;twitter_username}You{else}{$r.questioner}{/if}&lt;/a&gt;&lt;/h3&gt;
-				&lt;h4 class=&quot;follower-count&quot;&gt;{$t.follower_count|number_format}&lt;/h4&gt;
+				&lt;h4 class=&quot;follower-count&quot;&gt;{$t-&gt;follower_count|number_format}&lt;/h4&gt;
 			&lt;/div&gt;
 				
 			&lt;div class=&quot;tweet-body&quot;&gt;
 				&lt;p&gt;{$r.question|regex_replace:&quot;/^@[a-zA-Z0-9_]+/&quot;:&quot;&quot;|link_usernames}&lt;/p&gt;
-				&lt;h3&gt;&lt;a href=&quot;{$cfg-&gt;site_root_path}status/?t={$r.status_id}&quot;&gt;{$r.question_adj_pub_date|relative_datetime}&lt;/a&gt;&lt;h3&gt;
-				{if $r.location}&lt;h4 class=&quot;tweetstamp&quot;&gt;{$r.location}&lt;/h4&gt;{/if}
-				{if $r.description}&lt;h4 class=&quot;person-description&quot;&gt;{$r.description}&lt;/h4&gt;{/if}
+				&lt;h3&gt;&lt;a href=&quot;{$cfg-&gt;site_root_path}status/?t={$r.status_id}&quot;&gt;{$r-&gt;question_adj_pub_date|relative_datetime}&lt;/a&gt;&lt;h3&gt;
+				{if $r.location}&lt;h4 class=&quot;tweetstamp&quot;&gt;{$r-&gt;location}&lt;/h4&gt;{/if}
+				{if $r.description}&lt;h4 class=&quot;person-description&quot;&gt;{$r-&gt;description}&lt;/h4&gt;{/if}
 
 			&lt;/div&gt;
 		</diff>
      <filename>webapp/templates/_status.qa.tpl</filename>
    </modified>
    <modified>
      <diff>@@ -8,7 +8,7 @@ require_once('config.webapp.inc.php');
 ini_set(&quot;include_path&quot;, ini_get(&quot;include_path&quot;).PATH_SEPARATOR.$INCLUDE_PATH);
 require_once(&quot;init.php&quot;);
 
-$db = new Database();
+$db = new Database($TWITALYTIC_CFG);
 $conn = $db-&gt;getConnection();
 
 $ud = new UserDAO();</diff>
      <filename>webapp/user/index.php</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>crawler/logs/crawler.log</filename>
    </removed>
    <removed>
      <filename>tests/config.tests.inc.php</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>dd67e600ace1b6b70948e5ae8d30de4b1816f6a0</id>
    </parent>
  </parents>
  <author>
    <name>Gina Trapani</name>
    <email>ginatrapani@gmail.com</email>
  </author>
  <url>http://github.com/ginatrapani/twitalytic/commit/22f522c10cccf5a8b724b65d005132e9b3276193</url>
  <id>22f522c10cccf5a8b724b65d005132e9b3276193</id>
  <committed-date>2009-09-06T23:27:59-07:00</committed-date>
  <authored-date>2009-09-06T23:27:59-07:00</authored-date>
  <message>Major code cleanup; Refined method interfaces; Added more tests; foundations of table prefix and timezone support laid</message>
  <tree>f0a846c98538e2489c83d5d3f85e5da974bee48c</tree>
  <committer>
    <name>Gina Trapani</name>
    <email>ginatrapani@gmail.com</email>
  </committer>
</commit>
