Initial commit

This commit is contained in:
Nathan Adams
2013-07-20 17:41:56 -05:00
commit 3b1e713fc4
606 changed files with 136001 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
<?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 ***** */
/**
* AppVersion tag.
*
* Renders two meta tags that include the application's version and revision
*/
class IDF_Template_AppVersion extends Pluf_Template_Tag
{
function start($file = 'IDF/version.php')
{
if (!Pluf::fileExists($file)) {
return;
}
$info = include_once($file);
if (!is_array($info)) {
return;
}
if (array_key_exists('version', $info)) {
echo '<meta name="indefero-version" content="'.$info['version'].'" />'."\n";
}
if (array_key_exists('revision', $info)) {
if (strpos($info['revision'], '$') !== false) {
$info['revision'] = 'unknown';
$cmd = Pluf::f('idf_exec_cmd_prefix', '').
Pluf::f('git_path', 'git').
' log -1 --format=%H';
if (IDF_Scm::exec('IDF_Template_AppVersion::start', $cmd, $output)) {
$info['revision'] = trim(@$output[0]);
}
}
echo '<meta name="indefero-revision" content="'.$info['revision'].'" />'."\n";
}
}
}

View File

@@ -0,0 +1,55 @@
<?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_HTTP_URL_urlForView');
/**
* Show the name of a user in a template.
*
* It will automatically make the link to the profile if needed. In
* the future it will allow us to add little badges on the side of the
* user based on karma or whatever.
*
* This will also provide a consistent display of a user name in the
* application.
*/
class IDF_Template_AssignShowUser extends Pluf_Template_Tag
{
/**
* We need the user object and the request.
*
* If the user object is null (for example a non associated
* commit), we can use the $text value for an alternative display.
*
* @param string Which variable to assign
* @param Pluf_User
* @param Pluf_HTTP_Request
* @param string Alternate text ('')
*/
function start($var, $user, $request, $text='')
{
$t = new IDF_Template_ShowUser($this->context);
$this->context->set($var,
Pluf_Template::markSafe($t->start($user, $request, $text, false)));
}
}

View File

@@ -0,0 +1,36 @@
<?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_HTTP_URL_urlForView');
/**
* Hotkey tag.
*/
class IDF_Template_HotKey extends Pluf_Template_Tag
{
function start($key, $view, $params=array(), $get_params=array())
{
$url = addslashes(Pluf_HTTP_URL_urlForView($view, $params, $get_params));
echo "$(document).bind('keydown','$key',function (){window.location.href='$url';});";
}
}

View File

@@ -0,0 +1,255 @@
<?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_HTTP_URL_urlForView');
Pluf::loadFunction('IDF_Template_safePregReplace');
/**
* Make the links to issues and commits.
*/
class IDF_Template_IssueComment extends Pluf_Template_Tag
{
private $project = null;
private $request = null;
private $scm = null;
function start($text, $request, $echo=true, $wordwrap=true, $esc=true, $autolink=true, $nl2br=false)
{
$this->project = $request->project;
$this->request = $request;
$this->scm = IDF_Scm::get($request->project);
if ($esc) $text = Pluf_esc($text);
if ($autolink) {
$text = IDF_Template_safePregReplace('#([a-z]+://[^\s\(\)]+)#i',
'<a href="\1">\1</a>', $text);
}
if ($request->rights['hasIssuesAccess']) {
$text = IDF_Template_safePregReplace('#((?:issue|bug|ticket)(s)?\s+|\s+\#)(\d+)(\#ic\d+)?(?(2)((?:[, \w]+(?:\s+\#)?)?\d+(?:\#ic\d+)?){0,})#im',
array($this, 'callbackIssues'), $text);
}
if ($request->rights['hasReviewAccess']) {
$text = IDF_Template_safePregReplace('#(reviews?\s+)(\d+(?:(?:\s+and|\s+or|,)\s+\d+)*)\b#i',
array($this, 'callbackReviews'), $text);
}
if ($request->rights['hasSourceAccess']) {
$verbs = array('added', 'fixed', 'reverted', 'changed', 'removed');
$nouns = array('commit', 'commits', 'revision', 'revisions', 'rev', 'revs');
$prefix = implode(' in|', $verbs).' in' . '|'.
implode('|', $nouns);
$text = IDF_Template_safePregReplace('#((?:'.$prefix.')(?:\s+r?))([0-9a-f]{1,40}((?:\s+and|\s+or|,)\s+r?[0-9a-f]{1,40})*)\b#i',
array($this, 'callbackCommits'), $text);
$text = IDF_Template_safePregReplace('=(src:)([^\s@#,\(\)\\\\]+(?:(\\\\)[\s@#][^\s@#,\(\)\\\\]+){0,})+(?:\@([^\s#,]+))?(?:#(\d+))?=im',
array($this, 'callbackSource'), $text);
}
if ($wordwrap) $text = Pluf_Text::wrapHtml($text, 69, "\n");
if ($nl2br) $text = nl2br($text);
if ($echo) {
echo $text;
} else {
return $text;
}
}
/**
* General call back for the issues.
*/
function callbackIssues($m)
{
$c = count($m);
if (4 === $c || 5 === $c) {
$issue = new IDF_Issue($m[3]);
if (0 < $issue->id and $issue->project == $this->project->id) {
$m[1] = trim($m[1]);
$prefix = '';
if ('#' === $m[1]) {
$title = $m[1].$m[3];
$prefix = mb_substr($m[0], 0, strpos($m[0], $m[1])); // fixes \n matches
} else {
$title = $m[1].' '.$m[3];
}
if (4 === $c) {
return $prefix.$this->linkIssue($issue, $title);
} else {
return $prefix.$this->linkIssue($issue, $title, $m[4]);
}
}
return $m[0]; // not existing issue.
}
return IDF_Template_safePregReplace('#(\#)?(\d+)(\#ic\d+)?#',
array($this, 'callbackIssue'),
$m[0]);
}
/**
* Call back for the case of multiple issues like 'issues 1, 2 and 3'.
*
* Called from callbackIssues, it is linking only the number of
* the issues.
*/
function callbackIssue($m)
{
$issue = new IDF_Issue($m[2]);
if (0 < $issue->id and $issue->project == $this->project->id) {
if (4 === count($m)) {
return $this->linkIssue($issue, $m[1].$m[2], $m[3]);
}
return $this->linkIssue($issue, $m[1].$m[2]);
}
return $m[0]; // not existing issue.
}
/**
* General call back to convert commits to HTML links.
*
* @param array $m Single regex match.
* @return string Content with converted commits.
*/
function callbackCommits($m)
{
$keyword = rtrim($m[1]);
if (empty($m[3])) {
// Single commit like 'commit 6e030e6'.
return $m[1].call_user_func(array($this, 'callbackCommit'), array($m[2]));
}
// Multiple commits like 'commits 6e030e6, a25bfc1 and 3c094f8'.
return $m[1].IDF_Template_safePregReplace('#\b[0-9a-f]{1,40}\b#i', array($this, 'callbackCommit'), $m[2]);
}
/**
* Convert plaintext commit to HTML link. Called from callbackCommits.
*
* Regex callback for {@link IDF_Template_IssueComment::callbackCommits()}.
*
* @param array Single regex match.
* @return string HTML A element with commit.
*/
function callbackCommit($m)
{
$co = $this->scm->getCommit($m[0]);
if (!$co) {
return $m[0]; // not a commit.
}
return '<a href="'
.Pluf_HTTP_URL_urlForView('IDF_Views_Source::commit', array($this->project->shortname, $co->commit))
.'">'.$m[0].'</a>';
}
/**
* General call back to convert reviews to HTML links.
*
* @param array $m Single regex match.
* @return string Content with converted reviews.
*/
function callbackReviews($m)
{
$keyword = rtrim($m[1]);
if ('reviews' === $keyword) {
return $m[1].IDF_Template_safePregReplace('#\b(\d+)\b#i', array($this, 'callbackReview'), $m[2]);
} else if ('review' === $keyword) {
return $m[1].call_user_func(array($this, 'callbackReview'), array('', $m[2]));
}
return $m[0];
}
/**
* Convert plaintext commit to HTML link. Called from callbackReviews.
*
* Regex callback for {@link IDF_Template_IssueComment::callbackReviews()}.
*
* @param array Single regex match.
* @return string HTML A element with review.
*/
function callbackReview($m)
{
$review = new IDF_Review($m[1]);
if ($review->id > 0 and $review->project == $this->project->id) {
return $this->linkReview($review, $m[1]);
} else {
return $m[0]; // not existing issue.
}
}
function callbackSource($m)
{
if (!$this->scm->isAvailable())
return $m[0];
$commit = null;
if (!empty($m[4])) {
if (!$this->scm->getCommit($m[4])) {
return $m[0];
}
$commit = $m[4];
}
$file = $m[2];
if (!empty($m[3]))
$file = str_replace($m[3], '', $file);
$linktext = $file;
if (!empty($commit))
$linktext .= '@'.$commit;
$request_file_info = $this->scm->getPathInfo($file, $commit);
if (!$request_file_info) {
return $m[0];
}
if ($request_file_info->type == 'tree') {
return $m[0];
}
$link = Pluf_HTTP_URL_urlForView('IDF_Views_Source::tree', array(
$this->project->shortname,
$commit == null ? $this->scm->getMainBranch() : $commit,
$file
));
if (!empty($m[5])) {
$link .= '#L'.$m[5];
$linktext .= '#'.$m[5];
}
return $m[1].'<a href="'.$link.'">'.$linktext.'</a>';
}
/**
* Generate the link to an issue.
*
* @param IDF_Issue Issue.
* @param string Name of the link.
* @return string Linked issue.
*/
public function linkIssue($issue, $title, $anchor='')
{
$ic = (in_array($issue->status, $this->project->getTagIdsByStatus('closed'))) ? 'issue-c' : 'issue-o';
return '<a href="'.Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view',
array($this->project->shortname, $issue->id)).$anchor.'" class="'.$ic.'" title="'.Pluf_esc($issue->summary).'">'.Pluf_esc($title).'</a>';
}
/**
* Generate the link to a review.
*
* @param IDF_Review Review.
* @param string Name of the link.
* @return string Linked review.
*/
public function linkReview($review, $title, $anchor='')
{
$ic = (in_array($review->status, $this->project->getTagIdsByStatus('closed'))) ? 'issue-c' : 'issue-o';
return '<a href="'.Pluf_HTTP_URL_urlForView('IDF_Views_Review::view',
array($this->project->shortname, $review->id)).$anchor.'" class="'.$ic.'" title="'.Pluf_esc($review->summary).'">'.Pluf_esc($title).'</a>';
}
}

View File

@@ -0,0 +1,199 @@
<?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');
Pluf::loadFunction('IDF_Template_safePregReplace');
/**
* Make the links to issues and commits.
*/
class IDF_Template_Markdown extends Pluf_Template_Tag
{
private $project = null;
private $request = null;
private $scm = null;
function start($text, $request)
{
$this->project = $request->project;
$this->request = $request;
// Replace like in the issue text
$tag = new IDF_Template_IssueComment();
$text = $tag->start($text, $request, false, false, false, false);
// Replace [[[path/to/file.mdtext, commit]]] with embedding
// the content of the file into the wki page
if ($this->request->rights['hasSourceAccess']) {
$text = IDF_Template_safePregReplace('#\[\[\[([^\,]+)(?:, ([^/]+))?\]\]\]#im',
array($this, 'callbackEmbeddedDoc'),
$text);
}
// Replace [Page]([[PageName]]) with corresponding link to the page, with link text being Page.
$text = IDF_Template_safePregReplace('#\[([^\]]+)\]\(\[\[([A-Za-z0-9\-]+)\]\]\)#im',
array($this, 'callbackWikiPage'),
$text);
// Replace [[PageName]] with corresponding link to the page.
$text = IDF_Template_safePregReplace('#\[\[([A-Za-z0-9\-]+)\]\]#im',
array($this, 'callbackWikiPageNoName'),
$text);
$filter = new IDF_Template_MarkdownPrefilter();
$text = $filter->go(Pluf_Text_MarkDown_parse($text));
// Replace [[!ResourceName]] with corresponding HTML for the resource;
// we need to do that after the HTML filtering as we'd otherwise be unable to use
// certain HTML elements, such as iframes, that are used to display text content
// FIXME: no support for escaping yet in place
echo IDF_Template_safePregReplace('#\[\[!([A-Za-z0-9\-]+)(?:,\s*([^\]]+))?\]\]#im',
array($this, 'callbackWikiResource'),
$text);
}
function callbackWikiPageNoName($m)
{
$m[2] = $m[1]; //Set the link text to be the same as the page name.
return $this->callbackWikiPage($m);
}
function callbackWikiPage($m)
{
$sql = new Pluf_SQL('project=%s AND title=%s',
array($this->project->id, $m[2]));
$pages = Pluf::factory('IDF_Wiki_Page')->getList(array('filter'=>$sql->gen()));
if ($pages->count() != 1 and $this->request->rights['hasWikiAccess']
and !$this->request->user->isAnonymous()) {
return '<img style="vertical-align: text-bottom;" alt=" " src="'.Pluf::f('url_media').'/idf/img/add.png" /><a href="'.Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::createPage', array($this->project->shortname), array('name'=>$m[2])).'" title="'.__('Create this documentation page').'">'.$m[1].'</a>';
}
if (!$this->request->rights['hasWikiAccess'] or $pages->count() == 0) {
return $m[1];
}
return '<a href="'.Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::viewPage', array($this->project->shortname, $pages[0]->title)).'" title="'.Pluf_esc($pages[0]->summary).'">'.$m[1].'</a>';
}
function callbackWikiResource($m)
{
@list($match, $resourceName, $opts) = $m;
if (!$this->request->rights['hasWikiAccess']) {
return '<span title="'.__('You are not allowed to access the wiki.').'">'.$match.'</span>';
}
$sql = new Pluf_SQL('project=%s AND title=%s',
array($this->project->id, $resourceName));
$resources = Pluf::factory('IDF_Wiki_Resource')->getList(array('filter'=>$sql->gen()));
if ($resources->count() == 0) {
if ($this->request->user->isAnonymous()) {
return '<span title="'.__('The wiki resource has not been found.').'">'.$match.'</span>';
}
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::createResource',
array($this->project->shortname),
array('name' => $resourceName));
return '<img style="vertical-align: text-bottom;" alt=" " src="'.Pluf::f('url_media').'/idf/img/add.png" />'.
'<a href="'.$url.'" title="'.__('The wiki resource has not been found. Create it!').'">'.$match.'</a>';
}
// by default, render the most recent revision
$resourceRevision = $resources[0]->get_current_revision();
list($urlConf, $urlMatches) = $this->request->view;
// if we currently look at an existing wiki page, look up its name and find the proper resource (if any)
if ($urlConf['model'] == 'IDF_Views_Wiki' && $urlConf['method'] == 'viewPage') {
$sql = new Pluf_SQL('project=%s AND title=%s',
array($this->project->id, $urlMatches[2]));
$pages = Pluf::factory('IDF_Wiki_Page')->getList(array('filter'=>$sql->gen()));
if ($pages->count() == 0) throw new Exception('page not found');
$pageRevision = $pages[0]->get_current_revision();
// if we look at an old version of the page, figure out the resource version back then
if (isset($this->request->GET['rev']) and preg_match('/^[0-9]+$/', $this->request->GET['rev'])) {
$pageRevision = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_PageRevision',
$this->request->GET['rev']);
// this is actually an invariant since we came so far looking at
// and rendering the old revision already
if ($pageRevision == null) {
throw new Exception('page revision with id '.$this->request->GET['rev'].' not found');
}
}
$sql = new Pluf_SQL('wikiresource=%s AND idf_wiki_pagerevision_id=%s',
array($resources[0]->id, $pageRevision->id));
$resourceRevision = Pluf::factory('IDF_Wiki_ResourceRevision')->getOne(
array('filter' => $sql->gen(), 'view' => 'join_pagerevision'));
if ($resourceRevision == null) {
return '<span title="'.__('This revision of the resource is no longer available.').'">'.$match.'</span>';
}
}
$validOpts = array(
'align' => '/^(left|right|center)$/',
'width' => '/^\d+(%|px|em)?$/',
'height' => '/^\d+(%|px|em)?$/',
'preview' => '/^yes|no$/',
'title' => '/.+/',
);
$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;
}
return $resourceRevision->render($parsedOpts);
}
function callbackEmbeddedDoc($m)
{
$scm = IDF_Scm::get($this->request->project);
if (!$scm->isAvailable()) {
return $m[0];
}
$view_source = new IDF_Views_Source();
$match = array('dummy', $this->request->project->shortname);
$match[] = (isset($m[2])) ? $m[2] : $scm->getMainBranch();
$match[] = $m[1];
$res = $view_source->getFile($this->request, $match);
if ($res->status_code != 200) {
return $m[0];
}
$info = pathinfo($m[1]);
$fileinfo = array($res->headers['Content-Type'], $m[1],
isset($info['extension']) ? $info['extension'] : 'bin');
if (!IDF_FileUtil::isText($fileinfo)) {
return $m[0];
}
return $res->content;
}
}

View File

@@ -0,0 +1,119 @@
<?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');
Pluf::loadFunction('IDF_Template_safePregReplace');
class IDF_Template_MarkdownForge extends Pluf_Template_Tag
{
private $request;
public function start($text, $request)
{
$this->request = $request;
$filter = new IDF_Template_MarkdownPrefilter();
$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];
}
$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 IS NULL',
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);
}
}

View File

@@ -0,0 +1,214 @@
<?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 ***** */
/**
* Should be renamed MarkdownPostfilter.
*/
class IDF_Template_MarkdownPrefilter extends Pluf_Text_HTML_Filter
{
public $allowed_entities = array(
'amp',
'gt',
'lt',
'quot',
'nbsp',
'ndash',
'rdquo',
'ldquo',
'Alpha',
'Beta',
'Gamma',
'Delta',
'Epsilon',
'Zeta',
'Eta',
'Theta',
'Iota',
'Kappa',
'Lambda',
'Mu',
'Nu',
'Xi',
'Omicron',
'Pi',
'Rho',
'Sigma',
'Tau',
'Upsilon',
'Phi',
'Chi',
'Psi',
'Omega',
'alpha',
'beta',
'gamma',
'delta',
'epsilon',
'zeta',
'eta',
'theta',
'iota',
'kappa',
'lambda',
'mu',
'nu',
'xi',
'omicron',
'pi',
'rho',
'sigmaf',
'sigma',
'tau',
'upsilon',
'phi',
'chi',
'psi',
'omega',
'thetasym',
'upsih',
'piv',
);
public $allowed = array(
'a' => array('class', 'dir', 'id', 'style', 'title',
'href', 'hreflang', 'rel'),
'abbr' => array('class', 'dir', 'id', 'style', 'title'),
'address' => array('class', 'dir', 'id', 'style', 'title'),
'b' => array('class', 'dir', 'id', 'style', 'title'),
'blockquote' => array('class', 'dir', 'id', 'style', 'title',
'cite'),
'br' => array('class', 'id', 'style', 'title'),
'caption' => array('class', 'dir', 'id', 'style', 'title',
'align'), // deprecated attribute),
'code' => array('class', 'dir', 'id', 'style', 'title'),
'dd' => array('class', 'dir', 'id', 'style', 'title'),
'del' => array('class', 'dir', 'id', 'style', 'title',
'cite', 'datetime'),
'div' => array('class', 'dir', 'id', 'style', 'title',
'align'), // deprecated attribute
'dl' => array('class', 'dir', 'id', 'style', 'title'),
'dt' => array('class', 'dir', 'id', 'style', 'title'),
'em' => array('class', 'dir', 'id', 'style', 'title'),
'font' => array('class', 'dir', 'id', 'style', 'title', // deprecated element
'color', 'face', 'size'), // deprecated attribute
'h1' => array('class', 'dir', 'id', 'style', 'title',
'align'), // deprecated attribute
'h2' => array('class', 'dir', 'id', 'style', 'title',
'align'), // deprecated attribute
'h3' => array('class', 'dir', 'id', 'style', 'title',
'align'), // deprecated attribute
'h4' => array('class', 'dir', 'id', 'style', 'title',
'align'), // deprecated attribute
'h5' => array('class', 'dir', 'id', 'style', 'title',
'align'), // deprecated attribute
'h6' => array('class', 'dir', 'id', 'style', 'title',
'align'), // deprecated attribute
'hr' => array('class', 'dir', 'id', 'style', 'title',
'align', 'noshade', 'size', 'width'), // deprecated attribute
'i' => array('class', 'dir', 'id', 'style', 'title'),
'img' => array('class', 'dir', 'id', 'style', 'title',
'src', 'alt', 'height', 'width'),
'ins' => array('class', 'dir', 'id', 'style', 'title',
'cite', 'datetime'),
'li' => array('class', 'dir', 'id', 'style', 'title',
'type'), // deprecated attribute
'ol' => array('class', 'dir', 'id', 'style', 'title',
'type'), // deprecated attribute
'p' => array('class', 'dir', 'id', 'style', 'title',
'align'), // deprecated attribute
'pre' => array('class', 'dir', 'id', 'style', 'title',
'width'), // deprecated attribute
'strong' => array('class', 'dir', 'id', 'style', 'title'),
'table' => array('class', 'dir', 'id', 'style', 'title',
'border', 'cellpadding', 'cellspacing', 'frame', 'rules', 'summary', 'width',
'align', 'bgcolor'), // deprecated attribute
'td' => array('class', 'dir', 'id', 'style', 'title',
'align', 'colspan', 'headers', 'rowspan', 'scope', 'valign',
'bgcolor', 'height', 'nowrap', 'width'), // deprecated attribute
'th' => array('class', 'dir', 'id', 'style', 'title',
'align', 'colspan', 'rowspan', 'scope', 'valign',
'bgcolor', 'height', 'nowrap', 'width'), // deprecated attribute
'tr' => array('class', 'dir', 'id', 'style', 'title',
'align', 'valign',
'bgcolor'), // deprecated attribute
'ul' => array('class', 'dir', 'id', 'style', 'title',
'type'), // deprecated attribute
);
// tags which should always be self-closing (e.g. "<img />")
public $no_close = array(
'img',
'br',
'hr',
);
// tags which must always have seperate opening and closing tags
// (e.g. "<b></b>")
public $always_close = array(
'strong',
'em',
'b',
'code',
'i',
'ul',
'ol',
'li',
'p',
'table',
'caption',
'tr',
'td',
'span',
'a',
'blockquote',
'pre',
'iframe',
'h1', 'h2', 'h3', 'address',
'del',
'ins',
);
// attributes which should be checked for valid protocols
public $protocol_attributes = array(
'src',
'href',
);
// protocols which are allowed
public $allowed_protocols = array(
'http',
'https',
'ftp',
'mailto',
'irc'
);
// tags which should be removed if they contain no content
// (e.g. "<b></b>" or "<b />")
public $remove_blanks = array(
'p',
'strong',
'em',
'caption',
'li',
'span',
'del',
'ins',
);
}

View File

@@ -0,0 +1,67 @@
<?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_HTTP_URL_urlForView');
/**
* Show the name of a user in a template.
*
* It will automatically make the link to the profile if needed. In
* the future it will allow us to add little badges on the side of the
* user based on karma or whatever.
*
* This will also provide a consistent display of a user name in the
* application.
*/
class IDF_Template_ShowUser extends Pluf_Template_Tag
{
/**
* We need the user object and the request.
*
* If the user object is null (for example a non associated
* commit), we can use the $text value for an alternative display.
*
* @param Pluf_User
* @param Pluf_HTTP_Request
* @param string Alternate text ('')
*/
function start($user, $request, $text='', $echo=true)
{
if ($user == null) {
$out = (strlen($text)) ? strip_tags($text) : __('Anonymous');
} else {
if (!$user->isAnonymous() and $user->id == $request->user->id) {
$utext = __('Me');
$url = Pluf_HTTP_URL_urlForView('idf_dashboard');
} else {
$utext = Pluf_esc($user);
$url = Pluf_HTTP_URL_urlForView('IDF_Views_User::view',
array($user->login));
}
$out = sprintf('<a href="%s" class="username">%s</a>',
$url, $utext);
}
if ($echo) echo $out;
else return $out;
}
}

View File

@@ -0,0 +1,35 @@
<?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) 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 ***** */
class IDF_Template_Tag_UploadUrl extends Pluf_Template_Tag
{
function start($file='')
{
echo IDF_Template_Tag_UploadUrl::url($file);
}
public static function url($file='')
{
return Pluf::f('url_upload', Pluf_Template_Tag_MediaUrl::url() . '/upload') . $file;
}
}

View File

@@ -0,0 +1,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 ***** */
/**
* Make the links to issues and commits.
*/
class IDF_Template_TimelineFragment extends Pluf_Template_Tag
{
function start($item, $request)
{
$m = Pluf::factory($item->model_class, $item->model_id);
echo $m->timelineFragment($request);
}
}