Changeset 12865 for trunk/include


Ignore:
Timestamp:
Jan 8, 2012, 8:25:52 PM (12 years ago)
Author:
rvelices
Message:

feature 2548 multisize - added a page to build missing derivatives

  • browser driven, chained ws calls to retrieve urls, visual feedback of progress through slideshow
Location:
trunk/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/derivative.inc.php

    r12855 r12865  
    220220  }
    221221
     222  function get_path()
     223  {
     224    return PHPWG_ROOT_PATH.$this->rel_path;
     225  }
     226
    222227  function get_url()
    223228  {
  • trunk/include/ws_functions.inc.php

    r12855 r12865  
    9393    $clauses[] = $tbl_name.'width/'.$tbl_name.'height<='.$params['f_max_ratio'];
    9494  }
    95   if ( $params['f_with_thumbnail'] )
    96   {
    97     $clauses[] = $tbl_name.'tn_ext IS NOT NULL';
     95  if (is_numeric($params['f_max_level']) )
     96  {
     97    $clauses[] = $tbl_name.'level <= '.$params['f_max_level'];
    9898  }
    9999  return $clauses;
     
    148148{
    149149  $ret = array();
    150  
     150
    151151  $src_image = new SrcImage($image_row);
    152152
     
    156156    $ret['element_url'] = get_element_url($image_row);
    157157  }
    158  
     158
    159159  $derivatives = DerivativeImage::get_all($src_image);
    160160  $derivatives_arr = array();
     
    178178    'id','element_url', 'file','width','height','hit','date_available','date_creation'
    179179    );
     180}
     181
     182function ws_getMissingDerivatives($params, &$service)
     183{
     184  if (!is_admin())
     185  {
     186    return new PwgError(403, 'Forbidden');
     187  }
     188
     189  if ( empty($params['types']) )
     190  {
     191    $types = array_keys(ImageStdParams::get_defined_type_map());
     192  }
     193  else
     194  {
     195    $types = array_intersect(array_keys(ImageStdParams::get_defined_type_map()), $params['types']);
     196    if (count($types)==0)
     197    {
     198      return new PwgError(WS_ERR_INVALID_PARAM, "Invalid types");
     199    }
     200  }
     201
     202  if ( ($max_urls = intval($params['max_urls'])) <= 0)
     203  {
     204    return new PwgError(WS_ERR_INVALID_PARAM, "Invalid max_urls");
     205  }
     206
     207  list($max_id, $image_count) = pwg_db_fetch_row( pwg_query('SELECT MAX(id)+1, COUNT(*) FROM '.IMAGES_TABLE) );
     208  $start_id = intval($params['prev_page']);
     209  if ($start_id<=0)
     210  {
     211    $start_id = $max_id;
     212  }
     213
     214  $uid = '&b='.time();
     215  global $conf;
     216  $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true;
     217  $conf['derivative_url_style']=2; //script
     218
     219  $qlimit = min(5000, ceil(max($image_count/500, $max_urls/count($types))));
     220  $where_clauses = ws_std_image_sql_filter( $params, '' );
     221  $where_clauses[] = 'id<start_id';
     222
     223  $query_model = 'SELECT id, path, representative_ext, width, height
     224  FROM '.IMAGES_TABLE.'
     225  WHERE '.implode(' AND ', $where_clauses).'
     226  ORDER BY id DESC
     227  LIMIT '.$qlimit;
     228
     229  $urls=array();
     230  do
     231  {
     232    $result = pwg_query( str_replace('start_id', $start_id, $query_model));
     233    $is_last = pwg_db_num_rows($result) < $qlimit;
     234    while ($row=pwg_db_fetch_assoc($result))
     235    {
     236      $start_id = $row['id'];
     237      $src_image = new SrcImage($row);
     238      if ($src_image->is_mimetype())
     239        continue;
     240      foreach($types as $type)
     241      {
     242        $derivative = new DerivativeImage($type, $src_image);
     243        if ($type != $derivative->get_type())
     244          continue;
     245        if (@filemtime($derivative->get_path())===false)
     246        {
     247          $urls[] = $derivative->get_url().$uid;
     248        }
     249      }
     250      if (count($urls)>=$max_urls && !$is_last)
     251        break;
     252    }
     253    if ($is_last)
     254    {
     255      $start_id = 0;
     256    }
     257  }while (count($urls)<$max_urls && $start_id);
     258
     259  $ret = array();
     260  if ($start_id)
     261  {
     262    $ret['next_page']=$start_id;
     263  }
     264  $ret['urls']=$urls;
     265  return $ret;
    180266}
    181267
     
    515601  $user_representative_updates_for = array();
    516602  // management of the album thumbnail -- stops here
    517  
     603
    518604  $cats = array();
    519605  while ($row = pwg_db_fetch_assoc($result))
     
    553639
    554640    // management of the album thumbnail -- starts here
    555     // 
     641    //
    556642    // on branch 2.3, the algorithm is duplicated from
    557643    // include/category_cats, but we should use a common code for Piwigo 2.4
     
    604690      }
    605691    }
    606    
     692
    607693    if (isset($image_id))
    608694    {
     
    611697        $user_representative_updates_for[ $user['id'].'#'.$row['id'] ] = $image_id;
    612698      }
    613    
     699
    614700      $row['representative_picture_id'] = $image_id;
    615701      array_push($image_ids, $image_id);
     
    651737        // * register it at user_representative_picture_id
    652738        // * set it as the representative_picture_id for the category
    653        
     739
    654740        foreach ($categories as &$category)
    655741        {
     
    658744            // searching a random representant among elements in sub-categories
    659745            $image_id = get_random_image_in_category($category);
    660            
     746
    661747            if (isset($image_id) and !in_array($image_id, $image_ids))
    662748            {
    663749              array_push($new_image_ids, $image_id);
    664750            }
    665            
     751
    666752            if ($conf['representative_cache_on_level'])
    667753            {
    668754              $user_representative_updates_for[ $user['id'].'#'.$category['id'] ] = $image_id;
    669755            }
    670            
     756
    671757            $category['representative_picture_id'] = $image_id;
    672758          }
     
    675761      }
    676762    }
    677    
     763
    678764    if (count($new_image_ids) > 0)
    679765    {
     
    697783  {
    698784    $updates = array();
    699  
     785
    700786    foreach ($user_representative_updates_for as $user_cat => $image_id)
    701787    {
    702788      list($user_id, $cat_id) = explode('#', $user_cat);
    703    
     789
    704790      array_push(
    705791        $updates,
     
    736822    unset($cat['count_categories']);
    737823  }
    738   unset($cat); 
     824  unset($cat);
    739825  // management of the album thumbnail -- stops here
    740826
     
    15311617  // check dumped thumbnail md5
    15321618  $dumped_md5 = md5_file($file_path);
    1533   if ($dumped_md5 != $file_sum) 
     1619  if ($dumped_md5 != $file_sum)
    15341620  {
    15351621    return new PwgError(500, '[add_file] '.$type.' transfer failed');
     
    16661752  {
    16671753    ws_logfile('[pwg.images.add] resize activated');
    1668    
     1754
    16691755    // temporary file path
    16701756    $type = 'file';
    16711757    $file_path = $conf['upload_dir'].'/buffer/'.$params['original_sum'].'-'.$type;
    1672    
     1758
    16731759    merge_chunks($file_path, $params['original_sum'], $type);
    16741760    chmod($file_path, 0644);
    16751761
    16761762    include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
    1677    
     1763
    16781764    $image_id = add_uploaded_file(
    16791765      $file_path,
     
    17041790    $filename_wo_ext = $date_string.'-'.$random_string;
    17051791    $file_path = $upload_dir.'/'.$filename_wo_ext.'.jpg';
    1706    
     1792
    17071793    // add files
    17081794    $file_infos  = add_file($file_path, 'file',  $params['original_sum'], $params['file_sum']);
    17091795    $thumb_infos = add_file($file_path, 'thumb', $params['original_sum'], $params['thumbnail_sum']);
    1710    
     1796
    17111797    if (isset($params['high_sum']))
    17121798    {
     
    17631849    }
    17641850  }
    1765  
     1851
    17661852  if (count(array_keys($update)) > 0)
    17671853  {
     
    17741860
    17751861  $url_params = array('image_id' => $image_id);
    1776  
     1862
    17771863  // let's add links between the image and the categories
    17781864  if (isset($params['categories']))
     
    17821868    if (preg_match('/^\d+/', $params['categories'], $matches)) {
    17831869      $category_id = $matches[0];
    1784    
     1870
    17851871      $query = '
    17861872SELECT id, name, permalink
     
    17901876      $result = pwg_query($query);
    17911877      $category = pwg_db_fetch_assoc($result);
    1792      
     1878
    17931879      $url_params['section'] = 'categories';
    17941880      $url_params['category'] = $category;
     
    19582044    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid user_id');
    19592045  }
    1960  
     2046
    19612047  $query = '
    19622048DELETE FROM '.RATE_TABLE.'
    19632049  WHERE user_id='.$user_id;
    1964  
     2050
    19652051  if (!empty($params['anonymous_id']))
    19662052  {
    19672053    $query .= ' AND anonymous_id=\''.$params['anonymous_id'].'\'';
    19682054  }
    1969  
     2055
    19702056  $changes = pwg_db_changes(pwg_query($query));
    19712057  if ($changes)
     
    32753361    return new PwgError(403, "image can't be resized");
    32763362  }
    3277  
     3363
    32783364  $hd_path = get_high_path($image);
    32793365
     
    32853371      $hd_dir = dirname($hd_path);
    32863372      prepare_directory($hd_dir);
    3287      
     3373
    32883374      rename($image_path, $hd_path);
    32893375      $hd_infos = pwg_image_infos($hd_path);
Note: See TracChangeset for help on using the changeset viewer.