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

This commit is contained in:
Shish 2012-01-01 16:58:01 +00:00
commit 0c96603861
22 changed files with 238 additions and 62 deletions

View File

@ -32,12 +32,36 @@ class AdminPageTheme extends Themelet {
</form>
";
$page->add_block(new Block("Misc Admin Tools", $html));
/* First check
Requires you to click the checkbox to enable the delete by query form */
$dbqcheck = "
if(document.getElementById(&quot;dbqcheck&quot;).checked == false){
document.getElementById(&quot;dbqtags&quot;).disabled = true;
document.getElementById(&quot;dbqsubmit&quot;).disabled = true;
}else{
document.getElementById(&quot;dbqtags&quot;).disabled = false;
document.getElementById(&quot;dbqsubmit&quot;).disabled = false;
}";
/* Second check
Requires you to confirm the deletion by clicking ok. */
$html = "
".make_form(make_link("admin_utils"))."
<script type='text/javascript'>
function checkform(){
if(confirm('Are you sure you wish to delete all images using these tags?')){
return true;
}else{
return false;
}
}
</script>"
.make_form(make_link("admin_utils"),"post",false,false,"return checkform()")."
<input type='checkbox' id='dbqcheck' name='action' onclick='$dbqcheck'>
<input type='hidden' name='action' value='delete by query'>
<input type='text' name='query'>
<input type='submit' value='Go'>
<input type='text' id='dbqtags' disabled='true' name='query'>
<input type='submit' id='dbqsubmit' disabled='true' value='Go'>
</form>
";
$page->add_block(new Block("Delete by Query", $html));

View File

@ -47,7 +47,7 @@ EOD
$counter_html
<div class='space' id='foot'>
<small><small>
<a href='$contact_link'>Contact</a> &ndash; Serving $num_comma posts &ndash;
<a href='mailto:$contact_link'>Contact</a> &ndash; Serving $num_comma posts &ndash;
Running <a href='http://code.shishnet.org/shimmie2/'>Shimmie</a>
</small></small>
</div>

View File

@ -75,6 +75,7 @@ class MySQL extends DBEngine {
$data = str_replace("SCORE_DATETIME", "DATETIME", $data);
$data = str_replace("SCORE_NOW", "\"1970-01-01\"", $data);
$data = str_replace("SCORE_STRNORM", "", $data);
$data = str_replace("SCORE_ILIKE", "LIKE", $data);
return $data;
}
@ -96,6 +97,7 @@ class PostgreSQL extends DBEngine {
$data = str_replace("SCORE_DATETIME", "TIMESTAMP", $data);
$data = str_replace("SCORE_NOW", "current_time", $data);
$data = str_replace("SCORE_STRNORM", "lower", $data);
$data = str_replace("SCORE_ILIKE", "ILIKE", $data);
return $data;
}
@ -142,6 +144,7 @@ class SQLite extends DBEngine {
$data = str_replace("SCORE_BOOL", "CHAR(1)", $data);
$data = str_replace("SCORE_NOW", "\"1970-01-01\"", $data);
$data = str_replace("SCORE_STRNORM", "", $data);
$data = str_replace("SCORE_ILIKE", "LIKE", $data);
$cols = array();
$extras = "";
foreach(explode(",", $data) as $bit) {

View File

@ -129,34 +129,9 @@ function to_shorthand_int($int) {
* @retval string
*/
function autodate($date, $html=true) {
global $config;
$format = $config->get_string('autodate_format', "F j, Y");
$seconds = time() - strtotime($date);
$ago = seconds_to_time($seconds) . " ago";
$on = "on " . date($format, strtotime($date));
if($config->get_bool('use_autodate', true)) {
return ($html ? "<span title='$on'>$ago</span>" : $ago);
}
else {
return $on;
}
}
/**
* Turn a number of seconds into a vague human timespan, eg 142 -> "2 minutes"
*
* @retval string
*/
function seconds_to_time($seconds) {
if($seconds<60) return $seconds . " second" . plural($seconds); $seconds = round($seconds/60);
if($seconds<60) return $seconds . " minute" . plural($seconds); $seconds = round($seconds/60);
if($seconds<24) return $seconds . " hour" . plural($seconds); $seconds = round($seconds/24);
if($seconds<7) return $seconds . " day" . plural($seconds); $seconds = round($seconds/7);
if($seconds<4) return $seconds . " week" . plural($seconds); $seconds = round($seconds/4);
if($seconds<12) return $seconds . " month" . plural($seconds); $seconds = round($seconds/12);
return $seconds . " year" . plural($seconds);
$cpu = date('c', strtotime($date));
$hum = date('F j, Y', strtotime($date));
return ($html ? "<time datetime='$cpu'>$hum</time>" : $hum);
}
@ -279,13 +254,16 @@ function make_http($link) {
*
* @retval string
*/
function make_form($target, $method="POST", $multipart=False, $form_id="") {
function make_form($target, $method="POST", $multipart=False, $form_id="", $onsubmit="") {
global $user;
$auth = $user->get_auth_html();
$extra = empty($form_id) ? '' : " id='$form_id'";
if($multipart) {
$extra .= " enctype='multipart/form-data'";
}
if($onsubmit) {
$extra .= " onsubmit='$onsubmit'";
}
return "<form action='$target' method='$method'$extra>$auth";
}

View File

@ -179,6 +179,7 @@ class CommentListTheme extends Themelet {
return "
<a name='$i_comment_id'></a>
<div class='$oe comment'>
<!--<span class='timeago' style='float: right;'>$h_timestamp</span>-->
$h_userlink: $h_comment
$h_dellink
</div>

View File

@ -169,10 +169,8 @@ class Setup extends SimpleExtension {
$config->set_default_string("main_page", "post/list");
$config->set_default_string("base_href", "./index.php?q=");
$config->set_default_string("theme", "default");
$config->set_default_bool("use_autodate", true);
$config->set_default_bool("word_wrap", true);
$config->set_default_bool("comment_captcha", false);
$config->set_default_string("autodate_format", "F j, Y");
// Automatic caching is disabled by default
$config->set_default_string("autocache_location", "data/cache");
$config->set_default_bool("autocache_css", false);

View File

@ -141,7 +141,7 @@ class TagList implements Extension {
$tag_data = $database->get_col("
SELECT DISTINCT
substr(tag, 1, 1)
SCORE_STRNORM(substr(tag, 1, 1))
FROM tags
WHERE count >= :tags_min
ORDER BY substr(tag, 1, 1)
@ -184,7 +184,7 @@ class TagList implements Extension {
FLOOR(LOG(2.7, LOG(2.7, count - :tags_min2 + 1)+1)*1.5*100)/100 AS scaled
FROM tags
WHERE count >= :tags_min
AND tag LIKE :starts_with
AND tag SCORE_ILIKE :starts_with
ORDER BY tag
", array("tags_min"=>$tags_min, "tags_min2"=>$tags_min, "starts_with"=>$starts_with));
@ -216,7 +216,7 @@ class TagList implements Extension {
SELECT tag, count
FROM tags
WHERE count >= :tags_min
AND tag LIKE :starts_with
AND tag SCORE_ILIKE :starts_with
ORDER BY tag
", array("tags_min"=>$tags_min, "starts_with"=>$starts_with));

View File

@ -52,8 +52,12 @@ class TagListTheme extends Themelet {
$html .= " <span class='tag_count'>$count</span>";
}
}
$page->add_block(new Block("Related", $html, "left"));
if($config->get_string('tag_list_image_type')=="tags"){
$page->add_block(new Block("Tags", $html, "left", 10));}
else{
$page->add_block(new Block("Related Tags", $html, "left", 10));
}
}

View File

@ -27,11 +27,11 @@ class UploadTheme extends Themelet {
if($i==0){
$upload_list .= "<div id='hide$i'><img id='wrapper' src='ext/upload/minus.png' />" .
"<a href='javascript:document.getElementById(&quot;row$a&quot;).style.display = &quot;&quot;;javascript:document.getElementById(&quot;hide$i&quot;).style.display = &quot;none&quot;;javascript:document.getElementById(&quot;hide$a&quot;).style.display = &quot;&quot;;'>".
"<a href='#' onclick='javascript:document.getElementById(&quot;row$a&quot;).style.display = &quot;&quot;;document.getElementById(&quot;hide$i&quot;).style.display = &quot;none&quot;;document.getElementById(&quot;hide$a&quot;).style.display = &quot;&quot;;'>".
"<img src='ext/upload/plus.png'></a></div></td>";
}else{
$upload_list .="<div id='hide$i'>
<a href='javascript:document.getElementById(&quot;row$i&quot;).style.display = &quot;none&quot;;".
<a href='#' onclick='javascript:document.getElementById(&quot;row$i&quot;).style.display = &quot;none&quot;;".
"document.getElementById(&quot;hide$i&quot;).style.display = &quot;none&quot;;".
"document.getElementById(&quot;hide$s&quot;).style.display = &quot;&quot;;".
"document.getElementById(&quot;data$i&quot;).value = &quot;&quot;;".
@ -41,7 +41,7 @@ class UploadTheme extends Themelet {
$upload_list .="<img id='wrapper' src='ext/upload/plus.png' />";
}else{
$upload_list .=
"<a href='javascript:document.getElementById(&quot;row$a&quot;).style.display = &quot;&quot;;".
"<a href='#' onclick='javascript:document.getElementById(&quot;row$a&quot;).style.display = &quot;&quot;;".
"document.getElementById(&quot;hide$i&quot;).style.display = &quot;none&quot;;".
"document.getElementById(&quot;hide$a&quot;).style.display = &quot;&quot;;'>".
"<img src='ext/upload/plus.png' /></a>";
@ -113,15 +113,31 @@ class UploadTheme extends Themelet {
{
/* Danbooru > Shimmie Bookmarklet.
This "should" work on any site running danbooru, unless for some odd reason they switched around the id's or aren't using post/list.
Most likely this will stop working when Danbooru updates to v2, all depends if they switch the ids or not >_>.
Clicking the link on a danbooru image page should give you something along the lines of:
'http://www.website.com/shimmie/upload?url="http://sonohara.donmai.us/data/crazylongurl.jpg&tags="too many tags"&rating="s"&source="http://danbooru.donmai.us/post/show/012345/"'
TODO: Possibly make the entire/most of the script into a .js file, and just make the bookmarklet load it on click (Something like that?)
*/
$title = "Danbooru to " . $config->get_string('title');
$html .= '<p><a href="javascript:var img=document.getElementById(&quot;highres&quot;).href;var ste=&quot;' .
$link . $delimiter . 'url=&quot;;var tag=document.getElementById(&quot;post_old_tags&quot;).value;var doc=document.documentElement.innerHTML;var rtg=doc.match(&quot;<li>Rating: (.*)<\/li>&quot;);var srx=&quot;http://&quot; + document.location.hostname + document.location.href.match(&quot;\/post\/show\/.*\/&quot;);' .
'if (confirm(&quot;OK = Use Current tags.\nCancel = Use new tags.&quot;)==true)' .
'{if(tag.search(/\bflash\b/)==-1){location.href=ste+img+&quot;&amp;tags=&quot;+tag+&quot;&rating=&quot;+rtg[1]+&quot;&amp;source=&quot;+srx;}else{location.href=ste+document.getElementsByName(&quot;movie&quot;)[0].value' .
'+&quot;&amp;tags=&quot;+tag+&quot;&amp;rating=&quot;+rtg[1]+&quot;&amp;source=&quot;+srx;}}else{var p=prompt(&quot;Enter Tags&quot;,&quot;&quot;);if(tag.search(/\bflash\b/)==-1){location.href=ste+img+&quot;&amp;tags=&quot;+p+&quot;&amp;rating=&quot;+rtg[1]+&quot;&amp;source=&quot;+srx;}' .
'else{location.href=ste+document.getElementsByName(&quot;movie&quot;)[0].value+&quot;&amp;tags=&quot;+p+&quot;&amp;rating=&quot;+rtg[1]+&quot;&amp;source=&quot;+srx;}}">' .
$title . '</a> (As above, Click on a Danbooru-run image page. (This also grabs the tags, rating & source!))';
$html .= '<p><a href="javascript:'.
/* This should stop the bookmarklet being insanely long...not that it's already huge or anything. */
'var ste=&quot;'. $link . $delimiter .'url=&quot;;var tag=document.getElementById(&quot;post_tags&quot;).value;var rtg=document.documentElement.innerHTML.match(&quot;<li>Rating: (.*)<\/li>&quot;);var srx=&quot;http://&quot; + document.location.hostname+document.location.href.match(&quot;\/post\/show\/.*\/&quot;);' .
//The default confirm sucks, mainly due to being unable to change the text in the Ok/Cancel box (Yes/No would be better.)
'if (confirm(&quot;OK = Use Current tags.\nCancel = Use new tags.&quot;)==true){' . //Just incase some people don't want the insane amount of tags danbooru has.
//The flash check is kind of picky, although it should work on "most" images..there will be either some old or extremely new ones that lack the flash tag.
'if(tag.search(/\bflash\b/)==-1){'.
'location.href=ste+document.getElementById(&quot;highres&quot;).href+&quot;&amp;tags=&quot;+tag+&quot;&amp;rating=&quot;+rtg[1]+&quot;&amp;source=&quot;+srx;}'.
'else{'.
'location.href=ste+document.getElementsByName(&quot;movie&quot;)[0].value+&quot;&amp;tags=&quot;+tag+&quot;&amp;rating=&quot;+rtg[1]+&quot;&amp;source=&quot;+srx;}'.
//The following is more or less the same as above, instead using the tags on danbooru, should load a prompt box instead.
'}else{'.
'var p=prompt(&quot;Enter Tags&quot;,&quot;&quot;);'.
'if(tag.search(/\bflash\b/)==-1){'.
'location.href=ste+document.getElementById(&quot;highres&quot;).href+&quot;&amp;tags=&quot;+p+&quot;&amp;rating=&quot;+rtg[1]+&quot;&amp;source=&quot;+srx;}' .
'else{'.
'location.href=ste+document.getElementsByName(&quot;movie&quot;)[0].value+&quot;&amp;tags=&quot;+p+&quot;&amp;rating=&quot;+rtg[1]+&quot;&amp;source=&quot;+srx;}'.
'}">' .
$title . '</a> (As above, Click on a Danbooru-run image page. (This also grabs the tags/rating/source!))';
}

View File

@ -166,8 +166,8 @@ class UserPage extends SimpleExtension {
public function onUserPageBuilding(Event $event) {
global $page, $user, $config;
$h_join_date = html_escape($event->display_user->join_date);
$event->add_stats("Join date: $h_join_date", 10);
$h_join_date = autodate($event->display_user->join_date);
$event->add_stats("Joined: $h_join_date", 10);
$av = $event->display_user->get_avatar_html();
if($av) $event->add_stats($av, 0);

146
lib/jquery.timeago.js Normal file
View File

@ -0,0 +1,146 @@
/**
* Timeago is a jQuery plugin that makes it easy to support automatically
* updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
*
* @name timeago
* @version 0.10.0
* @requires jQuery v1.2.3+
* @author Ryan McGeary
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
*
* For usage and examples, visit:
* http://timeago.yarp.com/
*
* Copyright (c) 2008-2011, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
*/
(function($) {
$.timeago = function(timestamp) {
if (timestamp instanceof Date) {
return inWords(timestamp);
} else if (typeof timestamp === "string") {
return inWords($.timeago.parse(timestamp));
} else {
return inWords($.timeago.datetime(timestamp));
}
};
var $t = $.timeago;
$.extend($.timeago, {
settings: {
refreshMillis: 60000,
allowFuture: false,
strings: {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "ago",
suffixFromNow: "from now",
seconds: "less than a minute",
minute: "about a minute",
minutes: "%d minutes",
hour: "about an hour",
hours: "about %d hours",
day: "a day",
days: "%d days",
month: "about a month",
months: "%d months",
year: "about a year",
years: "%d years",
numbers: []
}
},
inWords: function(distanceMillis) {
var $l = this.settings.strings;
var prefix = $l.prefixAgo;
var suffix = $l.suffixAgo;
if (this.settings.allowFuture) {
if (distanceMillis < 0) {
prefix = $l.prefixFromNow;
suffix = $l.suffixFromNow;
}
}
var seconds = Math.abs(distanceMillis) / 1000;
var minutes = seconds / 60;
var hours = minutes / 60;
var days = hours / 24;
var years = days / 365;
function substitute(stringOrFunction, number) {
var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
var value = ($l.numbers && $l.numbers[number]) || number;
return string.replace(/%d/i, value);
}
var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
seconds < 90 && substitute($l.minute, 1) ||
minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
minutes < 90 && substitute($l.hour, 1) ||
hours < 24 && substitute($l.hours, Math.round(hours)) ||
hours < 48 && substitute($l.day, 1) ||
days < 30 && substitute($l.days, Math.floor(days)) ||
days < 60 && substitute($l.month, 1) ||
days < 365 && substitute($l.months, Math.floor(days / 30)) ||
years < 2 && substitute($l.year, 1) ||
substitute($l.years, Math.floor(years));
return $.trim([prefix, words, suffix].join(" "));
},
parse: function(iso8601) {
var s = $.trim(iso8601);
s = s.replace(/\.\d\d\d+/,""); // remove milliseconds
s = s.replace(/-/,"/").replace(/-/,"/");
s = s.replace(/T/," ").replace(/Z/," UTC");
s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
return new Date(s);
},
datetime: function(elem) {
// jQuery's `is()` doesn't play well with HTML5 in IE
var isTime = $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time");
var iso8601 = isTime ? $(elem).attr("datetime") : $(elem).attr("title");
return $t.parse(iso8601);
}
});
$.fn.timeago = function() {
var self = this;
self.each(refresh);
var $s = $t.settings;
if ($s.refreshMillis > 0) {
setInterval(function() { self.each(refresh); }, $s.refreshMillis);
}
return self;
};
function refresh() {
var data = prepareData(this);
if (!isNaN(data.datetime)) {
$(this).text(inWords(data.datetime));
}
return this;
}
function prepareData(element) {
element = $(element);
if (!element.data("timeago")) {
element.data("timeago", { datetime: $t.datetime(element) });
var text = $.trim(element.text());
if (text.length > 0) {
element.attr("title", text);
}
}
return element.data("timeago");
}
function inWords(date) {
return $t.inWords(distance(date));
}
function distance(date) {
return (new Date().getTime() - date.getTime());
}
// fix for IE6 suckage
document.createElement("abbr");
document.createElement("time");
}(jQuery));

View File

@ -26,6 +26,7 @@ $(document).ready(function() {
$confirm.dialog('open');
});
$("time").timeago();
});
var defaultTexts = new Array();

View File

@ -88,7 +88,7 @@ class Layout {
$debug = get_debug_info();
$contact = empty($contact_link) ? "" : "<br><a href='$contact_link'>Contact</a>";
$contact = empty($contact_link) ? "" : "<br><a href='mailto:$contact_link'>Contact</a>";
if(empty($this->subheading)) {
$subheading = "";

View File

@ -6,7 +6,7 @@ class CustomViewImageTheme extends ViewImageTheme {
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
$page->set_heading(html_escape($image->get_tag_list()));
$page->add_block(new Block("Navigation", $this->build_navigation($image), "left", 0));
$page->add_block(new Block("Statistics", $this->build_stats($image), "left", 10));
$page->add_block(new Block("Statistics", $this->build_stats($image), "left", 15));
$page->add_block(new Block(null, $this->build_image_editor($image, $editor_parts), "main", 10));
$page->add_block(new Block(null, $this->build_pin($image), "main", 11));
}

View File

@ -42,7 +42,7 @@ class Layout {
$debug = get_debug_info();
$contact = empty($contact_link) ? "" : "<br><a href='$contact_link'>Contact</a>";
$contact = empty($contact_link) ? "" : "<br><a href='mailto:$contact_link'>Contact</a>";
$wrapper = "";
if(strlen($page->heading) > 100) {

View File

@ -128,6 +128,10 @@ UL {
.comment {
text-align: left;
}
.comment .timeago {
float: right;
font-size: 75%;
}
.more:after {
content: " >>>";

View File

@ -42,7 +42,7 @@ class Layout {
$debug = get_debug_info();
$contact = empty($contact_link) ? "" : "<br><a href='$contact_link'>Contact</a>";
$contact = empty($contact_link) ? "" : "<br><a href='mailto:$contact_link'>Contact</a>";
$subheading = empty($page->subheading) ? "" : "<div id='subtitle'>{$page->subheading}</div>";
$wrapper = "";

View File

@ -37,7 +37,7 @@ class Layout {
$debug = get_debug_info();
$contact = empty($contact_link) ? "" : "<br><a href='$contact_link'>Contact</a>";
$contact = empty($contact_link) ? "" : "<br><a href='mailto:$contact_link'>Contact</a>";
if(empty($page->subheading)) {
$subheading = "";

View File

@ -138,7 +138,7 @@ class Layout {
$debug = get_debug_info();
$contact = empty($contact_link) ? "" : "<br><a href='$contact_link'>Contact</a>";
$contact = empty($contact_link) ? "" : "<br><a href='mailto:$contact_link'>Contact</a>";
$subheading = empty($page->subheading) ? "" : "<div id='subtitle'>{$page->subheading}</div>";
$wrapper = "";

View File

@ -3,6 +3,7 @@
class CustomViewImageTheme extends ViewImageTheme {
public function display_page($image, $editor_parts) {
global $page;
$metatags = str_replace(" ", ", ", html_escape($image->get_tag_list()));
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
$page->set_heading(html_escape($image->get_tag_list()));
$page->add_html_header("<meta name=\"keywords\" content=\"$metatags\">");
@ -11,7 +12,7 @@ class CustomViewImageTheme extends ViewImageTheme {
$page->add_html_header("<meta property=\"og:image\" content=\"".make_http($image->get_thumb_link())."\">");
$page->add_html_header("<meta property=\"og:url\" content=\"".make_http(make_link("post/view/{$image->id}"))."\">");
$page->add_block(new Block("Navigation", $this->build_navigation($image), "left", 0));
$page->add_block(new Block("Statistics", $this->build_stats($image), "left", 10));
$page->add_block(new Block("Statistics", $this->build_stats($image), "left", 15));
$page->add_block(new Block(null, $this->build_image_editor($image, $editor_parts), "main", 10));
$page->add_block(new Block(null, $this->build_pin($image), "main", 11));
}

View File

@ -37,7 +37,7 @@ class Layout {
$debug = get_debug_info();
$contact = empty($contact_link) ? "" : "<br><a href='$contact_link'>Contact</a>";
$contact = empty($contact_link) ? "" : "<br><a href='mailto:$contact_link'>Contact</a>";
$subheading = empty($page->subheading) ? "" : "<div id='subtitle'>{$page->subheading}</div>";
$wrapper = "";

View File

@ -47,7 +47,7 @@ class Layout {
$debug = get_debug_info();
$contact = empty($contact_link) ? "" : "<br><a href='$contact_link'>Contact</a>";
$contact = empty($contact_link) ? "" : "<br><a href='mailto:$contact_link'>Contact</a>";
$subheading = empty($page->subheading) ? "" : "<div id='subtitle'>{$page->subheading}</div>";
$wrapper = "";