FOSSology  4.4.0
Open Source License Compliance by Open Source Software
common-repo.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2008-2012 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: LGPL-2.1-only
6 */
7 
25 function GetMimeType($Item)
26 {
27  global $PG_CONN;
28 
29  $Sql = "SELECT mimetype_name
30  FROM uploadtree
31  INNER JOIN pfile ON pfile_pk = pfile_fk
32  INNER JOIN mimetype ON pfile.pfile_mimetypefk = mimetype.mimetype_pk
33  WHERE uploadtree_pk = $Item LIMIT 1;";
34  $result = pg_query($PG_CONN, $Sql);
35  DBCheckResult($result, $Sql, __FILE__, __LINE__);
36  if (pg_num_rows($result) > 0) {
37  $row = pg_fetch_assoc($result);
38  $Meta = $row['mimetype_name'];
39  } else {
40  $Meta = 'application/octet-stream';
41  }
42 
43  pg_free_result($result);
44  return($Meta);
45 } /* GetMimeType() */
46 
58 function RepPath($PfilePk, $Repo="files")
59 {
60  global $Plugins;
61  global $LIBEXECDIR;
62  global $PG_CONN;
63  if (empty($PG_CONN)) {
64  return;
65  }
66 
67  $sql = "SELECT * FROM pfile WHERE pfile_pk = $PfilePk LIMIT 1;";
68  $result = pg_query($PG_CONN, $sql);
69  DBCheckResult($result, $sql, __FILE__, __LINE__);
70  $Row = pg_fetch_assoc($result);
71  pg_free_result($result);
72  if (empty($Row['pfile_sha1'])) {
73  return (null);
74  }
75  $Hash = $Row['pfile_sha1'] . "." . $Row['pfile_md5'] . "." . $Row['pfile_size'];
76  exec("$LIBEXECDIR/reppath $Repo ".escapeshellarg($Hash), $Path);
77  return($Path[0]);
78 } // RepPath()
79 
91 function RepPathItem($Item, $Repo="files")
92 {
93  global $LIBEXECDIR;
94  global $PG_CONN;
95  if (empty($PG_CONN)) {
96  return;
97  }
98 
99  $sql = "SELECT * FROM pfile INNER JOIN uploadtree ON pfile_fk = pfile_pk
100  WHERE uploadtree_pk = $Item LIMIT 1;";
101  $result = pg_query($PG_CONN, $sql);
102  DBCheckResult($result, $sql, __FILE__, __LINE__);
103  $Row = pg_fetch_assoc($result);
104  pg_free_result($result);
105  if (empty($Row['pfile_sha1'])) {
106  return (null);
107  }
108  $Hash = $Row['pfile_sha1'] . "." . $Row['pfile_md5'] . "." . $Row['pfile_size'];
109  exec("$LIBEXECDIR/reppath $Repo ".escapeshellarg($Hash), $Path);
110  return($Path[0]);
111 }
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:187
RepPath($PfilePk, $Repo="files")
Given a pfile id, retrieve the pfile path.
Definition: common-repo.php:58
GetMimeType($Item)
Given an uploadtree_pk, return a string that describes the mime type.
Definition: common-repo.php:25
RepPathItem($Item, $Repo="files")
Given an uploadtree_pk, retrieve the pfile path.
Definition: common-repo.php:91
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN