Exemplo n.º 1
0
function contact_form_validate()
{
    $arr['version'] = system_ver();
    $arr['name'] = $_POST['name'];
    if (!empty($_POST['email'])) {
        $arr['email'] = $_POST['email'];
    }
    if (!empty($_POST['url'])) {
        $arr['url'] = $_POST['url'];
    }
    $arr['content'] = $_POST['content'];
    $arr['ip-address'] = utils_ipget();
    if (apply_filters('comment_validate', true, $arr)) {
        return $arr;
    } else {
        return false;
    }
}
Exemplo n.º 2
0
function comment_validate()
{
    global $smarty, $lang;
    $lerr =& $lang['comments']['error'];
    $r = true;
    /*			$lang['comments']['error'] = array(
    		'name'		=> 'You must enter a name',
    		'email'		=> 'You must enter a valid email',
    		'www'		=> 'You must enter a valid URL',
    		'comment'	=> 'You must enter a comment',
    	);*/
    $content = isset($_POST['content']) ? trim(stripslashes($_POST['content'])) : null;
    $errors = array();
    $loggedin = false;
    if (user_loggedin()) {
        $user = user_get();
        $loggedin = $arr['loggedin'] = true;
        $email = $user['email'];
        $url = $user['www'];
        $name = $user['userid'];
    } else {
        $name = trim(htmlspecialchars(@$_POST['name']));
        $email = isset($_POST['email']) ? trim(htmlspecialchars($_POST['email'])) : null;
        $url = isset($_POST['url']) ? trim(stripslashes(htmlspecialchars($_POST['url']))) : null;
        /*
         * check name
         *
         */
        if (!$name) {
            $errors['name'] = $lerr['name'];
        }
        /*
         * check email
         *
         */
        if ($email) {
            $_is_valid = !(preg_match('!@.*@|\\.\\.|\\,|\\;!', $email) || !preg_match('!^.+\\@(\\[?)[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$!', $email));
            if (!$_is_valid) {
                $errors['email'] = $lerr['email'];
            }
        }
        /*
         * check url
         *
         */
        if ($url) {
            if (!preg_match('!^http(s)?://[\\w-]+\\.[\\w-]+(\\S+)?$!i', $url)) {
                // || preg_match('!^http(s)?://localhost!', $value);
                $errors['url'] = $lerr['www'];
            }
        }
    }
    if (!$content) {
        $errors['content'] = $lerr['comment'];
    }
    if ($errors) {
        $smarty->assign('error', $errors);
        return false;
    }
    $arr['version'] = system_ver();
    $arr['name'] = $name;
    if (!$loggedin) {
        setcookie('comment_author_' . COOKIEHASH, $arr['name'], time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    }
    if ($email) {
        $arr['email'] = $email;
        if (!$loggedin) {
            setcookie('comment_author_email_' . COOKIEHASH, $arr['email'], time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
        }
    }
    if ($url) {
        $arr['url'] = $url;
        if (!$loggedin) {
            setcookie('comment_author_url_' . COOKIEHASH, $arr['url'], time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
        }
    }
    $arr['content'] = $content;
    if ($v = utils_ipget()) {
        $arr['ip-address'] = $v;
    }
    if ($loggedin || apply_filters('comment_validate', true, $arr)) {
        return $arr;
    } else {
        return false;
    }
}