api.linksdb.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // Copyright (C) ReloadCMS Development Team //
  4. // http://reloadcms.sf.net //
  5. // //
  6. // This program is distributed in the hope that it will be useful, //
  7. // but WITHOUT ANY WARRANTY, without even the implied warranty of //
  8. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
  9. // //
  10. // This product released under GNU General Public License v2 //
  11. ////////////////////////////////////////////////////////////////////////////////
  12. define('DOWNLOADS_DATAFILE', DF_PATH . 'downloads.dat');
  13. class linksdb {
  14. var $file = '';
  15. var $data = array();
  16. public function __construct($file) {
  17. $this->file = $file;
  18. if (is_readable($file) && $data = unserialize(file_get_contents($file)))
  19. $this->data = $data;
  20. else
  21. $this->data = array();
  22. }
  23. function createCategory($name, $desc, $level = 0) {
  24. if (empty($name))
  25. return false;
  26. $this->data[] = array('name' => $name, 'desc' => $desc, 'files' => array(), 'accesslevel' => $level);
  27. return true;
  28. }
  29. function updateCategory($id, $name, $desc, $level = 0) {
  30. if (empty($name))
  31. return false;
  32. if (empty($this->data[$id]))
  33. return false;
  34. $this->data[$id]['name'] = $name;
  35. $this->data[$id]['desc'] = $desc;
  36. $this->data[$id]['accesslevel'] = $level;
  37. return true;
  38. }
  39. function deleteCategory($id) {
  40. if (!isset($this->data[$id]))
  41. return false;
  42. unset($this->data[$id]);
  43. return true;
  44. }
  45. function createFile($cid, $name, $desc, $link, $size, $author) {
  46. if (empty($name))
  47. return false;
  48. if (empty($this->data[$cid]))
  49. return false;
  50. $this->data[$cid]['files'][] = array('name' => $name, 'desc' => $desc, 'link' => $link, 'size' => $size, 'date' => rcms_get_time(), 'author' => $author, 'count' => 0);
  51. return true;
  52. }
  53. function updateFile($cid, $fid, $name, $desc, $link, $size, $author) {
  54. if (empty($name))
  55. return false;
  56. if (empty($this->data[$cid]))
  57. return false;
  58. if (empty($this->data[$cid]['files'][$fid]))
  59. return false;
  60. $this->data[$cid]['files'][$fid]['name'] = $name;
  61. $this->data[$cid]['files'][$fid]['desc'] = $desc;
  62. $this->data[$cid]['files'][$fid]['link'] = $link;
  63. $this->data[$cid]['files'][$fid]['size'] = $size;
  64. $this->data[$cid]['files'][$fid]['author'] = $author;
  65. return true;
  66. }
  67. function deleteFile($cid, $fid) {
  68. if (empty($this->data[$cid]))
  69. return false;
  70. unset($this->data[$cid]['files'][$fid]);
  71. return true;
  72. }
  73. function getLastFiles($cnt) {
  74. global $system;
  75. $files = array();
  76. foreach ($this->data as $cid => $cdata) {
  77. if (@$cdata['accesslevel'] <= @$system->user['accesslevel'] || $system->checkForRight('-any-')) {
  78. foreach ($cdata['files'] as $fid => $fdata) {
  79. $files[$cid . '.' . $fid] = $fdata['date'];
  80. }
  81. }
  82. }
  83. natsort($files);
  84. $files = array_slice($files, -10);
  85. $return = array();
  86. foreach ($files as $id => $date) {
  87. $return[] = explode('.', $id);
  88. }
  89. return $return;
  90. }
  91. function close() {
  92. $res = array();
  93. foreach ($this->data as $key => $value)
  94. if (!empty($value))
  95. $res[$key] = $value;
  96. if (!($data = serialize($res)))
  97. return false;
  98. if (!(file_write_contents($this->file, $data)))
  99. return false;
  100. $this->file = '';
  101. $this->data = array();
  102. return true;
  103. }
  104. }
  105. ?>