sub_checkpost.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: sub_checkpost.php 32489 2013-01-29 03:57:16Z monkey $
  7. */
  8. if(!defined('IN_MOBILE_API')) {
  9. exit('Access Denied');
  10. }
  11. class mobile_api_sub {
  12. public static function getvariable() {
  13. global $_G;
  14. if(empty($_G['forum'])) {
  15. $allowpost = 0;
  16. } elseif(!$_G['uid'] && !((!$_G['forum']['postperm'] && $_G['group']['allowpost']) || ($_G['forum']['postperm'] && forumperm($_G['forum']['postperm'])))) {
  17. $allowpost = 0;
  18. } elseif(empty($_G['forum']['allowpost'])) {
  19. if(!$_G['forum']['postperm'] && !$_G['group']['allowpost']) {
  20. $allowpost = 0;
  21. } elseif($_G['forum']['postperm'] && !forumperm($_G['forum']['postperm'])) {
  22. $allowpost = 0;
  23. } else {
  24. $allowpost = 1;
  25. }
  26. } elseif($_G['forum']['allowpost'] == -1) {
  27. $allowpost = 0;
  28. } else {
  29. $allowpost = 1;
  30. }
  31. if(empty($_G['forum'])) {
  32. $allowreply = 0;
  33. } elseif(!$_G['uid'] && !((!$_G['forum']['replyperm'] && $_G['group']['allowreply']) || ($_G['forum']['replyperm'] && forumperm($_G['forum']['replyperm'])))) {
  34. $allowreply = 0;
  35. } elseif(empty($_G['forum']['allowreply'])) {
  36. if(!$_G['forum']['replyperm'] && !$_G['group']['allowreply']) {
  37. $allowreply = 0;
  38. } elseif($_G['forum']['replyperm'] && !forumperm($_G['forum']['replyperm'])) {
  39. $allowreply = 0;
  40. } else {
  41. $allowreply = 1;
  42. }
  43. } elseif($_G['forum']['allowreply'] == -1) {
  44. $allowreply = 0;
  45. } else {
  46. $allowreply = 1;
  47. }
  48. $mobile_attachextensions = array('jpg', 'jpeg', 'gif', 'png', 'mp3', 'txt', 'zip', 'rar', 'pdf');
  49. $_G['forum']['allowpostattach'] = isset($_G['forum']['allowpostattach']) ? $_G['forum']['allowpostattach'] : '';
  50. $allowupload = $_G['forum']['allowpostattach'] != -1 && ($_G['forum']['allowpostattach'] == 1 || (!$_G['forum']['postattachperm'] && $_G['group']['allowpostattach']) || ($_G['forum']['postattachperm'] && forumperm($_G['forum']['postattachperm'])));
  51. $allowupload = $allowupload && (!$_G['group']['maxattachnum'] || $_G['group']['maxattachnum'] && $_G['group']['maxattachnum'] > getuserprofile('todayattachs'));
  52. $attachremain = array();
  53. if($allowupload) {
  54. $attachextensions = !$_G['group']['attachextensions'] ? $mobile_attachextensions : array_map('trim', explode(',', $_G['group']['attachextensions']));
  55. $allowupload = $forummaxattachsize = array();
  56. loadcache('attachtype');
  57. if(isset($_G['cache']['attachtype'][$_G['forum']['fid']])) {
  58. $attachtype = $_G['cache']['attachtype'][$_G['forum']['fid']];
  59. } elseif(isset($_G['cache']['attachtype'][0])) {
  60. $attachtype = $_G['cache']['attachtype'][0];
  61. } else {
  62. $attachtype = array();
  63. }
  64. if($attachtype) {
  65. foreach($attachtype as $extension => $maxsize) {
  66. $forummaxattachsize[$extension] = $maxsize;
  67. }
  68. }
  69. foreach($mobile_attachextensions as $ext) {
  70. if(in_array($ext, $attachextensions)) {
  71. if(isset($forummaxattachsize[$ext])) {
  72. if($forummaxattachsize[$ext] > 0) {
  73. $allowupload[$ext] = $forummaxattachsize[$ext] ? $forummaxattachsize[$ext] : $_G['group']['maxattachsize'];
  74. } else {
  75. $allowupload[$ext] = 0;
  76. }
  77. } else {
  78. $allowupload[$ext] = -1;
  79. }
  80. } else {
  81. $allowupload[$ext] = 0;
  82. }
  83. }
  84. $attachremain = array(
  85. 'size' => $_G['group']['maxsizeperday'] ? $_G['group']['maxsizeperday'] - getuserprofile('todayattachsize') : -1,
  86. 'count' => $_G['group']['maxattachnum'] ? $_G['group']['maxattachnum'] - getuserprofile('todayattachs') : -1,
  87. );
  88. } else {
  89. $allowupload = array();
  90. }
  91. $uploadhash = md5(substr(md5($_G['config']['security']['authkey']), 8).$_G['uid']);
  92. $allowperm = array();
  93. $allowperm['allowperm'] = array();
  94. $allowkey = array('allowpost', 'allowreply', 'allowupload', 'attachremain', 'uploadhash');
  95. foreach($allowkey as $key) {
  96. if((!empty(${$key}) || ${$key} === 0) || !empty($_GET['debug'])) {
  97. $allowperm['allowperm'][$key] = ${$key};
  98. }
  99. }
  100. return $allowperm;
  101. }
  102. }
  103. ?>