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

This commit is contained in:
Shish 2012-02-09 01:07:21 +00:00
commit 3584f40551
35 changed files with 311 additions and 60 deletions

6
.gitignore vendored
View file

@ -1,8 +1,10 @@
.svn
backup
config.php
images
thumbs
data
images
imgdump-*.zip
thumbs
sql.log
shimmie.log
!lib/images

View file

@ -78,6 +78,13 @@ class AdminPage extends Extension {
case 'database dump':
$this->dbdump($page);
break;
case 'reset image ids':
$this->reset_imageids();
$redirect = true;
break;
case 'image dump':
$this->imgdump($page);
break;
}
if($redirect) {
@ -175,5 +182,67 @@ class AdminPage extends Extension {
}
}
*/
private function reset_imageids() {
global $database;
//This might be a bit laggy on boards with lots of images (?)
//Seems to work fine with 1.2k~ images though.
$i = 0;
$image = $database->get_all("SELECT * FROM images ORDER BY images.id ASC");
/*$score_log = $database->get_all("SELECT message FROM score_log");*/
foreach($image as $img){
$xid = $img[0];
$i = $i + 1;
$table = array( //Might be missing some tables?
"image_tags", "tag_histories", "image_reports", "comments", "user_favorites", "tag_histories",
"numeric_score_votes", "pool_images", "slext_progress_cache", "notes");
$sql =
"SET FOREIGN_KEY_CHECKS=0;
UPDATE images
SET id=".$i.
" WHERE id=".$xid.";"; //id for images
foreach($table as $tbl){
$sql .= "
UPDATE ".$tbl."
SET image_id=".$i."
WHERE image_id=".$xid.";";
}
/*foreach($score_log as $sl){
//This seems like a bad idea.
//TODO: Might be better for log_info to have an $id option (which would then affix the id to the table?)
preg_replace(".Image \\#[0-9]+.", "Image #".$i, $sl);
}*/
$sql .= " SET FOREIGN_KEY_CHECKS=1;";
$database->execute($sql);
}
$count = (count($image)) + 1;
$database->execute("ALTER TABLE images AUTO_INCREMENT=".$count);
}
private function imgdump($page) {
global $database;
$zip = new ZipArchive;
$images = $database->get_all("SELECT * FROM images");
$filename = 'imgdump-'.date('Ymd').'.zip';
if($zip->open($filename, 1 ? ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE)===TRUE){
foreach($images as $img){
$hash = $img["hash"];
preg_match("^[A-Za-z0-9]{2}^", $hash, $matches);
$img_loc = "images/".$matches[0]."/".$hash;
if(file_exists($img_loc)){
$zip->addFile($img_loc, $hash.".".$img["ext"]);
}
}
$zip->close();
}
$page->set_mode("redirect");
$page->set_redirect(make_link($filename)); //Fairly sure there is better way to do this..
//TODO: Delete file after downloaded?
}
}
?>

View file

@ -19,13 +19,26 @@ class AdminPageTheme extends Themelet {
public function display_form(Page $page) {
global $user;
$html = "
".make_form(make_link("admin_utils"))."
<select name='action'>
$html = '
<script type="text/javascript">
function imgidconfirm(){
if(document.getElementById("misc").selectedIndex == 4){
if(confirm("This function WILL break any bookmarks & links.\n The event log will also not be updated with new ids. \n Are you sure you wish to continue?")){
return true;
}else{
return false;
}
}
}
</script>
'.make_form(make_link("admin_utils"),"post", false, false, "return imgidconfirm()")."
<select name='action' id='misc'>
<option value='lowercase all tags'>All tags to lowercase</option>
<option value='recount tag use'>Recount tag use</option>
<option value='purge unused tags'>Purge unused tags</option>
<option value='database dump'>Download database contents</option>
<option value='reset image ids'>Reset image ids</option>
<option value='image dump'>Download all images</option>
<!--<option value='convert to innodb'>Convert database to InnoDB (MySQL only)</option>-->
</select>
<input type='submit' value='Go'>

View file

@ -2,6 +2,7 @@
/*
* Name: Comment Word Ban
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: For stopping spam and other comment abuse
* Documentation:

View file

@ -2,6 +2,7 @@
/*
* Name: Bulk Add
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: Bulk add server-side images
* Documentation:
@ -30,7 +31,9 @@ class BulkAdd extends Extension {
$this->theme->display_admin_block();
}
/**
* Generate the necessary DataUploadEvent for a given image and tags.
*/
private function add_image($tmpname, $filename, $tags) {
assert(file_exists($tmpname));

View file

@ -29,6 +29,9 @@ class ET extends Extension {
}
}
/**
* Collect the information and return it in a keyed array.
*/
private function get_info() {
global $config, $database;
global $_event_listeners; // yay for using secret globals \o/

View file

@ -24,6 +24,8 @@ class FavoritesTheme extends Themelet {
$i_favorites = count($username_array);
$html = "$i_favorites people:";
reset($username_array); // rewind to first element in array.
foreach($username_array as $row) {
$username = html_escape($row);
$html .= "<br><a href='".make_link("user/$username")."'>$username</a>";

View file

@ -2,6 +2,7 @@
/*
* Name: Featured Image
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: Bring a specific image to the users' attentions
* Documentation:

View file

@ -2,7 +2,8 @@
/*
* Name: Handle Flash
* Author: Shish <webmaster@shishnet.org>
* Description: Handle Flash files
* Link: http://code.shishnet.org/shimmie2/
* Description: Handle Flash files. (No thumbnail is generated for flash files)
*/
class FlashFileHandler extends DataHandlerExtension {

View file

@ -2,7 +2,8 @@
/*
* Name: Handle SVG
* Author: Shish <webmaster@shishnet.org>
* Description: Handle SVG files
* Link: http://code.shishnet.org/shimmie2/
* Description: Handle SVG files. (No thumbnail is generated for SVG files)
*/
class SVGFileHandler extends Extension {

View file

@ -2,6 +2,7 @@
/*
* Name: IP Ban
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: Ban IP addresses
* Documentation:

View file

@ -1,8 +1,9 @@
<?php
/*
* Name: Logging (Database)
* Author: Shish
* Description: Keep a record of SCore events
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* Description: Keep a record of SCore events (in the database).
* Visibility: admin
*/

View file

@ -41,6 +41,8 @@ class LogDatabaseTheme extends Themelet {
</thead>
<tbody>\n";
$n = 0;
reset($events); // rewind to first element in array.
foreach($events as $event) {
$oe = ($n++ % 2 == 0) ? "even" : "odd";
$c = $this->pri_to_col($event['priority']);

View file

@ -2,6 +2,7 @@
/*
* Name: News
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: Show a short amount of text in a block on the post list
* Documentation:

View file

@ -2,6 +2,7 @@
/*
* Name: Image Scores (Numeric)
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: Allow users to score images
* Documentation:

View file

@ -2,6 +2,7 @@
/*
* Name: Random Image
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: Do things with a random image
* Documentation:

View file

@ -2,6 +2,7 @@
/*
* Name: Image Ratings
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: Allow users to rate images "safe", "questionable" or "explicit"
*/
@ -33,6 +34,9 @@ class Ratings extends Extension {
while(true) {
$images = Image::find_images($n, 100, Tag::explode($_POST["query"]));
if(count($images) == 0) break;
reset($images); // rewind to first element in array.
foreach($images as $image) {
send_event(new RatingSetEvent($image, $user, $_POST['rating']));
}

View file

@ -2,6 +2,7 @@
/*
* Name: Regen Thumb
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: Regenerate a thumbnail image
* Documentation:

View file

@ -2,6 +2,7 @@
/*
* Name: Site Description
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Visibility: admin
* Description: A description for search engines

View file

@ -188,6 +188,7 @@ class DatabaseConfig extends BaseConfig {
*/
public function save(/*string*/ $name=null) {
if(is_null($name)) {
reset($this->values); // rewind the array to the first element
foreach($this->values as $name => $value) {
$this->save(/*string*/ $name);
}

View file

@ -39,6 +39,8 @@ class PageRequestEvent extends Event {
* Test if the requested path matches a given pattern.
*
* If it matches, store the remaining path elements in $args
*
* @retval bool
*/
public function page_matches(/*string*/ $name) {
$parts = explode("/", $name);
@ -57,6 +59,11 @@ class PageRequestEvent extends Event {
return true;
}
/**
* Get the n th argument of the page request (if it exists.)
* @param $n integer
* @retval The argmuent (string) or NULL
*/
public function get_arg(/*int*/ $n) {
$offset = $this->part_count + $n;
if($offset >= 0 && $offset < $this->arg_count) {
@ -67,6 +74,10 @@ class PageRequestEvent extends Event {
}
}
/**
* Returns the number of arguments the page request has.
* @retval int
*/
public function count_args() {
return (int)($this->arg_count - $this->part_count);
}

View file

@ -106,8 +106,10 @@ class Image {
/**
* Search for an array of images
*
* @retval Array
*/
public static function find_images($start, $limit, $tags=array()) {
public static function find_images(/*int*/ $start, /*int*/ $limit, $tags=array()) {
assert(is_numeric($start));
assert(is_numeric($limit));
assert(is_array($tags));
@ -383,7 +385,7 @@ class Image {
/**
* Set the image's source URL
*/
public function set_source($source) {
public function set_source(/*string*/ $source) {
global $database;
if(empty($source)) $source = null;
if($source != $this->source) {
@ -392,7 +394,10 @@ class Image {
}
}
/**
* Check if the image is locked.
* @retval bool
*/
public function is_locked() {
return ($this->locked === true || $this->locked == "Y" || $this->locked == "t");
}
@ -776,6 +781,8 @@ class Image {
}
}
reset($terms); // rewind to first element in array.
// turn each term into a specific type of querylet
foreach($terms as $term) {
$negative = false;
@ -1008,8 +1015,15 @@ class Tag {
}
}
/**
* This function takes a list (array) of tags and changes any tags that have aliases
*
* @param $tags Array of tags
* @return Array of tags
*/
public static function resolve_list($tags) {
$tags = Tag::explode($tags);
reset($tags); // rewind array to the first element.
$new = array();
foreach($tags as $tag) {
$new_set = explode(' ', Tag::resolve_alias($tag));

View file

@ -237,7 +237,7 @@ class Page {
protected function add_auto_html_headers() {
$data_href = get_base_href();
$this->add_html_header("<script>base_href = '$data_href';</script>");
$this->add_html_header("<script type='text/javascript'>base_href = '$data_href';</script>");
/* Attempt to cache the CSS & JavaScript files */
if ($this->add_cached_auto_html_headers() === FALSE) {
@ -291,7 +291,11 @@ class Page {
{
global $config;
if (!$config->get_bool("autocache_css") && !$config->get_bool("autocache_js")) {
// store local copy for speed.
$autocache_css = $config->get_bool("autocache_css");
$autocache_js = $config->get_bool("autocache_js");
if (!$autocache_css && !$autocache_js) {
return false; // caching disabled
}
@ -309,7 +313,7 @@ class Page {
$data_href = get_base_href();
/* ----- CSS Files ----- */
if ($config->get_bool("autocache_css"))
if ($autocache_css)
{
// First get all the CSS from the lib directory
$contents_from_lib = '';
@ -376,7 +380,7 @@ class Page {
/* ----- JavaScript Files ----- */
if ($config->get_bool("autocache_js"))
if ($autocache_js)
{
$data = '';
$js_files = glob("lib/*.js");
@ -394,7 +398,7 @@ class Page {
// Minify the JS if enabled.
if ($config->get_bool("autocache_min_js")){
// not supported yet.
// TODO: add support for Minifying CSS files.
// TODO: add support for Minifying JS files.
}
// compute the MD5 sum of the concatenated JavaScript files

View file

@ -216,6 +216,7 @@ class User {
/**
* Get a snippet of HTML which will render the user's avatar, be that
* a local file, a remote file, a gravatar, a something else, etc
* @retval String of HTML
*/
public function get_avatar_html() {
// FIXME: configurable
@ -242,6 +243,8 @@ class User {
* authtok = md5(sesskey, salt), presented to the user in web forms, to make sure that
* the form was generated within the session. Salted and re-hashed so that
* reading a web page from the user's cache doesn't give access to the session key
*
* @retval String containing auth token (MD5sum)
*/
public function get_auth_token() {
global $config;

View file

@ -190,12 +190,26 @@ function undb_bool($val) {
if($val === false || $val == 'N' || $val == 'n' || $val == 'F' || $val == 'f' || $val === 0) return false;
}
function startsWith($haystack, $needle) {
/**
* Checks if a given string contains another at the beginning.
*
* @param $haystack String to examine.
* @param $needle String to look for.
* @retval bool
*/
function startsWith(/*string*/ $haystack, /*string*/ $needle) {
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
function endsWith($haystack, $needle) {
/**
* Checks if a given string contains another at the end.
*
* @param $haystack String to examine.
* @param $needle String to look for.
* @retval bool
*/
function endsWith(/*string*/ $haystack, /*string*/ $needle) {
$length = strlen($needle);
$start = $length * -1; //negative
return (substr($haystack, $start) === $needle);
@ -621,6 +635,7 @@ function log_msg($section, $priority, $message) {
send_event(new LogEvent($section, $priority, $message));
}
// More shorthand ways of logging
function log_debug($section, $message) {log_msg($section, SCORE_LOG_DEBUG, $message);}
function log_info($section, $message) {log_msg($section, SCORE_LOG_INFO, $message);}
function log_warning($section, $message) {log_msg($section, SCORE_LOG_WARNING, $message);}
@ -848,6 +863,13 @@ function send_event(Event $event) {
// string representation of a number, it's two numbers separated by a space.
// What the fuck were the PHP developers smoking.
$_load_start = microtime(true);
/**
* Collects some debug information (execution time, memory usage, queries, etc)
* and formats it to stick in the footer of the page.
*
* @retval String of debug info to add to the page.
*/
function get_debug_info() {
global $config, $_event_count, $database, $_execs, $_load_start;
@ -1045,6 +1067,9 @@ function _load_extensions() {
ctx_log_endok();
}
/**
* Used to display fatal errors to the web user.
*/
function _fatal_error(Exception $e) {
$version = VERSION;
$message = $e->getMessage();

View file

@ -35,14 +35,17 @@ class CommentListTheme extends Themelet {
// parts for each image
$position = 10;
$comment_limit = $config->get_int("comment_list_count", 10);
$comment_captcha = $config->get_bool('comment_captcha');
foreach($images as $pair) {
$image = $pair[0];
$comments = $pair[1];
$thumb_html = $this->build_thumb_html($image);
$comment_html = "";
$comment_limit = $config->get_int("comment_list_count", 10);
$comment_count = count($comments);
if($comment_limit > 0 && $comment_count > $comment_limit) {
$hidden = $comment_count - $comment_limit;
@ -59,7 +62,7 @@ class CommentListTheme extends Themelet {
}
} else {
if ($can_post) {
if(!$config->get_bool('comment_captcha')) {
if(!$comment_captcha) {
$comment_html .= $this->build_postbox($image->id);
}
else {

View file

@ -1,7 +1,8 @@
<?php
/*
/**
* Name: Tag List
* Author: Shish
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* Description: Show the tags in various ways
*/
@ -107,13 +108,18 @@ class TagList extends Extension {
return make_link("post/list/$u_tag/1");
}
/**
* Get the minimum number of times a tag needs to be used
* in order to be considered in the tag list.
* @retval int
*/
private function get_tags_min() {
if(isset($_GET['mincount'])) {
return int_escape($_GET['mincount']);
}
else {
global $config;
return $config->get_int('tags_min');
return $config->get_int('tags_min'); // get the default.
}
}
@ -170,6 +176,8 @@ class TagList extends Extension {
$tags_min = $this->get_tags_min();
$starts_with = $this->get_starts_with();
// check if we have a cached version
$cache_key = "data/tag_cloud-" . md5("tc" . $tags_min . $starts_with) . ".html";
if(file_exists($cache_key)) {return file_get_contents($cache_key);}
@ -205,6 +213,8 @@ class TagList extends Extension {
$tags_min = $this->get_tags_min();
$starts_with = $this->get_starts_with();
// check if we have a cached version
$cache_key = "data/tag_alpha-" . md5("ta" . $tags_min . $starts_with) . ".html";
if(file_exists($cache_key)) {return file_get_contents($cache_key);}
@ -239,6 +249,8 @@ class TagList extends Extension {
global $database;
$tags_min = $this->get_tags_min();
// check if we have a cached version
$cache_key = "data/tag_popul-" . md5("tp" . $tags_min) . ".html";
if(file_exists($cache_key)) {return file_get_contents($cache_key);}

View file

@ -69,23 +69,28 @@ class TagListTheme extends Themelet {
*/
public function display_popular_block(Page $page, $tag_infos) {
global $config;
// store local copies for speed.
$info_link = $config->get_string('info_link');
$tag_list_num = $config->get_bool("tag_list_numbers");
$html = "";
$n = 0;
foreach($tag_infos as $row) {
$tag = $row['tag'];
$h_tag = html_escape($tag);
$h_tag_no_underscores = str_replace("_", " ", $h_tag);
$count = $row['count'];
if($n++) $html .= "\n<br/>";
if(!is_null($config->get_string('info_link'))) {
$link = str_replace('$tag', $tag, $config->get_string('info_link'));
$html .= " <a class='tag_info_link' href='$link'>?</a>";
if(!is_null($info_link)) {
$link = str_replace('$tag', $tag, $info_link);
$html .= ' <a class="tag_info_link" href="'.$link.'">?</a>';
}
$link = $this->tag_link($row['tag']);
$html .= " <a class='tag_name' href='$link'>$h_tag_no_underscores</a>";
if($config->get_bool("tag_list_numbers")) {
$html .= " <span class='tag_count'>$count</span>";
$html .= ' <a class="tag_name" href="$link">'.$h_tag_no_underscores.'</a>';
if($tag_list_num) {
$html .= ' <span class="tag_count">'.$count.'</span>';
}
}
@ -103,19 +108,23 @@ class TagListTheme extends Themelet {
public function display_refine_block(Page $page, $tag_infos, $search) {
global $config;
// store local copy for speed.
$info_link = $config->get_string('info_link');
$html = "";
$n = 0;
foreach($tag_infos as $row) {
$tag = $row['tag'];
$h_tag = html_escape($tag);
$h_tag_no_underscores = str_replace("_", " ", $h_tag);
if($n++) $html .= "\n<br/>";
if(!is_null($config->get_string('info_link'))) {
$link = str_replace('$tag', $tag, $config->get_string('info_link'));
$html .= " <a class='tag_info_link' href='$link'>?</a>";
if(!is_null($info_link)) {
$link = str_replace('$tag', $tag, $info_link);
$html .= ' <a class="tag_info_link" href="'.$link.'">?</a>';
}
$link = $this->tag_link($row['tag']);
$html .= " <a class='tag_name' href='$link'>$h_tag_no_underscores</a>";
$html .= ' <a class="tag_name" href="'.$link.'">'.$h_tag_no_underscores.'</a>';
$html .= $this->ars($tag, $search);
}

View file

@ -1,7 +1,8 @@
<?php
/*
* Name: Database Upgrader
* Author: Shish
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* Description: Keeps things happy behind the scenes
* Visibility: admin
*/

View file

@ -4,22 +4,49 @@
var maxsze = (maxsze.match("(?:\.*[0-9])")) * 1024; //This assumes we are only working with MB.
var toobig = "The file you are trying to upload is too big to upload!";
var notsup = "The file you are trying to upload is not supported!";
if (CA === 0 || CA > 2){ //Default
if (confirm("OK = Use Current tags.\nCancel = Use new tags.")==true){
}else{
var tag=prompt("Enter Tags","");
var chk=1; //This makes sure it doesn't use current tags.
}
}else if (CA === 1){ //Current Tags
}else if (CA === 2){ //New Tags
var tag=prompt("Enter Tags","");
var chk=1;
}
if (confirm("OK = Use Current tags.\nCancel = Use new tags.")==true){}else{var tag=prompt("Enter Tags","");var chk=1;};
// Danbooru
// Danbooru | oreno.imouto | konachan | sankakucomplex
if(document.getElementById("post_tags") !== null){
if (typeof tag !=="ftp://ftp." && chk !==1){var tag=document.getElementById("post_tags").value;}
var rtg=document.getElementById("stats").innerHTML.match("<li>Rating: (.*)<\/li>")[1];
var srx="http://" + document.location.hostname + document.location.href.match("\/post\/show\/[0-9]+\/");
var srx="http://" + document.location.hostname + document.location.href.match("\/post\/show\/[0-9]+");
if(srx.search("oreno\\.imouto") >= 0 || srx.search("konachan\\.com") >= 0){
var rtg=document.getElementById("stats").innerHTML.match("<li>Rating: (.*) <span")[1];
}else{
var rtg=document.getElementById("stats").innerHTML.match("<li>Rating: (.*)<\/li>")[1];
}
if(tag.search(/\bflash\b/)===-1){
var filesze=document.getElementById("stats").innerHTML.match("[0-9] \\(((?:\.*[0-9])) ([a-zA-Z]+)");
var hrs=document.getElementById("highres").href;
if(srx.search("oreno\\.imouto") >= 0 || srx.search("konachan\\.com") >= 0){ //oreno's theme seems to have moved the filesize
var filesze = document.getElementById("highres").innerHTML.match("[a-zA-Z0-9]+ \\(+([0-9]+\\.[0-9]+) ([a-zA-Z]+)");
}else{
var filesze=document.getElementById("stats").innerHTML.match("[0-9] \\(((?:\.*[0-9])) ([a-zA-Z]+)");
}
if(filesze[2] == "MB"){var filesze = filesze[1] * 1024;}else{var filesze = filesze[2].match("[0-9]+");}
if(supext.search(document.getElementById("highres").href.match("http\:\/\/.*\\.([a-z0-9]+)")[1]) !== -1){
if(supext.search(hrs.match("http\:\/\/.*\\.([a-z0-9]+)")[1]) !== -1){
if(filesze <= maxsze){
location.href=ste+document.getElementById("highres").href+"&tags="+tag+"&rating="+rtg+"&source="+srx;
if(srx.search("oreno\\.imouto") >= 0){
//this regex tends to be a bit picky with tags -_-;;
var hrs=hrs.match("(http\:\/\/[a-z0-9]+\.[a-z]+\.[a-z]\/[a-z0-9]+\/[a-z0-9]+)\/[a-z0-9A-Z%_-]+(\.[a-zA-Z0-9]+)");
var hrs=hrs[1]+hrs[2]; //this should bypass hotlink protection
}else if(srx.search("konachan\\.com") >= 0){
//konachan affixs konachan.com to the start of the tags, this requires different regex
var hrs=hrs.match("(http\:\/\/[a-z0-9]+\.[a-z]+\.[a-z]\/[a-z0-9]+\/[a-z0-9]+)\/[a-z0-9A-Z%_]+\.[a-zA-Z0-9%_-]+(\.[a-z0-9A-Z]+)")
var hrs=hrs[1]+hrs[2];
}
location.href=ste+hrs+"&tags="+tag+"&rating="+rtg+"&source="+srx;
}else{alert(toobig);}
}else{alert(notsup);}
}else{
@ -29,6 +56,7 @@ if(document.getElementById("post_tags") !== null){
}
}
/* Shimmie
One problem with shimmie is each theme does not show the same info as other themes (I.E only the danbooru & lite themes show statistics)
Shimmie doesn't seem to have any way to grab tags via id unless you have the ability to edit tags.
Have to go the round about way of checking the title for tags.
This crazy way of checking "should" work with older releases though (Seems to work with 2009~ ver) */
@ -36,7 +64,6 @@ else if(document.getElementsByTagName("title")[0].innerHTML.search("Image [0-9.-
if (typeof tag !=="ftp://ftp." && chk !==1){var tag=document.getElementsByTagName("title")[0].innerHTML.match("Image [0-9.-]+\: (.*)")[1];}
//TODO: Make rating show in statistics.
var srx="http://" + document.location.hostname + document.location.href.match("\/post\/view\/[0-9]+");
/*TODO: Figure out regex for shortening file link. I.E http://blah.net/_images/1234abcd/everysingletag.png > http://blah.net/_images/1234abcd.png*/
/*TODO: Make file size show on all themes (Only seems to show in lite/Danbooru themes.)*/
if(tag.search(/\bflash\b/)==-1){
var img = document.getElementById("main_image").src;
@ -52,7 +79,6 @@ else if(document.getElementsByTagName("title")[0].innerHTML.search("Image [0-9.-
}
// Gelbooru
else if(document.getElementById("tags") !== null){
//Gelbooru has an annoying anti-hotlinking thing which doesn't seem to like the bookmarklet.
if (typeof tag !=="ftp://ftp." && chk !==1){var tag=document.getElementById("tags").value;}
var rtg=document.getElementById("stats").innerHTML.match("<li>Rating: (.*)<\/li>")[1];
//Can't seem to grab source due to url containing a &
@ -61,6 +87,6 @@ else if(document.getElementById("tags") !== null){
//Since Gelbooru does not allow flash, no need to search for flash tag.
//Gelbooru doesn't show file size in statistics either...
if(supext.search(gmi.match("http\:\/\/.*\\.([a-z0-9]+)")[1]) !== -1){
location.href=ste+gmi+"&tags="+tag+"&rating="+rtg[1];//+"&source="+srx;
location.href=ste+gmi+"&tags="+tag+"&rating="+rtg;//+"&source="+srx;
}else{alert(notsup);}
}

View file

@ -1,5 +1,5 @@
<?php
/*
/**
* Name: Uploader
* Author: Shish
* Description: Allows people to upload files to the website
@ -58,6 +58,8 @@ class Upload extends Extension {
$this->is_full = false;
}
else {
// TODO: This size limit should be configureable by the admin...
// currently set to 100 MB
$this->is_full = $free_num < 100*1024*1024;
}
@ -150,12 +152,14 @@ class Upload extends Extension {
$tags = ''; // Tags aren't changed when uploading. Set to null to stop PHP warnings.
if(count($_FILES)) {
reset($_FILES); // rewind to first element in array.
foreach($_FILES as $file) {
$ok = $this->try_upload($file, $tags, $source, $image_id);
break; // leave the foreach loop.
}
}
else {
reset($_POST); // rewind to first element in array.
foreach($_POST as $name => $value) {
if(substr($name, 0, 3) == "url" && strlen($value) > 0) {
$ok = $this->try_transload($value, $tags, $source, $image_id);
@ -186,9 +190,11 @@ class Upload extends Extension {
$source = isset($_POST['source']) ? $_POST['source'] : null;
$ok = true;
foreach($_FILES as $file) {
reset($_FILES); // rewind to first element in array.
$ok = $ok & $this->try_upload($file, $tags, $source);
}
foreach($_POST as $name => $value) {
reset($_POST); // rewind to first element in array.
if(substr($name, 0, 3) == "url" && strlen($value) > 0) {
$ok = $ok & $this->try_transload($value, $tags, $source);
}
@ -218,14 +224,28 @@ class Upload extends Extension {
}
// }}}
// do things {{{
/**
* Check if a given user can upload.
* @param $user The user to check.
* @retval bool
*/
private function can_upload(User $user) {
global $config;
return ($config->get_bool("upload_anon") || !$user->is_anonymous());
}
// Helper function based on the one from the online PHP Documentation
// which is licensed under Creative Commons Attribution 3.0 License
// TODO: Make these messages user/admin editable
/**
* Returns a descriptive error message for the specified PHP error code.
*
* This is a helper function based on the one from the online PHP Documentation
* which is licensed under Creative Commons Attribution 3.0 License
*
* TODO: Make these messages user/admin editable
*
* @param $error_code PHP error code (int)
* @retval String
*/
private function upload_error_message($error_code) {
switch ($error_code) {
case UPLOAD_ERR_INI_SIZE:
@ -247,6 +267,10 @@ class Upload extends Extension {
}
}
/**
* Handle an upload.
* @retval bool TRUE on upload successful.
*/
private function try_upload($file, $tags, $source, $replace='') {
global $page;
global $config;
@ -293,6 +317,10 @@ class Upload extends Extension {
return $ok;
}
/**
* Handle an transload.
* @retval bool TRUE on transload successful.
*/
private function try_transload($url, $tags, $source, $replace='') {
global $page;
global $config;

View file

@ -18,6 +18,7 @@ class UploadTheme extends Themelet {
$upload_list = "";
$upload_count = $config->get_int('upload_count');
for($i=0; $i<$upload_count; $i++)
{
$a=$i+1;
@ -53,7 +54,7 @@ class UploadTheme extends Themelet {
<a href='#' onclick='$js'>".
"<img src='ext/upload/minus.png' /></a>";
if($a==$config->get_int('upload_count')){
if($a == $upload_count){
$upload_list .="<img id='wrapper' src='ext/upload/plus.png' />";
}else{
$js1 = 'javascript:$(function() {
@ -145,8 +146,7 @@ class UploadTheme extends Themelet {
{
/* Imageboard > Shimmie Bookmarklet
This is more or less, an upgraded version of the "Danbooru>Shimmie" bookmarklet.
At the moment this works with Shimmie & Danbooru.
It would also work with Gelbooru but unless someone can figure out how to bypass their hotlinking..meh.
At the moment this is known to work with Shimmie/Danbooru/Gelbooru/oreno.imouto/konachan/sankakucomplex.
The bookmarklet is now also loaded via the .js file in this folder.
*/
//Bookmarklet checks if shimmie supports ext. If not, won't upload to site/shows alert saying not supported.
@ -156,7 +156,8 @@ class UploadTheme extends Themelet {
if(file_exists("ext/handle_mp3")){$supported_ext .= " mp3";}
if(file_exists("ext/handle_svg")){$supported_ext .= " svg";}
$title = "Booru to " . $config->get_string('title');
$html .= '<p><a href="javascript:var ste=&quot;'. $link . $delimiter .'url=&quot;; var supext=&quot;'.$supported_ext.'&quot;; var maxsze=&quot;'.$max_kb.'&quot;; void(document.body.appendChild(document.createElement(&quot;script&quot;)).src=&quot;'.make_http(make_link("ext/upload/bookmarklet.js")).'&quot;)">'.
//CA=0: Ask to use current or new tags | CA=1: Always use current tags | CA=2: Always use new tags
$html .= '<p><a href="javascript:var ste=&quot;'. $link . $delimiter .'url=&quot;; var supext=&quot;'.$supported_ext.'&quot;; var maxsze=&quot;'.$max_kb.'&quot;; var CA=0; void(document.body.appendChild(document.createElement(&quot;script&quot;)).src=&quot;'.make_http(get_base_href())."/ext/upload/bookmarklet.js".'&quot;)">'.
$title . '</a> (Click when looking at an image page. Works on sites running Shimmie/Danbooru/Gelbooru. (This also grabs the tags/rating/source!))';
}

View file

@ -25,6 +25,10 @@ class CustomCommentListTheme extends CommentListTheme {
// parts for each image
$position = 10;
$comment_captcha = $config->get_bool('comment_captcha');
$comment_limit = $config->get_int("comment_list_count", 10);
foreach($images as $pair) {
$image = $pair[0];
$comments = $pair[1];
@ -42,7 +46,7 @@ class CustomCommentListTheme extends CommentListTheme {
$r = class_exists("Ratings") ? "<b>Rating</b> ".Ratings::rating_to_human($image->rating) : "";
$comment_html = "<b>Date</b> $p $s <b>User</b> $un $s $r<br><b>Tags</b> $t<p>&nbsp;";
$comment_limit = $config->get_int("comment_list_count", 10);
$comment_count = count($comments);
if($comment_limit > 0 && $comment_count > $comment_limit) {
$hidden = $comment_count - $comment_limit;
@ -57,7 +61,7 @@ class CustomCommentListTheme extends CommentListTheme {
$comment_html .= $this->build_postbox($image->id);
}
else {
if(!$config->get_bool('comment_captcha')) {
if(!$comment_captcha) {
$comment_html .= $this->build_postbox($image->id);
}
else {

View file

@ -38,7 +38,7 @@ class CustomViewImageTheme extends ViewImageTheme {
$html .= "<br>Source: <a href='$h_source'>link</a>";
}
if(!is_null($image->rating) && file_exists("ext/rating")) {
if(file_exists("ext/rating")) {
if($image->rating == null || $image->rating == "u"){
$image->rating = "u";
}

View file

@ -44,7 +44,7 @@ class CustomViewImageTheme extends ViewImageTheme {
$html .= "<br>Source: <a href='$h_source'>link</a>";
}
if(!is_null($image->rating) && file_exists("ext/rating")) {
if(file_exists("ext/rating")) {
if($image->rating == null || $image->rating == "u"){
$image->rating = "u";
}