FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
common-repo.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************
3  Copyright (C) 2008-2012 Hewlett-Packard Development Company, L.P.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License version 2.1 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this library; if not, write to the Free Software Foundation, Inc.0
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 ***********************************************************/
18 
36 function GetMimeType($Item)
37 {
38  global $PG_CONN;
39 
40  $Sql = "SELECT mimetype_name
41  FROM uploadtree
42  INNER JOIN pfile ON pfile_pk = pfile_fk
43  INNER JOIN mimetype ON pfile.pfile_mimetypefk = mimetype.mimetype_pk
44  WHERE uploadtree_pk = $Item LIMIT 1;";
45  $result = pg_query($PG_CONN, $Sql);
46  DBCheckResult($result, $Sql, __FILE__, __LINE__);
47  if (pg_num_rows($result) > 0) {
48  $row = pg_fetch_assoc($result);
49  $Meta = $row['mimetype_name'];
50  } else {
51  $Meta = 'application/octet-stream';
52  }
53 
54  pg_free_result($result);
55  return($Meta);
56 } /* GetMimeType() */
57 
69 function RepPath($PfilePk, $Repo="files")
70 {
71  global $Plugins;
72  global $LIBEXECDIR;
73  global $PG_CONN;
74  if (empty($PG_CONN)) {
75  return;
76  }
77 
78  $sql = "SELECT * FROM pfile WHERE pfile_pk = $PfilePk LIMIT 1;";
79  $result = pg_query($PG_CONN, $sql);
80  DBCheckResult($result, $sql, __FILE__, __LINE__);
81  $Row = pg_fetch_assoc($result);
82  pg_free_result($result);
83  if (empty($Row['pfile_sha1'])) {
84  return (null);
85  }
86  $Hash = $Row['pfile_sha1'] . "." . $Row['pfile_md5'] . "." . $Row['pfile_size'];
87  exec("$LIBEXECDIR/reppath $Repo $Hash", $Path);
88  return($Path[0]);
89 } // RepPath()
90 
102 function RepPathItem($Item, $Repo="files")
103 {
104  global $LIBEXECDIR;
105  global $PG_CONN;
106  if (empty($PG_CONN)) {
107  return;
108  }
109 
110  $sql = "SELECT * FROM pfile INNER JOIN uploadtree ON pfile_fk = pfile_pk
111  WHERE uploadtree_pk = $Item LIMIT 1;";
112  $result = pg_query($PG_CONN, $sql);
113  DBCheckResult($result, $sql, __FILE__, __LINE__);
114  $Row = pg_fetch_assoc($result);
115  pg_free_result($result);
116  if (empty($Row['pfile_sha1'])) {
117  return (null);
118  }
119  $Hash = $Row['pfile_sha1'] . "." . $Row['pfile_md5'] . "." . $Row['pfile_size'];
120  exec("$LIBEXECDIR/reppath $Repo $Hash", $Path);
121  return($Path[0]);
122 }
RepPath($PfilePk, $Repo="files")
Given a pfile id, retrieve the pfile path.
Definition: common-repo.php:69
RepPathItem($Item, $Repo="files")
Given an uploadtree_pk, retrieve the pfile path.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:198
GetMimeType($Item)
Given an uploadtree_pk, return a string that describes the mime type.
Definition: common-repo.php:36