Source for file api.pm.php

Documentation is available at api.pm.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_PM_DEFAULT_FILE', DATA_PATH.'/pm/'.$system->user['username'].'.dat');
  16.  
  17. function pm_disabled()
  18. {
  19. $arr = parse_ini_file(CONFIG_PATH . 'disable.ini');
  20. return isset($arr['pm']);
  21. }
  22.  
  23. function make_pm_file($file)
  24. {
  25. if (!file_exists($file)) {
  26. $f = fopen($file, "w");
  27. fclose($f);
  28. }
  29. }
  30.  
  31. function getUserData($username){
  32. global $system;
  33. $result = @unserialize(@file_get_contents(USERS_PATH . basename($username)));
  34. if(empty($result)) return false; else return $result;
  35. }
  36.  
  37. make_pm_file(RCMS_PM_DEFAULT_FILE);
  38.  
  39. $_CACHE['gbook'] = array();
  40.  
  41. function pm_get_msgs($page = 0, $parse = true, $limited = true, $file = RCMS_PM_DEFAULT_FILE) {
  42. global $_CACHE, $system;
  43. $all_pm = 0;
  44. $new_pm = 0;
  45. $pm_hint = __('No new messages');
  46. $ret = array($all_pm, $new_pm, $pm_hint);
  47. $data = &$_CACHE['gbook'][$file];
  48. if(!isset($data)) {
  49. if (!is_readable($file) || !($data = unserialize(file_get_contents($file)))) $data = array();
  50. }
  51. if(!empty($data)){
  52. $c = sizeof($data);
  53. $ndata = $rdata = array();
  54. foreach ($data as $key => $value) $ndata[$key . ''] = $value;
  55. $ndata = array_reverse($ndata, true);
  56. if($page !== null){
  57. $i = 0;
  58. while($i < (($page+1) * $system->config['perpage']) && $el = each($ndata)){
  59. if($i >= $page * $system->config['perpage']) $rdata[$el['key']] = $el['value'];
  60. $i++;
  61. }
  62. } else {
  63. $rdata = $ndata;
  64. }
  65. if($parse){
  66. foreach($rdata as $id => $msg){
  67. if(!empty($msg)) {
  68. $rdata[$id]['text'] = rcms_parse_text($msg['text'], !$limited, false, !$limited);
  69. $all_pm++;
  70. if ($msg['new'] == "1"){
  71. $new_pm++;
  72. $pm_hint = rcms_format_time('H:i:s d.m.Y', $msg['time']).' - '.__('last new message from ').$msg['username'].' ('.$msg['nickname'].')';
  73. }
  74. }
  75. }
  76. }
  77. return array($all_pm, $new_pm, $pm_hint);
  78. } else return $ret;
  79. }
  80.  
  81. function pm_get_msg_by_id($num = 10, $parse = true, $limited, $mid = '0', $file = RCMS_PM_DEFAULT_FILE) {
  82. global $_CACHE, $system;
  83. $t='';
  84. $data = &$_CACHE['gbook'][$file];
  85. if(!isset($data)) {
  86. if (!is_readable($file) || !($data = unserialize(file_get_contents($file)))) $data = array();
  87. }
  88. if(!empty($data)){
  89. $ndata = $rdata = array();
  90. foreach ($data as $key => $value) $ndata[$key . ''] = $value;
  91. $ndata = array_reverse($ndata, true);
  92. if($num !== null){
  93. $i = 0;
  94. while($i < $num && $el = each($ndata)){
  95. $rdata[$el['key']] = $el['value'];
  96. $i++;
  97. }
  98. } else {
  99. $rdata = $ndata;
  100. }
  101. if($parse){
  102. $t= $rdata[$mid]['text'];
  103. }
  104. }
  105. return $t;
  106. }
  107.  
  108. function pm_get_all_msgs($num = 10, $parse = true, $limited, $file = RCMS_PM_DEFAULT_FILE) {
  109. global $_CACHE, $system;
  110. $data = &$_CACHE['gbook'][$file];
  111. if(!isset($data)) {
  112. if (!is_readable($file) || !($data = unserialize(file_get_contents($file)))) $data = array();
  113. }
  114. if(!empty($data)){
  115. $ndata = $rdata = array();
  116. foreach ($data as $key => $value) $ndata[$key . ''] = $value;
  117. $ndata = array_reverse($ndata, true);
  118. if($num !== null){
  119. $i = 0;
  120. while($i < $num && $el = each($ndata)){
  121. $rdata[$el['key']] = $el['value'];
  122. $i++;
  123. }
  124. } else {
  125. $rdata = $ndata;
  126. }
  127. if($parse){
  128. foreach($rdata as $id => $msg){
  129. if(!empty($msg)) {
  130. $rdata[$id]['text'] = rcms_parse_text($msg['text'], !$limited, false, !$limited);
  131. $rdata[$id]['new'] = $msg['new'];
  132. $rdata[$id]['username'] = $msg['username'];
  133. $rdata[$id]['nickname'] = $msg['nickname'];
  134. $rdata[$id]['time'] = rcms_format_time('H:i:s d.m.Y', $msg['time']);
  135. }
  136. }
  137. }
  138. return $rdata;
  139. } else return array();
  140. }
  141.  
  142. function pm_set_all_nonew($num = 10, $parse = true, $limited, $file = RCMS_PM_DEFAULT_FILE) {
  143. global $_CACHE, $system;
  144. $data = &$_CACHE['gbook'][$file];
  145. if(!isset($data)) {
  146. if (!is_readable($file) || !($data = unserialize(file_get_contents($file)))) $data = array();
  147. }
  148. if(!empty($data)){
  149. $ndata = $rdata = array();
  150. foreach ($data as $key => $value) $ndata[$key . ''] = $value;
  151. if($num !== null){
  152. $i = 0;
  153. while($i < $num && $el = each($ndata)){
  154. $rdata[$el['key']] = $el['value'];
  155. $i++;
  156. }
  157. } else {
  158. $rdata = $ndata;
  159. }
  160. if($parse){
  161. foreach($rdata as $id => $msg){
  162. if(!empty($msg)) {
  163. $msg['new'] = '0';
  164. $rdata[$id]=$msg;
  165. }
  166. }
  167. }
  168. return file_write_contents($file, serialize($rdata));
  169. }
  170. }
  171.  
  172. function pm_get_pages_num($file = RCMS_PM_DEFAULT_FILE) {
  173. global $_CACHE, $system;
  174. $data = &$_CACHE['gbook'][$file];
  175. if(!isset($data)) {
  176. if (!is_readable($file) || !($data = unserialize(file_get_contents($file)))) $data = array();
  177. }
  178. if(!empty($system->config['perpage'])) {
  179. return ceil(sizeof($data)/$system->config['perpage']);
  180. } else return 1;
  181. }
  182.  
  183. function pm_post_msg($username, $nickname, $text, $to) {
  184. global $_CACHE, $system;
  185. $text = trim($text);
  186. if(empty($text)) return false;
  187. if(!getUserData($to)) return false;
  188. $file = DATA_PATH.'/pm/'.$to.'.dat';
  189. make_pm_file($file);
  190. $data = &$_CACHE['gbook'][$file];
  191. if(!isset($data)) {
  192. if (!is_readable($file) || !($data = unserialize(file_get_contents($file)))) $data = array();
  193. }
  194. $newmesg['username'] = $username;
  195. $newmesg['nickname'] = htmlspecialchars($nickname);
  196. $newmesg['time'] = rcms_get_time();
  197. $newmesg['text'] = $text;
  198. $newmesg['new'] = '1';
  199. $data[] = $newmesg;
  200. return file_write_contents($file, serialize($data));
  201. }
  202.  
  203. function pm_post_remove($id, $file = RCMS_PM_DEFAULT_FILE) {
  204. global $_CACHE;
  205. $data = &$_CACHE['gbook'][$file];
  206. if(!isset($data)) {
  207. if (!is_readable($file) || !($data = unserialize(file_get_contents($file)))) $data = array();
  208. }
  209. rcms_remove_index($id, $data, true);
  210. return file_write_contents($file, serialize($data));
  211. }
  212. ?>

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