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_comments_page.php

    r11251 r11267  
    11<?php
    2 /* inspired by include/comments.php */
     2/* inspired by comments.php */
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    44
     
    66$conf['comments_on_albums'] = unserialize($conf['comments_on_albums']);
    77
    8 $template->assign(array(
    9   'COA_PATH' => COA_PATH,
    10   'ICON_COLOR' => $conf['comments_on_albums']['icon_color'],
    11   'ICON_COLOR_OVER' => $conf['comments_on_albums']['icon_color_over'],
    12 ));
     8$template->assign(
     9  array(
     10    'COA_PATH' => COA_PATH,
     11    'ICON_COLOR' => $conf['comments_on_albums']['icon_color'],
     12    'ICON_COLOR_OVER' => $conf['comments_on_albums']['icon_color_over'],
     13    )
     14  );
    1315
    1416
    1517// +-----------------------------------------------------------------------+
    16 //        Main page (comments on photos)
     18// |                             main page                                 |
    1719// +-----------------------------------------------------------------------+
    1820
    19 if (!isset($_GET['display_mode'])) { 
     21if (!isset($_GET['display_mode']))
     22
    2023  // adds a button for switch page
    2124  $template->set_prefilter('comments', 'coa_add_button');
    22   function coa_add_button($content, &$smarty) {
     25 
     26  function coa_add_button($content, &$smarty)
     27  {
    2328    $search = '<ul class="categoryActions">';
    2429
     
    3742{/html_head}
    3843
    39   <ul class="categoryActions">
     44  '.$search.'
    4045    <li><a href="comments.php?display_mode=albums" title="' . l10n('COA_comments_albums') . '" class="pwg-state-default pwg-button">
    4146      <span class="pwg-icon pwg-icon-comments-albums">&nbsp;</span><span class="pwg-button-text">' . l10n('COA_comments_albums') . '</span>
     
    4752 
    4853// +-----------------------------------------------------------------------+
    49 //        Second page (comments on albums)
     54//                        comments on albums page                          |
    5055// +-----------------------------------------------------------------------+
    5156
    52 } else if ($_GET['display_mode'] == 'albums') {
     57}
     58else if ($_GET['display_mode'] == 'albums')
     59{
    5360  // reset some template vars
    5461  $template->clear_assign(array('comments', 'navbar', 'sort_by_options'));
     
    5865    'date' => l10n('comment date'),
    5966    'category_id' => l10n('album')
    60   );
     67    );
    6168  $template->assign('sort_by_options', $sort_by);
    6269
     
    6875
    6976  $actions = array('delete_albums', 'validate_albums', 'edit_albums'); // different indexes to not interfer with the main process
    70   foreach ($actions as $loop_action) {
    71     if (isset($_GET[$loop_action])) {
     77  foreach ($actions as $loop_action)
     78  {
     79    if (isset($_GET[$loop_action]))
     80    {
    7281      $action = $loop_action;
    7382      check_input_parameter($action, $_GET, false, PATTERN_ID);
     
    7786  }
    7887
    79   if (isset($action)) {
     88  if (isset($action))
     89  {
    8090    include_once(COA_PATH.'include/functions_comment.inc.php');
     91   
    8192    check_pwg_token();
     93   
    8294    $comment_author_id = get_comment_author_id_albums($comment_id);
     95   
    8396    $true_action = str_replace('_albums', null, $action); // but we must check true action names
    8497
    85     if (can_manage_comment($true_action, $comment_author_id)) {
     98    if (can_manage_comment($true_action, $comment_author_id))
     99    {
    86100      $perform_redirect = false;
    87101
    88       if ('delete_albums' == $action) {
     102      if ('delete_albums' == $action)
     103      {
    89104        delete_user_comment_albums($comment_id);
    90105        $perform_redirect = true;
    91106      }
    92       if ('validate_albums' == $action) {
     107      if ('validate_albums' == $action)
     108      {
    93109        validate_user_comment_albums($comment_id);
    94110        $perform_redirect = true;
    95111      }
    96       if ('edit_albums' == $action) {
    97         if (!empty($_POST['content'])) {
    98           update_user_comment_albums(array(
    99             'comment_id' => $_GET['edit_albums'],
    100             'image_id' => $_POST['image_id'],
    101             'content' => $_POST['content']
    102             ), $_POST['key']
    103           );
    104           $perform_redirect = true;
    105         } else {
     112      if ('edit_albums' == $action)
     113      {
     114        if (!empty($_POST['content']))
     115        {
     116          update_user_comment_albums(
     117            array(
     118              'comment_id' => $_GET['edit_albums'],
     119              'image_id' => $_POST['image_id'],
     120              'content' => $_POST['content']
     121              ),
     122            $_POST['key']
     123            );
     124          //$perform_redirect = true;
     125          $edit_comment = null;
     126        }
     127        else
     128        {
    106129          $edit_comment = $_GET['edit_albums'];
    107130        }
    108131      }
    109       if ($perform_redirect) {
    110         $redirect_url = PHPWG_ROOT_PATH.'comments.php'.get_query_string_diff(array('delete_albums','validate_albums','edit_albums','pwg_token'));
     132      if ($perform_redirect)
     133      {
     134        $redirect_url =
     135          PHPWG_ROOT_PATH
     136          .'comments.php'
     137          .get_query_string_diff(array('delete_albums','validate_albums','edit_albums','pwg_token'));
     138       
    111139        redirect($redirect_url);
    112140      }
     
    117145  // |                            navigation bar                             |
    118146  // +-----------------------------------------------------------------------+
    119   if (isset($_GET['start']) and is_numeric($_GET['start'])) {
     147  if (isset($_GET['start']) and is_numeric($_GET['start']))
     148  {
    120149    $start = $_GET['start'];
    121   } else {
     150  }
     151  else
     152  {
    122153    $start = 0;
    123154  }
    124155
    125   $query = 'SELECT COUNT(DISTINCT(com.id))
    126     FROM '.COA_TABLE.' AS com
    127     LEFT JOIN '.USERS_TABLE.' As u
     156  $query = '
     157SELECT
     158    COUNT(DISTINCT(com.id))
     159  FROM '.COA_TABLE.' AS com
     160  LEFT JOIN '.USERS_TABLE.' As u
    128161    ON u.'.$conf['user_fields']['id'].' = com.author_id
    129     WHERE '.implode('
     162  WHERE '.implode('
    130163    AND ', $page['where_clauses']).'
    131   ;';
     164;';
    132165  list($counter) = pwg_db_fetch_row(pwg_query($query));
    133166
    134   $url = PHPWG_ROOT_PATH . 'comments.php' . get_query_string_diff(array('start','delete_albums','validate_albums','edit_albums','pwg_token'));
    135   $navbar = create_navigation_bar($url, $counter, $start, $page['items_number'], '');
     167  $url =
     168    PHPWG_ROOT_PATH
     169    .'comments.php'
     170    .get_query_string_diff(array('start','delete_albums','validate_albums','edit_albums','pwg_token'));
     171   
     172  $navbar = create_navigation_bar(
     173    $url,
     174    $counter,
     175    $start,
     176    $page['items_number'],
     177    ''
     178    );
    136179  $template->assign('navbar', $navbar);
    137180
     
    143186  $category_ids = array();
    144187
    145   $query = 'SELECT
    146       com.id AS comment_id,
    147       com.category_id,
    148       com.author,
    149       com.author_id,
    150       '.$conf['user_fields']['username'].' AS username,
    151       com.date,
    152       com.content,
    153       com.validated
    154     FROM '.COA_TABLE.' AS com
    155     LEFT JOIN '.USERS_TABLE.' As u
     188  $query = '
     189SELECT
     190    com.id AS comment_id,
     191    com.category_id,
     192    com.author,
     193    com.author_id,
     194    '.$conf['user_fields']['username'].' AS username,
     195    com.date,
     196    com.content,
     197    com.validated
     198  FROM '.COA_TABLE.' AS com
     199  LEFT JOIN '.USERS_TABLE.' As u
    156200    ON u.'.$conf['user_fields']['id'].' = com.author_id
    157     WHERE '.implode('
     201  WHERE '.implode('
    158202    AND ', $page['where_clauses']).'
    159     GROUP BY
    160       comment_id,
    161       com.category_id,
    162       com.author,
    163       com.author_id,
    164       com.date,
    165       com.content,
    166       com.validated
    167     ORDER BY '.$page['sort_by'].' '.$page['sort_order'];
    168     if ('all' != $page['items_number']) {
    169       $query.= '
    170       LIMIT '.$page['items_number'].' OFFSET '.$start;
    171     }
     203  GROUP BY
     204    comment_id,
     205    com.category_id,
     206    com.author,
     207    com.author_id,
     208    com.date,
     209    com.content,
     210    com.validated
     211  ORDER BY '.$page['sort_by'].' '.$page['sort_order'];
     212  if ('all' != $page['items_number'])
     213  {
    172214    $query.= '
    173   ;';
     215  LIMIT '.$page['items_number'].' OFFSET '.$start;
     216  }
     217  $query.= '
     218;';
    174219  $result = pwg_query($query);
    175220
    176   while ($row = pwg_db_fetch_assoc($result)) {
     221  while ($row = pwg_db_fetch_assoc($result))
     222  {
    177223    array_push($comments, $row);
    178224    array_push($element_ids, $row['category_id']);
    179225  }
    180226
    181   if (count($comments) > 0) {
     227  if (count($comments) > 0)
     228  {
    182229    // retrieving category informations
    183     $query = 'SELECT
    184         cat.id,
    185         cat.name,
    186         cat.permalink,
    187         cat.uppercats,
    188         com.id as comment_id
    189       FROM '.CATEGORIES_TABLE.' AS cat
    190       LEFT JOIN '.COA_TABLE.' AS com
    191       ON cat.id=com.category_id
    192       '.get_sql_condition_FandF(array(
    193         'forbidden_categories' => 'cat.id',
    194         'visible_categories' => 'cat.id'
    195       ), 'WHERE').'
    196       AND cat.id IN ('.implode(',', $element_ids).')
    197     ;';
     230    $query = '
     231SELECT
     232    cat.id,
     233    cat.name,
     234    cat.permalink,
     235    cat.uppercats,
     236    com.id as comment_id
     237  FROM '.CATEGORIES_TABLE.' AS cat
     238  LEFT JOIN '.COA_TABLE.' AS com
     239    ON cat.id=com.category_id
     240  '.get_sql_condition_FandF(
     241    array(
     242      'forbidden_categories' => 'cat.id',
     243      'visible_categories' => 'cat.id'
     244      ),
     245    'WHERE'
     246    ).'
     247    AND cat.id IN ('.implode(',', $element_ids).')
     248;';
    198249    $categories = hash_from_query($query, 'comment_id');
    199250
    200     foreach ($comments as $comment) {
     251    foreach ($comments as $comment)
     252    {
    201253      // category
    202254      $name = $categories[$comment['comment_id']]['name'];
    203       $url = duplicate_index_url(array(
    204         'category' => array(
    205           'id' => $categories[$comment['comment_id']]['id'],
    206           'name' => $categories[$comment['comment_id']]['name'],
    207           'permalink' => $categories[$comment['comment_id']]['permalink'],
    208         ),array('start')
    209       ));
     255      $url = duplicate_index_url(
     256        array(
     257          'category' => array(
     258            'id' => $categories[$comment['comment_id']]['id'],
     259            'name' => $categories[$comment['comment_id']]['name'],
     260            'permalink' => $categories[$comment['comment_id']]['permalink'],
     261            ),
     262          array('start')
     263          )
     264        );
    210265     
    211266      // comment content
     
    217272        'DATE' => format_date($comment['date'], true),
    218273        'CONTENT' => trigger_event('render_comment_content',$comment['content']),
    219       );
     274        );
    220275
    221276      // rights
    222       if (can_manage_comment('delete', $comment['author_id'])) {
    223         $url = get_root_url().'comments.php'.get_query_string_diff(array('delete','validate','edit', 'pwg_token'));
    224 
    225         $tpl_comment['U_DELETE'] = add_url_params($url, array(
    226           'delete_albums' => $comment['comment_id'],
    227           'pwg_token' => get_pwg_token(),
    228         ));
    229       }
    230       if (can_manage_comment('edit', $comment['author_id'])) {
    231         $url = get_root_url().'comments.php'.get_query_string_diff(array('edit', 'delete','validate', 'pwg_token'));
    232 
    233         $tpl_comment['U_EDIT'] = add_url_params($url, array(
    234           'edit_albums' => $comment['comment_id'],
    235           'pwg_token' => get_pwg_token(),
    236         ));
    237 
    238         if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment)) {
     277      if (can_manage_comment('delete', $comment['author_id']))
     278      {
     279        $url =
     280          get_root_url()
     281          .'comments.php'
     282          .get_query_string_diff(array('delete','validate','edit', 'pwg_token'));
     283
     284        $tpl_comment['U_DELETE'] = add_url_params(
     285          $url,
     286          array(
     287            'delete_albums' => $comment['comment_id'],
     288            'pwg_token' => get_pwg_token(),
     289            )
     290          );
     291      }
     292      if (can_manage_comment('edit', $comment['author_id']))
     293      {
     294        $url =
     295          get_root_url()
     296          .'comments.php'
     297          .get_query_string_diff(array('edit', 'delete','validate', 'pwg_token'));
     298
     299        $tpl_comment['U_EDIT'] = add_url_params(
     300          $url,
     301          array(
     302            'edit_albums' => $comment['comment_id'],
     303            'pwg_token' => get_pwg_token(),
     304            )
     305          );
     306
     307        if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment))
     308        {
    239309          $key = get_ephemeral_key(2, $comment['category_id']);
    240310          $tpl_comment['IN_EDIT'] = true;
     
    244314        }
    245315      }
    246       if (can_manage_comment('validate', $comment['author_id'])) {
    247         if ('true' != $comment['validated']) {
    248           $tpl_comment['U_VALIDATE'] = add_url_params($url, array(
    249             'validate_albums'=> $comment['comment_id'],
    250             'pwg_token' => get_pwg_token(),
    251           ));
     316      if (can_manage_comment('validate', $comment['author_id']))
     317      {
     318        if ('true' != $comment['validated'])
     319        {
     320          $tpl_comment['U_VALIDATE'] = add_url_params(
     321            $url,
     322            array(
     323              'validate_albums'=> $comment['comment_id'],
     324              'pwg_token' => get_pwg_token(),
     325              )
     326            );
    252327        }
    253328      }
     
    258333
    259334  // +-----------------------------------------------------------------------+
    260   // |                        template                                       |
    261   // +-----------------------------------------------------------------------+
    262   $template->set_filenames(array('comments'=> dirname(__FILE__).'/../template/coa_comments_page.tpl'));
    263  
    264   // add a layer for display category name
     335  // |                            template                                   |
     336  // +-----------------------------------------------------------------------+
     337  $template->set_filenames(array('comments'=> dirname(__FILE__).'/../template/comments_page.tpl'));
     338 
     339  // add a line to display category name
    265340  $template->set_prefilter('comments', 'coa_change_comments_list');
     341 
    266342  function coa_change_comments_list($content, &$smarty) {
    267343    $search = '<div class="description"{if isset($comment.IN_EDIT)} style="height:200px"{/if}>';
    268344
    269 $replacement = '<div class="category-title">
     345    $replacement = '<div class="category-title">
    270346  <a href="{$comment.CAT_URL}">{$comment.CAT_NAME}</a>
    271347</div>
    272 <div class="description"{if isset($comment.IN_EDIT)} style="height:220px"{/if}>';
     348'.$search;
    273349
    274350    return str_replace($search, $replacement, $content);
Note: See TracChangeset for help on using the changeset viewer.