api.forum.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. class forum {
  13. var $topics = array();
  14. var $error = '';
  15. var $sort_all = array();
  16. public function __construct() {
  17. if (!$this->loadTopicsData()) {
  18. return false;
  19. }
  20. }
  21. function loadTopicsData() {
  22. if (!is_readable(FORUM_PATH . 'topic_index.dat')) {
  23. $this->error = __('Cannot load topics data');
  24. return false;
  25. }
  26. $content = file_get_contents(FORUM_PATH . 'topic_index.dat');
  27. if (($topics = @unserialize($content)) == false) {
  28. $this->error = __('Topics data corrupted');
  29. return false;
  30. }
  31. $this->topics = $topics;
  32. return true;
  33. }
  34. function getTopicData($topic_id) {
  35. return $this->topics[$topic_id];
  36. }
  37. function getFreshTopics($number) {
  38. $this->sortTopics($this->sort_all);
  39. return array_slice($this->sort_all, 0, $number);
  40. }
  41. function sortTopics(&$output, $method = 'all') {
  42. switch ($method) {
  43. case 'all' :
  44. $output = array();
  45. foreach ($this->topics as $topic_id => $topic) {
  46. if (!empty($topic)) {
  47. $output[$topic['last_reply']] = $topic_id;
  48. }
  49. }
  50. krsort($output);
  51. return true;
  52. break;
  53. }
  54. }
  55. }
  56. ?>