tiki-browse_freetags.php 4.67 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
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 = 'freetags';
rjsmelo's avatar
rjsmelo committed
12
require_once('tiki-setup.php');
13
$freetaglib = TikiLib::lib('freetag');
14 15 16
$access->check_feature('feature_freetags');
$access->check_permission('tiki_p_view_freetags');

17 18
if (isset($_REQUEST['del'])) {
	if ($tiki_p_admin == 'y' || $tiki_p_unassign_freetags == 'y') {
19
		$freetaglib->delete_object_tag($_REQUEST['itemit'], $_REQUEST['typeit'], $_REQUEST['tag']);
20
	} else {
21
		$smarty->assign('errortype', 401);
22 23 24
		$smarty->assign('msg', tra('Permission denied'));
		$smarty->display('error.tpl');
		die;
25 26
	}
}
27
if ($freetaglib->count_tags() == 0) {
28 29 30
	$smarty->assign('msg', tra("Nothing tagged yet") . '.');
	$smarty->display("error.tpl");
	die;
31
}
rjsmelo's avatar
rjsmelo committed
32
if (! isset($_REQUEST['tag']) && $prefs['freetags_preload_random_search'] == 'y') {
33
	$tag = $freetaglib->get_tag_suggestion('', 1);
rjsmelo's avatar
rjsmelo committed
34
	if (! empty($tag[0])) {
35
		$_REQUEST['tag'] = $tag[0];
36
		if (strstr($tag[0], ' ')) {
rjsmelo's avatar
rjsmelo committed
37
			$_REQUEST['tag'] = '"' . $_REQUEST['tag'] . '"';
38
		}
39
	}
40
}
rjsmelo's avatar
rjsmelo committed
41
if (! isset($_REQUEST["sort_mode"])) {
42
	$sort_mode = $prefs['freetags_sort_mode'];
43 44 45
} else {
	$sort_mode = $_REQUEST["sort_mode"];
}
46
$query_sort_mode = str_replace('created', 'o.`created`', $sort_mode);
47 48 49 50 51
if (isset($_REQUEST["find"])) {
	$find = $_REQUEST["find"];
} else {
	$find = '';
}
52
$smarty->assign_by_ref('sort_mode', $sort_mode);
53
$smarty->assign_by_ref('find', $find);
rjsmelo's avatar
rjsmelo committed
54
if (! isset($_REQUEST["offset"])) {
55 56 57 58 59
	$offset = 0;
} else {
	$offset = $_REQUEST["offset"];
}
$smarty->assign_by_ref('offset', $offset);
rjsmelo's avatar
rjsmelo committed
60 61
if (! isset($_REQUEST["type"])) {
	$type = isset($_REQUEST['old_type']) ? $_REQUEST['old_type'] : '';
62 63 64 65 66
} else {
	$type = $_REQUEST["type"];
}
$smarty->assign('type', $type);
if (isset($_REQUEST["user_only"]) && $_REQUEST["user_only"] == 'on') {
67 68
	$view_user = $user;
	$smarty->assign('user_only', 'on');
69
} else {
70 71
	$view_user = '';
	$smarty->assign('user_only', 'off');
72
}
73 74 75
if (isset($_REQUEST['broaden']) && $_REQUEST['broaden'] == 'last') {
	$broaden = 'last';
} elseif ((isset($_REQUEST['broaden']) && $_REQUEST['broaden'] == 'n') || (isset($_REQUEST['stopbroaden']) && $_REQUEST['stopbroaden'] == 'on')) {
76 77 78 79 80
	$broaden = 'n';
} else {
	$broaden = 'y';
}
$smarty->assign('broaden', $broaden);
pkdille's avatar
pkdille committed
81
$tagArray = $freetaglib->_parse_tag((isset($_REQUEST['tag'])) ? $_REQUEST['tag'] : '');
82
$tagString = '';
83
foreach ($tagArray as $t_ar) {
84
	if (strstr($t_ar, ' ')) {
rjsmelo's avatar
rjsmelo committed
85
		$tagString .= '"' . $t_ar . '" ';
86
	} else {
rjsmelo's avatar
rjsmelo committed
87
		$tagString .= $t_ar . ' ';
88
	}
89 90
}
$smarty->assign('tagString', trim($tagString));
pkdille's avatar
pkdille committed
91
$smarty->assign('tag', (isset($tagArray[0])) ? $tagArray[0] : '');
92 93 94 95 96 97 98 99 100
if (empty($_REQUEST['maxPopular'])) {
	$maxPopular = $prefs['freetags_browse_amount_tags_in_cloud'];
} else {
	$maxPopular = $_REQUEST['maxPopular'];
	$smarty->assign_by_ref('maxPopular', $maxPopular);
}
if (empty($_REQUEST['tsort_mode'])) {
	$tsort_mode = 'tag_asc';
} else {
101
	$tsort_mode = $_REQUEST['tsort_mode'];
102 103
	$smarty->assign_by_ref('tsort_mode', $tsort_mode);
}
rjsmelo's avatar
rjsmelo committed
104
if (! empty($_REQUEST['objectId'])) {
105 106 107 108 109 110 111 112 113 114
	$objectId = $_REQUEST['objectId'];
} else {
	$objectId = null;
}
$smarty->assign_by_ref('objectId', $objectId);
if ($prefs['feature_blogs'] == 'y' && $type == 'blog post') {
	$blogs = TikiLib::lib('blog')->list_blogs();
	$smarty->assign('blogs', $blogs['data']);
}

115
$most_popular_tags = $freetaglib->get_most_popular_tags('', 0, $maxPopular, $type, $objectId, $tsort_mode);
rjsmelo's avatar
rjsmelo committed
116
if (! empty($prefs['freetags_cloud_colors'])) {
117
	$colors = explode(',', $prefs['freetags_cloud_colors']);
118
	$prev = '';
119
	foreach ($most_popular_tags as $id => $tag) {
120 121 122
		if (count($colors) == 1) {
			$i = 0;
		} elseif (count($colors) == 2) {
123
			$i = $prev ? 0 : 1;
124 125 126 127 128
		}
		$most_popular_tags[$id]['color'] = $colors[$i];
		$prev = $i;
	}
}
129
$smarty->assign('most_popular_tags', $most_popular_tags);
130 131
if ($broaden == 'last') {
	$broaden = 'n';
rjsmelo's avatar
rjsmelo committed
132
	$tagArray = [
133
		$tagArray[count($tagArray) - 1]
rjsmelo's avatar
rjsmelo committed
134
	];
135
}
136
$objects = $freetaglib->get_objects_with_tag_combo($tagArray, $type, $view_user, $offset, $maxRecords, $query_sort_mode, $find, $broaden, $objectId);
137

138 139
$smarty->assign_by_ref('objects', $objects["data"]);
$smarty->assign_by_ref('cantobjects', $objects["cant"]);
140
$cant = $objects['cant'];
141 142
$smarty->assign('cant', $objects['cant']);

rjsmelo's avatar
rjsmelo committed
143
include_once('tiki-section_options.php');
144
ask_ticket('browse-freetags');
145

146
$smarty->assign(
147
	'objects_with_freetags',
rjsmelo's avatar
rjsmelo committed
148
	[
149 150 151 152 153 154 155 156 157 158 159 160 161
		'wiki page',
		'blog post',
		'article',
		'directory',
		'faq',
		'file gallery',
		'image gallery',
		'image',
		'poll',
		'quiz',
		'survey',
		'tracker',
		'tracker %d'
rjsmelo's avatar
rjsmelo committed
162
	 ]
163
);
164 165
$smarty->assign('mid', 'tiki-browse_freetags.tpl');
$smarty->display("tiki.tpl");