Changeset 12724

Show
Ignore:
Timestamp:
12/13/11 15:01:10 (18 months ago)
Author:
plg
Message:

merge r12722 from branch 2.3 into trunk
merge r12723 from branch 2.3 into trunk

feature 2531 added: pwg.images.add is able to generate web size + thumbnail
(remote client needs to set "resize" option to something else than 0). When
the "resize" is On, only the "file" must be send with pwg.images.addChunk.

Small improvement compared to code implemented in branch 2.3 : use of
single_insert when resize is Off, single algorithm to update $info_colums (resize On/Off)

Location:
trunk
Files:
2 modified

Legend:

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

    r12624 r12724  
    16551655  } 
    16561656 
    1657   // current date 
    1658   list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); 
    1659   list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4); 
    1660  
    1661   // upload directory hierarchy 
    1662   $upload_dir = sprintf( 
    1663     $conf['upload_dir'].'/%s/%s/%s', 
    1664     $year, 
    1665     $month, 
    1666     $day 
    1667     ); 
    1668  
    1669   // compute file path 
    1670   $date_string = preg_replace('/[^\d]/', '', $dbnow); 
    1671   $random_string = substr($params['file_sum'], 0, 8); 
    1672   $filename_wo_ext = $date_string.'-'.$random_string; 
    1673   $file_path = $upload_dir.'/'.$filename_wo_ext.'.jpg'; 
    1674  
    1675   // add files 
    1676   $file_infos  = add_file($file_path, 'file',  $params['original_sum'], $params['file_sum']); 
    1677   $thumb_infos = add_file($file_path, 'thumb', $params['original_sum'], $params['thumbnail_sum']); 
    1678  
    1679   if (isset($params['high_sum'])) 
    1680   { 
    1681     $high_infos = add_file($file_path, 'high', $params['original_sum'], $params['high_sum']); 
    1682   } 
    1683  
    1684   // database registration 
    1685   $insert = array( 
    1686     'file' => !empty($params['original_filename']) ? $params['original_filename'] : $filename_wo_ext.'.jpg', 
    1687     'date_available' => $dbnow, 
    1688     'tn_ext' => 'jpg', 
    1689     'name' => $params['name'], 
    1690     'path' => $file_path, 
    1691     'filesize' => $file_infos['filesize'], 
    1692     'width' => $file_infos['width'], 
    1693     'height' => $file_infos['height'], 
    1694     'md5sum' => $params['original_sum'], 
    1695     'added_by' => $user['id'], 
    1696     ); 
     1657  if ($params['resize']) 
     1658  { 
     1659    ws_logfile('[pwg.images.add] resize activated'); 
     1660     
     1661    // temporary file path 
     1662    $type = 'file'; 
     1663    $file_path = $conf['upload_dir'].'/buffer/'.$params['original_sum'].'-'.$type; 
     1664     
     1665    merge_chunks($file_path, $params['original_sum'], $type); 
     1666    chmod($file_path, 0644); 
     1667 
     1668    include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); 
     1669     
     1670    $image_id = add_uploaded_file( 
     1671      $file_path, 
     1672      $params['original_filename'] 
     1673      ); 
     1674 
     1675    // add_uploaded_file doesn't remove the original file in the buffer 
     1676    // directory if it was not uploaded as $_FILES 
     1677    unlink($file_path); 
     1678  } 
     1679  else 
     1680  { 
     1681    // current date 
     1682    list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); 
     1683    list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4); 
     1684 
     1685    // upload directory hierarchy 
     1686    $upload_dir = sprintf( 
     1687      $conf['upload_dir'].'/%s/%s/%s', 
     1688      $year, 
     1689      $month, 
     1690      $day 
     1691      ); 
     1692 
     1693    // compute file path 
     1694    $date_string = preg_replace('/[^\d]/', '', $dbnow); 
     1695    $random_string = substr($params['file_sum'], 0, 8); 
     1696    $filename_wo_ext = $date_string.'-'.$random_string; 
     1697    $file_path = $upload_dir.'/'.$filename_wo_ext.'.jpg'; 
     1698     
     1699    // add files 
     1700    $file_infos  = add_file($file_path, 'file',  $params['original_sum'], $params['file_sum']); 
     1701    $thumb_infos = add_file($file_path, 'thumb', $params['original_sum'], $params['thumbnail_sum']); 
     1702     
     1703    if (isset($params['high_sum'])) 
     1704    { 
     1705      $high_infos = add_file($file_path, 'high', $params['original_sum'], $params['high_sum']); 
     1706    } 
     1707 
     1708    // database registration 
     1709    $insert = array( 
     1710      'file' => !empty($params['original_filename']) ? $params['original_filename'] : $filename_wo_ext.'.jpg', 
     1711      'date_available' => $dbnow, 
     1712      'tn_ext' => 'jpg', 
     1713      'name' => $params['name'], 
     1714      'path' => $file_path, 
     1715      'filesize' => $file_infos['filesize'], 
     1716      'width' => $file_infos['width'], 
     1717      'height' => $file_infos['height'], 
     1718      'md5sum' => $params['original_sum'], 
     1719      'added_by' => $user['id'], 
     1720      ); 
     1721 
     1722    if (isset($params['high_sum'])) 
     1723    { 
     1724      $insert['has_high'] = 'true'; 
     1725      $insert['high_filesize'] = $high_infos['filesize']; 
     1726      $insert['high_width'] = $high_infos['width']; 
     1727      $insert['high_height'] = $high_infos['height']; 
     1728    } 
     1729 
     1730    single_insert( 
     1731      IMAGES_TABLE, 
     1732      $insert 
     1733      ); 
     1734 
     1735    $image_id = pwg_db_insert_id(IMAGES_TABLE); 
     1736 
     1737    // update metadata from the uploaded file (exif/iptc) 
     1738    require_once(PHPWG_ROOT_PATH.'admin/include/functions_metadata.php'); 
     1739    update_metadata(array($image_id=>$file_path)); 
     1740  } 
    16971741 
    16981742  $info_columns = array( 
     
    17081752    if (isset($params[$key])) 
    17091753    { 
    1710       $insert[$key] = $params[$key]; 
    1711     } 
    1712   } 
    1713  
    1714   if (isset($params['high_sum'])) 
    1715   { 
    1716     $insert['has_high'] = 'true'; 
    1717     $insert['high_filesize'] = $high_infos['filesize']; 
    1718     $insert['high_width'] = $high_infos['width']; 
    1719     $insert['high_height'] = $high_infos['height']; 
    1720   } 
    1721  
    1722   include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 
    1723   mass_inserts( 
    1724     IMAGES_TABLE, 
    1725     array_keys($insert), 
    1726     array($insert) 
    1727     ); 
    1728  
    1729   $image_id = pwg_db_insert_id(IMAGES_TABLE); 
     1754      $update[$key] = $params[$key]; 
     1755    } 
     1756  } 
     1757   
     1758  if (count(array_keys($update)) > 0) 
     1759  { 
     1760    single_update( 
     1761      IMAGES_TABLE, 
     1762      $update, 
     1763      array('id' => $image_id) 
     1764      ); 
     1765  } 
    17301766 
    17311767  // let's add links between the image and the categories 
     
    17431779      ); 
    17441780  } 
    1745  
    1746   // update metadata from the uploaded file (exif/iptc) 
    1747   require_once(PHPWG_ROOT_PATH.'admin/include/functions_metadata.php'); 
    1748   update_metadata(array($image_id=>$file_path)); 
    17491781 
    17501782  invalidate_user_cache(); 
  • trunk/ws.php

    r12695 r12724  
    227227    array( 
    228228      'file_sum' => array(), 
    229       'thumbnail_sum' => array(), 
     229      'thumbnail_sum' => array('default' => null), 
    230230      'high_sum' => array('default' => null), 
    231231      'original_sum' => array(), 
     
    241241        'maxValue' => $conf['available_permission_levels'] 
    242242        ), 
     243      'resize' => array('default' => false), 
    243244      ), 
    244245    'POST method only.