diff --git a/src/IDF/Template/MarkdownForge.php b/src/IDF/Template/MarkdownForge.php index 58516b8..c734b4b 100644 --- a/src/IDF/Template/MarkdownForge.php +++ b/src/IDF/Template/MarkdownForge.php @@ -25,10 +25,97 @@ Pluf::loadFunction('Pluf_Text_MarkDown_parse'); class IDF_Template_MarkdownForge extends Pluf_Template_Tag { - function start($text) + private $request; + + public function start($text, $request) { + $this->request = $request; $filter = new IDF_Template_MarkdownPrefilter(); - echo $filter->go(Pluf_Text_MarkDown_parse($text)); + $text = $filter->go(Pluf_Text_MarkDown_parse($text)); + + // replace {}-macros with the corresponding template rendering + echo IDF_Template_safePregReplace('#\{(\w+)(?:,\s*([^\}]+))?\}#im', + array($this, 'callbackMacros'), + $text); + } + + public function callbackMacros($matches) + { + @list(, $macro, $opts) = $matches; + $known_macros = array('projectlist'); + if (!in_array($macro, $known_macros)) { + return $matches[0]; + } + if (empty($opts)) { + $opts = array(); + } + $callbackName = 'callback'.ucfirst(strtolower($macro)).'Macro'; + return $this->callbackProjectlistMacro($opts); + } + + public function callbackProjectlistMacro($opts) + { + $validOpts = array( + 'label' => '/^\d+|(\w+:)?\w+$/', + 'order' => '/^name|activity$/', + 'limit' => '/^\d+$/', + ); + + $parsedOpts = array(); + // FIXME: no support for escaping yet in place + $opts = preg_split('/\s*,\s*/', $opts, -1, PREG_SPLIT_NO_EMPTY); + foreach ((array)@$opts as $opt) + { + list($key, $value) = preg_split('/\s*=\s*/', $opt, 2); + if (!array_key_exists($key, $validOpts)) { + continue; + } + if (!preg_match($validOpts[$key], $value)) { + continue; + } + $parsedOpts[$key] = $value; + } + + $tag = false; + if (!empty($parsedOpts['label'])) { + if (is_numeric($parsedOpts['label'])) { + $tag = Pluf::factory('IDF_Tag')->get($parsedOpts['label']); + } else { + @list($class, $name) = preg_split('/:/', $parsedOpts['label'], 2); + if (empty($name)) { + $name = $class; + $class = IDF_TAG_DEFAULT_CLASS; + } + $sql = new Pluf_SQL('class=%s AND lcname=%s AND project=0', + array(strtolower($class), mb_strtolower($name))); + $tag = Pluf::factory('IDF_Tag')->getOne(array('filter' => $sql->gen())); + } + // ignore non-global tags + if ($tag !== false && $tag->project > 0) { + $tag = false; + } + } + + $order = 'name'; + if (!empty($parsedOpts['order'])) { + $order = $parsedOpts['order']; + } + + $projects = IDF_Views::getProjects($this->request->user, $tag, $order); + if (!empty($parsedOpts['limit']) && $parsedOpts['limit'] < count($projects)) { + // there is no array_slice on ArrayObject, do'h! + $projectsCopy = array(); + for ($i=0; $i<$parsedOpts['limit']; ++$i) + $projectsCopy[] = $projects[$i]; + $projects = $projectsCopy; + } + + $tmpl = new Pluf_Template('idf/project-list.html'); + $context = new Pluf_Template_Context(array( + 'projects' => $projects, + 'order' => 'name', + )); + return $tmpl->render($context); } } diff --git a/src/IDF/templates/idf/gadmin/forge/index.html b/src/IDF/templates/idf/gadmin/forge/index.html index 20a31b1..188cac3 100644 --- a/src/IDF/templates/idf/gadmin/forge/index.html +++ b/src/IDF/templates/idf/gadmin/forge/index.html @@ -46,8 +46,19 @@ {/block} {block context} +{assign $eurl = 'http://michelf.com/projects/php-markdown/extra/'} +{assign $burl = 'http://daringfireball.net/projects/markdown/syntax'}
-

{blocktrans}You can define a custom forge start page that is displayed instead of the standard project listing.{/blocktrans}

+{blocktrans} +

Instructions:

+

You can set up a custom forge page that is used as entry page for the forge instead of the plain project listing. This page is then also accessible via the 'Home' link in main menu bar.

+

The content of the page can use the Markdown syntax with the Extra extension.

+

Additionally, the following macros are available:
+

+

+{/blocktrans}
{/block} diff --git a/src/IDF/templates/idf/index.html b/src/IDF/templates/idf/index.html index a60f6cd..d792abf 100644 --- a/src/IDF/templates/idf/index.html +++ b/src/IDF/templates/idf/index.html @@ -6,7 +6,7 @@ {trans 'Projects'} {/block} {block body} -{markdown_forge $content} +{markdown_forge $content, $request} {/block} {block context}{/block} diff --git a/src/IDF/templates/idf/listProjects.html b/src/IDF/templates/idf/listProjects.html index 80b6f43..aa340e6 100644 --- a/src/IDF/templates/idf/listProjects.html +++ b/src/IDF/templates/idf/listProjects.html @@ -7,44 +7,7 @@ {aurl 'url', 'IDF_Views_Admin::projectCreate'}

+ {trans 'Create Project'}

{/if} {else} -{foreach $projects as $p} -
- -

- {$p} - {assign $url = $p.external_project_url} - {if $url != ''} -   - {/if} - {if $p.private} - {trans 'Private project'}{/if} -

-

{$p.shortdesc}

-

{trans 'Labels:'} - {assign $tags = $p.get_tags_list()} - {if count($tags) == 0}{trans 'n/a'}{else} - {foreach $p.get_tags_list() as $idx => $label} - {if $idx != 0}, {/if} - {$label} - {/foreach} - {/if} -

-
-{/foreach} +{include 'idf/project-list.html'} {/if} {/block} diff --git a/src/IDF/templates/idf/project-list.html b/src/IDF/templates/idf/project-list.html new file mode 100644 index 0000000..74b42c9 --- /dev/null +++ b/src/IDF/templates/idf/project-list.html @@ -0,0 +1,41 @@ +
+ {foreach $projects as $p} +
+ +

+ {$p} + {assign $url = $p.external_project_url} + {if $url != ''} +   + {/if} + {if $p.private} - {trans 'Private project'}{/if} +

+

{$p.shortdesc}

+

{trans 'Labels:'} + {assign $tags = $p.get_tags_list()} + {if count($tags) == 0}{trans 'n/a'}{else} + {foreach $p.get_tags_list() as $idx => $label} + {if $idx != 0}, {/if} + {$label} + {/foreach} + {/if} +

+
+ {/foreach} +
+