diff options
author | Kevin Chabowski <kevin@kch42.de> | 2011-11-15 21:05:05 +0100 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2011-11-15 21:05:05 +0100 |
commit | 7343667d8327f0d9ed03fe9b807a9165588bf2a8 (patch) | |
tree | 5ba3611d405eb66187eaf79af264f33c47c551ab | |
parent | dae0fe30418e227d3e30b0c9c64c358a534baca0 (diff) | |
download | ratatoeskr-cms-7343667d8327f0d9ed03fe9b807a9165588bf2a8.tar.gz ratatoeskr-cms-7343667d8327f0d9ed03fe9b807a9165588bf2a8.tar.bz2 ratatoeskr-cms-7343667d8327f0d9ed03fe9b807a9165588bf2a8.zip |
Image management added to backend.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | ratatoeskr/backend/main.php | 96 | ||||
-rw-r--r-- | ratatoeskr/cms_style/layout.css | 9 | ||||
-rw-r--r-- | ratatoeskr/templates/src/systemtemplates/image_embed.html | 14 | ||||
-rw-r--r-- | ratatoeskr/templates/src/systemtemplates/image_list.html | 68 | ||||
-rw-r--r-- | ratatoeskr/translations/en.php | 16 |
6 files changed, 201 insertions, 3 deletions
@@ -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"] = "<img src=\"%root%/images/" . htmlesc(urlencode($image->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 @@ +<ste:load name="master.html" /> +<ste:block name="content"> + <div class="pos_center"> + <ste:if>$embed_code + <ste:then> + <p><strong><ste:escape><ste:get_translation for="embed_code" /></ste:escape>:</strong> <code><ste:escape>$embed_code</ste:escape></code></p> + </ste:then> + </ste:if> + <form action="$rel_path_to_root/backend/content/images/$image_id/$markup_variant" method="POST"> + <p><strong><ste:escape><ste:get_translation for="image_alt" /></ste:escape>:</strong> <input type="text" name="img_alt" /></p> + <p><input type="submit" /></p> + </form> + </div> +</ste:block> 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 @@ +<ste:load name="master.html" /> +<ste:block name="content"> + <ste:if>$success + <ste:then> + <div class="success"><ste:escape>$success</ste:escape></div> + </ste:then> + </ste:if> + <ste:if>$error + <ste:then> + <div class="error"><ste:escape>$error</ste:escape></div> + </ste:then> + </ste:if> + + <div class="dualcolumns"> + <div class="column_left"> + <form action="$rel_path_to_root/backend/content/images" method="POST" accept-charset="UTF-8" enctype="multipart/form-data"> + <h2><ste:escape><ste:get_translation for="image_upload" /></ste:escape></h2> + <p><input type="file" name="upload_img" class="fullwidth" /></p> + <p> + <strong><ste:escape><ste:get_translation for="img_upload_name" /></ste:escape></strong><br /> + <input type="text" name="upload_name" class="fullwidth" /><br /> + <ste:escape><ste:get_translation for="img_upload_name_leave_empty" /></ste:escape> + </p> + <p><input type="submit" name="upload" /></p> + </form> + </div> + <div class="column_main"> + <form action="$rel_path_to_root/backend/content/images" method="POST"> + <table class="fullwidth listtab"> + <thead><tr> + <th> </th> + <th><ste:escape><ste:get_translation for="image_preview" /></ste:escape></th> + <th><ste:escape><ste:get_translation for="image_name" /></ste:escape></th> + <th><ste:escape><ste:get_translation for="image_getmarkup" /></ste:escape></th> + </tr></thead> + <tbody> + <ste:set var="images_n"><ste:arraylen array="images" /></ste:set> + <ste:if>~{$images_n|gt|0} + <ste:then> + <ste:foreach array="images" value="image"> + <tr> + <td><input type="checkbox" name="image_multiselect[]" value="$image[id]" /></td> + <td><img src="$rel_path_to_root/images/previews/${image[id]}.png" alt="" /></td> + <td><a href="$rel_path_to_root/images/$image[file]"><ste:escape>$image[name]</ste:escape></a></td> + <td> + <a href="$rel_path_to_root/backend/content/images/$image[id]/markdown">Markdown</a> - <a href="$rel_path_to_root/backend/content/images/$image[id]/html">HTML</a> + </td> + </tr> + </ste:foreach> + </ste:then> + <ste:else> + <tr><td colspan="5" style="text-align: center;"><em><ste:escape><ste:get_translation for="no_images" /></ste:escape></em></td></tr> + </ste:else> + </ste:if> + </tbody> + </table> + <div> + <input type="submit" name="delete" value="<ste:escape><ste:get_translation for='delete' /></ste:escape>" /> + <select name="really_delete"> + <option value="no" selected="selected"><ste:escape><ste:get_translation for="notext_default" /></ste:escape></option> + <option value="yes"><ste:escape><ste:get_translation for="yestext_default" /></ste:escape></option> + </select> + </div> + </form> + </div> + </div> + <div class="dualcolumns_stop"></div> +</ste:block> 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" ); ?> |