Merge pull request #104 from DakuTree/master

Update ext & fixes
This commit is contained in:
Shish Moom 2012-01-31 07:05:16 -08:00
commit 61483aced2
16 changed files with 283 additions and 46 deletions

1
.gitignore vendored
View File

@ -63,6 +63,7 @@ ext/text_score
ext/tips
ext/twitter_soc
ext/upload_cmd
ext/update
ext/wiki
ext/word_filter
ext/zoom

View File

@ -6,7 +6,7 @@ class DowntimeTheme extends Themelet {
*/
public function display_notification(Page $page) {
$page->add_block(new Block("Downtime",
"<span style='font-size: 1.5em'><b>DOWNTIME MODE IS ON!</b></span>", "left", 0));
"<span style='font-size: 1.5em'><b><center>DOWNTIME MODE IS ON!</center></b></span>", "left", 0));
}
/**
@ -28,7 +28,7 @@ class DowntimeTheme extends Themelet {
</head>
<body>
<div id="downtime">
<h1>Down for Maintenance</h1>
<h1><center>Down for Maintenance</center></h1>
<div id="message">
$message
</div>

View File

@ -5,7 +5,7 @@ class FeaturedTheme extends Themelet {
* Show $text on the $page
*/
public function display_featured(Page $page, Image $image) {
$page->add_block(new Block("Featured Image", $this->build_thumb_html($image), "left", 3));
$page->add_block(new Block("Featured Image", $this->build_featured_html($image), "left", 3));
}
public function get_buttons_html($image_id) {
@ -18,5 +18,25 @@ class FeaturedTheme extends Themelet {
</form>
";
}
public function build_featured_html(Image $image, $query=null) {
global $config;
$i_id = int_escape($image->id);
$h_view_link = make_link("post/view/$i_id", $query);
$h_thumb_link = $image->get_thumb_link();
$h_tip = html_escape($image->get_tooltip());
$tsize = get_thumbnail_size($image->width, $image->height);
return "
<center><div>
<a href='$h_view_link' style='position: relative; height: {$tsize[1]}px; width: {$tsize[0]}px;'>
<img id='thumb_$i_id' title='$h_tip' alt='$h_tip' class='highlighted' style='height: {$tsize[1]}px; width: {$tsize[0]}px;' src='$h_thumb_link'>
</a>
</div></center>
";
}
}
?>

View File

@ -4,13 +4,14 @@ class MP3FileHandlerTheme extends Themelet {
public function display_image(Page $page, Image $image) {
$data_href = get_base_href();
$ilink = $image->get_image_link();
$fname = url_escape($image->filename); //Most of the time this will be the title/artist of the song.
$html = "
<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'
codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'
width='400' height='15'>
<param name='movie' value='$data_href/ext/handle_mp3/xspf_player_slim.swf?song_url=$ilink'/>
<param name='quality' value='high' />
<embed src='$data_href/ext/handle_mp3/xspf_player_slim.swf?song_url=$ilink' quality='high'
<embed src='$data_href/ext/handle_mp3/xspf_player_slim.swf?song_url=$ilink&song_title=$fname' quality='high'
pluginspage='http://www.macromedia.com/go/getflashplayer'
width='400' height='15'
type='application/x-shockwave-flash'></embed>

View File

@ -21,8 +21,7 @@ class Home extends SimpleExtension {
$config->set_default_string("home_links", '[$base/post/list|Posts]
[$base/comment/list|Comments]
[$base/tags|Tags]
[$base/wiki|Wiki]
[$base/wiki/more|&raquo;]');
[$base/ext_doc|&raquo;]');
}
public function onPageRequest(PageRequestEvent $event) {
@ -46,7 +45,8 @@ class Home extends SimpleExtension {
}
$sb = new SetupBlock("Home Page");
$sb->add_longtext_option("home_links", 'Page Links - Example: [/post/list|Posts]<br>');
$sb->add_bool_option("home_choice", "Use custom page links: ");
$sb->add_longtext_option("home_links", '<br>Page Links - Example: [/post/list|Posts]<br>');
$sb->add_longtext_option("home_text", "<br>Page Text:<br>");
$sb->add_choice_option("home_counter", $counters, "<br>Counter: ");
$event->panel->add_block($sb);
@ -74,7 +74,14 @@ class Home extends SimpleExtension {
}
// get the homelinks and process them
$main_links = $config->get_string('home_links');
if($config->get_bool('home_choice')){
$main_links = $config->get_string('home_links');
}else{
$main_links = '[$base/post/list|Posts] [$base/comment/list|Comments] [$base/tags|Tags]';
if(file_exists("ext/pools")){$main_links .= ' [$base/pools|Pools]';}
if(file_exists("ext/wiki")){$main_links .= ' [$base/wiki|Wiki]';}
$main_links .= ' [$base/ext_doc|&raquo;]';
}
$main_links = str_replace('$base', $base_href, $main_links);
$main_links = preg_replace('#\[(.*?)\|(.*?)\]#', "<a href='\\1'>\\2</a>", $main_links);
$main_links = str_replace('//', "/", $main_links);

View File

@ -29,6 +29,7 @@ EOD
$main_links_html = empty($main_links) ? "" : "<div class='space' id='links'>$main_links</div>";
$message_html = empty($main_text) ? "" : "<div class='space' id='message'>$main_text</div>";
$counter_html = empty($counter_text) ? "" : "<div class='space' id='counter'>$counter_text</div>";
$contact_link = empty($contact_link) ? "" : "<br><a href='mailto:$contact_link'>Contact</a> &ndash;";
$search_html = "
<div class='space' id='search'>
<form action='".make_link("post/list")."' method='GET'>
@ -47,7 +48,7 @@ EOD
$counter_html
<div class='space' id='foot'>
<small><small>
<a href='mailto:$contact_link'>Contact</a> &ndash; Serving $num_comma posts &ndash;
$contact_link Serving $num_comma posts &ndash;
Running <a href='http://code.shishnet.org/shimmie2/'>Shimmie</a>
</small></small>
</div>

View File

@ -161,6 +161,7 @@ class ImageBan extends SimpleExtension {
$database->Execute(
"INSERT INTO image_bans (hash, reason, date) VALUES (?, ?, now())",
array($hash, $reason));
log_info("image_hash_ban", "Banned hash: ($hash) because '$reason'");
}
public function remove_image_hash_ban($hash) {

View File

@ -262,6 +262,7 @@ class IPBan extends SimpleExtension {
$sql = "INSERT INTO bans (ip, reason, end_timestamp, banner_id) VALUES (:ip, :reason, :end, :admin_id)";
$database->Execute($sql, array("ip"=>$ip, "reason"=>$reason, "end"=>strtotime($end), "admin_id"=>$user->id));
$database->cache->delete("ip_bans");
log_info("ipban", "'$user->name' has banned '$ip' because '$reason' until '$end'");
}
// }}}
}

View File

@ -109,66 +109,67 @@ class NumericScore implements Extension {
if($event->page_matches("popular_by_day") || $event->page_matches("popular_by_month") || $event->page_matches("popular_by_year")) {
$t_images = $config->get_int("index_height") * $config->get_int("index_width");
//TODO: Somehow make popular_by_#/2012/12/31 > popular_by_#?day=31&month=12&year=2012 (So no problems with date formats)
//TODO: Add Popular_by_week.
$sql = "SELECT * FROM images ";
$args = array();
//year
if(int_escape($event->get_arg(0)) == 0){
if(empty($_GET['year'])){
$year = date("Y");
}else{
$year = $event->get_arg(0);
$year = $_GET['year'];
}
//month
if(int_escape($event->get_arg(1)) == 0 || int_escape($event->get_arg(1)) > 12){
if(empty($_GET['month']) || int_escape($_GET['month']) > 12){
$month = date("m");
}else{
$month = $event->get_arg(1);
$month = $_GET['month'];
}
//day
if(int_escape($event->get_arg(2)) == 0 || int_escape($event->get_arg(2)) > 31){
if(empty($_GET['day']) || int_escape($_GET['day']) > 31){
$day = date("d");
}else{
$day = $event->get_arg(2);
$day = $_GET['day'];
}
$totaldate = $year."/".$month."/".$day;
$sql =
"SELECT * FROM images
WHERE EXTRACT(YEAR FROM posted) = :year
";
$agrs = array("limit" => $t_images, "year" => $year);
if($event->page_matches("popular_by_day")){
$sql .=
"WHERE EXTRACT(YEAR FROM posted) = :year
AND EXTRACT(MONTH FROM posted) = :month
"AND EXTRACT(MONTH FROM posted) = :month
AND EXTRACT(DAY FROM posted) = :day
AND NOT numeric_score=0
";
$dte = array($totaldate, date("F jS, Y", (strtotime($totaldate))), "Y/m/d", "day");
//array_push doesn't seem to like using double arrows
//this requires us to instead create two arrays and merge
$sgra = array("month" => $month, "day" => $day);
$args = array_merge($agrs, $sgra);
$dte = array($totaldate, date("F jS, Y", (strtotime($totaldate))), "\\y\\e\\a\\r\\=Y\\&\\m\\o\\n\\t\\h\\=m\\&\\d\\a\\y\\=d", "day");
}
if($event->page_matches("popular_by_month")){
$sql .=
"WHERE EXTRACT(YEAR FROM posted) = :year
AND EXTRACT(MONTH FROM posted) = :month
"AND EXTRACT(MONTH FROM posted) = :month
AND NOT numeric_score=0
";
$sgra = array("month" => $month);
$args = array_merge($agrs, $sgra);
$title = date("F Y", (strtotime($totaldate)));
$dte = array($totaldate, $title, "Y/m", "month");
$dte = array($totaldate, $title, "\\y\\e\\a\\r\\=Y\\&\\m\\o\\n\\t\\h\\=m", "month");
}
if($event->page_matches("popular_by_year")){
$sql .=
"WHERE EXTRACT(YEAR FROM posted) = :year
AND NOT numeric_score=0
";
$dte = array($totaldate, $year, "Y", "year");
$sql .= "AND NOT numeric_score=0";
$dte = array($totaldate, $year, "\y\e\a\\r\=Y", "year");
$args = $agrs;
}
$sql .= " ORDER BY numeric_score DESC LIMIT :limit OFFSET 0";
//filter images by year/score != 0 > limit to max images on one page > order from highest to lowest score
$args = array(
"year" => $year,
"month" => $month,
"day" => $day,
"limit" => $t_images
);
$result = $database->get_all($sql, $args);
$images = array();

View File

@ -67,8 +67,8 @@ class NumericScoreTheme extends Themelet {
'</span>';
}
$b_dte = make_link("popular_by_".$dte[3]."/".date($dte[2], (strtotime('-1 '.$dte[3], strtotime($dte[0])))));
$f_dte = make_link("popular_by_".$dte[3]."/".date($dte[2], (strtotime('+1 '.$dte[3], strtotime($dte[0])))));
$b_dte = make_link("popular_by_".$dte[3]."?".date($dte[2], (strtotime('-1 '.$dte[3], strtotime($dte[0])))));
$f_dte = make_link("popular_by_".$dte[3]."?".date($dte[2], (strtotime('+1 '.$dte[3], strtotime($dte[0])))));
$html = '<center><h3><a href="'.$b_dte.'">&laquo;</a> '.$dte[1]
.' <a href="'.$f_dte.'">&raquo;</a>'

View File

@ -2,7 +2,26 @@
class RandomImageTheme extends Themelet {
public function display_random(Page $page, Image $image) {
$page->add_block(new Block("Random Image", $this->build_thumb_html($image), "left", 8));
$page->add_block(new Block("Random Image", $this->build_random_html($image), "left", 8));
}
public function build_random_html(Image $image, $query=null) {
global $config;
$i_id = int_escape($image->id);
$h_view_link = make_link("post/view/$i_id", $query);
$h_thumb_link = $image->get_thumb_link();
$h_tip = html_escape($image->get_tooltip());
$tsize = get_thumbnail_size($image->width, $image->height);
return "
<center><div>
<a href='$h_view_link' style='position: relative; height: {$tsize[1]}px; width: {$tsize[0]}px;'>
<img id='thumb_$i_id' title='$h_tip' alt='$h_tip' class='highlighted' style='height: {$tsize[1]}px; width: {$tsize[0]}px;' src='$h_thumb_link'>
</a>
</div></center>
";
}
}
?>

178
contrib/update/main.php Normal file
View File

@ -0,0 +1,178 @@
<?php
/**
* Name: Update
* Author: DakuTree <dakutree@codeanimu.net>
* Link: http://www.codeanimu.net
* License: GPLv2
* Description: Shimmie updater!
*/
class Update extends SimpleExtension {
public function onInitExt(Event $event) {
global $config;
$config->set_default_string("update_url", "http://nodeload.github.com/shish/shimmie2/zipball/master"); //best to avoid using https
$config->set_default_string("commit_hash", "");
}
public function onSetupBuilding($event) {
global $config;
//Would prefer to use the admin panel for this.
//But since the admin panel is optional...kind of stuck to using this.
$sb = new SetupBlock("Update");
$sb->position = 75;
$sb->add_label("Current Commit: ".$config->get_string('commit_hash'));
$sb->add_text_option("update_url", "<br>Update URL: ");
$sb->add_label("<br><a href='".make_link('update')."'>Update</a>");
$event->panel->add_block($sb);
}
public function onPageRequest(Event $event) {
global $config, $user;
if($event->page_matches("update") && $user->is_admin()) {
$ok = $this->update_shimmie();
}
}
private function update_shimmie() {
global $config, $page;
//This is a REALLY ugly function. (Damn my limited PHP knowledge >_<)
$html = "";
$url = $config->get_string("update_url");
$mfile = "master.zip";
if(glob("*-shimmie2*")){ //#3
$dir = glob("*-shimmie2*");
preg_match('@^([a-zA-Z0-9]+\-[0-9a-z]+\-)([^/]+)@i', $dir[0], $matches);
if(!empty($matches[2])){
$html .= "commit: ".$matches[2];
$commit = $matches[2];
mkdir("./backup");
$html .= "<br>backup folder created!";
$d_dir = "data/cache";
//This should empty the /data/cache/ folder.
if (is_dir($d_dir)) {
$objects = scandir($d_dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($d_dir."/".$object) == "dir") rmdir($d_dir."/".$object); else unlink($d_dir."/".$object);
}
}
reset($objects);
$html .= "<br>data folder emptied!";
}
copy ("./config.php", "./backup/config.php");//Although this stays the same, will keep backup just incase.
//FIXME: Somehow get rid of this massive rename list.
rename ("./core", "./backup/core");
rename ("./".$matches[0]."/core", "./core");
rename ("./lib", "./backup/lib");
rename ("./".$matches[0]."/lib", "./lib");
rename ("./themes", "./backup/themes");
rename ("./".$matches[0]."/themes", "./themes");
rename ("./.htaccess", "./backup/.htaccess");
rename ("./".$matches[0]."/.htaccess", "./.htaccess");
rename ("./doxygen.conf", "./backup/doxygen.conf");
rename ("./".$matches[0]."/doxygen.conf", "./doxygen.conf");
rename ("./index.php", "./backup/index.php");
rename ("./".$matches[0]."/index.php", "./index.php");
rename ("./install.php", "./backup/install.php");
rename ("./".$matches[0]."/install.php", "./install.php");
rename ("./ext", "./backup/ext");
rename ("./".$matches[0]."/ext", "./ext");
rename ("./contrib", "./backup/contrib");
rename ("./".$matches[0]."/contrib", "./contrib");
$html .= "<br>old shimmie setup has been moved to /backup/ (excluding images/thumbs)!";
if (is_dir($matches[0])) {
$objects = scandir($matches[0]);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($matches[0]."/".$object) == "dir") rmdir($matches[0]."/".$object); else unlink($matches[0]."/".$object);
}
}
reset($objects);
rmdir($matches[0]);
$html .= "<br>".$matches[0]." deleted!";
}
$html .= "<br>shimmie updated (although you may have gotten errors, it should have worked!";
$html .= "<br>due to the way shimmie loads extensions, all optional extensions have been disabled";
$config->set_string("commit_hash", $commit);
$html .= "<br>new commit_hash has been set!";
}else{
$html .= "Error! Folder does not exist!?"; //Although this should be impossible, shall have it anyway.
}
}elseif (file_exists($mfile)){ //#2
$zip = new ZipArchive;
if ($zip->open($mfile) === TRUE) {
$zip->extractTo('./');
$zip->close();
$html .= "extracted!";
$html .= "<br><a href='javascript:history.go(0)'>refresh</a> the page to continue!";
unlink($mfile); //Deletes master.zip
} else {
$html .= "failed!";
}
}else{ //#1
//Taken from the upload ext.
if($config->get_string("transload_engine") == "curl" && function_exists("curl_init")) {
$ch = curl_init($url);
$fp = fopen($mfile, "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Shimmie-".VERSION);
curl_exec($ch);
curl_close($ch);
fclose($fp);
if(file_exists($mfile)){
$html .= "downloaded!";
$html .= "<br><a href='javascript:history.go(0)'>refresh</a> the page to continue!";
}else{
$html .= "download failed!";
$html .= "<br><a href='javascript:history.go(0)'>refresh</a> to try again!";
$html .= "<br>if you keep having this problem, you may have a problem with your transload engine!";
}
}elseif($config->get_string("transload_engine") == "wget") {
//this doesn't work?
$s_url = escapeshellarg($url);
system("wget $s_url --output-document=$mfile");
if(file_exists($mfile)){
$html .= "downloaded!";
$html .= "<br><a href='javascript:history.go(0)'>refresh</a> the page to continue!";
}else{
$html .= "download failed!";
$html .= "<br><a href='javascript:history.go(0)'>refresh</a> to try again!";
$html .= "<br>if you keep having this problem, you may have a problem with your transload engine!";
}
}elseif($config->get_string("transload_engine") == "fopen") {
$fp = @fopen($url, "r");
if(!$fp) {
return false;
}
$data = "";
$length = 0;
while(!feof($fp) && $length <= $config->get_int('upload_size')) {
$data .= fread($fp, 8192);
$length = strlen($data);
}
fclose($fp);
$fp = fopen($mfile, "w");
fwrite($fp, $data);
fclose($fp);
if(file_exists($mfile)){
$html .= "downloaded!";
$html .= "<br><a href='javascript:history.go(0)'>refresh</a> the page to continue!";
}else{
$html .= "download failed!";
$html .= "<br><a href='javascript:history.go(0)'>refresh</a> to try again!";
$html .= "<br>if you keep having this problem, you may have a problem with your transload engine!";
}
}elseif($config->get_string("transload_engine") == "none"){
$html .= "no transload engine set!";
}
}
$page->add_block(new Block("Update", $html));
}
}
?>

View File

@ -251,11 +251,11 @@ class Image {
*/
public function get_image_link() {
global $config;
$image_ilink = $config->get_string('image_ilink'); // store a copy for speed.
if( !empty($image_ilink) ) { /* empty is faster than strlen */
return $this->parse_link_template($image_ilink);
return $this->parse_link_template(make_link($image_ilink));
}
else if($config->get_bool('nice_urls', false)) {
return $this->parse_link_template(make_link('_images/$hash/$id - $tags.$ext'));

View File

@ -845,6 +845,12 @@ function get_debug_info() {
else {
$i_mem = "???";
}
if($config->get_string("commit_hash") == ""){
$commit = "";
}else{
$commit = " (".$config->get_string("commit_hash").")";
}
$time = sprintf("%5.2f", microtime(true) - $_load_start);
$i_files = count(get_included_files());
$hits = $database->cache->get_hits();
@ -854,7 +860,7 @@ function get_debug_info() {
$debug .= "; Used $i_files files and $_execs queries";
$debug .= "; Sent $_event_count events";
$debug .= "; $hits cache hits and $miss misses";
$debug .= "; Shimmie version ". VERSION; // .", SCore Version ". SCORE_VERSION;
$debug .= "; Shimmie version ". VERSION . $commit; // .", SCore Version ". SCORE_VERSION;
return $debug;
}

View File

@ -142,7 +142,8 @@ class Layout {
case "upload":
if(file_exists("ext/numeric_score")){ $custom_sublinks .= "<li><b>Popular by </b><a href='".make_link('popular_by_day')."'>Day</a>/<a href='".make_link('popular_by_month')."'>Month</a>/<a href='".make_link('popular_by_year')."'>Year</a></li>";}
$custom_sublinks .= "<li><a href='".make_link('post/list')."'>All</a></li>";
$custom_sublinks .= "<li><a href='".make_link("post/list/favorited_by=$username/1")."'>My Favorites</a></li>";
if(file_exists("ext/favorites")){ $custom_sublinks .= "<li><a href='".make_link("post/list/favorited_by=$username/1")."'>My Favorites</a></li>";}
if(file_exists("ext/rss_images")){ $custom_sublinks .= "<li><a href='".make_link('rss/images')."'>Feed</a></li>";}
if(file_exists("ext/random_image")){ $custom_sublinks .= "<li><a href='".make_link("random_image/view")."'>Random Image</a></li>";}
if($hw){ $custom_sublinks .= "<li><a href='".make_link("wiki/posts")."'>Help</a></li>";
}else{ $custom_sublinks .= "<li><a href='".make_link("ext_doc/index")."'>Help</a></li>";}

View File

@ -96,8 +96,8 @@ class Layout {
case "post":
if(file_exists("ext/numeric_score")){ $cs .= "<b>Popular by </b><a href='".make_link('popular_by_day')."'>Day</a><b>/</b><a href='".make_link('popular_by_month')."'>Month</a><b>/</b><a href='".make_link('popular_by_year')."'>Year</a> ";}
$cs .= "<a class='tab' href='".make_link('post/list')."'>All</a>";
$cs .= "<a class='tab' href='".make_link("post/list/favorited_by=$username/1")."'>My Favorites</a>";
$cs .= "<a class='tab' href='".make_link('rss/images')."'>Feed</a>";
if(file_exists("ext/favorites")){ $cs .= "<a class='tab' href='".make_link("post/list/favorited_by=$username/1")."'>My Favorites</a>";}
if(file_exists("ext/rss_images")){ $cs .= "<a class='tab' href='".make_link('rss/images')."'>Feed</a>";}
if(file_exists("ext/random_image")){ $cs .= "<a class='tab' href='".make_link("random_image/view")."'>Random Image</a>";}
if($hw){ $cs .= "<a class='tab' href='".make_link("wiki/posts")."'>Help</a>";
}else{ $cs .= "<a class='tab' href='".make_link("ext_doc/index")."'>Help</a>";}