semi-automagic niceurls?

This commit is contained in:
Shish 2008-12-27 02:17:53 -08:00
parent 6f499ad940
commit 1d7578f052
4 changed files with 73 additions and 10 deletions

View File

@ -148,7 +148,16 @@ class Image {
}
public function get_image_link() {
return $this->parse_link_template($this->config->get_string('image_ilink'));
$c = $this->config;
if(strlen($c->get_string('image_ilink')) > 0) {
return $this->parse_link_template($c->get_string('image_ilink'));
}
else if($c->get_bool('nice_urls', false)) {
return $this->parse_link_template('$base/_images/$hash/$id - $tags.$ext');
}
else {
return $this->parse_link_template('image/$id.$ext');
}
}
public function get_short_link() {
@ -156,7 +165,16 @@ class Image {
}
public function get_thumb_link() {
return $this->parse_link_template($this->config->get_string('image_tlink'));
$c = $this->config;
if(strlen($c->get_string('image_tlink')) > 0) {
return $this->parse_link_template($c->get_string('image_tlink'));
}
else if($c->get_bool('nice_urls', false)) {
return $this->parse_link_template('$base/_thumbs/$hash/$id.jpg');
}
else {
return $this->parse_link_template('image/$id.$ext');
}
}
public function get_tooltip() {

View File

@ -97,7 +97,13 @@ function make_link($page=null, $query=null) {
if(is_null($page)) $page = $config->get_string('main_page');
$base = $config->get_string('base_href');
if($config->get_bool('nice_urls', false)) {
$full = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"];
$base = str_replace("/index.php", "", $full);
}
else {
$base = "./index.php?q=";
}
if(is_null($query)) {
return "$base/$page";

View File

@ -11,10 +11,10 @@ class ImageIO implements Extension {
$config->set_default_int('thumb_width', 192);
$config->set_default_int('thumb_height', 192);
$config->set_default_int('thumb_quality', 75);
$config->set_default_int('thumb_mem_limit', '8MB');
$config->set_default_int('thumb_mem_limit', parse_shorthand_int('8MB'));
$config->set_default_string('image_ilink', '$base/image/$id.$ext');
$config->set_default_string('image_tlink', '$base/thumb/$id.jpg');
$config->set_default_string('image_ilink', '');
$config->set_default_string('image_tlink', '');
$config->set_default_string('image_tip', '$tags // $size // $filesize');
$config->set_default_string('upload_collision_handler', 'error');
}
@ -46,9 +46,10 @@ class ImageIO implements Extension {
if($event instanceof SetupBuildingEvent) {
$sb = new SetupBlock("Image Options");
$sb->position = 30;
$sb->add_text_option("image_ilink", "Image link: ");
$sb->add_text_option("image_tlink", "<br>Thumbnail link: ");
$sb->add_text_option("image_tip", "<br>Image tooltip: ");
// advanced only
//$sb->add_text_option("image_ilink", "Image link: ");
//$sb->add_text_option("image_tlink", "<br>Thumbnail link: ");
$sb->add_text_option("image_tip", "Image tooltip: ");
$sb->add_choice_option("upload_collision_handler", array('Error'=>'error', 'Merge'=>'merge'), "<br>Upload collision handler: ");
$event->panel->add_block($sb);

View File

@ -137,6 +137,11 @@ class Setup implements Extension {
$config->set_default_string("theme", "default");
}
if(($event instanceof PageRequestEvent) && $event->page_matches("nicetest")) {
$event->page->set_mode("data");
$event->page->set_data("ok");
}
if(($event instanceof PageRequestEvent) && $event->page_matches("setup")) {
global $user;
if(!$user->is_admin()) {
@ -171,14 +176,47 @@ class Setup implements Extension {
$themes[ucfirst($name)] = $name;
}
$full = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"];
$test_url = str_replace("/index.php", "/nicetest", $full);
$nicescript = "<script language='javascript'>
function getHTTPObject() {
if (window.XMLHttpRequest){
return new XMLHttpRequest();
}
else if(window.ActiveXObject){
return new ActiveXObject('Microsoft.XMLHTTP');
}
}
checkbox = document.getElementById('nice_urls');
out_span = document.getElementById('nicetest');
checkbox.disabled = true;
out_span.innerHTML = '(testing...)';
http_request = getHTTPObject();
http_request.open('GET', '$test_url', false);
http_request.send(null);
if(http_request.status == 200 && http_request.responseText == 'ok') {
checkbox.disabled = false;
out_span.innerHTML = '(tested ok)';
}
else {
checkbox.disabled = true;
out_span.innerHTML = '(test failed)';
}
</script>";
$sb = new SetupBlock("General");
$sb->position = 0;
$sb->add_text_option("title", "Site title: ");
$sb->add_text_option("front_page", "<br>Front page: ");
$sb->add_text_option("main_page", "<br>Main page: ");
$sb->add_text_option("base_href", "<br>Base URL: ");
$sb->add_text_option("contact_link", "<br>Contact URL: ");
$sb->add_choice_option("theme", $themes, "<br>Theme: ");
$sb->add_bool_option("nice_urls", "<br>Nice URLs: ");
$sb->add_label("<span id='nicetest'>(Javascript inactive, can't test!)</span>$nicescript");
$event->panel->add_block($sb);
}