diff --git a/contrib/resize/main.php b/contrib/resize/main.php index bb5b423b..58991875 100644 --- a/contrib/resize/main.php +++ b/contrib/resize/main.php @@ -61,9 +61,8 @@ class ResizeImage extends Extension { public function onDataUpload(DataUploadEvent $event) { global $config; $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")){ + + if($config->get_bool("resize_upload") == true && ($image_obj->ext == "jpg" || $image_obj->ext == "png" || $image_obj->ext == "gif")){ $width = $height = 0; if ($config->get_int("resize_default_width") !== 0) { @@ -72,20 +71,32 @@ class ResizeImage extends Extension { if ($config->get_int("resize_default_height") !== 0) { $height = $config->get_int("resize_default_height"); } - - try { - $this->resize_image($event->image_id, $width, $height); - } catch (ImageResizeException $e) { - $this->theme->display_resize_error($page, "Error Resizing", $e->error); + $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 { + $this->resize_image($event->image_id, $width, $height); + } catch (ImageResizeException $e) { + $this->theme->display_resize_error($page, "Error Resizing", $e->error); + } - //Need to generate thumbnail again... - //This only seems to be an issue if one of the sizes was set to 0. - $image_obj = Image::by_id($event->image_id); //Must be a better way to grab the new hash than setting this again.. - send_event(new ThumbnailGenerationEvent($image_obj->hash, $image_obj->ext, true)); + //Need to generate thumbnail again... + //This only seems to be an issue if one of the sizes was set to 0. + $image_obj = Image::by_id($event->image_id); //Must be a better way to grab the new hash than setting this again.. + send_event(new ThumbnailGenerationEvent($image_obj->hash, $image_obj->ext, true)); - log_info("resize", "Image #{$event->image_id} has been resized to: ".$width."x".$height); - //TODO: Notify user that image has been resized. + log_info("resize", "Image #{$event->image_id} has been resized to: ".$width."x".$height); + //TODO: Notify user that image has been resized. + } } } @@ -209,8 +220,7 @@ class ResizeImage extends Extension { switch ( $info[2] ) { case IMAGETYPE_GIF: $image = imagecreatefromgif($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: throw new ImageResizeException("Unsupported image type."); } diff --git a/contrib/update/main.php b/contrib/update/main.php index 3a2f9a11..91ada364 100644 --- a/contrib/update/main.php +++ b/contrib/update/main.php @@ -9,18 +9,39 @@ class Update extends Extension { public function onInitExt(InitExtEvent $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", ""); + $config->set_default_string("update_guser", "shish"); + $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) { 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. //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", "
Update URL: "); + $sb->add_label("Current Commit: ".$config->get_string('commit_hash')." | ".$config->get_string('commit_time')); + $sb->add_label("
Latest Commit: ".$commitSHA." | ".$commitDateTime." | ".$commitMessage); + $sb->add_text_option("update_guser", "
User: "); + $sb->add_text_option("update_grepo", "Repo: "); $sb->add_label("
Update"); $event->panel->add_block($sb); } @@ -33,13 +54,30 @@ class Update extends Extension { } private function update_shimmie() { - global $config, $page; //This is a REALLY ugly function. (Damn my limited PHP knowledge >_<) + global $config, $page; $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"; - if(glob("*-shimmie2*")){ //#3 - $dir = glob("*-shimmie2*"); + if(glob("*-shimmie2-".$commitSHA)){ //#3 + $dir = glob("*-shimmie2-".$commitSHA); preg_match('@^([a-zA-Z0-9]+\-[0-9a-z]+\-)([^/]+)@i', $dir[0], $matches); if(!empty($matches[2])){ $html .= "commit: ".$matches[2]; @@ -59,25 +97,12 @@ class Update extends Extension { $html .= "
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"); + $folders = array("./core", "./lib", "./themes", "./.htaccess", "./doxygen.conf", "./index.php", "./install.php", "./ext", "./contrib"); + foreach($folders as $folder){ + //TODO: Check MD5 of each file, don't rename if same. + rename ($folder, "./backup".substr($folder, 1)); //Move old files to backup + rename ("./".$matches[0].substr($folder, 1), $folder); //Move new files to main + } $html .= "
old shimmie setup has been moved to /backup/ (excluding images/thumbs)!"; if (is_dir($matches[0])) { $objects = scandir($matches[0]); @@ -93,6 +118,7 @@ class Update extends Extension { $html .= "
shimmie updated (although you may have gotten errors, it should have worked!"; $html .= "
due to the way shimmie loads extensions, all optional extensions have been disabled"; $config->set_string("commit_hash", $commit); + $config->set_string("commit_time", $commitDateTime); $html .= "
new commit_hash has been set!"; }else{ $html .= "Error! Folder does not exist!?"; //Although this should be impossible, shall have it anyway. diff --git a/core/util.inc.php b/core/util.inc.php index 158d1f2e..a6af136a 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -944,7 +944,7 @@ function get_debug_info() { $i_mem = "???"; } - if($config->get_string("commit_hash") == ""){ + if($config->get_string("commit_hash") == "unknown"){ $commit = ""; }else{ $commit = " (".$config->get_string("commit_hash").")"; diff --git a/ext/bbcode/main.php b/ext/bbcode/main.php index 420b5033..28a44cb2 100644 --- a/ext/bbcode/main.php +++ b/ext/bbcode/main.php @@ -38,7 +38,7 @@ class BBCode extends FormatterExtension { $text = preg_replace("/\[i\](.*?)\[\/i\]/s", "\\1", $text); $text = preg_replace("/\[u\](.*?)\[\/u\]/s", "\\1", $text); $text = preg_replace("/\[s\](.*?)\[\/s\]/s", "\\1", $text); - $text = preg_replace("/>>(\d+)(#\d+)?/s", ">>\\1\\2", $text); + $text = preg_replace("/>>(\d+)(#(\d+))?/s", ">>\\1\\2", $text); $text = preg_replace("/(^|\s)#(\d+)/s", "\\1#\\2", $text); $text = preg_replace("/>>([^\d].+)/", "
\\1
", $text); $text = preg_replace("/\[url=((?:https?|ftp|irc|mailto):\/\/.*?)\](.*?)\[\/url\]/s", "\\2", $text); diff --git a/lib/shimmie.js b/lib/shimmie.js index 7ebfe6e3..b2d531a7 100644 --- a/lib/shimmie.js +++ b/lib/shimmie.js @@ -123,4 +123,5 @@ function replyTo(imageId, commentId) { box.focus(); box.val(box.val() + text); + $("[name="+commentId+"]").parent().effect("highlight", {}, 5000); }