Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added filter #4

Merged
merged 2 commits into from
Jul 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions code/FilePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ public function init() {
function Listing($ParentID = null) {
if(!$this->FolderID) return false;

$field = $_GET['fid'];
if (isset($field) && is_numeric($field)) {
if (DataObject::get("File", "ID = ".$_GET['fid'])) {
$ParentID = $_GET['fid'];
$field = filter_var($_GET['fid'], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);

if (isset($field)) {
if (DataObject::get("File", "ID = ".$field)) {
$ParentID = $field;
}
} else {
$ParentID = $this->FolderID;
Expand All @@ -75,8 +76,10 @@ function Listing($ParentID = null) {

// Checks if not at the root folder
function NotRoot() {
if (isset($_GET['fid'])) {
if (DataObject::get("File", "ID = ".$_GET['fid'])) {
$field = filter_var($_GET['fid'], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);

if (isset($field)) {
if (DataObject::get("File", "ID = ".$field)) {
return true;
}
}
Expand All @@ -85,8 +88,10 @@ function NotRoot() {

// Gets current folder from $_GET['fid']
function CurrentFolder() {
if (isset($_GET['fid'])) {
return DataObject::get_by_id("File",$_GET['fid']);
$field = filter_var($_GET['fid'], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);

if (isset($field)) {
return DataObject::get_by_id("File",$field);
}
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions templates/Layout/FilePage.ss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ $Content

<% if BackLink %>
<h2>$CurrentFolder.Title</h2>
<p class="item back"><a href="$Top.Link{$BackLink}"><strong><img src="/file-listing/images/dots.png" class="icon" width="16" height="16" />Back to $CurrentFolder.Parent.Title</strong></a></p>
<p class="item back"><a href="$Top.Link{$BackLink}"><strong><img src="file-listing/images/dots.png" class="icon" width="16" height="16" />Back to $CurrentFolder.Parent.Title</strong></a></p>
<% else %>
<% if FilesHeading %><h2>$FilesHeading</h2><% end_if %>
<% end_if %>
Expand All @@ -15,19 +15,19 @@ $Content

<% control Listing %>
<% if ClassName = Folder %>
<p class="item"><a class="mainlink" href="$Top.Link?fid=$ID"><img class="icon" src="/file-listing/images/folder.png"/><strong>$Title</strong></a></p>
<p class="item"><a class="mainlink" href="$Top.Link?fid=$ID"><img class="icon" src="file-listing/images/folder.png"/><strong>$Title</strong></a></p>

<% else_if ClassName = Image %>
<p class="item"><a class="mainlink" href="$setWidth(850).Link" class="lightbox" rel="gallery1" title="$Title" >
<img class="icon" src="/file-listing/images/photo.png"/>$Title</a> <a href="$Link" class="orig">(Download Original)</a><span> - Added $Created.Ago</span><br />
<img class="icon" src="file-listing/images/photo.png"/>$Title</a> <a href="$Link" class="orig">(Download Original)</a><span> - Added $Created.Ago</span><br />
<a href="$setWidth(850).Link" class="lightbox" rel="gallery2" title="$Title" ><img class="thumb" src="$setWidth(200).URL" width="$setWidth(200).Width" height="$setWidth(200).Height" /></a>
</p>

<% else_if Extension=="zip" || Extension=="ZIP" || Extension=="doc" || Extension=="DOC" || Extension=="DOCX" || Extension=="docx" || Extension=="xls" || Extension=="XLS" || Extension=="xlsx" || Extension=="XLSX" || Extension=="pdf" || Extension=="PDF" %>
<p class="item"><a class="mainlink" href="$Link">$Title ($Extension)</a><span> - Added $Created.Ago</span></p>

<% else %>
<p class="item"><img class="icon" src="/file-listing/images/page_white.png"/><a class="mainlink" href="$Link">$Title ($Extension)</a><span> - Added $Created.Ago</span></p>
<p class="item"><img class="icon" src="file-listing/images/page_white.png"/><a class="mainlink" href="$Link">$Title ($Extension)</a><span> - Added $Created.Ago</span></p>
<% end_if %>

<% end_control %>
Expand Down