Skip to content
This repository
Browse code

adds prev/next detection

  • Loading branch information...
commit 6f586d38b54170f5d93245812ca0ec96f029c1a5 1 parent 31dad67
Jack McDade authored March 30, 2012

Showing 1 changed file with 29 additions and 7 deletions. Show diff stats Hide diff stats

  1. 36  index.php
36  index.php
@@ -31,12 +31,14 @@ function get_meta($date) {
31 31
 
32 32
 	$app = Slim::getInstance();
33 33
 	
34  
-	$defaults = array(
35  
-		'title' => $app->config['defaultTitle']
  34
+	$initialize = array(
  35
+		'title' => $app->config['defaultTitle'],
  36
+		'prev' => find_prev($date),
  37
+		'next' => find_next($date),
36 38
 	);
37 39
 	$meta = Spyc::YAMLLoad('content/'. $date .'/meta.yaml');
38 40
 
39  
-	return array_merge($defaults, $meta);
  41
+	return array_merge($initialize, $meta);
40 42
 }
41 43
 
42 44
 // @todo functions
@@ -60,14 +62,31 @@ function find_latest()
60 62
 	return get_dir_endpoint($latest);
61 63
 }
62 64
 
63  
-function find_next()
  65
+function find_next($date)
64 66
 {
65  
-	$app = Slim::getInstance();
  67
+	$dirs = get_directories();
  68
+	$current = array_search('content/'.$date, $dirs);
  69
+
  70
+	if ($current)
  71
+	{
  72
+		while (key($dirs) !== $current) next($dirs);
  73
+			return next($dirs);	
  74
+	}
  75
+
  76
+	return FALSE;
66 77
 }
67 78
 
68  
-function find_prev()
  79
+function find_prev($date)
69 80
 {
70  
-	$app = Slim::getInstance();
  81
+	$dirs = get_directories();
  82
+	$current = array_search('content/'.$date, $dirs);
  83
+	if ($current)
  84
+	{
  85
+		while (key($dirs) !== $current) next($dirs);
  86
+			return prev($dirs);	
  87
+	}
  88
+
  89
+	return FALSE;
71 90
 }
72 91
 
73 92
 function get_dir_endpoint($dir)
@@ -95,6 +114,9 @@ function get_dir_endpoint($dir)
95 114
 $app->get('/:date', function ($date) use ($app) {
96 115
 
97 116
 	$data = get_meta($date);
  117
+
  118
+	print_r($data);
  119
+
98 120
 	$app->render($date.'/index.php', $data);
99 121
 
100 122
 });

0 notes on commit 6f586d3

Please sign in to comment.
Something went wrong with that request. Please try again.