| 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 | } |