XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
postcommon_register_insert_js_check.php
Go to the documentation of this file.
1 <?php
2 
4 
5  function execute()
6  {
7  ob_start( array( $this , 'ob_filter' ) ) ;
8 
9  if( ! empty( $_POST ) ) {
10  if( ! $this->checkValidate() ) {
12  }
13  }
14 
15  return true ;
16  }
17 
18  // insert javascript into the registering form
19  function ob_filter( $s )
20  {
21  $antispam_htmls = $this->getHtml4Assign() ;
22 
23  return preg_replace( '/<form[^>]*action=["\'](|#|register.php)["\'][^>]+>/i' , '$0'."\n".$antispam_htmls['html_in_form']."\n".$antispam_htmls['js_global'] , $s , 1 ) ;
24  }
25 
26 
27  // import from D3forumAntispamDefault.clas.php
28  function getMd5( $time = null )
29  {
30  if( empty( $time ) ) $time = time() ;
31  return md5( gmdate( 'YmdH' , $time ) . XOOPS_DB_PREFIX . XOOPS_DB_NAME ) ;
32  }
33 
34  function getHtml4Assign()
35  {
36  $as_md5 = $this->getMd5() ;
37  $as_md5array = preg_split( '//' , $as_md5 , -1 , PREG_SPLIT_NO_EMPTY ) ;
38  $as_md5shuffle = array() ;
39  foreach( $as_md5array as $key => $val ) {
40  $as_md5shuffle[] = array( 'key' => $key , 'val' => $val ) ;
41  }
42  shuffle( $as_md5shuffle ) ;
43  $js_in_validate_function = "antispam_md5s=new Array(32);\n" ;
44  foreach( $as_md5shuffle as $item ) {
45  $key = $item['key'] ;
46  $val = $item['val'] ;
47  $js_in_validate_function .= "antispam_md5s[$key]='$val';\n" ;
48  }
49  $js_in_validate_function .= "
50  antispam_md5 = '' ;
51  for( i = 0 ; i < 32 ; i ++ ) {
52  antispam_md5 += antispam_md5s[i] ;
53  }
54  xoopsGetElementById('antispam_md5').value = antispam_md5 ;
55  " ;
56 
57  return array(
58  'html_in_form' => '<input type="hidden" name="antispam_md5" id="antispam_md5" value="" />' ,
59  'js_global' => '<script type="text/javascript"><!--//'."\n".$js_in_validate_function."\n".'//--></script><noscript><div class="errorMsg">'._MD_PROTECTOR_TURNJAVASCRIPTON.'</div></noscript>' ,
60  ) ;
61  }
62 
63  function checkValidate()
64  {
65  $user_md5 = trim( @$_POST['antispam_md5'] ) ;
66 
67  // 2-3 hour margin
68  if( $user_md5 != $this->getMd5() && $user_md5 != $this->getMd5( time() - 3600 ) && $user_md5 != $this->getMd5( time() - 7200 ) ) {
69  $this->errors[] = _MD_PROTECTOR_TURNJAVASCRIPTON ;
70  return false ;
71  }
72  return true ;
73  }
74 }
75 
76 ?>