forked from pellcorp/opendb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_type.php
135 lines (119 loc) · 3.93 KB
/
file_type.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/*
OpenDb Media Collector Database
Copyright (C) 2001,2013 by Jason Pell
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
include_once("./lib/database.php");
include_once("./lib/logging.php");
function is_exists_file_type($content_type) {
$content_type = validate_content_type ( $content_type );
if (strlen ( $content_type ) > 0) {
$query = "SELECT 'x' FROM s_file_type WHERE content_type = '" . strtolower ( $content_type ) . "'";
$result = db_query ( $query );
if ($result && db_num_rows ( $result ) > 0) {
db_free_result ( $result );
return TRUE;
}
}
//else
return FALSE;
}
function is_exists_file_type_content_group($content_group) {
if (strlen ( $content_group ) > 0) {
$query = "SELECT 'x' FROM s_file_type_content_group WHERE content_group = '" . $content_group . "'";
$result = db_query ( $query );
if ($result && db_num_rows ( $result ) > 0) {
db_free_result ( $result );
return TRUE;
}
}
//else
return FALSE;
}
function fetch_file_type_for_extension($extension) {
$extension = strtolower ( trim ( $extension ) );
if (strlen ( $extension ) > 0) {
$query = "SELECT DISTINCT content_type
FROM s_file_type_extension
WHERE extension = '" . $extension . "'";
$result = db_query ( $query );
if ($result && db_num_rows ( $result ) > 0) {
$record_r = db_fetch_assoc ( $result );
db_free_result ( $result );
return $record_r ['content_type'];
} else {
return FALSE;
}
} else {
return FALSE;
}
}
function fetch_file_type_r($content_type) {
$content_type = validate_content_type ( $content_type );
if (strlen ( $content_type ) > 0) {
$query = "SELECT DISTINCT sft.content_group, sfte.extension, sft.content_type, sft.description, sft.image, sft.thumbnail_support_ind
FROM s_file_type sft,
s_file_type_extension sfte
WHERE sft.content_type = sfte.content_type AND
sfte.default_ind = 'Y' AND
sft.content_type = '" . $content_type . "'";
$result = db_query ( $query );
if ($result && db_num_rows ( $result ) > 0) {
$record_r = db_fetch_assoc ( $result );
db_free_result ( $result );
return $record_r;
} else {
return FALSE;
}
} else {
return FALSE;
}
}
/**
If content type includes a ; encoding remove it before checking
*/
function validate_content_type($content_type) {
$content_type = strtolower ( trim ( $content_type ) );
$index = strpos ( $content_type, ';' );
if ($index !== FALSE) {
$content_type = substr ( $content_type, 0, $index );
}
return $content_type;
}
/**
Its possible to specify an array of content groups
*/
function fetch_file_type_extensions_r($content_group) {
if (! is_array ( $content_group ) && strlen ( $content_group ) > 0)
$content_group_r [] = $content_group;
else if (is_array ( $content_group ))
$content_group_r = & $content_group;
$query = "SELECT sfte.extension
FROM s_file_type sft,
s_file_type_extension sfte
WHERE sft.content_type = sfte.content_type";
if (is_array ( $content_group_r )) {
$query .= " AND sft.content_group IN(" . format_sql_in_clause ( $content_group_r ) . ")";
}
$extensions_r = array ();
$results = db_query ( $query );
if ($results && db_num_rows ( $results ) > 0) {
while ( $extensions_rs = db_fetch_assoc ( $results ) ) {
$extensions_r [] = strtolower ( $extensions_rs ['extension'] );
}
db_free_result ( $results );
}
return $extensions_r;
}
?>