summaryrefslogtreecommitdiff
path: root/liberty_plugins/data.articles.php
blob: 93d67bdbd26191c188f5bf78bf10fbda294abc75 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
 * @version  $Revision$
 * @package  liberty
 * @subpackage plugins_data
 */
// +----------------------------------------------------------------------+
// | Copyright (c) 2004, bitweaver.org
// +----------------------------------------------------------------------+
// | All Rights Reserved. See below for details and a complete list of authors.
// | Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
// |
// | For comments, please use phpdocu.sourceforge.net documentation standards!!!
// | -> see http://phpdocu.sourceforge.net/
// +----------------------------------------------------------------------+
// | Author (TikiWiki): Gustavo Muslera <gmuslera@users.sourceforge.net>
// | Reworked for Bitweaver (& Undoubtedly Screwed-Up)
// | by: StarRider <starrrider@users.sourceforge.net>
// | Reworked from: wikiplugin_articles.php - see deprecated code below
// +----------------------------------------------------------------------+
// $Id$

/**
 * definitions
 */
global $gBitSystem, $gBitSmarty;
define( 'PLUGIN_GUID_DATAARTICLES', 'dataarticles' );
global $gLibertySystem;
$pluginParams = array (
	'tag' => 'ARTICLES',
	'auto_activate' => FALSE,
	'requires_pair' => FALSE,
	'load_function' => 'data_articles',
	'help_function' => 'data_articles_help',
	'title' => 'Articles',
	'help_page' => 'DataPluginArticles',
	'description' => tra( "This plugin will display several Articles." ),
	'syntax' => "{ARTICLES max= topic= type= }",
	'plugin_type' => DATA_PLUGIN
);
$gLibertySystem->registerPlugin( PLUGIN_GUID_DATAARTICLES, $pluginParams );
$gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATAARTICLES );

// Help Routine
function data_articles_help()
{
	$help =
		'<table class="data help">'
			.'<tr>'
				.'<th>' . tra( "Key" ) . '</th>'
				.'<th>' . tra( "Type" ) . '</th>'
				.'<th>' . tra( "Comments" ) . '</th>'
			.'</tr>'
			.'<tr class="odd">'
				.'<td>max</td>'
				.'<td>' . tra( "numeric") . '<br />' . tra("(optional)") . '</td>'
				.'<td>' . tra( "The number of Articles to be displayed. (Default = 3)") . '</td>'
			.'</tr>'
			.'<tr class="even">'
				.'<td>topic</td>'
				.'<td>' . tra( "topic name") . '<br />' . tra("(optional)") . '</td>'
				.'<td>' . tra( "Filters the Articles so that only the Topic specified is displayed") . '</td>'
			.'</tr>'
			.'<tr class="odd">'
				.'<td>type</td>'
				.'<td>' . tra( "type name") . '<br />' . tra("(optional)") . '</td>'
				.'<td>' . tra( "Filters the Articles so that only the Type specified is displayed") . '</td>'
			.'</tr>'
			.'<tr class="even">'
				.'<td>format</td>'
				.'<td>' . tra( "string") . '<br />' . tra("(optional)") . '</td>'
				.'<td>' . tra( "Specify format for article display - options: full, list (default)") . '</td>'
			.'</tr>'
		.'</table>'
		. tra("Example: ") . "{ARTICLES max=5 topic='some_topic'}<br />"
		. tra("Example: ") . "{ARTICLES max=5 type='some_type'}";
	return $help;
}

// Executable Routine
function data_articles($data, $params) { // No change in the parameters with Clyde
	global $gLibertySystem, $gBitSmarty, $gBitSystem;
	if( $gBitSystem->isPackageActive( 'articles' ) ) { // Do not include this Plugin if the Package is not active
		// The next 2 lines allow access to the $pluginParams given above and may be removed when no longer needed
		$pluginParams = $gLibertySystem->mPlugins[PLUGIN_GUID_DATAARTICLES];

		require_once( ARTICLES_PKG_CLASS_PATH.'BitArticle.php');
		require_once( LIBERTY_PKG_PATH.'lookup_content_inc.php' );

		$module_params = $params;
		$articlesObject = new BitArticle();
		$stati = array( 'pending', 'approved' );
		if( !empty( $module_params['status'] ) && in_array( $module_params['status'], $stati ) ) {
			$status_id = constant( 'ARTICLE_STATUS_'.strtoupper( $module_params['status'] ) );
		} else {
			$status_id = ARTICLE_STATUS_APPROVED;
		}

		$sortOptions = array(
			"last_modified_asc",
			"last_modified_desc",
			"created_asc",
			"created_desc",
			"random",
		);
		if( !empty( $module_params['sort_mode'] ) && in_array( $module_params['sort_mode'], $sortOptions ) ) {
			$sort_mode = $module_params['sort_mode'];
		} else {
			$sort_mode = 'last_modified_desc';
		}

		$getHash = Array();
		$getHash['status_id']     = $status_id;
		$getHash['sort_mode']     = $sort_mode;
		$getHash['max_records']   = empty( $module_params['max'] ) ? 1 : $module_params['max'];
		if( isset( $module_params['topic'] )) {
			$getHash['topic']     = !empty( $module_params['topic'] ) ? $module_params['topic'] : NULL;
		}
		if( isset( $module_params['topic_id'] )) {
			$getHash['topic_id']  = $module_params['topic_id'];
		}
		$articles_results = $articlesObject->getList( $getHash );

		$display_format = empty( $module_params['format'] ) ? 'simple_title_list' : $module_params['format'];
		$display_result = "";

		switch( $display_format ) {
			case 'full':
				$display_result = '<div class="articles">';
				$gBitSmarty->assign( 'showDescriptionsOnly', TRUE );
				foreach( $articles_results as $article ) {
					$gBitSmarty->assign( 'article', $article );
					$gBitSmarty->assign( 'gContent', $articlesObject );
					$display_result .= $gBitSmarty->fetch( 'bitpackage:articles/article_display.tpl' );
				}
				$display_result .= '</div>';
				$display_result = eregi_replace( "\n", "", $display_result );
				break;
			case 'list':
			default:
				$display_result = "<ul>";
				foreach( $articles_results as $article ) {
					$link = $articlesObject->getdisplaylink( $article['title'], $article );
					$display_result .= "<li>$link</li>\n";
				}
				$display_result .= "</ul>\n";
				break;
		}
		return $display_result;
	} else {
		return "<div class=error>The articles package is not active.</div>";
	}
}