<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>add_movie.css</filename>
    </added>
    <added>
      <filename>empty_star.gif</filename>
    </added>
    <added>
      <filename>full_star.gif</filename>
    </added>
    <added>
      <filename>wp_movie_ratings.css</filename>
    </added>
    <added>
      <filename>wp_movie_ratings.php</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,7 @@
 
 //var url = 'http://wieprz.oi.pg.gda.pl/pawel/wp_movie_ratings/index.php'
 
+// AJAX activity indicators
 Ajax.Responders.register({
   onCreate: function() {
     if($('loading') &amp;&amp; Ajax.activeRequestCount&gt;0)
@@ -12,6 +13,7 @@ Ajax.Responders.register({
   }
 });
 
+// Cross-browser AddEvent function
 function addEvent(obj, evType, fn) { 
 	if (obj.addEventListener) {
 		obj.addEventListener(evType, fn, false); 
@@ -24,11 +26,11 @@ function addEvent(obj, evType, fn) {
 	} 
 }
 
+// attach separate AJAX call to each star
 function add_behaviour() {
 	// get &lt;a href&gt; stars
 	var elements = $A( $('rating').getElementsByTagName('a') )
 	
-	// attach separate AJAX call to each star
 	elements.each( function(node) {
 		node.addEventListener('click', function () {
 			var msg = $('message')
@@ -44,6 +46,7 @@ function add_behaviour() {
 	})
 }
 
+// show AJAX response
 function show_response(originalRequest) {
 	var msg = $('message')
 	msg.innerHTML = unescape(originalRequest.responseText)
@@ -51,4 +54,3 @@ function show_response(originalRequest) {
 }
 
 addEvent(window, 'load', add_behaviour);
-</diff>
      <filename>add_movie.js</filename>
    </modified>
    <modified>
      <diff>@@ -2,14 +2,15 @@
 &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; lang=&quot;en&quot; xml:lang=&quot;en&quot;&gt;
 &lt;head&gt;
 &lt;title&gt;iMDB movie ratings&lt;/title&gt;
-&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;screen&quot; href=&quot;imdb.css&quot; /&gt;
+&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF8&quot; /&gt;
+&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;screen&quot; href=&quot;add_movie.css&quot; /&gt;
 &lt;script type=&quot;text/javascript&quot; src=&quot;prototype.js&quot;&gt;&lt;/script&gt;
 &lt;script type=&quot;text/javascript&quot; src=&quot;effects.js&quot;&gt;&lt;/script&gt;
 &lt;script type=&quot;text/javascript&quot; src=&quot;add_movie.js&quot;&gt;&lt;/script&gt;
 &lt;/head&gt;
 &lt;body&gt;
 
-&lt;form id=&quot;movie_data&quot; method=&quot;post&quot;&gt;
+&lt;form id=&quot;movie_data&quot; action=&quot;post&quot;&gt;
 
 &lt;p&gt;
 &lt;label for=&quot;url&quot;&gt;iMDB link:&lt;/label&gt;
@@ -18,6 +19,8 @@
 
 &lt;p&gt;
 &lt;label&gt;Movie rating:&lt;/label&gt;
+&lt;/p&gt;
+
 &lt;ul class=&quot;star-rating&quot; id=&quot;rating&quot;&gt;
 &lt;li&gt;&lt;a id=&quot;rating1&quot; href=&quot;#&quot; title=&quot;Rate this movie 1 star out of 10&quot; class=&quot;one-star&quot;&gt;&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a id=&quot;rating2&quot; href=&quot;#&quot; title=&quot;Rate this movie 2 stars out of 10&quot; class=&quot;two-stars&quot;&gt;&lt;/a&gt;&lt;/li&gt;
@@ -31,7 +34,6 @@
 &lt;li&gt;&lt;a id=&quot;rating10&quot; href=&quot;#&quot; title=&quot;Rate this movie 10 stars out of 10&quot; class=&quot;ten-stars&quot;&gt;&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;img id=&quot;loading&quot; src=&quot;loading.gif&quot; alt=&quot;Sending request... please wait.&quot; style=&quot;display: none&quot; /&gt;&lt;/li&gt;
 &lt;/ul&gt;
-&lt;/p&gt;
 
 &lt;/form&gt;
 </diff>
      <filename>add_movie.php</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1,10 @@
 &lt;?php
 
+# Get title of the movie and save its rating in the database
 if (isset($_POST[&quot;url&quot;]) &amp;&amp; isset($_POST[&quot;rating&quot;]))
 {
-	require_once(&quot;movie.class.php&quot;);
 	require_once(&quot;httprequest.class.php&quot;);
+	require_once(&quot;movie.class.php&quot;);
 
 	$url = rawurldecode(trim($_POST[&quot;url&quot;]));
 	$rating = intval($_POST[&quot;rating&quot;]);</diff>
      <filename>index.php</filename>
    </modified>
    <modified>
      <diff>@@ -1,21 +1,44 @@
-&lt;?php 
+&lt;?php
 
 class Movie
 {
-	var $_url;        # http://us.imdb.com/title/tt0424205/
-	var $_url_short;  # 0424205
-	var $_title;      # Joyeux No&#235;l (2005) 
-	var $_rating;     # 1-10
-  
+	var $_url;             # http://us.imdb.com/title/tt0424205/
+	var $_url_short;       # 0424205
+	var $_title;           # Joyeux No&#235;l (2005)
+	var $_rating;          # 10
+	var $_watched_on;      # 2006-03-01 23:15
+
+	var $_link;            # database connection handle
+	var $_db;              # database handle
+	var $_char_limit = 45; # limit on number of characters in the movie's title (so it won't collapse the page)
+
 	# constructor
-	function Movie($url, $rating)
+	function Movie($url_short=null, $rating=null, $title=null, $watched_on=null)
 	{
-		$this-&gt;_url_short = $url;
+		$this-&gt;_url_short = $url_short;
 		$this-&gt;_url = 'http://imdb.com/title/tt' . $this-&gt;_url_short . '/';
 		$this-&gt;_rating = $rating;
+		$this-&gt;_title = $title;
+		$this-&gt;_watched_on = $watched_on;
+	}
+
+	# connect to the database
+	function _connect_to_database()
+	{
+		$this-&gt;_link = mysql_connect('localhost', 'root', '');
+		if (!$this-&gt;_link) return false;
+		else return true;
 	}
 
-	# get title
+	# select database
+	function _select_database()
+	{
+		$this-&gt;_db = mysql_select_db(&quot;wp_movies&quot;);
+		if (!$this-&gt;_db) return false;
+		else return true;
+	}
+
+	# get title from imdb.com
 	function get_title()
 	{
 		$req = new HTTPRequest($this-&gt;_url);
@@ -31,30 +54,60 @@ class Movie
 		else return '';
 	}
 
-	# save to database
+	# save movie rating to the database
 	function save()
 	{
-		$link = mysql_connect('localhost', 'root', '');
-		if (!$link) return '&lt;p class=&quot;error&quot;&gt;Error: could not connect to the database.&lt;/p&gt;';
+		if (!$this-&gt;_connect_to_database()) return '&lt;p class=&quot;error&quot;&gt;Error: could not connect to the database.&lt;/p&gt;';
+		if (!$this-&gt;_select_database()) return '&lt;p class=&quot;error&quot;&gt;Error: could not select the database.&lt;/p&gt;';
 
-		$db = mysql_select_db(&quot;wp_movies&quot;);
-		if (!$db) return '&lt;p class=&quot;error&quot;&gt;Error: could not select the database.&lt;/p&gt;';
-
-		$result = mysql_query(&quot;INSERT INTO movies (title, imdb_url_short, rating, created_on, updated_on) VALUES ('$this-&gt;_title', '$this-&gt;_url_short', $this-&gt;_rating, NOW(), NOW())&quot;);
+		$result = mysql_query(&quot;INSERT INTO wp_movies (title, imdb_url_short, rating, created_on, updated_on) VALUES ('$this-&gt;_title', '$this-&gt;_url_short', $this-&gt;_rating, NOW(), NOW())&quot;);
 		if (!$result) return '&lt;p class=&quot;error&quot;&gt;Error: could not add record to the database.&lt;/p&gt;';
 
-		return '&lt;p&gt;' . rawurlencode($this-&gt;_title) . ' rated ' . $this-&gt;_rating . '/10 saved.';
+		# str_replace is to drop the 'magic quotes' (they tend to be here)
+		return '&lt;p&gt;' . rawurlencode(str_replace(&quot;''&quot;, &quot;'&quot;, $this-&gt;_title)) . ' rated ' . $this-&gt;_rating . '/10 saved.';
 	}
 
-	# debug information
-	function debug()
+	# get latest movies
+	function get_latest_movies()
+	{
+		if (!$this-&gt;_connect_to_database()) return '&lt;p class=&quot;error&quot;&gt;Error: could not connect to the database.&lt;/p&gt;';
+		if (!$this-&gt;_select_database()) return '&lt;p class=&quot;error&quot;&gt;Error: could not select the database.&lt;/p&gt;';
+
+		$movies = array();
+
+		$result = mysql_query(&quot;SELECT title, imdb_url_short, rating, DATE_FORMAT(created_on, '%Y-%m-%d %H:%i') AS watched_on FROM wp_movies ORDER BY id DESC LIMIT 7&quot;);
+		if (!$result) return $movies;
+		
+		while ($row = mysql_fetch_array($result))
+		{
+			$movie = new Movie($row[&quot;imdb_url_short&quot;], $row[&quot;rating&quot;], $row[&quot;title&quot;], $row[&quot;watched_on&quot;]);
+			array_push($movies, $movie);
+		}
+		return $movies;
+	}
+	
+	# show movie
+	function show()
 	{
-		?&gt;
-		&lt;p&gt;URL: &lt;a href=&quot;&lt;?= $this-&gt;_url ?&gt;&quot;&gt;&lt;?= $this-&gt;_url ?&gt;&lt;/a&gt;&lt;/p&gt;
-		&lt;p&gt;URL_short: &lt;strong&gt;&lt;?= $this-&gt;_url_short ?&gt;&lt;/strong&gt;&lt;/p&gt;
-		&lt;p&gt;Rating: &lt;strong&gt;&lt;?= $this-&gt;_rating ?&gt;&lt;/strong&gt;&lt;/p&gt;
-		&lt;p&gt;Title: &lt;strong&gt;&lt;?= $this-&gt;_title ?&gt;&lt;/strong&gt;&lt;/p&gt;
-		&lt;?
+		# shorten the title
+		if (strlen($this-&gt;_title) &lt;= $this-&gt;_char_limit) $title_short = $this-&gt;_title;
+		else
+		{
+			# cut at limit
+			$title_short = substr($this-&gt;_title, 0, $this-&gt;_char_limit);
+			# find last space char: &quot; &quot;
+			$last_space_position = strrpos($title_short, &quot; &quot;);
+			# cut at last space
+			$title_short = substr($title_short, 0, $last_space_position) . &quot;...&quot;;
+		}
+
+		?&gt;&lt;a href=&quot;&lt;?= $this-&gt;_url ?&gt;&quot; title=&quot;&lt;?= $this-&gt;_title . &quot;\n&quot; ?&gt;Watched on &lt;?= $this-&gt;_watched_on ?&gt;&quot;&gt;&lt;?= $title_short ?&gt;&lt;/a&gt;&lt;? echo &quot;\n&quot;;
+		
+		for($i=1; $i&lt;11; $i++)
+		{
+			if ($this-&gt;_rating &gt;= $i) { ?&gt;&lt;img src=&quot;full_star.gif&quot; alt=&quot;Full star gives one rating point&quot; /&gt;&lt;? echo &quot;\n&quot;; }
+			else { ?&gt;&lt;img src=&quot;empty_star.gif&quot; alt=&quot;Empty star gives no rating points&quot; /&gt;&lt;? echo &quot;\n&quot;; }
+		}
 	}
 }
 </diff>
      <filename>movie.class.php</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>imdb.css</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>36a3481667c56afdfc86d21a9b7125ba43ee8180</id>
    </parent>
  </parents>
  <author>
    <name>Pawe&#322; Go&#347;cicki</name>
    <email>pawel.goscicki@gmail.com</email>
  </author>
  <url>http://github.com/pjg/wp_movie_ratings/commit/64ed92cc105f2e5331d33271f70b3a7d83c79e5c</url>
  <id>64ed92cc105f2e5331d33271f70b3a7d83c79e5c</id>
  <committed-date>2006-03-01T07:55:42-08:00</committed-date>
  <authored-date>2006-03-01T07:55:42-08:00</authored-date>
  <message>New page listing movies plus fixes, tweaks and reorganization.</message>
  <tree>4870fa6fbbbceeb5a45f2fdbbb88e85b0353f30d</tree>
  <committer>
    <name>Pawe&#322; Go&#347;cicki</name>
    <email>pawel.goscicki@gmail.com</email>
  </committer>
</commit>
