summaryrefslogtreecommitdiff
path: root/smartyplugins/function.include_wiki_page_content.php
blob: 4b5b34e266de3a1f65d6a4d48eb36cdf18bf043a (plain)
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
<?php
namespace Bitweaver\Plugins;

use \Bitweaver\Wiki\BitPage;

/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/** \file
 * $Header: 
 *
 * \author jht <jht@lj.net>
 */

/**
 * \brief Smarty plugin to include specified wiki page content (transclusion)
 * Usage format {include_wiki_page_content page=>'name of page' }
 * or {include_wiki_page_content page=>'name of page' page_default='name of another page' }
 */

#
# This fuction provides transclusion in page templates.	To use transclusion
# inside of content, use the Liberty 'include' plugin
#
# ( Transclusion is including information from one document into another.
# For more on Transclusion - see: http://en.wikipedia.org/wiki/Wikipedia:Transclusion )
#
# This function can be used in any wiki template to include the content of any arbitrary
# wiki page.	There are many possible uses.
# For example, when editing pages, you want to include custom editing instructions
# but want these instructions to be easily updatable by any wiki user.
# Adding this line to the wiki/templates/edit_page.tpl file will automatically display
# the content of the page named: 'edit notice' whenever a wiki page is edited:
#
#	 {include_wiki_page_content page="edit notice"}
#
# Suppose that instead of a global notice that is the same for all pages, you want
# custom tailored notices specific to each page, and want to display a default
# notice for pages that don't have a custom notice defined.
# Example: whenever a page named "ABC" is edited you would like to display this notice:
# 	"Please Keep the Lists on this Page Alphabetical!"
#
# Step 1: Create a new page named: "ABC - edit notice" containing the notice
# The content of this page is the notice that you want shown whenever the page "ABC" is edited.
# The notice can be any length and include wiki markup.
#
# Step 2: Create a new page named something like: "default edit notice"
# The content of this page is the notice that you want shown whenever a page without a custom edit notices is edited.
# The notice can be any length and include wiki markup.
#
# Step 3: Include the following line in the wiki/edit_page.tpl file at the point where you want the notice displayed:
#
#{include_wiki_page_content page="`$gContent->mInfo.original_title` - edit notice" page_default="default edit notice"}
#
# Now whenever "ABC" is edited the custom notice will be displayed on the edit page.
# Editing any other page will display the default edit notice.
#

function smarty_function_include_wiki_page_content($params, &$gBitSmarty)
{
	$parsed = '';
	//
	if( ($pageName = !empty( $params['page'] ) ? $params['page'] : (!empty( $params['page_default'] ) ? $params['page_default'] : NULL )) ) {
		include_once WIKI_PKG_CLASS_PATH.'BitPage.php';
		if( $includePage = BitPage::lookupObject( [ 'page' => $pageName ] ) ) {
			$parsed = $includePage->getParsedData();
		}
	}

	return $parsed;
}