tiki-view_articles.php 5.79 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2016 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.
changi67's avatar
changi67 committed
9 10
// $Id$

11
$section = 'cms';
12
//get_strings tra('Articles Home');
13
require_once ('tiki-setup.php');
14
$artlib = TikiLib::lib('art');
15 16 17 18 19 20

if ($prefs['article_use_new_list_articles'] == 'y') {
	include "lists/articles.php";
	die;
}

21
if ($prefs['feature_freetags'] == 'y') {
22
	$freetaglib = TikiLib::lib('freetag');
23
}
24
if ($prefs['feature_categories'] == 'y') {
25
	$categlib = TikiLib::lib('categ');
26
}
27

jonnybradley's avatar
jonnybradley committed
28
$access->check_feature('feature_articles');
29

30
if (isset($_REQUEST["remove"])) {
31
	$access->check_permission('tiki_p_remove_article');
32 33
	$access->check_authenticity();
	$artlib->remove_article($_REQUEST["remove"]);
changi67's avatar
changi67 committed
34
}
marclaporte's avatar
marclaporte committed
35
// This script can receive the threshold
36 37 38
// for the information as the number of
// days to get in the log 1,3,4,etc
// it will default to 1 recovering information for today
39
if (empty($_REQUEST["sort_mode"])) {
40
	$sort_mode = $prefs['art_sort_mode'];
41
} else {
42
	$sort_mode = $_REQUEST["sort_mode"];
43 44
}
$smarty->assign_by_ref('sort_mode', $sort_mode);
45 46 47
// If offset is set use it if not then use offset =0
// use the maxRecords php variable to set the limit
// if sortMode is not set then use lastModif_desc
48
if (!isset($_REQUEST["offset"])) {
49
	$offset = 0;
50
} else {
51
	$offset = $_REQUEST["offset"];
52
}
53
$smarty->assign_by_ref('offset', $offset);
changi67's avatar
changi67 committed
54
if (isset($_REQUEST['date_min']) || isset($_REQUEST['date_max'])) {
55 56
	$date_min = isset($_REQUEST['date_min']) ? $_REQUEST['date_min'] : 0;
	$date_max = isset($_REQUEST['date_max']) ? $_REQUEST['date_max'] : $tikilib->now;
57
} elseif (isset($_SESSION["thedate"])) {
58 59 60 61 62 63 64 65 66 67
	$date_min = 0;
	if ($_SESSION["thedate"] < $tikilib->now) {
		$date_max = $_SESSION["thedate"];
	} else {
		if ($tiki_p_admin == 'y' || $tiki_p_admin_cms == 'y') {
			$date_max = $_SESSION["thedate"];
		} else {
			$date_max = $tikilib->now;
		}
	}
68
} else {
69 70
	$date_min = 0;
	$date_max = $tikilib->now;
71
}
72 73
//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", $date_max);
74 75
$min_rating = isset($_REQUEST['min_rating']) ? $_REQUEST['min_rating'] : '';
$max_rating = isset($_REQUEST['max_rating']) ? $_REQUEST['max_rating'] : '';
76
if (isset($_REQUEST["find"])) {
77
	$find = $_REQUEST["find"];
78
} else {
79
	$find = '';
80
}
81
$smarty->assign_by_ref('find', $find);
82
if (isset($_REQUEST["type"])) {
83
	$type = $_REQUEST["type"];
84
} else {
85
	$type = '';
86
}
87
if (isset($_REQUEST["topic"])) {
88
	$topic = $_REQUEST["topic"];
changi67's avatar
changi67 committed
89
} else {
90
	$topic = '';
91
}
92
if (isset($_REQUEST['topicName'])) {
93
	$topicName = $_REQUEST['topicName'];
changi67's avatar
changi67 committed
94
} else {
95
	$topicName = '';
changi67's avatar
changi67 committed
96
}
97
if (isset($_REQUEST["categId"])) {
98
	$categId = $_REQUEST["categId"];
99
} else {
100
	$categId = '';
101 102
}
$smarty->assign_by_ref('categId', $categId);
103
if (!isset($_REQUEST['lang'])) {
104
	$_REQUEST['lang'] = '';
105
}
106
// Get a list of last changes to the Wiki database
107
$listpages = $artlib->list_articles($offset, $prefs['maxArticles'], $sort_mode, $find, $date_min, $date_max, $user, $type, $topic, 'y', $topicName, $categId, '', '', $_REQUEST['lang'], $min_rating, $max_rating, false, 'y');
108
if ($prefs['feature_multilingual'] == 'y') {
109
	$multilinguallib = TikiLib::lib('multilingual');
110
	$listpages['data'] = $multilinguallib->selectLangList('article', $listpages['data']);
111 112 113
	foreach ($listpages['data'] as &$article) {
		$article['translations'] = $multilinguallib->getTranslations('article', $article['articleId'], $article["title"], $article['lang']);
	}
mose's avatar
mose committed
114
}
115 116
$topics = $artlib->list_topics();
$smarty->assign_by_ref('topics', $topics);
117
$temp_max = count($listpages["data"]);
118
for ($i = 0; $i < $temp_max; $i++) {
changi67's avatar
changi67 committed
119 120 121 122 123 124 125
	$listpages["data"][$i]["parsed_heading"] = $tikilib->parse_data(
		$listpages["data"][$i]["heading"],
		array(
			'min_one_paragraph' => true,
			'is_html' => $artlib->is_html($listpages["data"][$i], true),
		)
	);
126 127 128
	$comments_prefix_var = 'article:';
	$comments_object_var = $listpages["data"][$i]["articleId"];
	$comments_objectId = $comments_prefix_var . $comments_object_var;
129
	$listpages["data"][$i]["comments_cant"] = TikiLib::lib('comments')->count_comments($comments_objectId);
130 131 132
	if ($prefs['feature_freetags'] == 'y') { // And get the Tags for the posts
		$listpages["data"][$i]["freetags"] = $freetaglib->get_tags_on_object($listpages["data"][$i]["articleId"], "article");
	}
133
}
changi67's avatar
changi67 committed
134
if (!empty($topicName) && !strstr($topicName, '!') && !strstr($topicName, '+')) {
135
	$smarty->assign_by_ref('topic', $topicName);
changi67's avatar
changi67 committed
136
} elseif (!empty($topic) && is_numeric($topic)) {
137 138 139 140 141
	if (!empty($listpages['data'][0]['topicName'])) $smarty->assign_by_ref('topic', $listpages['data'][0]['topicName']);
	else {
		$topic_info = $artlib->get_topic($topic);
		if (isset($topic_info['name'])) $smarty->assign_by_ref('topic', $topic_info['name']);
	}
changi67's avatar
changi67 committed
142 143
}
if (!empty($type) && !strstr($type, '!') && !strstr($type, '+')) {
144
	$smarty->assign_by_ref('type', $type);
changi67's avatar
changi67 committed
145
}
146
$smarty->assign('maxArticles', $prefs['maxArticles']);
147
// If there're more records then assign next_offset
148
$smarty->assign_by_ref('listpages', $listpages["data"]);
luciash's avatar
luciash committed
149
$smarty->assign_by_ref('cant', $listpages["cant"]);
150 151 152 153 154 155 156 157 158 159 160
if ($prefs['feature_user_watches'] == 'y') {
	if ($user && isset($_REQUEST['watch_action'])) {
		$access->check_authenticity();
		if ($_REQUEST['watch_action'] == 'add') {
			$tikilib->add_user_watch($user, 'article_*', '*');
		} else {
			$tikilib->remove_user_watch($user, 'article_*', '*', null);
		}
	}
	$smarty->assign('user_watching_articles', ($user && $tikilib->user_watches($user, 'article_*', '*')) ? 'y' : 'n');
}
161 162
$headerLinks = 'y';
$smarty->assign('headerLinks', $headerLinks);
163
include_once ('tiki-section_options.php');
164
ask_ticket('view_article');
165
// Display the template
166
$smarty->assign('mid', 'tiki-view_articles.tpl');
167
$smarty->display("tiki.tpl");