Source for file api.guestbook.php

Documentation is available at api.guestbook.php

  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.  
  13.  
  14.  
  15. define('RCMS_GB_DEFAULT_FILE', DF_PATH . 'guestbook.dat');
  16. define('RCMS_MC_DEFAULT_FILE', DF_PATH . 'minichat.dat');
  17. $_CACHE['gbook'] = array();
  18.  
  19. function guestbook_get_msgs($page = 0, $parse = true, $limited = true, $file = RCMS_GB_DEFAULT_FILE, $config = 'guestbook.ini') {
  20. global $_CACHE, $system;
  21. $config = parse_ini_file(CONFIG_PATH . $config);
  22. $data = &$_CACHE['gbook'][$file];
  23. if(!isset($data)) {
  24. if (!is_readable($file) || !($data = unserialize(file_get_contents($file)))) $data = array();
  25. }
  26. if(!empty($data)){
  27. $c = sizeof($data);
  28. $ndata = $rdata = array();
  29. foreach ($data as $key => $value) $ndata[$key . ''] = $value;
  30. $ndata = array_reverse($ndata, true);
  31. if($page !== null){
  32. $i = 0;
  33. while($i < (($page+1) * $system->config['perpage']) && $el = each($ndata)){
  34. if($i >= $page * $system->config['perpage']) $rdata[$el['key']] = $el['value'];
  35. $i++;
  36. }
  37. } else {
  38. $rdata = $ndata;
  39. }
  40. if($parse){
  41. foreach($rdata as $id => $msg){
  42. if(!empty($msg)) $rdata[$id]['text'] = rcms_parse_text($msg['text'], !$limited, false, !$limited);
  43. }
  44. }
  45. return $rdata;
  46. } else return array();
  47. }
  48.  
  49. function guestbook_get_last_msgs($num = 10, $parse = true, $limited, $file = RCMS_GB_DEFAULT_FILE, $config = 'guestbook.ini') {
  50. global $_CACHE, $system;
  51. $config = parse_ini_file(CONFIG_PATH . $config);
  52. $data = &$_CACHE['gbook'][$file];
  53. if(!isset($data)) {
  54. if (!is_readable($file) || !($data = unserialize(file_get_contents($file)))) $data = array();
  55. }
  56. if(!empty($data)){
  57. $ndata = $rdata = array();
  58. foreach ($data as $key => $value) $ndata[$key . ''] = $value;
  59. $ndata = array_reverse($ndata, true);
  60. if($num !== null){
  61. $i = 0;
  62. while($i < $num && $el = each($ndata)){
  63. $rdata[$el['key']] = $el['value'];
  64. $i++;
  65. }
  66. } else {
  67. $rdata = $ndata;
  68. }
  69. if($parse){
  70. foreach($rdata as $id => $msg){
  71. if(!empty($msg)) {
  72. $rdata[$id]['text'] = rcms_parse_text($msg['text'], !$limited, false, !$limited);
  73. }
  74. }
  75. }
  76. return $rdata;
  77. } else return array();
  78. }
  79.  
  80. function guestbook_get_pages_num($file = RCMS_GB_DEFAULT_FILE, $config = 'guestbook.ini') {
  81. global $_CACHE, $system;
  82. $config = parse_ini_file(CONFIG_PATH . $config);
  83. $data = &$_CACHE['gbook'][$file];
  84. if(!isset($data)) {
  85. if (!is_readable($file) || !($data = unserialize(file_get_contents($file)))) $data = array();
  86. }
  87. if(!empty($system->config['perpage'])) {
  88. return ceil(sizeof($data)/$system->config['perpage']);
  89. } else return 1;
  90. }
  91.  
  92. function guestbook_post_msg($username, $nickname, $text, $file = RCMS_GB_DEFAULT_FILE, $config = 'guestbook.ini') {
  93. global $_CACHE;
  94. $text = trim($text);
  95. if(empty($text)) return false;
  96. $config = parse_ini_file(CONFIG_PATH . $config);
  97. $data = &$_CACHE['gbook'][$file];
  98. if(!isset($data)) {
  99. if (!is_readable($file) || !($data = unserialize(file_get_contents($file)))) $data = array();
  100. }
  101. if(!empty($config['max_db_size'])) $data = array_slice($data, -$config['max_db_size']+1);
  102. $newmesg['username'] = $username;
  103. $newmesg['nickname'] = (!empty($config['max_word_len']) && strlen($nickname) > $config['max_word_len']) ? '<abbr title="' . htmlspecialchars($nickname) . '">' . substr($nickname, 0, $config['max_word_len']) . '</abbr>' : htmlspecialchars($nickname);
  104. $newmesg['time'] = rcms_get_time();
  105. $newmesg['text'] = (strlen($text) > $config['max_message_len']) ? substr($text, 0, $config['max_message_len']) : $text;
  106. $data[] = $newmesg;
  107. return file_write_contents($file, serialize($data));
  108. }
  109.  
  110. function guestbook_post_remove($id, $file = RCMS_GB_DEFAULT_FILE, $config = 'guestbook.ini') {
  111. global $_CACHE;
  112. $config = parse_ini_file(CONFIG_PATH . $config);
  113. $data = &$_CACHE['gbook'][$file];
  114. if(!isset($data)) {
  115. if (!is_readable($file) || !($data = unserialize(file_get_contents($file)))) $data = array();
  116. }
  117. rcms_remove_index($id, $data, true);
  118. return file_write_contents($file, serialize($data));
  119. }
  120. ?>

Documentation generated on Fri, 08 Jun 2007 12:21:20 +0300 by phpDocumentor 1.3.0RC3