Changeset 27196 for extensions/MostCommented/main.inc.php
- Timestamp:
- Feb 4, 2014, 11:14:14 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/MostCommented/main.inc.php
r7198 r27196 2 2 /* 3 3 Plugin Name: Most Commented 4 Version: 2.0.a4 Version: auto 5 5 Description: Add a "Most Commented" link in "Specials" menu. 6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=1456 Plugin URI: auto 7 7 Author: P@t 8 8 Author URI: http://www.gauchon.com 9 9 */ 10 10 11 if (!defined('PHPWG_ROOT_PATH'))die('Hacking attempt!');11 defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); 12 12 13 13 define('MOSTCOMMENTED_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); 14 15 16 add_event_handler('init', 'init_mostcommented'); 17 18 19 function 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 } 14 31 15 32 function add_link_mostcommented($menu_ref_arr) … … 17 34 global $conf; 18 35 19 $menu = & 36 $menu = &$menu_ref_arr[0]; 20 37 $position = (isset($conf['mostcommented_position']) and is_numeric($conf['mostcommented_position'])) ? $conf['mostcommented_position'] : 3; 21 38 22 if (($block = $menu->get_block('mbSpecials')) != null 39 if (($block = $menu->get_block('mbSpecials')) != null) 23 40 { 24 load_language('plugin.lang', MOSTCOMMENTED_PATH);25 26 41 array_splice($block->data, $position-1, 0, array('most_commented' => 27 42 array( 28 43 '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') 31 46 ) 32 47 ) … … 35 50 } 36 51 37 function section_init_most _commented()52 function section_init_mostcommented() 38 53 { 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 = ' 67 SELECT 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 = ' 90 SELECT 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'); 42 107 } 43 108 44 add_event_handler('blockmanager_apply' , 'add_link_mostcommented'); 45 add_event_handler('loc_end_section_init', 'section_init_most_commented'); 109 function add_nb_comments_mostcommented($tpl_thumbnails_var) 110 { 111 global $template, $user, $selection; 46 112 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 = ' 120 SELECT 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.