these don't work either
This commit is contained in:
parent
ce91cde9c7
commit
6870a0d145
@ -1,84 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Name: Subversion Updater
|
|
||||||
* Author: Shish <webmaster@shishnet.org>
|
|
||||||
* License: GPLv2
|
|
||||||
* Description: Provides a button to check for updates
|
|
||||||
* Documentation:
|
|
||||||
* This is a very risky idea, implemented without safeguards.
|
|
||||||
* If you've done a clean SVN checkout, then updating will
|
|
||||||
* normally work fine; but if you've made changes in one way,
|
|
||||||
* and SVN has changed something in a different way, then there
|
|
||||||
* will be conflicts and the site will die :(
|
|
||||||
*/
|
|
||||||
|
|
||||||
class SVNUpdate implements Extension {
|
|
||||||
var $theme;
|
|
||||||
|
|
||||||
public function receive_event(Event $event) {
|
|
||||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
|
||||||
|
|
||||||
if(($event instanceof PageRequestEvent) && $event->page_matches("update")) {
|
|
||||||
if($event->user->is_admin()) {
|
|
||||||
if($event->get_arg(0) == "view_changes") {
|
|
||||||
$this->theme->display_update_todo($event->page,
|
|
||||||
$this->get_update_log(),
|
|
||||||
$this->get_branches());
|
|
||||||
}
|
|
||||||
if($event->get_arg(0) == "update") {
|
|
||||||
$this->theme->display_update_log($event->page, $this->run_update());
|
|
||||||
}
|
|
||||||
if($event->get_arg(0) == "dump") {
|
|
||||||
$this->theme->display_update_log($event->page, $this->run_dump());
|
|
||||||
}
|
|
||||||
//if($event->get_arg(0) == "switch") {
|
|
||||||
// $this->theme->display_update_log($event->page, $this->run_update());
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($event instanceof AdminBuildingEvent) {
|
|
||||||
global $page;
|
|
||||||
$this->theme->display_form($page);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function get_update_log() {
|
|
||||||
return shell_exec("svn log -r HEAD:BASE .");
|
|
||||||
}
|
|
||||||
private function run_update() {
|
|
||||||
return shell_exec("svn update");
|
|
||||||
}
|
|
||||||
private function run_dump() {
|
|
||||||
global $database_dsn;
|
|
||||||
$matches = array();
|
|
||||||
|
|
||||||
// FIXME: MySQL specific
|
|
||||||
if(preg_match("#^mysql://([^:]+):([^@]+)@([^/]+)/([^\?]+)#", $database_dsn, $matches)) {
|
|
||||||
$date = date("Ymd");
|
|
||||||
return
|
|
||||||
shell_exec("mysqldump -uUSER -pPASS -hHOST DATABASE | gzip > db-$date.sql.gz") .
|
|
||||||
"\n\nDatabase dump should now be sitting in db-$date.sql.gz in the shimmie folder";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return "Couldn't parse database connection string";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private function get_branches() {
|
|
||||||
$data = shell_exec("svn ls http://svn.shishnet.org/shimmie2/branches/");
|
|
||||||
$list = array();
|
|
||||||
foreach(split("\n", $data) as $line) {
|
|
||||||
$matches = array();
|
|
||||||
if(preg_match("/branch_(\d.\d+)/", $line, $matches)) {
|
|
||||||
$ver = $matches[1];
|
|
||||||
$list["branch_$ver"] = "Stable ($ver.X)";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ksort($list);
|
|
||||||
$list = array_reverse($list, true);
|
|
||||||
$list["trunk"] = "Unstable (Trunk)";
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add_event_listener(new SVNUpdate());
|
|
||||||
?>
|
|
@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class SVNUpdateTheme extends Themelet {
|
|
||||||
public function display_form(Page $page) {
|
|
||||||
$html = "
|
|
||||||
<a href='".make_link("update/view_changes")."'>Check for Updates</a>
|
|
||||||
";
|
|
||||||
$page->add_block(new Block("Update", $html));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function display_update_todo(Page $page, $log, $branches) {
|
|
||||||
$h_log = html_escape($log);
|
|
||||||
$updates = "
|
|
||||||
<textarea rows='20' cols='80'>$h_log</textarea>
|
|
||||||
<br/>
|
|
||||||
<form action='".make_link("update/update")."' method='POST'>
|
|
||||||
<input type='submit' value='Install Updates'>
|
|
||||||
</form>
|
|
||||||
";
|
|
||||||
$options = "";
|
|
||||||
foreach($branches as $name => $nice) {
|
|
||||||
$options .= "<option value='$name'>$nice</option>";
|
|
||||||
}
|
|
||||||
$branches = "
|
|
||||||
<form action='".make_link("update/switch")."' method='POST'>
|
|
||||||
<select name='branch'>
|
|
||||||
$options
|
|
||||||
</select>
|
|
||||||
<input type='submit' value='Change Branch'>
|
|
||||||
</form>
|
|
||||||
";
|
|
||||||
|
|
||||||
$page->set_title("Updates Available");
|
|
||||||
$page->set_heading("Updates Available");
|
|
||||||
$page->add_block(new NavBlock());
|
|
||||||
$page->add_block(new Block("Updates For Current Branch", $updates));
|
|
||||||
$page->add_block(new Block("Available Branches", $branches));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function display_update_log(Page $page, $log) {
|
|
||||||
$h_log = html_escape($log);
|
|
||||||
$html = "
|
|
||||||
<textarea rows='20' cols='80'>$h_log</textarea>
|
|
||||||
";
|
|
||||||
|
|
||||||
$page->set_title("Update Log");
|
|
||||||
$page->set_heading("Update Log");
|
|
||||||
$page->add_block(new NavBlock());
|
|
||||||
$page->add_block(new Block("Update Log", $html));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,109 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Name: Image Scores (Text)
|
|
||||||
* Author: Shish <webmaster@shishnet.org>
|
|
||||||
* License: GPLv2
|
|
||||||
* Description: Allow users to score images
|
|
||||||
* Documentation:
|
|
||||||
* Similar to the Image Scores (Numeric) extension, but this one
|
|
||||||
* uses an average rather than the sum of all votes, which means
|
|
||||||
* that the score will be [-2 .. +2], and each integer in that
|
|
||||||
* range has a label attached.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class TextScoreSetEvent extends Event {
|
|
||||||
var $image_id, $user, $score;
|
|
||||||
|
|
||||||
public function TextScoreSetEvent($image_id, $user, $score) {
|
|
||||||
$this->image_id = $image_id;
|
|
||||||
$this->user = $user;
|
|
||||||
$this->score = $score;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TextScore implements Extension {
|
|
||||||
var $theme;
|
|
||||||
|
|
||||||
public function receive_event(Event $event) {
|
|
||||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
|
||||||
|
|
||||||
if(($event instanceof InitExtEvent)) {
|
|
||||||
global $config;
|
|
||||||
if($config->get_int("ext_text_score_version", 0) < 1) {
|
|
||||||
$this->install();
|
|
||||||
}
|
|
||||||
$config->set_default_bool("text_score_anon", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(($event instanceof ImageInfoBoxBuildingEvent)) {
|
|
||||||
global $user;
|
|
||||||
global $config;
|
|
||||||
if(!$user->is_anonymous() || $config->get_bool("text_score_anon")) {
|
|
||||||
$event->add_part($this->theme->get_scorer_html($event->image));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($event instanceof ImageInfoSetEvent) {
|
|
||||||
global $user;
|
|
||||||
$i_score = int_escape($_POST['text_score__score']);
|
|
||||||
|
|
||||||
if($i_score >= -2 || $i_score <= 2) {
|
|
||||||
send_event(new TextScoreSetEvent($event->image->id, $user, $i_score));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(($event instanceof TextScoreSetEvent)) {
|
|
||||||
if(!$event->user->is_anonymous() || $config->get_bool("text_score_anon")) {
|
|
||||||
$this->add_vote($event->image_id, $event->user->id, $event->score);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(($event instanceof ImageDeletionEvent)) {
|
|
||||||
global $database;
|
|
||||||
$database->execute("DELETE FROM text_score_votes WHERE image_id=?", array($event->image->id));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(($event instanceof SetupBuildingEvent)) {
|
|
||||||
$sb = new SetupBlock("Text Score");
|
|
||||||
$sb->add_bool_option("text_score_anon", "Allow anonymous votes: ");
|
|
||||||
$event->panel->add_block($sb);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(($event instanceof ParseLinkTemplateEvent)) {
|
|
||||||
$event->replace('$text_score', $this->theme->score_to_name($event->image->text_score));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function install() {
|
|
||||||
global $database;
|
|
||||||
global $config;
|
|
||||||
|
|
||||||
if($config->get_int("ext_text_score_version") < 1) {
|
|
||||||
$database->Execute("ALTER TABLE images ADD COLUMN text_score INTEGER NOT NULL DEFAULT 0");
|
|
||||||
$database->Execute("CREATE INDEX images__text_score ON images(text_score)");
|
|
||||||
$database->create_table("text_score_votes", "
|
|
||||||
image_id INTEGER NOT NULL,
|
|
||||||
user_id INTEGER NOT NULL,
|
|
||||||
score INTEGER NOT NULL,
|
|
||||||
UNIQUE(image_id, user_id),
|
|
||||||
INDEX(image_id),
|
|
||||||
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
|
|
||||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
||||||
");
|
|
||||||
$config->set_int("ext_text_score_version", 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function add_vote($image_id, $user_id, $score) {
|
|
||||||
global $database;
|
|
||||||
// TODO: update if already voted
|
|
||||||
$database->Execute(
|
|
||||||
"REPLACE INTO text_score_votes(image_id, user_id, score) VALUES(?, ?, ?)",
|
|
||||||
array($image_id, $user_id, $score));
|
|
||||||
$database->Execute(
|
|
||||||
"UPDATE images SET text_score=(SELECT AVG(score) FROM text_score_votes WHERE image_id=?) WHERE id=?",
|
|
||||||
array($image_id, $image_id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add_event_listener(new TextScore());
|
|
||||||
?>
|
|
@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class TextScoreTheme extends Themelet {
|
|
||||||
public function get_scorer_html(Image $image) {
|
|
||||||
$i_image_id = int_escape($image->id);
|
|
||||||
|
|
||||||
$s_score = $this->score_to_name($image->text_score);
|
|
||||||
$html = "
|
|
||||||
Current score is \"$s_score\"
|
|
||||||
<br/>
|
|
||||||
<input type='hidden' name='image_id' value='$i_image_id' />
|
|
||||||
<input type='radio' name='text_score__score' value='-2' id='-2'><label for='-2'>Delete</label>
|
|
||||||
<input type='radio' name='text_score__score' value='-1' id='-1'><label for='-1'>Bad</label>
|
|
||||||
<input type='radio' name='text_score__score' value='0' id='0' ><label for='0' >Ok</label>
|
|
||||||
<input type='radio' name='text_score__score' value='1' id='1' ><label for='1' >Good</label>
|
|
||||||
<input type='radio' name='text_score__score' value='2' id='2' ><label for='2' >Favourite</label>
|
|
||||||
";
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function score_to_name($score) {
|
|
||||||
$words = array();
|
|
||||||
$words[-2] = "Delete";
|
|
||||||
$words[-1] = "Bad";
|
|
||||||
$words[ 0] = "Ok";
|
|
||||||
$words[ 1] = "Good";
|
|
||||||
$words[ 2] = "Favourite";
|
|
||||||
$s_score = $words[$score];
|
|
||||||
return $s_score;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
Loading…
x
Reference in New Issue
Block a user