diff options
author | Kevin Chabowski <kevin@kch42.de> | 2011-11-17 21:45:09 +0100 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2011-11-17 21:45:09 +0100 |
commit | 2ec78d505342e2bc241b32eac29164994ed911eb (patch) | |
tree | 2a1ab225e15f0954f33d92a20d40f72511d4916d | |
parent | c8e10265775400b15bd4369a6a2efca09224e1dc (diff) | |
download | ratatoeskr-cms-2ec78d505342e2bc241b32eac29164994ed911eb.tar.gz ratatoeskr-cms-2ec78d505342e2bc241b32eac29164994ed911eb.tar.bz2 ratatoeskr-cms-2ec78d505342e2bc241b32eac29164994ed911eb.zip |
Comment management added to backend.
-rw-r--r-- | ratatoeskr/backend/main.php | 174 | ||||
-rw-r--r-- | ratatoeskr/templates/src/systemtemplates/comments_list.html | 84 | ||||
-rw-r--r-- | ratatoeskr/templates/src/systemtemplates/single_comment.html | 62 | ||||
-rw-r--r-- | ratatoeskr/translations/en.php | 28 |
4 files changed, 346 insertions, 2 deletions
diff --git a/ratatoeskr/backend/main.php b/ratatoeskr/backend/main.php index ba3379b..cf1f5c3 100644 --- a/ratatoeskr/backend/main.php +++ b/ratatoeskr/backend/main.php @@ -722,6 +722,180 @@ $backend_subactions = url_action_subactions(array( ); }, $images); echo $ste->exectemplate("systemtemplates/image_list.html"); + }, + "comments" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root; + + list($comment_id) = $url_next; + + $url_next = array(); + + $ste->vars["section"] = "content"; + $ste->vars["submenu"] = "comments"; + $ste->vars["pagetitle"] = $translation["menu_comments"]; + + /* Single comment? */ + if(!empty($comment_id)) + { + try + { + $comment = Comment::by_id($comment_id); + } + catch(DoesNotExistError $e) + { + throw new NotFoundError(); + } + + if(!$comment->read_by_admin) + { + $comment->read_by_admin = True; + $comment->save(); + } + + if(isset($_POST["action_on_comment"])) + { + switch($_POST["action_on_comment"]) + { + case "delete": + $comment->delete(); + $ste->vars["success"] = $translation["comment_successfully_deleted"]; + goto backend_content_comments_overview; + break; + case "make_visible": + $comment->visible = True; + $comment->save(); + $ste->vars["success"] = $translation["comment_successfully_made_visible"]; + break; + case "make_invisible": + $comment->visible = False; + $comment->save(); + $ste->vars["success"] = $translation["comment_successfully_made_invisible"]; + break; + } + } + + $ste->vars["id"] = $comment->get_id(); + $ste->vars["visible"] = $comment->visible; + $ste->vars["article"] = $comment->get_article()->urlname; + $ste->vars["language"] = $comment->get_language(); + $ste->vars["date"] = $comment->get_timestamp(); + $ste->vars["author"] = "\"{$comment->author_name}\" <{$comment->author_mail}>"; + $ste->vars["comment_text"] = $comment->create_html(); + $ste->vars["comment_raw"] = $comment->text; + + echo $ste->exectemplate("systemtemplates/single_comment.html"); + return; + } + + backend_content_comments_overview: + + /* Perform an action on all selected comments */ + if(!empty($_POST["action_on_comments"])) + { + switch($_POST["action_on_comments"]) + { + case "delete": + $commentaction = function($c) { $c->delete(); }; + $ste->vars["success"] = $translation["comments_successfully_deleted"]; + break; + case "mark_read": + $commentaction = function($c) { $c->read_by_admin = True; $c->save(); }; + $ste->vars["success"] = $translation["comments_successfully_marked_read"]; + break; + case "mark_unread": + $commentaction = function($c) { $c->read_by_admin = False; $c->save(); }; + $ste->vars["success"] = $translation["comments_successfully_marked_unread"]; + break; + case "make_visible": + $commentaction = function($c) { $c->visible = True; $c->save(); }; + $ste->vars["success"] = $translation["comments_successfully_made_visible"]; + break; + case "make_invisible": + $commentaction = function($c) { $c->visible = False; $c->save(); }; + $ste->vars["success"] = $translation["comments_successfully_made_invisible"]; + break; + default; + $ste->vars["error"] = $translation["unknown_action"]; + break; + } + if(isset($commentaction)) + { + foreach($_POST["comment_multiselect"] as $c_id) + { + try + { + $comment = Comment::by_id($c_id); + $commentaction($comment); + } + catch(DoesNotExistError $e) + { + continue; + } + } + } + } + + $comments = Comment::all(); + + /* Filtering */ + $filterquery = array(); + if(!empty($_GET["filter_article"])) + { + $searchfor = strtolower($_GET["filter_article"]); + $comments = array_filter($comments, function($c) use ($searchfor) { return strpos(strtolower($c->get_article()->urlname), $searchfor) !== False; }); + $filterquery[] = "filter_article=" . urlencode($_GET["filter_article"]); + $ste->vars["filter_article"] = $_GET["filter_article"]; + } + $ste->vars["filterquery"] = implode("&", $filterquery); + + /* Sorting */ + if(isset($_GET["sort_asc"])) + { + $sort_dir = 1; + $sort_by = $_GET["sort_asc"]; + } + elseif(isset($_GET["sort_desc"])) + { + $sort_dir = -1; + $sort_by = $_GET["sort_desc"]; + } + else + { + $sort_dir = 1; + $sort_by = "was_read"; + } + + switch($sort_by) + { + case "language": + usort($comments, function($a, $b) use ($sort_dir) { return strcmp($a->get_language(), $b->get_language()) * $sort_dir; }); + break; + case "date": + usort($comments, function($a, $b) use ($sort_dir) { return intcmp($a->get_timestamp(), $b->get_timestamp()) * $sort_dir; }); + break; + case "was_read": + default: + usort($comments, function($a, $b) use ($sort_dir) { return intcmp((int) $a->read_by_admin, (int) $b->read_by_admin) * $sort_dir; }); + $sort_by = "was_read"; + break; + } + $ste->vars["sortquery"] = "sort_" . ($sort_dir == 1 ? "asc" : "desc") . "=$sort_by"; + $ste->vars["sorting"] = array("dir" => ($sort_dir == 1 ? "asc" : "desc"), "by" => $sort_by); + $ste->vars["sort_" . ($sort_dir == 1 ? "asc" : "desc") . "_$sort_by"] = True; + + $ste->vars["comments"] = array_map(function($c) { return array( + "id" => $c->get_id(), + "visible" => $c->visible, + "read_by_admin" => $c->read_by_admin, + "article" => $c->get_article()->urlname, + "excerpt" => substr(str_replace(array("\r\n", "\n", "\r"), " ", $c->text), 0, 50), + "language" => $c->get_language(), + "date" => $c->get_timestamp(), + "author" => "\"{$c->author_name}\" <{$c->author_mail}>" + ); }, $comments); + + echo $ste->exectemplate("systemtemplates/comments_list.html"); } )) )); diff --git a/ratatoeskr/templates/src/systemtemplates/comments_list.html b/ratatoeskr/templates/src/systemtemplates/comments_list.html new file mode 100644 index 0000000..4d05db2 --- /dev/null +++ b/ratatoeskr/templates/src/systemtemplates/comments_list.html @@ -0,0 +1,84 @@ +<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> + + <form action="$rel_path_to_root/backend/content/comments" method="GET" accept-charset="UTF-8"> + <div> + <strong><ste:escape><ste:get_translation for="filter" /></ste:escape>:</strong> + <ste:escape><ste:get_translation for="filter_article" /></ste:escape> <input type="text" name="filter_article" value="<ste:escape>$filter_article</ste:escape>" /> + <input type="hidden" name="sort_$sorting[dir]" value="$sorting[by]" /> + <input type="submit" /> + </div> + </form> + + <form action="$rel_path_to_root/backend/content/comments?$filterquery?{$filterquery|&|}$sortquery" method="POST"> + <table class="fullwidth listtab"> + <thead> + <tr> + <th> </th> + <th> + <ste:escape><ste:get_translation for="was_read" /></ste:escape> + <a href="$rel_path_to_root/backend/content/comments??{$filterquery|${filterquery}&|}sort_asc=was_read"><img src="$rel_path_to_root/ratatoeskr/cms_style/images/sortarrow_up_?{$sort_asc_was_read|filled|outline}.png" alt="<ste:get_translation for='sort_asc' />" /></a> + <a href="$rel_path_to_root/backend/content/comments??{$filterquery|${filterquery}&|}sort_desc=was_read"><img src="$rel_path_to_root/ratatoeskr/cms_style/images/sortarrow_down_?{$sort_desc_was_read|filled|outline}.png" alt="<ste:get_translation for='sort_desc' />" /></a> + </th> + <th><ste:escape><ste:get_translation for="visible" /></ste:escape></th> + <th><ste:escape><ste:get_translation for="comment_excerpt" /></ste:escape></th> + <th> + <ste:escape><ste:get_translation for="language" /></ste:escape> + <a href="$rel_path_to_root/backend/content/comments??{$filterquery|${filterquery}&|}sort_asc=language"><img src="$rel_path_to_root/ratatoeskr/cms_style/images/sortarrow_up_?{$sort_asc_language|filled|outline}.png" alt="<ste:get_translation for='sort_asc' />" /></a> + <a href="$rel_path_to_root/backend/content/comments??{$filterquery|${filterquery}&|}sort_desc=language"><img src="$rel_path_to_root/ratatoeskr/cms_style/images/sortarrow_down_?{$sort_desc_language|filled|outline}.png" alt="<ste:get_translation for='sort_desc' />" /></a> + </th> + <th><ste:escape><ste:get_translation for="author" /></ste:escape></th> + <th> + <ste:escape><ste:get_translation for="date_time" /></ste:escape> + <a href="$rel_path_to_root/backend/content/comments??{$filterquery|${filterquery}&|}sort_asc=date"><img src="$rel_path_to_root/ratatoeskr/cms_style/images/sortarrow_up_?{$sort_asc_date|filled|outline}.png" alt="<ste:get_translation for='sort_asc' />" /></a> + <a href="$rel_path_to_root/backend/content/comments??{$filterquery|${filterquery}&|}sort_desc=date"><img src="$rel_path_to_root/ratatoeskr/cms_style/images/sortarrow_down_?{$sort_desc_date|filled|outline}.png" alt="<ste:get_translation for='sort_desc' />" /></a> + </th> + <th><ste:escape><ste:get_translation for="article" /></ste:escape></th> + </tr> + </thead> + <tbody> + <ste:set var="comments_n"><ste:arraylen array="comments" /></ste:set> + <ste:if>~{$comments_n|gt|0} + <ste:then> + <ste:foreach array="comments" value="comment"> + <tr> + <td><input type="checkbox" name="comment_multiselect[]" value="$comment[id]" /></td> + <td>?{$comment[read_by_admin]|<ste:get_translation for="yes" />|<strong><ste:get_translation for="no" /></strong>}</td> + <td>?{$comment[visible]|<ste:get_translation for="yes" />|<ste:get_translation for="no" />}</td> + <td><em><ste:escape>$comment[excerpt]</ste:escape>...</em> <a href="$rel_path_to_root/backend/content/comments/$comment[id]"><ste:escape><ste:get_translation for="read_more" /></ste:escape></a></td> + <td>$comment[language]</td> + <td><ste:escape>$comment[author]</ste:escape></td> + <td><ste:date timestamp="$comment[date]">%Y-%m-%d %H:%M:%S</ste:date></td> + <td><a href="$rel_path_to_root/backend/content/write/<ste:escape>$comment[article]</ste:escape>"><ste:escape>$comment[article]</ste:escape></a></td> + </tr> + </ste:foreach> + </ste:then> + <ste:else> + <tr><td colspan="8" style="text-align: center"><em><ste:escape><ste:get_translation for="no_comments" /></ste:escape></em></td></tr> + </ste:else> + </ste:if> + </tbody> + </table> + <div> + <select name="action_on_comments"> + <option value="" selected="selected"></option> + <option value="mark_read"><ste:escape><ste:get_translation for="commentaction_mark_read" /></ste:escape></option> + <option value="mark_unread"><ste:escape><ste:get_translation for="commentaction_mark_unread" /></ste:escape></option> + <option value="make_visible"><ste:escape><ste:get_translation for="commentaction_make_visible" /></ste:escape></option> + <option value="make_invisible"><ste:escape><ste:get_translation for="commentaction_make_invisible" /></ste:escape></option> + <option value="delete"><ste:escape><ste:get_translation for="delete" /></ste:escape></option> + </select> + <input type="submit" /> + </div> + </form> +</ste:block> diff --git a/ratatoeskr/templates/src/systemtemplates/single_comment.html b/ratatoeskr/templates/src/systemtemplates/single_comment.html new file mode 100644 index 0000000..e53ced3 --- /dev/null +++ b/ratatoeskr/templates/src/systemtemplates/single_comment.html @@ -0,0 +1,62 @@ +<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="triplecolumns"> + <div class="column_left"> + <h2><ste:escape><ste:get_translation for="comment_perform_action" /></ste:escape></h2> + <form action="$rel_path_to_root/backend/content/comments/$id" method="POST"> + <select name="action_on_comment"> + <option value="" selected="selected"></option> + <option value="make_visible"><ste:escape><ste:get_translation for="commentaction_make_visible" /></ste:escape></option> + <option value="make_invisible"><ste:escape><ste:get_translation for="commentaction_make_invisible" /></ste:escape></option> + <option value="delete"><ste:escape><ste:get_translation for="delete" /></ste:escape></option> + </select> + <input type="submit" /> + </form> + </div> + <div class="column_right"> + <p> + <strong><ste:escape><ste:get_translation for="author" /></ste:escape></strong><br /> + <ste:escape>$author</ste:escape> + </p> + + <p> + <strong><ste:escape><ste:get_translation for="visible" /></ste:escape></strong><br /> + ?{$visible|<ste:get_translation for="yes" />|<ste:get_translation for="no" />} + </p> + + <p> + <strong><ste:escape><ste:get_translation for="date_time" /></ste:escape></strong><br /> + <ste:date timestamp="$date">%Y-%m-%d %H:%M:%S</ste:date> + </p> + + <p> + <strong><ste:escape><ste:get_translation for="article" /></ste:escape></strong><br /> + <a href="$rel_path_to_root/backend/content/write/<ste:escape>$article</ste:escape>"><ste:escape>$article</ste:escape></a> + </p> + + <p> + <strong><ste:escape><ste:get_translation for="language" /></ste:escape></strong><br /> + $language + </p> + </div> + <div class="column_main"> + <h2><ste:escape><ste:get_translation for="comment_text" /></ste:escape></h2> + $comment_text + <hr /> + <h2><ste:escape><ste:get_translation for="comment_text_raw" /></ste:escape></h2> + <pre><code><ste:escape>$comment_raw</ste:escape></code></pre> + </div> + </div> + <div class="triplecolumns_stop"></div> +</ste:block> diff --git a/ratatoeskr/translations/en.php b/ratatoeskr/translations/en.php index 9ab6c0b..9f1401e 100644 --- a/ratatoeskr/translations/en.php +++ b/ratatoeskr/translations/en.php @@ -69,7 +69,6 @@ $translation = array( "new_tag_name" => "Name", "tags_overview" => "Tag Overview", "tag_name" => "Tag name", - "delete" => "Delete", "yes" => "Yes", "no" => "No", "tag_add_lang" => "Add translation", @@ -106,7 +105,32 @@ $translation = array( "images_deleted" => "Images deleted.", "generate_embed_code" => "Generate embed code.", "image_alt" => "Alternative Title", - "embed_code" => "Embed code" + "embed_code" => "Embed code", + "was_read" => "Read?", + "article" => "Article", + "visible" => "Visible", + "comment_excerpt" => "Comment (excerpt)", + "no_comments" => "No comments available.", + "read_more" => "Read more", + "language" => "Language", + "author" => "Author", + "filter_article" => "by Article", + "commentaction_make_invisible" => "Make invisible", + "commentaction_make_visible" => "Make visible", + "commentaction_mark_read" => "Mark as read", + "commentaction_mark_unread" => "Mark as unread", + "comments_successfully_deleted" => "Comments sucessfully deleted.", + "comments_successfully_marked_read" => "Comments successfully marked as read.", + "comments_successfully_marked_unread" => "Comments successfully marked as unread.", + "comments_successfully_made_visible" => "Comments successfully made visible.", + "comments_successfully_made_invisible" => "Comments successfully made invisible.", + "unknown_action" => "Unknown action.", + "comment_successfully_deleted" => "Comment sucessfully deleted.", + "comment_successfully_made_visible" => "Comment successfully made visible.", + "comment_successfully_made_invisible" => "Comment successfully made invisible.", + "comment_perform_action" => "Perform an action on this comment", + "comment_text" => "Comment Text", + "comment_text_raw" => "Comment Text (raw)" ); ?> |