/** * * @return string */ function upload_gedcom_handler() { try { if (!current_user_can('upload_files')) { wp_die(_('You do not have permission to upload files.', 'rootspersona')); } $action = admin_url('/tools.php?page=rootsPersona&rootspage=upload'); $msg = ''; $retStr = ''; $batch_id = '1'; if (isset($_POST['submitUploadGedcomForm'])) { if ($_FILES['gedcomFile']['error'] != UPLOAD_ERR_OK) { $msg = __('Error Uploading File.', 'rootspersona'); } else { if (!is_uploaded_file($_FILES['gedcomFile']['tmp_name'])) { $msg = __('Empty File.', 'rootspersona'); } else { set_time_limit(60); if (WP_DEBUG === true) { $time_start = microtime(true); } $batch_id = isset($_POST['batch_id']) ? trim(esc_attr($_POST['batch_id'])) : '1'; $fileName = $_FILES['gedcomFile']['tmp_name']; $loader = new RP_Gedcom_Loader(); set_time_limit(60); $loader->load_tables($this->credentials, $fileName, $batch_id); unlink($_FILES['gedcomFile']['tmp_name']); if (WP_DEBUG === true) { $time = microtime(true) - $time_start; error_log("Done in {$time} seconds using " . memory_get_peak_usage(true) / 1024 / 1024 . 'MB.'); } } } } $options = get_option('persona_plugin'); if (empty($msg) && isset($_POST['submitUploadGedcomForm'])) { // The wp_redirect command uses a PHP redirect at its core, // therefore, it will not work either after header information // has been defined for a page. $location = admin_url('/tools.php?page=rootsPersona&rootspage=create&batch_id=' . $batch_id); $retStr = '<script type = "text/javascript">window.location = "' . $location . '"; </script>'; } else { $this->transaction = new RP_Transaction($this->credentials, true); $batch_ids = RP_Dao_Factory::get_rp_persona_dao($this->credentials->prefix)->get_batch_ids(); $this->transaction->close(); $builder = new RP_Upload_Page_Builder(); $retStr = $builder->build($action, $msg, $options, $batch_ids); } return $retStr; } catch (Exception $e) { error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(), 0); return '<span style="color:red;margin-top:20px;display:inline-block;">' . $e->getMessage() . "::" . RP_Persona_Helper::trace_caller() . '</span>'; } }
function process_form($credentials, $parms, $options) { $isSOR = $options['is_system_of_record'] == '1' ? true : false; $validator = new Persona_Validator(); $ret = $validator->validate($parms, $options); $options = $ret[1]; if ($ret[0] !== false) { if ($isSOR) { $handler = new RP_Gedcom_Loader(); $handler->credentials = $credentials; $handler->batch_id = $ret[0]->batch_id; $options['editMode'] = 1; $indi = $handler->process_individual($ret[0], $options); } else { $indi = $ret[0]; } if ($indi instanceof RP_Individual_Record) { if (isset($indi->id) && !empty($indi->id)) { $page = $indi->page; if (!isset($page) || empty($page)) { $title = RP_Dao_Factory::get_rp_persona_dao($this->credentials->prefix)->get_fullname($indi->id, $batch_id); $content = "[rootsPersona personid='{$indi->id}' batchId='{$indi->batch_id}'"; for ($i = 1; $i <= 7; $i++) { $pf = 'picfile' . $i; if (isset($indi->images[$i - 1])) { $content = $content . ' ' . $pf . "='" . $indi->images[$i - 1] . "'"; $pc = 'piccap' . $i; if (isset($indi->captions[$i - 1])) { $content = $content . ' ' . $pc . "='" . $indi->captions[$i - 1] . "'"; } } } $content = $content . "/]"; $page_id = RP_Persona_Helper::add_page(null, $title, $options, null, $content); $indi->page = $page_id; if ($page_id != false) { $this->transaction = new RP_Transaction($credentials); RP_Dao_Factory::get_rp_indi_dao($credentials->prefix)->update_page($indi->id, $indi->batch_id, $page_id); RP_Dao_Factory::get_rp_persona_dao($credentials->prefix)->update_persona_privacy($indi->id, $indi->batch_id, $indi->privacy, ''); $this->transaction->commit(); } } else { if ($indi->privacy != 'Exc') { $my_post = array(); $my_post['ID'] = $page; if ($isSOR) { $title = RP_Dao_Factory::get_rp_persona_dao($this->credentials->prefix)->get_fullname($indi->id, $batch_id); $my_post['post_title'] = $title; } $content = "[rootsPersona personid='{$indi->id}' batchId='{$indi->batch_id}'"; for ($i = 1; $i <= 7; $i++) { $pf = 'picfile' . $i; if (isset($indi->images[$i - 1])) { $content = $content . ' ' . $pf . "='" . $indi->images[$i - 1] . "'"; $pc = 'piccap' . $i; if (isset($indi->captions[$i - 1])) { $content = $content . ' ' . $pc . "='" . $indi->captions[$i - 1] . "'"; } } } $content = $content . "/]"; $my_post['post_content'] = $content; wp_update_post($my_post); $this->transaction = new RP_Transaction($credentials); RP_Dao_Factory::get_rp_persona_dao($credentials->prefix)->update_persona_privacy($indi->id, $indi->batch_id, $indi->privacy, ''); $this->transaction->commit(); } else { wp_delete_post($page); RP_Dao_Factory::get_rp_persona_dao($this->credentials->prefix)->delete_persona($indi->id, $indi->batch_id); $r = array(); $r['error'] = 'Persona deleted.'; return $r; } } } } else { $r = array(); $r['error'] = 'Error saving record.'; return $r; } } else { return $ret[1]['errors']; } $r = array(); $r['rp_id'] = $indi->id; $r['rp_page'] = $indi->page; if (isset($indi->parental->id) && !empty($indi->parental->id)) { $r['rp_famc'] = $indi->parental->id; } if (isset($indi->newFams) && !empty($indi->newFams)) { $r['rp_fams'] = $indi->newFams; } return $r; }