/** * 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'); $row_start = 0; $rows = array(); do { $rows = $db->query('SELECT * FROM ' . $table_prefix . 'attachments', 200, $row_start); foreach ($rows as $row) { if (import_check_if_imported('post_files', strval($row['attachment_id']))) { continue; } $post_id = $db->query_value_null_ok('posts', 'post_id', array('attachment_id' => $row['attachment_id'])); $post_row = array(); if (!is_null($post_id)) { $post_id = import_id_remap_get('post', $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['attachment_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']), true); if (is_null($member_id)) { $member_id = $post_row[0]['p_poster']; } $url = $this->data_to_disk($row['file_contents'], $row['file_name'], 'attachments', false); $thumb_url = ''; $a_id = $GLOBALS['SITE_DB']->query_insert('attachments', array('a_member_id' => $member_id, 'a_file_size' => strlen($row['file_contents']), 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => $row['file_name'], 'a_num_downloads' => $row['downloads'], 'a_last_downloaded_time' => NULL, 'a_add_time' => strtotime($row['upload_date']), 'a_description' => ''), true); $GLOBALS['SITE_DB']->query_insert('attachment_refs', array('r_referer_type' => 'ocf_post', 'r_referer_id' => $post_id, 'a_id' => $a_id)); $post .= "\n\n" . '[attachment=""]' . 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['attachment_id']), 1); } $row_start += 200; } while (count($rows) > 0); }
/** * The actualiser to do an import. * * @return tempcode The UI */ function do_import() { $refresh_url = get_self_url(true, false, array('type' => 'import'), true); $refresh_time = either_param_integer('refresh_time', 15); // Shouldn't default, but reported on some systems to do so if (function_exists('set_time_limit')) { @set_time_limit($refresh_time); } header('Content-type: text/html; charset=' . get_charset()); @ini_set('log_errors', '0'); global $I_REFRESH_URL; $I_REFRESH_URL = $refresh_url; require_code('database_action'); $title = get_page_title('IMPORT'); $importer = get_param('importer'); require_code('hooks/modules/admin_import/' . filter_naughty_harsh($importer)); $object = object_factory('Hook_' . filter_naughty_harsh($importer)); // Get data $old_base_dir = either_param('old_base_dir'); if (method_exists($object, 'verify_base_path') && !$object->verify_base_path($old_base_dir)) { warn_exit(do_lang_tempcode('BAD_IMPORT_PATH', escape_html($old_base_dir))); } if (method_exists($object, 'probe_db_access')) { list($db_name, $db_user, $db_password, $db_table_prefix) = $object->probe_db_access(either_param('old_base_dir')); } else { $db_name = either_param('db_name'); $db_user = either_param('db_user'); $db_password = either_param('db_password'); $db_table_prefix = either_param('db_table_prefix'); } if ($db_name == get_db_site() && $importer == 'ocp_merge' && $db_table_prefix == $GLOBALS['SITE_DB']->get_table_prefix()) { warn_exit(do_lang_tempcode('IMPORT_SELF_NO')); } $import_source = is_null($db_name) ? NULL : new database_driver($db_name, get_db_site_host(), $db_user, $db_password, $db_table_prefix); // Some preliminary tests $happy = get_param_integer('happy', 0); if (method_exists($object, 'pre_import_tests') && $happy == 0) { $ui = $object->pre_import_tests($import_source, $db_table_prefix, $old_base_dir); if (!is_null($ui)) { return $ui; } } // Save data $GLOBALS['SITE_DB']->query_delete('import_session', array('imp_session' => get_session_id()), '', 1); $GLOBALS['SITE_DB']->query_insert('import_session', array('imp_hook' => '', 'imp_old_base_dir' => $old_base_dir, 'imp_db_name' => is_null($db_name) ? '' : $db_name, 'imp_db_user' => is_null($db_user) ? '' : $db_user, 'imp_db_table_prefix' => is_null($db_table_prefix) ? '' : $db_table_prefix, 'imp_refresh_time' => $refresh_time, 'imp_session' => get_session_id())); $info = $object->info(); $_import_list = $info['import']; $out = new ocp_tempcode(); $parts_done = collapse_2d_complexity('imp_id', 'imp_session', $GLOBALS['SITE_DB']->query_select('import_parts_done', array('imp_id', 'imp_session'), array('imp_session' => get_session_id()))); $import_last = '-1'; if (get_forum_type() != 'ocf') { require_code('forum/ocf'); $GLOBALS['OCF_DRIVER'] = new forum_driver_ocf(); $GLOBALS['OCF_DRIVER']->connection = $GLOBALS['SITE_DB']; $GLOBALS['OCF_DRIVER']->MEMBER_ROWS_CACHED = array(); } $_import_list[] = 'ocf_switch'; $all_skipped = true; $lang_array = array(); $hooks = find_all_hooks('modules', 'admin_import_types'); foreach (array_keys($hooks) as $hook) { require_code('hooks/modules/admin_import_types/' . filter_naughty_harsh($hook)); $_hook = object_factory('Hook_admin_import_types_' . filter_naughty_harsh($hook)); $lang_array += $_hook->run(); } foreach ($_import_list as $import) { $import_this = either_param_integer('import_' . $import, 0); if ($import_this == 1) { $dependency = NULL; if (array_key_exists('dependencies', $info) && array_key_exists($import, $info['dependencies'])) { foreach ($info['dependencies'][$import] as $_dependency) { if (!array_key_exists($_dependency, $parts_done) && isset($lang_array[$_dependency])) { $dependency = $_dependency; } } } if (is_null($dependency)) { if ($import == 'ocf_switch') { $out->attach($this->ocf_switch()); } else { $function_name = 'import_' . $import; ocf_over_local(); $func_output = call_user_func_array(array($object, $function_name), array($import_source, $db_table_prefix, $old_base_dir)); if (!is_null($func_output)) { $out->attach($func_output); } ocf_over_msn(); } $parts_done[$import] = get_session_id(); $import_last = $import; $all_skipped = false; $GLOBALS['SITE_DB']->query_delete('import_parts_done', array('imp_id' => $import, 'imp_session' => get_session_id()), '', 1); $GLOBALS['SITE_DB']->query_insert('import_parts_done', array('imp_id' => $import, 'imp_session' => get_session_id())); } else { $out->attach(do_template('IMPORT_MESSAGE', array('_GUID' => 'b2a853f5fb93beada51a3eb8fbd1575f', 'MESSAGE' => do_lang_tempcode('IMPORT_OF_SKIPPED', escape_html($import), escape_html($dependency))))); } } } if (!$all_skipped) { $lang_code = 'SUCCESS'; if (count($GLOBALS['ATTACHED_MESSAGES_RAW']) != 0) { $lang_code = 'SOME_ERRORS_OCCURRED'; } $out->attach(do_template('IMPORT_MESSAGE', array('_GUID' => '4c4860d021814ffd1df6e21e712c7b44', 'MESSAGE' => do_lang_tempcode($lang_code)))); } log_it('IMPORT'); // Quick and simple decacheing. No need to be smart about this. delete_value('ocf_member_count'); delete_value('ocf_topic_count'); delete_value('ocf_post_count'); breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('IMPORT')), array('_SELF:_SELF:session', do_lang_tempcode('IMPORT_SESSION')), array('_SELF:_SELF:hook:importer=' . $importer . ':session=' . get_param('session'), do_lang_tempcode('IMPORT')))); breadcrumb_set_self(do_lang_tempcode('START')); $back_url = build_url(array('page' => '_SELF', 'type' => 'hook', 'importer' => get_param('importer'), 'just' => $import_last), '_SELF'); $_GET['just'] = $import_last; return $this->choose_actions($out); }
/** * 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_calendar($db, $table_prefix, $file_base) { require_code('calendar2'); $rows = $db->query('SELECT * FROM ' . $table_prefix . 'event'); foreach ($rows as $row) { if (import_check_if_imported('event', strval($row['eventid']))) { continue; } $submitter = import_id_remap_get('member', strval($row['userid']), true); if (is_null($submitter)) { $submitter = $GLOBALS['OCF_DRIVER']->get_guest_id(); } $recurrence = 'none'; $recurrences = NULL; $bits = explode('|', $row['recuroption']); switch ($row['recurring']) { case 1: $recurrence = 'daily ' . str_repeat('0', intval($bits[0]) - 1) . '1'; break; case 2: $recurrence = 'daily 1111100'; break; case 3: $recurrence = 'daily 0000000'; if (($bits[1] & 1) != 0) { $recurrence[6] = '1'; } if (($bits[1] & 2) != 0) { $recurrence[7] = '1'; } if (($bits[1] & 4) != 0) { $recurrence[8] = '1'; } if (($bits[1] & 8) != 0) { $recurrence[9] = '1'; } if (($bits[1] & 16) != 0) { $recurrence[10] = '1'; } if (($bits[1] & 32) != 0) { $recurrence[11] = '1'; } if (($bits[1] & 64) != 0) { $recurrence[12] = '1'; } $recurrences = $bits[0]; // Guess break; case 4: $recurrence = 'monthly ' . str_repeat('0', intval($bits[1]) - 1) . '1'; break; case 5: $recurrence = 'monthly ' . str_repeat('0', intval($bits[0]) - 1) . '1'; break; case 6: $recurrence = 'yearly ' . str_repeat('0', intval($bits[0]) - 1) . '1'; break; case 7: $recurrence = 'yearly ' . str_repeat('0', intval($bits[0]) - 1) . '1'; break; } list($start_year, $start_month, $start_day, $start_hour, $start_minute) = explode('-', date('Y-m-d-h-i', strtotime($row['dateline']))); list($end_year, $end_month, $end_day, $end_hour, $end_minute) = array(NULL, NULL, NULL, NULL, NULL); ocf_over_msn(); $id_new = add_calendar_event(db_get_first_id() + 1, $recurrence, $recurrences, 0, $row['title'], $row['event'], 3, $row['visible'], $start_year, $start_month, $start_day, $start_hour, $start_minute, $end_year, $end_month, $end_day, $end_hour, $end_minute, NULL, 1, $submitter, 0, $row['dateline']); ocf_over_local(); import_id_remap_put('event', strval($row['eventid']), $id_new); } }
/** * 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); }
/** * Check a comments forum has been configured. */ function test_for_comments_forum() { ocf_over_msn(); $comments_forum = $GLOBALS['FORUM_DRIVER']->forum_id_from_name(get_option('comments_forum_name')); ocf_over_local(); if (is_null($comments_forum)) { $_config_url = build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => 'FEATURE'), 'adminzone'); $config_url = $_config_url->evaluate(); warn_exit(do_lang_tempcode('IMPORT_NO_COMMENTS_FORUM', escape_html($config_url . '#group_USER_INTERACTION'))); } }
/** * 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_post_files($db, $table_prefix, $file_base) { global $STRICT_FILE; require_code('attachments2'); require_code('attachments3'); require_code('images'); $row_start = 0; $select = either_param('importer') == 'ipb1' ? 'pid,attach_id,attach_file,attach_hits,post_date' : 'pid,post_date'; $rows = array(); do { $rows = $db->query('SELECT ' . $select . ' FROM ' . $table_prefix . 'posts ORDER BY pid', 200, $row_start); foreach ($rows as $row) { if (import_check_if_imported('post_files', strval($row['pid']))) { continue; } $post_id = import_id_remap_get('post', strval($row['pid']), true); if (is_null($post_id)) { continue; } $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['pid']), 1); continue; // Orphaned post } $post = $post_row[0]['text_original']; $lang_id = $post_row[0]['p_post']; $member_id = import_id_remap_get('member', $post_row[0]['p_poster']); $post_date = $post_row[0]['p_time']; if (either_param('importer') == 'ipb1') { $has_attachment = false; if ($row['attach_id'] != '') { $target_path = get_custom_file_base() . '/uploads/attachments/' . $row['attach_id']; if (file_exists(get_custom_file_base() . '/uploads/attachments/' . $row['attach_id']) || @rename($file_base . '/uploads/' . $row['attach_id'], $target_path)) { $url = 'uploads/attachments/' . $row['attach_id']; sync_file($url); $thumb_url = ''; if (is_image($target_path)) { /* require_code('images'); $thumb_url='uploads/attachments_thumbs/'.$row['attach_id']; convert_image($url,$thumb_url,-1,-1,intval(get_option('thumb_width')),false,NULL,true);*/ } $_a_id = $GLOBALS['SITE_DB']->query_insert('attachments', array('a_member_id' => $member_id, 'a_file_size' => @filesize($target_path), 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => $row['attach_file'], 'a_num_downloads' => $row['attach_hits'], 'a_last_downloaded_time' => NULL, 'a_add_time' => $row['post_date'], 'a_description' => ''), true); $has_attachment = true; } else { if ($STRICT_FILE) { warn_exit(do_lang_tempcode('MISSING_ATTACHMENT', $row['attach_location'])); } } } } else { if (either_param('importer') == 'ipb1') { $attachments = $db->query('SELECT * FROM ' . $table_prefix . 'attachments WHERE attach_pid=' . strval($row['pid']) . ' AND attach_approved=1'); } else { $attachments = $db->query('SELECT * FROM ' . $table_prefix . 'attachments WHERE attach_rel_id=' . strval($row['pid']) . ' AND ' . db_string_equal_to('attach_rel_module', 'post')); } $i = 0; $a_id = array(); foreach ($attachments as $attachment) { $target_path = get_custom_file_base() . '/uploads/attachments/' . $attachment['attach_location']; if (file_exists(get_custom_file_base() . '/uploads/attachments/' . $attachment['attach_location']) || @rename($file_base . '/uploads/' . $attachment['attach_location'], $target_path)) { $url = 'uploads/attachments/' . $attachment['attach_location']; sync_file($url); $thumb_url = ''; if (is_image($target_path)) { /* require_code('images'); $thumb_url='uploads/attachments_thumbs/'.$attachment['attach_location']; convert_image($url,$thumb_url,-1,-1,intval(get_option('thumb_width')),false,NULL,true);*/ } $a_id[$i] = $GLOBALS['SITE_DB']->query_insert('attachments', array('a_member_id' => $member_id, 'a_file_size' => $attachment['attach_filesize'], 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => $attachment['attach_file'], 'a_num_downloads' => $attachment['attach_hits'], 'a_last_downloaded_time' => NULL, 'a_add_time' => $post_date, 'a_description' => ''), true); $has_attachment = true; } else { if ($STRICT_FILE) { warn_exit(do_lang_tempcode('MISSING_ATTACHMENT', $attachment['attach_location'])); } } $i++; } } if (either_param('importer') == 'ipb1') { if ($has_attachment) { $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]' . strval($_a_id) . '[/attachment]'; ocf_over_msn(); update_lang_comcode_attachments($lang_id, $post, 'ocf_post', strval($post_id)); ocf_over_local(); } } elseif (count($a_id) != 0) { $i = 0; foreach ($attachments as $attachment) { if (array_key_exists($i, $a_id)) { $GLOBALS['SITE_DB']->query_insert('attachment_refs', array('r_referer_type' => 'ocf_post', 'r_referer_id' => strval($post_id), 'a_id' => $a_id[$i])); $post .= "\n\n" . '[attachment]' . $a_id[$i] . '[/attachment]'; } $i++; } 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['pid']), 1); } $row_start += 200; } while (count($rows) > 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_calendar($db, $table_prefix, $file_base) { require_code('calendar2'); $rows = $db->query_select('calendar'); foreach ($rows as $row) { if (import_check_if_imported('event', strval($row['ID_EVENT']))) { continue; } $submitter = import_id_remap_get('member', strval($row['ID_MEMBER']), true); if (is_null($submitter)) { $submitter = $GLOBALS['OCF_DRIVER']->get_guest_id(); } $recurrence = 'none'; $recurrences = NULL; $days = intval(floor((strtotime($row['endDate']) - strtotime($row['startDate'])) / (60 * 60 * 24))); //Max 7 days in SMF if ($days == 0) { $recurrence = 'daily 1'; } else { $recurrence = 'daily '; for ($i = 1; $i <= $days; $i++) { $recurrence .= '1'; } } $start_hour = 0; $start_minute = 0; list($start_year, $start_month, $start_day) = array_map('intval', explode('-', $row['eventDate'])); list($end_year, $end_month, $end_day, $end_hour, $end_minute) = array($start_year, $start_month, $start_day, $start_hour, $start_minute); $description = ''; if ($row['ID_TOPIC'] != 0) { $messages = $db->query('SELECT * FROM ' . $table_prefix . 'messages WHERE ID_TOPIC=' . strval($row['ID_TOPIC']) . ' ORDER BY ID_TOPIC ASC'); ocf_over_msn(); $description = isset($messages[0]['body']) && $messages[0]['body'] != '' ? html_to_comcode($messages[0]['body']) : ''; ocf_over_local(); } ocf_over_msn(); $id_new = add_calendar_event(db_get_first_id() + 1, $recurrence, $recurrences, 0, $row['title'], $description, 3, 1, $start_year, $start_month, $start_day, $start_hour, $start_minute, $end_year, $end_month, $end_day, $end_hour, $end_minute, NULL, 1, 1, 1, 1, 1, '', $submitter); ocf_over_local(); import_id_remap_put('event', strval($row['ID_EVENT']), $id_new); } $rows = array(); $rows = $db->query_select('calendar_holidays'); foreach ($rows as $row) { if (import_check_if_imported('event', strval($row['ID_HOLIDAY']))) { continue; } $submitter = $GLOBALS['OCF_DRIVER']->get_guest_id(); $recurrence = 'none'; $recurrences = NULL; list($start_year, $start_month, $start_day, $start_hour, $start_minute) = array_map('intval', explode('-', date('Y-m-d-h-i', strtotime($row['eventDate'])))); list($end_year, $end_month, $end_day, $end_hour, $end_minute) = array_map('intval', explode('-', date('Y-m-d-h-i', strtotime($row['eventDate'])))); ocf_over_msn(); $id_new = add_calendar_event(db_get_first_id() + 1, $recurrence, $recurrences, 0, $row['title'], $row['title'], 3, 1, $start_year, $start_month, $start_day, $start_hour, $start_minute, $end_year, $end_month, $end_day, $end_hour, $end_minute, NULL, 1, 1, 1, 1, 1, '', $submitter); ocf_over_local(); import_id_remap_put('event', strval($row['ID_HOLIDAY']), $id_new); } }
/** * 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_calendar($db, $table_prefix, $file_base) { require_code('calendar2'); $rows = $db->query_select('events'); foreach ($rows as $row) { if (import_check_if_imported('event', strval($row['eid']))) { continue; } $submitter = import_id_remap_get('member', strval($row['uid']), true); if (is_null($submitter)) { $submitter = $GLOBALS['OCF_DRIVER']->get_guest_id(); } $recurrence = 'none'; $recurrences = NULL; $event_repeat_data = unserialize($row['repeats']); $event_repeats = isset($event_repeat_data['repeats']) && $event_repeat_data['repeats'] != 0 ? $event_repeat_data['repeats'] : 0; switch ($event_repeats) { case 1: $week_array = array(0, 0, 0, 0, 0, 0, 0); $start_day_num = intval(date('w', $row['starttime'])); $every_days = $event_repeat_data['days']; $week_array[$start_day_num] = 1; $next_day = $start_day_num; for ($i = 1; $i < 7; $i++) { $next_day += $every_days; if ($next_day > 6) { $next_day -= 6; } $week_array[$next_day] = 1; } $recurrence = 'daily ' . implode('', $week_array); break; case 2: $recurrence = 'daily 1111100'; break; case 3: $week_array = array(0, 0, 0, 0, 0, 0, 0); $week_array[0] = isset($event_repeat_data['days'][0]) && $event_repeat_data['days'][0] != '' ? 1 : 0; $week_array[1] = isset($event_repeat_data['days'][1]) && $event_repeat_data['days'][1] != '' ? 1 : 0; $week_array[2] = isset($event_repeat_data['days'][2]) && $event_repeat_data['days'][2] != '' ? 1 : 0; $week_array[3] = isset($event_repeat_data['days'][3]) && $event_repeat_data['days'][3] != '' ? 1 : 0; $week_array[4] = isset($event_repeat_data['days'][4]) && $event_repeat_data['days'][4] != '' ? 1 : 0; $week_array[5] = isset($event_repeat_data['days'][5]) && $event_repeat_data['days'][5] != '' ? 1 : 0; $week_array[6] = isset($event_repeat_data['days'][6]) && $event_repeat_data['days'][6] != '' ? 1 : 0; $recurrence = 'daily ' . implode('', $week_array); break; case 4: $pattern = '1'; $repeat_every_n_years = $event_repeat_data['months']; for ($i = 1; $i < $repeat_every_n_years; $i++) { $pattern .= '0'; } $recurrence = 'monthly ' . $pattern; break; case 5: $pattern = '1'; $repeat_every_n_years = $event_repeat_data['years']; for ($i = 1; $i < $repeat_every_n_years; $i++) { $pattern .= '0'; } $recurrence = 'yearly ' . $pattern; break; } list($start_year, $start_month, $start_day, $start_hour, $start_minute) = explode('-', date('Y-m-d-h-i', strtotime($row['starttime']))); list($end_year, $end_month, $end_day, $end_hour, $end_minute) = explode('-', date('Y-m-d-h-i', strtotime($row['endtime']))); ocf_over_msn(); $id_new = add_calendar_event(db_get_first_id() + 1, $recurrence, $recurrences, 0, $row['name'], $row['description'], 3, $row['visible'], $start_year, $start_month, $start_day, $start_hour, $start_minute, $end_year, $end_month, $end_day, $end_hour, $end_minute, NULL, 1, $submitter, 0, $row['dateline']); ocf_over_local(); import_id_remap_put('event', strval($row['eid']), $id_new); } }