Unnamed Fossil Project

Check-in [245a3809ef]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added wiki.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:245a3809ef2e8cd286142897a7b0b73cf736f0e3
User & Date: Spravce 2012-11-22 23:38:43
Context
2012-12-24
21:24
serializace check-in: a8ad69229f user: Spravce tags: trunk
2012-11-22
23:38
Added wiki. check-in: 245a3809ef user: Spravce tags: trunk
2012-11-17
20:35
Added first version of roll implementation. check-in: 38001529be user: Spravce tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added brick/c.php.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
// Common shorthand
// Běžné zkratky
class brick_c
{
	protected function _show($tplName, $data)
	{
		return $this->framework->getView()->show($tplName, $data);
	}
	
	protected function _getLink($controller = null, $method = null, $args=array() )
	{
		return $this->framework->getRouter()->getLink($controller, $method, $args);
	}
	
	protected function _redirect($controller = null, $method = null, $args=array() )
	{
		$link = $this->framework->getRouter()->getLink($controller, $method, $args);
		header('Location: ' . $link);
	}
}

Added brick/markdown/wrapper.php.



















>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
<?php
class brick_markdown_wrapper
{
	function parse($markdown)
	{
		include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'markdown.php';
		return Markdown($markdown);
	}
}

Changes to c/wiki.php.

1
2
3


4
5


















































6









7
8












9
10
11
12
13
14

15
16
<?php
class c_wiki{




	function index(){


















































		$this->page("index");









	}
	












	function page($pg){
		$text=file_get_contents($this->framework->file_path."/doc/".$pg.".txt");
		
		$this->framework->view->assign("title",$pg);
		$this->framework->view->assign("text",$text);
		$this->framework->view->display("wiki");

	}
}

|
|
>
>

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
|
<
|
<
<
<
>


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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

83



84
85
86
<?php
class c_wiki extends brick_c
{
	public $title="Brickyard framework";
	public $menu='';

	function index()
	{
		$this->_redirect("wiki", "show", array("index"));
	}
	
	function show($page="index")
	{
		$content = 'Stránka nenalezena';
		$m=$this->_model();
		if ($m->pageExists($page)) {
			$content = $m->getPage($page);
		}
		
		$markdown = new brick_markdown_wrapper;
		$content = $markdown->parse($content);
		$this->_setMenu('show', $page);
		$this->_showContent($content);
	}
	
	function edit($page="index")
	{
		$content='';
		$preview=null;
		$m=$this->_model();
		$markdown = new brick_markdown_wrapper;
		
		if (isset($_POST['text'])) {
			if (isset($_POST['prev'])) {
				$content = $_POST['text'];
				$preview = $markdown->parse($_POST['text']);
			} else {
				$m->savePage($page, $_POST['text'], 'anonymous', $_POST['comment']);
				$this->_redirect('wiki','show', array($page));
			}
		} else {
			if ($m->pageExists($page)) { $content = $m->getPage($page); }
		}
		
		$editor = $this->_show(
			'wiki_edit',
			array(
				'action'=>$this->_getLink('wiki','edit',array($page)),
				'content'=>$content,
				'preview'=>$preview
			)
		);
		$this->_showContent($editor);
	}
	
	private function _showContent($content)
	{
		echo $this->_show(
			'bootstrap',
			array(
				'brand'=>$this->title,
				'brandURL'=>$this->_getLink('wiki', 'page', array('index')),
				'title'=>$this->title,
				'main'=>$content,
				'otherNavbarContent'=>$this->menu
			)
		);
	
	}
	
	private function _setMenu($mode, $page)
	{
		$out='<div class="pull-right btn-group">';
		if ($mode=="show") {
			$out.='<a href="'.$this->_getLink('wiki', 'edit', array($page)).'" class="btn"><i class="icon-pencil"></i></a>';
		}
		$out.='<a href="'.$this->_getLink('wiki', 'history', array($page)).'" class="btn" title="history"><i class="icon-film"></i></a>';
		$out.='</div>';
		$this->menu = $out;
	}
	
	function _model()

	{



		return new model_wiki($this->framework->indexPath . DIRECTORY_SEPARATOR . 'doc');
	}
}

Added model/wiki.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
class model_wiki
{
	private $_dataDir = '.';

	function __construct($dataDir)
	{
		$this->_dataDir = $dataDir;
	}
	
	private function _pageFN($page)
	{
		return $this->_dataDir . DIRECTORY_SEPARATOR . $page . '.md';
	}
	
	private function _logFN($page)
	{
		return $this->_dataDir . DIRECTORY_SEPARATOR . $page . '.log';
	}
	
	private function _revFN($page, $rev)
	{
		return $this->_dataDir . DIRECTORY_SEPARATOR . $page . '.' . $rev . '.rev';
	}
	
	function pageExists($page)
	{
		return file_exists($this->_pageFN($page));
	}
	
	function getPage($page)
	{
		if ($this->pageExists($page)) {
			return file_get_contents($this->_pageFN($page));
		}
		return null;
	}
	
	function savePage($page, $newText, $author='', $comment='')
	{
		$oldText = $this->getPage($page);
		if ($newText != $oldText) {
			$history = $this->getHistory($page);
			$revision = count($history);
			if (file_put_contents($this->_pageFN($page), $newText)) {
				file_put_contents($this->_revFN($page, $revision), $newText);
				$history[] = array(
					'date'=>date('Y-m-d'),
					'time'=>date('H:i:s'),
					'author'=>$author,
					'comment'=>$comment
				);
				file_put_contents($this->_logFN($page), json_encode($history));
			}
		}
	}
	
	function getHistory($page)
	{
		if (file_exists($this->_logFN($page))) {
			return json_decode(file_get_contents($this->_logFN($page)));
		} else {
			return array();
		}
	}
	
	
}

Added static/note.txt.



>
1
drop bootstrap framework to directory bootstrap here to see wiki styled

Added tpl/bootstrap.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
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title><?php echo $title; ?></title>
	<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
	<style>body {padding-top: 40px; padding-bottom: 40px;}</style>
</head>
<body id="top">
	<div class="navbar navbar-fixed-top navbar-inverse">
		<div class="navbar-inner">
			<div class="container">
				<?php
				if (isset($brand)) {
					if (isset($brandURL)) {
						echo '<a href="' . $brandURL . '" class="brand">' . $brand . '</a>';
					} else {
						echo '<span class="brand">' . $brand . '</span>';
					}
				}
				if (isset($menu)) {
					echo '<ul class="nav">';
					foreach ($menu as $url=>$item) {
						echo '<li><a href="'. $url .'">' . $item . '</a></li>';
					}
					echo '</ul>';
				}
				if (isset($otherNavbarContent)) {
					echo $otherNavbarContent;
				}
				?>
			</div>
		</div>
	</div>
	<div class="container">
		<?php echo $main; ?>
	</div>
</body>
</html>

Added tpl/wiki_edit.php.





























>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php if (isset($preview)):?>
<div class="draft"><?php echo $preview; ?></div>
<small>This is only preview.</small>
<hr>
<?php endif; ?>
<form action="<?php echo $action; ?>" method="post">
<textarea name="text" rows="15" style="width: 100%">
<?php echo $content; ?>
</textarea><br>
<input type="submit" name="save" value="Save" class="btn btn-primary">
<input type="submit" name="prev" value="Preview" class="btn"> 
Comment: 
<input name="comment">
</form>