Ignore:
Timestamp:
Jan 16, 2013, 2:15:29 AM (11 years ago)
Author:
mistic100
Message:

impove display, add LiveValidation

Location:
extensions/GuestBook/include
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/GuestBook/include/functions.inc.php

    r17495 r20181  
    33if (!defined('GUESTBOOK_PATH')) die('Hacking attempt!');
    44
    5 if (!function_exists('is_valid_email'))
     5function gb_is_valid_email($mail_address)
    66{
    7   function is_valid_email($mail_address)
     7  if (function_exists('email_check_format'))
    88  {
    9     if (version_compare(PHP_VERSION, '5.2.0') >= 0)
    10     {
    11       return filter_var($mail_address, FILTER_VALIDATE_EMAIL)!==false;
    12     }
    13     else
    14     {
    15       $atom   = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]';   // before  arobase
    16       $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name
    17       $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i';
     9    return email_check_format($email_address);
     10  }
     11  else if (version_compare(PHP_VERSION, '5.2.0') >= 0)
     12  {
     13    return filter_var($mail_address, FILTER_VALIDATE_EMAIL)!==false;
     14  }
     15  else
     16  {
     17    $atom   = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]';   // before  arobase
     18    $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name
     19    $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i';
    1820
    19       if (!preg_match($regex, $mail_address)) return false;
    20       return true;
    21     }
     21    return (bool)preg_match($regex, $mail_address);
    2222  }
    2323}
    2424
    25 function is_valid_url($url)
     25function gb_is_valid_url($url)
    2626{
    27   if (version_compare(PHP_VERSION, '5.2.0') >= 0)
     27  if (function_exists('url_check_format'))
     28  {
     29    return url_check_format($url);
     30  }
     31  else if (version_compare(PHP_VERSION, '5.2.0') >= 0)
    2832  {
    2933    return filter_var($url, FILTER_VALIDATE_URL)!==false;
     
    3337    $regex = '#^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$#i';
    3438
    35     if (!preg_match($regex, $url)) return false;
    36     return true;
     39    return (bool)preg_match($regex, $url);
    3740  }
    3841}
  • extensions/GuestBook/include/functions_comment.inc.php

    r16000 r20181  
    66  EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
    77
    8 function insert_user_comment_guestbook( &$comm, $key, &$infos )
     8function insert_user_comment_guestbook( &$comm, $key )
    99{
    1010  global $conf, $user, $page;
     
    1616    )
    1717   );
    18 
    19   $infos = array();
     18 
    2019  if (!$conf['guestbook']['comments_validation'] or is_admin())
    2120  {
     
    7574    $comm['email'] = $user['email'];
    7675  }
    77   else if ( !empty($comm['email']) and !is_valid_email($comm['email']) )
     76  else if ( !empty($comm['email']) and !gb_is_valid_email($comm['email']) )
    7877  {
    7978    array_push($page['errors'], l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)'));
     
    8685    $comm['website'] = 'http://'.$comm['website'];
    8786  }
    88   if ( !empty($comm['website']) and !is_valid_url($comm['website']) )
     87  if ( !empty($comm['website']) and !gb_is_valid_url($comm['website']) )
    8988  {
    9089    array_push($page['errors'], l10n('invalid website address'));
     
    121120    if ($counter > 0)
    122121    {
    123       array_push( $infos, l10n('Anti-flood system : please wait for a moment before trying to post another comment') );
     122      array_push($page['errors'], l10n('Anti-flood system : please wait for a moment before trying to post another comment') );
    124123      $comment_action='reject';
    125124    }
  • extensions/GuestBook/include/guestbook.inc.php

    r17717 r20181  
    11<?php
    22if (!defined('GUESTBOOK_PATH')) die('Hacking attempt!');
     3
     4global $user;
    35
    46include(GUESTBOOK_PATH . '/include/functions.inc.php');
     
    116118  include_once(GUESTBOOK_PATH.'include/functions_comment.inc.php');
    117119
    118   $comment_action = insert_user_comment_guestbook($comm, @$_POST['key'], $page['infos']);
     120  $comment_action = insert_user_comment_guestbook($comm, @$_POST['key']);
    119121
    120122  switch ($comment_action)
     
    303305    }
    304306  }
     307  if (is_classic_user())
     308  {
     309    $author = $user['username'];
     310    $email = $user['email'];
     311  }
     312  if (empty($conf['comments_email_mandatory'])) // < 2.5 compatibility
     313  {
     314    $conf['comments_email_mandatory'] = false;
     315  }
     316
    305317  $template->assign('comment_add',
    306318      array(
     
    308320        'KEY' => get_ephemeral_key(3),
    309321        'CONTENT' => $content,
    310         'SHOW_AUTHOR' => !is_classic_user(),
    311         'AUTHOR' => $author ,
    312         'WEBSITE' => $website ,
    313         'EMAIL' => $email ,
     322        'IS_LOGGED' => is_classic_user(),
     323        'AUTHOR' => $author,
     324        'WEBSITE' => $website,
     325        'EMAIL' => $email,
    314326        'ACTIVATE_RATING' => $conf['guestbook']['activate_rating'],
     327        'EMAIL_MANDATORY' => $conf['comments_email_mandatory'],
    315328      ));
    316329}
     
    319332$template->assign('GUESTBOOK_PATH', GUESTBOOK_PATH);
    320333
    321 $template->assign('clear_themes', array(
    322   'clear',
    323   'gally-minimalist',
    324   'hr_os',
    325   'hr_os_xl',
    326   'kardon',
    327   'montblancxl',
    328   'Naive',
    329   'OS_glass_clear',
    330   'p0w0',
    331   'Pure_autumn',
    332   'Pure_clear_blue',
    333   'Pure_sky',
    334   'Pure_tr_clear_blue',
    335   'simple-white',
    336   'VerticalWhite',
    337   ));
    338 
    339334$template->set_filename('index', dirname(__FILE__).'/../template/guestbook.tpl');
    340335
Note: See TracChangeset for help on using the changeset viewer.