Exemplo n.º 1
0
 /**
  * Convert a WowBB database file to an ocPortal uploaded file (stored on disk).
  *
  * @param  string			The file data
  * @param  string			The optimal filename
  * @param  ID_TEXT		The upload type (e.g. ocf_photos)
  * @return URLPATH		The URL
  */
 function data_to_disk($data, $filename, $sections)
 {
     $filename = find_derivative_filename('uploads/' . $sections, $filename);
     $path = get_custom_file_base() . '/uploads/' . $sections . '/' . $filename . '.dat';
     $myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '/' . $filename . '.dat')));
     if (fwrite($myfile, $data) < strlen($data)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($path);
     sync_file($path);
     $url = 'uploads/' . $sections . '/' . $filename . '.dat';
     return $url;
 }
Exemplo n.º 2
0
 /**
  * Convert a AEF database file to an ocPortal uploaded file (stored on disk).
  *
  * @param  string			The file data
  * @param  string			The optimal filename
  * @param  ID_TEXT		The upload type (e.g. ocf_photos)
  * @param  PATH			The base directory we are importing from
  * @return array			Pair: The URL, the thumb url
  */
 function data_to_disk($data, $filename, $sections, $file_base)
 {
     $globals = array();
     require $file_base . '/universal.php';
     $attachments_dir = $globals['server_url'] . '/uploads/attachments/';
     //forum attachments directory
     $file_path = $attachments_dir . $filename;
     $data = $data == '' ? file_get_contents($file_path) : $data;
     $filename = find_derivative_filename('uploads/' . $sections, $filename);
     $path = get_custom_file_base() . '/uploads/' . $sections . '/' . $filename;
     $myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '/' . $filename)));
     if (fwrite($myfile, $data) < strlen($data)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($path);
     sync_file($path);
     $url = 'uploads/' . $sections . '/' . $filename;
     return array($url, $url);
 }
Exemplo n.º 3
0
 /**
  * Convert a VB database file to an ocPortal uploaded file (stored on disk).
  *
  * @param  string			The file data
  * @param  string			The optimal filename
  * @param  ID_TEXT		The upload type (e.g. ocf_photos)
  * @param  boolean		Whether to create a thumbnail for it
  * @param  string			Thumbnail data (blank: no thumbnail / generate one if asked)
  * @param  boolean		Whether to obfuscate the file type
  * @return array			A tuple containing the URL, and if requested, the thumbnail
  */
 function data_to_disk($data, $filename, $sections, $thumbnail = true, $thumbnail_data = '', $obfuscate = false)
 {
     if ($filename == '') {
         $filetype = '';
         if (substr($data, 4, 4) == 'JFIF') {
             $filetype = 'jpg';
         } elseif (substr($data, 0, 3) == 'GIF') {
             $filetype = 'gif';
         } elseif (substr($data, 1, 3) == 'PNG') {
             $filetype = 'png';
         }
         if ($filetype != '') {
             $filename = uniqid('', true) . '.' . $filetype;
         }
     }
     //if ((substr($filename,-4,4)=='.gif') && ($thumbnail)) $filename.='.png';
     if ($filename != '') {
         $filename = find_derivative_filename('uploads/' . $sections, $filename);
         $path = get_custom_file_base() . '/uploads/' . $sections . '/' . $filename . ($obfuscate ? '.dat' : '');
         $myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '/' . $filename . ($obfuscate ? '.dat' : ''))));
         if (fwrite($myfile, $data) < strlen($data)) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         fix_permissions($path);
         sync_file($path);
         $url = 'uploads/' . $sections . '/' . $filename . ($obfuscate ? '.dat' : '');
         if ($thumbnail_data == '') {
             if ($thumbnail) {
                 $t_filename = $filename;
                 $thumb_url = 'uploads/' . $sections . '_thumbs/' . find_derivative_filename('_thumbs', $t_filename, true);
                 require_code('images');
                 convert_image(get_custom_base_url() . '/' . $url, $thumb_url, -1, -1, intval(get_option('thumb_width')), false, NULL, true);
                 return array($url, $thumb_url);
             } else {
                 return array($url, '');
             }
         } else {
             $thumb_filename = find_derivative_filename('uploads/' . $sections . '_thumbs', $filename);
             $path = get_custom_file_base() . '/uploads/' . $sections . '_thumbs/' . $thumb_filename;
             $myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '_thumbs/' . $thumb_filename)));
             if (fwrite($myfile, $thumbnail_data) < strlen($thumbnail_data)) {
                 warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
             }
             fclose($myfile);
             $thumb_url = 'uploads/' . $sections . '/' . $thumb_filename;
             fix_permissions($path);
             sync_file($path);
             return array($url, $thumb_url);
         }
     }
     return array('', '');
 }
Exemplo n.º 4
0
 /**
  * Convert an SMF database file to an ocPortal uploaded file (stored on disk).
  *
  * @param  string			The file data
  * @param  string			The optimal filename
  * @param  ID_TEXT		The upload type (e.g. ocf_photos)
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  string			The filename to output to
  * @param  PATH			The base directory we are importing from
  * @param  string			Attachment ID
  * @return URLPATH		The URL
  */
 function data_to_disk($data, $filename, $sections, $db, $table_prefix = '', $output_filename = '', $file_base = '', $attachment_id = '', $ext = '.png')
 {
     $boardurl = '';
     $boarddir = '';
     require $file_base . '/Settings.php';
     $homeurl = $boardurl;
     $forum_dir = preg_replace('#\\\\#', '/', $boarddir);
     //full path to the forum folder
     $attachments_dir = $forum_dir . '/attachments/';
     //forum attachments directory
     $filename_fixed = $filename . $ext;
     $file_path = $attachments_dir . $filename;
     $data = $data == '' ? @file_get_contents($file_path) : $data;
     $filename = $output_filename == '' ? $filename_fixed : $output_filename;
     $filename = find_derivative_filename('uploads/' . $sections, $filename);
     $path = get_custom_file_base() . '/uploads/' . $sections . '/' . $filename;
     $myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '/' . $filename)));
     fwrite($myfile, $data);
     fclose($myfile);
     fix_permissions($path);
     sync_file($path);
     $url = 'uploads/' . $sections . '/' . $filename;
     return $url;
 }
Exemplo n.º 5
0
 /**
  * Standard import function. Note that this is designed for a very popular phpBB mod, and will exit silently if the mod hasn't been installed.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_post_files($db, $table_prefix, $file_base)
 {
     global $STRICT_FILE;
     require_code('attachments2');
     require_code('attachments3');
     $options = $db->query('SELECT * FROM ' . $table_prefix . 'attachments_config WHERE ' . db_string_equal_to('config_name', 'upload_dir') . ' OR ' . db_string_equal_to('config_name', 'max_attachments') . ' OR ' . db_string_equal_to('config_name', 'use_gd2'), NULL, NULL, true);
     if (is_null($options)) {
         return;
     }
     $upload_dir = $options[0]['config_value'];
     $row_start = 0;
     $rows = array();
     do {
         $rows = $db->query('SELECT * FROM ' . $table_prefix . 'attachments a LEFT JOIN ' . $table_prefix . 'attachments_desc d ON a.attach_id=d.attach_id ORDER BY attach_id', 200, $row_start);
         foreach ($rows as $row) {
             if (import_check_if_imported('post_files', strval($row['attach_id']))) {
                 continue;
             }
             if ($row['post_id'] == 0) {
                 $post_id = import_id_remap_get('pt', strval($row['privmsgs_id']));
             } else {
                 $post_id = import_id_remap_get('post', strval($row['post_id']));
             }
             $post_row = $GLOBALS['FORUM_DB']->query_select('f_posts p LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON p.p_post=t.id', array('p_time', 'text_original', 'p_poster', 'p_post'), array('p.id' => $post_id), '', 1);
             if (!array_key_exists(0, $post_row)) {
                 import_id_remap_put('post_files', strval($row['attach_id']), 1);
                 continue;
                 // Orphaned post
             }
             $post = $post_row[0]['text_original'];
             $lang_id = $post_row[0]['p_post'];
             $member_id = import_id_remap_get('member', strval($row['user_id_1']), true);
             if (is_null($member_id)) {
                 $member_id = $post_row[0]['p_poster'];
             }
             $source_path = $file_base . '/' . $upload_dir . '/' . $row['physical_filename'];
             $new_filename = find_derivative_filename('attachments', $row['physical_filename']);
             $target_path = get_custom_file_base() . '/uploads/attachments/' . $new_filename;
             if (@rename($source_path, $target_path)) {
                 sync_file($target_path);
                 $url = 'uploads/attachments/' . urlencode($new_filename);
                 $thumb_url = '';
                 $a_id = $GLOBALS['SITE_DB']->query_insert('attachments', array('a_member_id' => $member_id, 'a_file_size' => $row['filesize'], 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => $row['real_filename'], 'a_num_downloads' => $row['download_count'], 'a_last_downloaded_time' => NULL, 'a_add_time' => $row['filetime'], 'a_description' => ''), true);
                 $GLOBALS['SITE_DB']->query_insert('attachment_refs', array('r_referer_type' => 'ocf_post', 'r_referer_id' => strval($post_id), 'a_id' => $a_id));
                 $post .= "\n\n" . '[attachment="' . $row['comment'] . '"]' . strval($a_id) . '[/attachment]';
                 ocf_over_msn();
                 update_lang_comcode_attachments($lang_id, $post, 'ocf_post', strval($post_id));
                 ocf_over_local();
             }
             import_id_remap_put('post_files', strval($row['attach_id']), 1);
         }
         $row_start += 200;
     } while (count($rows) > 0);
 }
Exemplo n.º 6
0
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_member_files($db, $table_prefix, $file_base)
 {
     global $STRICT_FILE;
     $row_start = 0;
     $rows = array();
     do {
         $query = 'SELECT * FROM ' . $table_prefix . 'members ORDER BY id';
         $rows = $db->query($query, 200, $row_start);
         foreach ($rows as $row) {
             if (import_check_if_imported('member_files', strval($row['id']))) {
                 continue;
             }
             $member_id = import_id_remap_get('member', strval($row['id']));
             $photo_url = '';
             $photo_thumb_url = '';
             $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'member_extra WHERE id=' . strval($row['id']));
             if (array_key_exists(0, $rows2)) {
                 $row2 = $rows2[0];
                 if ($row2['photo_type'] == 'upload') {
                     $filename = rawurldecode($row2['photo_location']);
                     if (file_exists(get_custom_file_base() . '/uploads/ocf_photos/' . $filename) || @rename($file_base . '/uploads/' . $filename, get_custom_file_base() . '/uploads/ocf_photos/' . $filename)) {
                         $photo_url = 'uploads/ocf_photos/' . $filename;
                         sync_file($photo_url);
                     } else {
                         if ($STRICT_FILE) {
                             warn_exit(do_lang_tempcode('MISSING_PHOTO', $filename));
                         }
                         $photo_url = '';
                     }
                 } else {
                     $photo_url = $row2['photo_location'];
                     $rrpos = strrpos($photo_url, '/');
                     $filename = $rrpos === false ? $photo_url : substr($photo_url, $rrpos);
                 }
                 if ($photo_url != '' && function_exists('imagecreatefromstring')) {
                     $photo_thumb_url = 'uploads/ocf_photos_thumbs/' . find_derivative_filename('ocf_photos_thumbs', $filename, true);
                     require_code('images');
                     convert_image($photo_url, $photo_thumb_url, -1, -1, intval(get_option('thumb_width')), false, NULL, true);
                 }
                 if (either_param('importer') == 'ipb2') {
                     $row['avatar'] = $row2['avatar_location'];
                     $row['avatar_type'] = $row2['avatar_type'];
                 }
             }
             if (either_param('importer') == 'ipb2') {
                 if (!array_key_exists('avatar', $row)) {
                     $row['avatar'] = NULL;
                 }
             }
             $avatar_url = '';
             switch ($row['avatar']) {
                 case NULL:
                     break;
                 case 'noavatar':
                     break;
                 default:
                     if (substr($row['avatar'], 0, 7) == 'upload:') {
                         $filename = substr($row['avatar'], 7);
                         if (file_exists(get_custom_file_base() . '/uploads/ocf_avatars/' . $filename) || @rename($file_base . '/uploads/' . $filename, get_custom_file_base() . '/uploads/ocf_avatars/' . $filename)) {
                             $avatar_url = 'uploads/ocf_avatars/' . $filename;
                             sync_file($avatar_url);
                         } else {
                             if ($STRICT_FILE) {
                                 warn_exit(do_lang_tempcode('MISSING_AVATAR', $filename));
                             }
                             $avatar_url = '';
                         }
                     } elseif (url_is_local($row['avatar'])) {
                         $filename = rawurldecode($row['avatar']);
                         if (file_exists(get_custom_file_base() . '/uploads/ocf_avatars/' . $filename) || @rename($file_base . '/uploads/' . $filename, get_custom_file_base() . '/uploads/ocf_avatars/' . $filename)) {
                             $avatar_url = 'uploads/ocf_avatars/' . substr($filename, strrpos($filename, '/'));
                             sync_file($avatar_url);
                         } else {
                             // Try as a pack avatar then
                             $filename = rawurldecode($row['avatar']);
                             $striped_filename = str_replace('/', '_', $filename);
                             if (file_exists(get_custom_file_base() . '/uploads/ocf_avatars/' . $striped_filename) || @rename($file_base . '/style_avatars/' . $filename, get_custom_file_base() . '/uploads/ocf_avatars/' . $striped_filename)) {
                                 $avatar_url = 'uploads/ocf_avatars/' . substr($filename, strrpos($filename, '/'));
                                 sync_file($avatar_url);
                             } else {
                                 if ($STRICT_FILE) {
                                     warn_exit(do_lang_tempcode('MISSING_AVATAR', $filename));
                                 }
                                 $avatar_url = '';
                             }
                         }
                     } else {
                         $avatar_url = $row['avatar'];
                     }
             }
             $GLOBALS['FORUM_DB']->query_update('f_members', array('m_avatar_url' => $avatar_url, 'm_photo_url' => $photo_url, 'm_photo_thumb_url' => $photo_thumb_url), array('id' => $member_id), '', 1);
             import_id_remap_put('member_files', strval($row['id']), 1);
         }
         $row_start += 200;
     } while (count($rows) > 0);
 }
Exemplo n.º 7
0
 /**
  * Convert an SMF database file to an ocPortal uploaded file (stored on disk).
  *
  * @param  string			The file data
  * @param  string			The optimal filename
  * @param  ID_TEXT		The upload type (e.g. ocf_photos)
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  string			The filename to output to
  * @param  PATH			The base directory we are importing from
  * @param  string			Attachment ID
  * @return URLPATH		The URL
  */
 function data_to_disk($data, $filename, $sections, $db, $table_prefix = '', $output_filename = '', $file_base = '', $attachment_id = '')
 {
     $boardurl = '';
     $boarddir = '';
     require $file_base . '/Settings.php';
     $homeurl = $boardurl;
     $forum_dir = preg_replace('#\\\\#', '/', $boarddir);
     //full path to the forum folder
     $attachments_dir = $forum_dir . '/attachments/';
     //forum attachments directory
     //start preparing the attachment file path by adding it's md5-ied filename and attachment id
     $file_stripped = strtr($filename, 'äéöûü¿¡¬√ƒ≈«»… ÀÃÕŒœ—“”‘’÷ÿŸ⁄€‹›‡·‚„‰ÂÁËÈÍÎÏÌÓÔÒÚÛÙıˆ¯˘˙˚¸˝ˇ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy');
     $file_stripped = strtr($file_stripped, array('fi' => 'TH', '˛' => 'th', '–' => 'DH', '' => 'dh', 'fl' => 'ss', 'å' => 'OE', 'ú' => 'oe', '∆' => 'AE', 'Ê' => 'ae', 'µ' => 'u'));
     $file_stripped = preg_replace(array('/\\s/', '/[^\\w_\\.\\-]/'), array('_', ''), $file_stripped);
     $filename_fixed = strlen($attachment_id) > 0 ? $attachment_id . '_' . str_replace('.', '_', $file_stripped) . md5($file_stripped) : str_replace('.', '_', $file_stripped) . md5($file_stripped);
     $file_path = $attachments_dir . $filename_fixed;
     $data = $data == '' ? @file_get_contents($file_path) : $data;
     $filename = $output_filename == '' ? $filename_fixed : $output_filename;
     $filename = find_derivative_filename('uploads/' . $sections, $filename);
     $path = get_custom_file_base() . '/uploads/' . $sections . '/' . $filename;
     $myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '/' . $filename)));
     fwrite($myfile, $data);
     fclose($myfile);
     fix_permissions($path);
     sync_file($path);
     $url = 'uploads/' . $sections . '/' . $filename;
     return $url;
 }
Exemplo n.º 8
0
 /**
  * Convert a MyBB database file to an ocPortal uploaded file (stored on disk).
  *
  * @param  string			The file data
  * @param  string			The optimal filename
  * @param  ID_TEXT		The upload type (e.g. ocf_photos)
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  string			The filename to output to
  * @return URLPATH		The URL
  */
 function data_to_disk($data, $filename, $sections, $db, $table_prefix = '', $output_filename = '')
 {
     $options = $db->query('SELECT * FROM ' . $table_prefix . 'settings WHERE ' . db_string_equal_to('name', 'bburl'));
     $homeurl = isset($options[0]['value']) && $options[0]['value'] != '' ? $options[0]['value'] : '';
     $host = preg_replace('#\\.#', '\\.', $_SERVER['HTTP_HOST']);
     $doc_root = $_SERVER['DOCUMENT_ROOT'];
     $forum_dir = preg_replace('#http\\:\\/\\/www\\.#', '', $homeurl);
     $forum_dir = preg_replace('#http\\:\\/\\/#', '', $forum_dir);
     $forum_dir = preg_replace('#' . $host . '#', '', $forum_dir);
     $forum_dir = $doc_root . $forum_dir;
     //full path to the forum folder
     $attachments_dir = $forum_dir . '/uploads/';
     //forum attachments directory
     $file_path = $attachments_dir . $filename;
     if ($data == '') {
         if (file_exists($file_path)) {
             $data = file_get_contents($file_path);
         }
     }
     $filename = $output_filename == '' ? preg_replace('#.*\\/#', '', $filename) : $output_filename;
     $filename = find_derivative_filename('uploads/' . $sections, $filename);
     $path = get_custom_file_base() . '/uploads/' . $sections . '/' . $filename;
     $myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '/' . $filename)));
     fwrite($myfile, $data);
     fclose($myfile);
     fix_permissions($path);
     sync_file($path);
     $url = 'uploads/' . $sections . '/' . $filename;
     return $url;
 }