apply cleanups to 2.2

git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.2@807 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2008-04-11 05:47:16 +00:00
parent 7e92bdbd8e
commit 1fd2fe084b
24 changed files with 210 additions and 95 deletions

View File

@ -1,69 +0,0 @@
<?php
/**
* Name: Misc Admin Utils
* Author: Shish <webmaster@shishnet.org>
* Link: http://trac.shishnet.org/shimmie2/
* License: GPLv2
* Description: Various non-essential utilities
*/
class AdminUtils extends Extension {
var $theme;
public function receive_event($event) {
if(is_null($this->theme)) $this->theme = get_theme_object("admin_utils", "AdminUtilsTheme");
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "admin_utils")) {
if($event->user->is_admin()) {
set_time_limit(0);
switch($_POST['action']) {
case 'lowercase all tags':
$this->lowercase_all_tags();
break;
case 'recount tag use':
$this->recount_tag_use();
break;
case 'purge unused tags':
$this->purge_unused_tags();
break;
}
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("admin"));
}
}
if(is_a($event, 'AdminBuildingEvent')) {
global $page;
$this->theme->display_form($page);
}
}
private function lowercase_all_tags() {
global $database;
$database->execute("UPDATE tags SET tag=lower(tag)");
}
private function recount_tag_use() {
global $database;
$database->Execute("UPDATE tags SET count=(SELECT COUNT(image_id) FROM image_tags WHERE tag_id=tags.id GROUP BY tag_id)");
}
private function purge_unused_tags() {
global $database;
$this->recount_tag_use();
$database->Execute("DELETE FROM tags WHERE count=0");
}
private function check_for_orphanned_images() {
$orphans = array();
foreach(glob("images/*") as $dir) {
foreach(glob("$dir/*") as $file) {
$hash = str_replace("$dir/", "", $file);
if(!$this->db_has_hash($hash)) {
$orphans[] = $hash;
}
}
}
}
}
add_event_listener(new AdminUtils());
?>

View File

@ -1,24 +0,0 @@
<?php
class AdminUtilsTheme extends Themelet {
/*
* Show a form which links to admin_utils with POST[action] set to one of:
* 'lowercase all tags'
* 'recount tag use'
* 'purge unused tags'
*/
public function display_form($page) {
$html = "
<p><form action='".make_link("admin_utils")."' method='POST'>
<select name='action'>
<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>
</select>
<input type='submit' value='Go'>
</form>
";
$page->add_block(new Block("Misc Admin Tools", $html));
}
}
?>

View File

@ -5,8 +5,8 @@
<field name="id" type="I"><key/><autoincrement/></field>
<field name="banner_id" type="I"><notnull/></field>
<field name="ip" type="C" size="20"><notnull/></field>
<field name="date" type="T"><notnull/></field>
<field name="end" type="T"><notnull/></field>
<field name="date" type="D"><notnull/></field>
<field name="end" type="D"><notnull/></field>
<field name="reason" type="C" size="255"><notnull/></field>
<index name="bans__ip"><col>ip</col></index>
<opt platform="mysql">DEFAULT CHARSET='utf8'</opt>

View File

@ -40,6 +40,27 @@ class AdminPage extends Extension {
}
}
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "admin_utils")) {
if($event->user->is_admin()) {
set_time_limit(0);
switch($_POST['action']) {
case 'lowercase all tags':
$this->lowercase_all_tags();
break;
case 'recount tag use':
$this->recount_tag_use();
break;
case 'purge unused tags':
$this->purge_unused_tags();
break;
}
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("admin"));
}
}
if(is_a($event, 'DisplayingImageEvent')) {
global $user;
if($user->is_admin()) {
@ -49,6 +70,7 @@ class AdminPage extends Extension {
if(is_a($event, 'AdminBuildingEvent')) {
$this->theme->display_page($event->page);
$this->theme->display_form($event->page);
}
if(is_a($event, 'UserBlockBuildingEvent')) {
@ -57,6 +79,34 @@ class AdminPage extends Extension {
}
}
}
private function lowercase_all_tags() {
global $database;
$database->execute("UPDATE tags SET tag=lower(tag)");
}
private function recount_tag_use() {
global $database;
$database->Execute("UPDATE tags SET count=(SELECT COUNT(image_id) FROM image_tags WHERE tag_id=tags.id GROUP BY tag_id)");
}
private function purge_unused_tags() {
global $database;
$this->recount_tag_use();
$database->Execute("DELETE FROM tags WHERE count=0");
}
private function check_for_orphanned_images() {
$orphans = array();
foreach(glob("images/*") as $dir) {
foreach(glob("$dir/*") as $file) {
$hash = str_replace("$dir/", "", $file);
if(!$this->db_has_hash($hash)) {
$orphans[] = $hash;
}
}
}
}
}
add_event_listener(new AdminPage());
?>

View File

@ -25,5 +25,25 @@ class AdminPageTheme extends Themelet {
";
$page->add_block(new Block("Admin", $html, "left"));
}
/*
* Show a form which links to admin_utils with POST[action] set to one of:
* 'lowercase all tags'
* 'recount tag use'
* 'purge unused tags'
*/
public function display_form($page) {
$html = "
<p><form action='".make_link("admin_utils")."' method='POST'>
<select name='action'>
<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>
</select>
<input type='submit' value='Go'>
</form>
";
$page->add_block(new Block("Misc Admin Tools", $html));
}
}
?>

View File

@ -126,6 +126,7 @@ class Layout {
<link rel="stylesheet" href="$data_href/themes/$theme_name/style.css" type="text/css">
$header_html
<script src='$data_href/themes/$theme_name/sidebar.js' type='text/javascript'></script>
<script src='$data_href/themes/$theme_name/script.js' type='text/javascript'></script>
</head>
<body>

View File

@ -50,6 +50,7 @@ class Layout {
<link rel="stylesheet" href="$data_href/themes/$theme_name/style.css" type="text/css">
$header_html
<script src='$data_href/themes/$theme_name/sidebar.js' type='text/javascript'></script>
<script src='$data_href/themes/$theme_name/script.js' type='text/javascript'></script>
</head>
<body>

136
themes/default/script.js Normal file
View File

@ -0,0 +1,136 @@
var defaultTexts = new Array();
window.onload = function(e) {
var sections=get_sections();
for(var i=0;i<sections.length;i++) toggle(sections[i]);
initGray("search_input", "Search");
initGray("commentBox", "Comment");
initGray("tagBox", "tagme");
// if we're going to show with JS, hide with JS first
pass_confirm = byId("pass_confirm");
if(pass_confirm) {
pass_confirm.style.display = "none";
}
}
function initGray(boxname, text) {
var box = byId(boxname);
if(!box) return;
var clr = function () {cleargray(box, text);};
var set = function () {setgray(box, text);};
addEvent(box, "focus", clr, false);
addEvent(box, "blur", set, false);
if(box.value == text) {
box.style.color = "#999";
box.style.textAlign = "center";
}
else {
box.style.color = "#000";
box.style.textAlign = "left";
}
}
function cleargray(box, text) {
if(box.value == text) {
box.value = "";
box.style.color = "#000";
box.style.textAlign = "left";
}
}
function setgray(box, text) {
if(box.value == "") {
box.style.textAlign = "center";
box.style.color = "gray";
box.value = text;
}
}
function showUp(elem) {
e = document.getElementById(elem)
if(!e) return;
e.style.display = "";
// alert(e.type+": "+e.value);
if(e.value.match(/^http|^ftp/)) {
e.type = "text";
alert("Box is web upload");
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* LibShish-JS *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
function addEvent(obj, event, func, capture){
if (obj.addEventListener){
obj.addEventListener(event, func, capture);
} else if (obj.attachEvent){
obj.attachEvent("on"+event, func);
}
}
function byId(id) {
return document.getElementById(id);
}
function getHTTPObject() {
if (window.XMLHttpRequest){
return new XMLHttpRequest();
}
else if(window.ActiveXObject){
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function ajaxRequest(url, callback) {
var http = getHTTPObject();
http.open("GET", url, true);
http.onreadystatechange = function() {
if(http.readyState == 4) callback(http.responseText);
}
http.send(null);
}
/* get, set, and delete cookies */
function getCookie( name ) {
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
function setCookie( name, value, expires, path, domain, secure ) {
var today = new Date();
today.setTime( today.getTime() );
if ( expires ) {
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name+"="+escape( value ) +
( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
function deleteCookie( name, path, domain ) {
if ( getCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}