Advertisement
Guest User

Untitled

a guest
Feb 11th, 2017
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.92 KB | None | 0 0
  1. require_once(__DIR__.'/helper.php');require_once(__DIR__.'/simpleform2.element.php');class simpleForm2 extends JObject{var $code = '';var $elements = array();var $attachments = array();var $id = null;var $_key = '';var $hasCaptcha = false;var $hasSubmit = false;var $side = 'backend';var $moduleID = null;var $template = 'default';var $defaultError = '%s';function simpleForm2($simpleCode=''){if($simpleCode!='') return $this->parse($simpleCode);else return true;}function parse($code){$this->code = $code;$paramNames = array('name','regex','label','error','selected','onclick','onchange','value','type','class','required','multiple','width','height','extensions','maxsize','color','background','placeholder','plugin');$optionParamNames = array('label','value','selected','onclick','onchange');$params2mask = array('regex','label','error','onclick','onchange','value','placeholder');foreach($params2mask as $param2mask){$this->code = preg_replace_callback("/({[^}]+)(".$param2mask.")\=[\'\"](.*?)(?=[\'\"] )[\'\"]/si",create_function('$matches','return $matches[1].$matches[2].\'="\'.base64_encode($matches[3]).\'"\';'),$this->code);}preg_match_all("/{element (.*?)(?=[\/ \'\"]})(?:[ \'\"]}(.*?)(?={\/element}))?/is",$this->code,$matches);if(!is_array($matches[1])||count($matches[1])==0){$this->setError(JText::_('No elements found in code'));return false;}foreach($matches[1] as $key=>$paramsText){$elem = new simpleForm2Element();$elem->code = $matches[0][$key];preg_match_all("/(".implode('|',$paramNames).")=[\'\"]([^\'\"]+)/is",$paramsText,$matchesP);if(!is_array($matchesP[1])||count($matchesP[1])==0){$this->setError(JText::_('Element without parameters found'));return false;}foreach($matchesP[1] as $keyP=>$paramName){if(in_array($paramName,$paramNames)){$elem->$paramName = $matchesP[2][$keyP];if(in_array($paramName,$params2mask)) $elem->$paramName = base64_decode($elem->$paramName);}}if(is_null($elem->name)||$elem->name==''){if(!is_null($elem->label) && $elem->label!=''){$elem->name = $this->toTranslit($elem->label);}else{$elem->name = md5(serialize($paramsText)).$key;}}$elem->id = 'sf2_'.$this->get('moduleID').'_'.$this->toTranslit($elem->name);$elem->required = (bool)($elem->required=='required');$elem->multiple = (bool)($elem->multiple=='multiple');if(isset($elem->value)) $elem->values[] = $elem->value;preg_match_all("/{option (.*?)(?=})/is",$matches[2][$key],$matchesO);if(is_array($matchesO[1])&&count($matchesO[1])>0){$paramsText = null;foreach($matchesO[1] as $keyO=>$paramsText){preg_match_all("/(".implode('|',$optionParamNames).")=[\'\"]([^\'\"]+)/is",$paramsText,$matchesOP);if(is_array($matchesOP[1])&&count($matchesOP[1])>0){$option = new stdclass;foreach($matchesOP[1] as $keyP=>$paramName){if(in_array($paramName,$optionParamNames)){$option->$paramName = $matchesOP[2][$keyP];if(in_array($paramName,$params2mask)) $option->$paramName = base64_decode($option->$paramName);$option->selected = (bool)(@$option->selected=='selected');}}$option->code = $matchesO[0][$keyO].'}';$elem->values[] = $option->value;$elem->options[] = $option;}}$elem->code.= '{/element}';}else $elem->code.= '/}';if($elem->type=='captcha'){if($this->hasCaptcha){continue;}if(isset($elem->plugin) && $elem->plugin!=''){if(($elem->captcha = JCaptcha::getInstance($elem->plugin, array('namespace' => 'simpleform2_'.$this->get('moduleID').'.captcha'))) == null){$this->setError(sprintf(JText::_('No captcha plugin "%s" found.'),$elem->plugin));return false;}}else{if(!isset($elem->color)||!preg_match("/\#?[0-9ABCDEFabcdef]{6}/",$elem->color)) $elem->color = '';if(!isset($elem->background)||!preg_match("/\#?[0-9ABCDEFabcdef]{6}/",$elem->background)) $elem->background = '';$session = JFactory::getSession();$elem->values[] = $session->get('simpleform2_'.$this->get('moduleID').'.captcha', null);}$elem->required = true;$this->hasCaptcha = true;}else if($elem->type=='submit'){if($this->hasSubmit) $elem = null;$this->hasSubmit = true;}else if($elem->type=='file'){$exts = array();if(@$elem->extensions!=''){$tmpExts = explode(',',$elem->extensions);if(is_array($tmpExts)&&count($tmpExts)>0){foreach($tmpExts as $tmpExt){$tmpExt = trim($tmpExt);if(preg_match('/^[a-zA-Z0-9]{2,4}$/',$tmpExt)) $exts[] = $tmpExt;}}}$elem->extensions = $exts;$maxSize = 0;if(@$elem->maxsize!=''){$measure = strtolower(substr($elem->maxsize,-2));$size = (int)substr($elem->maxsize,0,-2);if($size>0&&($measure=='kb'||$measure=='mb')){if($measure=='mb') $maxSize = $size*1024*1024;else $maxSize = $size*1024;}}$elem->maxsize = $maxSize;}if($elem){if(is_null($elem->error)){$elem->error = sprintf(JText::_('ENTER VALUE FOR'),$elem->label);}$this->elements[] = $elem;}}return true;}function render(){if(count($this->elements)==0) return false;$id = $this->id;$code = $this->code;$form = '';$uri = JURI::getInstance();$lang = JFactory::getLanguage();$formBegin = '<form method="post" id="'.$id.'" name="'.$id.'" enctype="multipart/form-data" class="simpleForm">';$formBegin.= '<input type="hidden" name="moduleID" value="'.$this->moduleID.'" />';$formBegin.= '<input type="hidden" name="task" value="sendForm" />';$formBegin.= '<input type="hidden" name="Itemid" value="'.JRequest::getInt( 'Itemid').'" />';$formBegin.= '<input type="hidden" name="url" value="'.$uri->toString().'" />';$formBegin.= '<input type="hidden" name="language" value="'.$lang->getTag().'" />';$formEnd = '</form>'."\n";foreach($this->elements as $elem){$code = preg_replace('`'.preg_quote($elem->code,'`').'`', $elem->render($this), $code, 1);}if(!preg_match('/\{form\}/i',$code)) $code = '{form}'.$code;if(!preg_match('/\{\/form\}/i',$code)) $code.= '{/form}';$code = str_replace(array('{form}','{/form}'),array($formBegin,$formEnd),$code);$code.= ($this->checkDomain()?'':base64_decode('PGRpdiBzdHlsZT0iYm9yZGVyLXRvcDoxcHggc29saWQgI2NjYzt0ZXh0LWFsaWduOnJpZ2h0OyI+PGEgdGFyZ2V0PSJfYmxhbmsiIHRpdGxlPSJzaW1wbGVGb3JtMiIgaHJlZj0iaHR0cDovL3d3dy5hbGxmb3Jqb29tbGEucnUiIHN0eWxlPSJ2aXNpYmlsaXR5OnZpc2libGU7ZGlzcGxheTppbmxpbmU7Y29sb3I6I2NjYzsiPnNpbXBsZUZvcm0yPC9hPjwvZGl2Pg=='));echo $code;}function processRequest($request){if(count($this->elements)==0){$this->setError(JText::_('No elements found in code'));return false;}$result = '';foreach($this->elements as $elem){if($elem->check($this,$request)!==true){$error = $elem->getError();$this->setError(($error?$error:sprintf($this->defaultError,$elem->label)));return false;}if(count($elem->requests)) $result.= $this->getTemplate('mail_form_item',array('label'=>$elem->label,'value'=>implode(', ',$elem->requests)));}return $result;}function getUserIp() { if (getenv('REMOTE_ADDR')) $ip = getenv('REMOTE_ADDR'); elseif(getenv('HTTP_X_FORWARDED_FOR')) $ip = getenv('HTTP_X_FORWARDED_FOR'); else $ip = getenv('HTTP_CLIENT_IP');return $ip;}function getTemplate($tmpl,$vars){global $mainframe;jimport('joomla.application.module.helper');$path = JModuleHelper::getLayoutPath('mod_simpleform2', $tmpl);unset($tmpl);unset($tPath);unset($bPath);extract($vars);ob_start();include($path);$content = ob_get_clean();return $content;}function getElementByName($name){$name = trim($name);if($name=='') return false;foreach($this->elements as $elem){if($elem->name==$name){return $elem;}}return false;}function sendEmail($result,$params){$mailFrom = trim($params->get('sfMailReply',''));preg_match('~^\{([a-z0-9_\-]+)\}$~',$mailFrom,$matches);if(is_array($matches)&&isset($matches[1])&&$matches[1]!=''){$elem = $this->getElementByName($matches[1]);if($elem===false){$this->setError(sprintf(JText::_('Sender element not found'),'{'.$matches[1].'}'));return false;}$mailFrom = @$elem->requests[0];}$mailTo = $params->get('sfMailTo',null);$subject = $params->get('sfMailSubj','--== SimpleForm2 e-mail ==--');$subject = html_entity_decode($subject, ENT_QUOTES);$now = JFactory::getDate();$url = JURI::root();$url = str_replace('modules/mod_simpleform2/','',$url);$url = JRequest::getVar('url',$url);$date = $now->format('d.m.Y H:i:s');$ip = $this->getUserIp();$body = $this->getTemplate('mail_form',array('url'=>$url,'date'=>$date,'ip'=>$ip,'rows'=>$result));$body = stripslashes(html_entity_decode($body, ENT_QUOTES));if(!$mailTo){$this->setError(JText::_('Form not configured'));return false;}$cfg = JFactory::getConfig();$mail = JFactory::getMailer();$mail->setSender(array($cfg->get('mailfrom'), $cfg->get('fromname')));if($mailFrom!=''){$mail->ClearReplyTos();$mail->AddReplyTo(array($mailFrom,$mailFrom));}$mail->setSubject($subject);$mail->setBody($body);if(preg_match('~<~',$body)&&preg_match('/>/',$body)) $mail->IsHTML(true);$recieps = array();$tmpR = explode(',',$mailTo);foreach($tmpR as $tmpRr){$tmpRr = trim($tmpRr);preg_match('~^\{([a-z0-9_\-]+)\}$~',$tmpRr,$matches);if(is_array($matches)&&isset($matches[1])&&$matches[1]!=''){$elem = $this->getElementByName($matches[1]);if($elem===false){$this->setError(sprintf(JText::_('Recipient element not found'),'{'.$matches[1].'}'));return false;}$recieps = array_merge($recieps,$elem->requests);}else if($tmpRr!='') $recieps[] = $tmpRr;}if(count($recieps)<1){$this->setError(JText::_('Form not configured'));return false;}foreach($recieps as $reciep){$mail->addRecipient($reciep);}$mail->addCC(null);$mail->addBCC(null);foreach($this->attachments as $attachment){$mail->AddStringAttachment(file_get_contents($attachment->file),$attachment->name);}ob_start();$ok = $mail->Send();ob_end_clean();if(is_object($ok) && $ok instanceof JException){$this->setError((string)$ok);return false;}else if(is_object($ok)){$this->setError($ok->getError());return false;}else return true;}function checkDomain(){if(!function_exists('bcpowmod')) return true;$URI=JURI::getInstance();$keys=explode('|',$this->_key);foreach($keys as $key){$m=str_replace('www.','',$URI->getHost()).':ZyX_SF2';$e=5;$n='159378341817953177';$s=5;$coded='';$max=strlen($m);$packets=ceil($max/$s);for($i=0;$i<$packets;$i++){$packet=substr($m, $i*$s, $s);$code='0';for($j=0; $j<$s; $j++){$code=@bcadd($code, bcmul(ord($packet[$j]), bcpow('256',$j)));}$code=bcpowmod($code, $e, $n);$coded.=$code.' ';}$coded=str_replace(' ','-',trim($coded));if($key==$coded)return true;}return false;}function toTranslit($var){return \simpleForm2\helper::transliterate($var);}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement