Ignore:
Timestamp:
Feb 4, 2014, 11:14:14 PM (10 years ago)
Author:
mistic100
Message:

Update for Piwigo 2.6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/MostCommented/main.inc.php

    r7198 r27196  
    22/*
    33Plugin Name: Most Commented
    4 Version: 2.0.a
     4Version: auto
    55Description: Add a "Most Commented" link in "Specials" menu.
    6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=145
     6Plugin URI: auto
    77Author: P@t
    88Author URI: http://www.gauchon.com
    99*/
    1010
    11 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     11defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
    1212
    1313define('MOSTCOMMENTED_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
     14
     15
     16add_event_handler('init', 'init_mostcommented');
     17
     18
     19function init_mostcommented()
     20{
     21  global $conf;
     22 
     23  if ($conf['activate_comments'])
     24  {
     25    load_language('plugin.lang', MOSTCOMMENTED_PATH);
     26
     27    add_event_handler('blockmanager_apply' , 'add_link_mostcommented');
     28    add_event_handler('loc_end_section_init', 'section_init_mostcommented');
     29  }
     30}
    1431
    1532function add_link_mostcommented($menu_ref_arr)
     
    1734  global $conf;
    1835
    19   $menu = & $menu_ref_arr[0];
     36  $menu = &$menu_ref_arr[0];
    2037  $position = (isset($conf['mostcommented_position']) and is_numeric($conf['mostcommented_position'])) ? $conf['mostcommented_position'] : 3;
    2138 
    22   if (($block = $menu->get_block('mbSpecials')) != null )
     39  if (($block = $menu->get_block('mbSpecials')) != null)
    2340  {
    24     load_language('plugin.lang', MOSTCOMMENTED_PATH);
    25 
    2641    array_splice($block->data, $position-1, 0, array('most_commented' =>
    2742      array(
    2843        'URL' => make_index_url(array('section' => 'most_commented')),
    29         'TITLE' => l10n('most_commented_cat_hint'),
    30         'NAME' => l10n('most_commented_cat')
     44        'TITLE' => l10n('displays most commented pictures'),
     45        'NAME' => l10n('Most commented')
    3146        )
    3247      )
     
    3550}
    3651
    37 function section_init_most_commented()
     52function section_init_mostcommented()
    3853{
    39   global $tokens;
    40   if (in_array('most_commented', $tokens))
    41     include(MOSTCOMMENTED_PATH . 'most_commented.php');
     54  global $tokens, $page, $conf;
     55 
     56  if (!in_array('most_commented', $tokens))
     57  {
     58    return;
     59  }
     60 
     61  $page['section'] = 'most_commented';
     62  $page['title'] = '<a href="' . duplicate_index_url() . '">' . l10n('Most commented') . '</a>';
     63  $page['section_title'] = '<a href="'.get_gallery_home_url().'">' . l10n('Home') . '</a>'
     64    . $conf['level_separator'] . $page['title'];
     65
     66  $query = '
     67SELECT DISTINCT image_id
     68    FROM ' . IMAGE_CATEGORY_TABLE . '
     69    WHERE ' . 
     70      get_sql_condition_FandF(
     71        array(
     72          'forbidden_categories' => 'category_id',
     73          'visible_categories' => 'category_id',
     74          'visible_images' => 'image_id',
     75          ),
     76        '', true
     77        )
     78    . '
     79;';
     80
     81  $img = query2array($query, null, 'image_id');
     82
     83  if (empty($img))
     84  {
     85    $page['items'] = array();
     86  }
     87  else
     88  {
     89    $query = '
     90SELECT
     91    img.id,
     92    COUNT(*) AS count
     93  FROM ' . IMAGES_TABLE . ' AS img
     94    INNER JOIN ' . COMMENTS_TABLE . ' AS com
     95    ON com.image_id = img.id
     96  WHERE
     97    img.id IN (' . implode(',', $img) . ')
     98    AND com.validated = "true"
     99  GROUP BY img.id
     100  ORDER BY count DESC, img.hit DESC
     101  LIMIT ' . $conf['top_number'] . '
     102;';
     103    $page['items'] = query2array($query, null, 'id');
     104  }
     105 
     106  add_event_handler('loc_end_index_thumbnails', 'add_nb_comments_mostcommented');
    42107}
    43108
    44 add_event_handler('blockmanager_apply' , 'add_link_mostcommented');
    45 add_event_handler('loc_end_section_init', 'section_init_most_commented');
     109function add_nb_comments_mostcommented($tpl_thumbnails_var)
     110{
     111  global $template, $user, $selection;
    46112
    47 ?>
     113  // unsed sort order
     114  $template->clear_assign('image_orders');
     115
     116  // display nb comments if hidden by user
     117  if (!$user['show_nb_comments'])
     118  {
     119    $query = '
     120SELECT image_id, COUNT(*) AS nb_comments
     121  FROM '.COMMENTS_TABLE.'
     122  WHERE validated = \'true\'
     123    AND image_id IN ('.implode(',', $selection).')
     124  GROUP BY image_id
     125;';
     126    $nb_comments_of = query2array($query, 'image_id', 'nb_comments');
     127   
     128    foreach ($tpl_thumbnails_var as &$row)
     129    {
     130      $row['NB_COMMENTS'] = $nb_comments_of[$row['id']];
     131    }
     132    unset($row);
     133  }
     134
     135  return $tpl_thumbnails_var;
     136}
Note: See TracChangeset for help on using the changeset viewer.