b2evolution PHP Cross Reference Blogging Systems

Source: /inc/files/views/_file_duplicates.view.php - 199 lines - 6563 bytes - Summary - Text - Print

Description: This file implements the Duplicates file list. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**

   3   * This file implements the Duplicates file list.

   4   *

   5   * This file is part of the evoCore framework - {@link http://evocore.net/}

   6   * See also {@link http://sourceforge.net/projects/evocms/}.

   7   *

   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}

   9   *

  10   * @package admin

  11   *

  12   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  13   * @author fplanque: Francois PLANQUE.

  14   *

  15   * @version $Id: _file_duplicates.view.php 849 2012-02-16 09:09:09Z yura $

  16   */
  17  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  18  
  19  
  20  global $DB, $UserSettings;
  21  
  22  // set filter params

  23  $min_inappropriate_votes = param( 'miv', 'integer', 0, true );
  24  $min_spam_votes = param( 'msv', 'integer', 0, true );
  25  $file_ID = param( 'file_ID', 'integer', 0, true );
  26  
  27  // set default order

  28  $default_order = ( $min_inappropriate_votes >= $min_spam_votes ) ? '----D' : '-----D';
  29  
  30  // Create SQL query to find all file hashes that satisfy to filters

  31  $hash_SQL = new SQL();
  32  $hash_SQL->SELECT( 'f.file_hash, COUNT( f.file_ID )' );
  33  $hash_SQL->FROM( 'T_files AS f' );
  34  $hash_SQL->FROM_add( 'INNER JOIN (
  35          SELECT file_hash
  36            FROM T_files
  37           GROUP BY file_hash
  38          HAVING COUNT( file_ID ) > 1
  39      ) AS fd ON fd.file_hash = f.file_hash' );
  40  $hash_SQL->GROUP_BY( 'f.file_hash' );
  41  
  42  if( ( $min_inappropriate_votes > 0 ) || ( $min_spam_votes > 0 ) )
  43  { // we need to join files vote table to be able to filter by votes
  44      $hash_SQL->FROM_add( 'LEFT JOIN T_files__vote AS fv ON fv.fvot_file_ID = f.file_ID' );
  45      if( $min_inappropriate_votes > 0 )
  46      {    // Filter by minimum count of inappropriate votes
  47          $hash_SQL->HAVING_and( 'SUM( fvot_inappropriate ) >= '.$DB->quote( $min_inappropriate_votes ) );
  48      }
  49      if( $min_spam_votes > 0 )
  50      {    // Filter by minimum count of spam votes
  51          $hash_SQL->HAVING_and( 'SUM( fvot_spam ) >= '.$DB->quote( $min_spam_votes ) );
  52      }
  53  }
  54  if( $file_ID > 0 )
  55  {    // Filter by hash of File ID
  56      $hash_SQL->WHERE_and( '( SELECT fh.file_hash FROM T_files AS fh WHERE fh.file_ID ='.$DB->quote( $file_ID ).' ) = f.file_hash' );
  57  }
  58  
  59  // Get all distinct hash values from what we have duplicates and at least one file from duplicates corresponds to filters

  60  $hash_results = $DB->get_assoc( $hash_SQL->get() );
  61  $file_hash_values = array_keys( $hash_results );
  62  // set the number of count all files which will be displayed

  63  $num_file_results = array_sum( $hash_results );
  64  
  65  if( $num_file_results > 0 )
  66  { // Create SQL query to build a results table
  67      $SQL = new SQL();
  68      $SQL->SELECT( 'f.*,
  69          SUM( IFNULL( fvot_like, 0 ) ) as total_like,
  70          SUM( IFNULL( fvot_inappropriate, 0 ) ) as total_inappropriate,
  71          SUM( IFNULL( fvot_spam, 0 ) ) as total_spam,
  72          ( SELECT COUNT( file_ID ) FROM T_files AS f2 WHERE f.file_hash = f2.file_hash ) AS total_duplicates' );
  73      $SQL->FROM( 'T_files AS f' );
  74      $SQL->FROM_add( 'LEFT JOIN T_files__vote AS fv ON fv.fvot_file_ID = f.file_ID' );
  75      $SQL->WHERE( 'f.file_hash IN ( "'.implode( '","', $file_hash_values ).'" )' );
  76      $SQL->GROUP_BY( 'f.file_ID, f.file_hash' );
  77      $SQL->ORDER_BY( 'f.file_hash, *, total_spam DESC, total_inappropriate DESC' );
  78  }
  79  
  80  $Results = new Results( $num_file_results ? $SQL->get() : NULL, 'fdupl_', $default_order, $UserSettings->get( 'results_per_page' ), $num_file_results );
  81  $Results->Cache = & get_FileCache();
  82  $Results->Cache->clear();
  83  $Results->title = T_('Duplicate files');
  84  
  85  /*

  86   * Grouping params:

  87   */
  88  $Results->group_by = 'file_hash';
  89  
  90  /*

  91   * Group columns:

  92   */
  93  $Results->grp_cols[] = array(
  94          'td_class' => 'firstcol'.($current_User->check_perm( 'users', 'edit', false ) ? '' : ' lastcol' ),
  95          'td_colspan' => 0,
  96          'td' => sprintf( T_('%s duplicates'), '$total_duplicates$' ),
  97      );
  98  
  99  /**

 100   * Callback to add filters on top of the result set

 101   *

 102   * @param Form

 103   */
 104  function callback_filter_file_duplicated( & $Form )
 105  {
 106      $Form->text( 'miv', get_param( 'miv' ), 5, T_('Minimun inappropriate votes'), '', 6 );
 107  
 108      $Form->text( 'msv', get_param( 'msv' ), 5, T_('Minimun spam votes'), '', 6 );
 109  
 110      $Form->hidden( 'file_ID', get_param( 'file_ID' ) );
 111  }
 112  
 113  $filter_presets = array(
 114          'all' => array( T_('All'), '?ctrl=filemod&amp;tab=duplicates&amp;miv=0&amp;msv=0' ),
 115          'inappropriate' => array( T_('Inappropriate'), '?ctrl=filemod&amp;tab=duplicates&amp;miv=1&amp;msv=0' ),
 116          'spam' => array( T_('Spam'), '?ctrl=filemod&amp;tab=duplicates&amp;miv=0&amp;msv=1' ),
 117      );
 118  
 119  $Results->filter_area = array(
 120      'callback' => 'callback_filter_file_duplicated',
 121      'url_ignore' => 'results_fdupl_page',
 122      'presets' => $filter_presets,
 123      );
 124  
 125  function td_file_duplicates_icon( $File )
 126  {
 127      if( is_object( $File ) )
 128      { // Check if File object is correct
 129          return $File->get_preview_thumb( 'fulltype', true );
 130      }
 131      // Broken File object

 132      return T_('Not Found');
 133  }
 134  $Results->cols[] = array(
 135          'th' => T_('Icon/Type'),
 136          'th_class' => 'shrinkwrap',
 137          'td_class' => 'shrinkwrap',
 138          'td' => '%td_file_duplicates_icon( {Obj} )%',
 139      );
 140  
 141  function td_file_duplicates_path( $File, $file_root_type, $file_root_ID, $file_path )
 142  {
 143      if( is_object( $File ) )
 144      { // Check if File object is correct
 145          return $File->get_view_link().' '.$File->get_target_icon();
 146      }
 147      else
 148      { // Broken File object
 149          if( empty( $file_path ) )
 150          { // No file data exist in DB
 151              return T_('File no longer exists on disk.');
 152          }
 153          else
 154          { // Display file info from DB
 155              return $file_root_type.'_'.$file_root_ID.':'.$file_path;
 156          }
 157      }
 158  }
 159  $Results->cols[] = array(
 160          'th' => T_('Path'),
 161          'td' => '%td_file_duplicates_path( {Obj}, #file_root_type#, #file_root_ID#, #file_path# )%',
 162          'order' => 'file_path'
 163      );
 164  
 165  $Results->cols[] = array(
 166          'th' => T_('Attached To'),
 167          'td' => '%get_file_links( #file_ID# )%',
 168      );
 169  
 170  $Results->cols[] = array(
 171          'th' => /* TRANS: Header for # of times photo has been liked */ T_('Likes'),
 172          'td' => '$total_like$',
 173          'th_class' => 'shrinkwrap',
 174          'td_class' => 'center',
 175          'order' => 'total_like',
 176          'default_dir' => 'D',
 177      );
 178  
 179  $Results->cols[] = array(
 180          'th' => /* TRANS: Header for # of times photo has been votes inappropriate */ T_('Inappropriate'),
 181          'td' => '$total_inappropriate$',
 182          'th_class' => 'shrinkwrap',
 183          'td_class' => 'center',
 184          'order' => 'total_inappropriate',
 185          'default_dir' => 'D',
 186      );
 187  
 188  $Results->cols[] = array(
 189          'th' => T_('Spam'),
 190          'td' => '$total_spam$',
 191          'th_class' => 'shrinkwrap',
 192          'td_class' => 'center',
 193          'order' => 'total_spam',
 194          'default_dir' => 'D',
 195      );
 196  
 197  $Results->display();
 198  
 199  ?>

title

Description

title

Description

title

Description

title

title

Body