Changeset 26065


Ignore:
Timestamp:
Dec 21, 2013, 5:33:24 PM (7 years ago)
Author:
mistic100
Message:

update for Piwigo 2.6 + code clean

Location:
extensions/GuestBook
Files:
1 added
2 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • extensions/GuestBook/admin.php

    r24889 r26065  
    11<?php
    2 if(!defined('GUESTBOOK_PATH')) die('Hacking attempt!');
     2defined('GUESTBOOK_PATH') or die('Hacking attempt!');
    33
    44global $template, $page;
  • extensions/GuestBook/admin/config.php

    r24889 r26065  
    11<?php
    2 if (!defined('GUESTBOOK_PATH')) die('Hacking attempt!');
     2defined('GUESTBOOK_PATH') or die('Hacking attempt!');
    33
    44if (isset($_POST['submit']))
     
    1515   
    1616  conf_update_param('guestbook', serialize($conf['guestbook']));
    17   array_push($page['infos'], l10n('Information data registered in database'));
     17  $page['infos'][] = l10n('Information data registered in database');
    1818}
    1919
  • extensions/GuestBook/admin/pending.php

    r24889 r26065  
    1212  if (empty($_POST['comments']))
    1313  {
    14     array_push(
    15       $page['errors'],
    16       l10n('Select at least one comment')
    17       );
     14    $page['errors'][] =l10n('Select at least one comment');
    1815  }
    1916  else
    2017  {
    21     include_once( GUESTBOOK_PATH .'include/functions_comment.inc.php' );
     18    include_once(GUESTBOOK_PATH .'include/functions_comment.inc.php');
    2219    check_input_parameter('comments', $_POST, true, PATTERN_ID);
    2320   
     
    2623      validate_user_comment_guestbook($_POST['comments']);
    2724
    28       array_push(
    29         $page['infos'],
    30         l10n_dec(
    31           '%d user comment validated', '%d user comments validated',
    32           count($_POST['comments'])
    33           )
     25      $page['infos'][] = l10n_dec(
     26        '%d user comment validated', '%d user comments validated',
     27        count($_POST['comments'])
    3428        );
    3529    }
     
    3933      delete_user_comment_guestbook($_POST['comments']);
    4034
    41       array_push(
    42         $page['infos'],
    43         l10n_dec(
    44           '%d user comment rejected', '%d user comments rejected',
    45           count($_POST['comments'])
    46           )
     35      $page['infos'][] =l10n_dec(
     36        '%d user comment rejected', '%d user comments rejected',
     37        count($_POST['comments'])
    4738        );
    4839    }
     
    7566;';
    7667$result = pwg_query($query);
     68
    7769while ($row = pwg_db_fetch_assoc($result))
    7870{
     
    10193    );
    10294
    103   array_push($list, $row['id']);
     95  $list[] = $row['id'];
    10496}
    10597
    106 $template->assign('LIST', implode(',', $list) );
    10798
    108 $template->assign('F_ACTION', GUESTBOOK_ADMIN . '-pending');
    109 
     99$template->assign(array(
     100  'LIST' => implode(',', $list),
     101  'F_ACTION' => GUESTBOOK_ADMIN . '-pending',
     102  ));
    110103
    111104$template->set_filename('guestbook', realpath(GUESTBOOK_PATH . 'admin/template/pending.tpl'));
    112 
    113 ?>
  • extensions/GuestBook/admin/template/config.tpl

    r24889 r26065  
    1 {combine_css path=$GUESTBOOK_PATH|@cat:'template/style.css'}
     1{combine_css path=$GUESTBOOK_PATH|cat:'template/style.css'}
    22
    3 {footer_script}{literal}
     3{footer_script}
    44$('input[name="comments_validation"]').on('change', function() {
    55    $('#email_admin_on_comment_validation').toggle($(this).is(':checked'));
     
    1111})
    1212.trigger('change');
    13 {/literal}{/footer_script}
     13{/footer_script}
     14
    1415
    1516<div class="titrePage">
    16   <h2>{'GuestBook'|@translate}</h2>
     17  <h2>GuestBook</h2>
    1718</div>
    1819
     
    2324    <li>
    2425      <label>
    25         <b>{'Number of comments per page'|@translate}</b>
     26        <b>{'Number of comments per page'|translate}</b>
    2627        <input type="text" size="3" maxlength="4" name="nb_comment_page" id="nb_comment_page" value="{$nb_comment_page}">
    2728      </label>
     
    3132      <label>
    3233        <input type="checkbox" name="activate_rating" {if ($activate_rating)}checked="checked"{/if}>
    33         <b>{'Activate rating'|@translate}</b>
     34        <b>{'Activate rating'|translate}</b>
    3435      </label>
    3536    </li>
     
    3839      <label>
    3940        <input type="checkbox" name="comments_validation" {if ($comments_validation)}checked="checked"{/if}>
    40         <b>{'Validation'|@translate}</b>
     41        <b>{'Validation'|translate}</b>
    4142      </label>
    4243    </li>
    4344
    4445    <li>
    45       <strong>{'Notify administrators when a comment is'|@translate}</strong>
     46      <strong>{'Notify administrators when a comment is'|translate}</strong>
    4647
    4748      <label>
    48         <input type="checkbox" name="email_admin_on_comment" {if ($email_admin_on_comment)}checked="checked"{/if}> {'added'|@translate}
     49        <input type="checkbox" name="email_admin_on_comment" {if ($email_admin_on_comment)}checked="checked"{/if}> {'added'|translate}
    4950      </label>
    5051
    5152      <label id="email_admin_on_comment_validation">
    52         <input type="checkbox" name="email_admin_on_comment_validation" {if ($email_admin_on_comment_validation)}checked="checked"{/if}> {'pending validation'|@translate}
     53        <input type="checkbox" name="email_admin_on_comment_validation" {if ($email_admin_on_comment_validation)}checked="checked"{/if}> {'pending validation'|translate}
    5354      </label>
    5455    </li>
    5556   
    5657    <li>
    57       <strong>{'Guests (not registered) permissions :'|@translate}</strong>
     58      <strong>{'Guests (not registered) permissions :'|translate}</strong>
    5859
    5960      <label>
    60         <input type="checkbox" name="guest_can_view" {if ($guest_can_view)}checked="checked"{/if}> {'view comments'|@translate}
     61        <input type="checkbox" name="guest_can_view" {if ($guest_can_view)}checked="checked"{/if}> {'view comments'|translate}
    6162      </label>
    6263
    6364      <label id="guest_can_add">
    64         <input type="checkbox" name="guest_can_add" {if ($guest_can_add)}checked="checked"{/if}> {'add comment'|@translate}
     65        <input type="checkbox" name="guest_can_add" {if ($guest_can_add)}checked="checked"{/if}> {'add comment'|translate}
    6566      </label>
    6667    </li>
     
    6970
    7071  <p class="formButtons">
    71                 <input type="submit" name="submit" value="{'Save Settings'|@translate}">
     72                <input type="submit" name="submit" value="{'Save Settings'|translate}">
    7273        </p>
    7374</form>
  • extensions/GuestBook/admin/template/pending.tpl

    r15940 r26065  
    1 {combine_css path=$GUESTBOOK_PATH|@cat:'admin/template/style.css'}
     1{combine_css path=$GUESTBOOK_PATH|cat:'admin/template/style.css'}
    22
    33<div class="titrePage">
    4   <h2>{'GuestBook'|@translate}</h2>
     4  <h2>GuestBook</h2>
    55</div>
    66
    7 {footer_script}{literal}
    8 jQuery(document).ready(function(){
    9   function highlighComments() {
    10     jQuery(".checkComment").each(function() {
    11       var parent = jQuery(this).parent('tr');
    12       if (jQuery(this).children("input[type=checkbox]").is(':checked')) {
    13         jQuery(parent).addClass('selectedComment');
    14       }
    15       else {
    16         jQuery(parent).removeClass('selectedComment');
    17       }
    18     });
     7{footer_script}
     8function highlighComments() {
     9  jQuery(".checkComment").each(function() {
     10    var parent = jQuery(this).parent('tr');
     11    if (jQuery(this).children("input[type=checkbox]").is(':checked')) {
     12      jQuery(parent).addClass('selectedComment');
     13    }
     14    else {
     15      jQuery(parent).removeClass('selectedComment');
     16    }
     17  });
     18}
     19
     20jQuery(".checkComment").click(function(event) {
     21  var checkbox = jQuery(this).children("input[type=checkbox]");
     22  if (event.target.type !== 'checkbox') {
     23    jQuery(checkbox).attr('checked', !jQuery(checkbox).is(':checked'));
    1924  }
     25  highlighComments();
     26});
    2027
    21   jQuery(".checkComment").click(function(event) {
    22     var checkbox = jQuery(this).children("input[type=checkbox]");
    23     if (event.target.type !== 'checkbox') {
    24       jQuery(checkbox).attr('checked', !jQuery(checkbox).is(':checked'));
    25     }
    26     highlighComments();
     28jQuery("#commentSelectAll").click(function() {
     29  jQuery(".checkComment input[type=checkbox]").attr('checked', true);
     30  highlighComments();
     31  return false;
     32});
     33
     34jQuery("#commentSelectNone").click(function() {
     35  jQuery(".checkComment input[type=checkbox]").attr('checked', false);
     36  highlighComments();
     37  return false;
     38});
     39
     40jQuery("#commentSelectInvert").click(function() {
     41  jQuery(".checkComment input[type=checkbox]").each(function() {
     42    jQuery(this).attr('checked', !$(this).is(':checked'));
    2743  });
     44  highlighComments();
     45  return false;
     46});
     47{/footer_script}
    2848
    29   jQuery("#commentSelectAll").click(function () {
    30     jQuery(".checkComment input[type=checkbox]").attr('checked', true);
    31     highlighComments();
    32     return false;
    33   });
    3449
    35   jQuery("#commentSelectNone").click(function () {
    36     jQuery(".checkComment input[type=checkbox]").attr('checked', false);
    37     highlighComments();
    38     return false;
    39   });
    40 
    41   jQuery("#commentSelectInvert").click(function () {
    42     jQuery(".checkComment input[type=checkbox]").each(function() {
    43       jQuery(this).attr('checked', !$(this).is(':checked'));
    44     });
    45     highlighComments();
    46     return false;
    47   });
    48 
    49 });
    50 {/literal}{/footer_script}
    51 
    52 {if !empty($comments) }
     50{if !empty($comments)}
    5351<form method="post" action="{$F_ACTION}" id="pendingComments">
    5452 
     
    7472
    7573  <p class="checkActions">
    76     {'Select:'|@translate}
    77     <a href="#" id="commentSelectAll">{'All'|@translate}</a>,
    78     <a href="#" id="commentSelectNone">{'None'|@translate}</a>,
    79     <a href="#" id="commentSelectInvert">{'Invert'|@translate}</a>
     74    {'Select:'|translate}
     75    <a href="#" id="commentSelectAll">{'All'|translate}</a>,
     76    <a href="#" id="commentSelectNone">{'None'|translate}</a>,
     77    <a href="#" id="commentSelectInvert">{'Invert'|translate}</a>
    8078  </p>
    8179
    8280  <p class="bottomButtons">
    83     <input class="submit" type="submit" name="validate" value="{'Validate'|@translate}">
    84     <input class="submit" type="submit" name="reject" value="{'Reject'|@translate}">
     81    <input class="submit" type="submit" name="validate" value="{'Validate'|translate}">
     82    <input class="submit" type="submit" name="reject" value="{'Reject'|translate}">
    8583  </p>
    8684
    8785</form>
    8886{else}
    89 {'No pending comment'|@translate}
     87{'No pending comment'|translate}
    9088{/if}
  • extensions/GuestBook/include/events.inc.php

    r24889 r26065  
    44function gb_admin_menu($menu)
    55{
    6   array_push($menu, array(
     6  $menu[] = array(
    77    'NAME' => 'GuestBook',
    88    'URL' => GUESTBOOK_ADMIN,
    9   ));
     9  );
    1010  return $menu;
    1111}
     
    2424  if ( ($block = $menu->get_block('mbMenu')) != null )
    2525  {
    26     array_push($block->data, array(
     26    $block->data[] = array(
    2727      'URL' => GUESTBOOK_URL,
    2828      'TITLE' => l10n('GuestBook'),
    2929      'NAME' => l10n('GuestBook')
    30     ));
     30    );
    3131  }
    3232}
     
    3838  if ($tokens[0] == 'guestbook')
    3939  {
    40     add_event_handler('loc_begin_page_header', 'gb_page_header');
     40    $page['section'] = 'guestbook';
     41    $page['body_id'] = 'theGuestBook';
     42    $page['is_external'] = true;
     43    $page['is_homepage'] = false;
    4144   
    42     $page['section'] = 'guestbook';
    4345    $page['title'] = l10n('GuestBook');
    4446    $page['section_title'] = '<a href="'.get_gallery_home_url().'">'.l10n('Home').'</a>'.$conf['level_separator'].l10n('GuestBook');
     
    4648}
    4749
    48 function gb_page_header()
    49 {
    50   global $page;
    51   $page['body_id'] = 'theGuestBook';
    52 }
    53 
    5450function gb_index()
    5551{
    5652  global $template, $page, $conf;
    57  
    58   if (is_a_guest() && !$conf['guestbook']['guest_can_view'])
    59   {
    60     access_denied();
    61   }
    6253
    6354  if (isset($page['section']) and $page['section'] == 'guestbook')
    6455  {
     56    if (is_a_guest() && !$conf['guestbook']['guest_can_view'])
     57    {
     58      access_denied();
     59    }
     60 
    6561    include(GUESTBOOK_PATH . '/include/guestbook.inc.php');
    6662  }
    6763}
    68 
    69 /*function gb_register_stuffs_module($modules)
    70 {
    71   array_push($modules, array(
    72     'path' => GUESTBOOK_PATH . '/stuffs_module',
    73     'name' => GB_NAME,
    74     'description' => l10n('gb_stuffs_desc'),
    75   ));
    76 
    77   return $modules;
    78 }*/
  • extensions/GuestBook/include/functions.inc.php

    r24889 r26065  
    11<?php
    2 if (!defined('GUESTBOOK_PATH')) die('Hacking attempt!');
     2defined('GUESTBOOK_PATH') or die('Hacking attempt!');
    33
    44function get_stars($score, $path)
    55{
    6   if ($score === null) return null;
     6  if (!isset($score)) return null;
    77 
    88  $max = 5;
     
    1010  $floor = floor($score);
    1111 
    12   $html = null;
     12  $html = '';
    1313  for ($i=1; $i<=$floor; $i++)
    1414  {
  • extensions/GuestBook/include/functions_comment.inc.php

    r25786 r26065  
    11<?php
    2 if (!defined('GUESTBOOK_PATH')) die('Hacking attempt!');
     2defined('GUESTBOOK_PATH') or die('Hacking attempt!');
    33
    44include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
    5 add_event_handler('user_comment_check_guestbook', 'user_comment_check',
    6   EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
     5
    76
    87function insert_user_comment_guestbook( &$comm, $key )
     
    109  global $conf, $user, $page;
    1110
    12   $comm = array_merge( $comm,
     11  $comm = array_merge($comm,
    1312    array(
    1413      'ip' => $_SERVER['REMOTE_ADDR'],
     
    1918  if (!$conf['guestbook']['comments_validation'] or is_admin())
    2019  {
    21     $comment_action='validate'; //one of validate, moderate, reject
    22   }
    23   else
    24   {
    25     $comment_action='moderate'; //one of validate, moderate, reject
    26   }
    27 
    28   // display author field if the user status is guest or generic
     20    $comment_action='validate';
     21  }
     22  else
     23  {
     24    $comment_action='moderate';
     25  }
     26
     27  // author
    2928  if (!is_classic_user())
    3029  {
    31     if ( empty($comm['author']) )
    32     {
    33       array_push($page['errors'], l10n('Please enter your username'));
     30    if (empty($comm['author']))
     31    {
     32      $page['errors'][] = l10n('Please enter your username');
    3433      $comment_action='reject';
    3534    }
     
    3736    {
    3837      $comm['author_id'] = $conf['guest_id'];
    39       // if a guest try to use the name of an already existing user, he must be
    40       // rejected
     38      // if a guest try to use the name of an already existing user,
     39      // he must be rejected
    4140      $query = '
    4241SELECT COUNT(*) AS user_exists
    4342  FROM '.USERS_TABLE.'
    44   WHERE '.$conf['user_fields']['username']." = '".addslashes($comm['author'])."'";
    45       $row = pwg_db_fetch_assoc( pwg_query( $query ) );
     43  WHERE '.$conf['user_fields']['username']." = '".addslashes($comm['author'])."'
     44;";
     45      $row = pwg_db_fetch_assoc(pwg_query($query));
    4646     
    47       if ( $row['user_exists'] == 1 )
     47      if ($row['user_exists'] == 1)
    4848      {
    49         array_push($page['errors'], l10n('This login is already used by another user') );
     49        $page['errors'][] = l10n('This login is already used by another user');
    5050        $comment_action='reject';
    5151      }
     
    5858  }
    5959
    60   if ( empty($comm['content']) )
    61   { // empty comment content
    62     $comment_action='reject';
    63   }
    64 
    65   if ( !verify_ephemeral_key(@$key) )
     60  // content
     61  if (empty($comm['content']))
     62  {
     63    $comment_action='reject';
     64  }
     65
     66  // key
     67  if (!verify_ephemeral_key(@$key))
    6668  {
    6769    $comment_action='reject';
     
    7072 
    7173  // email
    72   if ( empty($comm['email']) and is_classic_user() and !empty($user['email']) )
     74  if (empty($comm['email']) and is_classic_user() and !empty($user['email']))
    7375  {
    7476    $comm['email'] = $user['email'];
    7577  }
    76   else if ( empty($comm['email']) and $conf['comments_email_mandatory'] )
    77   {
    78     array_push($page['errors'], l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)'));
    79     $comment_action='reject';
    80   }
    81   else if ( !empty($comm['email']) and !email_check_format($comm['email']) )
    82   {
    83     array_push($page['errors'], l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)'));
     78  else if (empty($comm['email']) and $conf['comments_email_mandatory'])
     79  {
     80    $page['errors'][] = l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)');
     81    $comment_action='reject';
     82  }
     83  else if (!empty($comm['email']) and !email_check_format($comm['email']))
     84  {
     85    $page['errors'][] = l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)');
    8486    $comment_action='reject';
    8587  }
    8688 
    8789  // website
    88   if ( !empty($comm['website']) and !preg_match('/^(https?:\/\/)/i', $comm['website']) )
     90  if (!empty($comm['website']) and !preg_match('/^(https?:\/\/)/i', $comm['website']))
    8991  {
    9092    $comm['website'] = 'http://'.$comm['website'];
    9193  }
    92   if ( !empty($comm['website']) and !url_check_format($comm['website']) )
    93   {
    94     array_push($page['errors'], l10n('invalid website address'));
     94  if (!empty($comm['website']) and !url_check_format($comm['website']))
     95  {
     96    $page['errors'][] = l10n('invalid website address');
    9597    $comment_action='reject';
    9698  }
     
    125127    if ($counter > 0)
    126128    {
    127       array_push($page['errors'], l10n('Anti-flood system : please wait for a moment before trying to post another comment') );
     129      $page['errors'][] = l10n('Anti-flood system : please wait for a moment before trying to post another comment');
    128130      $comment_action='reject';
    129131    }
     
    131133 
    132134  // perform more spam check
    133   $comment_action = trigger_event('user_comment_check_guestbook',
    134       $comment_action, $comm
    135     );
    136 
    137   if ( $comment_action!='reject' )
     135  $comment_action = trigger_event('user_comment_check', $comment_action, $comm);
     136
     137  if ($comment_action!='reject')
    138138  {
    139139    $query = '
     
    175175      $comment_url = add_url_params(GUESTBOOK_URL, array('comment_id'=>$comm['id']));
    176176
    177       $keyargs_content = array
    178       (
     177      $keyargs_content = array(
    179178        get_l10n_args('Author: %s', stripslashes($comm['author']) ),
    180179        get_l10n_args('Comment: %s', stripslashes($comm['content']) ),
     
    189188      }
    190189
    191       pwg_mail_notification_admins
    192       (
     190      pwg_mail_notification_admins(
    193191        get_l10n_args('Comment by %s', stripslashes($comm['author']) ),
    194192        $keyargs_content
     
    196194    }
    197195  }
     196 
    198197  return $comment_action;
    199198}
     
    205204  $comment_action = 'validate';
    206205
    207   if ( !verify_ephemeral_key($post_key) )
    208   {
    209     $comment_action='reject';
    210   }
    211   elseif (!$conf['guestbook']['comments_validation'] or is_admin()) // should the updated comment must be validated
    212   {
    213     $comment_action='validate'; //one of validate, moderate, reject
    214   }
    215   else
    216   {
    217     $comment_action='moderate'; //one of validate, moderate, reject
    218   }
    219 
    220   if ( $comment_action!='reject' )
     206  if (!verify_ephemeral_key($post_key))
     207  {
     208    $comment_action='reject';
     209  }
     210  else if (!$conf['guestbook']['comments_validation'] or is_admin()) // should the updated comment must be validated
     211  {
     212    $comment_action='validate';
     213  }
     214  else
     215  {
     216    $comment_action='moderate';
     217  }
     218
     219  if ($comment_action!='reject')
    221220  {
    222221    $user_where_clause = '';
     
    244243      $comment_url = add_url_params(GUESTBOOK_URL, array('comment_id'=>$comm['id']));
    245244
    246       $keyargs_content = array
    247       (
     245      $keyargs_content = array(
    248246        get_l10n_args('Author: %s', stripslashes($GLOBALS['user']['username']) ),
    249247        get_l10n_args('Comment: %s', stripslashes($comment['content']) ),
     
    254252      );
    255253
    256       pwg_mail_notification_admins
    257       (
     254      pwg_mail_notification_admins(
    258255        get_l10n_args('Comment by %s', stripslashes($GLOBALS['user']['username']) ),
    259256        $keyargs_content
     
    274271;';
    275272  $result = pwg_query($query);
     273
    276274  if (pwg_db_num_rows($result) == 0)
    277275  {
     
    296294  if (!is_admin())
    297295  {
    298     $user_where_clause = '   AND author_id = \''.$GLOBALS['user']['id'].'\'';
     296    $user_where_clause = ' AND author_id = \''.$GLOBALS['user']['id'].'\'';
    299297  }
    300298 
    301299  if (is_array($comment_id))
     300  {
    302301    $where_clause = 'id IN('.implode(',', $comment_id).')';
    303   else
     302  }
     303  else
     304  {
    304305    $where_clause = 'id = '.$comment_id;
     306  }
    305307   
    306308  $query = '
     
    315317{
    316318  if (is_array($comment_id))
     319  {
    317320    $where_clause = 'id IN('.implode(',', $comment_id).')';
    318   else
     321  }
     322  else
     323  {
    319324    $where_clause = 'id = '.$comment_id;
     325  }
    320326   
    321327  $query = '
  • extensions/GuestBook/include/guestbook.inc.php

    r24889 r26065  
    44global $user;
    55
    6 include(GUESTBOOK_PATH . '/include/functions.inc.php');
     6include(GUESTBOOK_PATH . 'include/functions.inc.php');
    77
    88$url_self = empty($page['start']) ? GUESTBOOK_URL : add_url_params(GUESTBOOK_URL, array('start' => $page['start']));
     
    106106// |                                add comment                            |
    107107// +-----------------------------------------------------------------------+
    108 if ( isset( $_POST['content'] ) && (!is_a_guest() || $conf['guestbook']['guest_can_add']))
     108if (isset($_POST['content']) && (!is_a_guest() || $conf['guestbook']['guest_can_add']))
    109109{
    110110  $comm = array(
    111     'author' => trim( @$_POST['author'] ),
    112     'email' => trim( @$_POST['email'] ),
    113     'content' => trim( $_POST['content'] ),
    114     'website' => trim( $_POST['website'] ),
     111    'author' => trim(@$_POST['author']),
     112    'email' => trim(@$_POST['email']),
     113    'content' => trim($_POST['content']),
     114    'website' => trim($_POST['website']),
    115115    'rate' => @$_POST['score'],
    116116   );
     
    123123  {
    124124    case 'moderate':
    125       array_push($page['infos'], l10n('An administrator must authorize your comment before it is visible.') );
     125      $page['infos'][] = l10n('An administrator must authorize your comment before it is visible.');
    126126    case 'validate':
    127       array_push($page['infos'], l10n('Your comment has been registered'));
     127      $page['infos'][] = l10n('Your comment has been registered');
    128128      break;
    129129    case 'reject':
    130130      set_status_header(403);
    131       array_push($page['errors'], l10n('Your comment has NOT been registered because it did not pass the validation rules') );
     131      $template->assign('GB_OPEN', true);
     132      $page['errors'][] = l10n('Your comment has NOT been registered because it did not pass the validation rules');
    132133      break;
    133134    default:
     
    136137
    137138  // allow plugins to notify what's going on
    138   trigger_action( 'user_comment_insertion',
    139       array_merge($comm, array('action'=>$comment_action) )
     139  trigger_action('user_comment_insertion',
     140      array_merge($comm, array('action'=>$comment_action))
    140141    );
    141142}
     
    145146// +-----------------------------------------------------------------------+
    146147$where_clauses = array('1=1');
    147 if ( !is_admin() )
    148 {
    149   array_push($where_clauses, 'validated = \'true\'');
     148if (!is_admin())
     149{
     150  $where_clauses[] = 'validated = \'true\'';
    150151}
    151152if (isset($_GET['comment_id']))
    152153{
    153   array_push($where_clauses, 'com.id = '.pwg_db_real_escape_string($_GET['comment_id']));
     154  $where_clauses[] = 'com.id = '.pwg_db_real_escape_string($_GET['comment_id']);
    154155}
    155156
     
    161162  WHERE '.implode(' AND ', $where_clauses).'
    162163;';
    163 $row = pwg_db_fetch_assoc( pwg_query( $query ) );
     164$row = pwg_db_fetch_assoc(pwg_query($query));
    164165
    165166// navigation bar creation
     
    178179  );
    179180
    180 $template->assign(
    181   array(
    182     'COMMENT_COUNT' => $row['nb_comments'],
    183     'navbar' => $navigation_bar,
    184     )
    185   );
     181$template->assign(array(
     182  'COMMENT_COUNT' => $row['nb_comments'],
     183  'navbar' => $navigation_bar,
     184  ));
    186185 
    187186if ($row['nb_comments'] > 0)
     
    223222    }
    224223
    225     $tpl_comment =
    226       array(
    227         'ID' => $row['id'],
    228         'AUTHOR' => trigger_event('render_comment_author', $author),
    229         'DATE' => format_date($row['date'], true),
    230         'CONTENT' => trigger_event('render_comment_content',$row['content']),
    231         'WEBSITE' => $row['website'],
     224    $tpl_comment = array(
     225      'ID' => $row['id'],
     226      'AUTHOR' => trigger_event('render_comment_author', $author),
     227      'DATE' => format_date($row['date'], true),
     228      'CONTENT' => trigger_event('render_comment_content', $row['content']),
     229      'WEBSITE' => $row['website'],
    232230      );
    233231     
     
    276274      {
    277275        $tpl_comment['U_VALIDATE'] = add_url_params(
    278                 $url_self,
    279                 array(
    280                   'action' => 'validate_comment',
    281                   'comment_to_validate' => $row['id'],
    282                   'pwg_token' => get_pwg_token(),
    283                   )
    284                 );
     276          $url_self,
     277          array(
     278            'action' => 'validate_comment',
     279            'comment_to_validate' => $row['id'],
     280            'pwg_token' => get_pwg_token(),
     281            )
     282          );
    285283      }
    286284    }
     
    316314
    317315  $template->assign('comment_add',
    318       array(
    319         'F_ACTION' => $url_self,
    320         'KEY' => get_ephemeral_key(3),
    321         'CONTENT' => $content,
    322         'IS_LOGGED' => is_classic_user(),
    323         'AUTHOR' => $author,
    324         'WEBSITE' => $website,
    325         'EMAIL' => $email,
    326         'ACTIVATE_RATING' => $conf['guestbook']['activate_rating'],
    327         'EMAIL_MANDATORY' => $conf['comments_email_mandatory'],
    328       ));
    329 }
    330 
    331 $template->assign('ABS_GUESTBOOK_PATH', realpath(GUESTBOOK_PATH) . '/');
    332 $template->assign('GUESTBOOK_PATH', GUESTBOOK_PATH);
    333 
    334 $template->set_filename('index', realpath(GUESTBOOK_PATH . 'template/guestbook.tpl'));
     316    array(
     317      'F_ACTION' => $url_self,
     318      'KEY' => get_ephemeral_key(3),
     319      'CONTENT' => $content,
     320      'IS_LOGGED' => is_classic_user(),
     321      'AUTHOR' => $author,
     322      'WEBSITE' => $website,
     323      'EMAIL' => $email,
     324      'ACTIVATE_RATING' => $conf['guestbook']['activate_rating'],
     325      'EMAIL_MANDATORY' => $conf['comments_email_mandatory'],
     326    ));
     327}
     328
     329$template->assign(array(
     330  'GUESTBOOK_PATH' => GUESTBOOK_PATH,
     331  'ABS_GUESTBOOK_PATH' => realpath(GUESTBOOK_PATH) . '/',
     332  ));
     333
     334$template->set_filename('guestbook', realpath(GUESTBOOK_PATH . 'template/guestbook.tpl'));
     335$template->assign_var_from_handle('CONTENT', 'guestbook');
  • extensions/GuestBook/main.inc.php

    r24889 r26065  
    99*/
    1010
    11 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     11defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
    1212
     13// TODO akismet
    1314global $prefixeTable;
    1415
    1516
    16 defined('GUESTBOOK_ID') or define('GUESTBOOK_ID', basename(dirname(__FILE__)));
     17define('GUESTBOOK_ID',      basename(dirname(__FILE__)));
    1718define('GUESTBOOK_PATH' ,   PHPWG_PLUGINS_PATH . GUESTBOOK_ID . '/');
    1819define('GUESTBOOK_TABLE' ,  $prefixeTable . 'guestbook');
     
    2627add_event_handler('init', 'guestbook_init');
    2728
    28 // admin page
    2929if (defined('IN_ADMIN'))
    3030{
     
    3232}
    3333
    34 // menu entry
    3534add_event_handler('blockmanager_apply', 'gb_menubar_apply', EVENT_HANDLER_PRIORITY_NEUTRAL+10);
    3635
    37 // guestbook section
    3836add_event_handler('loc_end_section_init', 'gb_section_init');
    3937add_event_handler('loc_end_index', 'gb_index');
    40 
    41 // stuff
    42 // add_event_handler('get_stuffs_modules', 'gb_register_stuffs_module')
    4338
    4439
    4540function guestbook_init()
    4641{
    47   global $conf, $pwg_loaded_plugins;
     42  global $conf;
    4843 
    49   // apply upgrade if needed
    50   if (
    51     GUESTBOOK_VERSION == 'auto' or
    52     $pwg_loaded_plugins[GUESTBOOK_ID]['version'] == 'auto' or
    53     version_compare($pwg_loaded_plugins[GUESTBOOK_ID]['version'], GUESTBOOK_VERSION, '<')
    54   )
    55   {
    56     // call install function
    57     include_once(GUESTBOOK_PATH . 'include/install.inc.php');
    58     guestbook_install();
    59    
    60     // update plugin version in database
    61     if ( $pwg_loaded_plugins[GUESTBOOK_ID]['version'] != 'auto' and GUESTBOOK_VERSION != 'auto' )
    62     {
    63       $query = '
    64 UPDATE '. PLUGINS_TABLE .'
    65 SET version = "'. GUESTBOOK_VERSION .'"
    66 WHERE id = "'. GUESTBOOK_ID .'"';
    67       pwg_query($query);
    68      
    69       $pwg_loaded_plugins[GUESTBOOK_ID]['version'] = GUESTBOOK_VERSION;
    70      
    71       if (defined('IN_ADMIN'))
    72       {
    73         $_SESSION['page_infos'][] = 'GuestBook updated to version '. GUESTBOOK_VERSION;
    74       }
    75     }
    76   }
     44  include_once(GUESTBOOK_PATH . 'maintain.inc.php');
     45  $maintain = new GuestBook_maintain(GUESTBOOK_ID);
     46  $maintain->autoUpdate(GUESTBOOK_VERSION, 'install');
    7747 
    78   // load plugin language file
    7948  load_language('plugin.lang', GUESTBOOK_PATH);
    8049 
    81   // prepare plugin configuration
    8250  $conf['guestbook'] = unserialize($conf['guestbook']);
    8351}
  • extensions/GuestBook/maintain.inc.php

    r24890 r26065  
    11<?php
    2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
    33
    4 defined('GUESTBOOK_ID') or define('GUESTBOOK_ID', basename(dirname(__FILE__)));
    5 include_once(PHPWG_PLUGINS_PATH . GUESTBOOK_ID . '/include/install.inc.php');
     4class GuestBook_maintain extends PluginMaintain
     5{
     6  private $installed = false;
     7 
     8  private $default_conf = array(
     9    'comments_validation' => false,
     10    'email_admin_on_comment' => false,
     11    'email_admin_on_comment_validation' => true,
     12    'nb_comment_page' => 15,
     13    'activate_rating' => true,
     14    'guest_can_view' => true,
     15    'guest_can_add' => true,
     16    );
    617
    7 // Installation
    8 function plugin_install()
    9 {
    10   guestbook_install();
    11   define('guestbook_installed', true);
    12 }
     18  function install($plugin_version, &$errors=array())
     19  {
     20    global $conf, $prefixeTable;
     21 
     22    if (empty($conf['guestbook']))
     23    {
     24      $conf['guestbook'] = serialize($this->default_conf);
     25      conf_update_param('guestbook', $conf['guestbook']);
     26    }
     27    else
     28    {
     29      $old_conf = is_string($conf['guestbook']) ? unserialize($conf['guestbook']) : $conf['guestbook'];
     30     
     31      if (!isset($old_conf['guest_can_view']))
     32      {
     33        $old_conf['guest_can_view'] = true;
     34        $old_conf['guest_can_add'] = true;
     35      }
     36     
     37      $conf['guestbook'] = serialize($old_conf);
     38      conf_update_param('guestbook', $conf['guestbook']);
     39    }
     40 
     41    pwg_query('
     42CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'guestbook` (
     43  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
     44  `date` datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
     45  `author` varchar(255) NOT NULL,
     46  `author_id` smallint(5) DEFAULT NULL,
     47  `anonymous_id` varchar(45) NOT NULL,
     48  `email` varchar(255) DEFAULT NULL,
     49  `website` varchar(255) DEFAULT NULL,
     50  `content` longtext NOT NULL,
     51  `rate` float(5,2) unsigned DEFAULT NULL,
     52  `validated` enum("true","false") NOT NULL DEFAULT "false",
     53  `validation_date` datetime DEFAULT NULL,
     54  PRIMARY KEY (`id`)
     55) ENGINE=MyISAM DEFAULT CHARSET=utf8
     56;');
    1357
    14 // Activation
    15 function plugin_activate()
    16 {
    17   if (!defined('guestbook_installed'))
     58    $this->installed = true;
     59  }
     60
     61  function activate($plugin_version, &$errors=array())
    1862  {
    19     guestbook_install();
     63    if (!$this->installed)
     64    {
     65      $this->install($plugin_version, $errors);
     66    }
     67  }
     68
     69  function deactivate()
     70  {
     71  }
     72
     73  function uninstall()
     74  {
     75    global $prefixeTable;
     76 
     77    pwg_query('DROP TABLE `' . $prefixeTable . 'guestbook`;');
     78
     79    conf_delete_param('guestbook');
    2080  }
    2181}
    22 
    23 // Uninstallation
    24 function plugin_uninstall()
    25 {
    26   guestbook_uninstall();
    27 }
  • extensions/GuestBook/template/comment_list.tpl

    r20181 r26065  
    66    <div class="actions" style="float:right;font-size:90%">
    77    {if isset($comment.U_DELETE)}
    8       <a href="{$comment.U_DELETE}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');">
    9         {'Delete'|@translate}
     8      <a href="{$comment.U_DELETE}" onclick="return confirm('{'Are you sure?'|translate|@escape:javascript}');">
     9        {'Delete'|translate}
    1010      </a>{if isset($comment.U_VALIDATE) or isset($comment.U_EDIT) or isset($comment.U_CANCEL)} | {/if}
    1111    {/if}
    1212    {if isset($comment.U_CANCEL)}
    1313      <a href="{$comment.U_CANCEL}">
    14         {'Cancel'|@translate}
     14        {'Cancel'|translate}
    1515      </a>{if isset($comment.U_VALIDATE)} | {/if}
    1616    {/if}
    1717    {if isset($comment.U_EDIT) and !isset($comment.IN_EDIT)}
    1818      <a class="editComment" href="{$comment.U_EDIT}#edit_comment">
    19         {'Edit'|@translate}
     19        {'Edit'|translate}
    2020      </a>{if isset($comment.U_VALIDATE)} | {/if}
    2121    {/if}
    2222    {if isset($comment.U_VALIDATE)}
    2323      <a href="{$comment.U_VALIDATE}">
    24         {'Validate'|@translate}
     24        {'Validate'|translate}
    2525      </a>
    2626    {/if}&nbsp;
     
    3737
    3838    <div class="commentHeader">
    39       {'%s says on %s :'|@translate|@sprintf:$author:$date}<br>
     39      {'%s says on %s :'|translate:$author:$date}<br>
    4040      {if $comment.STARS}{$comment.STARS}{/if}
    4141      {if $comment.EMAIL} <a href="mailto:{$comment.EMAIL}">{$comment.EMAIL}</a>{/if}
     
    4444    <a name="edit_comment"></a>
    4545    <form method="post" action="{$comment.U_EDIT}" id="editComment">
    46       <p><label>{'Edit a comment'|@translate} :</label></p>
     46      <p><label>{'Edit a comment'|translate} :</label></p>
    4747      <p><textarea name="content" id="contenteditid" rows="5" cols="80">{$comment.CONTENT|@escape}</textarea></p>
    4848      <p><input type="hidden" name="key" value="{$comment.KEY}">
    4949        <input type="hidden" name="pwg_token" value="{$comment.PWG_TOKEN}">
    5050        <input type="hidden" name="image_id" value="{$comment.IMAGE_ID|@default:$current.id}">
    51         <input type="submit" value="{'Submit'|@translate}">
     51        <input type="submit" value="{'Submit'|translate}">
    5252      </p>
    5353    </form>
  • extensions/GuestBook/template/guestbook.tpl

    r25786 r26065  
    1 {combine_css path=$GUESTBOOK_PATH|@cat:"template/style.css"}
    2 {combine_script id="livevalidation" load="footer" path=$GUESTBOOK_PATH|@cat:"template/livevalidation.min.js"}
     1{combine_css path=$GUESTBOOK_PATH|cat:'template/style.css'}
     2{combine_script id='livevalidation' load='footer' path=$GUESTBOOK_PATH|cat:'template/livevalidation.min.js'}
    33
    44{footer_script require='jquery,livevalidation'}
    5 {if !$comment_add.IS_LOGGED}
    6 var author = new LiveValidation('author', {ldelim} onlyOnSubmit: true });
    7 author.add(Validate.Presence, {ldelim} failureMessage: "{'Please enter your username'|@translate}" });
    8 {/if}
     5(function() {
     6  {if !$comment_add.IS_LOGGED}
     7  var author = new LiveValidation('author', {ldelim} onlyOnSubmit: true });
     8  author.add(Validate.Presence, {ldelim} failureMessage: "{'Please enter your username'|translate}" });
     9  {/if}
    910
    10 {if $comment_add.EMAIL_MANDATORY and (!$comment_add.IS_LOGGED or empty($comment_add.EMAIL))}
    11 var email = new LiveValidation('email', {ldelim} onlyOnSubmit: true });
    12 email.add(Validate.Presence, {ldelim} failureMessage: "{'Please enter your e-mail'|@translate}" });
    13 email.add(Validate.Email, {ldelim} failureMessage: "{'mail address must be like xxx@yyy.eee (example : jack@altern.org)'|@translate}" });
    14 {/if}
     11  {if $comment_add.EMAIL_MANDATORY and (!$comment_add.IS_LOGGED or empty($comment_add.EMAIL))}
     12  var email = new LiveValidation('email', {ldelim} onlyOnSubmit: true });
     13  email.add(Validate.Presence, {ldelim} failureMessage: "{'Please enter your e-mail'|translate}" });
     14  email.add(Validate.Email, {ldelim} failureMessage: "{'mail address must be like xxx@yyy.eee (example : jack@altern.org)'|translate}" });
     15  {/if}
    1516
    16 var website = new LiveValidation('website', {ldelim} onlyOnSubmit: true });
    17 website.add(Validate.Format, {ldelim} pattern: /^https?:\/\/[^\s\/$.?#].[^\s]*$/i,
    18   failureMessage: "{'invalid website address'|@translate}"});
     17  var website = new LiveValidation('website', {ldelim} onlyOnSubmit: true });
     18  website.add(Validate.Format, {ldelim} pattern: /^https?:\/\/[^\s\/$.?#].[^\s]*$/i,
     19    failureMessage: "{'invalid website address'|translate}"});
    1920
    20 var content = new LiveValidation('contentid', {ldelim} onlyOnSubmit: true });
    21 content.add(Validate.Presence, {ldelim} failureMessage: "{'Please enter a message'|@translate}" });
     21  var content = new LiveValidation('contentid', {ldelim} onlyOnSubmit: true });
     22  content.add(Validate.Presence, {ldelim} failureMessage: "{'Please enter a message'|translate}" });
    2223 
    23 jQuery("#addComment").hide();
    24 jQuery("#guestbookAdd").css('width','180px');
    25 jQuery("#expandForm").click(function() {ldelim}
    26   jQuery("#guestbookAdd").animate({ldelim}"width": "550px"}, function() {ldelim}
    27     jQuery("#expandForm").slideUp();
    28     jQuery("#addComment").slideDown("slow");
     24  {if !isset($GB_OPEN)}
     25  jQuery('#addComment').hide();
     26  jQuery('#guestbookAdd').css('width', '180px');
     27  jQuery('#expandForm').click(function() {ldelim}
     28    jQuery('#guestbookAdd').animate({ldelim}'width': '550px'}, function() {ldelim}
     29      jQuery('#expandForm').slideUp();
     30      jQuery('#addComment').slideDown('slow');
     31    });
    2932  });
    30 });
     33  {/if}
    3134
    32 jQuery("#website").on('blur', function() {ldelim}
    33   var val = $(this).val();
    34   if (val.substr(0, 4) != 'http') {ldelim}
    35     $(this).val('http://'+ val);
    36   }
    37 });
     35  jQuery('#website').on('blur', function() {ldelim}
     36    var val = $(this).val();
     37    if (val.substr(0, 4) != 'http') {ldelim}
     38      $(this).val('http://'+ val);
     39    }
     40  });
     41}());
    3842{/footer_script}
    3943
    4044{if $comment_add.ACTIVATE_RATING}
    41   {combine_script id="jquery.raty" path=$GUESTBOOK_PATH|@cat:"template/jquery.raty/jquery.raty.min.js"}
     45  {combine_script id='jquery.raty' path=$GUESTBOOK_PATH|cat:'template/jquery.raty/jquery.raty.min.js'}
    4246  {footer_script}
    43   jQuery("#comment_rate").raty({ldelim}
    44     path: "{$ROOT_URL}{$GUESTBOOK_PATH}template/jquery.raty/",
     47  jQuery('#comment_rate').raty({ldelim}
     48    path: '{$ROOT_URL}{$GUESTBOOK_PATH}template/jquery.raty/',
    4549    half: true
    4650  });
     
    4953
    5054
    51 {* <!-- Menubar & titrePage --> *}
    52 {if $themeconf.name == "stripped" or $themeconf.parent == "stripped"}
    53   {include file=$ABS_GUESTBOOK_PATH|@cat:'template/themes/stripped.tpl'}
    54   {assign var="clear" value="true"}
    55 {elseif $themeconf.name == "simple-grey" or $themeconf.parent == "simple"}
    56   {include file=$ABS_GUESTBOOK_PATH|@cat:'template/themes/simple.tpl'}
    57   {assign var="clear" value="true"}
    58 {else}
    59   {include file=$ABS_GUESTBOOK_PATH|@cat:'template/themes/default.tpl'}
    60 {/if}
    61 
    62 {if isset($errors) or not empty($infos)}
    63 {include file='infos_errors.tpl'}
    64 {/if}
    65 
    66 
    6755{if isset($comment_add)}
    6856<div id="guestbookAdd">
    69   <h4 id="expandForm">{'Sign the guestbook'|@translate}</h4>
     57  <h4 id="expandForm">{'Sign the guestbook'|translate}</h4>
    7058  <form method="post" action="{$comment_add.F_ACTION}" id="addComment" class="contact">
    7159    <table>
     
    7361      <tr>
    7462        <td>
    75           <label for="author">{'Author'|@translate}* :</label>
     63          <label for="author">{'Author'|translate}* :</label>
    7664        {if $comment_add.IS_LOGGED}
    7765          {$comment_add.AUTHOR}
     
    8270        </td>
    8371        <td>
    84           <label for="email">{'Email address'|@translate}{if $comment_add.EMAIL_MANDATORY}*{/if} ({'not publicly visible'|@translate}) :</label>
     72          <label for="email">{'Email address'|translate}{if $comment_add.EMAIL_MANDATORY}*{/if} ({'not publicly visible'|translate}) :</label>
    8573          <input type="text" name="email" id="email" value="{$comment_add.EMAIL}">
    8674        </td>
     
    9078      {if $comment_add.ACTIVATE_RATING}
    9179        <td>
    92           <label>{'Rate'|@translate} :</label>
     80          <label>{'Rate'|translate} :</label>
    9381          <span id="comment_rate"></span>
    9482        </td>
    9583      {/if}
    9684        <td>
    97           <label for="website">{'Website'|@translate} :</label>
     85          <label for="website">{'Website'|translate} :</label>
    9886          <input type="text" name="website" id="website" value="{$comment_add.WEBSITE}">
    9987        </td>
     
    10189      <tr>
    10290        <td colspan="2">
    103           <label for="contentid">{'Comment'|@translate}* :</label>
     91          <label for="contentid">{'Comment'|translate}* :</label>
    10492          <textarea name="content" id="contentid" rows="7">{$comment_add.CONTENT}</textarea>
    10593        </td>
     
    10795      <tr>
    10896        <td colspan="2">
    109           <input type="submit" value="{'Send'|@translate}">
    110           {'* : mandatory fields'|@translate}
     97          <input type="submit" value="{'Send'|translate}">
     98          {'* : mandatory fields'|translate}
    11199        </td>
    112100      </tr>
     
    118106{/if}
    119107
    120 <p class="comment_count">{'There are %d messages'|@translate|@sprintf:$COMMENT_COUNT}</p>
     108<p class="comment_count">{'There are %d messages'|translate:$COMMENT_COUNT}</p>
    121109
    122110{if isset($comments)}
     
    124112  {if !empty($navbar)}
    125113    <div id="pictureCommentNavBar">
    126       {include file='navigation_bar.tpl'|@get_extent:'navbar'}
     114      {include file='navigation_bar.tpl'|get_extent:'navbar'}
    127115    </div>
    128116  {/if}
    129   {include file=$ABS_GUESTBOOK_PATH|@cat:'template/comment_list.tpl'}
     117  {include file=$ABS_GUESTBOOK_PATH|cat:'template/comment_list.tpl'}
    130118</div>
    131119{/if}
    132 
    133 {if $clear}<div style="clear: both;"></div>
    134 </div>{/if}
    135 </div>{* <!-- content --> *}
Note: See TracChangeset for help on using the changeset viewer.