diff options
Diffstat (limited to 'ratatoeskr')
-rw-r--r-- | ratatoeskr/frontend.php | 115 | ||||
-rw-r--r-- | ratatoeskr/templates/src/usertemplates/standard.html | 118 | ||||
-rw-r--r-- | ratatoeskr/translations/de.php | 2 | ||||
-rw-r--r-- | ratatoeskr/translations/en.php | 2 |
4 files changed, 142 insertions, 95 deletions
diff --git a/ratatoeskr/frontend.php b/ratatoeskr/frontend.php index 0bc083b..76b0afc 100644 --- a/ratatoeskr/frontend.php +++ b/ratatoeskr/frontend.php @@ -158,18 +158,20 @@ function comment_transform_ste($comment) * The fields of an article can be looked up at <article_transform_ste>. * * Parameters: - * var - (mandatory) The name of the variable, where the current article should be stored at. - * id - (optional) Filter by ID. - * urlname - (optional) Filter by urlname. - * section - (optional) Filter by section (section name). - * status - (optional) Filter by status (numeric, <ARTICLE_STATUS_>). - * tag - (optional) Filter by tag (tag name). - * sort - (optional) How to sort. Format: "fieldname direction" where fieldname is one of [id, urlname, title, timestamp] and direction is one of [asc, desc]. - * perpage - (optional) How many articles should be shown per page (default unlimited). - * page - (optional) On which page are we (starting with 1). Useful in combination with $current[page], <page_prev> and <page_next>. (Default: 1) - * maxpage - (optional) (variable name) If given, the number of pages are stored in this variable. - * skip - (optional) How many articles should be skipped? (Default: none) - * count - (optional) How many articles to output. (Default unlimited) + * var - (mandatory) The name of the variable, where the current article should be stored at. + * id - (optional) Filter by ID. + * urlname - (optional) Filter by urlname. + * section - (optional) Filter by section (section name). + * sectionvar - (optional) Filter by section (Name of variable that contains a section). + * status - (optional) Filter by status (numeric, <ARTICLE_STATUS_>). + * tag - (optional) Filter by tag (tag name). + * tagvar - (optional) Filter by tag (Name of variable that contains a tag). + * sort - (optional) How to sort. Format: "fieldname direction" where fieldname is one of [id, urlname, title, timestamp] and direction is one of [asc, desc]. + * perpage - (optional) How many articles should be shown per page (default unlimited). + * page - (optional) On which page are we (starting with 1). Useful in combination with $current[page], <page_prev> and <page_next>. (Default: 1) + * maxpage - (optional) (variable name) If given, the number of pages are stored in this variable. + * skip - (optional) How many articles should be skipped? (Default: none) + * count - (optional) How many articles to output. (Default unlimited) * * Tag Content: * The tag's content will be executed for every article. The current article will be written to the variable specified by the var parameter before. @@ -183,27 +185,32 @@ $ste->register_tag("articles_get", function($ste, $params, $sub) if(!isset($params["var"])) throw new \ste\RuntimeError("Parameter var is needed in article_get!"); - if(isset($params["section"])) - { - try - { - $params["section"] = Section::by_name($params["section"]); - } - catch(NotFoundError $e) - { - unset($params["section"]); - } - } $criterias = array("langavail" => $lang, "onlyvisible" => True); if(isset($params["id"])) $criterias["id"] = $params["id"]; if(isset($params["urlname"])) $criterias["urlname"]; - if(isset($params["section"])) - $criterias["section"] = $params["section"]; if(isset($params["status"])) $criterias["status"] = $params["status"]; + if(isset($params["sectionvar"])) + { + $sectionvar = $ste->get_var_by_name($params["sectionvar"]); + $criterias["section"] = $sectionvar["__obj"]; + } + else if(isset($params["section"])) + { + try + { + $criterias["section"] = Section::by_name($params["section"]); + } + catch(DoesNotExistError $e) {} + } + if(isset($params["tagvar"])) + { + $tagvar = $ste->get_var_by_name($params["tagvar"]); + $criterias["tag"] = $tagvar["__obj"]; + } if(isset($params["tag"])) { try @@ -392,8 +399,9 @@ $ste->register_tag("article_comments", function($ste, $params, $sub) * Generates a HTML form tag that allows the visitor to write a comment. * * Parameters: - * article - (mandatory) The name of the variable, where the article is stored at. - * default - (optional) If not empty, a default formular with the mandatory fields will be generated. + * article - (mandatory) The name of the variable, where the article is stored at. + * default - (optional) If not empty, a default formular with the mandatory fields will be generated. + * previewbtn - (optional) If not empty and default form is choosen, a preview button will also be generated. * * Tag Content: * The tag's content will be written into the HTML form tag. @@ -446,11 +454,13 @@ $ste->register_tag("comment_form", function($ste, $params, $sub) $form_header = "<form action=\"{$tpl_article["fullurl"]}?comment\" method=\"post\" accept-charset=\"UTF-8\"><input type=\"hidden\" name=\"comment_token\" value=\"$token\" />"; + $previewbtn = $ste->evalbool(@$params["previewbtn"]) ? " <input type=\"submit\" name=\"preview_comment\" value=\"{$translation["comment_form_preview"]}\" />" : ""; + if($ste->evalbool(@$params["default"])) $form_body = "<p>{$translation["comment_form_name"]}: <input type=\"text\" name=\"author_name\" value=\"" . htmlesc(@$_POST["author_name"]) . "\" /></p> <p>{$translation["comment_form_mail"]}: <input type=\"text\" name=\"author_mail\" value=\"" . htmlesc(@$_POST["author_mail"]) . "\" /></p> <p>{$translation["comment_form_text"]}:<br /><textarea name=\"comment_text\" cols=\"50\" rows=\"10\">" . htmlesc(@$_POST["comment_text"]) . "</textarea></p> -<p><input type=\"submit\" name=\"post_comment\" /></p>"; +<p><input type=\"submit\" name=\"post_comment\" value=\"{$translation["comment_form_submit"]}\" />$previewbtn</p>"; else { $ste->vars["current"]["oldcomment"] = array( @@ -651,6 +661,55 @@ $ste->register_tag("title", function($ste, $params, $sub) return "<title>$pagetitle</title>"; }); +function make_on_anything_tag($field) +{ + return function($ste, $params, $sub) use ($field) + { + if($ste->evalbool($ste->vars["current"][$field])) + { + if(!empty($params["var"])) + $ste->set_var_by_name($params["var"], $ste->vars["current"][$field]); + return $sub($ste); + } + }; +} + +/* + * STETag: on_article + * Execute tag content, if currently an article is requested. + * + * Parameters: + * var - (optional) If set, the article will be stored in the variable with that name (see <article_transform_ste> for sub-fields). + * + * Returns: + * The executed tag content, if an article was requested. + */ +$ste->register_tag("on_article", make_on_anything_tag("article")); + +/* + * STETag: on_tag + * Execute tag content, if currently a tag is requested. + * + * Parameters: + * var - (optional) If set, the tag will be stored in the variable with that name (see <tag_transform_ste> for sub-fields). + * + * Returns: + * The executed tag content, if a tag was requested. + */ +$ste->register_tag("on_tag", make_on_anything_tag("tag")); + +/* + * STETag: on_section + * Execute tag content, if currently a section is requested. + * + * Parameters: + * var - (optional) If set, the section will be stored in the variable with that name (see <section_transform_ste> for sub-fields). + * + * Returns: + * The executed tag content, if a section was requested. + */ +$ste->register_tag("on_section", make_on_anything_tag("section")); + /* * STEVar: $current * Holds information about the current page in the frontend (the part of the webpage, the visitor sees). diff --git a/ratatoeskr/templates/src/usertemplates/standard.html b/ratatoeskr/templates/src/usertemplates/standard.html index c4d1eb9..ef78001 100644 --- a/ratatoeskr/templates/src/usertemplates/standard.html +++ b/ratatoeskr/templates/src/usertemplates/standard.html @@ -1,72 +1,56 @@ <ste:load name="master.html" />
<ste:block name="content">
- <ste:if>
- $current[section]
- <ste:then>
- <ste:articles_get var="article" section="$current[section][name]" sort="timestamp desc" perpage="10" page="$current[page]" maxpage="maxpage">
- <div class="article_short">
- <h2>$article[title]</h2>
- $article[excerpt]
- <div class="readmore_link"><a href="<ste:escape>$article[fullurl]</ste:escape>"><ste:get_translation for="read_more" /></a></div>
- </div class="article_short">
- </ste:articles_get>
- <ste:page_prev current="$current[page]" maxpage="$maxpage" default="y" />
- <ste:page_next current="$current[page]" maxpage="$maxpage" default="y" />
- </ste:then>
- </ste:if>
+ <ste:on_section var="section">
+ <ste:articles_get var="article" sectionvar="section" sort="timestamp desc" perpage="10" page="$current[page]" maxpage="maxpage">
+ <div class="article_short">
+ <h2>$article[title]</h2>
+ $article[excerpt]
+ <div class="readmore_link"><a href="<ste:escape>$article[fullurl]</ste:escape>"><ste:get_translation for="read_more" /></a></div>
+ </div class="article_short">
+ </ste:articles_get>
+ <ste:page_prev current="$current[page]" maxpage="$maxpage" default="y" />
+ <ste:page_next current="$current[page]" maxpage="$maxpage" default="y" />
+ </ste:on_section>
- <ste:if>
- $current[article]
- <ste:then>
- <div class="fullarticle">
- <h2>$current[article][title]</h2>
- <div class="article_meta">Published: <ste:date timestamp="$current[article][timestamp]">%d. %h. %Y, %H:%M</ste:date></div>
- $current[article][text]<!-- $current[article][comments_allowed] -->
- <ste:if>
- $current[article][comments_allowed]
- <ste:then>
- <h3>Comments (<ste:article_comments_count article="current[article]" />)</h3>
- <ste:article_comments var="comment" article="current[article]" sort="asc">
- <div class="comment">
- <p><strong>Name</strong>: $comment[author]</p>
- <p><strong>Date</strong>: <ste:date timestamp="$comment[timestamp]">%d. %B %Y, %H:%M</ste:date></p>
- $comment[text]
- </div>
- </ste:article_comments>
- ?{$current[commented]|Comment sucessfully stored!|}
- ?{$current[comment_fail]|Comment could not be stored: $current[comment_fail]|}
- <ste:if>$current[comment_prev]
- <ste:then>
- <h3>Comment preview</h3>
- <div class="comment">$current[comment_prev]</div>
- </ste:then>
- </ste:if>
- <ste:comment_form article="current[article]">
- Name: <input type="text" name="author_name" value="$current[oldcomment][name]" /><br />
- Mail: <input type="text" name="author_mail" value="$current[oldcomment][mail]" /><br />
- Text (Markdown): <br />
- <textarea name="comment_text" cols="50" rows="10">$current[oldcomment][text]</textarea><br />
- <input type="submit" name="post_comment" value="Post" />
- <input type="submit" name="preview_comment" value="Preview" />
- </ste:comment_form>
- </ste:then>
- </ste:if>
- </div>
- </ste:then>
- </ste:if>
+ <ste:on_article var="article">
+ <div class="fullarticle">
+ <h2>$article[title]</h2>
+ <div class="article_meta">Published: <ste:date timestamp="$article[timestamp]">%d. %h. %Y, %H:%M</ste:date></div>
+ $article[text]
+ <ste:if>
+ $article[comments_allowed]
+ <ste:then>
+ <h3>Comments (<ste:article_comments_count article="article" />)</h3>
+ <ste:article_comments var="comment" article="article" sort="asc">
+ <div class="comment">
+ <p><strong>Name</strong>: $comment[author]</p>
+ <p><strong>Date</strong>: <ste:date timestamp="$comment[timestamp]">%d. %B %Y, %H:%M</ste:date></p>
+ $comment[text]
+ </div>
+ </ste:article_comments>
+ ?{$current[commented]|Comment sucessfully stored!|}
+ ?{$current[comment_fail]|Comment could not be stored: $current[comment_fail]|}
+ <ste:if>$current[comment_prev]
+ <ste:then>
+ <h3>Comment preview</h3>
+ <div class="comment">$current[comment_prev]</div>
+ </ste:then>
+ </ste:if>
+ <ste:comment_form article="article" default="y" previewbtn="y" />
+ </ste:then>
+ </ste:if>
+ </div>
+ </ste:on_article>
- <ste:if>
- $current[tag]
- <ste:then>
- <ste:articles_get var="article" tag="$current[tag][name]" sort="timestamp desc" perpage="10" page="$current[page]" maxpage="maxpage">
- <div class="article_short">
- <h2><ste:escape>$article[title]</ste:escape></h2>
- $article[excerpt]
- <div class="readmore_link"><a href="<ste:escape>$article[fullurl]</ste:escape>"><ste:get_translation for="read_more" /></a></div>
- </div class="article_short">
- </ste:articles_get>
- <ste:page_prev current="$current[page]" maxpage="$maxpage" default="y" />
- <ste:page_next current="$current[page]" maxpage="$maxpage" default="y" />
- </ste:then>
- </ste:if>
+ <ste:on_tag var="tag">
+ <ste:articles_get var="article" tagvar="tag" sort="timestamp desc" perpage="10" page="$current[page]" maxpage="maxpage">
+ <div class="article_short">
+ <h2><ste:escape>$article[title]</ste:escape></h2>
+ $article[excerpt]
+ <div class="readmore_link"><a href="<ste:escape>$article[fullurl]</ste:escape>"><ste:get_translation for="read_more" /></a></div>
+ </div class="article_short">
+ </ste:articles_get>
+ <ste:page_prev current="$current[page]" maxpage="$maxpage" default="y" />
+ <ste:page_next current="$current[page]" maxpage="$maxpage" default="y" />
+ </ste:on_tag>
</ste:block>
diff --git a/ratatoeskr/translations/de.php b/ratatoeskr/translations/de.php index 56ebf4e..f49f379 100644 --- a/ratatoeskr/translations/de.php +++ b/ratatoeskr/translations/de.php @@ -33,6 +33,8 @@ $translation = array( "comment_form_name" => "Dein Name", "comment_form_mail" => "Deine E-Mailadresse", "comment_form_text" => "Dein Kommentar (Markdown Format)", + "comment_form_submit" => "Kommentar senden", + "comment_form_preview" => "Vorschau", "page_prev" => "<-- vorherige Seite", "page_next" => "nächste Seite -->", "e404_details" => "Die Seite [[URL]] konte nicht gefunden werden. Das tut uns leid.", diff --git a/ratatoeskr/translations/en.php b/ratatoeskr/translations/en.php index 86e17a2..a53617c 100644 --- a/ratatoeskr/translations/en.php +++ b/ratatoeskr/translations/en.php @@ -33,6 +33,8 @@ $translation = array( "comment_form_name" => "Your name", "comment_form_mail" => "Your E-Mailaddress", "comment_form_text" => "Your comment (Markdown format)", + "comment_form_submit" => "Submit comment", + "comment_form_preview" => "Preview", "page_prev" => "<-- previous page", "page_next" => "next page -->", "e404_details" => "The page [[URL]] could not be found. Sorry.", |