Changeset 12722


Ignore:
Timestamp:
Dec 13, 2011, 2:43:18 PM (9 years ago)
Author:
plg
Message:

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.

Location:
branches/2.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.3/include/ws_functions.inc.php

    r12651 r12722  
    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
     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    $image_id = add_uploaded_file(
     1669      $file_path,
     1670      $params['original_filename']
     1671      );
     1672
     1673    // add_uploaded_file doesn't remove the original file in the buffer
     1674    // directory if it was not uploaded as $_FILES
     1675    unlink($file_path);
     1676
     1677    $info_columns = array(
     1678      'name',
     1679      'author',
     1680      'comment',
     1681      'level',
     1682      'date_creation',
    16671683    );
    16681684
    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     );
    1697 
    1698   $info_columns = array(
    1699     'name',
    1700     'author',
    1701     'comment',
    1702     'level',
    1703     'date_creation',
    1704     );
    1705 
    1706   foreach ($info_columns as $key)
    1707   {
    1708     if (isset($params[$key]))
    1709     {
    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);
     1685    foreach ($info_columns as $key)
     1686    {
     1687      if (isset($params[$key]))
     1688      {
     1689        $update[$key] = $params[$key];
     1690      }
     1691    }
     1692
     1693    if (count(array_keys($update)) > 0)
     1694    {
     1695      single_update(
     1696        IMAGES_TABLE,
     1697        $update,
     1698        array('id' => $image_id)
     1699        );
     1700    }
     1701  }
     1702  else
     1703  {
     1704    // current date
     1705    list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
     1706    list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4);
     1707
     1708    // upload directory hierarchy
     1709    $upload_dir = sprintf(
     1710      $conf['upload_dir'].'/%s/%s/%s',
     1711      $year,
     1712      $month,
     1713      $day
     1714      );
     1715
     1716    // compute file path
     1717    $date_string = preg_replace('/[^\d]/', '', $dbnow);
     1718    $random_string = substr($params['file_sum'], 0, 8);
     1719    $filename_wo_ext = $date_string.'-'.$random_string;
     1720    $file_path = $upload_dir.'/'.$filename_wo_ext.'.jpg';
     1721   
     1722    // add files
     1723    $file_infos  = add_file($file_path, 'file',  $params['original_sum'], $params['file_sum']);
     1724    $thumb_infos = add_file($file_path, 'thumb', $params['original_sum'], $params['thumbnail_sum']);
     1725   
     1726    if (isset($params['high_sum']))
     1727    {
     1728      $high_infos = add_file($file_path, 'high', $params['original_sum'], $params['high_sum']);
     1729    }
     1730
     1731    // database registration
     1732    $insert = array(
     1733      'file' => !empty($params['original_filename']) ? $params['original_filename'] : $filename_wo_ext.'.jpg',
     1734      'date_available' => $dbnow,
     1735      'tn_ext' => 'jpg',
     1736      'name' => $params['name'],
     1737      'path' => $file_path,
     1738      'filesize' => $file_infos['filesize'],
     1739      'width' => $file_infos['width'],
     1740      'height' => $file_infos['height'],
     1741      'md5sum' => $params['original_sum'],
     1742      'added_by' => $user['id'],
     1743      );
     1744
     1745    $info_columns = array(
     1746      'name',
     1747      'author',
     1748      'comment',
     1749      'level',
     1750      'date_creation',
     1751      );
     1752
     1753    foreach ($info_columns as $key)
     1754    {
     1755      if (isset($params[$key]))
     1756      {
     1757        $insert[$key] = $params[$key];
     1758      }
     1759    }
     1760
     1761    if (isset($params['high_sum']))
     1762    {
     1763      $insert['has_high'] = 'true';
     1764      $insert['high_filesize'] = $high_infos['filesize'];
     1765      $insert['high_width'] = $high_infos['width'];
     1766      $insert['high_height'] = $high_infos['height'];
     1767    }
     1768
     1769    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     1770    mass_inserts(
     1771      IMAGES_TABLE,
     1772      array_keys($insert),
     1773      array($insert)
     1774      );
     1775
     1776    $image_id = pwg_db_insert_id(IMAGES_TABLE);
     1777
     1778    // update metadata from the uploaded file (exif/iptc)
     1779    require_once(PHPWG_ROOT_PATH.'admin/include/functions_metadata.php');
     1780    update_metadata(array($image_id=>$file_path));
     1781  }
    17301782
    17311783  // let's add links between the image and the categories
     
    17431795      );
    17441796  }
    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));
    17491797
    17501798  invalidate_user_cache();
  • branches/2.3/ws.php

    r12694 r12722  
    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.
Note: See TracChangeset for help on using the changeset viewer.