From 7343667d8327f0d9ed03fe9b807a9165588bf2a8 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Tue, 15 Nov 2011 21:05:05 +0100 Subject: Image management added to backend. --- .gitignore | 1 + ratatoeskr/backend/main.php | 96 ++++++++++++++++++++++ ratatoeskr/cms_style/layout.css | 9 +- .../templates/src/systemtemplates/image_embed.html | 14 ++++ .../templates/src/systemtemplates/image_list.html | 68 +++++++++++++++ ratatoeskr/translations/en.php | 16 +++- 6 files changed, 201 insertions(+), 3 deletions(-) create mode 100644 ratatoeskr/templates/src/systemtemplates/image_embed.html create mode 100644 ratatoeskr/templates/src/systemtemplates/image_list.html diff --git a/.gitignore b/.gitignore index b44ac43..a814b4f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ docu naturaldocs_dir *~ +images/* diff --git a/ratatoeskr/backend/main.php b/ratatoeskr/backend/main.php index a6df9ec..ba3379b 100644 --- a/ratatoeskr/backend/main.php +++ b/ratatoeskr/backend/main.php @@ -626,6 +626,102 @@ $backend_subactions = url_action_subactions(array( }, $articles); echo $ste->exectemplate("systemtemplates/articles.html"); + }, + "images" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root; + + list($imgid, $imageaction) = $url_next; + + $url_next = array(); + + $ste->vars["section"] = "content"; + $ste->vars["submenu"] = "images"; + $ste->vars["pagetitle"] = $translation["menu_images"]; + + if(!empty($imgid) and is_numeric($imgid)) + { + try + { + $image = Image::by_id($imgid); + } + catch(DoesNotExistError $e) + { + throw new NotFoundError(); + } + + if(empty($imageaction)) + throw new NotFoundError(); + else + { + if(($imageaction == "markdown") or ($imageaction == "html")) + { + $ste->vars["pagetitle"] = $translations["generate_embed_code"]; + $ste->vars["image_id"] = $image->get_id(); + $ste->vars["markup_variant"] = $imageaction; + if(isset($_POST["img_alt"])) + { + if($imageaction == "markdown") + $ste->vars["embed_code"] = "![" . str_replace("]", "\\]", $_POST["img_alt"]) . "](%root%/images/" . str_replace(")", "\\)", urlencode($image->get_filename())) . ")"; + elseif($imageaction == "html") + $ste->vars["embed_code"] = "get_filename())) . "\" alt=\"" . htmlesc($_POST["img_alt"]) . "\" />"; + } + + echo $ste->exectemplate("systemtemplates/image_embed.html"); + } + else + throw new NotFoundError(); + } + return; + } + + /* Upload Form */ + if(isset($_POST["upload"])) + { + try + { + $image = Image::create((!empty($_POST["upload_name"])) ? $_POST["upload_name"] : $_FILES["upload_img"]["name"], $_FILES["upload_img"]["tmp_name"]); + $image->save(); + $ste->vars["success"] = $translation["upload_success"]; + } + catch(IOError $e) + { + $ste->vars["error"] = $translation["upload_failed"]; + } + catch(UnknownFileFormat $e) + { + $ste->vars["error"] = $translation["unknown_file_format"]; + } + } + + /* Mass delete */ + if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes")) + { + foreach($_POST["image_multiselect"] as $image_id) + { + try + { + $image = Image::by_id($image_id); + $image->delete(); + } + catch(DoesNotExistError $e) + { + continue; + } + } + + $ste->vars["success"] = $translation["images_deleted"]; + } + + $images = Image::all(); + + $ste->vars["images"] = array_map(function($img) { return array( + "id" => $img->get_id(), + "name" => $img->name, + "file" => $img->get_filename() + ); }, $images); + + echo $ste->exectemplate("systemtemplates/image_list.html"); } )) )); diff --git a/ratatoeskr/cms_style/layout.css b/ratatoeskr/cms_style/layout.css index 30f0ac8..c0fec6f 100644 --- a/ratatoeskr/cms_style/layout.css +++ b/ratatoeskr/cms_style/layout.css @@ -140,7 +140,7 @@ h2 { font-weight: bold; } -.triplecolumns .column_left{ +.triplecolumns .column_left, .dualcolumns .column_left { float: left; width: 50mm; margin: 0px; @@ -159,7 +159,12 @@ h2 { padding: 0mm 55mm 0mm; } -.triplecolumns_stop { +.dualcolumns .column_main { + margin: 0mm; + padding: 0mm 0mm 0mm 55mm; +} + +.triplecolumns_stop .dualcolumns_stop { clear: both; } diff --git a/ratatoeskr/templates/src/systemtemplates/image_embed.html b/ratatoeskr/templates/src/systemtemplates/image_embed.html new file mode 100644 index 0000000..387dbaa --- /dev/null +++ b/ratatoeskr/templates/src/systemtemplates/image_embed.html @@ -0,0 +1,14 @@ + + +
+ $embed_code + +

: $embed_code

+
+
+
+

:

+

+
+
+
diff --git a/ratatoeskr/templates/src/systemtemplates/image_list.html b/ratatoeskr/templates/src/systemtemplates/image_list.html new file mode 100644 index 0000000..74bab9e --- /dev/null +++ b/ratatoeskr/templates/src/systemtemplates/image_list.html @@ -0,0 +1,68 @@ + + + $success + +
$success
+
+
+ $error + +
$error
+
+
+ +
+
+
+

+

+

+
+
+ +

+

+
+
+
+
+ + + + + + + + + + ~{$images_n|gt|0} + + + + + + + + + + + + + + + +
 
$image[name] + Markdown - HTML +
+
+ + +
+
+
+
+
+
diff --git a/ratatoeskr/translations/en.php b/ratatoeskr/translations/en.php index dfd3195..58fba23 100644 --- a/ratatoeskr/translations/en.php +++ b/ratatoeskr/translations/en.php @@ -92,7 +92,21 @@ $translation = array( "filter" => "Filter", "filter_urlname" => "by URL name", "filter_tag" => "by tag", - "filter_section" => "by section" + "filter_section" => "by section", + "image_upload" => "Upload a new image", + "img_upload_name" => "Name", + "img_upload_name_leave_empty" => "(Leave empty for default filename)", + "image_preview" => "Preview", + "image_name" => "Name", + "image_getmarkup" => "Embed code", + "no_images" => "No images stored.", + "upload_failed" => "Upload failed.", + "unknown_file_format" => "Unknown file format.", + "upload_success" => "Upload successful", + "images_deleted" => "Images deleted.", + "generate_embed_code" => "Generate embed code.", + "image_alt" => "Alternative Title", + "embed_code" => "Embed code" ); ?> -- cgit v1.2.3-54-g00ecf