Advertisement
Guest User

Untitled

a guest
Feb 11th, 2017
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.52 KB | None | 0 0
  1. class simpleForm2Element extends JObject{public $name = null;public $code = null;public $id = null;public $label = '';public $value = null;public $values = array();public $regex = null;public $error = null;public $type = null;public $requests = array();public $options = array();public $required = false;public $multiple = false;public $selected = false;public $plugin = null;public $captcha = null;public $class = ' ';public function simpleForm2Element($name='',$id=''){if($name!='') $this->name = $name;if($id!='') $this->id = $id;}public function check(&$form,$request){$checkVal = $this->getParam($request,$this->name,null);if(in_array($this->type,array('text','textarea'))){$checkVal = trim($checkVal);if(($this->required&&$checkVal=='')||($this->regex!=''&&!preg_match($this->regex,$checkVal))){$this->setError($this->error);return false;}$this->requests[] = $checkVal;}else if(in_array($this->type,array('select','radio','checkbox'))){if(is_array($checkVal)){$has = array_intersect($checkVal,$this->values);if($this->required&&count($has)==0||(count($checkVal)>0&&count($has)==0)){$this->setError($this->error);return false;}$this->requests = $checkVal;}else if(is_null($checkVal)){$this->requests[] = '';if($this->required){$this->setError($this->error);return false;}}else{$checkVal = trim($checkVal);if(($this->required&&$checkVal=='')||(count($this->values)>0&&!in_array($checkVal,$this->values))){$this->setError($this->error);return false;}$this->requests[] = $checkVal;}}else if(in_array($this->type,array('button','submit','reset'))){return true;}else if($this->type=='captcha'){$user = JFactory::getUser();if((int)$user->get('id')>0) return true;if(!is_null($this->captcha)){if(!$this->captcha->checkAnswer(null)){$this->setError($this->error);return false;}}else{$session = JFactory::getSession();$session->set('simpleform2_'.$form->get('moduleID').'.captcha', null);$checkVal = trim($checkVal);if($checkVal==''||!in_array($checkVal,$this->values)){$this->setError($this->error);return false;}}}else if($this->type=='file'){$fileData = $_FILES[$this->name];if($this->required&&!is_file($fileData['tmp_name'])){$this->setError($this->error);return false;}else if(!is_file($fileData['tmp_name'])) return true;if($this->maxsize>0&&$fileData['size']>$this->maxsize){$fSize = round($fileData['size']/1024,2);$error = sprintf(JText::_('File size is too big'),$fileData['name'].' ('.$fSize.'Kb)',round($this->maxsize/1024,2).'Kb');$this->setError($error);return false;}if(count($this->extensions)>0){$match = false;foreach($this->extensions as $ext){if(preg_match("/\.".$ext."$/",$fileData['name'])){$match = true;break;}}if(!$match){$this->setError(sprintf(JText::_('File extension is forbidden'),$fileData['name'],implode(', ',$this->extensions)));return false;}}$file = new stdclass;$file->file = $fileData['tmp_name'];$file->name = $fileData['name'];$form->attachments[] = $file;}return true;}function render($sf2){$result = $this->code;$result = preg_replace("/{\/?element(.*?)(?=})}/i",'',$result);$name = $this->name;$id = $this->id;$class = @$this->class;$default = @$this->value;$placeholder = @$this->placeholder;$label = '';if($this->label!='') $label = '<label for="'.$this->id.'">'.$this->label.($this->required?' <span>*</span>':'').'</label> ';switch($this->type){case 'text':$onchange = @$this->onchange;if(count($this->requests)) $default = $this->requests[0];$attribs = array();$attribs[] = 'name="'.$name.'"';$attribs[] = 'id="'.$id.'"';if($class) $attribs[] = 'class="'.$class.'"';if($onchange) $attribs[] = 'onchange="'.$onchange.'"';if($placeholder) $attribs[] = 'placeholder="'.$placeholder.'"';$result.= '<input type="text" '.implode(' ',$attribs).' value="'.htmlspecialchars($default).'" />';break;case 'textarea':$onchange = @$this->onchange;if(count($this->requests)) $default = $this->requests[0];$attribs = array();$attribs[] = 'name="'.$name.'"';$attribs[] = 'id="'.$id.'"';if($class) $attribs[] = 'class="'.$class.'"';if($onchange) $attribs[] = 'onchange="'.$onchange.'"';if($placeholder) $attribs[] = 'placeholder="'.$placeholder.'"';$result.= '<textarea '.implode(' ',$attribs).' >'.htmlspecialchars($default).'</textarea>';break;case 'select':$multi = @$this->multiple;$onchange = @$this->onchange;$result = '<select'.($multi?' multiple="multiple"':'').' name="'.$name.($multi?'[]':'').'" id="'.$id.'"'.($class?' class="'.$class.'"':'').($onchange?' onchange="'.$onchange.'"':'').'>'.$result;foreach($this->options as $option){$sel = '';if($option->selected || (count($this->requests)&&in_array($option->value,$this->requests))) $sel = ' selected="selected"';$optionCode = '<option value="'.$option->value.'"'.$sel.'>'.$option->label.'</option>';$result = str_replace($option->code,$optionCode,$result);}$result.= '</select>';break;case 'radio':foreach($this->options as $option){$id = md5($name.'_'.$option->label);$onclick = @$option->onclick;$sel = '';if($option->selected || (count($this->requests)&&in_array($option->value,$this->requests))) $sel = ' checked="checked"';$optionCode = '<input type="radio" name="'.$name.'" id="'.$id.'" value="'.$option->value.'"'.($class?' class="'.$class.'"':'').($onclick?' onclick="'.$onclick.'"':'').$sel.' /><label for="'.$id.'">'.$option->label.'</label>';$result = str_replace($option->code,$optionCode,$result);}break;case 'button':$default = @$this->value;$onclick = @$this->onclick;$result.= '<input type="button"'.($class?' class="'.$class.'"':'').($onclick?' onclick="'.$onclick.'"':'').' value="'.$default.'" />';break;case 'submit':$default = @$this->value;$result.= '<input'.($class?' class="'.$class.'"':'').' type="submit" value="'.$default.'" />';break;case 'reset':$default = @$this->value;$onclick = @$this->onclick;$result.= '<input type="reset"'.($name?' name="'.$name.'"':'').($class?' class="'.$class.'"':'').($onclick?' onclick="'.$onclick.'"':'').' value="'.$default.'" />';break;case 'checkbox':$default = @$this->value;$single = false;if(count($this->options)==0){$this->options = array($this);$single = true;}foreach($this->options as $option){$elid = $id;if(!$single){$elid = md5($name.'_'.$option->label);$default = @$option->value;}$onclick = @$option->onclick;$sel = '';if($option->selected || (count($this->requests)&&in_array($option->value,$this->requests))) $sel = ' checked="checked"';$optionCode = '<input type="checkbox" name="'.$name.(!$single?'[]':'').'" id="'.$elid.'"'.($class?' class="'.$class.'"':'').($onclick?' onclick="'.$onclick.'"':'').$sel.' value="'.$default.'" />';if($single) $result.= $optionCode;else{$optionCode.= ' <label for="'.$elid.'">'.$option->label.'</label>';$result = str_replace($option->code,$optionCode,$result);}}break;case 'captcha':$user = JFactory::getUser();if((int)$user->get('id')>0){$result = '';$label = '';}else if(!is_null($this->captcha)){$result = $this->captcha->display($this->name, $this->id, $this->class);}else{$default = @$this->value;$urlAdd = array();$urlAdd[] = 'moduleID='.$sf2->moduleID;$urlAdd[] = 'rand='.rand(1,99999);$onclick = 'this.src=\''.JURI::root().'modules/mod_simpleform2/index.php?task=captcha'.(count($urlAdd)?'&'.implode('&',$urlAdd):'').'&rand=\'+Math.random();';$attribs = array();$attribs[] = 'name="'.$name.'"';$attribs[] = 'id="'.$id.'"';if($class) $attribs[] = 'class="'.$class.'"';if($placeholder) $attribs[] = 'placeholder="'.$placeholder.'"';$result.= '<img class="sf2Captcha" src="'.JURI::root().'modules/mod_simpleform2/index.php?task=captcha'.(count($urlAdd)?'&'.implode('&',$urlAdd):'').'" alt="'.JText::_('Click to refresh').'" title="'.JText::_('Click to refresh').'" onclick="'.$onclick.'"'.' style="cursor:pointer;" /><div><input type="text" '.implode(' ',$attribs).' value="'.$default.'" /></div>';}break;case 'file':$onchange = @$this->onchange;$attribs = array();$attribs[] = 'name="'.$name.'"';$attribs[] = 'id="'.$id.'"';if($class) $attribs[] = 'class="'.$class.'"';if($onchange) $attribs[] = 'onchange="'.$onchange.'"';if($placeholder) $attribs[] = 'placeholder="'.$placeholder.'"';$result.= '<input type="file" '.implode(' ',$attribs).' />';break;}if($label!='') $result = $label.$result;return $result;}function getParam( &$arr, $name, $def=null, $mask=0 ){static $noHtmlFilter= null;static $safeHtmlFilter= null;$var = JArrayHelper::getValue( $arr, $name, $def, '' );if (!($mask & 1) && is_string($var)) {$var = trim($var);}if ($mask & 2) {if (is_null($safeHtmlFilter)) {$safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1);}$var = $safeHtmlFilter->clean($var, 'none');} elseif ($mask & 4) {$var = $var;} else {if (is_null($noHtmlFilter)) {$noHtmlFilter = JFilterInput::getInstance(/* $tags, $attr, $tag_method, $attr_method, $xss_auto */);}$var = $noHtmlFilter->clean($var, 'none');}return $var;}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement