Ignore:
Timestamp:
Jun 7, 2011, 9:44:37 PM (13 years ago)
Author:
mistic100
Message:

big code cleaning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Comments_on_Albums/include/coa_admin_comments.php

    r10984 r11267  
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    44
     5global $template, $conf;
    56load_language('plugin.lang', COA_PATH);
    67
    78// +-----------------------------------------------------------------------+
    8 //        Tabsheet
     9// |                               tabsheet                                |
    910// +-----------------------------------------------------------------------+
    1011include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
     
    1415    'code' => 'pictures',
    1516    'label' => l10n('COA_comments_photos'),
    16   ),
     17    ),
    1718  array(
    1819    'code' => 'albums',
    1920    'label' => l10n('COA_comments_albums'),
    20   ),
    21 );
     21    ),
     22  );
    2223
    2324$tab_codes = array_map(create_function('$a', 'return $a["code"];'), $tabs);
    2425
    25 if (isset($_GET['section']) and in_array($_GET['section'], $tab_codes)) {
     26if (isset($_GET['section']) and in_array($_GET['section'], $tab_codes))
     27{
    2628  $page['tab'] = $_GET['section'];
    27 } else {
     29}
     30else
     31{
    2832  $page['tab'] = $tabs[0]['code'];
    2933}
    3034
    3135$tabsheet = new tabsheet();
    32 foreach ($tabs as $tab) {
     36foreach ($tabs as $tab)
     37{
    3338  $tabsheet->add(
    3439    $tab['code'],
    3540    $tab['label'],
    3641    get_root_url().'admin.php?page=comments&section='.$tab['code']
    37   );
     42    );
    3843}
    3944$tabsheet->select($page['tab']);
     
    4146
    4247
    43 if ($page['tab'] == 'albums') {
     48if ($page['tab'] == 'albums')
     49{
     50  // clear template sended by original page
    4451  $template->clear_assign(array('ADMIN_CONTENT', 'comments', 'LIST', 'F_ACTION'));
    4552
    4653  // +-----------------------------------------------------------------------+
    47   //        Actions
     54  // |                                actions                                |
    4855  // +-----------------------------------------------------------------------+
    49   if (!empty($_POST)) {
    50     if (!empty($_POST['comments'])) {
     56  if (!empty($_POST))
     57  {
     58    if (empty($_POST['comments']))
     59    {
     60      array_push(
     61        $page['errors'],
     62        l10n('Select at least one comment')
     63        );
     64    }
     65    else
     66    {
    5167      check_input_parameter('comments', $_POST, true, PATTERN_ID);
    5268
    53       if (isset($_POST['validate_albums'])) {
    54         $query = 'UPDATE '.COA_TABLE.' SET
    55             validated = \'true\',
    56             validation_date = NOW()
    57           WHERE id IN ('.implode(',', $_POST['comments']).')
    58         ;';
     69      if (isset($_POST['validate_albums']))
     70      {
     71        $query = '
     72UPDATE '.COA_TABLE.'
     73  SET validated = \'true\',
     74      validation_date = NOW()
     75  WHERE id IN ('.implode(',', $_POST['comments']).')
     76;';
    5977        pwg_query($query);
    6078
    61         array_push($page['infos'], l10n_dec(
    62           '%d user comment validated', '%d user comments validated',
    63           count($_POST['comments'])
    64         ));
     79        array_push(
     80          $page['infos'],
     81          l10n_dec(
     82            '%d user comment validated', '%d user comments validated',
     83            count($_POST['comments'])
     84            )
     85          );
    6586      }
    6687
    67       if (isset($_POST['reject_albums'])) {
    68         $query = 'DELETE FROM '.COA_TABLE.'
    69           WHERE id IN ('.implode(',', $_POST['comments']).')
    70         ;';
     88      if (isset($_POST['reject_albums']))
     89      {
     90        $query = '
     91DELETE
     92  FROM '.COA_TABLE.'
     93  WHERE id IN ('.implode(',', $_POST['comments']).')
     94;';
    7195        pwg_query($query);
    7296
    73         array_push($page['infos'], l10n_dec(
    74           '%d user comment rejected', '%d user comments rejected',
    75           count($_POST['comments'])
    76         ));
     97        array_push(
     98          $page['infos'],
     99          l10n_dec(
     100            '%d user comment rejected', '%d user comments rejected',
     101            count($_POST['comments'])
     102            )
     103          );
    77104      }
    78105    }
     
    80107
    81108  // +-----------------------------------------------------------------------+
    82   //        Infos (re-assignation needed)
     109  // |                             template init                             |
    83110  // +-----------------------------------------------------------------------+
    84   if (count($page['infos']) != 0) {
     111
     112  $template->set_filename('comments', dirname(__FILE__) .'/../template/admin_comments.tpl');
     113
     114  $template->assign(
     115    array(
     116      'F_ACTION' => get_root_url().'admin.php?page=comments&section=albums'
     117      )
     118    );
     119   
     120  if (count($page['infos']) != 0)
     121  {
    85122    $template->assign('infos', $page['infos']);
    86123  }
    87124
    88125  // +-----------------------------------------------------------------------+
    89   //        Comments display
     126  // |                           comments display                            |
    90127  // +-----------------------------------------------------------------------+
    91128  $list = array();
    92129
    93   $query = 'SELECT
    94       com.id,
    95       com.category_id,
    96       com.date,
    97       com.author,
    98       '.$conf['user_fields']['username'].' AS username,
    99       com.content,
    100       cat.name
    101     FROM '.COA_TABLE.' AS com
     130  $query = '
     131SELECT
     132    com.id,
     133    com.category_id,
     134    com.date,
     135    com.author,
     136    '.$conf['user_fields']['username'].' AS username,
     137    com.content,
     138    cat.name
     139  FROM '.COA_TABLE.' AS com
    102140    INNER JOIN '.CATEGORIES_TABLE.' AS cat
    103     ON cat.id = com.category_id
     141      ON cat.id = com.category_id
    104142    LEFT JOIN '.USERS_TABLE.' AS u
    105     ON u.'.$conf['user_fields']['id'].' = com.author_id
    106     WHERE validated = \'false\'
    107     ORDER BY com.date DESC
    108   ;';
     143      ON u.'.$conf['user_fields']['id'].' = com.author_id
     144  WHERE validated = \'false\'
     145  ORDER BY com.date DESC
     146;';
    109147  $result = pwg_query($query);
    110148
    111   while ($row = pwg_db_fetch_assoc($result)) {
     149  while ($row = pwg_db_fetch_assoc($result))
     150  {
    112151    // author
    113     if (empty($row['author_id'])) {
     152    if (empty($row['author_id']))
     153    {
    114154      $author_name = $row['author'];
    115     } else {
     155    }
     156    else
     157    {
    116158      $author_name = stripslashes($row['username']);
    117159    }
    118160   
    119161    // comment content
    120     $template->append('comments', array(
    121       'CAT_URL' => PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id='.$row['category_id'],
    122       'CAT_NAME' => $row['name'],
    123       'ID' => $row['id'],
    124       'AUTHOR' => trigger_event('render_comment_author', $author_name),
    125       'DATE' => format_date($row['date'], true),
    126       'CONTENT' => trigger_event('render_comment_content',$row['content']),
    127     ));
     162    $template->append(
     163      'comments',
     164      array(
     165        'CAT_URL' => PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id='.$row['category_id'],
     166        'CAT_NAME' => $row['name'],
     167        'ID' => $row['id'],
     168        'AUTHOR' => trigger_event('render_comment_author', $author_name),
     169        'DATE' => format_date($row['date'], true),
     170        'CONTENT' => trigger_event('render_comment_content',$row['content']),
     171        )
     172      );
    128173
    129174    array_push($list, $row['id']);
    130175  }
    131176
    132   // template
    133   $template->set_filename('comments', dirname(__FILE__) .'/../template/coa_admin_comments.tpl');
    134   $template->assign(array(
    135     'F_ACTION' => get_root_url().'admin.php?page=comments&section=albums',
    136     'LIST' => implode(',', $list),
    137   ));
     177  $template->assign('LIST', implode(',', $list));
     178
     179  // +-----------------------------------------------------------------------+
     180  // |                           sending html code                           |
     181  // +-----------------------------------------------------------------------+
     182
    138183  $template->assign_var_from_handle('ADMIN_CONTENT', 'comments');
     184
    139185}
    140186
Note: See TracChangeset for help on using the changeset viewer.