Changeset 20181


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

impove display, add LiveValidation

Location:
extensions/GuestBook
Files:
1 added
1 deleted
8 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
  • extensions/GuestBook/language/en_UK/plugin.lang.php

    r16347 r20181  
    22
    33$lang['Please enter your username'] = 'Please enter your username';
     4$lang['Please enter your e-mail'] = 'Please enter your e-mail';
     5$lang['Please enter a message'] = 'Please enter a message';
    46$lang['invalid website address'] = 'invalid website address';
    57$lang['GuestBook'] = 'Guestbook';
  • extensions/GuestBook/language/fr_FR/plugin.lang.php

    r16347 r20181  
    22
    33$lang['Please enter your username'] = 'Veuillez renseigner votre nom';
     4$lang['Please enter your e-mail'] = 'Veuillez renseigner votre e-mail';
     5$lang['Please enter a message'] = 'Veuillez écrire un message';
    46$lang['invalid website address'] = 'adresse du site web invalide';
    57$lang['GuestBook'] = 'Livre d\'or';
    68$lang['Sign the guestbook'] = 'Signer le livre d\'or';
    7 $lang['not publicly visible'] = 'not visible';
     9$lang['not publicly visible'] = 'non visible';
    810$lang['Website'] = 'Site web';
    911$lang['* : mandatory fields'] = '* : champs obligatoires';
    1012$lang['There are %d messages'] = 'Il y a %d messages';
    11 $lang['Activate rating'] = 'Activater la notation';
     13$lang['Activate rating'] = 'Activer la notation';
    1214$lang['%s says on %s :'] = '%s a dit le %s :';
    1315
  • extensions/GuestBook/template/comment_list.tpl

    r16347 r20181  
    1313      <a href="{$comment.U_CANCEL}">
    1414        {'Cancel'|@translate}
    15       </a>{if isset($comment.U_VALIDATE) or isset($comment.U_EDIT)} | {/if}
     15      </a>{if isset($comment.U_VALIDATE)} | {/if}
    1616    {/if}
    1717    {if isset($comment.U_EDIT) and !isset($comment.IN_EDIT)}
  • extensions/GuestBook/template/guestbook.tpl

    r17732 r20181  
    11{combine_css path=$GUESTBOOK_PATH|@cat:"template/style.css"}
    2 {if $themeconf.name|in_array:$clear_themes}
    3   {combine_css path=$GUESTBOOK_PATH|@cat:"template/style-clear.css"}
     2{combine_script id="livevalidation" load="footer" path=$GUESTBOOK_PATH|@cat:"template/livevalidation.min.js"}
     3
     4{footer_script require='livevalidation'}
     5{if !$comment_add.IS_LOGGED}
     6var author = new LiveValidation('author', {ldelim} onlyOnSubmit: true });
     7author.add(Validate.Presence, {ldelim} failureMessage: "{'Please enter your username'|@translate}" });
    48{/if}
     9
     10{if $add_comment.EMAIL_MANDATORY and (!$add_comment.IS_LOGGED or empty($add_comment.EMAIL))}
     11var email = new LiveValidation('email', {ldelim} onlyOnSubmit: true });
     12email.add(Validate.Presence, {ldelim} failureMessage: "{'Please enter your e-mail'|@translate}" });
     13email.add(Validate.Email, {ldelim} failureMessage: "{'mail address must be like xxx@yyy.eee (example : jack@altern.org)'|@translate}" });
     14{/if}
     15
     16var website = new LiveValidation('website', {ldelim} onlyOnSubmit: true });
     17website.add(Validate.Format, {ldelim} pattern: /^https?:\/\/(-\.)?([^\s\/?\.#-]+\.?)+(\/[^\s]*)?$/i,
     18  failureMessage: "{'invalid website address'|@translate}"});
     19
     20var content = new LiveValidation('contentid', {ldelim} onlyOnSubmit: true });
     21content.add(Validate.Presence, {ldelim} failureMessage: "{'Please enter a message'|@translate}" });
     22 
     23jQuery("#addComment").hide();
     24jQuery("#guestbookAdd").css('width','180px');
     25jQuery("#expandForm").click(function() {ldelim}
     26  jQuery("#guestbookAdd").animate({ldelim}"width": "550px"}, function() {ldelim}
     27    jQuery("#expandForm").slideUp();
     28    jQuery("#addComment").slideDown("slow");
     29  });
     30});
     31{/footer_script}
    532
    633{if $comment_add.ACTIVATE_RATING}
     
    1340  {/footer_script}
    1441{/if}
    15 
    16 {footer_script}
    17 jQuery("#expandForm").click(function() {ldelim}
    18   jQuery("#guestbookAdd").animate({ldelim}"width": "500px"}, function() {ldelim}
    19     jQuery("#addComment").slideDown("slow");
    20   });
    21 });
    22 {/footer_script}
    2342
    2443
     
    4160{if isset($comment_add)}
    4261<div id="guestbookAdd">
    43 <h4 id="expandForm">{'Sign the guestbook'|@translate}</h4>
    44 <form method="post" action="{$comment_add.F_ACTION}" id="addComment" style="display:none;">
    45   <table>
    46   {if $comment_add.SHOW_AUTHOR}
    47     <tr>
    48     <td>
    49       <p><label for="author">{'Author'|@translate}* :</label></p>
    50       <p><input type="text" name="author" id="author" value="{$comment_add.AUTHOR}"></p>
    51     </td>
    52     <td>
    53       <p><label for="email">{'Email address'|@translate} ({'not publicly visible'|@translate}) :</label></p>
    54       <p><input type="text" name="email" id="email" size="30" value="{$comment_add.EMAIL}"></p>
    55     </td>
    56     </tr>
    57   {/if}
    58     <tr>
    59   {if $comment_add.ACTIVATE_RATING}
    60     <td>
    61       <p>{'Rate'|@translate} :</p>
    62       <p><span id="comment_rate"></span></p>
    63     </td>
    64   {/if}
    65     <td>
    66       <p><label for="website">{'Website'|@translate} :</label></p>
    67       <p><input type="text" name="website" id="website" size="30" value="{$comment_add.WEBSITE}"></p>
    68     </td>
    69     </tr>
    70   </table>
    71  
    72   <p><label for="contentid">{'Comment'|@translate}* :</label></p>
    73   <p><textarea name="content" id="contentid" rows="10" style="width:100%;">{$comment_add.CONTENT}</textarea></p>
    74   <p><input type="hidden" name="key" value="{$comment_add.KEY}">
    75     <input type="submit" value="{'Submit'|@translate}"> {'* : mandatory fields'|@translate}</p>
    76 </form>
     62  <h4 id="expandForm">{'Sign the guestbook'|@translate}</h4>
     63  <form method="post" action="{$comment_add.F_ACTION}" id="addComment" class="contact">
     64    <table>
     65    {if not $comment_add.IS_LOGGED or empty($comment_add.EMAIL)}
     66      <tr>
     67        <td>
     68          <label for="author">{'Author'|@translate}* :</label>
     69        {if $comment_add.IS_LOGGED}
     70          {$comment_add.AUTHOR}
     71          <input type="hidden" name="author" value="{$comment_add.AUTHOR}">
     72        {else}
     73          <input type="text" name="author" id="author" value="{$comment_add.AUTHOR}">
     74        {/if}
     75        </td>
     76        <td>
     77          <label for="email">{'Email address'|@translate}{if $comment_add.EMAIL_MANDATORY}*{/if} ({'not publicly visible'|@translate}) :</label>
     78          <input type="text" name="email" id="email" value="{$comment_add.EMAIL}">
     79        </td>
     80      </tr>
     81    {/if}
     82      <tr>
     83      {if $comment_add.ACTIVATE_RATING}
     84        <td>
     85          <label>{'Rate'|@translate} :</label>
     86          <span id="comment_rate"></span>
     87        </td>
     88      {/if}
     89        <td>
     90          <label for="website">{'Website'|@translate} :</label>
     91          <input type="text" name="website" id="website" value="{$comment_add.WEBSITE}">
     92        </td>
     93      </tr>
     94      <tr>
     95        <td colspan="2">
     96          <label for="contentid">{'Comment'|@translate}* :</label>
     97          <textarea name="content" id="contentid" rows="7">{$comment_add.CONTENT}</textarea>
     98        </td>
     99      </tr>
     100      <tr>
     101        <td colspan="2">
     102          <input type="submit" value="{'Send'|@translate}">
     103          {'* : mandatory fields'|@translate}
     104        </td>
     105      </tr>
     106    </table>
     107   
     108    <input type="hidden" name="key" value="{$comment_add.KEY}">
     109  </form>
    77110</div>
    78111{/if}
  • extensions/GuestBook/template/style.css

    r17717 r20181  
    11#guestbookAdd {
    22  padding:15px;
    3   width:180px;
     3  width:550px;
    44  margin:10px auto 25px auto;
    5   background: #333333;
    6   background: -moz-linear-gradient(top, #333333 0%, #252525 100%);
    7   background: -webkit-linear-gradient(top, #333333 0%, #252525 100%);
    8   background: -o-linear-gradient(top, #333333 0%, #252525 100%);
    9   background: -ms-linear-gradient(top, #333333 0%, #252525 100%);
    10   background: linear-gradient(top, #333333 0%, #252525 100%);
    115  border-radius:5px;
    126  border:1px solid #555;
    137  box-shadow:5px 5px 5px rgba(0, 0, 0, 0.25);
    14   color:#aaa;
     8  overflow:hidden;
    159}
    1610
     
    1913  cursor:pointer;
    2014  text-align:center;
     15  font-size:13px;
    2116}
    22   #guestbookAdd h4:hover {
    23     color:#fff;
    24   }
     17 
    2518
    26 #guestbookAdd table {
     19.contact table {
    2720  width:100%;
    2821  text-align:left;
    2922}
     23  .contact table td {
     24    width:50%;
     25    text-align:left;
     26  }
     27.contact label {
     28  font-weight:bold;
     29  display:block;
     30}
     31.contact input[type="text"], .contact textarea, .contact select {
     32  border-radius:2px;
     33  padding:3px;
     34}
     35.contact textarea {
     36  width:535px;
     37}
     38.contact input[type="text"] {
     39  width:260px;
     40}
    3041
    31 #addComment {
    32   margin-top:5px;
     42
     43.LV_validation_message{
     44  display:block;
     45  font-weight:bold;
     46  margin:0 0 0 5px;
    3347}
     48.LV_valid {
     49   display:none;
     50}
     51.LV_invalid {
     52  color:#cc0000;
     53}
     54.LV_invalid_field,
     55input.LV_invalid_field:hover,
     56input.LV_invalid_field:active,
     57textarea.LV_invalid_field:hover,
     58textarea.LV_invalid_field:active {
     59  border: 1px solid #cc0000;
     60}
     61
    3462
    3563p.comment_count {
     
    4068}
    4169
    42 #guestbookAdd p, .commentElement p {
     70.commentElement p {
    4371  text-align:left;
    4472  margin-bottom:0.5em;
     
    4775
    4876.commentElement {
    49   padding:0;
     77  padding:0 !important;
    5078  list-style:none;
    5179  text-align:left;
     80  border:1px solid #555;
     81  border-radius:5px;
     82  margin:5px;
     83  overflow:hidden;
    5284}
    5385  .commentElement .description {
    5486    padding:7px !important;
     87    min-height:0;
    5588  }
    5689  .commentHeader  {
    57     background:#444;
     90    background:rgba(127,127,127,0.5);
    5891    margin:-7px;
    5992    margin-bottom:0;
Note: See TracChangeset for help on using the changeset viewer.