Merge branch 'master' of github.com:shish/shimmie2

This commit is contained in:
Shish 2012-02-16 15:20:36 +00:00
commit 5fc7d6e574
5 changed files with 82 additions and 45 deletions

View File

@ -61,9 +61,8 @@ class ResizeImage extends Extension {
public function onDataUpload(DataUploadEvent $event) { public function onDataUpload(DataUploadEvent $event) {
global $config; global $config;
$image_obj = Image::by_id($event->image_id); $image_obj = Image::by_id($event->image_id);
//No auto resizing for gifs due to animated gif causing errors :(
//Also PNG resizing seems to be completely broken. if($config->get_bool("resize_upload") == true && ($image_obj->ext == "jpg" || $image_obj->ext == "png" || $image_obj->ext == "gif")){
if($config->get_bool("resize_upload") == true && ($image_obj->ext == "jpg")){
$width = $height = 0; $width = $height = 0;
if ($config->get_int("resize_default_width") !== 0) { if ($config->get_int("resize_default_width") !== 0) {
@ -72,7 +71,18 @@ class ResizeImage extends Extension {
if ($config->get_int("resize_default_height") !== 0) { if ($config->get_int("resize_default_height") !== 0) {
$height = $config->get_int("resize_default_height"); $height = $config->get_int("resize_default_height");
} }
$isanigif = 0;
if($image_obj->ext == "gif"){
$image_filename = warehouse_path("images", $image_obj->hash);
if(!($fh = @fopen($image_filename, 'rb'))){ //check if gif is animated (via http://www.php.net/manual/en/function.imagecreatefromgif.php#104473)
return false;
}
while(!feof($fh) && $isanigif < 2) {
$chunk = fread($fh, 1024 * 100);
$isanigif += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches);
}
}
if($isanigif == 0){
try { try {
$this->resize_image($event->image_id, $width, $height); $this->resize_image($event->image_id, $width, $height);
} catch (ImageResizeException $e) { } catch (ImageResizeException $e) {
@ -88,6 +98,7 @@ class ResizeImage extends Extension {
//TODO: Notify user that image has been resized. //TODO: Notify user that image has been resized.
} }
} }
}
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $page, $user; global $page, $user;
@ -209,8 +220,7 @@ class ResizeImage extends Extension {
switch ( $info[2] ) { switch ( $info[2] ) {
case IMAGETYPE_GIF: $image = imagecreatefromgif($image_filename); break; case IMAGETYPE_GIF: $image = imagecreatefromgif($image_filename); break;
case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($image_filename); break; case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($image_filename); break;
/* FIXME: PNG support seems to be broken. case IMAGETYPE_PNG: $image = imagecreatefrompng($image_filename); break;
case IMAGETYPE_PNG: $image = imagecreatefrompng($image_filename); break;*/
default: default:
throw new ImageResizeException("Unsupported image type."); throw new ImageResizeException("Unsupported image type.");
} }

View File

@ -9,18 +9,39 @@
class Update extends Extension { class Update extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $config; 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("update_guser", "shish");
$config->set_default_string("commit_hash", ""); $config->set_default_string("update_grepo", "shimmie2");
$config->set_default_string("commit_hash", "unknown");
$config->set_default_string("commit_time", "unknown");
} }
public function onSetupBuilding(SetupBuildingEvent $event) { public function onSetupBuilding(SetupBuildingEvent $event) {
global $config; global $config;
//Grab latest info via JSON.
$base = "https://api.github.com/repos/shish/shimmie2/commits";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $base);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$content = curl_exec($curl);
curl_close($curl);
$commits = json_decode($content, true);
$latestCommit = $commits[0];
$commitMessage = $latestCommit["commit"]["message"];
$commitDT = explode("T", $latestCommit["commit"]["committer"]["date"]);
$commitTD = explode("-", $commitDT[1]);
$commitDateTime = $commitDT[0]." (".$commitTD[0].")";
$commitSHA = substr($latestCommit["sha"],0,7);
//Would prefer to use the admin panel for this. //Would prefer to use the admin panel for this.
//But since the admin panel is optional...kind of stuck to using this. //But since the admin panel is optional...kind of stuck to using this.
$sb = new SetupBlock("Update"); $sb = new SetupBlock("Update");
$sb->position = 75; $sb->position = 75;
$sb->add_label("Current Commit: ".$config->get_string('commit_hash')); $sb->add_label("Current Commit: ".$config->get_string('commit_hash')." | ".$config->get_string('commit_time'));
$sb->add_text_option("update_url", "<br>Update URL: "); $sb->add_label("<br>Latest Commit: ".$commitSHA." | ".$commitDateTime." | ".$commitMessage);
$sb->add_text_option("update_guser", "<br>User: ");
$sb->add_text_option("update_grepo", "Repo: ");
$sb->add_label("<br><a href='".make_link('update')."'>Update</a>"); $sb->add_label("<br><a href='".make_link('update')."'>Update</a>");
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
@ -33,13 +54,30 @@ class Update extends Extension {
} }
private function update_shimmie() { private function update_shimmie() {
global $config, $page;
//This is a REALLY ugly function. (Damn my limited PHP knowledge >_<) //This is a REALLY ugly function. (Damn my limited PHP knowledge >_<)
global $config, $page;
$html = ""; $html = "";
$url = $config->get_string("update_url"); $g_user = $config->get_string("update_guser");
$g_repo = $config->get_string("update_grepo");
$base = "https://api.github.com/repos/".$g_user."/".$g_repo."/commits";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $base);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$content = curl_exec($curl);
curl_close($curl);
$commits = json_decode($content, true);
$latestCommit = $commits[0];
$commitDT = explode("T", $latestCommit["commit"]["committer"]["date"]);
$commitTD = explode("-", $commitDT[1]);
$commitDateTime = $commitDT[0]." (".$commitTD[0].")";
$commitSHA = substr($latestCommit["sha"],0,7);
$url = "http://nodeload.github.com/".$g_user."/".$g_repo."/zipball/".$commitSHA;
$mfile = "master.zip"; $mfile = "master.zip";
if(glob("*-shimmie2*")){ //#3 if(glob("*-shimmie2-".$commitSHA)){ //#3
$dir = glob("*-shimmie2*"); $dir = glob("*-shimmie2-".$commitSHA);
preg_match('@^([a-zA-Z0-9]+\-[0-9a-z]+\-)([^/]+)@i', $dir[0], $matches); preg_match('@^([a-zA-Z0-9]+\-[0-9a-z]+\-)([^/]+)@i', $dir[0], $matches);
if(!empty($matches[2])){ if(!empty($matches[2])){
$html .= "commit: ".$matches[2]; $html .= "commit: ".$matches[2];
@ -59,25 +97,12 @@ class Update extends Extension {
$html .= "<br>data folder emptied!"; $html .= "<br>data folder emptied!";
} }
copy ("./config.php", "./backup/config.php");//Although this stays the same, will keep backup just incase. 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. $folders = array("./core", "./lib", "./themes", "./.htaccess", "./doxygen.conf", "./index.php", "./install.php", "./ext", "./contrib");
rename ("./core", "./backup/core"); foreach($folders as $folder){
rename ("./".$matches[0]."/core", "./core"); //TODO: Check MD5 of each file, don't rename if same.
rename ("./lib", "./backup/lib"); rename ($folder, "./backup".substr($folder, 1)); //Move old files to backup
rename ("./".$matches[0]."/lib", "./lib"); rename ("./".$matches[0].substr($folder, 1), $folder); //Move new files to main
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)!"; $html .= "<br>old shimmie setup has been moved to /backup/ (excluding images/thumbs)!";
if (is_dir($matches[0])) { if (is_dir($matches[0])) {
$objects = scandir($matches[0]); $objects = scandir($matches[0]);
@ -93,6 +118,7 @@ class Update extends Extension {
$html .= "<br>shimmie updated (although you may have gotten errors, it should have worked!"; $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"; $html .= "<br>due to the way shimmie loads extensions, all optional extensions have been disabled";
$config->set_string("commit_hash", $commit); $config->set_string("commit_hash", $commit);
$config->set_string("commit_time", $commitDateTime);
$html .= "<br>new commit_hash has been set!"; $html .= "<br>new commit_hash has been set!";
}else{ }else{
$html .= "Error! Folder does not exist!?"; //Although this should be impossible, shall have it anyway. $html .= "Error! Folder does not exist!?"; //Although this should be impossible, shall have it anyway.

View File

@ -944,7 +944,7 @@ function get_debug_info() {
$i_mem = "???"; $i_mem = "???";
} }
if($config->get_string("commit_hash") == ""){ if($config->get_string("commit_hash") == "unknown"){
$commit = ""; $commit = "";
}else{ }else{
$commit = " (".$config->get_string("commit_hash").")"; $commit = " (".$config->get_string("commit_hash").")";

View File

@ -38,7 +38,7 @@ class BBCode extends FormatterExtension {
$text = preg_replace("/\[i\](.*?)\[\/i\]/s", "<i>\\1</i>", $text); $text = preg_replace("/\[i\](.*?)\[\/i\]/s", "<i>\\1</i>", $text);
$text = preg_replace("/\[u\](.*?)\[\/u\]/s", "<u>\\1</u>", $text); $text = preg_replace("/\[u\](.*?)\[\/u\]/s", "<u>\\1</u>", $text);
$text = preg_replace("/\[s\](.*?)\[\/s\]/s", "<s>\\1</s>", $text); $text = preg_replace("/\[s\](.*?)\[\/s\]/s", "<s>\\1</s>", $text);
$text = preg_replace("/&gt;&gt;(\d+)(#\d+)?/s", "<a href=\"".make_link("post/view/\\1\\2")."\">&gt;&gt;\\1\\2</a>", $text); $text = preg_replace("/&gt;&gt;(\d+)(#(\d+))?/s", "<a href=\"".make_link("post/view/\\1\\2")."\" onclick=\"$('[name=\\3]').parent().effect('highlight', {}, 5000);\">&gt;&gt;\\1\\2</a>", $text);
$text = preg_replace("/(^|\s)#(\d+)/s", "\\1<a href=\"#\\2\">#\\2</a>", $text); $text = preg_replace("/(^|\s)#(\d+)/s", "\\1<a href=\"#\\2\">#\\2</a>", $text);
$text = preg_replace("/&gt;&gt;([^\d].+)/", "<blockquote><small>\\1</small></blockquote>", $text); $text = preg_replace("/&gt;&gt;([^\d].+)/", "<blockquote><small>\\1</small></blockquote>", $text);
$text = preg_replace("/\[url=((?:https?|ftp|irc|mailto):\/\/.*?)\](.*?)\[\/url\]/s", "<a href=\"\\1\">\\2</a>", $text); $text = preg_replace("/\[url=((?:https?|ftp|irc|mailto):\/\/.*?)\](.*?)\[\/url\]/s", "<a href=\"\\1\">\\2</a>", $text);

View File

@ -123,4 +123,5 @@ function replyTo(imageId, commentId) {
box.focus(); box.focus();
box.val(box.val() + text); box.val(box.val() + text);
$("[name="+commentId+"]").parent().effect("highlight", {}, 5000);
} }