/**
 * Returns EXIF metadata to sync from a file, depending on EXIF mapping.
 *
 * @param string $file
 * @return array
 */
function get_sync_exif_data($file)
{
    global $conf;
    $exif = get_exif_data($file, $conf['use_exif_mapping']);
    foreach ($exif as $pwg_key => $value) {
        if (in_array($pwg_key, array('date_creation', 'date_available'))) {
            if (preg_match('/^(\\d{4}).(\\d{2}).(\\d{2}) (\\d{2}).(\\d{2}).(\\d{2})/', $value, $matches)) {
                $exif[$pwg_key] = $matches[1] . '-' . $matches[2] . '-' . $matches[3] . ' ' . $matches[4] . ':' . $matches[5] . ':' . $matches[6];
            } elseif (preg_match('/^(\\d{4}).(\\d{2}).(\\d{2})/', $value, $matches)) {
                $exif[$pwg_key] = $matches[1] . '-' . $matches[2] . '-' . $matches[3];
            } else {
                unset($exif[$pwg_key]);
                continue;
            }
        }
        $exif[$pwg_key] = addslashes($exif[$pwg_key]);
    }
    return $exif;
}
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+
/**
 * This file is included by the picture page to manage picture metadata
 *
 */
include_once PHPWG_ROOT_PATH . '/include/functions_metadata.inc.php';
if ($conf['show_exif'] and function_exists('read_exif_data')) {
    $exif_mapping = array();
    foreach ($conf['show_exif_fields'] as $field) {
        $exif_mapping[$field] = $field;
    }
    $exif = get_exif_data($picture['current']['src_image']->get_path(), $exif_mapping);
    if (count($exif) > 0) {
        $tpl_meta = array('TITLE' => l10n('EXIF Metadata'), 'lines' => array());
        foreach ($conf['show_exif_fields'] as $field) {
            if (strpos($field, ';') === false) {
                if (isset($exif[$field])) {
                    $key = $field;
                    if (isset($lang['exif_field_' . $field])) {
                        $key = $lang['exif_field_' . $field];
                    }
                    $tpl_meta['lines'][$key] = $exif[$field];
                }
            } else {
                $tokens = explode(';', $field);
                if (isset($exif[$field])) {
                    $key = $tokens[1];
/**
 * Function to process the file upload process
 */
function incoming_uploads_script()
{
    $is_uploaded = false;
    if (!file_exists(get_custom_file_base() . '/uploads/incoming')) {
        @mkdir(get_custom_file_base() . '/uploads/incoming', 0777);
        fix_permissions(get_custom_file_base() . '/uploads/incoming', 0777);
        sync_file(get_custom_file_base() . '/uploads/incoming');
    }
    $savename = 'uploads/incoming/' . uniqid('', true) . '.dat';
    if (array_key_exists('file', $_FILES)) {
        if (is_uploaded_file($_FILES['file']['tmp_name'])) {
            $is_uploaded = true;
        } else {
            header('HTTP/1.1 500 File Upload Error');
            @error_log('ocPortal: ' . do_lang('ERROR_UPLOADING_' . strval($_FILES['file']['error'])), 0);
            exit('ocPortal: ' . do_lang('ERROR_UPLOADING_' . strval($_FILES['file']['error'])));
        }
        $name = $_FILES['file']['name'];
        if ($is_uploaded) {
            @move_uploaded_file($_FILES['file']['tmp_name'], get_custom_file_base() . '/' . $savename) or intelligent_write_error(get_custom_file_base() . '/' . $savename);
        }
    } elseif (post_param('name', '') != '') {
        header("Cache-Control: no-cache, must-revalidate");
        // HTTP/1.1
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
        // Date in the past
        $name = post_param('name');
        // Read binary input stream and append it to temp file
        $in = fopen('php://input', 'rb');
        if ($in !== false) {
            // Open temp file
            $out = fopen($savename, 'wb');
            if ($out !== false) {
                $is_uploaded = true;
                do {
                    $buff = fread($in, 4096);
                    fwrite($out, $buff);
                } while (!feof($out));
                fclose($out);
            }
            fclose($in);
        }
    }
    if ($is_uploaded) {
        $max_length = 255;
        $field_type_test = $GLOBALS['SITE_DB']->query_value('db_meta', 'm_type', array('m_name' => 'i_orig_filename'));
        if ($field_type_test == 'ID_TEXT') {
            $max_length = 80;
        }
        // Legacy
        $name = substr($name, max(0, strlen($name) - $max_length));
        header('Content-type: text/plain; charset=' . get_charset());
        require_code('files');
        if (get_param_integer('base64', 0) == 1) {
            $new = base64_decode(file_get_contents(get_custom_file_base() . '/' . $savename));
            $myfile = @fopen(get_custom_file_base() . '/' . $savename, 'wb') or intelligent_write_error(get_custom_file_base() . '/' . $savename);
            fwrite($myfile, $new);
            fclose($myfile);
        }
        fix_permissions(get_custom_file_base() . '/' . $savename);
        sync_file(get_custom_file_base() . '/' . $savename);
        $member_id = get_member();
        $file_db_id = $GLOBALS['SITE_DB']->query_insert('incoming_uploads', array('i_submitter' => $member_id, 'i_date_and_time' => time(), 'i_orig_filename' => $name, 'i_save_url' => $savename), true, false);
        // File is valid, and was successfully uploaded. Now see if there is any metadata to surface from the file.
        require_code('images');
        $outa = array();
        if (is_image($name)) {
            require_code('exif');
            $outa += get_exif_data(get_custom_file_base() . '/' . $savename);
        }
        $outa['upload_id'] = strval($file_db_id);
        $outa['upload_name'] = $name;
        $outa['upload_savename'] = $savename;
        @ini_set('ocproducts.xss_detect', '0');
        $outstr = '{';
        $done = 0;
        foreach ($outa as $key => $val) {
            if (is_float($val)) {
                $val = float_to_raw_string($val);
            } elseif (is_integer($val)) {
                $val = strval($val);
            }
            if (is_string($val) && $val != '') {
                $val = str_replace(chr(0), '', $val);
                if ($done != 0) {
                    $outstr .= ', ';
                }
                $outstr .= '"' . str_replace(chr(10), '\\n', addcslashes($key, "\\\\'\"&\n\r<>")) . '": "' . str_replace(chr(10), '\\n', addcslashes($val, "\\\\'\"&\n\r<>")) . '"';
                $done++;
            }
        }
        $outstr .= '}';
        echo $outstr;
    } else {
        //header('Content-type: text/plain'); @print('No file ('.serialize($_FILES).')');
        header('HTTP/1.1 500 File Upload Error');
        // Test harness
        $title = get_page_title('UPLOAD');
        $fields = new ocp_tempcode();
        require_code('form_templates');
        $fields->attach(form_input_upload(do_lang_tempcode('FILE'), '', 'file', true, NULL, NULL, false));
        $hidden = new ocp_tempcode();
        $out2 = globalise(do_template('FORM_SCREEN', array('TITLE' => $title, 'SUBMIT_NAME' => do_lang_tempcode('PROCEED'), 'TEXT' => '', 'HIDDEN' => $hidden, 'URL' => find_script('incoming_uploads', true), 'FIELDS' => $fields)), NULL, '', true);
        $out2->evaluate_echo();
    }
    exit;
}
Exemple #4
0
 /**
  * Take a file in the gallery uploads directory, and add it to a gallery.
  *
  * @param  URLPATH	The URL to the file
  * @param  URLPATH	The thumb URL to the file
  * @param  string		The filename
  * @param  ID_TEXT	The gallery to add to
  */
 function simple_add($url, $thumb_url, $file, $cat)
 {
     require_code('exif');
     if (substr($thumb_url, -4, 4) == '.gif') {
         $thumb_url = substr($thumb_url, 0, strlen($thumb_url) - 4) . '.png';
     }
     if (is_video($url)) {
         $ret = get_video_details(get_custom_file_base() . '/' . rawurldecode($url), $file, true);
         if ($ret !== false) {
             list($width, $height, $length) = $ret;
             if (is_null($width)) {
                 $width = 100;
             }
             if (is_null($height)) {
                 $height = 100;
             }
             if (is_null($length)) {
                 $length = 0;
             }
             $exif = get_exif_data(get_custom_file_base() . '/' . rawurldecode($url), $file);
             $id = add_video($exif['UserComment'], $cat, '', $url, '', 1, post_param_integer('allow_rating', 0), post_param_integer('allow_reviews', post_param_integer('allow_comments', 0)), post_param_integer('allow_trackbacks', 0), post_param('notes', ''), $length, $width, $height);
             store_exif('video', strval($id), $exif);
             if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'galleries') && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'galleries', $cat)) {
                 syndicate_described_activity('galleries:ACTIVITY_ADD_VIDEO', $exif['UserComment'] == '' ? basename($url) : $exif['UserComment'], '', '', '_SEARCH:galleries:video:' . strval($id), '', '', 'galleries');
             }
         }
     } else {
         $ok = true;
         if (get_option('is_on_gd') == '1' && function_exists('imagecreatefromstring')) {
             require_code('images');
             $ok = convert_image(get_custom_base_url() . '/' . $url, get_custom_file_base() . '/' . rawurldecode($thumb_url), -1, -1, intval(get_option('thumb_width')), true);
         }
         if ($ok) {
             $exif = get_exif_data(get_custom_file_base() . '/' . rawurldecode($url), $file);
             if (get_option('is_on_gd') == '1' && function_exists('imagecreatefromstring')) {
                 // See if we need to resize the image
                 constrain_gallery_image_to_max_size(get_custom_file_base() . '/' . rawurldecode($url), $file, intval(get_option('maximum_image_size')));
                 // See if we need to do watermarking
                 $watermark = post_param_integer('watermark', 0);
                 if ($watermark == 1) {
                     watermark_gallery_image($cat, rawurldecode($url), $file);
                 }
             }
             $id = add_image($exif['UserComment'], $cat, '', $url, $thumb_url, 1, post_param_integer('allow_rating', 0), post_param_integer('allow_reviews', post_param_integer('allow_comments', 0)), post_param_integer('allow_trackbacks', 0), post_param('notes', ''));
             store_exif('image', strval($id), $exif);
             if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'galleries') && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'galleries', $cat)) {
                 syndicate_described_activity('galleries:ACTIVITY_ADD_IMAGE', $exif['UserComment'] == '' ? basename($url) : $exif['UserComment'], '', '', '_SEARCH:galleries:image:' . strval($id), '', '', 'galleries');
             }
         }
     }
 }