File manager - Edit - /home/capoccitel/www/wp-admin/helpers.tar
Back
validation.php 0000705 00000022565 15242100671 0007415 0 ustar 00 <?php /** * @package RSForm! Pro * @copyright (C) 2007-2014 www.rsjoomla.com * @license GPL, http://www.gnu.org/copyleft/gpl.html */ // no direct access defined( '_JEXEC' ) or die( 'Restricted access' ); class RSFormProValidations { public static function none($value,$extra=null,$data=null) { return true; } public static function alpha($param,$extra=null,$data=null) { if(strpos($param,"\n") !== false) $param = str_replace(array("\r","\n"),'',$param); for($i=0;$i<strlen($param);$i++) if(strpos($extra,$param[$i]) === false && preg_match('#([^a-zA-Z ])#', $param[$i])) return false; return true; } public static function numeric($param,$extra=null,$data=null) { if(strpos($param,"\n") !== false) $param = str_replace(array("\r","\n"),'',$param); for($i=0;$i<strlen($param);$i++) if (strpos($extra,$param[$i]) === false && !is_numeric($param[$i])) return false; return true; } public static function alphanumeric($param,$extra = null,$data=null) { if(strpos($param,"\n") !== false) $param = str_replace(array("\r","\n"),'',$param); for($i=0;$i<strlen($param);$i++) if(strpos($extra,$param[$i]) === false && preg_match('#([^a-zA-Z0-9 ])#', $param[$i])) return false; return true; } public static function alphaaccented($value, $extra=null, $data=null) { if (preg_match('#[^[:alpha:] ]#u', $value)) { return false; } return true; } public static function alphanumericaccented($value, $extra=null, $data=null) { if (preg_match('#[^[:alpha:]0-9 ]#u', $value)) { return false; } return true; } public static function email($email,$extra=null,$data=null) { jimport('joomla.mail.helper'); return JMailHelper::isEmailAddress($email); } public static function emaildns($email,$extra=null,$data=null) { // Check if it's an email address format if (!self::email($email,$extra,$data)) return false; list($user, $domain) = explode('@', $email, 2); // checkdnsrr for PHP < 5.3.0 if (!function_exists('checkdnsrr') && function_exists('exec') && is_callable('exec')) { @exec('nslookup -type=MX '.escapeshellcmd($domain), $output); foreach($output as $line) if (preg_match('/^'.preg_quote($domain).'/',$line)) return true; return false; } // fallback method... if (!function_exists('checkdnsrr') || !is_callable('checkdnsrr')) return true; return checkdnsrr($domain, substr(PHP_OS, 0, 3) == 'WIN' ? 'A' : 'MX'); } public static function uniquefield($value, $extra=null, $data=null) { $db = JFactory::getDbo(); $app = JFactory::getApplication(); $form = $app->input->get('form', array(), 'array'); $formId = isset($form['formId']) ? $form['formId'] : 0; $option = $app->input->getCmd('option'); $ctrl = $app->input->getCmd('controller'); $task = $app->input->getCmd('task'); $id = $app->input->getInt('id'); $query = $db->getQuery(true) ->select($db->qn('SubmissionValueId')) ->from($db->qn('#__rsform_submission_values')) ->where($db->qn('FormId').'='.$db->q($formId)) ->where($db->qn('FieldName').'='.$db->q($data['NAME'])) ->where($db->qn('FieldValue').'='.$db->q($value)); // Is this a directory edit? if ($id && $option == 'com_rsform' && $ctrl == 'directory' && ($task == 'save' || $task == 'apply')) { $query->where($db->qn('SubmissionId').' != '.$db->q($id)); } return $db->setQuery($query)->loadResult() ? false : true; } public static function uniquefielduser($value, $extra=null,$data=null) { $db = JFactory::getDbo(); $app = JFactory::getApplication(); $form = $app->input->get('form', array(), 'array'); $formId = isset($form['formId']) ? $form['formId'] : 0; $user = JFactory::getUser(); $userField = $user->guest ? 's.UserIp' : 's.UserId'; $userValue = $user->guest ? $app->input->server->getString('REMOTE_ADDR') : $user->id; $option = $app->input->getCmd('option'); $ctrl = $app->input->getCmd('controller'); $task = $app->input->getCmd('task'); $id = $app->input->getInt('id'); $query = $db->getQuery(true) ->select($db->qn('sv.SubmissionValueId')) ->from($db->qn('#__rsform_submission_values', 'sv')) ->join('left', $db->qn('#__rsform_submissions', 's').' ON ('.$db->qn('sv.SubmissionId').' = '.$db->qn('s.SubmissionId').')') ->where($db->qn('sv.FormId').'='.$db->q($formId)) ->where($db->qn('sv.FieldName').'='.$db->q($data['NAME'])) ->where($db->qn('sv.FieldValue').'='.$db->q($value)); // Is this a directory edit? if ($id && $option == 'com_rsform' && $ctrl == 'directory' && ($task == 'save' || $task == 'apply')) { $query->where($db->qn('s.SubmissionId').' != '.$db->q($id)); // Override the $userValue based on the submission original values $newquery = $db->getQuery(true) ->select($db->qn('UserId')) ->select($db->qn('UserIp')) ->from($db->qn('#__rsform_submissions')) ->where($db->qn('SubmissionId').'='.$db->q($id)); $submission = $db->setQuery($newquery)->loadObject(); if ($submission->UserId) { $userField = 's.UserId'; $userValue = $submission->UserId; } else { $userField = 's.UserIp'; $userValue = $submission->UserIp; } } $query->where($db->qn($userField).'='.$db->q($userValue)); return $db->setQuery($query)->loadResult() ? false : true; } public static function uszipcode($value) { return preg_match("/^([0-9]{5})(-[0-9]{4})?$/i",$value); } public static function phonenumber($value) { return preg_match("/\(?\b[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}\b/i", $value); } public static function creditcard($value,$extra=null,$data=null) { $value = preg_replace('/[^0-9]+/', '', $value); if (!$value) return false; if (preg_match("/^([34|37]{2})([0-9]{13})$/", $value) && self::luhn($value)) // Amex return true; if (preg_match("/^([30|36|38]{2})([0-9]{12})$/", $value) && self::luhn($value)) // Diners return true; if (preg_match("/^(?:6(?:011|5[0-9][0-9])[0-9]{12})$/", $value) && self::luhn($value)) // Discover return true; if (preg_match("/^([51|52|53|54|55]{2})([0-9]{14})$/", $value) && self::luhn($value)) // Master return true; if (preg_match("/^([4]{1})([0-9]{12,15})$/", $value) && self::luhn($value)) // Visa return true; return false; } public static function custom($param,$extra=null,$data=null) { if(strpos($param,"\n") !== FALSE) $param = str_replace(array("\r","\n"),'',$param); for($i=0;$i<strlen($param);$i++) if(strpos($extra,$param[$i]) === false) return false; return true; } public static function password($param,$extra=null,$data=null) { if (RSFormProHelper::isCode($data['DEFAULTVALUE']) == $param) return true; return false; } public static function ipaddress($param,$extra=null,$data=null) { return preg_match('#\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b#', $param, $match); } public static function validurl($param,$extra=null,$data=null) { try { // URLs need a scheme to be valid if (!preg_match('/^(https?):\/\//i', $param, $match)) { $param = 'http://'.$param; } // But too many schemes don't do if (substr_count($param, '://') > 1) { return false; } // Let's encode utf-8 characters $param = JStringPunycode::urlToPunycode($param); // Let's use the Joomla! Uri to grab the host $uri = JUri::getInstance($param); $host = $uri->getScheme().'://'.$uri->getHost(); // Now FILTER_VALIDATE_URL should suffice if (filter_var($host, FILTER_VALIDATE_URL)) { return true; } return false; } catch (Exception $e) { return false; } } public static function regex($value,$pattern=null,$data=null) { return preg_match($pattern, $value); } public static function sameas($value, $secondField, $data) { $valid = false; $form = JFactory::getApplication()->input->get('form', array(), 'array'); if (isset($form[$secondField])) { $secondValue = is_array($form[$secondField]) ? implode('', $form[$secondField]) : $form[$secondField]; if ($value == $secondValue) { $valid = true; } } return $valid; } public static function multiplerules($value, $extra = null, $data = null) { $validations = explode(',', $data['VALIDATIONMULTIPLE']); $extra = json_decode($extra); if (!empty($validations)) { foreach ($validations as $function) { $newData = $data; unset($newData['VALIDATIONMULTIPLE']); $newData['VALIDATIONRULE'] = $function; $newData['VALIDATIONEXTRA'] = !empty($extra->{$function}) ? $extra->{$function} : null; if (!call_user_func_array('self::'.$function, array($value, $newData['VALIDATIONEXTRA'], $newData))) { return false; } } } return true; } protected static function luhn($value) { $sum = 0; $odd = strlen($value) % 2; // Calculate sum of digits. for($i = 0; $i < strlen($value); $i++) { $sum += $odd ? $value[$i] : (($value[$i] * 2 > 9) ? $value[$i] * 2 - 9 : $value[$i] * 2); $odd = !$odd; } // Check validity. return ($sum % 10 == 0) ? true : false; } } captcha.php 0000705 00000011526 15242100671 0006661 0 ustar 00 <?php /** * @package RSForm! Pro * @copyright (C) 2007-2014 www.rsjoomla.com * @license GPL, http://www.gnu.org/copyleft/gpl.html */ // no direct access defined( '_JEXEC' ) or die( 'Restricted access' ); class RSFormProCaptcha { var $Size; var $Length; var $Type; var $CaptchaString; var $fontpath; var $fonts; var $data; public function __construct($componentId=0) { $this->data = RSFormProHelper::getComponentProperties($componentId); if (!isset($this->data['IMAGETYPE'])) $this->data['IMAGETYPE'] = 'FREETYPE'; if (!isset($this->data['LENGTH'])) $this->data['LENGTH'] = 4; if ($this->data['IMAGETYPE'] == 'INVISIBLE') die(); if (!function_exists('imagecreate')) { header('Location:'.JURI::root().'components/com_rsform/assets/images/nogd.gif'); die(); } if (JFactory::getDocument()->getType() != 'image') { header('Content-Type: image/png'); } $this->Length = $this->data['LENGTH']; $this->Size = !empty($this->data['SIZE']) && is_numeric($this->data['SIZE']) && $this->data['SIZE'] > 0 ? $this->data['SIZE'] : 15; $this->fontpath = JPATH_SITE.'/components/com_rsform/assets/fonts'; $this->fonts = $this->getFonts(); if ($this->data['IMAGETYPE'] == 'FREETYPE') { if (!count($this->fonts)) { $error = new RSFormProCaptchaError; $error->addError('No fonts available!'); $error->displayError(); die(); } if (!function_exists('imagettftext')) { $error = new RSFormProCaptchaError; $error->addError('The function imagettftext does not exist.'); $error->displayError(); die(); } } $this->stringGenerate(); $this->makeCaptcha($componentId); } function getFonts() { jimport('joomla.filesystem.folder'); return JFolder::files($this->fontpath, '\.ttf'); } function getRandomFont() { return $this->fontpath.'/'.$this->fonts[mt_rand(0, count($this->fonts) - 1)]; } function stringGenerate() { if (!isset($this->data['TYPE'])) $this->data['TYPE'] = 'ALPHANUMERIC'; switch ($this->data['TYPE']) { case 'ALPHA': $CharPool = range('a','z'); break; case 'NUMERIC': $CharPool = range('0','9'); break; case 'ALPHANUMERIC': default: $CharPool = array_merge(range('0','9'),range('a','z')); break; } $PoolLength = count($CharPool) - 1; for ($i = 0; $i < $this->Length; $i++) $this->CaptchaString .= $CharPool[mt_rand(0, $PoolLength)]; } function makeCaptcha($componentId=0) { if (!isset($this->data['BACKGROUNDCOLOR'])) $this->data['BACKGROUNDCOLOR'] = '#FFFFFF'; if (!isset($this->data['TEXTCOLOR'])) $this->data['TEXTCOLOR'] = '#000000'; $imagelength = $this->Length * $this->Size + 10; $imageheight = $this->Size*1.6; $image = imagecreate($imagelength, $imageheight); $usebgrcolor = sscanf($this->data['BACKGROUNDCOLOR'], '#%2x%2x%2x'); $usestrcolor = sscanf($this->data['TEXTCOLOR'], '#%2x%2x%2x'); $bgcolor = imagecolorallocate($image, $usebgrcolor[0], $usebgrcolor[1], $usebgrcolor[2]); $stringcolor = imagecolorallocate($image, $usestrcolor[0], $usestrcolor[1], $usestrcolor[2]); if ($this->data['IMAGETYPE'] == 'FREETYPE') for ($i = 0; $i < strlen($this->CaptchaString); $i++) { imagettftext($image,$this->Size, mt_rand(-15,15), $i * $this->Size + 10, $imageheight/100*80, $stringcolor, $this->getRandomFont(), $this->CaptchaString{$i}); } if ($this->data['IMAGETYPE'] == 'NOFREETYPE') imagestring($image, mt_rand(3,5), 10, 0, $this->CaptchaString, $stringcolor); $this->addNoise($image, 2); imagepng($image); imagedestroy($image); } function addNoise(&$image, $runs = 30) { $w = imagesx($image); $h = imagesy($image); for ($n = 0; $n < $runs; $n++) for ($i = 1; $i <= $h; $i++) { $randcolor = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagesetpixel($image, mt_rand(1, $w), mt_rand(1, $h), $randcolor); } } function getCaptcha() { return $this->CaptchaString; } } class RSFormProCaptchaError { var $errors = array(); function addError($errormsg = '') { $this->errors[] = $errormsg; } function displayError() { $iheight = count($this->errors) * 20 + 10; $iheight = ($iheight < 70) ? 70 : $iheight; $image = imagecreate(600, $iheight); $bgcolor = imagecolorallocate($image, 255, 255, 255); $stringcolor = imagecolorallocate($image, 0, 0, 0); for ($i = 0; $i < count($this->errors); $i++) { $imx = ($i == 0) ? $i * 20 + 5 : $i * 20; imagestring($image, 5, 5, $imx, $this->errors[$i], $stringcolor); } imagepng($image); imagedestroy($image); } } datevalidation.php 0000705 00000003253 15242100671 0010244 0 ustar 00 <?php /** * @package RSForm! Pro * @copyright (C) 2007-2014 www.rsjoomla.com * @license GPL, http://www.gnu.org/copyleft/gpl.html */ // no direct access defined( '_JEXEC' ) or die( 'Restricted access' ); class RSFormProDateValidations { public static function none($day, $month, $year, $data = array()) { // no validation $valid = true; return $valid; } public static function fromtoday($day, $month, $year, $data = array()) { $today = JFactory::getDate(); $selected = JFactory::getDate($year.'-'.self::padding($month).'-'.self::padding($day).' 23:59:59'); return $selected->toUnix() >= $today->toUnix(); } public static function fromtomorrow($day, $month, $year, $data = array()) { $tomorrow = JFactory::getDate(); $tomorrow->modify('+1 day'); $selected = JFactory::getDate($year.'-'.self::padding($month).'-'.self::padding($day).' 23:59:59'); return $selected->toUnix() >= $tomorrow->toUnix(); } public static function beforetodayexcluding($day, $month, $year, $data = array()) { $today = JFactory::getDate(); $today->setTime(0, 0, 0); $selected = JFactory::getDate($year.'-'.self::padding($month).'-'.self::padding($day).' 00:00:00'); return $selected->toUnix() < $today->toUnix(); } public static function beforetodayincluding($day, $month, $year, $data = array()) { $today = JFactory::getDate(); $today->setTime(23, 59, 59); $selected = JFactory::getDate($year.'-'.self::padding($month).'-'.self::padding($day).' 00:00:00'); return $selected->toUnix() < $today->toUnix(); } protected static function padding($value) { return str_pad($value, 2, '0', STR_PAD_LEFT); } } index.html 0000705 00000000032 15242100671 0006530 0 ustar 00 <html><body></body></html>