Gazelle/sections/collages/browse.php

327 lines
10 KiB
PHP
Raw Normal View History

2013-05-28 08:01:02 +00:00
<?php
2011-03-28 14:21:28 +00:00
define('COLLAGES_PER_PAGE', 25);
2013-05-27 08:00:58 +00:00
include(SERVER_ROOT.'/classes/text.class.php'); // Text formatting class
2011-03-28 14:21:28 +00:00
$Text = new TEXT;
2013-05-28 08:01:02 +00:00
list($Page, $Limit) = Format::page_limit(COLLAGES_PER_PAGE);
2011-03-28 14:21:28 +00:00
2013-05-25 08:01:03 +00:00
$OrderVals = array('Time', 'Name', 'Subscribers', 'Torrents', 'Updated');
2011-03-28 14:21:28 +00:00
$WayVals = array('Ascending', 'Descending');
2013-05-25 08:01:03 +00:00
$OrderTable = array('Time'=>'ID', 'Name'=>'c.Name', 'Subscribers'=> 'c.Subscribers', 'Torrents'=>'NumTorrents', 'Updated' => 'c.Updated');
2011-03-28 14:21:28 +00:00
$WayTable = array('Ascending'=>'ASC', 'Descending'=>'DESC');
// Are we searching in bodies, or just names?
2013-04-19 08:00:55 +00:00
if (!empty($_GET['type'])) {
2011-03-28 14:21:28 +00:00
$Type = $_GET['type'];
2013-04-19 08:00:55 +00:00
if (!in_array($Type, array('c.name', 'description'))) {
2011-03-28 14:21:28 +00:00
$Type = 'c.name';
}
} else {
$Type = 'c.name';
}
2013-04-19 08:00:55 +00:00
if (!empty($_GET['search'])) {
2011-03-28 14:21:28 +00:00
// What are we looking for? Let's make sure it isn't dangerous.
2012-05-18 13:35:17 +00:00
$Search = db_string(trim($_GET['search']));
2011-03-28 14:21:28 +00:00
// Break search string down into individual words
$Words = explode(' ', $Search);
}
2013-04-19 08:00:55 +00:00
if (!empty($_GET['tags'])) {
2011-03-28 14:21:28 +00:00
$Tags = explode(',',db_string(trim($_GET['tags'])));
2013-04-19 08:00:55 +00:00
foreach ($Tags as $ID=>$Tag) {
2012-10-11 08:00:15 +00:00
$Tags[$ID] = Misc::sanitize_tag($Tag);
2011-03-28 14:21:28 +00:00
}
}
2013-04-19 08:00:55 +00:00
if (!empty($_GET['cats'])) {
2011-03-28 14:21:28 +00:00
$Categories = $_GET['cats'];
2013-04-19 08:00:55 +00:00
foreach ($Categories as $Cat=>$Accept) {
if (empty($CollageCats[$Cat]) || !$Accept) {
unset($Categories[$Cat]);
}
2011-03-28 14:21:28 +00:00
}
$Categories = array_keys($Categories);
} else {
2013-05-29 08:00:51 +00:00
$Categories = array(1, 2, 3, 4, 5, 6, 7);
2011-03-28 14:21:28 +00:00
}
// Ordering
2013-04-19 08:00:55 +00:00
if (!empty($_GET['order_by']) && !empty($OrderTable[$_GET['order_by']])) {
2012-11-06 08:00:20 +00:00
$Order = $OrderTable[$_GET['order_by']];
2011-03-28 14:21:28 +00:00
} else {
$Order = 'ID';
}
2013-04-19 08:00:55 +00:00
if (!empty($_GET['order_way']) && !empty($WayTable[$_GET['order_way']])) {
2012-11-06 08:00:20 +00:00
$Way = $WayTable[$_GET['order_way']];
2011-03-28 14:21:28 +00:00
} else {
$Way = 'DESC';
}
$BookmarkView = !empty($_GET['bookmarks']);
if ($BookmarkView) {
2012-03-14 08:00:27 +00:00
$Categories[] = 0;
$BookmarkJoin = 'INNER JOIN bookmarks_collages AS bc ON c.ID = bc.CollageID';
} else {
$BookmarkJoin = '';
}
2013-05-15 08:00:54 +00:00
$BaseSQL = $SQL = "
2013-05-29 08:00:51 +00:00
SELECT
SQL_CALC_FOUND_ROWS
2013-05-15 08:00:54 +00:00
c.ID,
c.Name,
c.NumTorrents,
c.TagList,
c.CategoryID,
2013-05-25 08:01:03 +00:00
c.UserID,
c.Subscribers,
c.Updated
2013-02-22 08:00:24 +00:00
FROM collages AS c
2013-05-15 08:00:54 +00:00
$BookmarkJoin
2011-03-28 14:21:28 +00:00
WHERE Deleted = '0'";
if ($BookmarkView) {
$SQL .= " AND bc.UserID = '" . $LoggedUser['ID'] . "'";
}
2013-04-19 08:00:55 +00:00
if (!empty($Search)) {
2011-03-28 14:21:28 +00:00
$SQL .= " AND $Type LIKE '%";
$SQL .= implode("%' AND $Type LIKE '%", $Words);
$SQL .= "%'";
}
2012-11-06 08:00:20 +00:00
if (isset($_GET['tags_type']) && $_GET['tags_type'] == 0) { // Any
$_GET['tags_type'] = 0;
} else { // All
$_GET['tags_type'] = 1;
}
2013-04-19 08:00:55 +00:00
if (!empty($Tags)) {
2012-11-06 08:00:20 +00:00
$SQL.= " AND (TagList LIKE '%";
if ($_GET['tags_type'] == 0) {
$SQL .= implode("%' OR TagList LIKE '%", $Tags);
} else {
$SQL .= implode("%' AND TagList LIKE '%", $Tags);
}
$SQL .= "%')";
2011-03-28 14:21:28 +00:00
}
2013-04-19 08:00:55 +00:00
if (!empty($_GET['userid'])) {
2011-03-28 14:21:28 +00:00
$UserID = $_GET['userid'];
2013-04-19 08:00:55 +00:00
if (!is_number($UserID)) {
2011-03-28 14:21:28 +00:00
error(404);
}
2012-10-11 08:00:15 +00:00
$User = Users::user_info($UserID);
$Perms = Permissions::get_permissions($User['PermissionID']);
2011-03-28 14:21:28 +00:00
$UserClass = $Perms['Class'];
$UserLink = '<a href="user.php?id='.$UserID.'">'.$User['Username'].'</a>';
2013-04-19 08:00:55 +00:00
if (!empty($_GET['contrib'])) {
if (!check_paranoia('collagecontribs', $User['Paranoia'], $UserClass, $UserID)) {
error(403);
}
2011-03-28 14:21:28 +00:00
$DB->query("SELECT DISTINCT CollageID FROM collages_torrents WHERE UserID = $UserID");
$CollageIDs = $DB->collect('CollageID');
2013-04-19 08:00:55 +00:00
if (empty($CollageIDs)) {
2011-03-28 14:21:28 +00:00
$SQL .= " AND 0";
} else {
$SQL .= " AND c.ID IN(".db_string(implode(',', $CollageIDs)).")";
}
} else {
2013-05-14 08:00:34 +00:00
if (!check_paranoia('collages', $User['Paranoia'], $UserClass, $UserID)) {
error(403);
}
2011-03-28 14:21:28 +00:00
$SQL .= " AND UserID='".$_GET['userid']."'";
}
$Categories[] = 0;
}
2013-04-19 08:00:55 +00:00
if (!empty($Categories)) {
2011-03-28 14:21:28 +00:00
$SQL.=" AND CategoryID IN(".db_string(implode(',',$Categories)).")";
}
if ($_GET['action'] == 'mine') {
$SQL = $BaseSQL;
$SQL .= " AND c.UserID='".$LoggedUser['ID']."' AND c.CategoryID=0";
}
2011-03-28 14:21:28 +00:00
$SQL.=" ORDER BY $Order $Way LIMIT $Limit ";
$DB->query($SQL);
$Collages = $DB->to_array();
$DB->query("SELECT FOUND_ROWS()");
list($NumResults) = $DB->next_record();
2012-10-11 08:00:15 +00:00
View::show_header(($BookmarkView)?'Your bookmarked collages':'Browse collages');
2011-03-28 14:21:28 +00:00
?>
<div class="thin">
2012-08-19 08:00:19 +00:00
<div class="header">
<? if ($BookmarkView) { ?>
2012-08-19 08:00:19 +00:00
<h2>Your bookmarked collages</h2>
<? } else { ?>
2012-08-19 08:00:19 +00:00
<h2>Browse collages<?=(!empty($UserLink) ? (isset($CollageIDs) ? ' with contributions by '.$UserLink : ' started by '.$UserLink) : '')?></h2>
<? } ?>
2012-08-19 08:00:19 +00:00
</div>
<? if (!$BookmarkView) { ?>
<div>
2012-09-15 08:00:25 +00:00
<form class="search_form" name="collages" action="" method="get">
2011-03-28 14:21:28 +00:00
<div><input type="hidden" name="action" value="search" /></div>
2012-09-01 08:00:24 +00:00
<table cellpadding="6" cellspacing="1" border="0" class="layout border" width="100%">
2012-11-06 08:00:20 +00:00
<tr id="search_terms">
<td class="label">Search terms:</td>
<td>
2011-03-28 14:21:28 +00:00
<input type="text" name="search" size="70" value="<?=(!empty($_GET['search']) ? display_str($_GET['search']) : '')?>" />
</td>
</tr>
2012-11-06 08:00:20 +00:00
<tr id="tagfilter">
<td class="label">Tags (comma-separated):</td>
<td>
<input type="text" name="tags" size="70" value="<?=(!empty($_GET['tags']) ? display_str($_GET['tags']) : '')?>" />&nbsp;
2013-03-02 08:00:34 +00:00
<input type="radio" name="tags_type" id="tags_type0" value="0"<?Format::selected('tags_type',0,'checked')?> /><label for="tags_type0"> Any</label>&nbsp;&nbsp;
<input type="radio" name="tags_type" id="tags_type1" value="1"<?Format::selected('tags_type',1,'checked')?> /><label for="tags_type1"> All</label>
2011-03-28 14:21:28 +00:00
</td>
</tr>
2012-11-06 08:00:20 +00:00
<tr id="categories">
<td class="label">Categories:</td>
<td>
2013-04-19 08:00:55 +00:00
<? foreach ($CollageCats as $ID=>$Cat) { ?>
2013-05-15 08:00:54 +00:00
<input type="checkbox" value="1" name="cats[<?=$ID?>]" id="cats_<?=$ID?>"<? if (in_array($ID, $Categories)) { echo ' checked="checked"'; } ?> />
2012-11-06 08:00:20 +00:00
<label for="cats_<?=$ID?>"><?=$Cat?></label>&nbsp;&nbsp;
2011-03-28 14:21:28 +00:00
<? } ?>
</td>
</tr>
2012-11-06 08:00:20 +00:00
<tr id="search_name_description">
<td class="label">Search in:</td>
2011-03-28 14:21:28 +00:00
<td>
2013-05-15 08:00:54 +00:00
<input type="radio" name="type" value="c.name" <? if ($Type == 'c.name') { echo 'checked="checked" '; } ?>/> Names&nbsp;&nbsp;
<input type="radio" name="type" value="description" <? if ($Type == 'description') { echo 'checked="checked" '; } ?>/> Descriptions
2011-03-28 14:21:28 +00:00
</td>
2012-11-06 08:00:20 +00:00
</tr>
<tr id="order_by">
<td class="label">Order by:</td>
2011-03-28 14:21:28 +00:00
<td>
2012-11-06 08:00:20 +00:00
<select name="order_by" class="ft_order_by">
2013-04-19 08:00:55 +00:00
<? foreach ($OrderVals as $Cur) { ?>
<option value="<?=$Cur?>"<? if (isset($_GET['order_by']) && $_GET['order_by'] == $Cur || (!isset($_GET['order_by']) && $Cur == 'Time')) { echo ' selected="selected"'; } ?>><?=$Cur?></option>
2013-03-02 08:00:34 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
</select>
2012-11-06 08:00:20 +00:00
<select name="order_way" class="ft_order_way">
2013-04-19 08:00:55 +00:00
<? foreach ($WayVals as $Cur) { ?>
<option value="<?=$Cur?>"<? if (isset($_GET['order_way']) && $_GET['order_way'] == $Cur || (!isset($_GET['order_way']) && $Cur == 'Descending')) { echo ' selected="selected"'; } ?>><?=$Cur?></option>
2013-03-02 08:00:34 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
</select>
</td>
</tr>
<tr>
2012-11-06 08:00:20 +00:00
<td colspan="2" class="center">
2011-03-28 14:21:28 +00:00
<input type="submit" value="Search" />
</td>
</tr>
2013-02-22 08:00:24 +00:00
</table>
2011-03-28 14:21:28 +00:00
</form>
</div>
<? } // if (!$BookmarkView) ?>
2011-03-28 14:21:28 +00:00
<div class="linkbox">
2013-04-19 08:00:55 +00:00
<? if (!$BookmarkView) {
if (check_perms('site_collages_create')) { ?>
2013-01-24 08:00:24 +00:00
<a href="collages.php?action=new" class="brackets">New collage</a>
2013-04-19 08:00:55 +00:00
<? }
if (check_perms('site_collages_personal')) {
2013-02-22 08:00:24 +00:00
2013-04-19 08:00:55 +00:00
$DB->query("SELECT ID FROM collages WHERE UserID='$LoggedUser[ID]' AND CategoryID='0' AND Deleted='0'");
$CollageCount = $DB->record_count();
2013-02-22 08:00:24 +00:00
2013-04-19 08:00:55 +00:00
if ($CollageCount == 1) {
list($CollageID) = $DB->next_record();
?>
2013-01-24 08:00:24 +00:00
<a href="collages.php?id=<?=$CollageID?>" class="brackets">Personal collage</a>
2013-04-19 08:00:55 +00:00
<? } elseif ($CollageCount > 1) { ?>
2013-01-24 08:00:24 +00:00
<a href="collages.php?action=mine" class="brackets">Personal collages</a>
2013-04-19 08:00:55 +00:00
<? }
}
if (check_perms('site_collages_subscribe')) { ?>
2013-01-24 08:00:24 +00:00
<a href="userhistory.php?action=subscribed_collages" class="brackets">Subscribed collages</a>
2013-04-19 08:00:55 +00:00
<? } ?>
2013-01-24 08:00:24 +00:00
<a href="bookmarks.php?type=collages" class="brackets">Bookmarked collages</a>
2012-06-03 08:00:14 +00:00
<?
2013-04-19 08:00:55 +00:00
if (check_perms('site_collages_recover')) { ?>
2013-01-24 08:00:24 +00:00
<a href="collages.php?action=recover" class="brackets">Recover collage</a>
2013-04-19 08:00:55 +00:00
<? }
if (check_perms('site_collages_create') || check_perms('site_collages_personal') || check_perms('site_collages_recover')) {
?>
<br />
2013-04-19 08:00:55 +00:00
<? } ?>
2013-01-24 08:00:24 +00:00
<a href="collages.php?userid=<?=$LoggedUser['ID']?>" class="brackets">Collages you started</a>
<a href="collages.php?userid=<?=$LoggedUser['ID']?>&amp;contrib=1" class="brackets">Collages you contributed to</a>
2013-04-19 08:00:55 +00:00
<? } else { ?>
2013-01-24 08:00:24 +00:00
<a href="bookmarks.php?type=torrents" class="brackets">Torrents</a>
<a href="bookmarks.php?type=artists" class="brackets">Artists</a>
<a href="bookmarks.php?type=collages" class="brackets">Collages</a>
<a href="bookmarks.php?type=requests" class="brackets">Requests</a>
2013-04-19 08:00:55 +00:00
<? } ?>
<br /><br />
2011-03-28 14:21:28 +00:00
<?
2013-05-15 08:00:54 +00:00
$Pages = Format::get_pages($Page, $NumResults, COLLAGES_PER_PAGE, 9);
2011-03-28 14:21:28 +00:00
echo $Pages;
?>
</div>
2013-04-19 08:00:55 +00:00
<? if (count($Collages) == 0) { ?>
<div class="box pad" align="center">
2013-04-19 08:00:55 +00:00
<? if ($BookmarkView) { ?>
<h2>You have not bookmarked any collages.</h2>
2013-04-19 08:00:55 +00:00
<? } else { ?>
<h2>Your search did not match anything.</h2>
<p>Make sure all names are spelled correctly, or try making your search less specific.</p>
2013-04-19 08:00:55 +00:00
<? } ?>
</div><!--box-->
</div><!--content-->
2013-04-19 08:00:55 +00:00
<? View::show_footer();
die();
} ?>
2012-09-01 08:00:24 +00:00
<table width="100%" class="collage_table">
2011-03-28 14:21:28 +00:00
<tr class="colhead">
<td>Category</td>
<td>Collage</td>
<td>Torrents</td>
2013-05-25 08:01:03 +00:00
<td>Subscribers</td>
<td>Updated</td>
2011-03-28 14:21:28 +00:00
<td>Author</td>
</tr>
<?
$Row = 'a'; // For the pretty colours
foreach ($Collages as $Collage) {
2013-05-25 08:01:03 +00:00
list($ID, $Name, $NumTorrents, $TagList, $CategoryID, $UserID, $Subscribers, $Updated) = $Collage;
2011-03-28 14:21:28 +00:00
$Row = ($Row == 'a') ? 'b' : 'a';
2013-02-25 21:16:55 +00:00
$TorrentTags = new Tags($TagList);
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
//Print results
?>
2013-03-02 08:00:34 +00:00
<tr class="row<?=$Row?><?=($BookmarkView) ? ' bookmark_'.$ID : ''?>">
2011-03-28 14:21:28 +00:00
<td>
<a href="collages.php?action=search&amp;cats[<?=(int)$CategoryID?>]=1"><?=$CollageCats[(int)$CategoryID]?></a>
</td>
<td>
<a href="collages.php?id=<?=$ID?>"><?=$Name?></a>
<? if ($BookmarkView) { ?>
2013-04-19 08:00:55 +00:00
<span style="float: right;">
2013-02-09 08:01:01 +00:00
<a href="#" onclick="Unbookmark('collage', <?=$ID?>,'');return false;" class="brackets">Remove bookmark</a>
</span>
2013-02-25 21:16:55 +00:00
<? } ?>
<div class="tags"><?=$TorrentTags->format('collages.php?action=search&amp;tags=')?></div>
2011-03-28 14:21:28 +00:00
</td>
2013-03-02 08:00:34 +00:00
<td><?=number_format((int)$NumTorrents)?></td>
2013-05-25 08:01:03 +00:00
<td><?=number_format((int)$Subscribers)?></td>
<td><?=time_diff($Updated)?></td>
2012-10-11 08:00:15 +00:00
<td><?=Users::format_username($UserID, false, false, false)?></td>
2011-03-28 14:21:28 +00:00
</tr>
2013-04-19 08:00:55 +00:00
<?
} ?>
2011-03-28 14:21:28 +00:00
</table>
<div class="linkbox"><?=$Pages?></div>
</div>
2013-05-21 08:01:09 +00:00
<? View::show_footer(); ?>