Indefero

Indefero Commit Details


Date:2011-12-24 08:50:41 (12 years 11 months ago)
Author:Thomas Keller
Branch:develop, release-1.3
Commit:f4058ddd69be63318098b64cf722e472b694493b
Parents: 17c6ba97d67ed5ad2a55906e84104251c99a7160
Message:Implement a simple form to save custom markdown-enabled content in the forge's admin area that is displayed instead of the default project list. Sanitize the URLs that we're using and make a redirect to the listProjects page when no custom forge page is enabled.

Changes:

File differences

src/IDF/Forge.php
7070
7171
7272
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
7389
}
return $tags;
}
public function setCustomForgePageEnabled($enabled) {
$this->conf->setVal('custom_forge_page_enabled', $enabled);
}
public function isCustomForgePageEnabled($default = false) {
return $this->conf->getVal('custom_forge_page_enabled', $default);
}
public function getCustomForgePageContent($default = '') {
return $this->conf->getVal('custom_forge_page_content', $default);
}
public function setCustomForgePageContent($content) {
$this->conf->setVal('custom_forge_page_content', $content);
}
}
src/IDF/Form/Admin/ForgeConf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of InDefero, an open source project management application.
# Copyright(C) 2008-2011 Céondo Ltd and contributors.
#
# InDefero is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* Configuration of the forge's start page.
*/
class IDF_Form_Admin_ForgeConf extends Pluf_Form
{
public function initFields($extra=array())
{
$this->fields['enabled'] = new Pluf_Form_Field_Boolean(
array('required' => false,
'label' => __('Custom forge page enabled'),
'widget' => 'Pluf_Form_Widget_CheckboxInput',
));
$this->fields['content'] = new Pluf_Form_Field_Varchar(
array('required' => true,
'label' => __('Content'),
'widget' => 'Pluf_Form_Widget_TextareaInput',
'widget_attrs' => array(
'cols' => 68,
'rows' => 26,
),
));
}
}
src/IDF/Middleware.php
8585
8686
8787
88
8889
8990
9091
......
102103
103104
104105
106
105107
106108
107109
......
115117
116118
117119
120
118121
119122
120123
'issuetext' => 'IDF_Template_IssueComment',
'timeline' => 'IDF_Template_TimelineFragment',
'markdown' => 'IDF_Template_Markdown',
'markdown_forge' => 'IDF_Template_MarkdownForge',
'showuser' => 'IDF_Template_ShowUser',
'ashowuser' => 'IDF_Template_AssignShowUser',
'appversion' => 'IDF_Template_AppVersion',
function IDF_Middleware_ContextPreProcessor($request)
{
$forge = IDF_Forge::instance();
$c = array();
$c['request'] = $request;
$c['isAdmin'] = ($request->user->administrator or $request->user->staff);
}
$c['usherConfigured'] = Pluf::f("mtn_usher_conf", null) !== null;
$c['allProjects'] = IDF_Views::getProjects($request->user);
$c['customForgePageEnabled'] = $forge->isCustomForgePageEnabled();
return $c;
}
src/IDF/Template/MarkdownForge.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of InDefero, an open source project management application.
# Copyright (C) 2008-2011 Céondo Ltd and contributors.
#
# InDefero is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
Pluf::loadFunction('Pluf_Text_MarkDown_parse');
class IDF_Template_MarkdownForge extends Pluf_Template_Tag
{
function start($text)
{
$filter = new IDF_Template_MarkdownPrefilter();
echo $filter->go(Pluf_Text_MarkDown_parse($text));
}
}
src/IDF/Views.php
3636
3737
3838
39
40
41
42
39
40
41
42
43
44
45
46
47
48
49
4350
4451
4552
46
53
4754
48
49
55
56
57
5058
5159
5260
61
62
63
64
65
66
67
68
69
70
71
72
73
5374
5475
5576
*/
public function index($request, $match)
{
// TODO: add a switch here later on to determine whether the project list
// or a custom start page should be displayed
$match = array('', 'all', 'name');
return $this->listProjects($request, $match);
$forge = IDF_Forge::instance();
if (!$forge->isCustomForgePageEnabled()) {
$url = Pluf_HTTP_URL_urlForView('IDF_Views::listProjects');
return new Pluf_HTTP_Response_Redirect($url);
}
return Pluf_Shortcuts_RenderToResponse('idf/index.html',
array('page_title' => __('Welcome'),
'content' => $forge->getCustomForgePageContent(),
),
$request);
}
/**
* List all the projects managed by InDefero.
* List all projects unfiltered
*
* Only the public projects are listed or the private with correct
* rights.
* @param unknown_type $request
* @param unknown_type $match
* @return Pluf_HTTP_Response
*/
public function listProjects($request, $match)
{
$match = array('', 'all', 'name');
return $this->listProjectsByLabel($request, $match);
}
/**
* List projects, optionally filtered by label
*
* @param unknown_type $request
* @param unknown_type $match
* @return Pluf_HTTP_Response
*/
public function listProjectsByLabel($request, $match)
{
list(, $tagId, $order) = $match;
$tag = false;
src/IDF/Views/Admin.php
3232
3333
3434
35
36
37
35
3836
39
40
37
38
4139
4240
43
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
4463
45
46
64
65
66
4767
48
68
4969
5070
5171
class IDF_Views_Admin
{
/**
* Home page of the administration.
*
* It should provide an overview of the forge status.
* Start page of the administration.
*/
public $home_precond = array('Pluf_Precondition::staffRequired');
public function home($request, $match)
public $forge_precond = array('Pluf_Precondition::staffRequired');
public function forge($request, $match)
{
$title = __('Forge Management');
return Pluf_Shortcuts_RenderToResponse('idf/gadmin/home.html',
$forge = IDF_Forge::instance();
if ($request->method == 'POST') {
$form = new IDF_Form_Admin_ForgeConf($request->POST);
if ($form->isValid()) {
$forge->setCustomForgePageEnabled($form->cleaned_data['enabled']);
$forge->setCustomForgePageContent($form->cleaned_data['content']);
$request->user->setMessage(__('The forge configuration has been saved.'));
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Admin::forge');
return new Pluf_HTTP_Response_Redirect($url);
}
} else {
$params = array();
$params['enabled'] = $forge->isCustomForgePageEnabled();
if (($content = $forge->getCustomForgePageContent(false)) !== false) {
$params['content'] = $content;
}
if (count($params) == 0) {
$params = null; //Nothing in the db, so new form.
}
$form = new IDF_Form_Admin_ForgeConf($params);
}
return Pluf_Shortcuts_RenderToResponse('idf/gadmin/forge/index.html',
array(
'page_title' => $title,
),
'page_title' => $title,
'form' => $form,
),
$request);
}
}
/**
* Projects overview.
src/IDF/conf/urls.php
2929
3030
3131
32
32
3333
3434
3535
3636
37
38
39
40
41
3742
3843
3944
......
473478
474479
475480
481
482
483
484
485
476486
477487
478488
'model' => 'IDF_Views',
'method' => 'index');
$ctl[] = array('regex' => '#^/label/(\w+)/(\w+)/$#',
$ctl[] = array('regex' => '#^/projects/$#',
'base' => $base,
'model' => 'IDF_Views',
'method' => 'listProjects');
$ctl[] = array('regex' => '#^/projects/label/(\w+)/(\w+)/$#',
'base' => $base,
'model' => 'IDF_Views',
'method' => 'listProjectsByLabel');
$ctl[] = array('regex' => '#^/login/$#',
'base' => $base,
'model' => 'IDF_Views',
// ---------- FORGE ADMIN --------------------------------
$ctl[] = array('regex' => '#^/admin/forge/$#',
'base' => $base,
'model' => 'IDF_Views_Admin',
'method' => 'forge');
$ctl[] = array('regex' => '#^/admin/projects/$#',
'base' => $base,
'model' => 'IDF_Views_Admin',
src/IDF/templates/idf/gadmin/base.html
3939
4040
4141
42
4243
4344
4445
{include 'idf/main-menu.html'}
<div id="header">
<div id="main-tabs">
<a href="{url 'IDF_Views_Admin::forge'}"{block tabforge}{/block}>{trans 'Forge'}</a>
<a href="{url 'IDF_Views_Admin::projects'}"{block tabprojects}{/block}>{trans 'Projects'}</a>
<a href="{url 'IDF_Views_Admin::users'}"{block tabusers}{/block}>{trans 'People'}</a>
{if $usherConfigured}
src/IDF/templates/idf/gadmin/forge/base.html
1
2
3
4
5
{extends "idf/gadmin/base.html"}
{block tabforge} class="active"{/block}
{block subtabs}
<a {if $inIndex}class="active" {/if}href="{url 'IDF_Views_Admin::forge'}">{trans 'Frontpage'}</a>
{/block}
src/IDF/templates/idf/gadmin/forge/index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{extends "idf/gadmin/forge/base.html"}
{block docclass}yui-t3{assign $inIndex=true}{/block}
{block body}
<form method="post" action=".">
<table class="form" summary="">
<colgroup>
<col width="20" />
<col width="*" />
</colgroup>
<tr>
<td>{$form.f.enabled|unsafe}</td>
<td>
{$form.f.enabled.labelTag}
{if $form.f.enabled.errors}{$form.f.enabled.fieldErrors}{/if}
</td>
</tr>
<tr>
<td colspan="2">
{if $form.f.content.errors}{$form.f.content.fieldErrors}{/if}
{$form.f.content|unsafe}
</td>
<tr>
<td colspan="2">
<input type="submit" value="{trans 'Save Changes'}" name="submit" />
</td>
</tr>
</table>
</form>
<script type="text/javascript" charset="utf-8">
// <!-- {literal}
$(document).ready(function() {
var handler = function() {
if ($(this).is(':checked')) {
$('#id_content').removeAttr('readonly');
} else {
$('#id_content').attr('readonly', 'readonly');
}
};
$('#id_enabled').bind('click', handler);
handler.call($('#id_enabled'));
});
// {/literal} -->
</script>
{/block}
{block context}
<div class="issue-submit-info">
<p>{blocktrans}You can define a custom forge start page that is displayed instead of the standard project listing.{/blocktrans}</p>
</div>
{/block}
src/IDF/templates/idf/gadmin/home.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{extends "idf/gadmin/base.html"}
{block docclass}yui-t2{/block}
{block tabhome} class="active"{/block}
{block subtabs}
{trans 'Welcome'}
{/block}
{block body}
<p>{blocktrans}You have here access to the administration of the forge.{/blocktrans}</p>
{/block}
{block context}
{/block}
{block foot}<div id="branding">Powered by <a href="http://www.indefero.net" title="InDefero, bug tracking and more">InDefero</a>,<br />a <a href="http://www.ceondo.com">Céondo Ltd</a> initiative.</div>{/block}
src/IDF/templates/idf/index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{extends "idf/base-simple.html"}
{block docclass}yui-t2{/block}
{block tabhome} class="active"{/block}
{block subtabs}
<a href="{url 'IDF_Views::index'}" class="active">{trans 'Home'}</a> |
<a href="{url 'IDF_Views::listProjects', array('all', 'name')}" class="active">{trans 'Projects'}</a>
{/block}
{block body}
{markdown_forge $content}
{/block}
{block context}{/block}
{block foot}<div id="branding">Powered by <a href="http://www.indefero.net" title="InDefero, bug tracking and more">InDefero</a>,<br />a <a href="http://www.ceondo.com">Céondo Ltd</a> initiative.</div>{/block}
src/IDF/templates/idf/listProjects.html
11
22
3
4
53
64
75
......
4139
4240
4341
44
42
4543
4644
4745
......
5856
5957
6058
61
59
6260
6361
6462
65
63
6664
6765
6866
......
7270
7371
7472
75
73
7674
7775
78
76
7977
8078
8179
{extends "idf/base-simple.html"}
{block docclass}yui-t2{/block}
{block tabhome} class="active"{/block}
{block subtabs}<a href="{url 'IDF_Views::index'}" class="active">{trans 'Projects'}</a>{/block}
{block body}
{if $projects.count() == 0}
<p>{trans 'No projects managed with InDefero were found.'}</p>
{if count($tags) == 0}{trans 'n/a'}{else}
{foreach $p.get_tags_list() as $idx => $label}
{if $idx != 0}, {/if}
<a class="label" href="{url 'IDF_Views::listProjects', array($label->id, $order)}">{$label}</a>
<a class="label" href="{url 'IDF_Views::listProjectsByLabel', array($label->id, $order)}">{$label}</a>
{/foreach}
{/if}
</p>
<dl class="tagscloud smaller">{foreach $projectLabels as $class => $labels}
<dt class="label">{$class}</dt>
{foreach $labels as $idx => $label}
<dd><a href="{url 'IDF_Views::listProjects', array($label->id, $order)}" class="label" title="{blocktrans $label.project_count}1 project{plural}{$label.project_count} projects{/blocktrans}">{$label.name}{if $idx != count($labels) - 1},{/if}</a></dd>
<dd><a href="{url 'IDF_Views::listProjectsByLabel', array($label->id, $order)}" class="label" title="{blocktrans $label.project_count}1 project{plural}{$label.project_count} projects{/blocktrans}">{$label.name}{if $idx != count($labels) - 1},{/if}</a></dd>
{/foreach}
{/foreach}</dl>
{if $tag}
<p class="smaller"><a href="{url 'IDF_Views::listProjects', array('all', $order)}">
<p class="smaller"><a href="{url 'IDF_Views::listProjectsByLabel', array('all', $order)}">
{blocktrans}Remove filter for {$tag}{/blocktrans}</a></p>
{/if}
{/if}
{assign $labelPart = 'all'}
{if $tag}{assign $labelPart = $tag->id}{/if}
<p class="smaller">
{if $order != 'name'}<a href="{url 'IDF_Views::listProjects', array($labelPart, 'name')}">{/if}
{if $order != 'name'}<a href="{url 'IDF_Views::listProjectsByLabel', array($labelPart, 'name')}">{/if}
{trans 'By name'}{if $order != 'name'}</a>{/if}
&ndash;
{if $order != 'activity'}<a href="{url 'IDF_Views::listProjects', array($labelPart, 'activity')}">{/if}
{if $order != 'activity'}<a href="{url 'IDF_Views::listProjectsByLabel', array($labelPart, 'activity')}">{/if}
{trans 'By activity'}{if $order != 'activity'}</a>{/if}
</p>
<br />
src/IDF/templates/idf/main-menu.html
55
66
77
8
8
9
10
911
1012
1113
1214
13
15
1416
1517
1618
<li>{blocktrans}Welcome, <strong><a class="userw" href="{$url}">{$user}</a></strong>.{/blocktrans}
<a href="{url 'IDF_Views::logout'}">{trans 'Sign Out'}</a></li>{else}<li>
<a href="{url 'IDF_Views::login'}">{trans 'Sign in or create your account'}</a></li>
{/if}<li id="project-list"><a href="{url 'IDF_Views::index'}">{trans 'Project List'} &#x25be;</a>
{/if}{if $customForgePageEnabled}
<li><a href="{url 'IDF_Views::index'}">{trans 'Home'}</a></li>
{/if}<li id="project-list"><a href="{url 'IDF_Views::listProjects'}">{trans 'Project List'} &#x25be;</a>
{if $allProjects.count() != 0}
<ul>{foreach $allProjects as $p}
<li><a href="{url 'IDF_Views_Project::home', array($p.shortname)}"><img class="logo" src="{url 'IDF_Views_Project::logo', array($p.shortname)}" alt="{trans 'Project logo'}" />{if $p.private}<img class="lock" src="{media '/idf/img/lock.png'}" alt="{trans 'Private project'}" />{/if}{$p}</a></li>
{/foreach}</ul>
{/if}</li>{if $isAdmin}<li><a href="{url 'IDF_Views_Admin::projects'}">{trans 'Forge Management'}</a></li>{/if}<li>
{/if}</li>{if $isAdmin}<li><a href="{url 'IDF_Views_Admin::forge'}">{trans 'Forge Management'}</a></li>{/if}<li>
<a href="{url 'IDF_Views::faq'}" title="{trans 'Help and accessibility features'}">{trans 'Help'}</a></li>
</ul>

Archive Download the corresponding diff file

Page rendered in 0.11649s using 13 queries.