need to generate the json
authorToby Elliott <telliott@mozilla.com>
Thu, 09 Jul 2009 10:03:34 -0700
changeset 1070 af79cdf45832efebf878f3d127aaecf4eba0a954
parent 1069 38df053783fbb63c8c133b3a01211bbfcf9347f6
child 1071 a711bf967a09d34bbeb55bd28716b874f0107584
push id687
push usertelliott@mozilla.com
push dateThu, 09 Jul 2009 17:03:38 +0000
need to generate the json
compile.php
--- a/compile.php
+++ b/compile.php
@@ -36,185 +36,59 @@
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 	
 	require_once 'server/lib/personas_constants.php';	
 	require_once 'server/lib/personas_functions.php';	
 	require_once 'server/lib/storage.php';
 
-	$page_size = 501;
 	
 	$db = new PersonaStorage();
 	$categories = $db->get_categories();
 
 	
-	function get_directory_html($path, $file)
-	{
-		if (!is_dir(PERSONAS_STORAGE_PREFIX . "/gallery/$path"))
-		{
-			mkdir(PERSONAS_STORAGE_PREFIX . "/gallery/$path");
-		}
-
-		$ch = curl_init();
-		$fp = fopen(PERSONAS_STORAGE_PREFIX . "/gallery/$path/$file", "w");	
-		curl_setopt($ch, CURLOPT_URL, PERSONAS_BUILD_SERVER . "/store/dynamic/gallery/$path/$file?no_my=1");
-		curl_setopt($ch, CURLOPT_FILE, $fp);
-		curl_exec($ch);
-		fclose($fp);	
-	}
-
-	function make_directory_path($file)
-	{
-		$file = substr($file, 1); #remove leading slash
-		$components = explode("/", $file);
-		array_pop($components); #remove filename
-		$path = "";
-		foreach ($components as $dir)
-		{
-			$path .= "/" . $dir;
-			if (!is_dir($path))
-				mkdir($path);
-		}
-	}
-	
-	function store_page($url, $filename)
-	{
-		make_directory_path($filename);
-		$fp = fopen($filename, "w");
-
-		$ch = curl_init();
-		curl_setopt($ch, CURLOPT_URL, $url);
-		curl_setopt($ch, CURLOPT_FILE, $fp);
-		curl_exec($ch);
-		fclose($fp);		
-	}
-
 	#Top level popular page
-	$popular_list = $db->get_popular_personas(null, 21);
+	$popular_list = array_slice($db->get_popular_personas(null), 21);
 	foreach ($popular_list as $item)
 	{
 		$data = extract_record_data($item);
 		$data['recent'] = (time() - strtotime($item['approve']) < 604800) ? true : false;
 		$popular_json[] = $data;
 	}
 	$master['popular'] = $popular_json;
 
 	#Top level recent page
-	$recent_list = $db->get_recent_personas(null, 21);
+	$recent_list = array_slice($db->get_recent_personas(null), 21);
 	foreach ($recent_list as $item)
 	{
 		$data = extract_record_data($item);
 		$data['recent'] = (time() - strtotime($item['approve']) < 604800) ? true : false;
 		$recent_json[] = $data;
 	}
 	$master['recent'] = $recent_json;
 
 
 	foreach ($categories as $category)
 	{
 		#get category counts for pagination
 		$category_total = $db->get_active_persona_count($category);
 		$pages = floor($category_total/$page_size) + 1;
 		
-		$popular_list = $db->get_popular_personas($category, 10);
+		$popular_list = array_slice($db->get_popular_personas($category), 10);
 	
-		$count = 0;
 		$short_cat_list = array();
 		foreach ($popular_list as $item)
 		{
 			$data = extract_record_data($item);
 			$data['recent'] = (time() - strtotime($item['approve']) < 604800) ? true : false;
 			$short_cat_list[] = $data;
 		}
 		$category_array[] = array('name' => $category, 'personas' => $short_cat_list);
 
-		if (PERSONAS_BUILD_SERVER)
-		{
-			#get the html
-			#the popular page
-			store_page(PERSONAS_BUILD_SERVER . "/gallery/$category/Popular?no_my", PERSONAS_STORAGE_PREFIX . "/gallery/$category/Popular");
-		
-			#the recent page
-			store_page(PERSONAS_BUILD_SERVER . "/gallery/$category/Recent?no_my", PERSONAS_STORAGE_PREFIX . "/gallery/$category/Recent");
-
-			$i = 1;
-			while ($i <= $pages)
-			{
-				store_page(PERSONAS_BUILD_SERVER . "/gallery/$category/All/$i?no_my", PERSONAS_STORAGE_PREFIX . "/gallery/$category/All/$i");
-				$i++;
-			}		
-		}
 	}
 	$master['categories'] = $category_array;
 
 	file_put_contents(PERSONAS_STORAGE_PREFIX . '/index_1.json', json_encode($master));
 
-	#we're done unless you need a static tree
-	if (!PERSONAS_BUILD_SERVER)
-		exit;
-	
-	
-	
-	
-	#now write out the individual pages
-	$master_list = $db->get_active_persona_ids();
-	foreach ($master_list as $id)
-	{
-		$path = get_persona_path(PERSONAS_STORAGE_PREFIX . "/gallery/persona", $id);
-		store_page(PERSONAS_BUILD_SERVER . "/persona/$id?no_my=1", $path . "/" . ($id < 10 ? '0' : '') .  $id);
-	}
-		
-	#and the index
-	store_page(PERSONAS_BUILD_SERVER . "/index.html?no_my=1", PERSONAS_STORAGE_PREFIX . "/index.html");
-
-	#the all page
-	$category_total = $db->get_active_persona_count();
-	$pages = floor($category_total/$page_size) + 1;
-	$i = 1;
-	while ($i <= $pages)
-	{
-		store_page(PERSONAS_BUILD_SERVER . "/gallery/All/All/$i?no_my=1", PERSONAS_STORAGE_PREFIX . "/gallery/All/All/$i");
-		$i++;
-	}		
-
-	#the popular page
-	store_page(PERSONAS_BUILD_SERVER . "/gallery/All/Popular?no_my=1", PERSONAS_STORAGE_PREFIX . "/gallery/All/Popular");
-
-	#the recent page
-	store_page(PERSONAS_BUILD_SERVER . "/gallery/All/Recent?no_my=1", PERSONAS_STORAGE_PREFIX . "/gallery/All/Recent");
-
-	#update page
-	store_page(PERSONAS_BUILD_SERVER . "/updated?no_my=1", PERSONAS_STORAGE_PREFIX . "/updated.html");
-
-	#firstrun page
-	store_page(PERSONAS_BUILD_SERVER . "/firstrun?no_my=1", PERSONAS_STORAGE_PREFIX . "/firstrun.html");
-
-	#recent page hack to provide a backwards compatible recent.html
-	store_page(PERSONAS_BUILD_SERVER . "/gallery/All/Recent?no_my=1", PERSONAS_STORAGE_PREFIX . "/recent.html");
-
-	#faq
-	store_page(PERSONAS_BUILD_SERVER . "/faq?no_my=1", PERSONAS_STORAGE_PREFIX . "/faq.html");
-
-	#demo_install
-	store_page(PERSONAS_BUILD_SERVER . "/demo_install?no_my=1", PERSONAS_STORAGE_PREFIX . "/demo_install.html");
-
-	#demo_create
-	store_page(PERSONAS_BUILD_SERVER . "/demo_create?no_my=1", PERSONAS_STORAGE_PREFIX . "/demo_create.html");
-	store_page(PERSONAS_BUILD_SERVER . "/demo_create_2?no_my=1", PERSONAS_STORAGE_PREFIX . "/demo_create_2.html");
-	store_page(PERSONAS_BUILD_SERVER . "/demo_create_3?no_my=1", PERSONAS_STORAGE_PREFIX . "/demo_create_3.html");
-	store_page(PERSONAS_BUILD_SERVER . "/demo_create_4?no_my=1", PERSONAS_STORAGE_PREFIX . "/demo_create_4.html");
-
-	#privacy
-	store_page(PERSONAS_BUILD_SERVER . "/privacy?no_my=1", PERSONAS_STORAGE_PREFIX . "/privacy.html");
-	
-	#designer pages
-	
-	$designer_list = $db->get_active_designers();
-	foreach ($designer_list as $designer)
-	{
-		store_page(PERSONAS_BUILD_SERVER . "/gallery/Designer/" . $designer . "?no_my=1", PERSONAS_STORAGE_PREFIX . "/gallery/Designer/" . $designer);		
-	}
-	
-	
 	
 	
 ?>
\ No newline at end of file