mirror of
https://github.com/Yetangitu/owncloud-apps.git
synced 2025-10-02 14:49:17 +02:00
Initial commit
This commit is contained in:
parent
26dd81b2df
commit
993289d86b
51 changed files with 16863 additions and 0 deletions
67
files_opds/lib/files.php
Normal file
67
files_opds/lib/files.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ownCloud - Files_Opds App
|
||||
*
|
||||
* @author Frank de Lange
|
||||
* @copyright 2014 Frank de Lange
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Opds;
|
||||
|
||||
/**
|
||||
* Files class, extendes \OCA\Files, tailored for OPDS
|
||||
*/
|
||||
class Files extends \OCA\Files\Helper
|
||||
{
|
||||
/**
|
||||
* Formats the file info to be returned as OPDS to the client.
|
||||
*
|
||||
* @param \OCP\Files\FileInfo $i
|
||||
* @return array formatted file info
|
||||
*/
|
||||
public static function formatFileInfo($i) {
|
||||
$entry = array();
|
||||
|
||||
$entry['id'] = $i['fileid'];
|
||||
$entry['mtime'] = $i['mtime'] * 1000;
|
||||
$entry['icon'] = self::determineIcon($i);
|
||||
$entry['name'] = $i->getName();
|
||||
$entry['mimetype'] = $i['mimetype'];
|
||||
$entry['size'] = $i['size'];
|
||||
$entry['type'] = $i['type'];
|
||||
return $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format file info for OPDS feed
|
||||
* @param \OCP\Files\FileInfo[] $fileInfos file infos
|
||||
*/
|
||||
public static function formatFileInfos($fileInfos) {
|
||||
$files = array();
|
||||
/* if set, add only files with given extensions */
|
||||
$fileTypes = array_filter(explode(',', strtolower(Config::get('file_types', ''))));
|
||||
foreach ($fileInfos as $i) {
|
||||
if((!empty($fileTypes)) && (!in_array(strtolower(substr(strrchr($i->getName(), "."), 1)), $fileTypes))) {
|
||||
continue;
|
||||
}
|
||||
$files[] = self::formatFileInfo($i);
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief check if $child is a subdirectory of $parent
|
||||
*
|
||||
* @param string $parent a directory
|
||||
* @param string $child a directory
|
||||
* @return bool true if $child is a subdirectory of $parent
|
||||
*/
|
||||
public static function isChild($parent, $child) {
|
||||
return strpos($child, $parent . '/') === 0;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue