PageRenderTime 57ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/content/mosforme/mosforme.php

https://bitbucket.org/organicdevelopment/joomla-2.5
PHP | 699 lines | 500 code | 136 blank | 63 comment | 136 complexity | 943762f128238ca1785668febbf1eda9 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0, MIT, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * @version 1.0.6
  4. * @package RSform! 1.0.6
  5. * @copyright (C) 2007 www.rsjoomla.com
  6. * @license GPL, http://www.gnu.org/copyleft/gpl.html
  7. */
  8. @session_start();
  9. $mainframe->registerEvent( 'onPrepareContent', 'plgMosForme' );
  10. /**
  11. * Mambot that loads module positions within content
  12. */
  13. function plgMosForme( &$row, &$params, $page=0 ) {
  14. $database =& JFactory::getDBO();
  15. $plugin =& JPluginHelper::getPlugin('content', 'mosforme');
  16. // simple performance check to determine whether bot should process further
  17. if ( strpos( $row->text, 'mosforme' ) === false ) {
  18. return true;
  19. }
  20. // expression to search for
  21. $regex = '/{mosforme\s*.*?}/i';
  22. // find all instances of mambot and put in $matches
  23. preg_match_all( $regex, $row->text, $matches );
  24. // Number of mambots
  25. $count = count( $matches[0] );
  26. // mambot only processes if there are any instances of the mambot in the text
  27. if ( $count ) {
  28. if (file_exists(JPATH_SITE.DS.'components'.DS.'com_forme'.DS.'forme.php'))
  29. processForme( $row, $matches, $count, $regex );
  30. else
  31. JError::raiseWarning(500, 'The mosforme Plugin works only with RSForm! (different product than RSForm! Pro), which you do not have installed. Aborting...');
  32. }
  33. }
  34. function processForme ( &$row, &$matches, $count, $regex ) {
  35. $my = & JFactory::getUser();
  36. $CONFIG = new JConfig();
  37. $database =& JFactory::getDBO();
  38. $func = JRequest::getVar( 'func' );
  39. $did = JRequest::getVar('did','');
  40. for ( $i=0; $i < $count; $i++ ) {
  41. $load = str_replace( 'mosforme', '', $matches[0][$i] );
  42. $load = str_replace( '{', '', $load );
  43. $load = str_replace( '}', '', $load );
  44. $load = trim( $load );
  45. switch ($func) {
  46. case 'thankyou':
  47. //thankyou($option, $did);
  48. $row->text = thankyou('com_forme', $did);//str_replace($matches[0][$i], thankyou('com_forme', $did), $row->text);
  49. break;
  50. default:
  51. $row->text = str_replace($matches[0][$i], showForm('com_forme',$load), $row->text);
  52. break;
  53. }
  54. }
  55. // removes tags without matching module positions
  56. $row->text = preg_replace( $regex, '', $row->text );
  57. }
  58. if(!function_exists('showForm')){
  59. //require_once( dirname(__FILE__) .'/../../plugins/system/legacy/functions.php' );
  60. function processForm($fid, $processform){
  61. global $Itemid, $mainframe;
  62. if(!$Itemid) $Itemid = 999999;
  63. $my = & JFactory::getUser();
  64. $CONFIG = new JConfig();
  65. $database =& JFactory::getDBO();
  66. require_once( $mainframe->getPath( 'class','com_forme' ) );
  67. $row = new forme_data($database);
  68. $row->form_id = $fid;
  69. $data_id = 0;
  70. $form = new forme_forms($database);
  71. $form->load($fid);
  72. eval($form->script_process);
  73. if(!empty($processform)){
  74. $errors = false;
  75. $form_data = JRequest::getVar('form',array(),'POST');
  76. if(!empty($form_data)){
  77. foreach($form_data as $key=>$value){
  78. $form_data[$key] = RemoveXSS($form_data[$key]);
  79. }
  80. }
  81. $row->uip = $_SERVER['REMOTE_ADDR'];
  82. $row->date_added = date('Y-m-d H:i:s');
  83. $_SESSION['formmsg'] = array();
  84. //check captcha if any
  85. $database->setQuery("SELECT * FROM #__forme_fields WHERE form_id = '$fid' AND published = 1");
  86. $fields = $database->loadObjectList();
  87. //load input data
  88. foreach($fields as $field){
  89. if(isset($form_data[$field->name])){
  90. $_SESSION['formdata'][$field->name] = $form_data[$field->name];
  91. }else{
  92. $_SESSION['formdata'][$field->name] = array();
  93. }
  94. }
  95. foreach($fields as $i=>$field){
  96. //check captcha
  97. if($field->inputtype == 'captcha'){
  98. //check session
  99. if(isset($_SESSION['CAPTCHA'])){
  100. if(isset($form_data[$field->name])){
  101. if(strtoupper($form_data[$field->name])!=$_SESSION['CAPTCHA']){
  102. $_SESSION['formmsg'][$field->name][] = ($field->validation_message == '') ? _FORME_FRONTEND_REGISTRA_CAPTCHA : $field->validation_message;
  103. }
  104. }
  105. else
  106. $_SESSION['formmsg'][$field->name][] = ($field->validation_message == '') ? _FORME_FRONTEND_REGISTRA_CAPTCHA : $field->validation_message;
  107. }else{
  108. $_SESSION['formmsg'][$field->name][] = ($field->validation_message == '') ? _FORME_FRONTEND_REGISTRA_CAPTCHA : $field->validation_message;
  109. }
  110. }
  111. //check mandatory
  112. if($field->validation_rule == 'mandatory'){
  113. if($field->inputtype!='file upload'){
  114. if(isset($form_data[$field->name])){
  115. if(is_array($form_data[$field->name])){
  116. if(empty($form_data[$field->name])||(count($form_data[$field->name])==1&&$form_data[$field->name][0]=='')) $_SESSION['formmsg'][$field->name][] = ($field->validation_message == '') ? sprintf(_FORME_FRONTEND_REGISTRA_CANNOT_EMPTY,$field->title) : $field->validation_message;
  117. }else{
  118. if($form_data[$field->name]=='') $_SESSION['formmsg'][$field->name][] = ($field->validation_message == '') ? sprintf(_FORME_FRONTEND_REGISTRA_CANNOT_EMPTY,$field->title) : $field->validation_message;
  119. }
  120. }else{
  121. $_SESSION['formmsg'][$field->name][] = $_SESSION['formmsg'][$field->name][] = ($field->validation_message == '') ? sprintf(_FORME_FRONTEND_REGISTRA_CANNOT_EMPTY,$field->title) : $field->validation_message;
  122. }
  123. }else{
  124. $field_exists = false;
  125. foreach($_FILES['form']['name'] as $field_name=>$field_value){
  126. if($field_name==$field->name){
  127. if($_FILES['form']['tmp_name'][$field_name]!='') $field_exists = true;
  128. }
  129. }
  130. if(!$field_exists){
  131. $_SESSION['formmsg'][$field->name][] = ($field->validation_message == '') ? sprintf(_FORME_FRONTEND_REGISTRA_FILE_CANNOT_EMPTY) : $field->validation_message;
  132. }
  133. }
  134. }
  135. //check alphanum
  136. if($field->validation_rule == 'alphanum'){
  137. if(eregi('[^a-zA-Z0-9 ]', $form_data[$field->name] )|| $form_data[$field->name] == ''){
  138. $_SESSION['formmsg'][$field->name][] = ($field->validation_message == '') ? sprintf(_FORME_FRONTEND_REGISTRA_ALPHANUMERIC,$field->title) : $field->validation_message;
  139. }
  140. }
  141. //check alpha
  142. if($field->validation_rule == 'alpha'){
  143. if(eregi('[^a-zA-Z ]', $form_data[$field->name] )|| $form_data[$field->name] == ''){
  144. $_SESSION['formmsg'][$field->name][] = ($field->validation_message == '') ? sprintf(_FORME_FRONTEND_REGISTRA_ALPHA,$field->title) : $field->validation_message;
  145. }
  146. }
  147. //check email
  148. if($field->validation_rule == 'email'){
  149. if(!eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}$", stripslashes(trim($form_data[$field->name]))) || $form_data[$field->name] == ''){
  150. $_SESSION['formmsg'][$field->name][] = ($field->validation_message == '') ? _FORME_FRONTEND_REGISTRA_EMAIL : $field->validation_message;
  151. }
  152. }
  153. //check number
  154. if($field->validation_rule == 'number'){
  155. if(!is_numeric($form_data[$field->name] )|| $form_data[$field->name] == ''){
  156. $_SESSION['formmsg'][$field->name][] = ($field->validation_message == '') ? sprintf(_FORME_FRONTEND_REGISTRA_NUMERIC,$field->title) : $field->validation_message;
  157. }
  158. }
  159. //check file type compatibility
  160. if($field->inputtype== 'file upload'){
  161. foreach($_FILES['form']['name'] as $field_name=>$field_value){
  162. if($field_name == $field->name){
  163. $field_rules = explode(',',$field->default_value);
  164. if( $field_rules[0] != '' || $field->default_value!=''){
  165. $type_match = false;
  166. foreach($field_rules as $rule){
  167. //check for size
  168. $size = explode('/',$rule);
  169. if($size[0]=='size'){
  170. if(!isset($size[1])) $size[1] = 0;
  171. if($size[1]){
  172. if($_FILES['form']['size'][$field->name] > (int)$size[1]*1024){
  173. $_SESSION['formmsg'][$field->name][] = sprintf(_FORME_FRONTEND_REGISTRA_SIZE,$size[1]);
  174. }
  175. }
  176. }
  177. //check for file type
  178. if($rule==$_FILES['form']['type'][$field->name]){
  179. $type_match = true;
  180. }
  181. }
  182. if($_FILES['form']['type'][$field->name]=='') $type_match = true;
  183. if(!$type_match){
  184. $_SESSION['formmsg'][$field->name][] = _FORME_FRONTEND_REGISTRA_NOT_ALLOWED;
  185. }
  186. }
  187. }
  188. }
  189. }
  190. }
  191. if(!empty($_SESSION['formmsg'])){
  192. $mainframe->redirect(str_replace( '&amp;', '&', $_SERVER['REQUEST_URI']));
  193. }
  194. //build params
  195. $params_field = '';
  196. foreach($form_data as $key=>$value){
  197. if(is_array($value)) $value = implode(',',$value);
  198. $params_field .= $key.'='.$value."||\n";
  199. }
  200. //files
  201. foreach($fields as $field){
  202. if($field->inputtype=='file upload'){
  203. $target_file = time().'_'.$_FILES['form']['name'][$field->name];
  204. if(!move_uploaded_file($_FILES['form']['tmp_name'][$field->name],JPATH_SITE.'/components/com_forme/uploads/'.$target_file)){
  205. }else{
  206. @chmod(JPATH_SITE.'/components/com_forme/uploads/'.$target_file,0755);
  207. if(!isset($array_files)) $array_files = array();
  208. $array_files[] = JPATH_SITE.'/components/com_forme/uploads/'.$target_file;
  209. $params_field .= $field->name . '=' . $target_file ."||\n";
  210. }
  211. }
  212. }
  213. // bind it to the table
  214. if (!$row -> bind($form_data)) {
  215. echo "<script> alert('"
  216. .$row -> getError()
  217. ."'); window.history.go(-1); </script>\n";
  218. exit();
  219. }else{
  220. $row->params = $params_field;
  221. }
  222. if($my->id) $row->uid = $my->id;
  223. // store it in the db
  224. if (!$row -> store()) {
  225. echo "<script> alert('"
  226. .$row -> getError()
  227. ."'); window.history.go(-1); </script>\n";
  228. exit();
  229. }else{
  230. //$data_id = mysql_insert_id();
  231. $data_id = $row->id;
  232. if($form->emailto!=''&&$form->email!=''){
  233. $emailto = explode(',',str_replace(' ','',$form->emailto));
  234. $fields = populateGlobal($fields);
  235. $params = prepareParams($data_id);
  236. foreach($fields as $field){
  237. if(!isset($params[$field->name])) $params[$field->name] = '';
  238. $form->email = str_replace('{'.$field->name.'}',$params[$field->name],$form->email);
  239. $form->emailsubject = str_replace('{'.$field->name.'}',$params[$field->name],$form->emailsubject);
  240. $form->emailfrom = str_replace('{'.$field->name.'}',$params[$field->name],$form->emailfrom);
  241. $form->emailfromname = str_replace('{'.$field->name.'}',$params[$field->name],$form->emailfromname);
  242. foreach($emailto as $i=>$to){
  243. $emailto[$i] = str_replace('{'.$field->name.'}',$params[$field->name],$emailto[$i]);
  244. }
  245. }
  246. if($form->emailfrom=='')$form->emailfrom = $CONFIG->mailfrom;
  247. if($form->emailfromname=='')$form->emailfromname = $CONFIG->sitename;
  248. foreach($emailto as $to){
  249. JUtility::sendMail($form->emailfrom,$form->emailfromname,$to,$form->emailsubject,$form->email,$form->emailmode,null,null,$array_files);
  250. }
  251. }
  252. }
  253. //check if there is a thank you message
  254. if(strlen($form->thankyou)!=0){
  255. if(isset($_SESSION['formdata'])){
  256. unset($_SESSION['formdata']);
  257. }
  258. //$mainframe->redirect( str_replace( '&amp;', '&', "index.php?option=com_forme&func=thankyou&did=" . md5( $data_id.$row->date_added )."&Itemid=$Itemid"));
  259. if(stristr($_SERVER['REQUEST_URI'],'?')) $sign = '&';
  260. else $sign = '?';
  261. $mainframe->redirect( $_SERVER['REQUEST_URI'] . $sign . "func=thankyou&did=" . md5( $data_id.$row->date_added ));
  262. }else {
  263. if(isset($_SESSION['formdata'])){
  264. unset($_SESSION['formdata']);
  265. }
  266. //if there is a return url
  267. if($form->return_url!=''){
  268. $params = prepareParams($data_id);
  269. $fields = populateGlobal($fields);
  270. foreach($fields as $field){
  271. if(!isset($params[$field->name])) $params[$field->name] = '';
  272. $form->return_url = str_replace('{'.$field->name.'}',$params[$field->name],$form->return_url);
  273. }
  274. $mainframe->redirect(str_replace( '&amp;', '&', $form->return_url), _FORME_FRONTEND_REGISTRA_SUCCESS." ");
  275. }else{
  276. if(isset($_SESSION['formdata'])){
  277. unset($_SESSION['formdata']);
  278. }
  279. if(stristr($_SERVER['REQUEST_URI'],'?')) $sign = '&';
  280. else $sign = '?';
  281. $mainframe->redirect( $_SERVER['REQUEST_URI'],_FORME_FRONTEND_REGISTRA_SUCCESS);
  282. }
  283. }
  284. }
  285. }
  286. function showForm($option, $fid){
  287. global $mainframe, $limitstart, $processform;
  288. $fid = (int) $fid;
  289. $my = & JFactory::getUser();
  290. $CONFIG = new JConfig();
  291. $database =& JFactory::getDBO();
  292. $elpath = JPATH_SITE.'/components/com_forme';
  293. $processform = JRequest::getVar( 'form', array(), 'POST');
  294. if(!empty($processform)){
  295. foreach($processform as $key=>$value){
  296. $processform[$key] = RemoveXSS($processform[$key]);
  297. }
  298. }
  299. $check = false;
  300. if(isset($_COOKIE['mbfcookie']['lang'])) $check = $_COOKIE['mbfcookie']['lang'];
  301. if(isset($_COOKIE['jfcookie']['lang'])) $check = $_COOKIE['jfcookie']['lang'];
  302. if(isset($_REQUEST['lang'])) $check = JRequest::getWord('lang',false);
  303. if($check){
  304. if(file_exists($elpath.'/languages/'.$check.'.php')){
  305. require_once($elpath.'/languages/'.$check.'.php');
  306. }else{
  307. require_once($elpath.'/languages/en.php');
  308. }
  309. }else{
  310. require_once($elpath.'/languages/en.php');
  311. }
  312. require_once( $mainframe->getPath( 'front_html','com_forme' ) );
  313. if(!$fid){
  314. //get first cid
  315. $database->setQuery("SELECT id FROM #__forme_forms WHERE published = 1 LIMIT 1");
  316. $fid = (int)$database->loadResult();
  317. }
  318. //check language
  319. //first check global joomfish
  320. $check = false;
  321. if(isset($_COOKIE['mbfcookie']['lang'])) $check = $_COOKIE['mbfcookie']['lang'];
  322. if(isset($_COOKIE['jfcookie']['lang'])) $check = $_COOKIE['jfcookie']['lang'];
  323. if(isset($_REQUEST['lang'])) $check = JRequest::getWord('lang',false);
  324. if($check){
  325. $database->setQuery("SELECT name FROM #__forme_forms WHERE id = '$fid'");
  326. $old_name = $database->loadResult();
  327. //check if we find something similar
  328. $database->setQuery("SELECT id FROM #__forme_forms WHERE lang='".$database->getEscaped($check)."' AND name='".$database->getEscaped($old_name)."' ");
  329. $newfid = $database->loadResult();
  330. if($newfid) $fid = $newfid;
  331. }
  332. processForm($fid, $processform);
  333. $query = "SELECT * FROM #__forme_forms WHERE id = '{$fid}' AND published = '1'";
  334. $database->setQuery($query);
  335. $form = $database->loadObject();
  336. //load fields
  337. $query = "SELECT * FROM #__forme_fields WHERE form_id = '{$fid}' AND published = '1' ORDER BY ordering";
  338. $database->setQuery($query);
  339. $fields = $database->loadObjectList();
  340. if(!$form->published) $mainframe->redirect(JRoute::_(JURI :: base(),_NOT_EXIST));
  341. //Output
  342. global $Itemid, $mainframe, $params, $hide_js, $pop, $formeConfig;
  343. $html = '';
  344. if(isset($form->id)){
  345. //mosCommonHTML::loadCalendar();
  346. eval($form->script_display);
  347. //if we have upload file fields, add enctype
  348. $enctype='';
  349. foreach($fields as $field){
  350. if($field->inputtype=='file upload') $enctype = ' enctype="multipart/form-data"';
  351. }
  352. //load calendar if calendar field exists
  353. $calexists = false;
  354. foreach($fields as $field){
  355. if($field->inputtype=='calendar') $calexists = true;
  356. }
  357. //parse field template
  358. $formfields = '';
  359. foreach($fields as $field){
  360. if($form->fieldstyle=='') $form->fieldstyle = _FORME_BACKEND_EDITFORMS_FIELDSTYLE_DEFAULT;
  361. if($field->fieldstyle=='') $field->fieldstyle = $form->fieldstyle;
  362. $formfields .= forme_HTML::parseFields($field);
  363. }
  364. if($calexists){
  365. $check = false;
  366. if(isset($_COOKIE['mbfcookie']['lang'])) $check = $_COOKIE['mbfcookie']['lang'];
  367. if(isset($_COOKIE['jfcookie']['lang'])) $check = $_COOKIE['jfcookie']['lang'];
  368. if(isset($_REQUEST['lang'])) $check = JRequest::getWord('lang',false);
  369. if($check){
  370. if(file_exists(JPATH_SITE.'/components/com_forme/calendar/initcal-'.$check.'.php'))
  371. require_once(JPATH_SITE.'/components/com_forme/calendar/initcal-'.$check.'.php');
  372. else require_once(JPATH_SITE.'/components/com_forme/calendar/initcal.php');
  373. }
  374. else require_once(JPATH_SITE.'/components/com_forme/calendar/initcal.php');
  375. $html .='
  376. <script language="javascript">
  377. function init() {';
  378. foreach($fields as $field){
  379. if($field->inputtype=='calendar'){
  380. $html.='
  381. function handleSelect'.$field->name.'(type,args,obj) {
  382. var dates = args[0];
  383. var date = dates[0];
  384. var year = date[0], month = date[1], day = date[2];
  385. var txtDate = document.getElementById("txt'.$field->name.'");
  386. txtDate.value = month + "/" + day + "/" + year;
  387. }
  388. YAHOO.example.calendar.'.$field->name.' = new YAHOO.widget.Calendar("'.$field->name.'","'.$field->name.'Container");
  389. YAHOO.example.calendar.'.$field->name.'.selectEvent.subscribe(handleSelect'.$field->name.', YAHOO.example.calendar.'.$field->name.', true);
  390. var txt'.$field->name.' = document.getElementById("txt'.$field->name.'");
  391. if (txt'.$field->name.'.value != "") {
  392. YAHOO.example.calendar.'.$field->name.'.select(txt'.$field->name.'.value);
  393. }
  394. YAHOO.example.calendar.'.$field->name.'.render();';
  395. }
  396. }
  397. $html .='
  398. }
  399. YAHOO.util.Event.addListener(window, "load", init);
  400. </script>';
  401. }
  402. $action = '';
  403. //parse form template
  404. if($form->formstyle == '') $form->formstyle = _FORME_BACKEND_EDITFORMS_STYLE_DEFAULT;
  405. $form->formstyle = str_replace('{formtitle}',$form->title,$form->formstyle);
  406. $form->formstyle = str_replace('{formname}',$form->name,$form->formstyle);
  407. $form->formstyle = str_replace('{enctype}',$enctype,$form->formstyle);
  408. $form->formstyle = str_replace('{action}',$action,$form->formstyle);
  409. $form->formstyle = str_replace('{formfields}',$formfields,$form->formstyle);
  410. $html .= $form->formstyle;
  411. }
  412. return $html;
  413. }
  414. function populateGlobal($fields){
  415. $fields[]->name = 'jos_sitename';
  416. $fields[]->name = 'jos_siteurl';
  417. $fields[]->name = 'jos_userip';
  418. $fields[]->name = 'jos_user_id';
  419. $fields[]->name = 'jos_username';
  420. $fields[]->name = 'jos_email';
  421. return $fields;
  422. }
  423. function prepareParams($did){
  424. $my = & JFactory::getUser();
  425. $CONFIG = new JConfig();
  426. $database =& JFactory::getDBO();
  427. $database->setQuery("SELECT * FROM #__forme_data WHERE id = '".$database->getEscaped($did)."'");
  428. $data_row = $database->loadObject();
  429. $params = $data_row->params;
  430. $database->setQuery("SELECT * FROM #__users WHERE id = '$data_row->uid'");
  431. $user = $database->loadObject();
  432. $result['jos_sitename'] = $CONFIG->sitename;
  433. $result['jos_siteurl'] = JURI :: base();
  434. $result['jos_userip'] = $data_row->uip;
  435. $result['jos_user_id'] = $data_row->uid;
  436. $result['jos_username'] = (isset($user->username)) ? $user->username : 0;
  437. $result['jos_email'] = (isset($user->email)) ? $user->email : 0;
  438. $result_explode = explode("||\n",$params);
  439. foreach($result_explode as $param_row){
  440. $param_row = explode('=',$param_row,2);
  441. if(isset($param_row[1])){
  442. $result[$param_row[0]] = $param_row[1];
  443. }else{
  444. $result[$param_row[0]] = '';
  445. }
  446. }
  447. return $result;
  448. }
  449. function RemoveXSS($val) {
  450. // remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed
  451. // this prevents some character re-spacing such as <java\0script>
  452. // note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs
  453. $val = preg_replace('/([\x00-\x08][\x0b-\x0c][\x0e-\x20])/', '', $val);
  454. // straight replacements, the user should never need these since they're normal characters
  455. // this prevents like <IMG SRC=&#X40&#X61&#X76&#X61&#X73&#X63&#X72&#X69&#X70&#X74&#X3A&#X61&#X6C&#X65&#X72&#X74&#X28&#X27&#X58&#X53&#X53&#X27&#X29>
  456. $search = 'abcdefghijklmnopqrstuvwxyz';
  457. $search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  458. $search .= '1234567890!@#$%^&*()';
  459. $search .= '~`";:?+/={}[]-_|\'\\';
  460. for ($i = 0; $i < strlen($search); $i++) {
  461. // ;? matches the ;, which is optional
  462. // 0{0,7} matches any padded zeros, which are optional and go up to 8 chars
  463. // &#x0040 @ search for the hex values
  464. $val = preg_replace('/(&#[x|X]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ;
  465. // &#00064 @ 0{0,7} matches '0' zero to seven times
  466. $val = preg_replace('/(&#0{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ;
  467. }
  468. // now the only remaining whitespace attacks are \t, \n, and \r
  469. $ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base');
  470. $ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');
  471. $ra = array_merge($ra1, $ra2);
  472. $found = true; // keep replacing as long as the previous round replaced something
  473. while ($found == true) {
  474. $val_before = $val;
  475. for ($i = 0; $i < sizeof($ra); $i++) {
  476. $pattern = '/';
  477. for ($j = 0; $j < strlen($ra[$i]); $j++) {
  478. if ($j > 0) {
  479. $pattern .= '(';
  480. $pattern .= '(&#[x|X]0{0,8}([9][a][b]);?)?';
  481. $pattern .= '|(&#0{0,8}([9][10][13]);?)?';
  482. $pattern .= ')?';
  483. }
  484. $pattern .= $ra[$i][$j];
  485. }
  486. $pattern .= '/i';
  487. $replacement = substr($ra[$i], 0, 2).'<x>'.substr($ra[$i], 2); // add in <> to nerf the tag
  488. $val = preg_replace($pattern, $replacement, $val); // filter out the hex tags
  489. if ($val_before == $val) {
  490. // no replacements were made, so exit the loop
  491. $found = false;
  492. }
  493. }
  494. }
  495. return $val;
  496. }
  497. function thankyou($option, $did){
  498. global $mainframe, $limitstart, $Itemid;
  499. $result = '';
  500. $elpath = JPATH_SITE.'/components/com_forme';
  501. $check = false;
  502. if(isset($_COOKIE['mbfcookie']['lang'])) $check = $_COOKIE['mbfcookie']['lang'];
  503. if(isset($_COOKIE['jfcookie']['lang'])) $check = $_COOKIE['jfcookie']['lang'];
  504. if(isset($_REQUEST['lang'])) $check = JRequest::getWord('lang',false);
  505. if($check){
  506. require_once($elpath.'/languages/'.$check.'.php');
  507. }else{
  508. require_once($elpath.'/languages/en.php');
  509. }
  510. require_once( $mainframe->getPath( 'front_html','com_forme' ) );
  511. $my = & JFactory::getUser();
  512. $CONFIG = new JConfig();
  513. $database =& JFactory::getDBO();
  514. //get the submission & form id
  515. $database->setQuery("SELECT * FROM #__forme_data WHERE MD5(CONCAT(id,date_added)) = '".$database->getEscaped($did)."'");
  516. $formdata = $database->loadOBject();
  517. if(isset($formdata->form_id)){
  518. //get form_id
  519. //$database->setQuery("SELECT * FROM #__forme_data WHERE id = '$did'");
  520. //$formdata = $database->loadObject();
  521. //check if form has a thank you message
  522. $database->setQuery("SELECT * FROM #__forme_forms WHERE id = '$formdata->form_id'");
  523. $form = $database->loadObject();
  524. $params = prepareParams($formdata->id);
  525. //load fields
  526. $database->setQuery("SELECT * FROM #__forme_fields WHERE form_id = '$formdata->form_id' AND published = 1");
  527. $fields = $database->loadObjectList();
  528. $fields = populateGlobal($fields);
  529. foreach($fields as $field){
  530. if(!isset($params[$field->name])) $params[$field->name] = '';
  531. $form->thankyou = str_replace('{'.$field->name.'}',$params[$field->name],$form->thankyou);
  532. $form->return_url = str_replace('{'.$field->name.'}',$params[$field->name],$form->return_url);
  533. }
  534. if(stristr($_SERVER['REQUEST_URI'],'?')) $sign = '&';
  535. else $sign = '?';
  536. if($form->thankyou!='') {
  537. $return_url = ($form->return_url == '') ? $_SERVER['HTTP_REFERER'] : $form->return_url;
  538. $result .= '<div class="thankyou">'.stripslashes($form->thankyou).'</div>';//
  539. $result .= '<input type="button" name="ok" value="'._FORME_FRONTEND_THANKYOU_BUTTON.'" onclick="window.location=\''.$return_url.'\';"/>';
  540. return $result;
  541. }else{
  542. //if there is a return url
  543. if($form->return_url!=''){
  544. $mainframe->redirect($form->return_url, _FORME_FRONTEND_REGISTRA_SUCCESS." ");
  545. }else{
  546. $mainframe->redirect(JRoute::_("index.php?option=com_forme&Itemid=$Itemid", false), _FORME_FRONTEND_REGISTRA_SUCCESS." ");
  547. }
  548. }
  549. }else{
  550. $mainframe->redirect(JRoute::_("index.php?option=com_forme&Itemid=$Itemid", false), _FORME_FRONTEND_REGISTRA_SUCCESS." ");
  551. }
  552. }
  553. }
  554. ?>