tiki-read_article.php 10.7 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
6
//
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9
// $Id$
changi67's avatar
changi67 committed
10

11
$section = 'cms';
12
require_once ('tiki-setup.php');
lphuberdeau's avatar
lphuberdeau committed
13
$artlib = TikiLib::lib('art');
14
$access->check_feature('feature_articles');
15 16
if (!isset($_REQUEST["articleId"])) {
	$smarty->assign('msg', tra("No article indicated"));
17 18 19
	$smarty->display("error.tpl");
	die;
}
20 21 22

$parserlib = TikiLib::lib('parser');

23
$article_data = $artlib->get_article($_REQUEST["articleId"]);
24
$tikilib->get_perm_object($_REQUEST['articleId'], 'article');
25
if ($article_data === false) {
26
	if (!$user) $_SESSION['loginfrom'] = $_SERVER['REQUEST_URI'];
27
	$smarty->assign('errortype', 401);
28 29 30 31 32 33 34 35 36
	$smarty->assign('msg', tra('Permission denied'));
	$smarty->display('error.tpl');
	die;
}
if (!$article_data) {
	$smarty->assign('msg', tra("Article not found"));
	$smarty->display("error.tpl");
	die;
}
37
if (($article_data['publishDate'] > $tikilib->now) && ($article_data['author'] != $user && $tiki_p_admin != 'y' && $tiki_p_admin_cms != 'y') && ($article_data['type'] != 'Event')) {
38
	$smarty->assign('msg', tra("Article is not published yet"));
39 40 41
	$smarty->display("error.tpl");
	die;
}
42

43
if ($article_data['ispublished'] == 'n' && $tiki_p_edit_article != 'y') {
44 45 46 47 48
	$smarty->assign('msg', tra("Article is not published yet"));
	$smarty->display("error.tpl");
	die;
}

49
if (isset($_REQUEST['switchlang']) && $_REQUEST['switchlang'] == 'y' && $prefs['feature_multilingual'] == 'y' && $prefs['feature_sync_language'] == 'y' && !empty($article_data["lang"]) && $prefs['language'] != $article_data["lang"]) {
50 51
	header('Location: tiki-switch_lang.php?language=' . $article_data['lang']);
	die;
52 53
}

lphuberdeau's avatar
lphuberdeau committed
54
$statslib = TikiLib::lib('stats');
55
if ($prefs['feature_categories'] == 'y') {
56
	$categlib = TikiLib::lib('categ');
57
}
58
//This is basicaly a copy of part of the freetag code from tiki-setup.php and should be only there. The problem is that the section name for articles is "cms" and the object name for article in the table tiki_objects is "article". Maybe it is a good idea to use "cms" on tiki_objects instead "article" and then this block of code can be removed. Another solution?
59
if ($prefs['feature_freetags'] == 'y') {
lphuberdeau's avatar
lphuberdeau committed
60
	$freetaglib = TikiLib::lib('freetag');
61 62
	$here = $sections[$section];
	if (isset($here['itemkey']) and isset($_REQUEST[$here['itemkey']])) {
changi67's avatar
changi67 committed
63
		$tags = $freetaglib->get_tags_on_object($_REQUEST[$here['itemkey']], "article " . $_REQUEST[$here['key']]);
64 65 66 67 68
	} elseif (isset($here['key']) and isset($_REQUEST[$here['key']])) {
		$tags = $freetaglib->get_tags_on_object($_REQUEST[$here['key']], "article");
	} else {
		$tags = array();
	}
changi67's avatar
changi67 committed
69
	$smarty->assign('freetags', $tags);
70
}
changi67's avatar
changi67 committed
71 72 73 74 75 76 77 78 79 80 81 82 83
$artlib->add_article_hit($_REQUEST["articleId"]);
$smarty->assign('articleId', $_REQUEST["articleId"]);
$smarty->assign('arttitle', $article_data["title"]);
$smarty->assign('topline', $article_data["topline"]);
$smarty->assign('show_topline', $article_data["show_topline"]);
$smarty->assign('subtitle', $article_data["subtitle"]);
$smarty->assign('show_subtitle', $article_data["show_subtitle"]);
$smarty->assign('linkto', $article_data["linkto"]);
$smarty->assign('show_linkto', $article_data["show_linkto"]);
$smarty->assign('image_caption', $article_data["image_caption"]);
$smarty->assign('show_image_caption', $article_data["show_image_caption"]);
$smarty->assign('lang', $article_data["lang"]);
$smarty->assign('authorName', $article_data["authorName"]);
84
$smarty->assign('author', $article_data["author"]);
changi67's avatar
changi67 committed
85 86 87 88 89 90 91 92 93 94 95
$smarty->assign('show_author', $article_data["show_author"]);
$smarty->assign('topicId', $article_data["topicId"]);
$smarty->assign('type', $article_data["type"]);
$smarty->assign('rating', $article_data["rating"]);
$smarty->assign('entrating', $article_data["entrating"]);
$smarty->assign('useImage', $article_data["useImage"]);
$smarty->assign('isfloat', $article_data["isfloat"]);
$smarty->assign('image_name', $article_data["image_name"]);
$smarty->assign('image_type', $article_data["image_type"]);
$smarty->assign('image_size', $article_data["image_size"]);
$smarty->assign('image_x', $article_data["image_x"]);
96
$smarty->assign('list_image_x', $article_data["list_image_x"]);
changi67's avatar
changi67 committed
97 98 99 100 101 102 103
$smarty->assign('image_y', $article_data["image_y"]);
$smarty->assign('image_data', urlencode($article_data["image_data"]));
$smarty->assign('reads', $article_data["nbreads"]);
$smarty->assign('show_reads', $article_data["show_reads"]);
$smarty->assign('size', $article_data["size"]);
$smarty->assign('show_size', $article_data["show_size"]);
$smarty->assign('use_ratings', $article_data["use_ratings"]);
104
$smarty->assign('comment_can_rate_article', $article_data["comment_can_rate_article"]);
105
$smarty->assign('ispublished', $article_data["ispublished"]);
changi67's avatar
changi67 committed
106 107
if (strlen($article_data["image_data"]) > 0) {
	$smarty->assign('hasImage', 'y');
108 109
} else {
	$smarty->assign('hasImage', 'n');
changi67's avatar
changi67 committed
110
}
111 112 113 114 115 116 117
if ($article_data['image_x'] > 0) {
	$smarty->assign('width', $article_data['image_x']);
} else {
	require_once('lib/images/images.php');
	$img = new Image($article_data['image_x'], false);
	$smarty->assign('width', $img->get_width()+2);
}
changi67's avatar
changi67 committed
118
$smarty->assign('heading', $article_data["heading"]);
119
if ( $prefs['article_paginate'] == 'y' ) {
120 121 122 123
	if (!isset($_REQUEST['page'])) $_REQUEST['page'] = 1;
	// Get ~pp~, ~np~ and <pre> out of the way. --rlpowell, 24 May 2004
	$preparsed = array();
	$noparsed = array();
changi67's avatar
changi67 committed
124

125
	$parserlib->plugins_remove($article_data["body"], $noparsed);
126
	$parserlib->parse_first($article_data["body"], $preparsed, $noparsed);
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
	$pages = $artlib->get_number_of_pages($article_data["body"]);
	$article_data["body"] = $artlib->get_page($article_data["body"], $_REQUEST['page']);
	$smarty->assign('pages', $pages);
	if ($pages > $_REQUEST['page']) {
		$smarty->assign('next_page', $_REQUEST['page'] + 1);
	} else {
		$smarty->assign('next_page', $_REQUEST['page']);
	}
	if ($_REQUEST['page'] > 1) {
		$smarty->assign('prev_page', $_REQUEST['page'] - 1);
	} else {
		$smarty->assign('prev_page', 1);
	}
	$smarty->assign('first_page', 1);
	$smarty->assign('last_page', $pages);
	$smarty->assign('pagenum', $_REQUEST['page']);
	// Put ~pp~, ~np~ and <pre> back. --rlpowell, 24 May 2004
144 145
	$parserlib = TikiLib::lib('parser');
	$parserlib->replace_preparse($article_data["body"], $preparsed, $noparsed);
changi67's avatar
changi67 committed
146
}
147 148
if ($prefs["article_custom_attributes"] == 'y') {
	$t_article_attributes = $artlib->get_article_attributes($article_data["articleId"]);
149
	$type_attributes = $artlib->get_article_type_attributes($article_data["type"], 'relationId ASC');
150 151 152 153 154
	$article_attributes = array();
	foreach ($type_attributes as $attname => $att) {
		if (in_array($att["itemId"], array_keys($t_article_attributes))) {
			$article_attributes[$attname] = $t_article_attributes[$att["itemId"]];
		}
changi67's avatar
changi67 committed
155
	}
156 157 158 159
	$smarty->assign('article_attributes', $article_attributes);
} else {
	$smarty->assign('article_attributes', array());
}
changi67's avatar
changi67 committed
160 161
$smarty->assign('body', $article_data["body"]);
$smarty->assign('publishDate', $article_data["publishDate"]);
162
$smarty->assign('expireDate', $article_data["expireDate"]);
changi67's avatar
changi67 committed
163
$smarty->assign('show_pubdate', $article_data["show_pubdate"]);
164
$smarty->assign('show_expdate', $article_data["show_expdate"]);
changi67's avatar
changi67 committed
165 166 167
$smarty->assign('edit_data', 'y');
$body = $article_data["body"];
$heading = $article_data["heading"];
168 169 170 171 172 173 174 175 176 177 178

// We need to figure out in which theme we are before the page parsing
// in case the page contains pluginModule in which cas the parser triggers tiki-modules.php
// which needs $tc_theme for deciding on the visible modules everywhere in the page
include_once ('tiki-section_options.php');
if ($prefs['feature_theme_control'] == 'y') {
	$cat_type = 'article';
	$cat_objid = $_REQUEST["articleId"];
	include ('tiki-tc.php');
}

179
$smarty->assign('parsed_body', $tikilib->parse_data($body, array('is_html' => $artlib->is_html($article_data))));
changi67's avatar
changi67 committed
180 181 182 183 184 185 186 187 188
$smarty->assign(
	'parsed_heading',
	$tikilib->parse_data(
		$heading,
		array(
			'min_one_paragraph' => true,
			'is_html' => $artlib->is_html($article_data, true),
		)
	)
189
);
190 191 192 193 194 195 196
if ($prefs['article_related_articles'] == 'y') {
	$article_data['related_articles'] = $artlib->get_related_articles($article_data['articleId']);
	if (isset($article_data['related_articles']) && !empty($article_data['related_articles'])) {
		$smarty->assign('related_articles', $article_data['related_articles']);
	}
}

197
$topics = $artlib->list_topics();
198 199
if (isset($topics[$article_data['topicId']])) {
	$smarty->assign('topicName', $topics[$article_data['topicId']]['name']);
200
}
201
$smarty->assign_by_ref('topics', $topics);
202

203
$objId = $_REQUEST['articleId'];
204
if ($prefs['feature_categories'] == 'y') {
205
	$is_categorized = $categlib->is_categorized('article', $objId);
206
}
207
// Display category path or not (like {catpath()})
208
if (isset($is_categorized) && $is_categorized) {
changi67's avatar
changi67 committed
209
	$smarty->assign('is_categorized', 'y');
210 211 212 213
	if ($prefs['feature_categories'] == 'y' && $prefs['feature_categorypath'] == 'y') {
		$cats = $categlib->get_object_categories('article', $objId);
		$display_catpath = $categlib->get_categorypath($cats);
		$smarty->assign('display_catpath', $display_catpath);
changi67's avatar
changi67 committed
214 215 216 217 218 219 220 221 222
	}
	// Display current category objects or not (like {category()})
	if (isset($prefs['feature_categoryobjects']) and $prefs['feature_categories'] == 'y') {
		if ($prefs['feature_categoryobjects'] == 'y') {
			$catids = $categlib->get_object_categories('article', $objId);
			$display_catobjects = $categlib->get_categoryobjects($catids);
			$smarty->assign('display_catobjects', $display_catobjects);
		}
	}
223
	if ($prefs['feature_categories'] == 'y' && $prefs['category_morelikethis_algorithm'] != '') {
lphuberdeau's avatar
lphuberdeau committed
224
		$freetaglib = TikiLib::lib('freetag');
225
		$category_related_objects = $freetaglib->get_similar('article', $_REQUEST['articleId'], empty($prefs['category_morelikethis_mincommon_max'])? $prefs['maxRecords']: $prefs['category_morelikethis_mincommon_max'], null, 'category');
226 227
		$smarty->assign_by_ref('category_related_objects', $category_related_objects);
	}
228
} else {
changi67's avatar
changi67 committed
229
	$smarty->assign('is_categorized', 'n');
230
}
231

232
if ($prefs['feature_multilingual'] == 'y' && $article_data['lang']) {
233
	$multilinguallib = TikiLib::lib('multilingual');
sylvieg's avatar
sylvieg committed
234 235 236
	$trads = $multilinguallib->getTranslations('article', $article_data['articleId'], $article_data["title"], $article_data['lang']);
	$smarty->assign('trads', $trads);
}
237 238
//Keep track of month of last viewed article for article months_links module foldable display
$_SESSION['cms_last_viewed_month'] = TikiLib::date_format("%Y-%m", $article_data["publishDate"]);
239
ask_ticket('article-read');
240
//add a hit
changi67's avatar
changi67 committed
241
$statslib->stats_hit($article_data["title"], "article", $article_data['articleId']);
242 243 244
if ($prefs['feature_actionlog'] == 'y') {
	$logslib->add_action('Viewed', $_REQUEST['articleId'], 'article');
}
245 246 247
// Display the Index Template
$smarty->assign('mid', 'tiki-read_article.tpl');
$smarty->display("tiki.tpl");