added 'home' extension from bzchan
git-svn-id: file:///home/shish/svn/shimmie2/trunk@165 7f39781d-f577-437e-ae19-be835c7a54ca
| @ -38,6 +38,17 @@ class AdminUtils extends Extension { | |||||||
| 		global $database; | 		global $database; | ||||||
| 		$database->execute("UPDATE tags SET tag=lower(tag)"); | 		$database->execute("UPDATE tags SET tag=lower(tag)"); | ||||||
| 	} | 	} | ||||||
|  | 	private function check_for_orphanned_images() { | ||||||
|  | 		$orphans = array(); | ||||||
|  | 		foreach(glob("images/*") as $dir) { | ||||||
|  | 			foreach(glob("$dir/*") as $file) { | ||||||
|  | 				$hash = str_replace("$dir/", "", $file); | ||||||
|  | 				if(!$this->db_has_hash($hash)) { | ||||||
|  | 					$orphans[] = $hash; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| // }}}
 | // }}}
 | ||||||
| // admin page HTML {{{
 | // admin page HTML {{{
 | ||||||
| 	private function build_form() { | 	private function build_form() { | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								contrib/home/counter_link.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1 @@ | |||||||
|  | maybe the counter source http://kokagex.hp.infoseek.co.jp/ | ||||||
							
								
								
									
										
											BIN
										
									
								
								contrib/home/counters/default/0.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.8 KiB | 
							
								
								
									
										
											BIN
										
									
								
								contrib/home/counters/default/1.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.7 KiB | 
							
								
								
									
										
											BIN
										
									
								
								contrib/home/counters/default/2.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.8 KiB | 
							
								
								
									
										
											BIN
										
									
								
								contrib/home/counters/default/3.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.8 KiB | 
							
								
								
									
										
											BIN
										
									
								
								contrib/home/counters/default/4.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.7 KiB | 
							
								
								
									
										
											BIN
										
									
								
								contrib/home/counters/default/5.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 2.2 KiB | 
							
								
								
									
										
											BIN
										
									
								
								contrib/home/counters/default/6.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 2.1 KiB | 
							
								
								
									
										
											BIN
										
									
								
								contrib/home/counters/default/7.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 2.0 KiB | 
							
								
								
									
										
											BIN
										
									
								
								contrib/home/counters/default/8.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.9 KiB | 
							
								
								
									
										
											BIN
										
									
								
								contrib/home/counters/default/9.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 1.9 KiB | 
							
								
								
									
										134
									
								
								contrib/home/main.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,134 @@ | |||||||
|  | <?php | ||||||
|  | /** | ||||||
|  | * Name: Home Extension | ||||||
|  | * Author: Bzchan <bzchan@animemahou.com> | ||||||
|  | * Link: http://trac.shishnet.org/shimmie2/ | ||||||
|  | * License: GPLv2 | ||||||
|  | * Description: Extension adds a page "home" containing user specified | ||||||
|  | *              links and a counter showing total number of posts. The | ||||||
|  | *              page is accessed via /home. | ||||||
|  | */ | ||||||
|  | 
 | ||||||
|  | class Home extends Extension { | ||||||
|  | 
 | ||||||
|  | 	public function receive_event($event) { | ||||||
|  | 		global $page; | ||||||
|  | 		if(is_a($event, 'PageRequestEvent') && ($event->page == "home")) | ||||||
|  | 		{ | ||||||
|  | 			// this is a request to display this page so output the page.
 | ||||||
|  | 		  	$this->output_pages(); | ||||||
|  | 		} | ||||||
|  | 		if(is_a($event, 'SetupBuildingEvent')) | ||||||
|  | 		{ | ||||||
|  | 			$counters = array(); | ||||||
|  | 			foreach(glob("ext/home/counters/*") as $counter_dirname) { | ||||||
|  | 				$name = str_replace("ext/home/counters/", "", $counter_dirname); | ||||||
|  | 				$counters[ucfirst($name)] = $name; | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
|  | 			$sb = new SetupBlock("Home Page"); | ||||||
|  | 			$sb->add_label("Page Links - Example: [$"."base/index|Posts]"); | ||||||
|  | 			$sb->add_longtext_option("home_links", "<br>"); | ||||||
|  | 			$sb->add_choice_option("home_counter", $counters, "<br>Counter: "); | ||||||
|  | 			$sb->add_label("<br>Note: page accessed via /home"); | ||||||
|  | 			$event->panel->add_main_block($sb); | ||||||
|  | 		} | ||||||
|  | 		if(is_a($event, 'ConfigSaveEvent')) | ||||||
|  | 		{ | ||||||
|  | 			$event->config->set_string_from_post("home_links"); | ||||||
|  | 			$event->config->set_string_from_post("home_counter"); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	private function get_body() | ||||||
|  | 	{ | ||||||
|  | 		// returns just the contents of the body
 | ||||||
|  | 		global $database; | ||||||
|  | 		global $config; | ||||||
|  | 		$base_href = $config->get_string('base_href'); | ||||||
|  | 		$data_href = $config->get_string('data_href'); | ||||||
|  | 		$sitename = $config->get_string('title'); | ||||||
|  | 	    $contact_link = $config->get_string('contact_link'); | ||||||
|  | 		$counter_dir = $config->get_string('home_counter');		 | ||||||
|  | 		 | ||||||
|  | 		$total = ceil($database->db->GetOne("SELECT COUNT(*) FROM images")); | ||||||
|  | 	   	    | ||||||
|  | 		$numbers = array(); | ||||||
|  | 		$numbers = str_split($total); | ||||||
|  | 		$num_comma = number_format($total); | ||||||
|  | 	    | ||||||
|  | 		$counter_text = ""; | ||||||
|  | 		foreach ($numbers as $cur) | ||||||
|  | 		{ | ||||||
|  | 			$counter_text .= " <img alt='$cur' src='$data_href/ext/home/counters/$counter_dir/$cur.gif' />  "; | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 		// get the homelinks and process them
 | ||||||
|  | 		$main_links = $config->get_string('home_links'); | ||||||
|  | 		$main_links = str_replace('$base',	$base_href, 	$main_links); | ||||||
|  | 		$main_links = str_replace('[', 		"<a href='", 	$main_links); | ||||||
|  | 		$main_links = str_replace('|', 		"'>", 			$main_links); | ||||||
|  | 		$main_links = str_replace(']', 		"</a>", 		$main_links); | ||||||
|  | 				 | ||||||
|  | 		return " | ||||||
|  | 		<div id='front-page'> | ||||||
|  | 			<h1> | ||||||
|  | 				<a style='text-decoration: none;' href='".make_link("index")."'><span>$sitename</span></a> | ||||||
|  | 			</h1> | ||||||
|  | 			<div class='space' id='links'> | ||||||
|  | 				$main_links | ||||||
|  | 			</div> | ||||||
|  | 			<div class='space'> | ||||||
|  | 				<form action='".make_link("index")."' method='GET'> | ||||||
|  | 				<input id='search_input' name='search' size='55' type='text' value='' autocomplete='off' /><br/> | ||||||
|  | 				<input type='submit' value='Search'/> | ||||||
|  | 				</form> | ||||||
|  | 			</div> | ||||||
|  |       		<div style='font-size: 80%; margin-bottom: 2em;'> | ||||||
|  | 		 		<a href='$contact_link'>contact</a> – Serving $num_comma posts | ||||||
|  | 			</div> | ||||||
|  | 		 | ||||||
|  | 			<div class='space'> | ||||||
|  | 				Powered by <a href='http://trac.shishnet.org/shimmie2/'>Shimmie</a> | ||||||
|  | 			</div> | ||||||
|  | 			<div class='space'> | ||||||
|  | 				$counter_text | ||||||
|  | 			</div> | ||||||
|  | 		</div>";
 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  |     private function output_pages() | ||||||
|  | 	{ | ||||||
|  | 		// output a sectionalised list of all the main pages on the site.
 | ||||||
|  | 		global $config; | ||||||
|  | 		$base_href = $config->get_string('base_href'); | ||||||
|  | 		$data_href = $config->get_string('data_href'); | ||||||
|  | 		$sitename = $config->get_string('title'); | ||||||
|  | 		$theme_name = $config->get_string('theme'); | ||||||
|  | 		 | ||||||
|  | 		$body = $this->get_body();	    | ||||||
|  | 	   | ||||||
|  | 	  	print <<<EOD | ||||||
|  | <html> | ||||||
|  | 	<head> | ||||||
|  | 		<title>$sitename</title> | ||||||
|  | 		<link rel='stylesheet' href='$data_href/themes/$theme_name/style.css' type='text/css'> | ||||||
|  | 	</head> | ||||||
|  | 	<style> | ||||||
|  | 		div#front-page h1 {font-size: 4em; margin-top: 2em; text-align: center; border: none; background: none;}
 | ||||||
|  | 		div#front-page {text-align:center;}
 | ||||||
|  | 		.space {margin-bottom: 1em;} | ||||||
|  | 		div#front-page div#links a {margin: 0 0.5em;}
 | ||||||
|  | 		div#front-page li {list-style-type: none; margin: 0;}
 | ||||||
|  | 	</style> | ||||||
|  | 	<body> | ||||||
|  | 		$body		 | ||||||
|  | 	</body> | ||||||
|  | </html> | ||||||
|  | EOD; | ||||||
|  | 		exit; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | add_event_listener(new Home()); | ||||||
|  | ?>
 | ||||||