PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/source/class/helper/helper_form.php

https://github.com/kuaileshike/upload
PHP | 190 lines | 176 code | 8 blank | 6 comment | 40 complexity | a829ff09f4b2889ccb80e7d7b447b958 MD5 | raw file
  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: helper_form.php 30757 2012-06-18 06:23:23Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class helper_form {
  12. public static function submitcheck($var, $allowget = 0, $seccodecheck = 0, $secqaacheck = 0) {
  13. if(!getgpc($var)) {
  14. return FALSE;
  15. } else {
  16. global $_G;
  17. if($allowget || ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_GET['formhash']) && $_GET['formhash'] == formhash() && empty($_SERVER['HTTP_X_FLASH_VERSION']) && (empty($_SERVER['HTTP_REFERER']) ||
  18. preg_replace("/https?:\/\/([^\:\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) == preg_replace("/([^\:]+).*/", "\\1", $_SERVER['HTTP_HOST'])))) {
  19. if(checkperm('seccode')) {
  20. if($secqaacheck && !check_secqaa($_GET['secanswer'], $_GET['sechash'])) {
  21. showmessage('submit_secqaa_invalid');
  22. }
  23. if($seccodecheck && !check_seccode($_GET['seccodeverify'], $_GET['sechash'])) {
  24. showmessage('submit_seccode_invalid');
  25. }
  26. }
  27. return TRUE;
  28. } else {
  29. showmessage('submit_invalid');
  30. }
  31. }
  32. }
  33. public static function censor($message, $modword = NULL, $return = FALSE) {
  34. global $_G;
  35. $censor = discuz_censor::instance();
  36. $censor->check($message, $modword);
  37. if($censor->modbanned() && empty($_G['group']['ignorecensor'])) {
  38. $wordbanned = implode(', ', $censor->words_found);
  39. if($return) {
  40. return array('message' => lang('message', 'word_banned', array('wordbanned' => $wordbanned)));
  41. }
  42. if(!defined('IN_ADMINCP')) {
  43. showmessage('word_banned', '', array('wordbanned' => $wordbanned));
  44. } else {
  45. cpmsg(lang('message', 'word_banned'), '', 'error', array('wordbanned' => $wordbanned));
  46. }
  47. }
  48. if($_G['group']['allowposturl'] == 0 || $_G['group']['allowposturl'] == 2) {
  49. $urllist = self::get_url_list($message);
  50. if(is_array($urllist[1])) foreach($urllist[1] as $key => $val) {
  51. if(!$val = trim($val)) continue;
  52. if(!iswhitelist($val)) {
  53. if($_G['group']['allowposturl'] == 0) {
  54. if($return) {
  55. return array('message' => 'post_url_nopermission');
  56. }
  57. showmessage('post_url_nopermission');
  58. } elseif($_G['group']['allowposturl'] == 2) {
  59. $message = str_replace('[url]'.$urllist[0][$key].'[/url]', $urllist[0][$key], $message);
  60. $message = preg_replace(
  61. array(
  62. "@\[url=[^\]]*?".preg_quote($urllist[0][$key],'@')."[^\]]*?\](.*?)\[/url\]@is",
  63. "@href=('|\")".preg_quote($urllist[0][$key],'@')."\\1@is",
  64. "@\[url\]([^\]]*?".preg_quote($urllist[0][$key],'@')."[^\]]*?)\[/url\]@is",
  65. ),
  66. array(
  67. '\\1',
  68. '',
  69. '\\1',
  70. ),
  71. $message);
  72. }
  73. }
  74. }
  75. }
  76. return $message;
  77. }
  78. public static function censormod($message) {
  79. global $_G;
  80. if($_G['group']['ignorecensor']) {
  81. return false;
  82. }
  83. $modposturl = false;
  84. if($_G['group']['allowposturl'] == 1) {
  85. $urllist = self::get_url_list($message);
  86. if(is_array($urllist[1])) foreach($urllist[1] as $key => $val) {
  87. if(!$val = trim($val)) continue;
  88. if(!iswhitelist($val)) {
  89. $modposturl = true;
  90. }
  91. }
  92. }
  93. if($modposturl) {
  94. return true;
  95. }
  96. $censor = discuz_censor::instance();
  97. $censor->check($message);
  98. return $censor->modmoderated();
  99. }
  100. public static function check_seccode($value, $idhash) {
  101. global $_G;
  102. if(!$_G['setting']['seccodestatus']) {
  103. return true;
  104. }
  105. if(!is_numeric($_G['setting']['seccodedata']['type'])) {
  106. if(file_exists($codefile = libfile('seccode/'.$_G['setting']['seccodedata']['type'], 'class'))) {
  107. @include_once $codefile;
  108. $class = 'seccode_'.$_G['setting']['seccodedata']['type'];
  109. if(class_exists($class)) {
  110. $code = new $class();
  111. $code->setting = $_G['setting']['seccodedata']['extra'][$_G['setting']['seccodedata']['type']];
  112. if(method_exists($code, 'check')) {
  113. return $code->check($value, $idhash);
  114. }
  115. }
  116. }
  117. return false;
  118. }
  119. if(!isset($_G['cookie']['seccode'.$idhash])) {
  120. return false;
  121. }
  122. list($checkvalue, $checktime, $checkidhash, $checkformhash) = explode("\t", authcode($_G['cookie']['seccode'.$idhash], 'DECODE', $_G['config']['security']['authkey']));
  123. return $checkvalue == strtoupper($value) && TIMESTAMP - 180 > $checktime && $checkidhash == $idhash && FORMHASH == $checkformhash;
  124. }
  125. public static function check_secqaa($value, $idhash) {
  126. global $_G;
  127. if(!$_G['setting']['secqaa']) {
  128. return true;
  129. }
  130. if(!isset($_G['cookie']['secqaa'.$idhash])) {
  131. return false;
  132. }
  133. loadcache('secqaa');
  134. list($checkvalue, $checktime, $checkidhash, $checkformhash) = explode("\t", authcode($_G['cookie']['secqaa'.$idhash], 'DECODE', $_G['config']['security']['authkey']));
  135. return $checkvalue == md5($value) && TIMESTAMP - 180 > $checktime && $checkidhash == $idhash && FORMHASH == $checkformhash;
  136. }
  137. public static function get_url_list($message) {
  138. $return = array();
  139. (strpos($message, '[/img]') || strpos($message, '[/flash]')) && $message = preg_replace("/\[img[^\]]*\]\s*([^\[\<\r\n]+?)\s*\[\/img\]|\[flash[^\]]*\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/is", '', $message);
  140. if(preg_match_all("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^ \[\]\"']+/i", $message, $urllist)) {
  141. foreach($urllist[0] as $key => $val) {
  142. $val = trim($val);
  143. $return[0][$key] = $val;
  144. if(!preg_match('/^http:\/\//is', $val)) $val = 'http://'.$val;
  145. $tmp = parse_url($val);
  146. $return[1][$key] = $tmp['host'];
  147. if($tmp['port']){
  148. $return[1][$key] .= ":$tmp[port]";
  149. }
  150. }
  151. }
  152. return $return;
  153. }
  154. public static function updatemoderate($idtype, $ids, $status = 0) {
  155. $ids = is_array($ids) ? $ids : array($ids);
  156. if(!$ids) {
  157. return;
  158. }
  159. if(!$status) {
  160. foreach($ids as $id) {
  161. C::t('common_moderate')->insert($idtype, array(
  162. 'id' => $id,
  163. 'status' => 0,
  164. 'dateline' => TIMESTAMP,
  165. ), false, true);
  166. }
  167. } elseif($status == 1) {
  168. C::t('common_moderate')->update($ids, $idtype, array('status' => 1));
  169. } elseif($status == 2) {
  170. C::t('common_moderate')->delete($ids, $idtype);
  171. }
  172. }
  173. }
  174. ?>