marge admin utils into admin
git-svn-id: file:///home/shish/svn/shimmie2/trunk@804 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
ff199a7c63
commit
59a0979d7f
@ -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());
|
|
||||||
?>
|
|
@ -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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -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')) {
|
if(is_a($event, 'DisplayingImageEvent')) {
|
||||||
global $user;
|
global $user;
|
||||||
if($user->is_admin()) {
|
if($user->is_admin()) {
|
||||||
@ -49,6 +70,7 @@ class AdminPage extends Extension {
|
|||||||
|
|
||||||
if(is_a($event, 'AdminBuildingEvent')) {
|
if(is_a($event, 'AdminBuildingEvent')) {
|
||||||
$this->theme->display_page($event->page);
|
$this->theme->display_page($event->page);
|
||||||
|
$this->theme->display_form($event->page);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_a($event, 'UserBlockBuildingEvent')) {
|
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());
|
add_event_listener(new AdminPage());
|
||||||
?>
|
?>
|
||||||
|
@ -25,5 +25,25 @@ class AdminPageTheme extends Themelet {
|
|||||||
";
|
";
|
||||||
$page->add_block(new Block("Admin", $html, "left"));
|
$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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user