Changeset 23318


Ignore:
Timestamp:
Jun 18, 2013, 3:38:03 AM (11 years ago)
Author:
mistic100
Message:

it's late! some corrections, code cleaning & filter by size on admin page

Location:
extensions/BatchDownloader
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • extensions/BatchDownloader/admin/sets.php

    r23317 r23318  
    6464  }
    6565 
    66   $order_by = $_POST['order_by'].' '.$_POST['direction'];
     66  if ($_POST['size'] != -1)
     67  {
     68    array_push($where_clauses, 'size = "'.$_POST['size'].'"');
     69  }
     70 
     71  if ($_POST['order_by'] == 'size')
     72  {
     73    $order_by = 'FIND_IN_SET(size, "square,thumb,2small,xsmall,small,medium,large,xlarge,xxlarge,original") '.$_POST['direction'];
     74  }
     75  else
     76  {
     77    $order_by = $_POST['order_by'].' '.$_POST['direction'];
     78  }
    6779}
    6880
     
    122134  );
    123135
     136$page['size_items'] = array(
     137  -1 => '------------',
     138  );
     139foreach (ImageStdParams::get_defined_type_map() as $params)
     140{
     141  $page['size_items'][ $params->type ] = l10n($params->type);
     142}
     143$page['size_items']['original'] = l10n('Original');
     144
    124145$page['order_by_items'] = array(
    125146  'date_creation' => l10n('Creation date'),
     
    127148  'nb_images' => l10n('Number of images'),
    128149  'nb_archives' => l10n('Number of archives'),
     150  'size' => l10n('Photo sizes'),
    129151  );
    130152
     
    139161  'type_options' => $page['type_items'],
    140162  'type_selected' => isset($_POST['type']) ? $_POST['type'] : '',
     163  'size_options' => $page['size_items'],
     164  'size_selected' => isset($_POST['size']) ? $_POST['size'] : '',
    141165  'order_options' => $page['order_by_items'],
    142166  'order_selected' => isset($_POST['order_by']) ? $_POST['order_by'] : '',
  • extensions/BatchDownloader/admin/template/sets.tpl

    r23291 r23318  
    1717    {'Set type'|@translate}
    1818    {html_options name=type options=$type_options selected=$type_selected}
     19  </label>
     20 
     21  <label>
     22    {'Photo sizes'|@translate}
     23    {html_options name=size options=$size_options selected=$size_selected}
    1924  </label>
    2025 
     
    4954      <td class="type">{'Set type'|@translate}</td>
    5055      <td class="date">{'Creation date'|@translate}</td>
    51       <td class="size">{'Total size'|@translate}</td>
     56      <td class="img_size">{'Photo sizes'|@translate}</td>
    5257      <td class="images">{'Number of images'|@translate}</td>
    5358      <td class="archives">{'Number of archives'|@translate}</td>
     59      <td class="size">{'Total size'|@translate}</td>
    5460      <td class="status">{'Status'|@translate}</td>
    5561      <td class="action">{'Actions'|@translate}</td>
     
    6268    <td>{$set.NAME}</td>
    6369    <td style="text-align:center;">{$set.DATE_CREATION}</td>
    64     <td>{$set.TOTAL_SIZE}</td>
     70    <td>{if $set.SIZE=='original'}{'Original'|@translate}{else}{$set.SIZE|@translate}{/if}</td>
    6571    <td>{$set.NB_IMAGES}</td>
    6672    <td>{$set.NB_ARCHIVES}</td>
     73    <td>{$set.TOTAL_SIZE}</td>
    6774    <td>
    6875      {$set.STATUS|@translate}
  • extensions/BatchDownloader/admin/template/style.css

    r23288 r23318  
    3838  width:100px;
    3939}
     40.table2 .img_size {
     41  width:120px;
     42}
    4043.table2 .images {
    4144  width:100px;
  • extensions/BatchDownloader/include/BatchDownloader.class.php

    r23317 r23318  
    1212   * @param: mixed set id (##|'new')
    1313   * @param: array images
    14    * @param: string set type ('album'|'tag'|'selection')
    15    * @param: int set type id (for retrieving album infos for instance)
     14   * @param: string set type (calendar,category,flat,tags,search,favorites,most_visited,best_rated,list,recent_pics,collection)
     15   * @param: mixed set type id (for calendar,category,tags,search,collection)
    1616   * @param: string size to download
    1717   */
     
    3232      'nb_images' => 0,
    3333      'total_size' => 0,
    34       'estimated_total_size' => 0,
    3534      'status' => 'new',
     35      'estimated_total_size' => 0, // not in db
    3636      );
    3737    $this->images = array();
     
    4343SELECT *
    4444  FROM '.BATCH_DOWNLOAD_TSETS.'
    45   WHERE
    46     id = '.$set_id.'
     45  WHERE id = '.$set_id.'
    4746    '.(!is_admin() ? 'AND user_id = '.$this->data['user_id'] : null).'
    4847;';
     
    5655          );
    5756       
    58         // make sur all pictures of the set exist
     57        // make sure all pictures of the set exist
    5958        $query = '
    6059DELETE FROM '.BATCH_DOWNLOAD_TIMAGES.'
     
    6665     
    6766        $query = '
    68 SELECT
    69     image_id,
    70     zip
     67SELECT *
    7168  FROM '.BATCH_DOWNLOAD_TIMAGES.'
    7269  WHERE set_id = '.$this->data['id'].'
     
    8986      if ($size != 'original')
    9087      {
    91         $type_map = array_keys(ImageStdParams::get_defined_type_map());
    92         if (!in_array($size, $type_map))
     88        $types = array_keys(ImageStdParams::get_defined_type_map());
     89        if (!in_array($size, $types))
    9390        {
    9491          throw new Exception(sprintf(l10n('Invalid size %s'), $size));
     
    166163  /**
    167164   * getImages
    168    * @return: array
     165   * @return: array(image_id => zip_idx)
    169166   */
    170167  function getImages()
     
    213210  function addImages($image_ids)
    214211  {
    215     global $conf;
    216    
    217212    if (empty($image_ids) or !is_array($image_ids)) return;
    218213   
     
    229224    {
    230225      if ($this->isInSet($image_id)) continue;
    231       if (!in_array(get_extension($file), $conf['batch_download']['allowed_ext'])) continue;
     226      if (!in_array(get_extension($file), $this->conf['allowed_ext'])) continue;
    232227     
    233228      $this->images[ $image_id ] = 0;
    234       array_push($inserts, array('set_id'=>$this->data['id'], 'image_id'=>$image_id, 'zip'=>0));
    235     }
    236    
    237     mass_inserts(
    238       BATCH_DOWNLOAD_TIMAGES,
    239       array('set_id', 'image_id', 'zip'),
    240       $inserts
    241       );
     229      $inserts[] = array(
     230        'set_id' => $this->data['id'],
     231        'image_id' => $image_id,
     232        'zip' => 0,
     233        );
     234    }
     235   
     236    if (count($inserts))
     237    {
     238      mass_inserts(
     239        BATCH_DOWNLOAD_TIMAGES,
     240        array('set_id','image_id','zip'),
     241        $inserts
     242        );
     243    }
    242244     
    243245    $this->updateParam('nb_images', count($this->images));
     
    259261 
    260262  /**
    261    * get missing derivatives files
     263   * getMissingDerivatives
     264   * @param: bool update, if true, update IMAGE_SIZES with FS datas
    262265   * @return: array of i.php urls
    263266   */
     
    268271      return array();
    269272    }
    270    
    271     global $conf;
    272273   
    273274    $root_url = get_root_url();
     
    280281    $to_update = $urls = $inserts = array();
    281282   
     283    global $conf;
     284    $conf['old_question_mark_in_urls'] = $conf['question_mark_in_urls'];
     285    $conf['old_php_extension_in_urls'] = $conf['php_extension_in_urls'];
     286    $conf['old_derivative_url_style'] = $conf['derivative_url_style'];
    282287    $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true;
    283     $conf['derivative_url_style'] = 2; //script
     288    $conf['derivative_url_style'] = 2;
    284289   
    285290    // images which we need to update stats
     
    287292    {
    288293      $query = '
    289 SELECT image_id, filemtime FROM '.IMAGE_SIZES_TABLE.'
     294SELECT image_id, filemtime
     295  FROM '.IMAGE_SIZES_TABLE.'
    290296  WHERE image_id IN('.implode(',', $image_ids).')
    291297    AND type = "'.$this->data['size'].'"
     
    328334      {
    329335        $derivative = new DerivativeImage($this->data['size'], $src_image);
    330         // if ($this->data['size'] != $derivative->get_type()) continue;
    331336       
    332337        $filemtime = @filemtime($derivative->get_path());
     
    369374    }
    370375   
     376    $conf['question_mark_in_urls'] = $conf['old_question_mark_in_urls'];
     377    $conf['php_extension_in_urls'] = $conf['old_php_extension_in_urls'];
     378    $conf['derivative_url_style'] = $conf['old_derivative_url_style'];
     379   
    371380    return $urls;
    372381  }
     
    412421      }
    413422     
    414       $this->getEstimatedArchiveNumber();
     423      $this->getEstimatedArchiveNumber(true);
    415424     
    416425      $this->updateParam('date_creation', date('Y-m-d H:i:s'));
     
    572581    }
    573582   
    574     list($total) = pwg_db_fetch_row(pwg_query($query));
    575     $this->data['estimated_total_size'] = $total;
    576     return $total;
     583    list($this->data['estimated_total_size']) = pwg_db_fetch_row(pwg_query($query));
     584    return $this->data['estimated_total_size'];
    577585  }
    578586 
     
    581589   * @return: int
    582590   */
    583   function getEstimatedArchiveNumber()
     591  function getEstimatedArchiveNumber($force=false)
    584592  {
    585593    if ($this->data['status'] == 'done') return $this->data['nb_zip'];
    586    
    587     return ceil( $this->getEstimatedTotalSize() / ($this->conf['max_size']*1024) );
     594    if ( !empty($this->data['nb_zip']) and !$force ) return $this->data['nb_zip'];
     595   
     596    $this->updateParam('nb_zip', ceil( $this->getEstimatedTotalSize($force) / ($this->conf['max_size']*1024) ));
     597    return $this->data['nb_zip'];
    588598  }
    589599 
     
    649659    $path.= $set['BASENAME'] . '_';
    650660    $path.= $this->data['user_id'] . $this->data['id'];
    651     $path.= '_part' . $i;
    652     $path.= '.zip';
     661    $path.= '_part' . $i . '.zip';
    653662   
    654663    return $path;
     
    657666  /**
    658667   * getNames
    659    * @return: array
     668   * @return: array
     669   *    NAME, set name with HTML
     670   *    sNAME, set name without HTML
     671   *    BASENAME, set filename
     672   *    COMMENT, set comment
    660673   */
    661674  function getNames()
     
    848861      'NB_IMAGES' =>     $this->data['nb_images'],
    849862      'NB_ARCHIVES' =>   $this->data['status']=='new' ? l10n('Unknown') : $this->getEstimatedArchiveNumber(),
    850       'STATUS' =>        $this->data['status'],
     863      'STATUS' =>        $this->data['status']=='ready' ? 'new' : $this->data['status'],
    851864      'LAST_ZIP' =>      $this->data['last_zip'],
    852865      'TOTAL_SIZE' =>    $this->data['status']=='new' ? l10n('Unknown') : sprintf(l10n('%d MB'), ceil($this->getEstimatedTotalSize()/1024)),
    853866      'DATE_CREATION' => format_date($this->data['date_creation'], true),
    854       'SIZE_ID' =>       $this->data['size'],
    855       'SIZE' =>          $this->data['size']=='original' ? l10n('Original') : l10n($this->data['size']),
     867      'SIZE' =>          $this->data['size'],
    856868      );
    857869     
  • extensions/BatchDownloader/include/events.inc.php

    r23290 r23318  
    141141    'BATCH_DWN_URL' => $url,
    142142    ));
    143    
    144   $type_map = ImageStdParams::get_defined_type_map();
    145   foreach ($type_map as $params)
     143 
     144  foreach (ImageStdParams::get_defined_type_map() as $params)
    146145  {
    147146    $template->append(
  • extensions/BatchDownloader/include/functions.inc.php

    r23291 r23318  
    3434      {
    3535        $batch_type = 'flat';
    36         $batch_id = 0;
     36        $batch_id = null;
    3737      }
    3838      break;
     
    5858    case 'recent_pics':
    5959      $batch_type = $page['section'];
    60       $batch_id = 0;
     60      $batch_id = null;
    6161      break;
    6262    default:
  • extensions/BatchDownloader/template/init_zip.tpl

    r23291 r23318  
    9393    <li class="error">{$elements_error}</li>
    9494    <li><b>{'%d photos'|@translate|@sprintf:$set.NB_IMAGES}</b>{if $set.U_EDIT_SET}, <a href="{$set.U_EDIT_SET}" rel="nofollow">{'Edit the set'|@translate}</a>{/if}</li>
    95     <li><b>{'Size'|@translate}:</b> {$set.SIZE} {if $set.SIZE_INFO}<span class="downloadSizeDetails">({$set.SIZE_INFO})</span>{/if}</li>
     95    <li><b>{'Photo sizes'|@translate}:</b> {if $set.SIZE=='original'}{'Original'|@translate}{else}{$set.SIZE|@translate}{/if} {if $set.SIZE_INFO}<span class="downloadSizeDetails">({$set.SIZE_INFO})</span>{/if}</li>
    9696    <li><b>{'Estimated size'|@translate}:</b> {$set.TOTAL_SIZE}</li>
    9797    <li><b>{'Estimated number of archives'|@translate}:</b> {$set.NB_ARCHIVES} <i>({'real number of archives can differ'|@translate})</i></li>
Note: See TracChangeset for help on using the changeset viewer.